Commit 6881301e by Greg Hartman

Connect AndroidNativeImage lock calls to the sw::Surface

Change-Id: Ic2a4e0ed2844a412122ce2ba3ee6f9f774025eed Reviewed-on: https://swiftshader-review.googlesource.com/3070Reviewed-by: 's avatarNicolas Capens <capn@google.com> Tested-by: 's avatarGreg Hartman <ghartman@google.com>
parent e7dee540
...@@ -446,8 +446,8 @@ namespace egl ...@@ -446,8 +446,8 @@ namespace egl
{ {
return parentTexture->addRef(); return parentTexture->addRef();
} }
int newCount = sw::atomicIncrement(&referenceCount);
sw::atomicIncrement(&referenceCount); LOGLOCK("%s image=%p referenceCount=%d", __FUNCTION__, this, newCount);
} }
void Image::release() void Image::release()
...@@ -457,12 +457,9 @@ namespace egl ...@@ -457,12 +457,9 @@ namespace egl
return parentTexture->release(); return parentTexture->release();
} }
if(referenceCount > 0) int newCount = sw::atomicDecrement(&referenceCount);
{ LOGLOCK("%s image=%p referenceCount=%d", __FUNCTION__, this, newCount);
sw::atomicDecrement(&referenceCount); if (newCount == 0)
}
if(referenceCount == 0)
{ {
ASSERT(!shared); // Should still hold a reference if eglDestroyImage hasn't been called ASSERT(!shared); // Should still hold a reference if eglDestroyImage hasn't been called
delete this; delete this;
......
...@@ -16,8 +16,10 @@ ...@@ -16,8 +16,10 @@
#ifdef __ANDROID__ #ifdef __ANDROID__
#include "../../Common/DebugAndroid.hpp" #include "../../Common/DebugAndroid.hpp"
#define LOGLOCK(fmt, ...) // ALOGI(fmt " tid=%d", ##__VA_ARGS__, gettid())
#else #else
#include <assert.h> #include <assert.h>
#define LOGLOCK(...)
#endif #endif
namespace egl namespace egl
...@@ -191,9 +193,18 @@ private: ...@@ -191,9 +193,18 @@ private:
virtual void *lockInternal(int x, int y, int z, sw::Lock lock, sw::Accessor client) virtual void *lockInternal(int x, int y, int z, sw::Lock lock, sw::Accessor client)
{ {
if(nativeBuffer) // Lock the buffer from ANativeWindowBuffer LOGLOCK("image=%p op=%s.swsurface lock=%d", this, __FUNCTION__, lock);
// Always do this for reference counting.
void *data = sw::Surface::lockInternal(x, y, z, lock, client);
if(nativeBuffer)
{
if (x || y || z)
{ {
void *data = lockNativeBuffer( ALOGI("badness: %s called with unsupported parms: image=%p x=%d y=%d z=%d", __FUNCTION__, this, x, y, z);
}
LOGLOCK("image=%p op=%s.ani lock=%d", this, __FUNCTION__, lock);
// Lock the ANativeWindowBuffer and use it's address.
data = lockNativeBuffer(
GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN); GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN);
if (lock == sw::LOCK_UNLOCKED) if (lock == sw::LOCK_UNLOCKED)
{ {
...@@ -201,28 +212,34 @@ private: ...@@ -201,28 +212,34 @@ private:
// immediately. This keeps the gralloc reference counts sane. // immediately. This keeps the gralloc reference counts sane.
unlockNativeBuffer(); unlockNativeBuffer();
} }
return data;
} }
return sw::Surface::lockInternal(x, y, z, lock, client); return data;
} }
virtual void unlockInternal() virtual void unlockInternal()
{ {
if(nativeBuffer) // Unlock the buffer from ANativeWindowBuffer if(nativeBuffer) // Unlock the buffer from ANativeWindowBuffer
{ {
return unlockNativeBuffer(); LOGLOCK("image=%p op=%s.ani", this, __FUNCTION__);
unlockNativeBuffer();
} }
return sw::Surface::unlockInternal(); LOGLOCK("image=%p op=%s.swsurface", this, __FUNCTION__);
sw::Surface::unlockInternal();
} }
virtual void *lock(unsigned int /*left*/, unsigned int /*top*/, sw::Lock /*lock*/) virtual void *lock(unsigned int left, unsigned int top, sw::Lock lock)
{ {
LOGLOCK("image=%p op=%s lock=%d", this, __FUNCTION__, lock);
(void)sw::Surface::lockExternal(left, top, 0, lock, sw::PUBLIC);
return lockNativeBuffer(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN); return lockNativeBuffer(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN);
} }
virtual void unlock() virtual void unlock()
{ {
LOGLOCK("image=%p op=%s.ani", this, __FUNCTION__);
unlockNativeBuffer(); unlockNativeBuffer();
LOGLOCK("image=%p op=%s.swsurface", this, __FUNCTION__);
sw::Surface::unlockExternal();
} }
void* lockNativeBuffer(int usage) void* lockNativeBuffer(int usage)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment