From d7855ee3323e8493f139af70db9d0cdb853c2a08 Mon Sep 17 00:00:00 2001 From: Johann Rudloff Date: Mon, 8 Nov 2010 18:55:42 -0500 Subject: radeon: Implement GL_OES_EGL_image agd5f: add support to radeon/r200/r300 as well --- src/mesa/drivers/dri/radeon/radeon_context.c | 4 ++ src/mesa/drivers/dri/radeon/radeon_fbo.c | 46 ++++++++++++++++++++ src/mesa/drivers/dri/radeon/radeon_tex.c | 4 ++ src/mesa/drivers/dri/radeon/radeon_texture.c | 64 ++++++++++++++++++++++++++++ src/mesa/drivers/dri/radeon/radeon_texture.h | 7 +++ 5 files changed, 125 insertions(+) (limited to 'src/mesa/drivers/dri/radeon') diff --git a/src/mesa/drivers/dri/radeon/radeon_context.c b/src/mesa/drivers/dri/radeon/radeon_context.c index cc9590213c..e3de534b5f 100644 --- a/src/mesa/drivers/dri/radeon/radeon_context.c +++ b/src/mesa/drivers/dri/radeon/radeon_context.c @@ -66,6 +66,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define need_GL_EXT_fog_coord #define need_GL_EXT_secondary_color #define need_GL_EXT_framebuffer_object +#define need_GL_OES_EGL_image #include "main/remap_helper.h" #define DRIVER_DATE "20061018" @@ -101,6 +102,9 @@ static const struct dri_extension card_extensions[] = { "GL_ATI_texture_mirror_once", NULL }, { "GL_MESA_ycbcr_texture", NULL }, { "GL_NV_blend_square", NULL }, +#if FEATURE_OES_EGL_image + { "GL_OES_EGL_image", GL_OES_EGL_image_functions }, +#endif { NULL, NULL } }; diff --git a/src/mesa/drivers/dri/radeon/radeon_fbo.c b/src/mesa/drivers/dri/radeon/radeon_fbo.c index 2a6fbaeaf0..a36a1dc94a 100644 --- a/src/mesa/drivers/dri/radeon/radeon_fbo.c +++ b/src/mesa/drivers/dri/radeon/radeon_fbo.c @@ -199,6 +199,48 @@ radeon_alloc_renderbuffer_storage(struct gl_context * ctx, struct gl_renderbuffe } +#if FEATURE_OES_EGL_image +static void +radeon_image_target_renderbuffer_storage(struct gl_context *ctx, + struct gl_renderbuffer *rb, + void *image_handle) +{ + radeonContextPtr radeon = RADEON_CONTEXT(ctx); + struct radeon_renderbuffer *rrb; + __DRIscreen *screen; + __DRIimage *image; + + screen = radeon->radeonScreen->driScreen; + image = screen->dri2.image->lookupEGLImage(screen, image_handle, + screen->loaderPrivate); + if (image == NULL) + return; + + rrb = radeon_renderbuffer(rb); + + if (ctx->Driver.Flush) + ctx->Driver.Flush(ctx); /* +r6/r7 */ + + if (rrb->bo) + radeon_bo_unref(rrb->bo); + rrb->bo = image->bo; + radeon_bo_ref(rrb->bo); + fprintf(stderr, "image->bo: %p, name: %d, rbs: w %d -> p %d\n", image->bo, image->bo->handle, + image->width, image->pitch); + + rrb->cpp = image->cpp; + rrb->pitch = image->pitch * image->cpp; + + rb->Format = image->format; + rb->InternalFormat = image->internal_format; + rb->Width = image->width; + rb->Height = image->height; + rb->Format = image->format; + rb->DataType = image->data_type; + rb->_BaseFormat = _mesa_base_fbo_format(radeon->glCtx, + image->internal_format); +} +#endif /** * Called for each hardware renderbuffer when a _window_ is resized. @@ -622,6 +664,10 @@ void radeon_fbo_init(struct radeon_context *radeon) #if FEATURE_EXT_framebuffer_blit radeon->glCtx->Driver.BlitFramebuffer = _mesa_meta_BlitFramebuffer; #endif +#if FEATURE_OES_EGL_image + radeon->glCtx->Driver.EGLImageTargetRenderbufferStorage = + radeon_image_target_renderbuffer_storage; +#endif } diff --git a/src/mesa/drivers/dri/radeon/radeon_tex.c b/src/mesa/drivers/dri/radeon/radeon_tex.c index d5285e24cd..83b1d1b1d7 100644 --- a/src/mesa/drivers/dri/radeon/radeon_tex.c +++ b/src/mesa/drivers/dri/radeon/radeon_tex.c @@ -465,5 +465,9 @@ void radeonInitTextureFuncs( radeonContextPtr radeon, struct dd_function_table * functions->MapTexture = radeonMapTexture; functions->UnmapTexture = radeonUnmapTexture; +#if FEATURE_OES_EGL_image + functions->EGLImageTargetTexture2D = radeon_image_target_texture_2d; +#endif + driInitTextureFormats(); } diff --git a/src/mesa/drivers/dri/radeon/radeon_texture.c b/src/mesa/drivers/dri/radeon/radeon_texture.c index 18ccb512d7..8b1e34fe76 100644 --- a/src/mesa/drivers/dri/radeon/radeon_texture.c +++ b/src/mesa/drivers/dri/radeon/radeon_texture.c @@ -1007,3 +1007,67 @@ unsigned radeonIsFormatRenderable(gl_format mesa_format) return 0; } } + +#if FEATURE_OES_EGL_image +void radeon_image_target_texture_2d(struct gl_context *ctx, GLenum target, + struct gl_texture_object *texObj, + struct gl_texture_image *texImage, + GLeglImageOES image_handle) +{ + radeonContextPtr radeon = RADEON_CONTEXT(ctx); + radeonTexObj *t = radeon_tex_obj(texObj); + radeon_texture_image *radeonImage = get_radeon_texture_image(texImage); + __DRIscreen *screen; + __DRIimage *image; + + screen = radeon->dri.screen; + image = screen->dri2.image->lookupEGLImage(screen, image_handle, + screen->loaderPrivate); + if (image == NULL) + return; + + radeonFreeTexImageData(ctx, texImage); + + texImage->Width = image->width; + texImage->Height = image->height; + texImage->Depth = 1; + texImage->_BaseFormat = GL_RGBA; + texImage->TexFormat = image->format; + texImage->RowStride = image->pitch; + texImage->InternalFormat = image->internal_format; + + if(t->mt) + { + radeon_miptree_unreference(&t->mt); + t->mt = NULL; + } + + /* NOTE: The following is *very* ugly and will probably break. But + I don't know how to deal with it, without creating a whole new + function like radeon_miptree_from_bo() so I'm going with the + easy but error-prone way. */ + + radeon_try_alloc_miptree(radeon, t); + + radeonImage->mtface = _mesa_tex_target_to_face(target); + radeonImage->mtlevel = 0; + radeon_miptree_reference(t->mt, &radeonImage->mt); + + if (t->mt == NULL) + { + radeon_print(RADEON_TEXTURE, RADEON_VERBOSE, + "%s Failed to allocate miptree.\n", __func__); + return; + } + + /* Particularly ugly: this is guaranteed to break, if image->bo is + not of the required size for a miptree. */ + radeon_bo_unref(t->mt->bo); + radeon_bo_ref(image->bo); + t->mt->bo = image->bo; + + if (!radeon_miptree_matches_image(t->mt, &radeonImage->base, + radeonImage->mtface, 0)) + fprintf(stderr, "miptree doesn't match image\n"); +} +#endif diff --git a/src/mesa/drivers/dri/radeon/radeon_texture.h b/src/mesa/drivers/dri/radeon/radeon_texture.h index 9138a7d554..a1908c6bc7 100644 --- a/src/mesa/drivers/dri/radeon/radeon_texture.h +++ b/src/mesa/drivers/dri/radeon/radeon_texture.h @@ -137,4 +137,11 @@ void radeonCopyTexSubImage2D(struct gl_context *ctx, GLenum target, GLint level, unsigned radeonIsFormatRenderable(gl_format mesa_format); +#if FEATURE_OES_EGL_image +void radeon_image_target_texture_2d(struct gl_context *ctx, GLenum target, + struct gl_texture_object *texObj, + struct gl_texture_image *texImage, + GLeglImageOES image_handle); +#endif + #endif -- cgit v1.2.3