1 /* 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 #include "Scheduler/LayerInfo.h" 24 25 #include "LayerCreationArgs.h" 26 #include "TransactionState.h" 27 28 namespace 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. 35 struct 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, 51 AffectsChildren = 1u << 12, 52 FrameRate = 1u << 13, 53 VisibleRegion = 1u << 14, 54 Buffer = 1u << 15, 55 SidebandStream = 1u << 16, 56 Animation = 1u << 17, 57 BufferSize = 1u << 18, 58 GameMode = 1u << 19, 59 }; 60 static Rect reduce(const Rect& win, const Region& exclude); 61 RequestedLayerState(const LayerCreationArgs&); 62 void merge(const ResolvedComposerState&); 63 void clearChanges(); 64 65 // Currently we only care about the primary display 66 ui::Transform getTransform(uint32_t displayRotationFlags) const; 67 ui::Size getUnrotatedBufferSize(uint32_t displayRotationFlags) const; 68 bool canBeDestroyed() const; 69 bool isRoot() const; 70 bool isHiddenByPolicy() const; 71 half4 getColor() const; 72 Rect getBufferSize(uint32_t displayRotationFlags) const; 73 Rect getCroppedBufferSize(const Rect& bufferSize) const; 74 Rect getBufferCrop() const; 75 std::string getDebugString() const; 76 std::string getDebugStringShort() const; 77 aidl::android::hardware::graphics::composer3::Composition getCompositionType() const; 78 bool hasValidRelativeParent() const; 79 bool hasInputInfo() const; 80 bool hasBlur() const; 81 bool hasFrameUpdate() const; 82 bool hasReadyFrame() const; 83 bool hasSidebandStreamFrame() const; 84 bool willReleaseBufferOnLatch() const; 85 86 // Layer serial number. This gives layers an explicit ordering, so we 87 // have a stable sort order when their layer stack and Z-order are 88 // the same. 89 const uint32_t id; 90 const std::string name; 91 bool canBeRoot = false; 92 const uint32_t layerCreationFlags; 93 const uint32_t textureName; 94 // The owner of the layer. If created from a non system process, it will be the calling uid. 95 // If created from a system process, the value can be passed in. 96 const gui::Uid ownerUid; 97 // The owner pid of the layer. If created from a non system process, it will be the calling pid. 98 // If created from a system process, the value can be passed in. 99 const gui::Pid ownerPid; 100 bool dataspaceRequested; 101 bool hasColorTransform; 102 bool premultipliedAlpha{true}; 103 // This layer can be a cursor on some displays. 104 bool potentialCursor{false}; 105 bool protectedByApp{false}; // application requires protected path to external sink 106 ui::Transform requestedTransform; 107 std::shared_ptr<FenceTime> acquireFenceTime; 108 std::shared_ptr<renderengine::ExternalTexture> externalTexture; 109 gui::GameMode gameMode; 110 scheduler::LayerInfo::FrameRate requestedFrameRate; 111 uint32_t parentId = UNASSIGNED_LAYER_ID; 112 uint32_t relativeParentId = UNASSIGNED_LAYER_ID; 113 uint32_t layerIdToMirror = UNASSIGNED_LAYER_ID; 114 ui::LayerStack layerStackToMirror = ui::INVALID_LAYER_STACK; 115 uint32_t touchCropId = UNASSIGNED_LAYER_ID; 116 uint32_t bgColorLayerId = UNASSIGNED_LAYER_ID; 117 uint64_t barrierFrameNumber = 0; 118 uint32_t barrierProducerId = 0; 119 120 // book keeping states 121 bool handleAlive = true; 122 bool isRelativeOf = false; 123 std::vector<uint32_t> mirrorIds{}; 124 ftl::Flags<RequestedLayerState::Changes> changes; 125 bool bgColorLayer = false; 126 }; 127 128 } // namespace android::surfaceflinger::frontend 129