xref: /aosp_15_r20/frameworks/native/services/surfaceflinger/FrontEnd/LayerCreationArgs.h (revision 38e8c45f13ce32b0dcecb25141ffecaf386fa17f)
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 <binder/Binder.h>
20*38e8c45fSAndroid Build Coastguard Worker #include <gui/LayerMetadata.h>
21*38e8c45fSAndroid Build Coastguard Worker #include <ui/LayerStack.h>
22*38e8c45fSAndroid Build Coastguard Worker #include <utils/StrongPointer.h>
23*38e8c45fSAndroid Build Coastguard Worker #include <cstdint>
24*38e8c45fSAndroid Build Coastguard Worker #include <limits>
25*38e8c45fSAndroid Build Coastguard Worker #include <optional>
26*38e8c45fSAndroid Build Coastguard Worker 
27*38e8c45fSAndroid Build Coastguard Worker constexpr uint32_t UNASSIGNED_LAYER_ID = std::numeric_limits<uint32_t>::max();
28*38e8c45fSAndroid Build Coastguard Worker constexpr uint32_t INTERNAL_LAYER_PREFIX = 1u << 31;
29*38e8c45fSAndroid Build Coastguard Worker 
30*38e8c45fSAndroid Build Coastguard Worker namespace android {
31*38e8c45fSAndroid Build Coastguard Worker class SurfaceFlinger;
32*38e8c45fSAndroid Build Coastguard Worker class Client;
33*38e8c45fSAndroid Build Coastguard Worker } // namespace android
34*38e8c45fSAndroid Build Coastguard Worker 
35*38e8c45fSAndroid Build Coastguard Worker namespace android::surfaceflinger {
36*38e8c45fSAndroid Build Coastguard Worker 
37*38e8c45fSAndroid Build Coastguard Worker struct LayerCreationArgs {
38*38e8c45fSAndroid Build Coastguard Worker     static std::atomic<uint32_t> sSequence;
39*38e8c45fSAndroid Build Coastguard Worker     static std::atomic<uint32_t> sInternalSequence;
40*38e8c45fSAndroid Build Coastguard Worker     static uint32_t getInternalLayerId(uint32_t id);
41*38e8c45fSAndroid Build Coastguard Worker     static LayerCreationArgs fromOtherArgs(const LayerCreationArgs& other);
42*38e8c45fSAndroid Build Coastguard Worker 
43*38e8c45fSAndroid Build Coastguard Worker     LayerCreationArgs(android::SurfaceFlinger*, sp<android::Client>, std::string name,
44*38e8c45fSAndroid Build Coastguard Worker                       uint32_t flags, gui::LayerMetadata, std::optional<uint32_t> id = std::nullopt,
45*38e8c45fSAndroid Build Coastguard Worker                       bool internalLayer = false);
46*38e8c45fSAndroid Build Coastguard Worker     LayerCreationArgs(std::optional<uint32_t> id, bool internalLayer = false);
47*38e8c45fSAndroid Build Coastguard Worker     LayerCreationArgs() = default; // for tracing
48*38e8c45fSAndroid Build Coastguard Worker     std::string getDebugString() const;
49*38e8c45fSAndroid Build Coastguard Worker 
50*38e8c45fSAndroid Build Coastguard Worker     android::SurfaceFlinger* flinger;
51*38e8c45fSAndroid Build Coastguard Worker     sp<android::Client> client;
52*38e8c45fSAndroid Build Coastguard Worker     std::string name;
53*38e8c45fSAndroid Build Coastguard Worker     uint32_t flags; // ISurfaceComposerClient flags
54*38e8c45fSAndroid Build Coastguard Worker     gui::LayerMetadata metadata;
55*38e8c45fSAndroid Build Coastguard Worker     pid_t ownerPid;
56*38e8c45fSAndroid Build Coastguard Worker     uid_t ownerUid;
57*38e8c45fSAndroid Build Coastguard Worker     uint32_t sequence;
58*38e8c45fSAndroid Build Coastguard Worker     bool addToRoot = true;
59*38e8c45fSAndroid Build Coastguard Worker     wp<IBinder> parentHandle = nullptr;
60*38e8c45fSAndroid Build Coastguard Worker     wp<IBinder> mirrorLayerHandle = nullptr;
61*38e8c45fSAndroid Build Coastguard Worker     ui::LayerStack layerStackToMirror = ui::INVALID_LAYER_STACK;
62*38e8c45fSAndroid Build Coastguard Worker     uint32_t parentId = UNASSIGNED_LAYER_ID;
63*38e8c45fSAndroid Build Coastguard Worker     uint32_t layerIdToMirror = UNASSIGNED_LAYER_ID;
64*38e8c45fSAndroid Build Coastguard Worker     std::atomic<int32_t>* pendingBuffers = 0;
65*38e8c45fSAndroid Build Coastguard Worker };
66*38e8c45fSAndroid Build Coastguard Worker 
67*38e8c45fSAndroid Build Coastguard Worker } // namespace android::surfaceflinger
68