blob: 0ddf5e2895332e6948d7d60ab6aed7a6b51eabf5 [file] [log] [blame]
Vishnu Nairdc4d31b2022-11-17 03:20: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 <aidl/android/hardware/graphics/composer3/Composition.h>
20#include <ftl/flags.h>
21#include <gui/LayerState.h>
22#include <renderengine/ExternalTexture.h>
23
24#include "LayerCreationArgs.h"
25#include "TransactionState.h"
26
27namespace android::surfaceflinger::frontend {
28
29// Stores client requested states for a layer.
30// This struct does not store any other states or states pertaining to
31// other layers. Links to other layers that are part of the client
32// requested state such as parent are translated to layer id so
33// we can avoid extending the lifetime of layer handles.
34struct RequestedLayerState : layer_state_t {
35 // Changes in state after merging with new state. This includes additional state
36 // changes found in layer_state_t::what.
37 enum class Changes : uint32_t {
38 Created = 1u << 0,
39 Destroyed = 1u << 1,
40 Hierarchy = 1u << 2,
41 Geometry = 1u << 3,
42 Content = 1u << 4,
43 Input = 1u << 5,
44 Z = 1u << 6,
45 Mirror = 1u << 7,
46 Parent = 1u << 8,
47 RelativeParent = 1u << 9,
48 Metadata = 1u << 10,
49 Visibility = 1u << 11,
50 };
51 static Rect reduce(const Rect& win, const Region& exclude);
52 RequestedLayerState(const LayerCreationArgs&);
53 void merge(const ResolvedComposerState&);
54 ui::Transform getTransform() const;
55 bool canBeDestroyed() const;
56 bool isRoot() const;
57 bool isHiddenByPolicy() const;
58 half4 getColor() const;
59 Rect getBufferSize() const;
60 Rect getCroppedBufferSize() const;
61 Rect getBufferCrop() const;
62 std::string getDebugString() const;
63 std::string getDebugStringShort() const;
64 aidl::android::hardware::graphics::composer3::Composition getCompositionType() const;
65
66 // Layer serial number. This gives layers an explicit ordering, so we
67 // have a stable sort order when their layer stack and Z-order are
68 // the same.
69 const uint32_t id;
70 const std::string name;
71 const bool canBeRoot = false;
72 const uint32_t layerCreationFlags;
73 const uint32_t textureName;
74 // The owner of the layer. If created from a non system process, it will be the calling uid.
75 // If created from a system process, the value can be passed in.
76 const uid_t ownerUid;
77 // The owner pid of the layer. If created from a non system process, it will be the calling pid.
78 // If created from a system process, the value can be passed in.
79 const pid_t ownerPid;
80 bool dataspaceRequested;
81 bool hasColorTransform;
82 bool premultipliedAlpha{true};
83 // This layer can be a cursor on some displays.
84 bool potentialCursor{false};
85 bool protectedByApp{false}; // application requires protected path to external sink
86 ui::Transform requestedTransform;
87 std::shared_ptr<FenceTime> acquireFenceTime;
88 std::shared_ptr<renderengine::ExternalTexture> externalTexture;
89 int hwcBufferSlot = 0;
90
91 // book keeping states
92 bool handleAlive = true;
93 bool isRelativeOf = false;
94 uint32_t parentId = UNASSIGNED_LAYER_ID;
95 uint32_t relativeParentId = UNASSIGNED_LAYER_ID;
96 uint32_t mirrorId = UNASSIGNED_LAYER_ID;
97 uint32_t touchCropId = UNASSIGNED_LAYER_ID;
98 uint32_t bgColorLayerId = UNASSIGNED_LAYER_ID;
99 ftl::Flags<RequestedLayerState::Changes> changes;
100};
101
102} // namespace android::surfaceflinger::frontend