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

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

Merge changes I02236342,I5e693d91,I0d3c09d4 into main

* changes:
  Consolidate layer snapshot functions for screenshots
  Encapsulate excludeLayerId logic into a function
  Cleaner ScreenshotArg struct init, function parameter cleanup
parents 2c540b72 5192a21b
Loading
Loading
Loading
Loading
+19 −18
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,24 +359,27 @@ void RegionSamplingThread::captureSample() {
                                                             WRITEABLE);
    }

    constexpr bool kRegionSampling = true;
    constexpr bool kGrayscale = false;
    constexpr bool kIsProtected = false;

    SurfaceFlinger::ScreenshotArgs screenshotArgs;
    screenshotArgs.captureTypeVariant = displayWeak;
    screenshotArgs.displayIdVariant = std::nullopt;
    screenshotArgs.sourceCrop = sampledBounds.isEmpty() ? layerStackSpaceRect : sampledBounds;
    screenshotArgs.reqSize = sampledBounds.getSize();
    screenshotArgs.dataspace = ui::Dataspace::V0_SRGB;
    screenshotArgs.isSecure = true;
    screenshotArgs.seamlessTransition = false;
    SurfaceFlinger::ScreenshotArgs
            screenshotArgs{.captureTypeVariant = displayWeak,
                           .displayIdVariant = std::nullopt,
                           .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,
                           .isGrayscale = false,
                           .isSecure = true,
                           .seamlessTransition = false,
                           .debugName = "RegionSampling"};

    std::vector<std::pair<Layer*, sp<LayerFE>>> layers;
    mFlinger.getSnapshotsFromMainThread(screenshotArgs, getLayerSnapshotsFn, layers);
    FenceResult fenceResult = mFlinger.captureScreenshot(screenshotArgs, buffer, kRegionSampling,
                                                         kGrayscale, kIsProtected, nullptr, layers)
                                      .get();
    mFlinger.getSnapshotsFromMainThread(screenshotArgs);
    FenceResult fenceResult = mFlinger.captureScreenshot(screenshotArgs, buffer, nullptr).get();
    if (fenceResult.ok()) {
        fenceResult.value()->waitForever(LOG_TAG);
    }
+9 −18
Original line number Diff line number Diff line
@@ -33,13 +33,12 @@ std::shared_ptr<ScreenCaptureOutput> createScreenCaptureOutput(ScreenCaptureOutp
            /* sourceCrop */ const Rect, ftl::Optional<DisplayIdVariant>,
            const compositionengine::Output::ColorProfile&,
            /* layerAlpha */ float,
            /* regionSampling */ bool>(args.compositionEngine, args.sourceCrop,
                                       args.displayIdVariant, args.colorProfile, args.layerAlpha,
                                       args.regionSampling,
            /* disableBlur */ bool>(args.compositionEngine, args.sourceCrop, args.displayIdVariant,
                                    args.colorProfile, args.layerAlpha, args.disableBlur,
                                    args.dimInGammaSpaceForEnhancedScreenshots,
                                    args.enableLocalTonemapping);
    output->editState().isSecure = args.isSecure;
    output->editState().isProtected = args.isProtected;
    output->editState().isProtected = args.buffer->getUsage() & GRALLOC_USAGE_PROTECTED;
    output->setCompositionEnabled(true);
    output->setLayerFilter({args.layerStack});
    output->setRenderSurface(std::make_unique<ScreenCaptureRenderSurface>(std::move(args.buffer)));
@@ -57,27 +56,19 @@ std::shared_ptr<ScreenCaptureOutput> createScreenCaptureOutput(ScreenCaptureOutp
    output->setDisplaySize({sourceCrop.getWidth(), sourceCrop.getHeight()});
    output->setProjection(orientation, sourceCrop,
                          {args.reqBufferSize.width, args.reqBufferSize.height});

    {
        std::string name = args.regionSampling ? "RegionSampling" : "ScreenCaptureOutput";
        if (const auto id = args.displayIdVariant.and_then(asDisplayIdOfType<DisplayId>)) {
            base::StringAppendF(&name, " for %" PRIu64, id->value);
        }
        output->setName(name);
    }
    output->setName(args.debugName);
    return output;
}

ScreenCaptureOutput::ScreenCaptureOutput(
        const Rect sourceCrop, ftl::Optional<DisplayIdVariant> displayIdVariant,
        const compositionengine::Output::ColorProfile& colorProfile, float layerAlpha,
        bool regionSampling, bool dimInGammaSpaceForEnhancedScreenshots,
        bool enableLocalTonemapping)
        bool disableBlur, bool dimInGammaSpaceForEnhancedScreenshots, bool enableLocalTonemapping)
      : mSourceCrop(sourceCrop),
        mDisplayIdVariant(displayIdVariant),
        mColorProfile(colorProfile),
        mLayerAlpha(layerAlpha),
        mRegionSampling(regionSampling),
        mDisableBlur(disableBlur),
        mDimInGammaSpaceForEnhancedScreenshots(dimInGammaSpaceForEnhancedScreenshots),
        mEnableLocalTonemapping(enableLocalTonemapping) {}

@@ -189,7 +180,7 @@ ScreenCaptureOutput::generateClientCompositionRequests(
        }
    }

    if (mRegionSampling) {
    if (mDisableBlur) {
        for (auto& layer : clientCompositionLayers) {
            layer.backgroundBlurRadius = 0;
            layer.blurRegions.clear();
+4 −4
Original line number Diff line number Diff line
@@ -37,12 +37,12 @@ struct ScreenCaptureOutputArgs {
    // Counterintuitively, when targetBrightness > 1.0 then dim the scene.
    float targetBrightness;
    float layerAlpha;
    bool regionSampling;
    bool disableBlur;
    bool treat170mAsSrgb;
    bool dimInGammaSpaceForEnhancedScreenshots;
    bool isSecure = false;
    bool isProtected = false;
    bool enableLocalTonemapping = false;
    std::string debugName;
};

// ScreenCaptureOutput is used to compose a set of layers into a preallocated buffer.
@@ -53,7 +53,7 @@ class ScreenCaptureOutput : public compositionengine::impl::Output {
public:
    ScreenCaptureOutput(const Rect sourceCrop, ftl::Optional<DisplayIdVariant> displayIdVariant,
                        const compositionengine::Output::ColorProfile& colorProfile,
                        float layerAlpha, bool regionSampling,
                        float layerAlpha, bool disableBlur,
                        bool dimInGammaSpaceForEnhancedScreenshots, bool enableLocalTonemapping);

    void updateColorProfile(const compositionengine::CompositionRefreshArgs&) override;
@@ -73,7 +73,7 @@ private:
    const ftl::Optional<DisplayIdVariant> mDisplayIdVariant;
    const compositionengine::Output::ColorProfile& mColorProfile;
    const float mLayerAlpha;
    const bool mRegionSampling;
    const bool mDisableBlur;
    const bool mDimInGammaSpaceForEnhancedScreenshots;
    const bool mEnableLocalTonemapping;
};
Loading