1/* 2 * Permission to use, copy, modify, distribute, and sell this software and its 3 * documentation for any purpose is hereby granted without fee, provided that 4 * the above copyright notice appear in all copies and that both that copyright 5 * notice and this permission notice appear in supporting documentation, and 6 * that the name of the copyright holders not be used in advertising or 7 * publicity pertaining to distribution of the software without specific, 8 * written prior permission. The copyright holders make no representations 9 * about the suitability of this software for any purpose. It is provided "as 10 * is" without express or implied warranty. 11 * 12 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 13 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO 14 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR 15 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 16 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 17 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 18 * OF THIS SOFTWARE. 19 */ 20 21#include <errno.h> 22#include <stdbool.h> 23#include <stdio.h> 24#include <sys/types.h> 25 26#include <GL/gl.h> /* dri_interface needs GL types */ 27#include <GL/internal/dri_interface.h> 28 29#include "drm-uapi/drm_fourcc.h" 30#include "loader_dri_helper.h" 31 32__DRIimage *loader_dri_create_image(__DRIscreen *screen, 33 const __DRIimageExtension *image, 34 uint32_t width, uint32_t height, 35 uint32_t dri_format, uint32_t dri_usage, 36 const uint64_t *modifiers, 37 unsigned int modifiers_count, 38 void *loaderPrivate) 39{ 40 if (modifiers && modifiers_count > 0 && 41 image->base.version > 14 && image->createImageWithModifiers) { 42 bool has_valid_modifier = false; 43 int i; 44 45 /* It's acceptable to create an image with INVALID modifier in the list, 46 * but it cannot be on the only modifier (since it will certainly fail 47 * later). While we could easily catch this after modifier creation, doing 48 * the check here is a convenient debug check likely pointing at whatever 49 * interface the client is using to build its modifier list. 50 */ 51 for (i = 0; i < modifiers_count; i++) { 52 if (modifiers[i] != DRM_FORMAT_MOD_INVALID) { 53 has_valid_modifier = true; 54 break; 55 } 56 } 57 if (!has_valid_modifier) 58 return NULL; 59 60 if (image->base.version >= 19 && image->createImageWithModifiers2) 61 return image->createImageWithModifiers2(screen, width, height, 62 dri_format, modifiers, 63 modifiers_count, dri_usage, 64 loaderPrivate); 65 else 66 return image->createImageWithModifiers(screen, width, height, 67 dri_format, modifiers, 68 modifiers_count, loaderPrivate); 69 } 70 71 /* No modifier given or fallback to the legacy createImage allowed */ 72 return image->createImage(screen, width, height, dri_format, dri_usage, 73 loaderPrivate); 74} 75