xref: /aosp_15_r20/frameworks/native/services/surfaceflinger/ScreenCaptureOutput.h (revision 38e8c45f13ce32b0dcecb25141ffecaf386fa17f)
1*38e8c45fSAndroid Build Coastguard Worker /*
2*38e8c45fSAndroid Build Coastguard Worker  * Copyright 2022 The Android Open Source Project
3*38e8c45fSAndroid Build Coastguard Worker  *
4*38e8c45fSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*38e8c45fSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*38e8c45fSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*38e8c45fSAndroid Build Coastguard Worker  *
8*38e8c45fSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*38e8c45fSAndroid Build Coastguard Worker  *
10*38e8c45fSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*38e8c45fSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*38e8c45fSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*38e8c45fSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*38e8c45fSAndroid Build Coastguard Worker  * limitations under the License.
15*38e8c45fSAndroid Build Coastguard Worker  */
16*38e8c45fSAndroid Build Coastguard Worker 
17*38e8c45fSAndroid Build Coastguard Worker #pragma once
18*38e8c45fSAndroid Build Coastguard Worker 
19*38e8c45fSAndroid Build Coastguard Worker #include <compositionengine/DisplayColorProfile.h>
20*38e8c45fSAndroid Build Coastguard Worker #include <compositionengine/RenderSurface.h>
21*38e8c45fSAndroid Build Coastguard Worker #include <compositionengine/impl/Output.h>
22*38e8c45fSAndroid Build Coastguard Worker #include <ui/Rect.h>
23*38e8c45fSAndroid Build Coastguard Worker 
24*38e8c45fSAndroid Build Coastguard Worker #include "RenderArea.h"
25*38e8c45fSAndroid Build Coastguard Worker 
26*38e8c45fSAndroid Build Coastguard Worker namespace android {
27*38e8c45fSAndroid Build Coastguard Worker 
28*38e8c45fSAndroid Build Coastguard Worker struct ScreenCaptureOutputArgs {
29*38e8c45fSAndroid Build Coastguard Worker     const compositionengine::CompositionEngine& compositionEngine;
30*38e8c45fSAndroid Build Coastguard Worker     const compositionengine::Output::ColorProfile& colorProfile;
31*38e8c45fSAndroid Build Coastguard Worker     const RenderArea& renderArea;
32*38e8c45fSAndroid Build Coastguard Worker     ui::LayerStack layerStack;
33*38e8c45fSAndroid Build Coastguard Worker     std::shared_ptr<renderengine::ExternalTexture> buffer;
34*38e8c45fSAndroid Build Coastguard Worker     float sdrWhitePointNits;
35*38e8c45fSAndroid Build Coastguard Worker     float displayBrightnessNits;
36*38e8c45fSAndroid Build Coastguard Worker     // Counterintuitively, when targetBrightness > 1.0 then dim the scene.
37*38e8c45fSAndroid Build Coastguard Worker     float targetBrightness;
38*38e8c45fSAndroid Build Coastguard Worker     bool regionSampling;
39*38e8c45fSAndroid Build Coastguard Worker     bool treat170mAsSrgb;
40*38e8c45fSAndroid Build Coastguard Worker     bool dimInGammaSpaceForEnhancedScreenshots;
41*38e8c45fSAndroid Build Coastguard Worker     bool isProtected = false;
42*38e8c45fSAndroid Build Coastguard Worker     bool enableLocalTonemapping = false;
43*38e8c45fSAndroid Build Coastguard Worker };
44*38e8c45fSAndroid Build Coastguard Worker 
45*38e8c45fSAndroid Build Coastguard Worker // ScreenCaptureOutput is used to compose a set of layers into a preallocated buffer.
46*38e8c45fSAndroid Build Coastguard Worker //
47*38e8c45fSAndroid Build Coastguard Worker // SurfaceFlinger passes instances of ScreenCaptureOutput to CompositionEngine in calls to
48*38e8c45fSAndroid Build Coastguard Worker // SurfaceFlinger::captureLayers and SurfaceFlinger::captureDisplay.
49*38e8c45fSAndroid Build Coastguard Worker class ScreenCaptureOutput : public compositionengine::impl::Output {
50*38e8c45fSAndroid Build Coastguard Worker public:
51*38e8c45fSAndroid Build Coastguard Worker     ScreenCaptureOutput(const RenderArea& renderArea,
52*38e8c45fSAndroid Build Coastguard Worker                         const compositionengine::Output::ColorProfile& colorProfile,
53*38e8c45fSAndroid Build Coastguard Worker                         bool regionSampling, bool dimInGammaSpaceForEnhancedScreenshots,
54*38e8c45fSAndroid Build Coastguard Worker                         bool enableLocalTonemapping);
55*38e8c45fSAndroid Build Coastguard Worker 
56*38e8c45fSAndroid Build Coastguard Worker     void updateColorProfile(const compositionengine::CompositionRefreshArgs&) override;
57*38e8c45fSAndroid Build Coastguard Worker 
58*38e8c45fSAndroid Build Coastguard Worker     std::vector<compositionengine::LayerFE::LayerSettings> generateClientCompositionRequests(
59*38e8c45fSAndroid Build Coastguard Worker             bool supportsProtectedContent, ui::Dataspace outputDataspace,
60*38e8c45fSAndroid Build Coastguard Worker             std::vector<compositionengine::LayerFE*>& outLayerFEs) override;
61*38e8c45fSAndroid Build Coastguard Worker 
62*38e8c45fSAndroid Build Coastguard Worker protected:
getSkipColorTransform()63*38e8c45fSAndroid Build Coastguard Worker     bool getSkipColorTransform() const override { return false; }
64*38e8c45fSAndroid Build Coastguard Worker     renderengine::DisplaySettings generateClientCompositionDisplaySettings(
65*38e8c45fSAndroid Build Coastguard Worker             const std::shared_ptr<renderengine::ExternalTexture>& buffer) const override;
66*38e8c45fSAndroid Build Coastguard Worker 
67*38e8c45fSAndroid Build Coastguard Worker private:
68*38e8c45fSAndroid Build Coastguard Worker     const RenderArea& mRenderArea;
69*38e8c45fSAndroid Build Coastguard Worker     const compositionengine::Output::ColorProfile& mColorProfile;
70*38e8c45fSAndroid Build Coastguard Worker     const bool mRegionSampling;
71*38e8c45fSAndroid Build Coastguard Worker     const bool mDimInGammaSpaceForEnhancedScreenshots;
72*38e8c45fSAndroid Build Coastguard Worker     const bool mEnableLocalTonemapping;
73*38e8c45fSAndroid Build Coastguard Worker };
74*38e8c45fSAndroid Build Coastguard Worker 
75*38e8c45fSAndroid Build Coastguard Worker std::shared_ptr<ScreenCaptureOutput> createScreenCaptureOutput(ScreenCaptureOutputArgs);
76*38e8c45fSAndroid Build Coastguard Worker 
77*38e8c45fSAndroid Build Coastguard Worker } // namespace android
78