diff --git a/include/gui/GLConsumer.h b/include/gui/GLConsumer.h index e0fa8934f..b1622d2e8 100644 --- a/include/gui/GLConsumer.h +++ b/include/gui/GLConsumer.h @@ -98,13 +98,12 @@ public: // This calls doGLFenceWait to ensure proper synchronization. status_t updateTexImage(); - // setReleaseFence stores a fence file descriptor that will signal when the - // current buffer is no longer being read. This fence will be returned to - // the producer when the current buffer is released by updateTexImage(). - // Multiple fences can be set for a given buffer; they will be merged into - // a single union fence. The GLConsumer will close the file descriptor - // when finished with it. - void setReleaseFence(int fenceFd); + // setReleaseFence stores a fence that will signal when the current buffer + // is no longer being read. This fence will be returned to the producer + // when the current buffer is released by updateTexImage(). Multiple + // fences can be set for a given buffer; they will be merged into a single + // union fence. + void setReleaseFence(const sp& fence); // setDefaultMaxBufferCount sets the default limit on the maximum number // of buffers that will be allocated at one time. The image producer may diff --git a/libs/gui/GLConsumer.cpp b/libs/gui/GLConsumer.cpp index 09831fb8b..630eb7c04 100644 --- a/libs/gui/GLConsumer.cpp +++ b/libs/gui/GLConsumer.cpp @@ -367,14 +367,14 @@ status_t GLConsumer::checkAndUpdateEglStateLocked() { return NO_ERROR; } -void GLConsumer::setReleaseFence(int fenceFd) { - sp fence(new Fence(fenceFd)); - if (fenceFd == -1 || mCurrentTexture == BufferQueue::INVALID_BUFFER_SLOT) - return; - status_t err = addReleaseFence(mCurrentTexture, fence); - if (err != OK) { - ST_LOGE("setReleaseFence: failed to add the fence: %s (%d)", - strerror(-err), err); +void GLConsumer::setReleaseFence(const sp& fence) { + if (fence->isValid() && + mCurrentTexture != BufferQueue::INVALID_BUFFER_SLOT) { + status_t err = addReleaseFence(mCurrentTexture, fence); + if (err != OK) { + ST_LOGE("setReleaseFence: failed to add the fence: %s (%d)", + strerror(-err), err); + } } } diff --git a/services/surfaceflinger/DisplayDevice.cpp b/services/surfaceflinger/DisplayDevice.cpp index 5493e7d43..e16abef3d 100644 --- a/services/surfaceflinger/DisplayDevice.cpp +++ b/services/surfaceflinger/DisplayDevice.cpp @@ -235,8 +235,8 @@ void DisplayDevice::swapBuffers(HWComposer& hwc) const { void DisplayDevice::onSwapBuffersCompleted(HWComposer& hwc) const { if (hwc.initCheck() == NO_ERROR) { - int fd = hwc.getAndResetReleaseFenceFd(mType); - mDisplaySurface->onFrameCommitted(fd); + sp fence = hwc.getAndResetReleaseFence(mType); + mDisplaySurface->onFrameCommitted(fence); } } diff --git a/services/surfaceflinger/DisplayHardware/DisplaySurface.h b/services/surfaceflinger/DisplayHardware/DisplaySurface.h index 644584877..bc717a956 100644 --- a/services/surfaceflinger/DisplayHardware/DisplaySurface.h +++ b/services/surfaceflinger/DisplayHardware/DisplaySurface.h @@ -52,7 +52,7 @@ public: // hardware composer and a release fence is available for the buffer. // Further operations on the buffer can be queued as long as they wait for // the fence to signal. - virtual void onFrameCommitted(int fenceFd) = 0; + virtual void onFrameCommitted(const sp& fence) = 0; virtual void dump(String8& result) const = 0; diff --git a/services/surfaceflinger/DisplayHardware/FramebufferSurface.cpp b/services/surfaceflinger/DisplayHardware/FramebufferSurface.cpp index 83ab38e6e..c35ac956c 100644 --- a/services/surfaceflinger/DisplayHardware/FramebufferSurface.cpp +++ b/services/surfaceflinger/DisplayHardware/FramebufferSurface.cpp @@ -140,14 +140,12 @@ void FramebufferSurface::freeBufferLocked(int slotIndex) { } } -void FramebufferSurface::onFrameCommitted(int fenceFd) { - if (fenceFd >= 0) { - sp fence(new Fence(fenceFd)); - if (mCurrentBufferSlot != BufferQueue::INVALID_BUFFER_SLOT) { - status_t err = addReleaseFence(mCurrentBufferSlot, fence); - ALOGE_IF(err, "setReleaseFenceFd: failed to add the fence: %s (%d)", - strerror(-err), err); - } +void FramebufferSurface::onFrameCommitted(const sp& fence) { + if (fence->isValid() && + mCurrentBufferSlot != BufferQueue::INVALID_BUFFER_SLOT) { + status_t err = addReleaseFence(mCurrentBufferSlot, fence); + ALOGE_IF(err, "setReleaseFenceFd: failed to add the fence: %s (%d)", + strerror(-err), err); } } diff --git a/services/surfaceflinger/DisplayHardware/FramebufferSurface.h b/services/surfaceflinger/DisplayHardware/FramebufferSurface.h index 1402740ca..164f81f27 100644 --- a/services/surfaceflinger/DisplayHardware/FramebufferSurface.h +++ b/services/surfaceflinger/DisplayHardware/FramebufferSurface.h @@ -43,7 +43,7 @@ public: virtual status_t compositionComplete(); virtual status_t advanceFrame(); - virtual void onFrameCommitted(int fenceFd); + virtual void onFrameCommitted(const sp& fence); // Implementation of DisplaySurface::dump(). Note that ConsumerBase also // has a non-virtual dump() with the same signature. diff --git a/services/surfaceflinger/DisplayHardware/HWComposer.cpp b/services/surfaceflinger/DisplayHardware/HWComposer.cpp index 8599a29d0..eb7d1286e 100644 --- a/services/surfaceflinger/DisplayHardware/HWComposer.cpp +++ b/services/surfaceflinger/DisplayHardware/HWComposer.cpp @@ -627,9 +627,9 @@ bool HWComposer::hasGlesComposition(int32_t id) const { return mDisplayData[id].hasFbComp; } -int HWComposer::getAndResetReleaseFenceFd(int32_t id) { +sp HWComposer::getAndResetReleaseFence(int32_t id) { if (uint32_t(id)>31 || !mAllocatedDisplayIDs.hasBit(id)) - return BAD_INDEX; + return Fence::NO_FENCE; int fd = INVALID_OPERATION; if (mHwc && hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_1)) { @@ -640,7 +640,7 @@ int HWComposer::getAndResetReleaseFenceFd(int32_t id) { disp.framebufferTarget->releaseFenceFd = -1; } } - return fd; + return fd >= 0 ? new Fence(fd) : Fence::NO_FENCE; } status_t HWComposer::commit() { @@ -803,10 +803,10 @@ public: virtual uint32_t getHints() const { return getLayer()->hints; } - virtual int getAndResetReleaseFenceFd() { + virtual sp getAndResetReleaseFence() { int fd = getLayer()->releaseFenceFd; getLayer()->releaseFenceFd = -1; - return fd; + return fd >= 0 ? new Fence(fd) : Fence::NO_FENCE; } virtual void setAcquireFenceFd(int fenceFd) { getLayer()->acquireFenceFd = fenceFd; diff --git a/services/surfaceflinger/DisplayHardware/HWComposer.h b/services/surfaceflinger/DisplayHardware/HWComposer.h index fdbd2d962..346526aae 100644 --- a/services/surfaceflinger/DisplayHardware/HWComposer.h +++ b/services/surfaceflinger/DisplayHardware/HWComposer.h @@ -114,7 +114,7 @@ public: // get the releaseFence file descriptor for a display's framebuffer layer. // the release fence is only valid after commit() - int getAndResetReleaseFenceFd(int32_t id); + sp getAndResetReleaseFence(int32_t id); // needed forward declarations class LayerListIterator; @@ -141,7 +141,7 @@ public: public: virtual int32_t getCompositionType() const = 0; virtual uint32_t getHints() const = 0; - virtual int getAndResetReleaseFenceFd() = 0; + virtual sp getAndResetReleaseFence() = 0; virtual void setDefaultState() = 0; virtual void setSkip(bool skip) = 0; virtual void setBlending(uint32_t blending) = 0; diff --git a/services/surfaceflinger/DisplayHardware/VirtualDisplaySurface.cpp b/services/surfaceflinger/DisplayHardware/VirtualDisplaySurface.cpp index fac6c3eb7..255b77f65 100644 --- a/services/surfaceflinger/DisplayHardware/VirtualDisplaySurface.cpp +++ b/services/surfaceflinger/DisplayHardware/VirtualDisplaySurface.cpp @@ -70,9 +70,8 @@ status_t VirtualDisplaySurface::advanceFrame() { return mHwc.fbPost(mDisplayId, fence, mAcquiredBuffer); } -void VirtualDisplaySurface::onFrameCommitted(int fenceFd) { +void VirtualDisplaySurface::onFrameCommitted(const sp& fence) { Mutex::Autolock lock(mMutex); - sp fence(new Fence(fenceFd)); if (mAcquiredBuffer != NULL) { status_t result = mSource->releaseBuffer(fence); ALOGE_IF(result != NO_ERROR, "VirtualDisplaySurface \"%s\": " diff --git a/services/surfaceflinger/DisplayHardware/VirtualDisplaySurface.h b/services/surfaceflinger/DisplayHardware/VirtualDisplaySurface.h index 85a7a879e..13476800f 100644 --- a/services/surfaceflinger/DisplayHardware/VirtualDisplaySurface.h +++ b/services/surfaceflinger/DisplayHardware/VirtualDisplaySurface.h @@ -58,7 +58,7 @@ public: virtual status_t compositionComplete(); virtual status_t advanceFrame(); - virtual void onFrameCommitted(int fenceFd); + virtual void onFrameCommitted(const sp& fence); virtual void dump(String8& result) const; private: diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp index 1677c7687..a4c613cb8 100644 --- a/services/surfaceflinger/Layer.cpp +++ b/services/surfaceflinger/Layer.cpp @@ -144,7 +144,7 @@ void Layer::onLayerDisplayed(const sp& hw, HWComposer::HWCLayerInterface* layer) { if (layer) { layer->onDisplayed(); - mSurfaceFlingerConsumer->setReleaseFence(layer->getAndResetReleaseFenceFd()); + mSurfaceFlingerConsumer->setReleaseFence(layer->getAndResetReleaseFence()); } }