am a02e9484: Merge "SurfaceFlinger: Prevent deadlock by updating an atomic layer set." into lmp-dev

* commit 'a02e9484be6894f8a4db7049d432f534a4e0a676':
  SurfaceFlinger: Prevent deadlock by updating an atomic layer set.
This commit is contained in:
Eric Penner 2014-08-01 13:48:37 +00:00 committed by Android Git Automerger
commit 3367a960ab
2 changed files with 22 additions and 2 deletions

View File

@ -281,6 +281,11 @@ public:
*/ */
Rect getContentCrop() const; Rect getContentCrop() const;
/*
* Returns if a frame is queued.
*/
bool hasQueuedFrame() const { return mQueuedFrames > 0; }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
void clearWithOpenGL(const sp<const DisplayDevice>& hw, const Region& clip) const; void clearWithOpenGL(const sp<const DisplayDevice>& hw, const Region& clip) const;

View File

@ -1636,9 +1636,24 @@ void SurfaceFlinger::handlePageFlip()
bool visibleRegions = false; bool visibleRegions = false;
const LayerVector& layers(mDrawingState.layersSortedByZ); const LayerVector& layers(mDrawingState.layersSortedByZ);
const size_t count = layers.size();
for (size_t i=0 ; i<count ; i++) { // Store the set of layers that need updates. This set must not change as
// buffers are being latched, as this could result in a deadlock.
// Example: Two producers share the same command stream and:
// 1.) Layer 0 is latched
// 2.) Layer 0 gets a new frame
// 2.) Layer 1 gets a new frame
// 3.) Layer 1 is latched.
// Display is now waiting on Layer 1's frame, which is behind layer 0's
// second frame. But layer 0's second frame could be waiting on display.
Vector<Layer*> layersWithQueuedFrames;
for (size_t i = 0, count = layers.size(); i<count ; i++) {
const sp<Layer>& layer(layers[i]); const sp<Layer>& layer(layers[i]);
if (layer->hasQueuedFrame())
layersWithQueuedFrames.push_back(layer.get());
}
for (size_t i = 0, count = layersWithQueuedFrames.size() ; i<count ; i++) {
Layer* layer = layersWithQueuedFrames[i];
const Region dirty(layer->latchBuffer(visibleRegions)); const Region dirty(layer->latchBuffer(visibleRegions));
const Layer::State& s(layer->getDrawingState()); const Layer::State& s(layer->getDrawingState());
invalidateLayerStack(s.layerStack, dirty); invalidateLayerStack(s.layerStack, dirty);