Pass sp<Fence>s around instead of file descriptors

Change-Id: Iac70584a2207940730e8f803a543e4e9a4000c47
This commit is contained in:
Jesse Hall 2013-03-20 11:37:21 -07:00
parent 8d8c759761
commit 13f01cbdbd
11 changed files with 34 additions and 38 deletions

View File

@ -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>& fence);
// setDefaultMaxBufferCount sets the default limit on the maximum number
// of buffers that will be allocated at one time. The image producer may

View File

@ -367,14 +367,14 @@ status_t GLConsumer::checkAndUpdateEglStateLocked() {
return NO_ERROR;
}
void GLConsumer::setReleaseFence(int fenceFd) {
sp<Fence> 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>& 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);
}
}
}

View File

@ -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> fence = hwc.getAndResetReleaseFence(mType);
mDisplaySurface->onFrameCommitted(fence);
}
}

View File

@ -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>& fence) = 0;
virtual void dump(String8& result) const = 0;

View File

@ -140,14 +140,12 @@ void FramebufferSurface::freeBufferLocked(int slotIndex) {
}
}
void FramebufferSurface::onFrameCommitted(int fenceFd) {
if (fenceFd >= 0) {
sp<Fence> 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>& 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);
}
}

View File

@ -43,7 +43,7 @@ public:
virtual status_t compositionComplete();
virtual status_t advanceFrame();
virtual void onFrameCommitted(int fenceFd);
virtual void onFrameCommitted(const sp<Fence>& fence);
// Implementation of DisplaySurface::dump(). Note that ConsumerBase also
// has a non-virtual dump() with the same signature.

View File

@ -627,9 +627,9 @@ bool HWComposer::hasGlesComposition(int32_t id) const {
return mDisplayData[id].hasFbComp;
}
int HWComposer::getAndResetReleaseFenceFd(int32_t id) {
sp<Fence> 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<Fence> 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;

View File

@ -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<Fence> 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<Fence> getAndResetReleaseFence() = 0;
virtual void setDefaultState() = 0;
virtual void setSkip(bool skip) = 0;
virtual void setBlending(uint32_t blending) = 0;

View File

@ -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>& fence) {
Mutex::Autolock lock(mMutex);
sp<Fence> fence(new Fence(fenceFd));
if (mAcquiredBuffer != NULL) {
status_t result = mSource->releaseBuffer(fence);
ALOGE_IF(result != NO_ERROR, "VirtualDisplaySurface \"%s\": "

View File

@ -58,7 +58,7 @@ public:
virtual status_t compositionComplete();
virtual status_t advanceFrame();
virtual void onFrameCommitted(int fenceFd);
virtual void onFrameCommitted(const sp<Fence>& fence);
virtual void dump(String8& result) const;
private:

View File

@ -144,7 +144,7 @@ void Layer::onLayerDisplayed(const sp<const DisplayDevice>& hw,
HWComposer::HWCLayerInterface* layer) {
if (layer) {
layer->onDisplayed();
mSurfaceFlingerConsumer->setReleaseFence(layer->getAndResetReleaseFenceFd());
mSurfaceFlingerConsumer->setReleaseFence(layer->getAndResetReleaseFence());
}
}