OSDN Git Service

Discern between EGL image types.
authorNicolas Capens <capn@google.com>
Fri, 20 Nov 2015 16:16:34 +0000 (11:16 -0500)
committerNicolas Capens <capn@google.com>
Fri, 27 Nov 2015 21:57:25 +0000 (16:57 -0500)
EGL images can be created from an Android native buffer or a GL client
texture.

Bug 24517776

Change-Id: I3b77ec44ae9e630d7bb4aec87e2ec3957a2f3ab2

system/GLESv1/gl.cpp
system/GLESv2/gl2.cpp
system/OpenglSystemCommon/EGLImage.h [new file with mode: 0644]
system/egl/egl.cpp

index a7950eb..1e51e52 100644 (file)
@@ -22,6 +22,7 @@
 #include "ErrorLog.h"
 #include "gralloc_cb.h"
 #include "ThreadInfo.h"
+#include "EGLImage.h"
 
 
 //XXX: fix this macro to get the context from fast tls path
@@ -48,31 +49,41 @@ static EGLClient_glesInterface * s_gl = NULL;
     }
 
 //GL extensions
-void glEGLImageTargetTexture2DOES(void * self, GLenum target, GLeglImageOES image)
+void glEGLImageTargetTexture2DOES(void * self, GLenum target, GLeglImageOES img)
 {
     (void)self;
 
-    DBG("glEGLImageTargetTexture2DOES v1 target=%#x image=%p", target, image);
-    //TODO: check error - we don't have a way to set gl error
-    android_native_buffer_t* native_buffer = (android_native_buffer_t*)image;
+    DBG("glEGLImageTargetTexture2DOES v1 target=%#x img=%p", target, img);
+    
+    EGLImage_t *image = (EGLImage_t*)img;
+
+    if (image->target == EGL_NATIVE_BUFFER_ANDROID) {
+        //TODO: check error - we don't have a way to set gl error
+        android_native_buffer_t* native_buffer = image->native_buffer;
+
+        if (native_buffer->common.magic != ANDROID_NATIVE_BUFFER_MAGIC) {
+            return;
+        }
+
+        if (native_buffer->common.version != sizeof(android_native_buffer_t)) {
+            return;
+        }
+
+        GET_CONTEXT;
+        DEFINE_AND_VALIDATE_HOST_CONNECTION();
+
+        ctx->override2DTextureTarget(target);
+        rcEnc->rcBindTexture(rcEnc,
+                ((cb_handle_t *)(native_buffer->handle))->hostHandle);
+        ctx->restore2DTextureTarget();
 
-    if (native_buffer->common.magic != ANDROID_NATIVE_BUFFER_MAGIC) {
         return;
     }
+    else if (image->target == EGL_GL_TEXTURE_2D_KHR) {
+        // TODO
 
-    if (native_buffer->common.version != sizeof(android_native_buffer_t)) {
         return;
     }
-
-    GET_CONTEXT;
-    DEFINE_AND_VALIDATE_HOST_CONNECTION();
-
-    ctx->override2DTextureTarget(target);
-    rcEnc->rcBindTexture(rcEnc,
-            ((cb_handle_t *)(native_buffer->handle))->hostHandle);
-    ctx->restore2DTextureTarget();
-
-    return;
 }
 
 void glEGLImageTargetRenderbufferStorageOES(void *self, GLenum target, GLeglImageOES image)
index e545779..836c824 100644 (file)
@@ -22,6 +22,7 @@
 #include "ErrorLog.h"
 #include "gralloc_cb.h"
 #include "ThreadInfo.h"
+#include "EGLImage.h"
 
 //XXX: fix this macro to get the context from fast tls path
 #define GET_CONTEXT GL2Encoder * ctx = getEGLThreadInfo()->hostConn->gl2Encoder();
@@ -48,31 +49,41 @@ static EGLClient_glesInterface * s_gl = NULL;
     }
 
 //GL extensions
-void glEGLImageTargetTexture2DOES(void * self, GLenum target, GLeglImageOES image)
+void glEGLImageTargetTexture2DOES(void * self, GLenum target, GLeglImageOES img)
 {
     (void)self;
     (void)target;
 
-    DBG("glEGLImageTargetTexture2DOES v2 target=%#x img=%p\n", target, image);
-    //TODO: check error - we don't have a way to set gl error
-    android_native_buffer_t* native_buffer = (android_native_buffer_t*)image;
+    DBG("glEGLImageTargetTexture2DOES v2 target=%#x img=%p\n", target, img);
+
+    EGLImage_t *image = (EGLImage_t*)img;
+
+    if (image->target == EGL_NATIVE_BUFFER_ANDROID) {
+        //TODO: check error - we don't have a way to set gl error
+        android_native_buffer_t* native_buffer = image->native_buffer;
+
+        if (native_buffer->common.magic != ANDROID_NATIVE_BUFFER_MAGIC) {
+            return;
+        }
+
+        if (native_buffer->common.version != sizeof(android_native_buffer_t)) {
+            return;
+        }
+
+        GET_CONTEXT;
+        DEFINE_AND_VALIDATE_HOST_CONNECTION();
+
+        ctx->override2DTextureTarget(target);
+        rcEnc->rcBindTexture(rcEnc, ((cb_handle_t *)(native_buffer->handle))->hostHandle);
+        ctx->restore2DTextureTarget();
 
-    if (native_buffer->common.magic != ANDROID_NATIVE_BUFFER_MAGIC) {
         return;
     }
+    else if (image->target == EGL_GL_TEXTURE_2D_KHR) {
+        // TODO
 
-    if (native_buffer->common.version != sizeof(android_native_buffer_t)) {
         return;
     }
-
-    GET_CONTEXT;
-    DEFINE_AND_VALIDATE_HOST_CONNECTION();
-
-    ctx->override2DTextureTarget(target);
-    rcEnc->rcBindTexture(rcEnc, ((cb_handle_t *)(native_buffer->handle))->hostHandle);
-    ctx->restore2DTextureTarget();
-
-    return;
 }
 
 void glEGLImageTargetRenderbufferStorageOES(void *self, GLenum target, GLeglImageOES image)
diff --git a/system/OpenglSystemCommon/EGLImage.h b/system/OpenglSystemCommon/EGLImage.h
new file mode 100644 (file)
index 0000000..5edb44e
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+* Copyright (C) 2015 The Android Open Source Project
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+#ifndef __COMMON_EGL_IMAGE_H
+#define __COMMON_EGL_IMAGE_H
+
+#include <EGL/egl.h>
+#include <EGL/eglext.h>
+#include <GLES/gl.h>
+#include <system/window.h>
+
+struct EGLImage_t
+{
+    EGLDisplay dpy;
+    EGLenum target;
+
+    union
+    {
+        android_native_buffer_t *native_buffer;
+        uint32_t host_egl_image;
+    };
+};
+
+#endif
index a9f6cf7..f6c510d 100644 (file)
@@ -24,6 +24,7 @@
 #include "GLSharedGroup.h"
 #include "eglContext.h"
 #include "ClientAPIExts.h"
+#include "EGLImage.h"
 
 #include "GLEncoder.h"
 #ifdef WITH_GLES2
@@ -1187,52 +1188,90 @@ EGLImageKHR eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, EG
     (void)attrib_list;
 
     VALIDATE_DISPLAY_INIT(dpy, EGL_NO_IMAGE_KHR);
-    if (ctx != EGL_NO_CONTEXT) {
-        setErrorReturn(EGL_BAD_CONTEXT, EGL_NO_IMAGE_KHR);
-    }
-    if (target != EGL_NATIVE_BUFFER_ANDROID) {
-        setErrorReturn(EGL_BAD_PARAMETER, EGL_NO_IMAGE_KHR);
-    }
 
-    android_native_buffer_t* native_buffer = (android_native_buffer_t*)buffer;
-
-    if (native_buffer->common.magic != ANDROID_NATIVE_BUFFER_MAGIC)
-        setErrorReturn(EGL_BAD_PARAMETER, EGL_NO_IMAGE_KHR);
+    if (target == EGL_NATIVE_BUFFER_ANDROID) {
+        if (ctx != EGL_NO_CONTEXT) {
+            setErrorReturn(EGL_BAD_CONTEXT, EGL_NO_IMAGE_KHR);
+        }
 
-    if (native_buffer->common.version != sizeof(android_native_buffer_t))
-        setErrorReturn(EGL_BAD_PARAMETER, EGL_NO_IMAGE_KHR);
+        android_native_buffer_t* native_buffer = (android_native_buffer_t*)buffer;
 
-    cb_handle_t *cb = (cb_handle_t *)(native_buffer->handle);
+        if (native_buffer->common.magic != ANDROID_NATIVE_BUFFER_MAGIC)
+            setErrorReturn(EGL_BAD_PARAMETER, EGL_NO_IMAGE_KHR);
 
-    switch (cb->format) {
-        case HAL_PIXEL_FORMAT_RGBA_8888:
-        case HAL_PIXEL_FORMAT_RGBX_8888:
-        case HAL_PIXEL_FORMAT_RGB_888:
-        case HAL_PIXEL_FORMAT_RGB_565:
-        case HAL_PIXEL_FORMAT_BGRA_8888:
-            break;
-        default:
+        if (native_buffer->common.version != sizeof(android_native_buffer_t))
             setErrorReturn(EGL_BAD_PARAMETER, EGL_NO_IMAGE_KHR);
+
+        cb_handle_t *cb = (cb_handle_t *)(native_buffer->handle);
+
+        switch (cb->format) {
+            case HAL_PIXEL_FORMAT_RGBA_8888:
+            case HAL_PIXEL_FORMAT_RGBX_8888:
+            case HAL_PIXEL_FORMAT_RGB_888:
+            case HAL_PIXEL_FORMAT_RGB_565:
+            case HAL_PIXEL_FORMAT_BGRA_8888:
+                break;
+            default:
+                setErrorReturn(EGL_BAD_PARAMETER, EGL_NO_IMAGE_KHR);
+        }
+
+        native_buffer->common.incRef(&native_buffer->common);
+
+        EGLImage_t *image = new EGLImage_t();
+        image->dpy = dpy;
+        image->target = target;
+        image->native_buffer = native_buffer;
+
+        return (EGLImageKHR)image;
     }
+    else if (target == EGL_GL_TEXTURE_2D_KHR) {
+        setErrorReturn(EGL_BAD_CONTEXT, EGL_NO_IMAGE_KHR);   // TODO
+
+        VALIDATE_CONTEXT_RETURN(ctx, EGL_NO_IMAGE_KHR);
 
-    native_buffer->common.incRef(&native_buffer->common);
-    return (EGLImageKHR)native_buffer;
+        EGLImage_t *image = new EGLImage_t();
+        image->dpy = dpy;
+        image->target = target;
+        image->texture_2d = 0;   // TODO
+
+        return (EGLImageKHR)image;
+    }
+    
+    setErrorReturn(EGL_BAD_PARAMETER, EGL_NO_IMAGE_KHR);
 }
 
 EGLBoolean eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR img)
 {
     VALIDATE_DISPLAY_INIT(dpy, EGL_FALSE);
-    android_native_buffer_t* native_buffer = (android_native_buffer_t*)img;
+    EGLImage_t *image = (EGLImage_t*)img;
 
-    if (native_buffer->common.magic != ANDROID_NATIVE_BUFFER_MAGIC)
-        setErrorReturn(EGL_BAD_PARAMETER, EGL_FALSE);
+    if (!image || image->dpy != dpy) {
+        RETURN_ERROR(EGL_FALSE, EGL_BAD_PARAMETER);
+    }
 
-    if (native_buffer->common.version != sizeof(android_native_buffer_t))
-        setErrorReturn(EGL_BAD_PARAMETER, EGL_FALSE);
+    if (image->target == EGL_NATIVE_BUFFER_ANDROID) {
+        android_native_buffer_t* native_buffer = image->native_buffer;
 
-    native_buffer->common.decRef(&native_buffer->common);
+        if (native_buffer->common.magic != ANDROID_NATIVE_BUFFER_MAGIC)
+            setErrorReturn(EGL_BAD_PARAMETER, EGL_FALSE);
 
-    return EGL_TRUE;
+        if (native_buffer->common.version != sizeof(android_native_buffer_t))
+            setErrorReturn(EGL_BAD_PARAMETER, EGL_FALSE);
+
+        native_buffer->common.decRef(&native_buffer->common);
+        delete image;
+
+        return EGL_TRUE;
+    }
+    else if (image->target == EGL_GL_TEXTURE_2D_KHR) {
+        // TODO
+
+        delete image;
+
+        return EGL_TRUE;
+    }
+
+    setErrorReturn(EGL_BAD_PARAMETER, EGL_FALSE);
 }
 
 #define FENCE_SYNC_HANDLE (EGLSyncKHR)0xFE4CE