blob: ac97717f2d5d583aadbcd402a137077751be56de [file] [log] [blame]
Drew Davenport93443182023-12-14 09:25:45 +00001/*
2 * Copyright (C) 2023 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
Manasi Navare3f0c01a2024-10-04 18:01:55 +000019#include "drm/DrmDisplayPipeline.h"
Drew Davenport93443182023-12-14 09:25:45 +000020#include "drm/ResourceManager.h"
21#include "hwc2_device/HwcDisplay.h"
22
23namespace android {
24
25class DrmHwc : public PipelineToFrontendBindingInterface {
26 public:
27 DrmHwc();
28 ~DrmHwc() override = default;
29
Manasi Navare3f0c01a2024-10-04 18:01:55 +000030 // Enum for Display status: Connected, Disconnected, Link Training Failed
31 enum DisplayStatus {
32 kDisconnected,
33 kConnected,
34 kLinkTrainingFailed,
35 };
36
Drew Davenport93443182023-12-14 09:25:45 +000037 // Client Callback functions.:
38 virtual void SendVsyncEventToClient(hwc2_display_t displayid,
39 int64_t timestamp,
40 uint32_t vsync_period) const = 0;
41 virtual void SendVsyncPeriodTimingChangedEventToClient(
42 hwc2_display_t displayid, int64_t timestamp) const = 0;
43 virtual void SendRefreshEventToClient(uint64_t displayid) = 0;
44 virtual void SendHotplugEventToClient(hwc2_display_t displayid,
Manasi Navare3f0c01a2024-10-04 18:01:55 +000045 enum DisplayStatus display_status) = 0;
Drew Davenport93443182023-12-14 09:25:45 +000046
47 // Device functions
48 HWC2::Error CreateVirtualDisplay(uint32_t width, uint32_t height,
49 int32_t *format, hwc2_display_t *display);
50 HWC2::Error DestroyVirtualDisplay(hwc2_display_t display);
51 void Dump(uint32_t *out_size, char *out_buffer);
52 uint32_t GetMaxVirtualDisplayCount();
53
54 auto GetDisplay(hwc2_display_t display_handle) {
55 return displays_.count(display_handle) != 0
56 ? displays_[display_handle].get()
57 : nullptr;
58 }
59
60 auto &GetResMan() {
61 return resource_manager_;
62 }
63
Manasi Navare3f0c01a2024-10-04 18:01:55 +000064 void ScheduleHotplugEvent(hwc2_display_t displayid,
65 enum DisplayStatus display_status) {
66 deferred_hotplug_events_[displayid] = display_status;
Drew Davenport93443182023-12-14 09:25:45 +000067 }
68
Drew Davenport1ac3b622024-09-05 10:59:16 -060069 void DeinitDisplays();
70
Drew Davenport93443182023-12-14 09:25:45 +000071 // PipelineToFrontendBindingInterface
72 bool BindDisplay(std::shared_ptr<DrmDisplayPipeline> pipeline) override;
73 bool UnbindDisplay(std::shared_ptr<DrmDisplayPipeline> pipeline) override;
74 void FinalizeDisplayBinding() override;
75
Manasi Navare3f0c01a2024-10-04 18:01:55 +000076 // Notify Display Link Status
77 void NotifyDisplayLinkStatus(
78 std::shared_ptr<DrmDisplayPipeline> pipeline) override;
79
Drew Davenport93443182023-12-14 09:25:45 +000080 protected:
Manasi Navare3f0c01a2024-10-04 18:01:55 +000081 auto &Displays() {
82 return displays_;
83 }
Drew Davenport93443182023-12-14 09:25:45 +000084
85 private:
86 ResourceManager resource_manager_;
87 std::map<hwc2_display_t, std::unique_ptr<HwcDisplay>> displays_;
88 std::map<std::shared_ptr<DrmDisplayPipeline>, hwc2_display_t>
89 display_handles_;
90
91 std::string dump_string_;
92
Manasi Navare3f0c01a2024-10-04 18:01:55 +000093 std::map<hwc2_display_t, enum DisplayStatus> deferred_hotplug_events_;
Drew Davenport93443182023-12-14 09:25:45 +000094 std::vector<hwc2_display_t> displays_for_removal_list_;
95
96 uint32_t last_display_handle_ = kPrimaryDisplay;
97};
98} // namespace android