dri: add loader_dri_create_image helper

The DRI image extension already has two different ways to allocate an
image (with and without a modifier) and will soon grow a third one.
Add a helper, which handles calling the appropriate implementation to
get rid of code duplication in the winsys.

This convert the two obvious call sites (GBM dri and EGL wayland)
that profit from the code dedup.

Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
Reviewed-by: Daniel Stone <daniels@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8106>
This commit is contained in:
Lucas Stach
2020-12-15 14:39:32 +01:00
committed by Marge Bot
parent 7327b2b7b4
commit cb9ae4273d
6 changed files with 133 additions and 83 deletions

View File

@@ -0,0 +1,68 @@
/*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that copyright
* notice and this permission notice appear in supporting documentation, and
* that the name of the copyright holders not be used in advertising or
* publicity pertaining to distribution of the software without specific,
* written prior permission. The copyright holders make no representations
* about the suitability of this software for any purpose. It is provided "as
* is" without express or implied warranty.
*
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
* OF THIS SOFTWARE.
*/
#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
#include <sys/types.h>
#include <GL/gl.h> /* dri_interface needs GL types */
#include <GL/internal/dri_interface.h>
#include "drm-uapi/drm_fourcc.h"
#include "loader_dri_helper.h"
__DRIimage *loader_dri_create_image(__DRIscreen *screen,
const __DRIimageExtension *image,
uint32_t width, uint32_t height,
uint32_t dri_format, uint32_t dri_usage,
const uint64_t *modifiers,
unsigned int modifiers_count,
void *loaderPrivate)
{
if (modifiers &&
image->base.version > 14 && image->createImageWithModifiers) {
bool has_valid_modifier = false;
int i;
/* It's acceptable to create an image with INVALID modifier in the list,
* but it cannot be on the only modifier (since it will certainly fail
* later). While we could easily catch this after modifier creation, doing
* the check here is a convenient debug check likely pointing at whatever
* interface the client is using to build its modifier list.
*/
for (i = 0; i < modifiers_count; i++) {
if (modifiers[i] != DRM_FORMAT_MOD_INVALID) {
has_valid_modifier = true;
break;
}
}
if (!has_valid_modifier)
return NULL;
return image->createImageWithModifiers(screen, width, height,
dri_format, modifiers,
modifiers_count, loaderPrivate);
}
/* No modifier given or fallback to the legacy createImage allowed */
return image->createImage(screen, width, height, dri_format, dri_usage,
loaderPrivate);
}