Loading services/surfaceflinger/Layer.cpp +1 −1 Original line number Original line Diff line number Diff line Loading @@ -130,7 +130,7 @@ Layer::~Layer() { } } mFrameTracker.logAndResetStats(mName); mFrameTracker.logAndResetStats(mName); mFlinger->onLayerDestroyed(); mFlinger->onLayerDestroyed(this); } } // --------------------------------------------------------------------------- // --------------------------------------------------------------------------- Loading services/surfaceflinger/SurfaceFlinger.cpp +30 −1 Original line number Original line Diff line number Diff line Loading @@ -2944,6 +2944,13 @@ void SurfaceFlinger::commitTransaction() if (l->isRemovedFromCurrentState()) { if (l->isRemovedFromCurrentState()) { latchAndReleaseBuffer(l); latchAndReleaseBuffer(l); } } // If the layer has been removed and has no parent, then it will not be reachable // when traversing layers on screen. Add the layer to the offscreenLayers set to // ensure we can copy its current to drawing state. if (!l->getParent()) { mOffscreenLayers.emplace(l.get()); } } } mLayersPendingRemoval.clear(); mLayersPendingRemoval.clear(); } } Loading @@ -2957,7 +2964,17 @@ void SurfaceFlinger::commitTransaction() // clear the "changed" flags in current state // clear the "changed" flags in current state mCurrentState.colorMatrixChanged = false; mCurrentState.colorMatrixChanged = false; mDrawingState.traverseInZOrder([](Layer* layer) { layer->commitChildList(); }); mDrawingState.traverseInZOrder([&](Layer* layer) { layer->commitChildList(); // If the layer can be reached when traversing mDrawingState, then the layer is no // longer offscreen. Remove the layer from the offscreenLayer set. if (mOffscreenLayers.count(layer)) { mOffscreenLayers.erase(layer); } }); commitOffscreenLayers(); }); }); mTransactionPending = false; mTransactionPending = false; Loading Loading @@ -2985,6 +3002,18 @@ void SurfaceFlinger::withTracingLock(std::function<void()> lockedOperation) { } } } } void SurfaceFlinger::commitOffscreenLayers() { for (Layer* offscreenLayer : mOffscreenLayers) { offscreenLayer->traverseInZOrder(LayerVector::StateSet::Drawing, [](Layer* layer) { uint32_t trFlags = layer->getTransactionFlags(eTransactionNeeded); if (!trFlags) return; layer->doTransaction(0); layer->commitChildList(); }); } } void SurfaceFlinger::computeVisibleRegions(const sp<const DisplayDevice>& displayDevice, void SurfaceFlinger::computeVisibleRegions(const sp<const DisplayDevice>& displayDevice, Region& outDirtyRegion, Region& outOpaqueRegion) { Region& outDirtyRegion, Region& outOpaqueRegion) { ATRACE_CALL(); ATRACE_CALL(); Loading services/surfaceflinger/SurfaceFlinger.h +11 −1 Original line number Original line Diff line number Diff line Loading @@ -308,7 +308,10 @@ public: const sp<IGraphicBufferProducer>& bufferProducer) const; const sp<IGraphicBufferProducer>& bufferProducer) const; inline void onLayerCreated() { mNumLayers++; } inline void onLayerCreated() { mNumLayers++; } inline void onLayerDestroyed() { mNumLayers--; } inline void onLayerDestroyed(Layer* layer) { mNumLayers--; mOffscreenLayers.erase(layer); } TransactionCompletedThread& getTransactionCompletedThread() { TransactionCompletedThread& getTransactionCompletedThread() { return mTransactionCompletedThread; return mTransactionCompletedThread; Loading Loading @@ -563,6 +566,7 @@ private: uint32_t setTransactionFlags(uint32_t flags, Scheduler::TransactionStart transactionStart); uint32_t setTransactionFlags(uint32_t flags, Scheduler::TransactionStart transactionStart); void latchAndReleaseBuffer(const sp<Layer>& layer); void latchAndReleaseBuffer(const sp<Layer>& layer); void commitTransaction() REQUIRES(mStateLock); void commitTransaction() REQUIRES(mStateLock); void commitOffscreenLayers(); bool containsAnyInvalidClientState(const Vector<ComposerState>& states); bool containsAnyInvalidClientState(const Vector<ComposerState>& states); bool transactionIsReadyToBeApplied(int64_t desiredPresentTime, bool transactionIsReadyToBeApplied(int64_t desiredPresentTime, const Vector<ComposerState>& states); const Vector<ComposerState>& states); Loading Loading @@ -1152,6 +1156,12 @@ private: // Flag used to set override allowed display configs from backdoor // Flag used to set override allowed display configs from backdoor bool mDebugDisplayConfigSetByBackdoor = false; bool mDebugDisplayConfigSetByBackdoor = false; // A set of layers that have no parent so they are not drawn on screen. // Should only be accessed by the main thread. // The Layer pointer is removed from the set when the destructor is called so there shouldn't // be any issues with a raw pointer referencing an invalid object. std::unordered_set<Layer*> mOffscreenLayers; }; }; } // namespace android } // namespace android Loading
services/surfaceflinger/Layer.cpp +1 −1 Original line number Original line Diff line number Diff line Loading @@ -130,7 +130,7 @@ Layer::~Layer() { } } mFrameTracker.logAndResetStats(mName); mFrameTracker.logAndResetStats(mName); mFlinger->onLayerDestroyed(); mFlinger->onLayerDestroyed(this); } } // --------------------------------------------------------------------------- // --------------------------------------------------------------------------- Loading
services/surfaceflinger/SurfaceFlinger.cpp +30 −1 Original line number Original line Diff line number Diff line Loading @@ -2944,6 +2944,13 @@ void SurfaceFlinger::commitTransaction() if (l->isRemovedFromCurrentState()) { if (l->isRemovedFromCurrentState()) { latchAndReleaseBuffer(l); latchAndReleaseBuffer(l); } } // If the layer has been removed and has no parent, then it will not be reachable // when traversing layers on screen. Add the layer to the offscreenLayers set to // ensure we can copy its current to drawing state. if (!l->getParent()) { mOffscreenLayers.emplace(l.get()); } } } mLayersPendingRemoval.clear(); mLayersPendingRemoval.clear(); } } Loading @@ -2957,7 +2964,17 @@ void SurfaceFlinger::commitTransaction() // clear the "changed" flags in current state // clear the "changed" flags in current state mCurrentState.colorMatrixChanged = false; mCurrentState.colorMatrixChanged = false; mDrawingState.traverseInZOrder([](Layer* layer) { layer->commitChildList(); }); mDrawingState.traverseInZOrder([&](Layer* layer) { layer->commitChildList(); // If the layer can be reached when traversing mDrawingState, then the layer is no // longer offscreen. Remove the layer from the offscreenLayer set. if (mOffscreenLayers.count(layer)) { mOffscreenLayers.erase(layer); } }); commitOffscreenLayers(); }); }); mTransactionPending = false; mTransactionPending = false; Loading Loading @@ -2985,6 +3002,18 @@ void SurfaceFlinger::withTracingLock(std::function<void()> lockedOperation) { } } } } void SurfaceFlinger::commitOffscreenLayers() { for (Layer* offscreenLayer : mOffscreenLayers) { offscreenLayer->traverseInZOrder(LayerVector::StateSet::Drawing, [](Layer* layer) { uint32_t trFlags = layer->getTransactionFlags(eTransactionNeeded); if (!trFlags) return; layer->doTransaction(0); layer->commitChildList(); }); } } void SurfaceFlinger::computeVisibleRegions(const sp<const DisplayDevice>& displayDevice, void SurfaceFlinger::computeVisibleRegions(const sp<const DisplayDevice>& displayDevice, Region& outDirtyRegion, Region& outOpaqueRegion) { Region& outDirtyRegion, Region& outOpaqueRegion) { ATRACE_CALL(); ATRACE_CALL(); Loading
services/surfaceflinger/SurfaceFlinger.h +11 −1 Original line number Original line Diff line number Diff line Loading @@ -308,7 +308,10 @@ public: const sp<IGraphicBufferProducer>& bufferProducer) const; const sp<IGraphicBufferProducer>& bufferProducer) const; inline void onLayerCreated() { mNumLayers++; } inline void onLayerCreated() { mNumLayers++; } inline void onLayerDestroyed() { mNumLayers--; } inline void onLayerDestroyed(Layer* layer) { mNumLayers--; mOffscreenLayers.erase(layer); } TransactionCompletedThread& getTransactionCompletedThread() { TransactionCompletedThread& getTransactionCompletedThread() { return mTransactionCompletedThread; return mTransactionCompletedThread; Loading Loading @@ -563,6 +566,7 @@ private: uint32_t setTransactionFlags(uint32_t flags, Scheduler::TransactionStart transactionStart); uint32_t setTransactionFlags(uint32_t flags, Scheduler::TransactionStart transactionStart); void latchAndReleaseBuffer(const sp<Layer>& layer); void latchAndReleaseBuffer(const sp<Layer>& layer); void commitTransaction() REQUIRES(mStateLock); void commitTransaction() REQUIRES(mStateLock); void commitOffscreenLayers(); bool containsAnyInvalidClientState(const Vector<ComposerState>& states); bool containsAnyInvalidClientState(const Vector<ComposerState>& states); bool transactionIsReadyToBeApplied(int64_t desiredPresentTime, bool transactionIsReadyToBeApplied(int64_t desiredPresentTime, const Vector<ComposerState>& states); const Vector<ComposerState>& states); Loading Loading @@ -1152,6 +1156,12 @@ private: // Flag used to set override allowed display configs from backdoor // Flag used to set override allowed display configs from backdoor bool mDebugDisplayConfigSetByBackdoor = false; bool mDebugDisplayConfigSetByBackdoor = false; // A set of layers that have no parent so they are not drawn on screen. // Should only be accessed by the main thread. // The Layer pointer is removed from the set when the destructor is called so there shouldn't // be any issues with a raw pointer referencing an invalid object. std::unordered_set<Layer*> mOffscreenLayers; }; }; } // namespace android } // namespace android