From fef0c61c9ccc1c0ca08ef4e8538d86d5e892e682 Mon Sep 17 00:00:00 2001 From: Prabir Pradhan Date: Thu, 4 Nov 2021 14:08:50 -0700 Subject: SpriteController: Reparent pointer surfaces under DisplayContent When using MediaProjection to mirror a display, only surfaces that are inside the mirrored DisplayContent's hierarcy show up in the mirror surface. Previously, since pointer icons created by SpriteController were not part of SF's hierarcy under the DisplayContent's SurfaceControl, they did not show up in the mirror surface. In this CL, we reparent pointer sprite surfaces to the the DisplayContent's SurfaceControl whenever there are surface changes, ensuring that they show up in screen recordings. Bug: 202258016 Test: manual: Start screen recording from quick settings tile Change-Id: Ib404ed36bd13b0fc8cc4a6fb593dc54b3e35dd1a --- libs/input/SpriteController.cpp | 11 ++++++----- libs/input/SpriteController.h | 4 +++- libs/input/tests/mocks/MockSpriteController.h | 3 ++- 3 files changed, 11 insertions(+), 7 deletions(-) (limited to 'libs/input') diff --git a/libs/input/SpriteController.cpp b/libs/input/SpriteController.cpp index 0c6dac02453a..da21438bafd1 100644 --- a/libs/input/SpriteController.cpp +++ b/libs/input/SpriteController.cpp @@ -27,10 +27,12 @@ namespace android { // --- SpriteController --- -SpriteController::SpriteController(const sp& looper, int32_t overlayLayer) : - mLooper(looper), mOverlayLayer(overlayLayer) { +SpriteController::SpriteController(const sp& looper, int32_t overlayLayer, + ParentSurfaceProvider parentSurfaceProvider) + : mLooper(looper), + mOverlayLayer(overlayLayer), + mParentSurfaceProvider(std::move(parentSurfaceProvider)) { mHandler = new WeakMessageHandler(this); - mLocked.transactionNestingCount = 0; mLocked.deferredSpriteUpdate = false; } @@ -168,8 +170,7 @@ void SpriteController::doUpdateSprites() { // If surface is a new one, we have to set right layer stack. if (update.surfaceChanged || update.state.dirty & DIRTY_DISPLAY_ID) { - t.setLayerStack(update.state.surfaceControl, - ui::LayerStack::fromValue(update.state.displayId)); + t.reparent(update.state.surfaceControl, mParentSurfaceProvider(update.state.displayId)); needApplyTransaction = true; } } diff --git a/libs/input/SpriteController.h b/libs/input/SpriteController.h index 137b5646feae..2a80d9579711 100644 --- a/libs/input/SpriteController.h +++ b/libs/input/SpriteController.h @@ -114,7 +114,8 @@ protected: virtual ~SpriteController(); public: - SpriteController(const sp& looper, int32_t overlayLayer); + using ParentSurfaceProvider = std::function(int /*displayId*/)>; + SpriteController(const sp& looper, int32_t overlayLayer, ParentSurfaceProvider parent); /* Creates a new sprite, initially invisible. */ virtual sp createSprite(); @@ -245,6 +246,7 @@ private: sp mLooper; const int32_t mOverlayLayer; sp mHandler; + ParentSurfaceProvider mParentSurfaceProvider; sp mSurfaceComposerClient; diff --git a/libs/input/tests/mocks/MockSpriteController.h b/libs/input/tests/mocks/MockSpriteController.h index a034f66c9abf..62f1d65e77a5 100644 --- a/libs/input/tests/mocks/MockSpriteController.h +++ b/libs/input/tests/mocks/MockSpriteController.h @@ -26,7 +26,8 @@ namespace android { class MockSpriteController : public SpriteController { public: - MockSpriteController(sp looper) : SpriteController(looper, 0) {} + MockSpriteController(sp looper) + : SpriteController(looper, 0, [](int) { return nullptr; }) {} ~MockSpriteController() {} MOCK_METHOD(sp, createSprite, (), (override)); -- cgit v1.2.3-59-g8ed1b