blob: 9b4ba86a80fd806b71d4882a520bfc49c30c2120 [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
Drew Davenport5951b112024-08-05 09:44:27 -060031DrmHwcThree::~DrmHwcThree() {
Normunds Rieksts425a6962024-03-11 14:46:07 +000032 /* Display deinit routine is handled by resource manager */
33 GetResMan().DeInit();
Drew Davenport5951b112024-08-05 09:44:27 -060034}
35
Drew Davenportade69652024-07-16 15:54:33 -060036void DrmHwcThree::Init(std::shared_ptr<IComposerCallback> callback) {
37 composer_callback_ = std::move(callback);
38 GetResMan().Init();
39}
40
41void 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
53void DrmHwcThree::SendRefreshEventToClient(uint64_t display_id) {
Drew Davenport5951b112024-08-05 09:44:27 -060054 composer_resources_->SetDisplayMustValidateState(display_id, true);
Drew Davenportade69652024-07-16 15:54:33 -060055 composer_callback_->onRefresh(static_cast<int64_t>(display_id));
56}
57
58void 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 Stratiienko71a8f022024-10-16 23:17:33 +030064#if __ANDROID_API__ >= 35
65
Manasi Navare3f0c01a2024-10-04 18:01:55 +000066void 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 Davenport7231bbd2024-09-13 10:39:03 -060082 composer_callback_->onHotplugEvent(static_cast<int64_t>(display_id), event);
Drew Davenportade69652024-07-16 15:54:33 -060083}
84
Roman Stratiienko71a8f022024-10-16 23:17:33 +030085#else
86
87void 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 Davenport5951b112024-08-05 09:44:27 -060096void 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 Stratiienkoe757ee82024-12-09 04:41:19 +0200104 /* 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 Davenport5951b112024-08-05 09:44:27 -0600111 }
Drew Davenport5951b112024-08-05 09:44:27 -0600112}
113
Drew Davenportade69652024-07-16 15:54:33 -0600114} // namespace aidl::android::hardware::graphics::composer3::impl