st/dri: move some image functions to dri_helpers.c
These functions will be used both by drisw.c and dri2.c. This patch also moves some headers that can be shared. Reviewed-by: Emil Velikov <emil.velikov@collabora.com> Reviewed-by: Marek Olšák <marek.olsak@amd.com>
This commit is contained in:
parent
18eb3bdb85
commit
12fcdc4ba0
|
@ -45,10 +45,8 @@
|
|||
#include "main/bufferobj.h"
|
||||
#include "main/texobj.h"
|
||||
|
||||
#include "dri_screen.h"
|
||||
#include "dri_context.h"
|
||||
#include "dri_drawable.h"
|
||||
#include "dri_helpers.h"
|
||||
#include "dri_drawable.h"
|
||||
#include "dri_query_renderer.h"
|
||||
#include "dri2_buffer.h"
|
||||
|
||||
|
@ -884,21 +882,6 @@ dri2_update_tex_buffer(struct dri_drawable *drawable,
|
|||
/* no-op */
|
||||
}
|
||||
|
||||
static __DRIimage *
|
||||
dri2_lookup_egl_image(struct dri_screen *screen, void *handle)
|
||||
{
|
||||
const __DRIimageLookupExtension *loader = screen->sPriv->dri2.image;
|
||||
__DRIimage *img;
|
||||
|
||||
if (!loader->lookupEGLImage)
|
||||
return NULL;
|
||||
|
||||
img = loader->lookupEGLImage(screen->sPriv,
|
||||
handle, screen->sPriv->loaderPrivate);
|
||||
|
||||
return img;
|
||||
}
|
||||
|
||||
static __DRIimage *
|
||||
dri2_create_image_from_winsys(__DRIscreen *_screen,
|
||||
int width, int height, int format,
|
||||
|
@ -1072,19 +1055,6 @@ exit:
|
|||
return img;
|
||||
}
|
||||
|
||||
static __DRIimage *
|
||||
dri2_create_image_from_renderbuffer(__DRIcontext *context,
|
||||
int renderbuffer, void *loaderPrivate)
|
||||
{
|
||||
struct dri_context *ctx = dri_context(context);
|
||||
|
||||
if (!ctx->st->get_resource_for_egl_image)
|
||||
return NULL;
|
||||
|
||||
/* TODO */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static __DRIimage *
|
||||
dri2_create_image_common(__DRIscreen *_screen,
|
||||
int width, int height,
|
||||
|
@ -1369,72 +1339,6 @@ dri2_from_planar(__DRIimage *image, int plane, void *loaderPrivate)
|
|||
return img;
|
||||
}
|
||||
|
||||
static __DRIimage *
|
||||
dri2_create_from_texture(__DRIcontext *context, int target, unsigned texture,
|
||||
int depth, int level, unsigned *error,
|
||||
void *loaderPrivate)
|
||||
{
|
||||
__DRIimage *img;
|
||||
struct gl_context *ctx = ((struct st_context *)dri_context(context)->st)->ctx;
|
||||
struct gl_texture_object *obj;
|
||||
struct pipe_resource *tex;
|
||||
GLuint face = 0;
|
||||
|
||||
obj = _mesa_lookup_texture(ctx, texture);
|
||||
if (!obj || obj->Target != target) {
|
||||
*error = __DRI_IMAGE_ERROR_BAD_PARAMETER;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tex = st_get_texobj_resource(obj);
|
||||
if (!tex) {
|
||||
*error = __DRI_IMAGE_ERROR_BAD_PARAMETER;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (target == GL_TEXTURE_CUBE_MAP)
|
||||
face = depth;
|
||||
|
||||
_mesa_test_texobj_completeness(ctx, obj);
|
||||
if (!obj->_BaseComplete || (level > 0 && !obj->_MipmapComplete)) {
|
||||
*error = __DRI_IMAGE_ERROR_BAD_PARAMETER;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (level < obj->BaseLevel || level > obj->_MaxLevel) {
|
||||
*error = __DRI_IMAGE_ERROR_BAD_MATCH;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (target == GL_TEXTURE_3D && obj->Image[face][level]->Depth < depth) {
|
||||
*error = __DRI_IMAGE_ERROR_BAD_MATCH;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
img = CALLOC_STRUCT(__DRIimageRec);
|
||||
if (!img) {
|
||||
*error = __DRI_IMAGE_ERROR_BAD_ALLOC;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
img->level = level;
|
||||
img->layer = depth;
|
||||
img->dri_format = driGLFormatToImageFormat(obj->Image[face][level]->TexFormat);
|
||||
|
||||
img->loader_private = loaderPrivate;
|
||||
|
||||
if (img->dri_format == __DRI_IMAGE_FORMAT_NONE) {
|
||||
*error = __DRI_IMAGE_ERROR_BAD_PARAMETER;
|
||||
free(img);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pipe_resource_reference(&img->texture, tex);
|
||||
|
||||
*error = __DRI_IMAGE_ERROR_SUCCESS;
|
||||
return img;
|
||||
}
|
||||
|
||||
static __DRIimage *
|
||||
dri2_from_fds(__DRIscreen *screen, int width, int height, int fourcc,
|
||||
int *fds, int num_fds, int *strides, int *offsets,
|
||||
|
@ -1647,13 +1551,6 @@ dri2_unmap_image(__DRIcontext *context, __DRIimage *image, void *data)
|
|||
pipe_transfer_unmap(pipe, (struct pipe_transfer *)data);
|
||||
}
|
||||
|
||||
static void
|
||||
dri2_destroy_image(__DRIimage *img)
|
||||
{
|
||||
pipe_resource_reference(&img->texture, NULL);
|
||||
FREE(img);
|
||||
}
|
||||
|
||||
static int
|
||||
dri2_get_capabilities(__DRIscreen *_screen)
|
||||
{
|
||||
|
|
|
@ -23,9 +23,11 @@
|
|||
#include <dlfcn.h>
|
||||
#include "util/u_memory.h"
|
||||
#include "pipe/p_screen.h"
|
||||
#include "state_tracker/st_texture.h"
|
||||
#include "state_tracker/st_context.h"
|
||||
#include "main/texobj.h"
|
||||
|
||||
#include "dri_context.h"
|
||||
#include "dri_screen.h"
|
||||
#include "dri_helpers.h"
|
||||
|
||||
static bool
|
||||
dri2_is_opencl_interop_loaded_locked(struct dri_screen *screen)
|
||||
|
@ -228,4 +230,106 @@ const __DRI2fenceExtension dri2FenceExtension = {
|
|||
.get_fence_fd = dri2_get_fence_fd,
|
||||
};
|
||||
|
||||
__DRIimage *
|
||||
dri2_lookup_egl_image(struct dri_screen *screen, void *handle)
|
||||
{
|
||||
const __DRIimageLookupExtension *loader = screen->sPriv->dri2.image;
|
||||
__DRIimage *img;
|
||||
|
||||
if (!loader->lookupEGLImage)
|
||||
return NULL;
|
||||
|
||||
img = loader->lookupEGLImage(screen->sPriv,
|
||||
handle, screen->sPriv->loaderPrivate);
|
||||
|
||||
return img;
|
||||
}
|
||||
|
||||
__DRIimage *
|
||||
dri2_create_image_from_renderbuffer(__DRIcontext *context,
|
||||
int renderbuffer, void *loaderPrivate)
|
||||
{
|
||||
struct dri_context *ctx = dri_context(context);
|
||||
|
||||
if (!ctx->st->get_resource_for_egl_image)
|
||||
return NULL;
|
||||
|
||||
/* TODO */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
dri2_destroy_image(__DRIimage *img)
|
||||
{
|
||||
pipe_resource_reference(&img->texture, NULL);
|
||||
FREE(img);
|
||||
}
|
||||
|
||||
|
||||
__DRIimage *
|
||||
dri2_create_from_texture(__DRIcontext *context, int target, unsigned texture,
|
||||
int depth, int level, unsigned *error,
|
||||
void *loaderPrivate)
|
||||
{
|
||||
__DRIimage *img;
|
||||
struct gl_context *ctx = ((struct st_context *)dri_context(context)->st)->ctx;
|
||||
struct gl_texture_object *obj;
|
||||
struct pipe_resource *tex;
|
||||
GLuint face = 0;
|
||||
|
||||
obj = _mesa_lookup_texture(ctx, texture);
|
||||
if (!obj || obj->Target != target) {
|
||||
*error = __DRI_IMAGE_ERROR_BAD_PARAMETER;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tex = st_get_texobj_resource(obj);
|
||||
if (!tex) {
|
||||
*error = __DRI_IMAGE_ERROR_BAD_PARAMETER;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (target == GL_TEXTURE_CUBE_MAP)
|
||||
face = depth;
|
||||
|
||||
_mesa_test_texobj_completeness(ctx, obj);
|
||||
if (!obj->_BaseComplete || (level > 0 && !obj->_MipmapComplete)) {
|
||||
*error = __DRI_IMAGE_ERROR_BAD_PARAMETER;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (level < obj->BaseLevel || level > obj->_MaxLevel) {
|
||||
*error = __DRI_IMAGE_ERROR_BAD_MATCH;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (target == GL_TEXTURE_3D && obj->Image[face][level]->Depth < depth) {
|
||||
*error = __DRI_IMAGE_ERROR_BAD_MATCH;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
img = CALLOC_STRUCT(__DRIimageRec);
|
||||
if (!img) {
|
||||
*error = __DRI_IMAGE_ERROR_BAD_ALLOC;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
img->level = level;
|
||||
img->layer = depth;
|
||||
img->dri_format = driGLFormatToImageFormat(obj->Image[face][level]->TexFormat);
|
||||
|
||||
img->loader_private = loaderPrivate;
|
||||
|
||||
if (img->dri_format == __DRI_IMAGE_FORMAT_NONE) {
|
||||
*error = __DRI_IMAGE_ERROR_BAD_PARAMETER;
|
||||
free(img);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pipe_resource_reference(&img->texture, tex);
|
||||
|
||||
*error = __DRI_IMAGE_ERROR_SUCCESS;
|
||||
return img;
|
||||
}
|
||||
|
||||
/* vim: set sw=3 ts=8 sts=3 expandtab: */
|
||||
|
|
|
@ -23,8 +23,25 @@
|
|||
#ifndef DRI_HELPERS_H
|
||||
#define DRI_HELPERS_H
|
||||
|
||||
#include "dri_context.h"
|
||||
#include "dri_screen.h"
|
||||
|
||||
extern const __DRI2fenceExtension dri2FenceExtension;
|
||||
|
||||
__DRIimage *
|
||||
dri2_lookup_egl_image(struct dri_screen *screen, void *handle);
|
||||
|
||||
__DRIimage *
|
||||
dri2_create_image_from_renderbuffer(__DRIcontext *context,
|
||||
int renderbuffer, void *loaderPrivate);
|
||||
|
||||
void
|
||||
dri2_destroy_image(__DRIimage *img);
|
||||
|
||||
__DRIimage *
|
||||
dri2_create_from_texture(__DRIcontext *context, int target, unsigned texture,
|
||||
int depth, int level, unsigned *error,
|
||||
void *loaderPrivate);
|
||||
#endif
|
||||
|
||||
/* vim: set sw=3 ts=8 sts=3 expandtab: */
|
||||
|
|
Loading…
Reference in New Issue