diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c index db8b3a4f4ac..88cea224420 100644 --- a/src/mesa/main/teximage.c +++ b/src/mesa/main/teximage.c @@ -3543,14 +3543,33 @@ egl_image_target_texture(struct gl_context *ctx, texObj->External = GL_TRUE; + struct st_egl_image stimg; + bool native_supported; + if (!st_get_egl_image(ctx, image, PIPE_BIND_SAMPLER_VIEW, caller, + &stimg, &native_supported)) + return; + if (tex_storage) { - st_egl_image_target_tex_storage(ctx, target, texObj, texImage, - image); + /* EXT_EGL_image_storage + * If the EGL image was created using EGL_EXT_image_dma_buf_import, + * then the following applies: + * - must be GL_TEXTURE_2D or GL_TEXTURE_EXTERNAL_OES. + * Otherwise, the error INVALID_OPERATION is generated. + */ + if (stimg.imported_dmabuf && + (target == GL_TEXTURE_2D || target == GL_TEXTURE_EXTERNAL_OES)) { + _mesa_error(ctx, GL_INVALID_OPERATION, + "%s(texture is imported from dmabuf)", caller); + return; + } + st_bind_egl_image(ctx, texObj, texImage, &stimg, true, native_supported); } else { - st_egl_image_target_texture_2d(ctx, target, texObj, texImage, - image); + st_bind_egl_image(ctx, texObj, texImage, &stimg, + target != GL_TEXTURE_EXTERNAL_OES, native_supported); } + pipe_resource_reference(&stimg.texture, NULL); + _mesa_dirty_texobj(ctx, texObj); } diff --git a/src/mesa/state_tracker/st_cb_eglimage.c b/src/mesa/state_tracker/st_cb_eglimage.c index 34a177ad1c8..02567b07619 100644 --- a/src/mesa/state_tracker/st_cb_eglimage.c +++ b/src/mesa/state_tracker/st_cb_eglimage.c @@ -162,7 +162,7 @@ is_nv12_as_r8_g8b8_supported(struct pipe_screen *screen, struct st_egl_image *ou /** * Return the gallium texture of an EGLImage. */ -static bool +bool st_get_egl_image(struct gl_context *ctx, GLeglImageOES image_handle, unsigned usage, const char *error, struct st_egl_image *out, bool *native_supported) @@ -260,7 +260,7 @@ st_egl_image_target_renderbuffer_storage(struct gl_context *ctx, } } -static void +void st_bind_egl_image(struct gl_context *ctx, struct gl_texture_object *texObj, struct gl_texture_image *texImage, @@ -410,44 +410,6 @@ st_bind_egl_image(struct gl_context *ctx, _mesa_dirty_texobj(ctx, texObj); } -void -st_egl_image_target_texture_2d(struct gl_context *ctx, GLenum target, - struct gl_texture_object *texObj, - struct gl_texture_image *texImage, - GLeglImageOES image_handle) -{ - struct st_egl_image stimg; - bool native_supported; - - if (!st_get_egl_image(ctx, image_handle, PIPE_BIND_SAMPLER_VIEW, - "glEGLImageTargetTexture2D", &stimg, - &native_supported)) - return; - - st_bind_egl_image(ctx, texObj, texImage, &stimg, - target != GL_TEXTURE_EXTERNAL_OES, - native_supported); - pipe_resource_reference(&stimg.texture, NULL); -} - -void -st_egl_image_target_tex_storage(struct gl_context *ctx, GLenum target, - struct gl_texture_object *texObj, - struct gl_texture_image *texImage, - GLeglImageOES image_handle) -{ - struct st_egl_image stimg; - bool native_supported; - - if (!st_get_egl_image(ctx, image_handle, PIPE_BIND_SAMPLER_VIEW, - "glEGLImageTargetTexture2D", &stimg, - &native_supported)) - return; - - st_bind_egl_image(ctx, texObj, texImage, &stimg, true, native_supported); - pipe_resource_reference(&stimg.texture, NULL); -} - static GLboolean st_validate_egl_image(struct gl_context *ctx, GLeglImageOES image_handle) { diff --git a/src/mesa/state_tracker/st_cb_eglimage.h b/src/mesa/state_tracker/st_cb_eglimage.h index 4a28690f70e..379e6646303 100644 --- a/src/mesa/state_tracker/st_cb_eglimage.h +++ b/src/mesa/state_tracker/st_cb_eglimage.h @@ -35,14 +35,16 @@ extern void st_init_eglimage_functions(struct dd_function_table *functions, bool has_egl_image_validate); -void st_egl_image_target_texture_2d(struct gl_context *ctx, GLenum target, - struct gl_texture_object *texObj, - struct gl_texture_image *texImage, - GLeglImageOES image_handle); -void st_egl_image_target_tex_storage(struct gl_context *ctx, GLenum target, - struct gl_texture_object *texObj, - struct gl_texture_image *texImage, - GLeglImageOES image_handle); +bool st_get_egl_image(struct gl_context *ctx, GLeglImageOES image_handle, + unsigned usage, const char *error, + struct st_egl_image *out, bool *native_supported); +void st_bind_egl_image(struct gl_context *ctx, + struct gl_texture_object *texObj, + struct gl_texture_image *texImage, + struct st_egl_image *stimg, + bool tex_storage, + bool native_supported); + void st_egl_image_target_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *rb, GLeglImageOES image_handle);