blob: 44dc276f3d919f46bc5cbd32703496a24ed51397 [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
19#include "drm/ResourceManager.h"
20#include "hwc2_device/HwcDisplay.h"
21
22namespace android {
23
24class DrmHwc : public PipelineToFrontendBindingInterface {
25 public:
26 DrmHwc();
27 ~DrmHwc() override = default;
28
29 // Client Callback functions.:
30 virtual void SendVsyncEventToClient(hwc2_display_t displayid,
31 int64_t timestamp,
32 uint32_t vsync_period) const = 0;
33 virtual void SendVsyncPeriodTimingChangedEventToClient(
34 hwc2_display_t displayid, int64_t timestamp) const = 0;
35 virtual void SendRefreshEventToClient(uint64_t displayid) = 0;
36 virtual void SendHotplugEventToClient(hwc2_display_t displayid,
37 bool connected) = 0;
38
39 // Device functions
40 HWC2::Error CreateVirtualDisplay(uint32_t width, uint32_t height,
41 int32_t *format, hwc2_display_t *display);
42 HWC2::Error DestroyVirtualDisplay(hwc2_display_t display);
43 void Dump(uint32_t *out_size, char *out_buffer);
44 uint32_t GetMaxVirtualDisplayCount();
45
46 auto GetDisplay(hwc2_display_t display_handle) {
47 return displays_.count(display_handle) != 0
48 ? displays_[display_handle].get()
49 : nullptr;
50 }
51
52 auto &GetResMan() {
53 return resource_manager_;
54 }
55
56 void ScheduleHotplugEvent(hwc2_display_t displayid, bool connected) {
57 deferred_hotplug_events_[displayid] = connected;
58 }
59
Drew Davenport1ac3b622024-09-05 10:59:16 -060060 void DeinitDisplays();
61
Drew Davenport93443182023-12-14 09:25:45 +000062 // PipelineToFrontendBindingInterface
63 bool BindDisplay(std::shared_ptr<DrmDisplayPipeline> pipeline) override;
64 bool UnbindDisplay(std::shared_ptr<DrmDisplayPipeline> pipeline) override;
65 void FinalizeDisplayBinding() override;
66
67 protected:
68 auto& Displays() { return displays_; }
69
70 private:
71 ResourceManager resource_manager_;
72 std::map<hwc2_display_t, std::unique_ptr<HwcDisplay>> displays_;
73 std::map<std::shared_ptr<DrmDisplayPipeline>, hwc2_display_t>
74 display_handles_;
75
76 std::string dump_string_;
77
78 std::map<hwc2_display_t, bool> deferred_hotplug_events_;
79 std::vector<hwc2_display_t> displays_for_removal_list_;
80
81 uint32_t last_display_handle_ = kPrimaryDisplay;
82};
83} // namespace android