1*0a9764feSAndroid Build Coastguard Worker /* 2*0a9764feSAndroid Build Coastguard Worker * Copyright (C) 2023 The Android Open Source Project 3*0a9764feSAndroid Build Coastguard Worker * 4*0a9764feSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*0a9764feSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*0a9764feSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*0a9764feSAndroid Build Coastguard Worker * 8*0a9764feSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*0a9764feSAndroid Build Coastguard Worker * 10*0a9764feSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*0a9764feSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*0a9764feSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*0a9764feSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*0a9764feSAndroid Build Coastguard Worker * limitations under the License. 15*0a9764feSAndroid Build Coastguard Worker */ 16*0a9764feSAndroid Build Coastguard Worker 17*0a9764feSAndroid Build Coastguard Worker #pragma once 18*0a9764feSAndroid Build Coastguard Worker 19*0a9764feSAndroid Build Coastguard Worker #include "drm/DrmDisplayPipeline.h" 20*0a9764feSAndroid Build Coastguard Worker #include "drm/ResourceManager.h" 21*0a9764feSAndroid Build Coastguard Worker #include "hwc2_device/HwcDisplay.h" 22*0a9764feSAndroid Build Coastguard Worker 23*0a9764feSAndroid Build Coastguard Worker namespace android { 24*0a9764feSAndroid Build Coastguard Worker 25*0a9764feSAndroid Build Coastguard Worker class DrmHwc : public PipelineToFrontendBindingInterface { 26*0a9764feSAndroid Build Coastguard Worker public: 27*0a9764feSAndroid Build Coastguard Worker DrmHwc(); 28*0a9764feSAndroid Build Coastguard Worker ~DrmHwc() override = default; 29*0a9764feSAndroid Build Coastguard Worker 30*0a9764feSAndroid Build Coastguard Worker // Enum for Display status: Connected, Disconnected, Link Training Failed 31*0a9764feSAndroid Build Coastguard Worker enum DisplayStatus { 32*0a9764feSAndroid Build Coastguard Worker kDisconnected, 33*0a9764feSAndroid Build Coastguard Worker kConnected, 34*0a9764feSAndroid Build Coastguard Worker kLinkTrainingFailed, 35*0a9764feSAndroid Build Coastguard Worker }; 36*0a9764feSAndroid Build Coastguard Worker 37*0a9764feSAndroid Build Coastguard Worker // Client Callback functions.: 38*0a9764feSAndroid Build Coastguard Worker virtual void SendVsyncEventToClient(hwc2_display_t displayid, 39*0a9764feSAndroid Build Coastguard Worker int64_t timestamp, 40*0a9764feSAndroid Build Coastguard Worker uint32_t vsync_period) const = 0; 41*0a9764feSAndroid Build Coastguard Worker virtual void SendVsyncPeriodTimingChangedEventToClient( 42*0a9764feSAndroid Build Coastguard Worker hwc2_display_t displayid, int64_t timestamp) const = 0; 43*0a9764feSAndroid Build Coastguard Worker virtual void SendRefreshEventToClient(uint64_t displayid) = 0; 44*0a9764feSAndroid Build Coastguard Worker virtual void SendHotplugEventToClient(hwc2_display_t displayid, 45*0a9764feSAndroid Build Coastguard Worker enum DisplayStatus display_status) = 0; 46*0a9764feSAndroid Build Coastguard Worker 47*0a9764feSAndroid Build Coastguard Worker // Device functions 48*0a9764feSAndroid Build Coastguard Worker HWC2::Error CreateVirtualDisplay(uint32_t width, uint32_t height, 49*0a9764feSAndroid Build Coastguard Worker int32_t *format, hwc2_display_t *display); 50*0a9764feSAndroid Build Coastguard Worker HWC2::Error DestroyVirtualDisplay(hwc2_display_t display); 51*0a9764feSAndroid Build Coastguard Worker void Dump(uint32_t *out_size, char *out_buffer); 52*0a9764feSAndroid Build Coastguard Worker uint32_t GetMaxVirtualDisplayCount(); 53*0a9764feSAndroid Build Coastguard Worker GetDisplay(hwc2_display_t display_handle)54*0a9764feSAndroid Build Coastguard Worker auto GetDisplay(hwc2_display_t display_handle) { 55*0a9764feSAndroid Build Coastguard Worker return displays_.count(display_handle) != 0 56*0a9764feSAndroid Build Coastguard Worker ? displays_[display_handle].get() 57*0a9764feSAndroid Build Coastguard Worker : nullptr; 58*0a9764feSAndroid Build Coastguard Worker } 59*0a9764feSAndroid Build Coastguard Worker GetResMan()60*0a9764feSAndroid Build Coastguard Worker auto &GetResMan() { 61*0a9764feSAndroid Build Coastguard Worker return resource_manager_; 62*0a9764feSAndroid Build Coastguard Worker } 63*0a9764feSAndroid Build Coastguard Worker ScheduleHotplugEvent(hwc2_display_t displayid,enum DisplayStatus display_status)64*0a9764feSAndroid Build Coastguard Worker void ScheduleHotplugEvent(hwc2_display_t displayid, 65*0a9764feSAndroid Build Coastguard Worker enum DisplayStatus display_status) { 66*0a9764feSAndroid Build Coastguard Worker deferred_hotplug_events_[displayid] = display_status; 67*0a9764feSAndroid Build Coastguard Worker } 68*0a9764feSAndroid Build Coastguard Worker 69*0a9764feSAndroid Build Coastguard Worker void DeinitDisplays(); 70*0a9764feSAndroid Build Coastguard Worker 71*0a9764feSAndroid Build Coastguard Worker // PipelineToFrontendBindingInterface 72*0a9764feSAndroid Build Coastguard Worker bool BindDisplay(std::shared_ptr<DrmDisplayPipeline> pipeline) override; 73*0a9764feSAndroid Build Coastguard Worker bool UnbindDisplay(std::shared_ptr<DrmDisplayPipeline> pipeline) override; 74*0a9764feSAndroid Build Coastguard Worker void FinalizeDisplayBinding() override; 75*0a9764feSAndroid Build Coastguard Worker 76*0a9764feSAndroid Build Coastguard Worker // Notify Display Link Status 77*0a9764feSAndroid Build Coastguard Worker void NotifyDisplayLinkStatus( 78*0a9764feSAndroid Build Coastguard Worker std::shared_ptr<DrmDisplayPipeline> pipeline) override; 79*0a9764feSAndroid Build Coastguard Worker 80*0a9764feSAndroid Build Coastguard Worker protected: Displays()81*0a9764feSAndroid Build Coastguard Worker auto &Displays() { 82*0a9764feSAndroid Build Coastguard Worker return displays_; 83*0a9764feSAndroid Build Coastguard Worker } 84*0a9764feSAndroid Build Coastguard Worker 85*0a9764feSAndroid Build Coastguard Worker private: 86*0a9764feSAndroid Build Coastguard Worker ResourceManager resource_manager_; 87*0a9764feSAndroid Build Coastguard Worker std::map<hwc2_display_t, std::unique_ptr<HwcDisplay>> displays_; 88*0a9764feSAndroid Build Coastguard Worker std::map<std::shared_ptr<DrmDisplayPipeline>, hwc2_display_t> 89*0a9764feSAndroid Build Coastguard Worker display_handles_; 90*0a9764feSAndroid Build Coastguard Worker 91*0a9764feSAndroid Build Coastguard Worker std::string dump_string_; 92*0a9764feSAndroid Build Coastguard Worker 93*0a9764feSAndroid Build Coastguard Worker std::map<hwc2_display_t, enum DisplayStatus> deferred_hotplug_events_; 94*0a9764feSAndroid Build Coastguard Worker std::vector<hwc2_display_t> displays_for_removal_list_; 95*0a9764feSAndroid Build Coastguard Worker 96*0a9764feSAndroid Build Coastguard Worker uint32_t last_display_handle_ = kPrimaryDisplay; 97*0a9764feSAndroid Build Coastguard Worker }; 98*0a9764feSAndroid Build Coastguard Worker } // namespace android