Melody Hsu | 41ade20 | 2024-05-03 01:25:50 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2024 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 "DisplayDevice.h" |
| 20 | #include "DisplayRenderArea.h" |
| 21 | #include "LayerRenderArea.h" |
| 22 | #include "ui/Size.h" |
| 23 | #include "ui/Transform.h" |
| 24 | |
| 25 | namespace android { |
| 26 | /** |
| 27 | * A parameter object for creating a render area |
| 28 | */ |
| 29 | struct RenderAreaBuilder { |
| 30 | // Source crop of the render area |
| 31 | Rect crop; |
| 32 | |
| 33 | // Size of the physical render area |
| 34 | ui::Size reqSize; |
| 35 | |
| 36 | // Composition data space of the render area |
| 37 | ui::Dataspace reqDataSpace; |
| 38 | |
| 39 | // If true, the secure layer would be blacked out or skipped |
| 40 | // when rendered to an insecure render area |
| 41 | bool allowSecureLayers; |
| 42 | |
| 43 | // If true, the render result may be used for system animations |
| 44 | // that must preserve the exact colors of the display |
| 45 | bool hintForSeamlessTransition; |
| 46 | |
| 47 | virtual std::unique_ptr<RenderArea> build() const = 0; |
| 48 | |
| 49 | RenderAreaBuilder(Rect crop, ui::Size reqSize, ui::Dataspace reqDataSpace, |
| 50 | bool allowSecureLayers, bool hintForSeamlessTransition) |
| 51 | : crop(crop), |
| 52 | reqSize(reqSize), |
| 53 | reqDataSpace(reqDataSpace), |
| 54 | allowSecureLayers(allowSecureLayers), |
| 55 | hintForSeamlessTransition(hintForSeamlessTransition) {} |
| 56 | |
| 57 | virtual ~RenderAreaBuilder() = default; |
| 58 | }; |
| 59 | |
| 60 | struct DisplayRenderAreaBuilder : RenderAreaBuilder { |
| 61 | DisplayRenderAreaBuilder(Rect crop, ui::Size reqSize, ui::Dataspace reqDataSpace, |
| 62 | bool allowSecureLayers, bool hintForSeamlessTransition, |
| 63 | wp<const DisplayDevice> displayWeak) |
| 64 | : RenderAreaBuilder(crop, reqSize, reqDataSpace, allowSecureLayers, |
| 65 | hintForSeamlessTransition), |
| 66 | displayWeak(displayWeak) {} |
| 67 | |
| 68 | // Display that render area will be on |
| 69 | wp<const DisplayDevice> displayWeak; |
| 70 | |
| 71 | std::unique_ptr<RenderArea> build() const override { |
| 72 | return DisplayRenderArea::create(displayWeak, crop, reqSize, reqDataSpace, |
| 73 | hintForSeamlessTransition, allowSecureLayers); |
| 74 | } |
| 75 | }; |
| 76 | |
| 77 | struct LayerRenderAreaBuilder : RenderAreaBuilder { |
| 78 | LayerRenderAreaBuilder(Rect crop, ui::Size reqSize, ui::Dataspace reqDataSpace, |
| 79 | bool allowSecureLayers, bool hintForSeamlessTransition, sp<Layer> layer, |
| 80 | bool childrenOnly) |
| 81 | : RenderAreaBuilder(crop, reqSize, reqDataSpace, allowSecureLayers, |
| 82 | hintForSeamlessTransition), |
| 83 | layer(layer), |
| 84 | childrenOnly(childrenOnly) {} |
| 85 | |
Melody Hsu | 50c151a | 2024-05-14 06:11:12 +0000 | [diff] [blame^] | 86 | // Root layer of the render area |
Melody Hsu | 41ade20 | 2024-05-03 01:25:50 +0000 | [diff] [blame] | 87 | sp<Layer> layer; |
| 88 | |
Melody Hsu | 50c151a | 2024-05-14 06:11:12 +0000 | [diff] [blame^] | 89 | // Layer snapshot of the root layer |
| 90 | frontend::LayerSnapshot layerSnapshot; |
| 91 | |
Melody Hsu | 41ade20 | 2024-05-03 01:25:50 +0000 | [diff] [blame] | 92 | // Transform to be applied on the layers to transform them |
| 93 | // into the logical render area |
| 94 | ui::Transform layerTransform{ui::Transform()}; |
| 95 | |
| 96 | // Buffer bounds |
| 97 | Rect layerBufferSize{Rect()}; |
| 98 | |
| 99 | // If false, transform is inverted from the parent snapshot |
| 100 | bool childrenOnly; |
| 101 | |
| 102 | // Uses parent snapshot to determine layer transform and buffer size |
Melody Hsu | 50c151a | 2024-05-14 06:11:12 +0000 | [diff] [blame^] | 103 | void setLayerSnapshot(const frontend::LayerSnapshot& parentSnapshot) { |
| 104 | layerSnapshot = parentSnapshot; |
Melody Hsu | 41ade20 | 2024-05-03 01:25:50 +0000 | [diff] [blame] | 105 | if (!childrenOnly) { |
Melody Hsu | 50c151a | 2024-05-14 06:11:12 +0000 | [diff] [blame^] | 106 | layerTransform = parentSnapshot.localTransform.inverse(); |
Melody Hsu | 41ade20 | 2024-05-03 01:25:50 +0000 | [diff] [blame] | 107 | } |
Melody Hsu | 50c151a | 2024-05-14 06:11:12 +0000 | [diff] [blame^] | 108 | layerBufferSize = parentSnapshot.bufferSize; |
Melody Hsu | 41ade20 | 2024-05-03 01:25:50 +0000 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | std::unique_ptr<RenderArea> build() const override { |
Melody Hsu | 50c151a | 2024-05-14 06:11:12 +0000 | [diff] [blame^] | 112 | return std::make_unique<LayerRenderArea>(layer, std::move(layerSnapshot), crop, reqSize, |
| 113 | reqDataSpace, allowSecureLayers, layerTransform, |
| 114 | layerBufferSize, hintForSeamlessTransition); |
Melody Hsu | 41ade20 | 2024-05-03 01:25:50 +0000 | [diff] [blame] | 115 | } |
| 116 | }; |
| 117 | |
| 118 | } // namespace android |