1 /* 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/DrmDisplayPipeline.h" 20 #include "drm/ResourceManager.h" 21 #include "hwc2_device/HwcDisplay.h" 22 23 namespace android { 24 25 class DrmHwc : public PipelineToFrontendBindingInterface { 26 public: 27 DrmHwc(); 28 ~DrmHwc() override = default; 29 30 // Enum for Display status: Connected, Disconnected, Link Training Failed 31 enum DisplayStatus { 32 kDisconnected, 33 kConnected, 34 kLinkTrainingFailed, 35 }; 36 37 // 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, 45 enum DisplayStatus display_status) = 0; 46 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 GetDisplay(hwc2_display_t display_handle)54 auto GetDisplay(hwc2_display_t display_handle) { 55 return displays_.count(display_handle) != 0 56 ? displays_[display_handle].get() 57 : nullptr; 58 } 59 GetResMan()60 auto &GetResMan() { 61 return resource_manager_; 62 } 63 ScheduleHotplugEvent(hwc2_display_t displayid,enum DisplayStatus display_status)64 void ScheduleHotplugEvent(hwc2_display_t displayid, 65 enum DisplayStatus display_status) { 66 deferred_hotplug_events_[displayid] = display_status; 67 } 68 69 void DeinitDisplays(); 70 71 // PipelineToFrontendBindingInterface 72 bool BindDisplay(std::shared_ptr<DrmDisplayPipeline> pipeline) override; 73 bool UnbindDisplay(std::shared_ptr<DrmDisplayPipeline> pipeline) override; 74 void FinalizeDisplayBinding() override; 75 76 // Notify Display Link Status 77 void NotifyDisplayLinkStatus( 78 std::shared_ptr<DrmDisplayPipeline> pipeline) override; 79 80 protected: Displays()81 auto &Displays() { 82 return displays_; 83 } 84 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 93 std::map<hwc2_display_t, enum DisplayStatus> deferred_hotplug_events_; 94 std::vector<hwc2_display_t> displays_for_removal_list_; 95 96 uint32_t last_display_handle_ = kPrimaryDisplay; 97 }; 98 } // namespace android