blob: a25c6e0b67a1282f81e8e72fd246e8d25b8171b9 [file] [log] [blame]
Melody Hsu41ade202024-05-03 01:25:50 +00001/*
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
25namespace android {
26/**
27 * A parameter object for creating a render area
28 */
29struct 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
60struct 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
77struct 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 Hsu50c151a2024-05-14 06:11:12 +000086 // Root layer of the render area
Melody Hsu41ade202024-05-03 01:25:50 +000087 sp<Layer> layer;
88
Melody Hsu50c151a2024-05-14 06:11:12 +000089 // Layer snapshot of the root layer
90 frontend::LayerSnapshot layerSnapshot;
91
Melody Hsu41ade202024-05-03 01:25:50 +000092 // 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 Hsu50c151a2024-05-14 06:11:12 +0000103 void setLayerSnapshot(const frontend::LayerSnapshot& parentSnapshot) {
104 layerSnapshot = parentSnapshot;
Melody Hsu41ade202024-05-03 01:25:50 +0000105 if (!childrenOnly) {
Melody Hsu50c151a2024-05-14 06:11:12 +0000106 layerTransform = parentSnapshot.localTransform.inverse();
Melody Hsu41ade202024-05-03 01:25:50 +0000107 }
Melody Hsu50c151a2024-05-14 06:11:12 +0000108 layerBufferSize = parentSnapshot.bufferSize;
Melody Hsu41ade202024-05-03 01:25:50 +0000109 }
110
111 std::unique_ptr<RenderArea> build() const override {
Melody Hsu50c151a2024-05-14 06:11:12 +0000112 return std::make_unique<LayerRenderArea>(layer, std::move(layerSnapshot), crop, reqSize,
113 reqDataSpace, allowSecureLayers, layerTransform,
114 layerBufferSize, hintForSeamlessTransition);
Melody Hsu41ade202024-05-03 01:25:50 +0000115 }
116};
117
118} // namespace android