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