OSDN Git Service

Connect AndroidNativeImage lock calls to the sw::Surface
authorGreg Hartman <ghartman@google.com>
Thu, 7 May 2015 05:20:20 +0000 (22:20 -0700)
committerGreg Hartman <ghartman@google.com>
Fri, 8 May 2015 15:35:34 +0000 (15:35 +0000)
Change-Id: Ic2a4e0ed2844a412122ce2ba3ee6f9f774025eed
Reviewed-on: https://swiftshader-review.googlesource.com/3070
Reviewed-by: Nicolas Capens <capn@google.com>
Tested-by: Greg Hartman <ghartman@google.com>
src/OpenGL/common/Image.cpp
src/OpenGL/common/Image.hpp

index b01c680..e443544 100644 (file)
@@ -446,8 +446,8 @@ namespace egl
                {
                        return parentTexture->addRef();
                }
-
-               sw::atomicIncrement(&referenceCount);
+               int newCount = sw::atomicIncrement(&referenceCount);
+               LOGLOCK("%s image=%p referenceCount=%d", __FUNCTION__, this, newCount);
        }
 
        void Image::release()
@@ -457,12 +457,9 @@ namespace egl
                        return parentTexture->release();
                }
 
-               if(referenceCount > 0)
-               {
-                       sw::atomicDecrement(&referenceCount);
-               }
-
-               if(referenceCount == 0)
+               int newCount = sw::atomicDecrement(&referenceCount);
+               LOGLOCK("%s image=%p referenceCount=%d", __FUNCTION__, this, newCount);
+               if (newCount == 0)
                {
                        ASSERT(!shared);   // Should still hold a reference if eglDestroyImage hasn't been called
                        delete this;
index 93a0535..60b0176 100644 (file)
 \r
 #ifdef __ANDROID__\r
 #include "../../Common/DebugAndroid.hpp"\r
+#define LOGLOCK(fmt, ...) // ALOGI(fmt " tid=%d", ##__VA_ARGS__, gettid())\r
 #else\r
 #include <assert.h>\r
+#define LOGLOCK(...)\r
 #endif\r
 \r
 namespace egl\r
@@ -191,9 +193,18 @@ private:
 \r
        virtual void *lockInternal(int x, int y, int z, sw::Lock lock, sw::Accessor client)\r
        {\r
-               if(nativeBuffer)   // Lock the buffer from ANativeWindowBuffer\r
+               LOGLOCK("image=%p op=%s.swsurface lock=%d", this, __FUNCTION__, lock);\r
+               // Always do this for reference counting.\r
+               void *data = sw::Surface::lockInternal(x, y, z, lock, client);\r
+               if(nativeBuffer)\r
                {\r
-                       void *data = lockNativeBuffer(\r
+                       if (x || y || z)\r
+                       {\r
+                               ALOGI("badness: %s called with unsupported parms: image=%p x=%d y=%d z=%d", __FUNCTION__, this, x, y, z);\r
+                       }\r
+                       LOGLOCK("image=%p op=%s.ani lock=%d", this, __FUNCTION__, lock);\r
+                       // Lock the ANativeWindowBuffer and use it's address.\r
+                       data = lockNativeBuffer(\r
                                GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN);\r
                        if (lock == sw::LOCK_UNLOCKED)\r
                        {\r
@@ -201,28 +212,34 @@ private:
                                // immediately. This keeps the gralloc reference counts sane.\r
                                unlockNativeBuffer();\r
                        }\r
-                       return data;\r
                }\r
-               return sw::Surface::lockInternal(x, y, z, lock, client);\r
+               return data;\r
        }\r
 \r
        virtual void unlockInternal()\r
        {\r
                if(nativeBuffer)   // Unlock the buffer from ANativeWindowBuffer\r
                {\r
-                       return unlockNativeBuffer();\r
+                       LOGLOCK("image=%p op=%s.ani", this, __FUNCTION__);\r
+                       unlockNativeBuffer();\r
                }\r
-               return sw::Surface::unlockInternal();\r
+               LOGLOCK("image=%p op=%s.swsurface", this, __FUNCTION__);\r
+               sw::Surface::unlockInternal();\r
        }\r
 \r
-       virtual void *lock(unsigned int /*left*/, unsigned int /*top*/, sw::Lock /*lock*/)\r
+       virtual void *lock(unsigned int left, unsigned int top, sw::Lock lock)\r
        {\r
+               LOGLOCK("image=%p op=%s lock=%d", this, __FUNCTION__, lock);\r
+               (void)sw::Surface::lockExternal(left, top, 0, lock, sw::PUBLIC);\r
                return lockNativeBuffer(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN);\r
        }\r
 \r
        virtual void unlock()\r
        {\r
+               LOGLOCK("image=%p op=%s.ani", this, __FUNCTION__);\r
                unlockNativeBuffer();\r
+               LOGLOCK("image=%p op=%s.swsurface", this, __FUNCTION__);\r
+               sw::Surface::unlockExternal();\r
        }\r
 \r
        void* lockNativeBuffer(int usage)\r