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:
int lock(
buffer_handle_t handle, int usage,
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) {
......
......@@ -56,7 +56,6 @@ namespace sw
protected:
void copy(void *source, Format format);
int width;
int height;
Format sourceFormat;
......
......@@ -35,7 +35,7 @@ namespace sw
if (buffer && locked)
{
locked = 0;
unlock(buffer);
unlock();
}
buffer->common.decRef(&buffer->common);
......@@ -58,9 +58,13 @@ namespace sw
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;
}
......@@ -87,18 +91,16 @@ namespace sw
void FrameBufferAndroid::unlock()
{
locked = 0;
}
int FrameBufferAndroid::lock(ANativeWindowBuffer* buf, int usage, void** vaddr)
{
return gralloc->lock(gralloc, buf->handle, usage, 0, 0, buf->width, buf->height, vaddr);
}
int FrameBufferAndroid::unlock(ANativeWindowBuffer* buf)
{
if (!buf) return -1;
return gralloc->unlock(gralloc, buf->handle);
if (!buffer)
{
ALOGE("%s: badness unlock with no active buffer", __FUNCTION__);
return;
}
locked = 0;
if (gralloc->unlock(gralloc, buffer->handle) != android::NO_ERROR)
{
ALOGE("%s: badness unlock failed", __FUNCTION__);
}
}
}
......
......@@ -25,9 +25,6 @@ namespace sw
bool setSwapRectangle(int l, int t, int w, int h);
private:
int lock(ANativeWindowBuffer* buf, int usage, void** vaddr);
int unlock(ANativeWindowBuffer* buf);
ANativeWindow* nativeWindow;
ANativeWindowBuffer* buffer;
gralloc_module_t const* gralloc;
......
......@@ -194,7 +194,15 @@ private:
{
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);
}
......
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