OSDN Git Service

opengl: rcOpenColorBuffer must be synchronous
authorJesse Hall <jessehall@google.com>
Tue, 27 May 2014 16:25:24 +0000 (09:25 -0700)
committerJesse Hall <jessehall@google.com>
Tue, 27 May 2014 18:33:21 +0000 (11:33 -0700)
The gralloc register_buffer() function, which calls rcOpenColorBuffer,
must actually increment the reference count before returning.
Otherwise the buffer allocator may release its reference before the
client has obtained one, and the buffer will be freed prematurely.
Since rcOpenColorBuffer was just sending a message to the host without
waiting for it to be received/processed, this guarantee was not met.
Adding a return value makes the call synchronous.

Bug: 12988668
Change-Id: I8b2399cfb0f600f99b3387f630343291b59bc9a6

system/gralloc/gralloc.cpp
system/renderControl_enc/renderControl_client_context.cpp
system/renderControl_enc/renderControl_client_context.h
system/renderControl_enc/renderControl_client_proc.h
system/renderControl_enc/renderControl_enc.cpp
system/renderControl_enc/renderControl_enc.h
system/renderControl_enc/renderControl_entry.cpp
system/renderControl_enc/renderControl_ftable.h
system/renderControl_enc/renderControl_opcodes.h

index 6250a2f..c13a98d 100644 (file)
@@ -535,7 +535,7 @@ static int gralloc_register_buffer(gralloc_module_t const* module,
     if (cb->hostHandle != 0) {
         DEFINE_AND_VALIDATE_HOST_CONNECTION;
         D("Opening host ColorBuffer 0x%x\n", cb->hostHandle);
-        rcEnc->rcOpenColorBuffer(rcEnc, cb->hostHandle);
+        rcEnc->rcOpenColorBuffer2(rcEnc, cb->hostHandle);
     }
 
     //
index 9488248..a4bdb25 100644 (file)
@@ -37,6 +37,7 @@ int renderControl_client_context_t::initDispatchByName(void *(*getProc)(const ch
        ptr = getProc("rcColorBufferCacheFlush", userData); set_rcColorBufferCacheFlush((rcColorBufferCacheFlush_client_proc_t)ptr);
        ptr = getProc("rcReadColorBuffer", userData); set_rcReadColorBuffer((rcReadColorBuffer_client_proc_t)ptr);
        ptr = getProc("rcUpdateColorBuffer", userData); set_rcUpdateColorBuffer((rcUpdateColorBuffer_client_proc_t)ptr);
+       ptr = getProc("rcOpenColorBuffer2", userData); set_rcOpenColorBuffer2((rcOpenColorBuffer2_client_proc_t)ptr);
        return 0;
 }
 
index ed2b1fb..46a007f 100644 (file)
@@ -33,6 +33,7 @@ struct renderControl_client_context_t {
        rcColorBufferCacheFlush_client_proc_t rcColorBufferCacheFlush;
        rcReadColorBuffer_client_proc_t rcReadColorBuffer;
        rcUpdateColorBuffer_client_proc_t rcUpdateColorBuffer;
+       rcOpenColorBuffer2_client_proc_t rcOpenColorBuffer2;
        //Accessors 
        virtual rcGetRendererVersion_client_proc_t set_rcGetRendererVersion(rcGetRendererVersion_client_proc_t f) { rcGetRendererVersion_client_proc_t retval = rcGetRendererVersion; rcGetRendererVersion = f; return retval;}
        virtual rcGetEGLVersion_client_proc_t set_rcGetEGLVersion(rcGetEGLVersion_client_proc_t f) { rcGetEGLVersion_client_proc_t retval = rcGetEGLVersion; rcGetEGLVersion = f; return retval;}
@@ -59,6 +60,7 @@ struct renderControl_client_context_t {
        virtual rcColorBufferCacheFlush_client_proc_t set_rcColorBufferCacheFlush(rcColorBufferCacheFlush_client_proc_t f) { rcColorBufferCacheFlush_client_proc_t retval = rcColorBufferCacheFlush; rcColorBufferCacheFlush = f; return retval;}
        virtual rcReadColorBuffer_client_proc_t set_rcReadColorBuffer(rcReadColorBuffer_client_proc_t f) { rcReadColorBuffer_client_proc_t retval = rcReadColorBuffer; rcReadColorBuffer = f; return retval;}
        virtual rcUpdateColorBuffer_client_proc_t set_rcUpdateColorBuffer(rcUpdateColorBuffer_client_proc_t f) { rcUpdateColorBuffer_client_proc_t retval = rcUpdateColorBuffer; rcUpdateColorBuffer = f; return retval;}
+       virtual rcOpenColorBuffer2_client_proc_t set_rcOpenColorBuffer2(rcOpenColorBuffer2_client_proc_t f) { rcOpenColorBuffer2_client_proc_t retval = rcOpenColorBuffer2; rcOpenColorBuffer2 = f; return retval;}
         virtual ~renderControl_client_context_t() {}
 
        typedef renderControl_client_context_t *CONTEXT_ACCESSOR_TYPE(void);
index 3e00290..85200cf 100644 (file)
@@ -34,6 +34,7 @@ typedef void (renderControl_APIENTRY *rcBindRenderbuffer_client_proc_t) (void *
 typedef EGLint (renderControl_APIENTRY *rcColorBufferCacheFlush_client_proc_t) (void * ctx, uint32_t, EGLint, int);
 typedef void (renderControl_APIENTRY *rcReadColorBuffer_client_proc_t) (void * ctx, uint32_t, GLint, GLint, GLint, GLint, GLenum, GLenum, void*);
 typedef int (renderControl_APIENTRY *rcUpdateColorBuffer_client_proc_t) (void * ctx, uint32_t, GLint, GLint, GLint, GLint, GLenum, GLenum, void*);
+typedef int (renderControl_APIENTRY *rcOpenColorBuffer2_client_proc_t) (void * ctx, uint32_t);
 
 
 #endif
index 41f59d0..a40a501 100644 (file)
@@ -505,6 +505,25 @@ int rcUpdateColorBuffer_enc(void *self , uint32_t colorbuffer, GLint x, GLint y,
        return retval;
 }
 
+int rcOpenColorBuffer2_enc(void *self , uint32_t colorbuffer)
+{
+
+       renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self;
+       IOStream *stream = ctx->m_stream;
+
+        unsigned char *ptr;
+        const size_t packetSize = 8 + 4;
+       ptr = stream->alloc(packetSize);
+       int tmp = OP_rcOpenColorBuffer2;memcpy(ptr, &tmp, 4); ptr += 4;
+       memcpy(ptr, &packetSize, 4);  ptr += 4;
+
+               memcpy(ptr, &colorbuffer, 4); ptr += 4;
+
+       int retval;
+       stream->readback(&retval, 4);
+       return retval;
+}
+
 renderControl_encoder_context_t::renderControl_encoder_context_t(IOStream *stream)
 {
        m_stream = stream;
@@ -534,5 +553,6 @@ renderControl_encoder_context_t::renderControl_encoder_context_t(IOStream *strea
        set_rcColorBufferCacheFlush(rcColorBufferCacheFlush_enc);
        set_rcReadColorBuffer(rcReadColorBuffer_enc);
        set_rcUpdateColorBuffer(rcUpdateColorBuffer_enc);
+       set_rcOpenColorBuffer2(rcOpenColorBuffer2_enc);
 }
 
index 712eeb9..92ef76e 100644 (file)
@@ -47,5 +47,6 @@ extern "C" {
        EGLint rcColorBufferCacheFlush_enc(void *self , uint32_t colorbuffer, EGLint postCount, int forRead);
        void rcReadColorBuffer_enc(void *self , uint32_t colorbuffer, GLint x, GLint y, GLint width, GLint height, GLenum format, GLenum type, void* pixels);
        int rcUpdateColorBuffer_enc(void *self , uint32_t colorbuffer, GLint x, GLint y, GLint width, GLint height, GLenum format, GLenum type, void* pixels);
+       int rcOpenColorBuffer2_enc(void *self , uint32_t colorbuffer);
 };
 #endif
\ No newline at end of file
index 9a0bba9..a15fd14 100644 (file)
@@ -31,6 +31,7 @@ extern "C" {
        EGLint rcColorBufferCacheFlush(uint32_t colorbuffer, EGLint postCount, int forRead);
        void rcReadColorBuffer(uint32_t colorbuffer, GLint x, GLint y, GLint width, GLint height, GLenum format, GLenum type, void* pixels);
        int rcUpdateColorBuffer(uint32_t colorbuffer, GLint x, GLint y, GLint width, GLint height, GLenum format, GLenum type, void* pixels);
+       int rcOpenColorBuffer2(uint32_t colorbuffer);
 };
 
 #endif
@@ -190,3 +191,9 @@ int rcUpdateColorBuffer(uint32_t colorbuffer, GLint x, GLint y, GLint width, GLi
         return ctx->rcUpdateColorBuffer(ctx, colorbuffer, x, y, width, height, format, type, pixels);
 }
 
+int rcOpenColorBuffer2(uint32_t colorbuffer)
+{
+       GET_CONTEXT; 
+        return ctx->rcOpenColorBuffer2(ctx, colorbuffer);
+}
+
index 1e9e2f9..a43fe5b 100644 (file)
@@ -33,6 +33,7 @@ static struct _renderControl_funcs_by_name {
        {"rcColorBufferCacheFlush", (void*)rcColorBufferCacheFlush},
        {"rcReadColorBuffer", (void*)rcReadColorBuffer},
        {"rcUpdateColorBuffer", (void*)rcUpdateColorBuffer},
+       {"rcOpenColorBuffer2", (void*)rcOpenColorBuffer2},
 };
 static int renderControl_num_funcs = sizeof(renderControl_funcs_by_name) / sizeof(struct _renderControl_funcs_by_name);
 
index b44f5d0..a00dc77 100644 (file)
@@ -28,7 +28,8 @@
 #define OP_rcColorBufferCacheFlush                                     10022
 #define OP_rcReadColorBuffer                                   10023
 #define OP_rcUpdateColorBuffer                                         10024
-#define OP_last                                        10025
+#define OP_rcOpenColorBuffer2                                  10025
+#define OP_last                                        10026
 
 
 #endif