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

Commit 03a8ff5c authored by Melody Hsu's avatar Melody Hsu Committed by Android (Google) Code Review
Browse files

Merge "Remove legacy layer path in screenshot pathway" into main

parents 683fe045 eddfe939
Loading
Loading
Loading
Loading
+10 −34
Original line number Diff line number Diff line
@@ -315,39 +315,15 @@ void RegionSamplingThread::captureSample() {
        return true;
    };

    std::function<std::vector<std::pair<Layer*, sp<LayerFE>>>()> getLayerSnapshots;
    if (mFlinger.mLayerLifecycleManagerEnabled) {
        auto filterFn = [&](const frontend::LayerSnapshot& snapshot,
                            bool& outStopTraversal) -> bool {
            const Rect bounds =
                    frontend::RequestedLayerState::reduce(Rect(snapshot.geomLayerBounds),
    auto filterFn = [&](const frontend::LayerSnapshot& snapshot, bool& outStopTraversal) -> bool {
        const Rect bounds = frontend::RequestedLayerState::reduce(Rect(snapshot.geomLayerBounds),
                                                                  snapshot.transparentRegionHint);
        const ui::Transform transform = snapshot.geomLayerTransform;
        return layerFilterFn(snapshot.name.c_str(), snapshot.path.id, bounds, transform,
                             outStopTraversal);
    };
        getLayerSnapshots =
                mFlinger.getLayerSnapshotsForScreenshots(layerStack, CaptureArgs::UNSET_UID,
                                                         filterFn);
    } else {
        auto traverseLayers = [&](const LayerVector::Visitor& visitor) {
            bool stopLayerFound = false;
            auto filterVisitor = [&](Layer* layer) {
                // We don't want to capture any layers beyond the stop layer
                if (stopLayerFound) return;

                if (!layerFilterFn(layer->getDebugName(), layer->getSequence(),
                                   Rect(layer->getBounds()), layer->getTransform(),
                                   stopLayerFound)) {
                    return;
                }
                visitor(layer);
            };
            mFlinger.traverseLayersInLayerStack(layerStack, CaptureArgs::UNSET_UID, {},
                                                filterVisitor);
        };
        getLayerSnapshots = RenderArea::fromTraverseLayersLambda(traverseLayers);
    }
    auto getLayerSnapshotsFn =
            mFlinger.getLayerSnapshotsForScreenshots(layerStack, CaptureArgs::UNSET_UID, filterFn);

    std::shared_ptr<renderengine::ExternalTexture> buffer = nullptr;
    if (mCachedBuffer && mCachedBuffer->getBuffer()->getWidth() == sampledBounds.getWidth() &&
@@ -379,7 +355,7 @@ void RegionSamplingThread::captureSample() {
                                                   ui::Dataspace::V0_SRGB,
                                                   kHintForSeamlessTransition,
                                                   true /* captureSecureLayers */, displayWeak),
                                           getLayerSnapshots, buffer, kRegionSampling, kGrayscale,
                                           getLayerSnapshotsFn, buffer, kRegionSampling, kGrayscale,
                                           kIsProtected, nullptr)
                        .get();
        fenceResult.ok()) {
+19 −61
Original line number Diff line number Diff line
@@ -7932,23 +7932,14 @@ void SurfaceFlinger::captureDisplay(const DisplayCaptureArgs& args,
        }
    }

    GetLayerSnapshotsFunction getLayerSnapshots;
    if (mLayerLifecycleManagerEnabled) {
        getLayerSnapshots =
    GetLayerSnapshotsFunction getLayerSnapshotsFn =
            getLayerSnapshotsForScreenshots(layerStack, args.uid, std::move(excludeLayerIds));
    } else {
        auto traverseLayers = [this, args, excludeLayerIds,
                               layerStack](const LayerVector::Visitor& visitor) {
            traverseLayersInLayerStack(layerStack, args.uid, std::move(excludeLayerIds), visitor);
        };
        getLayerSnapshots = RenderArea::fromTraverseLayersLambda(traverseLayers);
    }

    captureScreenCommon(RenderAreaBuilderVariant(std::in_place_type<DisplayRenderAreaBuilder>,
                                                 args.sourceCrop, reqSize, args.dataspace,
                                                 args.hintForSeamlessTransition,
                                                 args.captureSecureLayers, displayWeak),
                        getLayerSnapshots, reqSize, args.pixelFormat, args.allowProtected,
                        getLayerSnapshotsFn, reqSize, args.pixelFormat, args.allowProtected,
                        args.grayscale, captureListener);
}

@@ -7985,16 +7976,9 @@ void SurfaceFlinger::captureDisplay(DisplayId displayId, const CaptureArgs& args
        return;
    }

    GetLayerSnapshotsFunction getLayerSnapshots;
    if (mLayerLifecycleManagerEnabled) {
        getLayerSnapshots = getLayerSnapshotsForScreenshots(layerStack, CaptureArgs::UNSET_UID,
    GetLayerSnapshotsFunction getLayerSnapshotsFn =
            getLayerSnapshotsForScreenshots(layerStack, CaptureArgs::UNSET_UID,
                                            /*snapshotFilterFn=*/nullptr);
    } else {
        auto traverseLayers = [this, layerStack](const LayerVector::Visitor& visitor) {
            traverseLayersInLayerStack(layerStack, CaptureArgs::UNSET_UID, {}, visitor);
        };
        getLayerSnapshots = RenderArea::fromTraverseLayersLambda(traverseLayers);
    }

    if (captureListener == nullptr) {
        ALOGE("capture screen must provide a capture listener callback");
@@ -8009,7 +7993,7 @@ void SurfaceFlinger::captureDisplay(DisplayId displayId, const CaptureArgs& args
                                                 Rect(), size, args.dataspace,
                                                 args.hintForSeamlessTransition,
                                                 false /* captureSecureLayers */, displayWeak),
                        getLayerSnapshots, size, args.pixelFormat, kAllowProtected, kGrayscale,
                        getLayerSnapshotsFn, size, args.pixelFormat, kAllowProtected, kGrayscale,
                        captureListener);
}

@@ -8091,41 +8075,15 @@ void SurfaceFlinger::captureLayers(const LayerCaptureArgs& args,
        return;
    }

    GetLayerSnapshotsFunction getLayerSnapshots;
    if (mLayerLifecycleManagerEnabled) {
    std::optional<FloatRect> parentCrop = std::nullopt;
    if (args.childrenOnly) {
        parentCrop = crop.isEmpty() ? FloatRect(0, 0, reqSize.width, reqSize.height)
                                    : crop.toFloatRect();
    }

        getLayerSnapshots = getLayerSnapshotsForScreenshots(parent->sequence, args.uid,
                                                            std::move(excludeLayerIds),
    GetLayerSnapshotsFunction getLayerSnapshotsFn =
            getLayerSnapshotsForScreenshots(parent->sequence, args.uid, std::move(excludeLayerIds),
                                            args.childrenOnly, parentCrop);
    } else {
        auto traverseLayers = [parent, args, excludeLayerIds](const LayerVector::Visitor& visitor) {
            parent->traverseChildrenInZOrder(LayerVector::StateSet::Drawing, [&](Layer* layer) {
                if (!layer->isVisible()) {
                    return;
                } else if (args.childrenOnly && layer == parent.get()) {
                    return;
                } else if (args.uid != CaptureArgs::UNSET_UID && args.uid != layer->getOwnerUid()) {
                    return;
                }

                auto p = sp<Layer>::fromExisting(layer);
                while (p != nullptr) {
                    if (excludeLayerIds.count(p->sequence) != 0) {
                        return;
                    }
                    p = p->getParent();
                }

                visitor(layer);
            });
        };
        getLayerSnapshots = RenderArea::fromTraverseLayersLambda(traverseLayers);
    }

    if (captureListener == nullptr) {
        ALOGD("capture screen must provide a capture listener callback");
@@ -8137,7 +8095,7 @@ void SurfaceFlinger::captureLayers(const LayerCaptureArgs& args,
                                                 reqSize, dataspace, args.captureSecureLayers,
                                                 args.hintForSeamlessTransition, parent,
                                                 args.childrenOnly),
                        getLayerSnapshots, reqSize, args.pixelFormat, args.allowProtected,
                        getLayerSnapshotsFn, reqSize, args.pixelFormat, args.allowProtected,
                        args.grayscale, captureListener);
}

@@ -8166,7 +8124,7 @@ bool SurfaceFlinger::layersHasProtectedLayer(
}

void SurfaceFlinger::captureScreenCommon(RenderAreaBuilderVariant renderAreaBuilder,
                                         GetLayerSnapshotsFunction getLayerSnapshots,
                                         GetLayerSnapshotsFunction getLayerSnapshotsFn,
                                         ui::Size bufferSize, ui::PixelFormat reqPixelFormat,
                                         bool allowProtected, bool grayscale,
                                         const sp<IScreenCaptureListener>& captureListener) {
@@ -8187,7 +8145,7 @@ void SurfaceFlinger::captureScreenCommon(RenderAreaBuilderVariant renderAreaBuil
    const bool supportsProtected = getRenderEngine().supportsProtectedContent();
    bool hasProtectedLayer = false;
    if (allowProtected && supportsProtected) {
        auto layers = mScheduler->schedule([=]() { return getLayerSnapshots(); }).get();
        auto layers = mScheduler->schedule([=]() { return getLayerSnapshotsFn(); }).get();
        hasProtectedLayer = layersHasProtectedLayer(layers);
    }
    const bool isProtected = hasProtectedLayer && allowProtected && supportsProtected;
@@ -8214,7 +8172,7 @@ void SurfaceFlinger::captureScreenCommon(RenderAreaBuilderVariant renderAreaBuil
                                                 renderengine::impl::ExternalTexture::Usage::
                                                         WRITEABLE);
    auto futureFence =
            captureScreenshot(renderAreaBuilder, getLayerSnapshots, texture,
            captureScreenshot(renderAreaBuilder, getLayerSnapshotsFn, texture,
                              false /* regionSampling */, grayscale, isProtected, captureListener);
    futureFence.get();
}
+3 −2
Original line number Diff line number Diff line
@@ -205,7 +205,8 @@ void CompositionTest::captureScreenComposition() {
                                                   CaptureArgs::UNSET_UID, {}, visitor);
    };

    auto getLayerSnapshots = RenderArea::fromTraverseLayersLambda(traverseLayers);
    // TODO: Use SurfaceFlinger::getLayerSnapshotsForScreenshots instead of this legacy function
    auto getLayerSnapshotsFn = RenderArea::fromTraverseLayersLambda(traverseLayers);

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

    auto future = mFlinger.renderScreenImpl(mDisplay, std::move(renderArea), getLayerSnapshots,
    auto future = mFlinger.renderScreenImpl(mDisplay, std::move(renderArea), getLayerSnapshotsFn,
                                            mCaptureScreenBuffer, regionSampling);
    ASSERT_TRUE(future.valid());
    const auto fenceResult = future.get();
+3 −4
Original line number Diff line number Diff line
@@ -487,7 +487,7 @@ public:

    auto renderScreenImpl(const sp<DisplayDevice> display,
                          std::unique_ptr<const RenderArea> renderArea,
                          SurfaceFlinger::GetLayerSnapshotsFunction traverseLayers,
                          SurfaceFlinger::GetLayerSnapshotsFunction getLayerSnapshotsFn,
                          const std::shared_ptr<renderengine::ExternalTexture>& buffer,
                          bool regionSampling) {
        Mutex::Autolock lock(mFlinger->mStateLock);
@@ -495,7 +495,7 @@ public:

        ScreenCaptureResults captureResults;
        SurfaceFlinger::OutputCompositionState state = display->getCompositionDisplay()->getState();
        auto layers = mFlinger->getLayerSnapshotsFromMainThread(traverseLayers);
        auto layers = mFlinger->getLayerSnapshotsFromMainThread(getLayerSnapshotsFn);

        return mFlinger->renderScreenImpl(std::move(renderArea), buffer, regionSampling,
                                          false /* grayscale */, false /* isProtected */,
@@ -505,8 +505,7 @@ public:
    auto traverseLayersInLayerStack(ui::LayerStack layerStack, int32_t uid,
                                    std::unordered_set<uint32_t> excludeLayerIds,
                                    const LayerVector::Visitor& visitor) {
        return mFlinger->SurfaceFlinger::traverseLayersInLayerStack(layerStack, uid,
                                                                    excludeLayerIds, visitor);
        return mFlinger->traverseLayersInLayerStack(layerStack, uid, excludeLayerIds, visitor);
    }

    auto getDisplayNativePrimaries(const sp<IBinder>& displayToken,