blob: c233ead57567cea65f8f538d1a23689e608957da [file] [log] [blame]
Patrick Williams7584c6a2022-10-29 02:10:58 +00001/*
2 * Copyright 2022 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#include <compositionengine/DisplayColorProfile.h>
20#include <compositionengine/RenderSurface.h>
21#include <compositionengine/impl/Output.h>
22#include <ui/Rect.h>
23
24#include "RenderArea.h"
25
26namespace android {
27
28struct ScreenCaptureOutputArgs {
29 const compositionengine::CompositionEngine& compositionEngine;
30 const compositionengine::Output::ColorProfile& colorProfile;
31 const RenderArea& renderArea;
32 ui::LayerStack layerStack;
33 std::shared_ptr<renderengine::ExternalTexture> buffer;
34 float sdrWhitePointNits;
35 float displayBrightnessNits;
Alec Mouri3e5965f2023-04-07 18:00:58 +000036 // Counterintuitively, when targetBrightness > 1.0 then dim the scene.
37 float targetBrightness;
Patrick Williams7584c6a2022-10-29 02:10:58 +000038 bool regionSampling;
Alec Mouri7dae9c12023-07-13 19:40:53 +000039 bool treat170mAsSrgb;
Alec Mouri9af38ba2023-08-16 22:41:14 +000040 bool dimInGammaSpaceForEnhancedScreenshots;
Chavi Weingarten18fa7c62023-11-28 21:16:03 +000041 bool isProtected = false;
Alec Mouria7e752e2024-05-24 18:21:21 +000042 bool enableLocalTonemapping = false;
Patrick Williams7584c6a2022-10-29 02:10:58 +000043};
44
45// ScreenCaptureOutput is used to compose a set of layers into a preallocated buffer.
46//
47// SurfaceFlinger passes instances of ScreenCaptureOutput to CompositionEngine in calls to
48// SurfaceFlinger::captureLayers and SurfaceFlinger::captureDisplay.
49class ScreenCaptureOutput : public compositionengine::impl::Output {
50public:
Patrick Williams01c31162022-11-14 17:45:19 +000051 ScreenCaptureOutput(const RenderArea& renderArea,
Patrick Williams01c31162022-11-14 17:45:19 +000052 const compositionengine::Output::ColorProfile& colorProfile,
Alec Mouria7e752e2024-05-24 18:21:21 +000053 bool regionSampling, bool dimInGammaSpaceForEnhancedScreenshots,
54 bool enableLocalTonemapping);
Patrick Williams7584c6a2022-10-29 02:10:58 +000055
56 void updateColorProfile(const compositionengine::CompositionRefreshArgs&) override;
57
58 std::vector<compositionengine::LayerFE::LayerSettings> generateClientCompositionRequests(
59 bool supportsProtectedContent, ui::Dataspace outputDataspace,
60 std::vector<compositionengine::LayerFE*>& outLayerFEs) override;
61
Patrick Williams7584c6a2022-10-29 02:10:58 +000062protected:
63 bool getSkipColorTransform() const override { return false; }
Alec Mourif97df4d2023-09-06 02:10:05 +000064 renderengine::DisplaySettings generateClientCompositionDisplaySettings(
65 const std::shared_ptr<renderengine::ExternalTexture>& buffer) const override;
Patrick Williams7584c6a2022-10-29 02:10:58 +000066
67private:
68 const RenderArea& mRenderArea;
Patrick Williams7584c6a2022-10-29 02:10:58 +000069 const compositionengine::Output::ColorProfile& mColorProfile;
70 const bool mRegionSampling;
Alec Mouri9af38ba2023-08-16 22:41:14 +000071 const bool mDimInGammaSpaceForEnhancedScreenshots;
Alec Mouria7e752e2024-05-24 18:21:21 +000072 const bool mEnableLocalTonemapping;
Patrick Williams7584c6a2022-10-29 02:10:58 +000073};
74
Patrick Williams01c31162022-11-14 17:45:19 +000075std::shared_ptr<ScreenCaptureOutput> createScreenCaptureOutput(ScreenCaptureOutputArgs);
Patrick Williams7584c6a2022-10-29 02:10:58 +000076
77} // namespace android