Path: blob/21.2-virgl/src/loader/loader_dri_helper.c
4550 views
/*1* Permission to use, copy, modify, distribute, and sell this software and its2* documentation for any purpose is hereby granted without fee, provided that3* the above copyright notice appear in all copies and that both that copyright4* notice and this permission notice appear in supporting documentation, and5* that the name of the copyright holders not be used in advertising or6* publicity pertaining to distribution of the software without specific,7* written prior permission. The copyright holders make no representations8* about the suitability of this software for any purpose. It is provided "as9* is" without express or implied warranty.10*11* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,12* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO13* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR14* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,15* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER16* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE17* OF THIS SOFTWARE.18*/1920#include <errno.h>21#include <stdbool.h>22#include <stdio.h>23#include <sys/types.h>2425#include <GL/gl.h> /* dri_interface needs GL types */26#include <GL/internal/dri_interface.h>2728#include "drm-uapi/drm_fourcc.h"29#include "loader_dri_helper.h"3031__DRIimage *loader_dri_create_image(__DRIscreen *screen,32const __DRIimageExtension *image,33uint32_t width, uint32_t height,34uint32_t dri_format, uint32_t dri_usage,35const uint64_t *modifiers,36unsigned int modifiers_count,37void *loaderPrivate)38{39if (modifiers && modifiers_count > 0 &&40image->base.version > 14 && image->createImageWithModifiers) {41bool has_valid_modifier = false;42int i;4344/* It's acceptable to create an image with INVALID modifier in the list,45* but it cannot be on the only modifier (since it will certainly fail46* later). While we could easily catch this after modifier creation, doing47* the check here is a convenient debug check likely pointing at whatever48* interface the client is using to build its modifier list.49*/50for (i = 0; i < modifiers_count; i++) {51if (modifiers[i] != DRM_FORMAT_MOD_INVALID) {52has_valid_modifier = true;53break;54}55}56if (!has_valid_modifier)57return NULL;5859if (image->base.version >= 19 && image->createImageWithModifiers2)60return image->createImageWithModifiers2(screen, width, height,61dri_format, modifiers,62modifiers_count, dri_usage,63loaderPrivate);64else65return image->createImageWithModifiers(screen, width, height,66dri_format, modifiers,67modifiers_count, loaderPrivate);68}6970/* No modifier given or fallback to the legacy createImage allowed */71return image->createImage(screen, width, height, dri_format, dri_usage,72loaderPrivate);73}747576