diff --git a/include/ui/Fence.h b/include/ui/Fence.h index 195f2e9e3..3d49e6a14 100644 --- a/include/ui/Fence.h +++ b/include/ui/Fence.h @@ -69,6 +69,11 @@ public: static sp merge(const String8& name, const sp& f1, const sp& f2); + // Return a duplicate of the fence file descriptor. The caller is + // responsible for closing the returned file descriptor. On error, -1 will + // be returned and errno will indicate the problem. + int dup() const; + // Flattenable interface size_t getFlattenedSize() const; size_t getFdCount() const; diff --git a/libs/gui/SurfaceTextureClient.cpp b/libs/gui/SurfaceTextureClient.cpp index 57bc604f1..84f2ff4e9 100644 --- a/libs/gui/SurfaceTextureClient.cpp +++ b/libs/gui/SurfaceTextureClient.cpp @@ -222,15 +222,18 @@ int SurfaceTextureClient::dequeueBuffer(android_native_buffer_t** buffer, } if (fence.get()) { - status_t err = fence->wait(Fence::TIMEOUT_NEVER); - if (err != OK) { - ALOGE("dequeueBuffer: error waiting for fence: %d", err); + *fenceFd = fence->dup(); + if (*fenceFd == -1) { + ALOGE("dequeueBuffer: error duping fence: %d", errno); + // dup() should never fail; something is badly wrong. Soldier on + // and hope for the best; the worst that should happen is some + // visible corruption that lasts until the next frame. } - fence.clear(); + } else { + *fenceFd = -1; } *buffer = gbuf.get(); - *fenceFd = -1; return OK; } diff --git a/libs/ui/Fence.cpp b/libs/ui/Fence.cpp index 5c17d10e7..08340f24b 100644 --- a/libs/ui/Fence.cpp +++ b/libs/ui/Fence.cpp @@ -62,6 +62,10 @@ sp Fence::merge(const String8& name, const sp& f1, return sp(new Fence(result)); } +int Fence::dup() const { + return ::dup(mFenceFd); +} + size_t Fence::getFlattenedSize() const { return 0; }