Drew Davenport | ade6965 | 2024-07-16 15:54:33 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 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 | |
Manasi Navare | 3f0c01a | 2024-10-04 18:01:55 +0000 | [diff] [blame] | 17 | #define LOG_TAG "drmhwc" |
| 18 | |
Drew Davenport | ade6965 | 2024-07-16 15:54:33 -0600 | [diff] [blame] | 19 | #include "DrmHwcThree.h" |
| 20 | |
| 21 | #include <cinttypes> |
| 22 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 23 | #include "Utils.h" |
| 24 | #include "aidl/android/hardware/graphics/common/Dataspace.h" |
Roman Stratiienko | 71a8f02 | 2024-10-16 23:17:33 +0300 | [diff] [blame] | 25 | #if __ANDROID_API__ >= 35 |
Drew Davenport | 7231bbd | 2024-09-13 10:39:03 -0600 | [diff] [blame] | 26 | #include "aidl/android/hardware/graphics/common/DisplayHotplugEvent.h" |
Roman Stratiienko | 71a8f02 | 2024-10-16 23:17:33 +0300 | [diff] [blame] | 27 | #endif |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 28 | |
Drew Davenport | ade6965 | 2024-07-16 15:54:33 -0600 | [diff] [blame] | 29 | namespace aidl::android::hardware::graphics::composer3::impl { |
| 30 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 31 | DrmHwcThree::~DrmHwcThree() { |
Normunds Rieksts | 425a696 | 2024-03-11 14:46:07 +0000 | [diff] [blame] | 32 | /* Display deinit routine is handled by resource manager */ |
| 33 | GetResMan().DeInit(); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 34 | } |
| 35 | |
Drew Davenport | ade6965 | 2024-07-16 15:54:33 -0600 | [diff] [blame] | 36 | void DrmHwcThree::Init(std::shared_ptr<IComposerCallback> callback) { |
| 37 | composer_callback_ = std::move(callback); |
| 38 | GetResMan().Init(); |
| 39 | } |
| 40 | |
| 41 | void DrmHwcThree::SendVsyncPeriodTimingChangedEventToClient( |
| 42 | uint64_t display_id, int64_t timestamp) const { |
| 43 | VsyncPeriodChangeTimeline timeline; |
| 44 | timeline.newVsyncAppliedTimeNanos = timestamp; |
| 45 | timeline.refreshRequired = false; |
| 46 | timeline.refreshTimeNanos = 0; |
| 47 | |
| 48 | composer_callback_->onVsyncPeriodTimingChanged(static_cast<int64_t>( |
| 49 | display_id), |
| 50 | timeline); |
| 51 | } |
| 52 | |
| 53 | void DrmHwcThree::SendRefreshEventToClient(uint64_t display_id) { |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 54 | composer_resources_->SetDisplayMustValidateState(display_id, true); |
Drew Davenport | ade6965 | 2024-07-16 15:54:33 -0600 | [diff] [blame] | 55 | composer_callback_->onRefresh(static_cast<int64_t>(display_id)); |
| 56 | } |
| 57 | |
| 58 | void DrmHwcThree::SendVsyncEventToClient(uint64_t display_id, int64_t timestamp, |
| 59 | uint32_t vsync_period) const { |
| 60 | composer_callback_->onVsync(static_cast<int64_t>(display_id), timestamp, |
| 61 | static_cast<int32_t>(vsync_period)); |
| 62 | } |
| 63 | |
Roman Stratiienko | 71a8f02 | 2024-10-16 23:17:33 +0300 | [diff] [blame] | 64 | #if __ANDROID_API__ >= 35 |
| 65 | |
Manasi Navare | 3f0c01a | 2024-10-04 18:01:55 +0000 | [diff] [blame] | 66 | void DrmHwcThree::SendHotplugEventToClient( |
| 67 | hwc2_display_t display_id, DrmHwc::DisplayStatus display_status) { |
| 68 | common::DisplayHotplugEvent event = common::DisplayHotplugEvent::DISCONNECTED; |
| 69 | switch (display_status) { |
| 70 | case DrmHwc::kDisconnected: |
| 71 | event = common::DisplayHotplugEvent::DISCONNECTED; |
| 72 | HandleDisplayHotplugEvent(static_cast<uint64_t>(display_id), false); |
| 73 | break; |
| 74 | case DrmHwc::kConnected: |
| 75 | event = common::DisplayHotplugEvent::CONNECTED; |
| 76 | HandleDisplayHotplugEvent(static_cast<uint64_t>(display_id), true); |
| 77 | break; |
| 78 | case DrmHwc::kLinkTrainingFailed: |
| 79 | event = common::DisplayHotplugEvent::ERROR_INCOMPATIBLE_CABLE; |
| 80 | break; |
| 81 | } |
Drew Davenport | 7231bbd | 2024-09-13 10:39:03 -0600 | [diff] [blame] | 82 | composer_callback_->onHotplugEvent(static_cast<int64_t>(display_id), event); |
Drew Davenport | ade6965 | 2024-07-16 15:54:33 -0600 | [diff] [blame] | 83 | } |
| 84 | |
Roman Stratiienko | 71a8f02 | 2024-10-16 23:17:33 +0300 | [diff] [blame] | 85 | #else |
| 86 | |
| 87 | void DrmHwcThree::SendHotplugEventToClient( |
| 88 | hwc2_display_t display_id, DrmHwc::DisplayStatus display_status) { |
| 89 | bool connected = display_status != DrmHwc::kDisconnected; |
| 90 | HandleDisplayHotplugEvent(static_cast<uint64_t>(display_id), connected); |
| 91 | composer_callback_->onHotplug(static_cast<int64_t>(display_id), connected); |
| 92 | } |
| 93 | |
| 94 | #endif |
| 95 | |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 96 | void DrmHwcThree::HandleDisplayHotplugEvent(uint64_t display_id, |
| 97 | bool connected) { |
| 98 | DEBUG_FUNC(); |
| 99 | if (!connected) { |
| 100 | composer_resources_->RemoveDisplay(display_id); |
| 101 | return; |
| 102 | } |
| 103 | |
Roman Stratiienko | e757ee8 | 2024-12-09 04:41:19 +0200 | [diff] [blame] | 104 | /* The second or any subsequent hotplug event with connected status enabled is |
| 105 | * a special way to inform the client (SF) that the display has changed its |
| 106 | * dimensions. In this case, the client removes all layers and re-creates |
| 107 | * them. In this case, we keep the display resources. |
| 108 | */ |
| 109 | if (!composer_resources_->HasDisplay(display_id)) { |
| 110 | composer_resources_->AddPhysicalDisplay(display_id); |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 111 | } |
Drew Davenport | 5951b11 | 2024-08-05 09:44:27 -0600 | [diff] [blame] | 112 | } |
| 113 | |
Drew Davenport | ade6965 | 2024-07-16 15:54:33 -0600 | [diff] [blame] | 114 | } // namespace aidl::android::hardware::graphics::composer3::impl |