Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 1 | /* |
| 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 Qi | 10fc899 | 2024-12-03 22:10:45 -0800 | [diff] [blame] | 23 | #include <unordered_map> |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 24 | |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 25 | namespace android { |
| 26 | |
| 27 | struct ScreenCaptureOutputArgs { |
| 28 | const compositionengine::CompositionEngine& compositionEngine; |
| 29 | const compositionengine::Output::ColorProfile& colorProfile; |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 30 | ui::LayerStack layerStack; |
Melody Hsu | 5b3d976 | 2025-01-28 21:22:52 +0000 | [diff] [blame] | 31 | Rect sourceCrop; |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 32 | std::shared_ptr<renderengine::ExternalTexture> buffer; |
Gil Dekel | de4ce29 | 2025-03-03 17:08:43 -0500 | [diff] [blame] | 33 | ftl::Optional<DisplayIdVariant> displayIdVariant; |
Melody Hsu | 5b3d976 | 2025-01-28 21:22:52 +0000 | [diff] [blame] | 34 | ui::Size reqBufferSize; |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 35 | float sdrWhitePointNits; |
| 36 | float displayBrightnessNits; |
Alec Mouri | 3e5965f | 2023-04-07 18:00:58 +0000 | [diff] [blame] | 37 | // Counterintuitively, when targetBrightness > 1.0 then dim the scene. |
| 38 | float targetBrightness; |
Melody Hsu | 5b3d976 | 2025-01-28 21:22:52 +0000 | [diff] [blame] | 39 | float layerAlpha; |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 40 | bool regionSampling; |
Alec Mouri | 7dae9c1 | 2023-07-13 19:40:53 +0000 | [diff] [blame] | 41 | bool treat170mAsSrgb; |
Alec Mouri | 9af38ba | 2023-08-16 22:41:14 +0000 | [diff] [blame] | 42 | bool dimInGammaSpaceForEnhancedScreenshots; |
Melody Hsu | 5b3d976 | 2025-01-28 21:22:52 +0000 | [diff] [blame] | 43 | bool isSecure = false; |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 44 | bool isProtected = false; |
Alec Mouri | a7e752e | 2024-05-24 18:21:21 +0000 | [diff] [blame] | 45 | bool enableLocalTonemapping = false; |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 46 | }; |
| 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. |
| 52 | class ScreenCaptureOutput : public compositionengine::impl::Output { |
| 53 | public: |
Gil Dekel | de4ce29 | 2025-03-03 17:08:43 -0500 | [diff] [blame] | 54 | ScreenCaptureOutput(const Rect sourceCrop, ftl::Optional<DisplayIdVariant> displayIdVariant, |
Patrick Williams | 01c3116 | 2022-11-14 17:45:19 +0000 | [diff] [blame] | 55 | const compositionengine::Output::ColorProfile& colorProfile, |
Melody Hsu | 5b3d976 | 2025-01-28 21:22:52 +0000 | [diff] [blame] | 56 | float layerAlpha, bool regionSampling, |
| 57 | bool dimInGammaSpaceForEnhancedScreenshots, bool enableLocalTonemapping); |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 58 | |
| 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 Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 65 | protected: |
| 66 | bool getSkipColorTransform() const override { return false; } |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 67 | renderengine::DisplaySettings generateClientCompositionDisplaySettings( |
| 68 | const std::shared_ptr<renderengine::ExternalTexture>& buffer) const override; |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 69 | |
| 70 | private: |
Sally Qi | 10fc899 | 2024-12-03 22:10:45 -0800 | [diff] [blame] | 71 | std::unordered_map<int32_t, aidl::android::hardware::graphics::composer3::Luts> generateLuts(); |
Melody Hsu | 5b3d976 | 2025-01-28 21:22:52 +0000 | [diff] [blame] | 72 | const Rect mSourceCrop; |
Gil Dekel | de4ce29 | 2025-03-03 17:08:43 -0500 | [diff] [blame] | 73 | const ftl::Optional<DisplayIdVariant> mDisplayIdVariant; |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 74 | const compositionengine::Output::ColorProfile& mColorProfile; |
Melody Hsu | 5b3d976 | 2025-01-28 21:22:52 +0000 | [diff] [blame] | 75 | const float mLayerAlpha; |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 76 | const bool mRegionSampling; |
Alec Mouri | 9af38ba | 2023-08-16 22:41:14 +0000 | [diff] [blame] | 77 | const bool mDimInGammaSpaceForEnhancedScreenshots; |
Alec Mouri | a7e752e | 2024-05-24 18:21:21 +0000 | [diff] [blame] | 78 | const bool mEnableLocalTonemapping; |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 79 | }; |
| 80 | |
Patrick Williams | 01c3116 | 2022-11-14 17:45:19 +0000 | [diff] [blame] | 81 | std::shared_ptr<ScreenCaptureOutput> createScreenCaptureOutput(ScreenCaptureOutputArgs); |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 82 | |
| 83 | } // namespace android |