blob: 6df30225133ef3dd87b90000f5c5e2460a4c7324 [file] [log] [blame]
Drew Davenportade69652024-07-16 15:54:33 -06001/*
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 Navare3f0c01a2024-10-04 18:01:55 +000017#define LOG_TAG "drmhwc"
18
Drew Davenportade69652024-07-16 15:54:33 -060019#include "DrmHwcThree.h"
20
21#include <cinttypes>
22
Drew Davenport5951b112024-08-05 09:44:27 -060023#include "Utils.h"
24#include "aidl/android/hardware/graphics/common/Dataspace.h"
Roman Stratiienko71a8f022024-10-16 23:17:33 +030025#if __ANDROID_API__ >= 35
Drew Davenport7231bbd2024-09-13 10:39:03 -060026#include "aidl/android/hardware/graphics/common/DisplayHotplugEvent.h"
Roman Stratiienko71a8f022024-10-16 23:17:33 +030027#endif
Drew Davenport5951b112024-08-05 09:44:27 -060028
Drew Davenportade69652024-07-16 15:54:33 -060029namespace aidl::android::hardware::graphics::composer3::impl {
30
Roman Stratiienkoe501a972025-01-26 14:10:31 +020031auto DrmHwcThree::GetHwc3Display(::android::HwcDisplay& display)
32 -> std::shared_ptr<Hwc3Display> {
33 auto frontend_private_data = display.GetFrontendPrivateData();
34 if (!frontend_private_data) {
35 frontend_private_data = std::make_shared<Hwc3Display>();
36 display.SetFrontendPrivateData(frontend_private_data);
37 }
38 return std::static_pointer_cast<Hwc3Display>(frontend_private_data);
39}
40
Drew Davenport5951b112024-08-05 09:44:27 -060041DrmHwcThree::~DrmHwcThree() {
Normunds Rieksts425a6962024-03-11 14:46:07 +000042 /* Display deinit routine is handled by resource manager */
43 GetResMan().DeInit();
Drew Davenport5951b112024-08-05 09:44:27 -060044}
45
Drew Davenportade69652024-07-16 15:54:33 -060046void DrmHwcThree::Init(std::shared_ptr<IComposerCallback> callback) {
47 composer_callback_ = std::move(callback);
48 GetResMan().Init();
49}
50
51void DrmHwcThree::SendVsyncPeriodTimingChangedEventToClient(
52 uint64_t display_id, int64_t timestamp) const {
53 VsyncPeriodChangeTimeline timeline;
54 timeline.newVsyncAppliedTimeNanos = timestamp;
55 timeline.refreshRequired = false;
56 timeline.refreshTimeNanos = 0;
57
58 composer_callback_->onVsyncPeriodTimingChanged(static_cast<int64_t>(
59 display_id),
60 timeline);
61}
62
63void DrmHwcThree::SendRefreshEventToClient(uint64_t display_id) {
Roman Stratiienkoe501a972025-01-26 14:10:31 +020064 {
65 const std::unique_lock lock(GetResMan().GetMainLock());
66 auto* idisplay = GetDisplay(display_id);
67 if (idisplay == nullptr) {
68 ALOGE("Failed to get display %" PRIu64, display_id);
69 return;
70 }
71 auto hwc3_display = GetHwc3Display(*idisplay);
72 hwc3_display->must_validate = true;
73 }
Drew Davenportade69652024-07-16 15:54:33 -060074 composer_callback_->onRefresh(static_cast<int64_t>(display_id));
75}
76
77void DrmHwcThree::SendVsyncEventToClient(uint64_t display_id, int64_t timestamp,
78 uint32_t vsync_period) const {
79 composer_callback_->onVsync(static_cast<int64_t>(display_id), timestamp,
80 static_cast<int32_t>(vsync_period));
81}
82
Roman Stratiienko71a8f022024-10-16 23:17:33 +030083#if __ANDROID_API__ >= 35
84
Manasi Navare3f0c01a2024-10-04 18:01:55 +000085void DrmHwcThree::SendHotplugEventToClient(
86 hwc2_display_t display_id, DrmHwc::DisplayStatus display_status) {
87 common::DisplayHotplugEvent event = common::DisplayHotplugEvent::DISCONNECTED;
88 switch (display_status) {
89 case DrmHwc::kDisconnected:
90 event = common::DisplayHotplugEvent::DISCONNECTED;
Manasi Navare3f0c01a2024-10-04 18:01:55 +000091 break;
92 case DrmHwc::kConnected:
93 event = common::DisplayHotplugEvent::CONNECTED;
Manasi Navare3f0c01a2024-10-04 18:01:55 +000094 break;
95 case DrmHwc::kLinkTrainingFailed:
96 event = common::DisplayHotplugEvent::ERROR_INCOMPATIBLE_CABLE;
97 break;
98 }
Drew Davenport7231bbd2024-09-13 10:39:03 -060099 composer_callback_->onHotplugEvent(static_cast<int64_t>(display_id), event);
Drew Davenportade69652024-07-16 15:54:33 -0600100}
101
Roman Stratiienko71a8f022024-10-16 23:17:33 +0300102#else
103
104void DrmHwcThree::SendHotplugEventToClient(
105 hwc2_display_t display_id, DrmHwc::DisplayStatus display_status) {
106 bool connected = display_status != DrmHwc::kDisconnected;
Roman Stratiienko71a8f022024-10-16 23:17:33 +0300107 composer_callback_->onHotplug(static_cast<int64_t>(display_id), connected);
108}
109
110#endif
111
Drew Davenportade69652024-07-16 15:54:33 -0600112} // namespace aidl::android::hardware::graphics::composer3::impl