blob: 09f33de63bb4213acccd10f73b1eb12a4897833f [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>
Vishnu Naircfb2d252023-01-19 04:44:02 +000023#include "Scheduler/LayerInfo.h"
Vishnu Nairdc4d31b2022-11-17 03:20:58 +000024
25#include "LayerCreationArgs.h"
26#include "TransactionState.h"
27
28namespace android::surfaceflinger::frontend {
29
30// Stores client requested states for a layer.
31// This struct does not store any other states or states pertaining to
32// other layers. Links to other layers that are part of the client
33// requested state such as parent are translated to layer id so
34// we can avoid extending the lifetime of layer handles.
35struct RequestedLayerState : layer_state_t {
36 // Changes in state after merging with new state. This includes additional state
37 // changes found in layer_state_t::what.
38 enum class Changes : uint32_t {
39 Created = 1u << 0,
40 Destroyed = 1u << 1,
41 Hierarchy = 1u << 2,
42 Geometry = 1u << 3,
43 Content = 1u << 4,
44 Input = 1u << 5,
45 Z = 1u << 6,
46 Mirror = 1u << 7,
47 Parent = 1u << 8,
48 RelativeParent = 1u << 9,
49 Metadata = 1u << 10,
50 Visibility = 1u << 11,
Vishnu Nair8fc721b2022-12-22 20:06:32 +000051 AffectsChildren = 1u << 12,
Vishnu Naircfb2d252023-01-19 04:44:02 +000052 FrameRate = 1u << 13,
53 VisibleRegion = 1u << 14,
54 Buffer = 1u << 15,
Vishnu Naird47bcee2023-02-24 18:08:51 +000055 SidebandStream = 1u << 16,
Vishnu Nairef68d6d2023-02-28 06:18:27 +000056 Animation = 1u << 17,
Vishnu Naira02943f2023-06-03 13:44:46 -070057 BufferSize = 1u << 18,
58 GameMode = 1u << 19,
Vishnu Nair0808ae62023-08-07 21:42:42 -070059 BufferUsageFlags = 1u << 20,
Vishnu Nairdc4d31b2022-11-17 03:20:58 +000060 };
61 static Rect reduce(const Rect& win, const Region& exclude);
62 RequestedLayerState(const LayerCreationArgs&);
63 void merge(const ResolvedComposerState&);
Vishnu Naird47bcee2023-02-24 18:08:51 +000064 void clearChanges();
65
Vishnu Nair8fc721b2022-12-22 20:06:32 +000066 // Currently we only care about the primary display
67 ui::Transform getTransform(uint32_t displayRotationFlags) const;
68 ui::Size getUnrotatedBufferSize(uint32_t displayRotationFlags) const;
Vishnu Nairdc4d31b2022-11-17 03:20:58 +000069 bool canBeDestroyed() const;
70 bool isRoot() const;
71 bool isHiddenByPolicy() const;
72 half4 getColor() const;
Vishnu Nair8fc721b2022-12-22 20:06:32 +000073 Rect getBufferSize(uint32_t displayRotationFlags) const;
74 Rect getCroppedBufferSize(const Rect& bufferSize) const;
Vishnu Nairdc4d31b2022-11-17 03:20:58 +000075 Rect getBufferCrop() const;
76 std::string getDebugString() const;
77 std::string getDebugStringShort() const;
Vishnu Nair3cc15a42023-06-30 06:20:22 +000078 friend std::ostream& operator<<(std::ostream& os, const RequestedLayerState& obj);
Vishnu Nairdc4d31b2022-11-17 03:20:58 +000079 aidl::android::hardware::graphics::composer3::Composition getCompositionType() const;
Vishnu Nair04f89692022-11-16 23:21:05 +000080 bool hasValidRelativeParent() const;
Vishnu Nair8fc721b2022-12-22 20:06:32 +000081 bool hasInputInfo() const;
Vishnu Nair80a5a702023-02-11 01:21:51 +000082 bool hasBlur() const;
Vishnu Naird47bcee2023-02-24 18:08:51 +000083 bool hasFrameUpdate() const;
84 bool hasReadyFrame() const;
85 bool hasSidebandStreamFrame() const;
Vishnu Nair7ee4f462023-04-19 09:54:09 -070086 bool willReleaseBufferOnLatch() const;
Vishnu Nair4d9cef92023-06-24 22:34:41 +000087 bool backpressureEnabled() const;
88 bool isSimpleBufferUpdate(const layer_state_t&) const;
Vishnu Nair0808ae62023-08-07 21:42:42 -070089 bool isProtected() const;
Vishnu Nair854ce1c2023-08-19 15:00:13 -070090 bool hasSomethingToDraw() const;
Vishnu Nairdc4d31b2022-11-17 03:20:58 +000091
92 // Layer serial number. This gives layers an explicit ordering, so we
93 // have a stable sort order when their layer stack and Z-order are
94 // the same.
95 const uint32_t id;
96 const std::string name;
Vishnu Nair04f89692022-11-16 23:21:05 +000097 bool canBeRoot = false;
Vishnu Nairdc4d31b2022-11-17 03:20:58 +000098 const uint32_t layerCreationFlags;
Vishnu Nairdc4d31b2022-11-17 03:20:58 +000099 // The owner of the layer. If created from a non system process, it will be the calling uid.
100 // If created from a system process, the value can be passed in.
Vishnu Naira02943f2023-06-03 13:44:46 -0700101 const gui::Uid ownerUid;
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000102 // The owner pid of the layer. If created from a non system process, it will be the calling pid.
103 // If created from a system process, the value can be passed in.
Vishnu Naira02943f2023-06-03 13:44:46 -0700104 const gui::Pid ownerPid;
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000105 bool dataspaceRequested;
106 bool hasColorTransform;
107 bool premultipliedAlpha{true};
108 // This layer can be a cursor on some displays.
109 bool potentialCursor{false};
110 bool protectedByApp{false}; // application requires protected path to external sink
111 ui::Transform requestedTransform;
112 std::shared_ptr<FenceTime> acquireFenceTime;
113 std::shared_ptr<renderengine::ExternalTexture> externalTexture;
Vishnu Naircfb2d252023-01-19 04:44:02 +0000114 gui::GameMode gameMode;
115 scheduler::LayerInfo::FrameRate requestedFrameRate;
Vishnu Nair1391de22023-03-05 19:56:14 -0800116 uint32_t parentId = UNASSIGNED_LAYER_ID;
117 uint32_t relativeParentId = UNASSIGNED_LAYER_ID;
Vishnu Naira9c43762023-01-27 19:10:25 +0000118 uint32_t layerIdToMirror = UNASSIGNED_LAYER_ID;
Vishnu Nair1391de22023-03-05 19:56:14 -0800119 ui::LayerStack layerStackToMirror = ui::INVALID_LAYER_STACK;
120 uint32_t touchCropId = UNASSIGNED_LAYER_ID;
121 uint32_t bgColorLayerId = UNASSIGNED_LAYER_ID;
Vishnu Nair63221212023-04-06 15:17:37 -0700122 uint64_t barrierFrameNumber = 0;
123 uint32_t barrierProducerId = 0;
Vishnu Nair3cc15a42023-06-30 06:20:22 +0000124 std::string debugName;
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000125
126 // book keeping states
127 bool handleAlive = true;
128 bool isRelativeOf = false;
Vishnu Naira9c43762023-01-27 19:10:25 +0000129 std::vector<uint32_t> mirrorIds{};
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000130 ftl::Flags<RequestedLayerState::Changes> changes;
Vishnu Naird47bcee2023-02-24 18:08:51 +0000131 bool bgColorLayer = false;
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000132};
133
134} // namespace android::surfaceflinger::frontend