Skip to content

Commit 6497eab

Browse files
committed
mDirtyRegion is single threaded, but could be accessed from a hwc thread
We now have mInvalidateRegion which holds the region to invalidate, it can be set from any thread as long as mInvalidateLock is held. We use fine-grained locking here because mInvalidateRegion can be set from anywhere, in particular frmo HWC callbacks. Bug: 5466774 Change-Id: Iafca20aa3f5b25a87755e65bde7b769aa8f997bc
1 parent 8bf89f3 commit 6497eab

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

services/surfaceflinger/SurfaceFlinger.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,8 @@ void SurfaceFlinger::handlePageFlip()
788788
}
789789

790790
unlockPageFlip(currentLayers);
791+
792+
mDirtyRegion.orSelf(getAndClearInvalidateRegion());
791793
mDirtyRegion.andSelf(screenRegion);
792794
}
793795

@@ -1798,12 +1800,24 @@ status_t SurfaceFlinger::onTransact(
17981800
}
17991801

18001802
void SurfaceFlinger::repaintEverything() {
1801-
Mutex::Autolock _l(mStateLock);
18021803
const DisplayHardware& hw(graphicPlane(0).displayHardware());
1803-
mDirtyRegion.set(hw.bounds());
1804+
const Rect bounds(hw.getBounds());
1805+
setInvalidateRegion(Region(bounds));
18041806
signalEvent();
18051807
}
18061808

1809+
void SurfaceFlinger::setInvalidateRegion(const Region& reg) {
1810+
Mutex::Autolock _l(mInvalidateLock);
1811+
mInvalidateRegion = reg;
1812+
}
1813+
1814+
Region SurfaceFlinger::getAndClearInvalidateRegion() {
1815+
Mutex::Autolock _l(mInvalidateLock);
1816+
Region reg(mInvalidateRegion);
1817+
mInvalidateRegion.clear();
1818+
return reg;
1819+
}
1820+
18071821
// ---------------------------------------------------------------------------
18081822

18091823
status_t SurfaceFlinger::renderScreenToTexture(DisplayID dpy,

services/surfaceflinger/SurfaceFlinger.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,9 @@ class SurfaceFlinger :
308308
void composeSurfaces(const Region& dirty);
309309

310310

311+
void setInvalidateRegion(const Region& reg);
312+
Region getAndClearInvalidateRegion();
313+
311314
ssize_t addClientLayer(const sp<Client>& client,
312315
const sp<LayerBaseClient>& lbc);
313316
status_t addLayer_l(const sp<LayerBase>& layer);
@@ -367,6 +370,10 @@ class SurfaceFlinger :
367370
bool mLayersRemoved;
368371
DefaultKeyedVector< wp<IBinder>, wp<Layer> > mLayerMap;
369372

373+
// access must be protected by mInvalidateLock
374+
mutable Mutex mInvalidateLock;
375+
Region mInvalidateRegion;
376+
370377
// constant members (no synchronization needed for access)
371378
sp<IMemoryHeap> mServerHeap;
372379
surface_flinger_cblk_t* mServerCblk;

0 commit comments

Comments
 (0)