1*38e8c45fSAndroid Build Coastguard Worker /* 2*38e8c45fSAndroid Build Coastguard Worker * Copyright 2022 The Android Open Source Project 3*38e8c45fSAndroid Build Coastguard Worker * 4*38e8c45fSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*38e8c45fSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*38e8c45fSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*38e8c45fSAndroid Build Coastguard Worker * 8*38e8c45fSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*38e8c45fSAndroid Build Coastguard Worker * 10*38e8c45fSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*38e8c45fSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*38e8c45fSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*38e8c45fSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*38e8c45fSAndroid Build Coastguard Worker * limitations under the License. 15*38e8c45fSAndroid Build Coastguard Worker */ 16*38e8c45fSAndroid Build Coastguard Worker 17*38e8c45fSAndroid Build Coastguard Worker #pragma once 18*38e8c45fSAndroid Build Coastguard Worker 19*38e8c45fSAndroid Build Coastguard Worker #include <aidl/android/hardware/graphics/composer3/Composition.h> 20*38e8c45fSAndroid Build Coastguard Worker #include <ftl/flags.h> 21*38e8c45fSAndroid Build Coastguard Worker #include <gui/LayerState.h> 22*38e8c45fSAndroid Build Coastguard Worker #include <renderengine/ExternalTexture.h> 23*38e8c45fSAndroid Build Coastguard Worker #include "Scheduler/LayerInfo.h" 24*38e8c45fSAndroid Build Coastguard Worker 25*38e8c45fSAndroid Build Coastguard Worker #include "LayerCreationArgs.h" 26*38e8c45fSAndroid Build Coastguard Worker #include "TransactionState.h" 27*38e8c45fSAndroid Build Coastguard Worker 28*38e8c45fSAndroid Build Coastguard Worker namespace android::surfaceflinger::frontend { 29*38e8c45fSAndroid Build Coastguard Worker using namespace ftl::flag_operators; 30*38e8c45fSAndroid Build Coastguard Worker 31*38e8c45fSAndroid Build Coastguard Worker // Stores client requested states for a layer. 32*38e8c45fSAndroid Build Coastguard Worker // This struct does not store any other states or states pertaining to 33*38e8c45fSAndroid Build Coastguard Worker // other layers. Links to other layers that are part of the client 34*38e8c45fSAndroid Build Coastguard Worker // requested state such as parent are translated to layer id so 35*38e8c45fSAndroid Build Coastguard Worker // we can avoid extending the lifetime of layer handles. 36*38e8c45fSAndroid Build Coastguard Worker struct RequestedLayerState : layer_state_t { 37*38e8c45fSAndroid Build Coastguard Worker // Changes in state after merging with new state. This includes additional state 38*38e8c45fSAndroid Build Coastguard Worker // changes found in layer_state_t::what. 39*38e8c45fSAndroid Build Coastguard Worker enum class Changes : uint32_t { 40*38e8c45fSAndroid Build Coastguard Worker Created = 1u << 0, 41*38e8c45fSAndroid Build Coastguard Worker Destroyed = 1u << 1, 42*38e8c45fSAndroid Build Coastguard Worker Hierarchy = 1u << 2, 43*38e8c45fSAndroid Build Coastguard Worker Geometry = 1u << 3, 44*38e8c45fSAndroid Build Coastguard Worker Content = 1u << 4, 45*38e8c45fSAndroid Build Coastguard Worker Input = 1u << 5, 46*38e8c45fSAndroid Build Coastguard Worker Z = 1u << 6, 47*38e8c45fSAndroid Build Coastguard Worker Mirror = 1u << 7, 48*38e8c45fSAndroid Build Coastguard Worker Parent = 1u << 8, 49*38e8c45fSAndroid Build Coastguard Worker RelativeParent = 1u << 9, 50*38e8c45fSAndroid Build Coastguard Worker Metadata = 1u << 10, 51*38e8c45fSAndroid Build Coastguard Worker Visibility = 1u << 11, 52*38e8c45fSAndroid Build Coastguard Worker AffectsChildren = 1u << 12, 53*38e8c45fSAndroid Build Coastguard Worker FrameRate = 1u << 13, 54*38e8c45fSAndroid Build Coastguard Worker VisibleRegion = 1u << 14, 55*38e8c45fSAndroid Build Coastguard Worker Buffer = 1u << 15, 56*38e8c45fSAndroid Build Coastguard Worker SidebandStream = 1u << 16, 57*38e8c45fSAndroid Build Coastguard Worker Animation = 1u << 17, 58*38e8c45fSAndroid Build Coastguard Worker BufferSize = 1u << 18, 59*38e8c45fSAndroid Build Coastguard Worker GameMode = 1u << 19, 60*38e8c45fSAndroid Build Coastguard Worker BufferUsageFlags = 1u << 20, 61*38e8c45fSAndroid Build Coastguard Worker }; 62*38e8c45fSAndroid Build Coastguard Worker 63*38e8c45fSAndroid Build Coastguard Worker static constexpr ftl::Flags<Changes> kMustComposite = Changes::Created | Changes::Destroyed | 64*38e8c45fSAndroid Build Coastguard Worker Changes::Hierarchy | Changes::Geometry | Changes::Content | Changes::Input | 65*38e8c45fSAndroid Build Coastguard Worker Changes::Z | Changes::Mirror | Changes::Parent | Changes::RelativeParent | 66*38e8c45fSAndroid Build Coastguard Worker Changes::Metadata | Changes::Visibility | Changes::VisibleRegion | Changes::Buffer | 67*38e8c45fSAndroid Build Coastguard Worker Changes::SidebandStream | Changes::Animation | Changes::BufferSize | Changes::GameMode | 68*38e8c45fSAndroid Build Coastguard Worker Changes::BufferUsageFlags; 69*38e8c45fSAndroid Build Coastguard Worker static Rect reduce(const Rect& win, const Region& exclude); 70*38e8c45fSAndroid Build Coastguard Worker RequestedLayerState(const LayerCreationArgs&); 71*38e8c45fSAndroid Build Coastguard Worker void merge(const ResolvedComposerState&); 72*38e8c45fSAndroid Build Coastguard Worker void clearChanges(); 73*38e8c45fSAndroid Build Coastguard Worker 74*38e8c45fSAndroid Build Coastguard Worker // Currently we only care about the primary display 75*38e8c45fSAndroid Build Coastguard Worker ui::Transform getTransform(uint32_t displayRotationFlags) const; 76*38e8c45fSAndroid Build Coastguard Worker ui::Size getUnrotatedBufferSize(uint32_t displayRotationFlags) const; 77*38e8c45fSAndroid Build Coastguard Worker bool canBeDestroyed() const; 78*38e8c45fSAndroid Build Coastguard Worker bool isRoot() const; 79*38e8c45fSAndroid Build Coastguard Worker bool isHiddenByPolicy() const; 80*38e8c45fSAndroid Build Coastguard Worker half4 getColor() const; 81*38e8c45fSAndroid Build Coastguard Worker Rect getBufferSize(uint32_t displayRotationFlags) const; 82*38e8c45fSAndroid Build Coastguard Worker FloatRect getCroppedBufferSize(const Rect& bufferSize) const; 83*38e8c45fSAndroid Build Coastguard Worker Rect getBufferCrop() const; 84*38e8c45fSAndroid Build Coastguard Worker std::string getDebugString() const; 85*38e8c45fSAndroid Build Coastguard Worker std::string getDebugStringShort() const; 86*38e8c45fSAndroid Build Coastguard Worker friend std::ostream& operator<<(std::ostream& os, const RequestedLayerState& obj); 87*38e8c45fSAndroid Build Coastguard Worker aidl::android::hardware::graphics::composer3::Composition getCompositionType() const; 88*38e8c45fSAndroid Build Coastguard Worker bool hasValidRelativeParent() const; 89*38e8c45fSAndroid Build Coastguard Worker bool hasInputInfo() const; 90*38e8c45fSAndroid Build Coastguard Worker bool needsInputInfo() const; 91*38e8c45fSAndroid Build Coastguard Worker bool hasBlur() const; 92*38e8c45fSAndroid Build Coastguard Worker bool hasFrameUpdate() const; 93*38e8c45fSAndroid Build Coastguard Worker bool hasReadyFrame() const; 94*38e8c45fSAndroid Build Coastguard Worker bool hasSidebandStreamFrame() const; 95*38e8c45fSAndroid Build Coastguard Worker bool willReleaseBufferOnLatch() const; 96*38e8c45fSAndroid Build Coastguard Worker bool backpressureEnabled() const; 97*38e8c45fSAndroid Build Coastguard Worker bool isSimpleBufferUpdate(const layer_state_t&) const; 98*38e8c45fSAndroid Build Coastguard Worker bool isProtected() const; 99*38e8c45fSAndroid Build Coastguard Worker bool hasSomethingToDraw() const; 100*38e8c45fSAndroid Build Coastguard Worker 101*38e8c45fSAndroid Build Coastguard Worker // Layer serial number. This gives layers an explicit ordering, so we 102*38e8c45fSAndroid Build Coastguard Worker // have a stable sort order when their layer stack and Z-order are 103*38e8c45fSAndroid Build Coastguard Worker // the same. 104*38e8c45fSAndroid Build Coastguard Worker const uint32_t id; 105*38e8c45fSAndroid Build Coastguard Worker const std::string name; 106*38e8c45fSAndroid Build Coastguard Worker bool canBeRoot = false; 107*38e8c45fSAndroid Build Coastguard Worker const uint32_t layerCreationFlags; 108*38e8c45fSAndroid Build Coastguard Worker // The owner of the layer. If created from a non system process, it will be the calling uid. 109*38e8c45fSAndroid Build Coastguard Worker // If created from a system process, the value can be passed in. 110*38e8c45fSAndroid Build Coastguard Worker const gui::Uid ownerUid; 111*38e8c45fSAndroid Build Coastguard Worker // The owner pid of the layer. If created from a non system process, it will be the calling pid. 112*38e8c45fSAndroid Build Coastguard Worker // If created from a system process, the value can be passed in. 113*38e8c45fSAndroid Build Coastguard Worker const gui::Pid ownerPid; 114*38e8c45fSAndroid Build Coastguard Worker bool dataspaceRequested; 115*38e8c45fSAndroid Build Coastguard Worker bool hasColorTransform; 116*38e8c45fSAndroid Build Coastguard Worker bool premultipliedAlpha{true}; 117*38e8c45fSAndroid Build Coastguard Worker // This layer can be a cursor on some displays. 118*38e8c45fSAndroid Build Coastguard Worker bool potentialCursor{false}; 119*38e8c45fSAndroid Build Coastguard Worker bool protectedByApp{false}; // application requires protected path to external sink 120*38e8c45fSAndroid Build Coastguard Worker ui::Transform requestedTransform; 121*38e8c45fSAndroid Build Coastguard Worker std::shared_ptr<FenceTime> acquireFenceTime; 122*38e8c45fSAndroid Build Coastguard Worker std::shared_ptr<renderengine::ExternalTexture> externalTexture; 123*38e8c45fSAndroid Build Coastguard Worker gui::GameMode gameMode; 124*38e8c45fSAndroid Build Coastguard Worker scheduler::LayerInfo::FrameRate requestedFrameRate; 125*38e8c45fSAndroid Build Coastguard Worker uint32_t parentId = UNASSIGNED_LAYER_ID; 126*38e8c45fSAndroid Build Coastguard Worker uint32_t relativeParentId = UNASSIGNED_LAYER_ID; 127*38e8c45fSAndroid Build Coastguard Worker uint32_t layerIdToMirror = UNASSIGNED_LAYER_ID; 128*38e8c45fSAndroid Build Coastguard Worker ui::LayerStack layerStackToMirror = ui::INVALID_LAYER_STACK; 129*38e8c45fSAndroid Build Coastguard Worker uint32_t touchCropId = UNASSIGNED_LAYER_ID; 130*38e8c45fSAndroid Build Coastguard Worker uint32_t bgColorLayerId = UNASSIGNED_LAYER_ID; 131*38e8c45fSAndroid Build Coastguard Worker uint64_t barrierFrameNumber = 0; 132*38e8c45fSAndroid Build Coastguard Worker uint32_t barrierProducerId = 0; 133*38e8c45fSAndroid Build Coastguard Worker std::string debugName; 134*38e8c45fSAndroid Build Coastguard Worker std::atomic<int32_t>* pendingBuffers = 0; 135*38e8c45fSAndroid Build Coastguard Worker 136*38e8c45fSAndroid Build Coastguard Worker // book keeping states 137*38e8c45fSAndroid Build Coastguard Worker bool handleAlive = true; 138*38e8c45fSAndroid Build Coastguard Worker bool isRelativeOf = false; 139*38e8c45fSAndroid Build Coastguard Worker std::vector<uint32_t> mirrorIds{}; 140*38e8c45fSAndroid Build Coastguard Worker ftl::Flags<RequestedLayerState::Changes> changes; 141*38e8c45fSAndroid Build Coastguard Worker bool bgColorLayer = false; 142*38e8c45fSAndroid Build Coastguard Worker }; 143*38e8c45fSAndroid Build Coastguard Worker 144*38e8c45fSAndroid Build Coastguard Worker } // namespace android::surfaceflinger::frontend 145