radeon: Implement GL_OES_EGL_image
authorJohann Rudloff <cypheon@googlemail.com>
Mon, 8 Nov 2010 23:55:42 +0000 (18:55 -0500)
committerAlex Deucher <alexdeucher@gmail.com>
Tue, 9 Nov 2010 00:59:53 +0000 (19:59 -0500)
agd5f: add support to radeon/r200/r300 as well

src/mesa/drivers/dri/r200/r200_context.c
src/mesa/drivers/dri/r200/r200_tex.c
src/mesa/drivers/dri/r300/r300_context.c
src/mesa/drivers/dri/r300/r300_tex.c
src/mesa/drivers/dri/r600/r600_context.c
src/mesa/drivers/dri/r600/r600_tex.c
src/mesa/drivers/dri/radeon/radeon_context.c
src/mesa/drivers/dri/radeon/radeon_fbo.c
src/mesa/drivers/dri/radeon/radeon_tex.c
src/mesa/drivers/dri/radeon/radeon_texture.c
src/mesa/drivers/dri/radeon/radeon_texture.h

index 723e31401ded900eecca9f83eccabe0244fd65ad..5abfc9dac51b895fb6a2745562ada16d68bf9677 100644 (file)
@@ -71,6 +71,8 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #define need_GL_NV_vertex_program
 #define need_GL_ARB_point_parameters
 #define need_GL_EXT_framebuffer_object
+#define need_GL_OES_EGL_image
+
 #include "main/remap_helper.h"
 
 #define DRIVER_DATE    "20060602"
@@ -137,6 +139,9 @@ static const struct dri_extension card_extensions[] =
     { "GL_ATI_texture_mirror_once",        NULL },
     { "GL_MESA_pack_invert",               NULL },
     { "GL_NV_blend_square",                NULL },
+#if FEATURE_OES_EGL_image
+    { "GL_OES_EGL_image",                  GL_OES_EGL_image_functions },
+#endif
     { NULL,                                NULL }
 };
 
index 5207c2901a3969c63535eadc070869f8c647f571..064324731b5e27a1db5eff2e379f59a623638e0e 100644 (file)
@@ -537,6 +537,10 @@ void r200InitTextureFuncs( radeonContextPtr radeon, struct dd_function_table *fu
    functions->MapTexture = radeonMapTexture;
    functions->UnmapTexture = radeonUnmapTexture;
 
+#if FEATURE_OES_EGL_image
+   functions->EGLImageTargetTexture2D = radeon_image_target_texture_2d;
+#endif
+
    driInitTextureFormats();
 
 }
index 9fbd36bfe63a02f20545763b25ad8f8e14e50e00..c288834d24349b0d52fa9daa66742affae6a359e 100644 (file)
@@ -86,6 +86,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #define need_GL_EXT_stencil_two_side
 #define need_GL_ATI_separate_stencil
 #define need_GL_NV_vertex_program
+#define need_GL_OES_EGL_image
 
 #include "main/remap_helper.h"
 
@@ -134,6 +135,9 @@ static const struct dri_extension card_extensions[] = {
   {"GL_MESAX_texture_float",           NULL},
   {"GL_NV_blend_square",               NULL},
   {"GL_NV_vertex_program",             GL_NV_vertex_program_functions},
+#if FEATURE_OES_EGL_image
+  {"GL_OES_EGL_image",                  GL_OES_EGL_image_functions },
+#endif
   {NULL,                               NULL}
   /* *INDENT-ON* */
 };
index a6bda0e49901b2f4d7fbcfc639936e429f74bffb..de662939992f9e46a8df3fb68783428604dd62b3 100644 (file)
@@ -382,5 +382,9 @@ void r300InitTextureFuncs(radeonContextPtr radeon, struct dd_function_table *fun
 
        functions->GenerateMipmap = radeonGenerateMipmap;
 
+#if FEATURE_OES_EGL_image
+       functions->EGLImageTargetTexture2D = radeon_image_target_texture_2d;
+#endif
+
        driInitTextureFormats();
 }
index c882a9cce9e6be57b07be23c49e391ba0d346a52..b6443bf0c535153b5335154f729448157e74074d 100644 (file)
@@ -94,6 +94,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #define need_GL_EXT_stencil_two_side
 #define need_GL_ATI_separate_stencil
 #define need_GL_NV_vertex_program
+#define need_GL_OES_EGL_image
 
 #include "main/remap_helper.h"
 
@@ -148,6 +149,9 @@ static const struct dri_extension card_extensions[] = {
   {"GL_NV_vertex_program",             GL_NV_vertex_program_functions},
   {"GL_ARB_pixel_buffer_object",        NULL},
   {"GL_ARB_draw_elements_base_vertex", GL_ARB_draw_elements_base_vertex_functions },
+#if FEATURE_OES_EGL_image
+  {"GL_OES_EGL_image",                 GL_OES_EGL_image_functions},
+#endif
   {NULL,                               NULL}
   /* *INDENT-ON* */
 };
index d6a58f410cccc3d44816cff0775a8bdf8d275e82..c3d68c41e573458a5ebb4c99848e617f8adb15ec 100644 (file)
@@ -475,5 +475,9 @@ void r600InitTextureFuncs(radeonContextPtr radeon, struct dd_function_table *fun
 
        functions->GenerateMipmap = radeonGenerateMipmap;
 
+#if FEATURE_OES_EGL_image
+       functions->EGLImageTargetTexture2D = radeon_image_target_texture_2d;
+#endif
+
        driInitTextureFormats();
 }
index cc9590213c4bc802f00e569bc165ec82f5a085b1..e3de534b5f73e4bcada012dc57cfe7d87a153f0e 100644 (file)
@@ -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 }
 };
 
index 2a6fbaeaf090b68f169a900e6685f93c71571ffa..a36a1dc94ac40fa7ae0a6dc82c299a515b8c0300 100644 (file)
@@ -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
 }
 
   
index d5285e24cd54b50b232b16666a945205d6aec267..83b1d1b1d74bd0729f198d01cc7f78b52b26a4e8 100644 (file)
@@ -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();
 }
index 18ccb512d7a776ca6ee3ccd7113c17f266bc75b9..8b1e34fe7669cdb122359654fc1d579e8545225d 100644 (file)
@@ -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
index 9138a7d554878d6bdcdd650065c53118764c5d0a..a1908c6bc72bc6ea5f5398705ae357290e01c56f 100644 (file)
@@ -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