OSDN Git Service

Create and read color buffer when expecting reads
authorBjoern Johansson <bjoernj@google.com>
Thu, 12 May 2016 17:38:27 +0000 (10:38 -0700)
committerBjoern Johansson <bjoernj@google.com>
Thu, 12 May 2016 17:38:27 +0000 (10:38 -0700)
Make sure color buffers are created when gralloc is allocating buffers
that indicate that software reads are going to happen. In this case
software will require the rendered data to be available from the host at
a later point and that means that rendering has to be stored in a color
buffer. Also make sure that when gralloc locks a buffer for reading it
will actually read the data from the host if the buffer is marked for
reading.

Change-Id: Ief4b7fe34401727cabec9fdd5c2b9812a6c49612

system/gralloc/gralloc.cpp

index 188df18..f597d2b 100644 (file)
@@ -312,10 +312,13 @@ static int gralloc_alloc(alloc_device_t* dev,
     //
     // Allocate ColorBuffer handle on the host (only if h/w access is allowed)
     // Only do this for some h/w usages, not all.
+    // Also do this if we need to read from the surface, in this case the
+    // rendering will still happen on the host but we also need to be able to
+    // read back from the color buffer, which requires that there is a buffer
     //
     if (usage & (GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_HW_RENDER |
                     GRALLOC_USAGE_HW_2D | GRALLOC_USAGE_HW_COMPOSER |
-                    GRALLOC_USAGE_HW_FB) ) {
+                    GRALLOC_USAGE_HW_FB | GRALLOC_USAGE_SW_READ_MASK) ) {
         DEFINE_HOST_CONNECTION;
         if (hostCon && rcEnc) {
             cb->hostHandle = rcEnc->rcCreateColorBuffer(rcEnc, w, h, glFormat);
@@ -682,12 +685,8 @@ static int gralloc_lock(gralloc_module_t const* module,
             return -EBUSY;
         }
 
-        const bool sw_read = (cb->usage & GRALLOC_USAGE_SW_READ_MASK);
-        const bool hw_write = (cb->usage & GRALLOC_USAGE_HW_RENDER);
-        const bool screen_capture_mode = (sw_read && hw_write);
-        if (screen_capture_mode) {
+        if (sw_read) {
             D("gralloc_lock read back color buffer %d %d\n", cb->width, cb->height);
-            DEFINE_AND_VALIDATE_HOST_CONNECTION;
             rcEnc->rcReadColorBuffer(rcEnc, cb->hostHandle,
                     0, 0, cb->width, cb->height, GL_RGBA, GL_UNSIGNED_BYTE, cpu_addr);
         }