blob: d4e20fc2f36e2ef884a0461e39952640babff78f [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>
Sally Qi10fc8992024-12-03 22:10:45 -080023#include <unordered_map>
Patrick Williams7584c6a2022-10-29 02:10:58 +000024
Patrick Williams7584c6a2022-10-29 02:10:58 +000025namespace android {
26
27struct ScreenCaptureOutputArgs {
28 const compositionengine::CompositionEngine& compositionEngine;
29 const compositionengine::Output::ColorProfile& colorProfile;
Patrick Williams7584c6a2022-10-29 02:10:58 +000030 ui::LayerStack layerStack;
Melody Hsu5b3d9762025-01-28 21:22:52 +000031 Rect sourceCrop;
Patrick Williams7584c6a2022-10-29 02:10:58 +000032 std::shared_ptr<renderengine::ExternalTexture> buffer;
Gil Dekelde4ce292025-03-03 17:08:43 -050033 ftl::Optional<DisplayIdVariant> displayIdVariant;
Melody Hsu5b3d9762025-01-28 21:22:52 +000034 ui::Size reqBufferSize;
Patrick Williams7584c6a2022-10-29 02:10:58 +000035 float sdrWhitePointNits;
36 float displayBrightnessNits;
Alec Mouri3e5965f2023-04-07 18:00:58 +000037 // Counterintuitively, when targetBrightness > 1.0 then dim the scene.
38 float targetBrightness;
Melody Hsu5b3d9762025-01-28 21:22:52 +000039 float layerAlpha;
Patrick Williams7584c6a2022-10-29 02:10:58 +000040 bool regionSampling;
Alec Mouri7dae9c12023-07-13 19:40:53 +000041 bool treat170mAsSrgb;
Alec Mouri9af38ba2023-08-16 22:41:14 +000042 bool dimInGammaSpaceForEnhancedScreenshots;
Melody Hsu5b3d9762025-01-28 21:22:52 +000043 bool isSecure = false;
Chavi Weingarten18fa7c62023-11-28 21:16:03 +000044 bool isProtected = false;
Alec Mouria7e752e2024-05-24 18:21:21 +000045 bool enableLocalTonemapping = false;
Patrick Williams7584c6a2022-10-29 02:10:58 +000046};
47
48// ScreenCaptureOutput is used to compose a set of layers into a preallocated buffer.
49//
50// SurfaceFlinger passes instances of ScreenCaptureOutput to CompositionEngine in calls to
51// SurfaceFlinger::captureLayers and SurfaceFlinger::captureDisplay.
52class ScreenCaptureOutput : public compositionengine::impl::Output {
53public:
Gil Dekelde4ce292025-03-03 17:08:43 -050054 ScreenCaptureOutput(const Rect sourceCrop, ftl::Optional<DisplayIdVariant> displayIdVariant,
Patrick Williams01c31162022-11-14 17:45:19 +000055 const compositionengine::Output::ColorProfile& colorProfile,
Melody Hsu5b3d9762025-01-28 21:22:52 +000056 float layerAlpha, bool regionSampling,
57 bool dimInGammaSpaceForEnhancedScreenshots, bool enableLocalTonemapping);
Patrick Williams7584c6a2022-10-29 02:10:58 +000058
59 void updateColorProfile(const compositionengine::CompositionRefreshArgs&) override;
60
61 std::vector<compositionengine::LayerFE::LayerSettings> generateClientCompositionRequests(
62 bool supportsProtectedContent, ui::Dataspace outputDataspace,
63 std::vector<compositionengine::LayerFE*>& outLayerFEs) override;
64
Patrick Williams7584c6a2022-10-29 02:10:58 +000065protected:
66 bool getSkipColorTransform() const override { return false; }
Alec Mourif97df4d2023-09-06 02:10:05 +000067 renderengine::DisplaySettings generateClientCompositionDisplaySettings(
68 const std::shared_ptr<renderengine::ExternalTexture>& buffer) const override;
Patrick Williams7584c6a2022-10-29 02:10:58 +000069
70private:
Sally Qi10fc8992024-12-03 22:10:45 -080071 std::unordered_map<int32_t, aidl::android::hardware::graphics::composer3::Luts> generateLuts();
Melody Hsu5b3d9762025-01-28 21:22:52 +000072 const Rect mSourceCrop;
Gil Dekelde4ce292025-03-03 17:08:43 -050073 const ftl::Optional<DisplayIdVariant> mDisplayIdVariant;
Patrick Williams7584c6a2022-10-29 02:10:58 +000074 const compositionengine::Output::ColorProfile& mColorProfile;
Melody Hsu5b3d9762025-01-28 21:22:52 +000075 const float mLayerAlpha;
Patrick Williams7584c6a2022-10-29 02:10:58 +000076 const bool mRegionSampling;
Alec Mouri9af38ba2023-08-16 22:41:14 +000077 const bool mDimInGammaSpaceForEnhancedScreenshots;
Alec Mouria7e752e2024-05-24 18:21:21 +000078 const bool mEnableLocalTonemapping;
Patrick Williams7584c6a2022-10-29 02:10:58 +000079};
80
Patrick Williams01c31162022-11-14 17:45:19 +000081std::shared_ptr<ScreenCaptureOutput> createScreenCaptureOutput(ScreenCaptureOutputArgs);
Patrick Williams7584c6a2022-10-29 02:10:58 +000082
83} // namespace android