xref: /aosp_15_r20/frameworks/native/services/surfaceflinger/Display/PhysicalDisplay.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 <functional>
20*38e8c45fSAndroid Build Coastguard Worker #include <utility>
21*38e8c45fSAndroid Build Coastguard Worker 
22*38e8c45fSAndroid Build Coastguard Worker #include <binder/IBinder.h>
23*38e8c45fSAndroid Build Coastguard Worker #include <ui/DisplayId.h>
24*38e8c45fSAndroid Build Coastguard Worker #include <ui/DisplayMap.h>
25*38e8c45fSAndroid Build Coastguard Worker #include <utils/StrongPointer.h>
26*38e8c45fSAndroid Build Coastguard Worker 
27*38e8c45fSAndroid Build Coastguard Worker #include "DisplaySnapshot.h"
28*38e8c45fSAndroid Build Coastguard Worker #include "DisplaySnapshotRef.h"
29*38e8c45fSAndroid Build Coastguard Worker 
30*38e8c45fSAndroid Build Coastguard Worker namespace android::display {
31*38e8c45fSAndroid Build Coastguard Worker 
32*38e8c45fSAndroid Build Coastguard Worker // TODO(b/229877597): Replace with AIDL type.
33*38e8c45fSAndroid Build Coastguard Worker using DisplayToken = IBinder;
34*38e8c45fSAndroid Build Coastguard Worker 
35*38e8c45fSAndroid Build Coastguard Worker class PhysicalDisplay {
36*38e8c45fSAndroid Build Coastguard Worker public:
37*38e8c45fSAndroid Build Coastguard Worker     template <typename... Args>
PhysicalDisplay(sp<DisplayToken> token,Args &&...args)38*38e8c45fSAndroid Build Coastguard Worker     PhysicalDisplay(sp<DisplayToken> token, Args&&... args)
39*38e8c45fSAndroid Build Coastguard Worker           : mToken(std::move(token)), mSnapshot(std::forward<Args>(args)...) {}
40*38e8c45fSAndroid Build Coastguard Worker 
41*38e8c45fSAndroid Build Coastguard Worker     PhysicalDisplay(const PhysicalDisplay&) = delete;
42*38e8c45fSAndroid Build Coastguard Worker     PhysicalDisplay(PhysicalDisplay&&) = default;
43*38e8c45fSAndroid Build Coastguard Worker 
token()44*38e8c45fSAndroid Build Coastguard Worker     const sp<DisplayToken>& token() const { return mToken; }
snapshot()45*38e8c45fSAndroid Build Coastguard Worker     const DisplaySnapshot& snapshot() const { return mSnapshot; }
46*38e8c45fSAndroid Build Coastguard Worker 
47*38e8c45fSAndroid Build Coastguard Worker     // Transformers for PhysicalDisplays::get.
48*38e8c45fSAndroid Build Coastguard Worker 
snapshotRef()49*38e8c45fSAndroid Build Coastguard Worker     DisplaySnapshotRef snapshotRef() const { return std::cref(mSnapshot); }
50*38e8c45fSAndroid Build Coastguard Worker 
isInternal()51*38e8c45fSAndroid Build Coastguard Worker     bool isInternal() const {
52*38e8c45fSAndroid Build Coastguard Worker         return mSnapshot.connectionType() == ui::DisplayConnectionType::Internal;
53*38e8c45fSAndroid Build Coastguard Worker     }
54*38e8c45fSAndroid Build Coastguard Worker 
55*38e8c45fSAndroid Build Coastguard Worker     // Predicate for ftl::find_if on PhysicalDisplays.
hasToken(const sp<DisplayToken> & token)56*38e8c45fSAndroid Build Coastguard Worker     static constexpr auto hasToken(const sp<DisplayToken>& token) {
57*38e8c45fSAndroid Build Coastguard Worker         return [&token](const std::pair<const PhysicalDisplayId, PhysicalDisplay>& pair) {
58*38e8c45fSAndroid Build Coastguard Worker             return pair.second.token() == token;
59*38e8c45fSAndroid Build Coastguard Worker         };
60*38e8c45fSAndroid Build Coastguard Worker     }
61*38e8c45fSAndroid Build Coastguard Worker 
62*38e8c45fSAndroid Build Coastguard Worker private:
63*38e8c45fSAndroid Build Coastguard Worker     const sp<DisplayToken> mToken;
64*38e8c45fSAndroid Build Coastguard Worker 
65*38e8c45fSAndroid Build Coastguard Worker     // Effectively const except in move constructor.
66*38e8c45fSAndroid Build Coastguard Worker     DisplaySnapshot mSnapshot;
67*38e8c45fSAndroid Build Coastguard Worker };
68*38e8c45fSAndroid Build Coastguard Worker 
69*38e8c45fSAndroid Build Coastguard Worker using PhysicalDisplays = ui::PhysicalDisplayMap<PhysicalDisplayId, PhysicalDisplay>;
70*38e8c45fSAndroid Build Coastguard Worker 
71*38e8c45fSAndroid Build Coastguard Worker // Combinator for ftl::Optional<PhysicalDisplayId>::and_then.
getPhysicalDisplay(const PhysicalDisplays & displays)72*38e8c45fSAndroid Build Coastguard Worker constexpr auto getPhysicalDisplay(const PhysicalDisplays& displays) {
73*38e8c45fSAndroid Build Coastguard Worker     return [&](PhysicalDisplayId id) { return displays.get(id); };
74*38e8c45fSAndroid Build Coastguard Worker }
75*38e8c45fSAndroid Build Coastguard Worker 
76*38e8c45fSAndroid Build Coastguard Worker } // namespace android::display
77