Dominik Laskowski | 6e46515 | 2022-09-28 11:00:25 -0400 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2024 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 | #undef LOG_TAG |
| 18 | #define LOG_TAG "DisplayModeController" |
| 19 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS |
| 20 | |
| 21 | #include "Display/DisplayModeController.h" |
| 22 | #include "Display/DisplaySnapshot.h" |
| 23 | |
| 24 | #include <log/log.h> |
| 25 | |
| 26 | namespace android::display { |
| 27 | |
| 28 | void DisplayModeController::registerDisplay(DisplaySnapshotRef snapshotRef, |
| 29 | DisplayModeId activeModeId, |
| 30 | scheduler::RefreshRateSelector::Config config) { |
| 31 | const auto& snapshot = snapshotRef.get(); |
| 32 | const auto displayId = snapshot.displayId(); |
| 33 | |
| 34 | mDisplays.emplace_or_replace(displayId, snapshotRef, snapshot.displayModes(), activeModeId, |
| 35 | config); |
| 36 | } |
| 37 | |
| 38 | void DisplayModeController::unregisterDisplay(PhysicalDisplayId displayId) { |
| 39 | const bool ok = mDisplays.erase(displayId); |
| 40 | ALOGE_IF(!ok, "%s: Unknown display %s", __func__, to_string(displayId).c_str()); |
| 41 | } |
| 42 | |
| 43 | auto DisplayModeController::selectorPtrFor(PhysicalDisplayId displayId) -> RefreshRateSelectorPtr { |
| 44 | return mDisplays.get(displayId) |
| 45 | .transform([](const Display& display) { return display.selectorPtr; }) |
| 46 | .value_or(nullptr); |
| 47 | } |
| 48 | |
| 49 | } // namespace android::display |