From 5b3d97658c251f80e7147fab23886fc6466d0d2b Mon Sep 17 00:00:00 2001 From: Melody Hsu Date: Tue, 28 Jan 2025 21:22:52 +0000 Subject: Extract RenderArea elements into screenshot args Removes Renderarea and its child classes + builders and provides its elements in a parameter struct. This is a step toward untangling dependencies on legacy layer, SF state lock, and separating screenshot logic into a separate class. Bug: b/377758217 Test: atest SurfaceFlinger_test, atest CompositionTest Test: presubmit, screenshots, screen lock/unlock Flag: EXEMPT, refactor Change-Id: Id92f2697101f07e1fac50a6f6a770ad6d762ad8b --- services/surfaceflinger/ScreenCaptureOutput.cpp | 42 +++++++++++++++---------- 1 file changed, 25 insertions(+), 17 deletions(-) (limited to 'services/surfaceflinger/ScreenCaptureOutput.cpp') diff --git a/services/surfaceflinger/ScreenCaptureOutput.cpp b/services/surfaceflinger/ScreenCaptureOutput.cpp index 5f71b88d01..712390574f 100644 --- a/services/surfaceflinger/ScreenCaptureOutput.cpp +++ b/services/surfaceflinger/ScreenCaptureOutput.cpp @@ -29,11 +29,15 @@ namespace android { std::shared_ptr createScreenCaptureOutput(ScreenCaptureOutputArgs args) { std::shared_ptr output = compositionengine::impl::createOutputTemplated< - ScreenCaptureOutput, compositionengine::CompositionEngine, const RenderArea&, + ScreenCaptureOutput, compositionengine::CompositionEngine, + /* sourceCrop */ const Rect, std::optional, const compositionengine::Output::ColorProfile&, - bool>(args.compositionEngine, args.renderArea, args.colorProfile, args.regionSampling, - args.dimInGammaSpaceForEnhancedScreenshots, args.enableLocalTonemapping); - output->editState().isSecure = args.renderArea.isSecure(); + /* layerAlpha */ float, + /* regionSampling */ bool>(args.compositionEngine, args.sourceCrop, args.displayId, + args.colorProfile, args.layerAlpha, args.regionSampling, + args.dimInGammaSpaceForEnhancedScreenshots, + args.enableLocalTonemapping); + output->editState().isSecure = args.isSecure; output->editState().isProtected = args.isProtected; output->setCompositionEnabled(true); output->setLayerFilter({args.layerStack}); @@ -47,16 +51,16 @@ std::shared_ptr createScreenCaptureOutput(ScreenCaptureOutp .setHasWideColorGamut(true) .Build())); - const Rect& sourceCrop = args.renderArea.getSourceCrop(); + const Rect& sourceCrop = args.sourceCrop; const ui::Rotation orientation = ui::ROTATION_0; output->setDisplaySize({sourceCrop.getWidth(), sourceCrop.getHeight()}); output->setProjection(orientation, sourceCrop, - {args.renderArea.getReqWidth(), args.renderArea.getReqHeight()}); + {args.reqBufferSize.width, args.reqBufferSize.height}); { std::string name = args.regionSampling ? "RegionSampling" : "ScreenCaptureOutput"; - if (auto displayDevice = args.renderArea.getDisplayDevice()) { - base::StringAppendF(&name, " for %" PRIu64, displayDevice->getId().value); + if (args.displayId) { + base::StringAppendF(&name, " for %" PRIu64, args.displayId.value().value); } output->setName(name); } @@ -64,11 +68,14 @@ std::shared_ptr createScreenCaptureOutput(ScreenCaptureOutp } ScreenCaptureOutput::ScreenCaptureOutput( - const RenderArea& renderArea, const compositionengine::Output::ColorProfile& colorProfile, + const Rect sourceCrop, std::optional displayId, + const compositionengine::Output::ColorProfile& colorProfile, float layerAlpha, bool regionSampling, bool dimInGammaSpaceForEnhancedScreenshots, bool enableLocalTonemapping) - : mRenderArea(renderArea), + : mSourceCrop(sourceCrop), + mDisplayId(displayId), mColorProfile(colorProfile), + mLayerAlpha(layerAlpha), mRegionSampling(regionSampling), mDimInGammaSpaceForEnhancedScreenshots(dimInGammaSpaceForEnhancedScreenshots), mEnableLocalTonemapping(enableLocalTonemapping) {} @@ -83,7 +90,7 @@ renderengine::DisplaySettings ScreenCaptureOutput::generateClientCompositionDisp const std::shared_ptr& buffer) const { auto clientCompositionDisplay = compositionengine::impl::Output::generateClientCompositionDisplaySettings(buffer); - clientCompositionDisplay.clip = mRenderArea.getSourceCrop(); + clientCompositionDisplay.clip = mSourceCrop; auto renderIntent = static_cast(clientCompositionDisplay.renderIntent); if (mDimInGammaSpaceForEnhancedScreenshots && renderIntent != ui::RenderIntent::COLORIMETRIC && @@ -130,8 +137,8 @@ ScreenCaptureOutput::generateLuts() { } std::vector luts; - if (auto displayDevice = mRenderArea.getDisplayDevice()) { - const auto id = PhysicalDisplayId::tryCast(displayDevice->getId()); + if (mDisplayId) { + const auto id = PhysicalDisplayId::tryCast(mDisplayId.value()); if (id) { auto& hwc = getCompositionEngine().getHwComposer(); hwc.getLuts(*id, buffers, &luts); @@ -201,14 +208,15 @@ ScreenCaptureOutput::generateClientCompositionRequests( } } - Rect sourceCrop = mRenderArea.getSourceCrop(); compositionengine::LayerFE::LayerSettings fillLayer; fillLayer.source.buffer.buffer = nullptr; fillLayer.source.solidColor = half3(0.0f, 0.0f, 0.0f); fillLayer.geometry.boundaries = - FloatRect(static_cast(sourceCrop.left), static_cast(sourceCrop.top), - static_cast(sourceCrop.right), static_cast(sourceCrop.bottom)); - fillLayer.alpha = half(RenderArea::getCaptureFillValue(mRenderArea.getCaptureFill())); + FloatRect(static_cast(mSourceCrop.left), static_cast(mSourceCrop.top), + static_cast(mSourceCrop.right), + static_cast(mSourceCrop.bottom)); + + fillLayer.alpha = half(mLayerAlpha); clientCompositionLayers.insert(clientCompositionLayers.begin(), fillLayer); return clientCompositionLayers; -- cgit v1.2.3-59-g8ed1b