Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 1 | /* |
| 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 Laskowski | 6b049ff | 2023-01-29 15:46:45 -0500 | [diff] [blame] | 24 | #include <ui/DisplayMap.h> |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 25 | #include <utils/StrongPointer.h> |
| 26 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 27 | #include "DisplaySnapshot.h" |
Dominik Laskowski | 6e46515 | 2022-09-28 11:00:25 -0400 | [diff] [blame] | 28 | #include "DisplaySnapshotRef.h" |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 29 | |
| 30 | namespace android::display { |
| 31 | |
| 32 | // TODO(b/229877597): Replace with AIDL type. |
| 33 | using DisplayToken = IBinder; |
| 34 | |
| 35 | class PhysicalDisplay { |
| 36 | public: |
| 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 Laskowski | 6e46515 | 2022-09-28 11:00:25 -0400 | [diff] [blame] | 49 | DisplaySnapshotRef snapshotRef() const { return std::cref(mSnapshot); } |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 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 | |
| 62 | private: |
| 63 | const sp<DisplayToken> mToken; |
| 64 | |
| 65 | // Effectively const except in move constructor. |
| 66 | DisplaySnapshot mSnapshot; |
| 67 | }; |
| 68 | |
Dominik Laskowski | 6b049ff | 2023-01-29 15:46:45 -0500 | [diff] [blame] | 69 | using PhysicalDisplays = ui::PhysicalDisplayMap<PhysicalDisplayId, PhysicalDisplay>; |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 70 | |
| 71 | // Combinator for ftl::Optional<PhysicalDisplayId>::and_then. |
| 72 | constexpr auto getPhysicalDisplay(const PhysicalDisplays& displays) { |
| 73 | return [&](PhysicalDisplayId id) { return displays.get(id); }; |
| 74 | } |
| 75 | |
| 76 | } // namespace android::display |