17ec681f3Smrg/* 27ec681f3Smrg * Permission to use, copy, modify, distribute, and sell this software and its 37ec681f3Smrg * documentation for any purpose is hereby granted without fee, provided that 47ec681f3Smrg * the above copyright notice appear in all copies and that both that copyright 57ec681f3Smrg * notice and this permission notice appear in supporting documentation, and 67ec681f3Smrg * that the name of the copyright holders not be used in advertising or 77ec681f3Smrg * publicity pertaining to distribution of the software without specific, 87ec681f3Smrg * written prior permission. The copyright holders make no representations 97ec681f3Smrg * about the suitability of this software for any purpose. It is provided "as 107ec681f3Smrg * is" without express or implied warranty. 117ec681f3Smrg * 127ec681f3Smrg * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 137ec681f3Smrg * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO 147ec681f3Smrg * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR 157ec681f3Smrg * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 167ec681f3Smrg * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 177ec681f3Smrg * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 187ec681f3Smrg * OF THIS SOFTWARE. 197ec681f3Smrg */ 207ec681f3Smrg 217ec681f3Smrg#include <errno.h> 227ec681f3Smrg#include <stdbool.h> 237ec681f3Smrg#include <stdio.h> 247ec681f3Smrg#include <sys/types.h> 257ec681f3Smrg 267ec681f3Smrg#include <GL/gl.h> /* dri_interface needs GL types */ 277ec681f3Smrg#include <GL/internal/dri_interface.h> 287ec681f3Smrg 297ec681f3Smrg#include "drm-uapi/drm_fourcc.h" 307ec681f3Smrg#include "loader_dri_helper.h" 317ec681f3Smrg 327ec681f3Smrg__DRIimage *loader_dri_create_image(__DRIscreen *screen, 337ec681f3Smrg const __DRIimageExtension *image, 347ec681f3Smrg uint32_t width, uint32_t height, 357ec681f3Smrg uint32_t dri_format, uint32_t dri_usage, 367ec681f3Smrg const uint64_t *modifiers, 377ec681f3Smrg unsigned int modifiers_count, 387ec681f3Smrg void *loaderPrivate) 397ec681f3Smrg{ 407ec681f3Smrg if (modifiers && modifiers_count > 0 && 417ec681f3Smrg image->base.version > 14 && image->createImageWithModifiers) { 427ec681f3Smrg bool has_valid_modifier = false; 437ec681f3Smrg int i; 447ec681f3Smrg 457ec681f3Smrg /* It's acceptable to create an image with INVALID modifier in the list, 467ec681f3Smrg * but it cannot be on the only modifier (since it will certainly fail 477ec681f3Smrg * later). While we could easily catch this after modifier creation, doing 487ec681f3Smrg * the check here is a convenient debug check likely pointing at whatever 497ec681f3Smrg * interface the client is using to build its modifier list. 507ec681f3Smrg */ 517ec681f3Smrg for (i = 0; i < modifiers_count; i++) { 527ec681f3Smrg if (modifiers[i] != DRM_FORMAT_MOD_INVALID) { 537ec681f3Smrg has_valid_modifier = true; 547ec681f3Smrg break; 557ec681f3Smrg } 567ec681f3Smrg } 577ec681f3Smrg if (!has_valid_modifier) 587ec681f3Smrg return NULL; 597ec681f3Smrg 607ec681f3Smrg if (image->base.version >= 19 && image->createImageWithModifiers2) 617ec681f3Smrg return image->createImageWithModifiers2(screen, width, height, 627ec681f3Smrg dri_format, modifiers, 637ec681f3Smrg modifiers_count, dri_usage, 647ec681f3Smrg loaderPrivate); 657ec681f3Smrg else 667ec681f3Smrg return image->createImageWithModifiers(screen, width, height, 677ec681f3Smrg dri_format, modifiers, 687ec681f3Smrg modifiers_count, loaderPrivate); 697ec681f3Smrg } 707ec681f3Smrg 717ec681f3Smrg /* No modifier given or fallback to the legacy createImage allowed */ 727ec681f3Smrg return image->createImage(screen, width, height, dri_format, dri_usage, 737ec681f3Smrg loaderPrivate); 747ec681f3Smrg} 75