blob: 6891fbc8e6048488225427123ceb854f452e0b33 [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;
Vishnu Nair04f89692022-11-16 23:21:05 +000065 bool hasValidRelativeParent() const;
Vishnu Nairdc4d31b2022-11-17 03:20:58 +000066
67 // Layer serial number. This gives layers an explicit ordering, so we
68 // have a stable sort order when their layer stack and Z-order are
69 // the same.
70 const uint32_t id;
71 const std::string name;
Vishnu Nair04f89692022-11-16 23:21:05 +000072 bool canBeRoot = false;
Vishnu Nairdc4d31b2022-11-17 03:20:58 +000073 const uint32_t layerCreationFlags;
74 const uint32_t textureName;
75 // The owner of the layer. If created from a non system process, it will be the calling uid.
76 // If created from a system process, the value can be passed in.
77 const uid_t ownerUid;
78 // The owner pid of the layer. If created from a non system process, it will be the calling pid.
79 // If created from a system process, the value can be passed in.
80 const pid_t ownerPid;
81 bool dataspaceRequested;
82 bool hasColorTransform;
83 bool premultipliedAlpha{true};
84 // This layer can be a cursor on some displays.
85 bool potentialCursor{false};
86 bool protectedByApp{false}; // application requires protected path to external sink
87 ui::Transform requestedTransform;
88 std::shared_ptr<FenceTime> acquireFenceTime;
89 std::shared_ptr<renderengine::ExternalTexture> externalTexture;
90 int hwcBufferSlot = 0;
91
92 // book keeping states
93 bool handleAlive = true;
94 bool isRelativeOf = false;
95 uint32_t parentId = UNASSIGNED_LAYER_ID;
96 uint32_t relativeParentId = UNASSIGNED_LAYER_ID;
97 uint32_t mirrorId = UNASSIGNED_LAYER_ID;
98 uint32_t touchCropId = UNASSIGNED_LAYER_ID;
99 uint32_t bgColorLayerId = UNASSIGNED_LAYER_ID;
100 ftl::Flags<RequestedLayerState::Changes> changes;
101};
102
103} // namespace android::surfaceflinger::frontend