Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5192a21b authored by Melody Hsu's avatar Melody Hsu
Browse files

Consolidate layer snapshot functions for screenshots

Merges layer snapshot functions into 1 and directly calls into
it to get snapshots for screenshots, reducing the need to
pass around a snapshot function.

Bug: b/377758217
Test: atest SurfaceFlinger_test, atest CompositionTest
Flag: EXEMPT, refactor
Change-Id: I02236342f77102b500d11b02882023eb71cab9df
parent 834e8bcd
Loading
Loading
Loading
Loading
+19 −17
Original line number Diff line number Diff line
@@ -339,8 +339,6 @@ void RegionSamplingThread::captureSample() {
        return layerFilterFn(snapshot.name.c_str(), snapshot.path.id, bounds, transform,
                             outStopTraversal);
    };
    auto getLayerSnapshotsFn =
            mFlinger.getLayerSnapshotsForScreenshots(layerStack, CaptureArgs::UNSET_UID, filterFn);

    std::shared_ptr<renderengine::ExternalTexture> buffer = nullptr;
    if (mCachedBuffer && mCachedBuffer->getBuffer()->getWidth() == sampledBounds.getWidth() &&
@@ -361,11 +359,16 @@ void RegionSamplingThread::captureSample() {
                                                             WRITEABLE);
    }

    SurfaceFlinger::ScreenshotArgs screenshotArgs{.captureTypeVariant = displayWeak,
    SurfaceFlinger::ScreenshotArgs
            screenshotArgs{.captureTypeVariant = displayWeak,
                           .displayIdVariant = std::nullopt,
                                                  .sourceCrop = sampledBounds.isEmpty()
                                                          ? layerStackSpaceRect
                                                          : sampledBounds,
                           .snapshotRequest =
                                   SurfaceFlinger::SnapshotRequestArgs{.uid = gui::Uid::INVALID,
                                                                       .layerStack = layerStack,
                                                                       .snapshotFilterFn =
                                                                               filterFn},
                           .sourceCrop =
                                   sampledBounds.isEmpty() ? layerStackSpaceRect : sampledBounds,
                           .size = sampledBounds.getSize(),
                           .dataspace = ui::Dataspace::V0_SRGB,
                           .disableBlur = true,
@@ -375,9 +378,8 @@ void RegionSamplingThread::captureSample() {
                           .debugName = "RegionSampling"};

    std::vector<std::pair<Layer*, sp<LayerFE>>> layers;
    mFlinger.getSnapshotsFromMainThread(screenshotArgs, getLayerSnapshotsFn, layers);
    FenceResult fenceResult =
            mFlinger.captureScreenshot(screenshotArgs, buffer, nullptr, layers).get();
    mFlinger.getSnapshotsFromMainThread(screenshotArgs);
    FenceResult fenceResult = mFlinger.captureScreenshot(screenshotArgs, buffer, nullptr).get();
    if (fenceResult.ok()) {
        fenceResult.value()->waitForever(LOG_TAG);
    }
+95 −137

File changed.

Preview size limit exceeded, changes collapsed.

+31 −19

File changed.

Preview size limit exceeded, changes collapsed.

+4 −4
Original line number Diff line number Diff line
@@ -197,8 +197,8 @@ void CompositionTest::captureScreenComposition() {

    const Rect sourceCrop(0, 0, DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT);

    auto getLayerSnapshotsFn = mFlinger.getLayerSnapshotsForScreenshotsFn(mDisplay->getLayerStack(),
                                                                          CaptureArgs::UNSET_UID);
    auto layers =
            mFlinger.getLayerSnapshotsForScreenshots(mDisplay->getLayerStack(), gui::Uid::INVALID);

    const uint32_t usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN |
            GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE;
@@ -208,8 +208,8 @@ void CompositionTest::captureScreenComposition() {
                                                                      HAL_PIXEL_FORMAT_RGBA_8888, 1,
                                                                      usage);

    auto future = mFlinger.renderScreenImpl(mDisplay, sourceCrop, ui::Dataspace::V0_SRGB,
                                            getLayerSnapshotsFn, mCaptureScreenBuffer,
    auto future = mFlinger.renderScreenImpl(mDisplay, sourceCrop, ui::Dataspace::V0_SRGB, layers,
                                            mCaptureScreenBuffer,
                                            /* disableBlur */ false, mDisplay->isSecure(),
                                            /* seamlessTransition */ true);
    ASSERT_TRUE(future.valid());
+9 −6

File changed.

Preview size limit exceeded, changes collapsed.