blob: 9b1f1ed921f52c6148d9be6f19b25943956e4594 [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>
Dominik Laskowski6b049ff2023-01-29 15:46:45 -050024#include <ui/DisplayMap.h>
Dominik Laskowskib363c4c2022-08-02 14:03:41 -070025#include <utils/StrongPointer.h>
26
Dominik Laskowskib363c4c2022-08-02 14:03:41 -070027#include "DisplaySnapshot.h"
Dominik Laskowski6e465152022-09-28 11:00:25 -040028#include "DisplaySnapshotRef.h"
Dominik Laskowskib363c4c2022-08-02 14:03:41 -070029
30namespace android::display {
31
32// TODO(b/229877597): Replace with AIDL type.
33using DisplayToken = IBinder;
34
35class PhysicalDisplay {
36public:
37 template <typename... Args>
38 PhysicalDisplay(sp<DisplayToken> token, Args&&... args)
39 : mToken(std::move(token)), mSnapshot(std::forward<Args>(args)...) {}
40
41 PhysicalDisplay(const PhysicalDisplay&) = delete;
42 PhysicalDisplay(PhysicalDisplay&&) = default;
43
44 const sp<DisplayToken>& token() const { return mToken; }
45 const DisplaySnapshot& snapshot() const { return mSnapshot; }
46
47 // Transformers for PhysicalDisplays::get.
48
Dominik Laskowski6e465152022-09-28 11:00:25 -040049 DisplaySnapshotRef snapshotRef() const { return std::cref(mSnapshot); }
Dominik Laskowskib363c4c2022-08-02 14:03:41 -070050
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
Dominik Laskowski6b049ff2023-01-29 15:46:45 -050069using PhysicalDisplays = ui::PhysicalDisplayMap<PhysicalDisplayId, PhysicalDisplay>;
Dominik Laskowskib363c4c2022-08-02 14:03:41 -070070
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