Commit a3aca1f3 by Greg Hartman

Fix pairing of gralloc locks and unlocks to avoid reference leaks

Change-Id: Ic6dfa9f565154602d540286d5feb091349f794bf Reviewed-on: https://swiftshader-review.googlesource.com/3061Reviewed-by: 's avatarNicolas Capens <capn@google.com> Tested-by: 's avatarGreg Hartman <ghartman@google.com>
parent 394b7078
...@@ -11,7 +11,7 @@ public: ...@@ -11,7 +11,7 @@ public:
int lock( int lock(
buffer_handle_t handle, int usage, buffer_handle_t handle, int usage,
int left, int top, int width, int height, void**vaddr) { int left, int top, int width, int height, void**vaddr) {
return m_module->lock(m_module, handle, 0, left, top, width, height, vaddr); return m_module->lock(m_module, handle, usage, left, top, width, height, vaddr);
} }
int unlock(buffer_handle_t handle) { int unlock(buffer_handle_t handle) {
......
...@@ -56,7 +56,6 @@ namespace sw ...@@ -56,7 +56,6 @@ namespace sw
protected: protected:
void copy(void *source, Format format); void copy(void *source, Format format);
int width; int width;
int height; int height;
Format sourceFormat; Format sourceFormat;
......
...@@ -35,7 +35,7 @@ namespace sw ...@@ -35,7 +35,7 @@ namespace sw
if (buffer && locked) if (buffer && locked)
{ {
locked = 0; locked = 0;
unlock(buffer); unlock();
} }
buffer->common.decRef(&buffer->common); buffer->common.decRef(&buffer->common);
...@@ -58,9 +58,13 @@ namespace sw ...@@ -58,9 +58,13 @@ namespace sw
buffer->common.incRef(&buffer->common); buffer->common.incRef(&buffer->common);
if (lock(buffer, GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, &locked) != android::NO_ERROR) if (gralloc->lock(
gralloc, buffer->handle,
GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN,
0, 0, buffer->width, buffer->height, &locked)
!= android::NO_ERROR)
{ {
ALOGE("connect() failed to lock buffer %p", buffer); ALOGE("%s failed to lock buffer %p", __FUNCTION__, buffer);
return NULL; return NULL;
} }
...@@ -87,18 +91,16 @@ namespace sw ...@@ -87,18 +91,16 @@ namespace sw
void FrameBufferAndroid::unlock() void FrameBufferAndroid::unlock()
{ {
locked = 0; if (!buffer)
} {
ALOGE("%s: badness unlock with no active buffer", __FUNCTION__);
int FrameBufferAndroid::lock(ANativeWindowBuffer* buf, int usage, void** vaddr) return;
{ }
return gralloc->lock(gralloc, buf->handle, usage, 0, 0, buf->width, buf->height, vaddr); locked = 0;
} if (gralloc->unlock(gralloc, buffer->handle) != android::NO_ERROR)
{
int FrameBufferAndroid::unlock(ANativeWindowBuffer* buf) ALOGE("%s: badness unlock failed", __FUNCTION__);
{ }
if (!buf) return -1;
return gralloc->unlock(gralloc, buf->handle);
} }
} }
......
...@@ -25,9 +25,6 @@ namespace sw ...@@ -25,9 +25,6 @@ namespace sw
bool setSwapRectangle(int l, int t, int w, int h); bool setSwapRectangle(int l, int t, int w, int h);
private: private:
int lock(ANativeWindowBuffer* buf, int usage, void** vaddr);
int unlock(ANativeWindowBuffer* buf);
ANativeWindow* nativeWindow; ANativeWindow* nativeWindow;
ANativeWindowBuffer* buffer; ANativeWindowBuffer* buffer;
gralloc_module_t const* gralloc; gralloc_module_t const* gralloc;
......
...@@ -194,7 +194,15 @@ private: ...@@ -194,7 +194,15 @@ private:
{ {
if(nativeBuffer) // Lock the buffer from ANativeWindowBuffer if(nativeBuffer) // Lock the buffer from ANativeWindowBuffer
{ {
return lockNativeBuffer(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN); void *data = lockNativeBuffer(
GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN);
if (lock == sw::LOCK_UNLOCKED)
{
// We're never going to get a corresponding unlock, so unlock
// immediately. This keeps the gralloc reference counts sane.
unlockNativeBuffer();
}
return data;
} }
return sw::Surface::lockInternal(x, y, z, lock, client); return sw::Surface::lockInternal(x, y, z, lock, client);
} }
......
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