From 8760f1673ea9c2aca0181827808cbd6981a5a2ee Mon Sep 17 00:00:00 2001 From: Omprakash Dhyade Date: Thu, 9 Aug 2012 19:00:37 -0700 Subject: [PATCH] fix copy back dirty region Copyback dirty region logic does copyback, even when its not necessary causing 2ms delay. Fix the logic to copy back only what is necessary CRs-fixed: 562334 Change-Id: I52de68258ac9f87d704ee5401f93417805fa6773 --- libs/gui/Surface.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/libs/gui/Surface.cpp b/libs/gui/Surface.cpp index 4b76f9834..444544221 100644 --- a/libs/gui/Surface.cpp +++ b/libs/gui/Surface.cpp @@ -1023,6 +1023,7 @@ status_t Surface::lock( } // figure out if we can copy the frontbuffer back + int backBufferSlot(getSlotFromBufferLocked(backBuffer.get())); const sp& frontBuffer(mPostedBuffer); const bool canCopyBack = (frontBuffer != 0 && backBuffer->width == frontBuffer->width && @@ -1030,15 +1031,19 @@ status_t Surface::lock( backBuffer->format == frontBuffer->format); if (canCopyBack) { - // copy the area that is invalid and not repainted this round - const Region copyback(mDirtyRegion.subtract(newDirtyRegion)); + Mutex::Autolock lock(mMutex); + Region oldDirtyRegion; + for(int i = 0 ; i < NUM_BUFFER_SLOTS; i++ ) { + if(i != backBufferSlot && !mSlots[i].dirtyRegion.isEmpty()) + oldDirtyRegion.orSelf(mSlots[i].dirtyRegion); + } + const Region copyback(oldDirtyRegion.subtract(newDirtyRegion)); if (!copyback.isEmpty()) copyBlt(backBuffer, frontBuffer, copyback); } else { // if we can't copy-back anything, modify the user's dirty // region to make sure they redraw the whole buffer newDirtyRegion.set(bounds); - mDirtyRegion.clear(); Mutex::Autolock lock(mMutex); for (size_t i=0 ; i= 0) { - Region& dirtyRegion(mSlots[backBufferSlot].dirtyRegion); - mDirtyRegion.subtract(dirtyRegion); - dirtyRegion = newDirtyRegion; - } + mSlots[backBufferSlot].dirtyRegion = newDirtyRegion; } - mDirtyRegion.orSelf(newDirtyRegion); if (inOutDirtyBounds) { *inOutDirtyBounds = newDirtyRegion.getBounds(); }