1 /* 2 * Copyright (C) 2016 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 <hardware/hwcomposer2.h> 20 21 #include "drm/ResourceManager.h" 22 #include "hwc2_device/HwcDisplay.h" 23 24 namespace android { 25 26 class DrmHwcTwo : public PipelineToFrontendBindingInterface { 27 public: 28 DrmHwcTwo(); 29 ~DrmHwcTwo() override = default; 30 31 std::pair<HWC2_PFN_HOTPLUG, hwc2_callback_data_t> hotplug_callback_{}; 32 std::pair<HWC2_PFN_VSYNC, hwc2_callback_data_t> vsync_callback_{}; 33 #if __ANDROID_API__ > 29 34 std::pair<HWC2_PFN_VSYNC_2_4, hwc2_callback_data_t> vsync_2_4_callback_{}; 35 std::pair<HWC2_PFN_VSYNC_PERIOD_TIMING_CHANGED, hwc2_callback_data_t> 36 period_timing_changed_callback_{}; 37 #endif 38 std::pair<HWC2_PFN_REFRESH, hwc2_callback_data_t> refresh_callback_{}; 39 40 // Device functions 41 HWC2::Error CreateVirtualDisplay(uint32_t width, uint32_t height, 42 int32_t *format, hwc2_display_t *display); 43 HWC2::Error DestroyVirtualDisplay(hwc2_display_t display); 44 void Dump(uint32_t *outSize, char *outBuffer); 45 uint32_t GetMaxVirtualDisplayCount(); 46 HWC2::Error RegisterCallback(int32_t descriptor, hwc2_callback_data_t data, 47 hwc2_function_pointer_t function); 48 GetDisplay(hwc2_display_t display_handle)49 auto GetDisplay(hwc2_display_t display_handle) { 50 return displays_.count(display_handle) != 0 51 ? displays_[display_handle].get() 52 : nullptr; 53 } 54 GetResMan()55 auto &GetResMan() { 56 return resource_manager_; 57 } 58 ScheduleHotplugEvent(hwc2_display_t displayid,bool connected)59 void ScheduleHotplugEvent(hwc2_display_t displayid, bool connected) { 60 deferred_hotplug_events_[displayid] = connected; 61 } 62 63 // PipelineToFrontendBindingInterface 64 bool BindDisplay(std::shared_ptr<DrmDisplayPipeline> pipeline) override; 65 bool UnbindDisplay(std::shared_ptr<DrmDisplayPipeline> pipeline) override; 66 void FinalizeDisplayBinding() override; 67 68 void SendVsyncEventToClient(hwc2_display_t displayid, int64_t timestamp, 69 uint32_t vsync_period) const; 70 void SendVsyncPeriodTimingChangedEventToClient(hwc2_display_t displayid, 71 int64_t timestamp) const; 72 73 private: 74 void SendHotplugEventToClient(hwc2_display_t displayid, bool connected) const; 75 76 ResourceManager resource_manager_; 77 std::map<hwc2_display_t, std::unique_ptr<HwcDisplay>> displays_; 78 std::map<std::shared_ptr<DrmDisplayPipeline>, hwc2_display_t> 79 display_handles_; 80 81 std::string mDumpString; 82 83 std::map<hwc2_display_t, bool> deferred_hotplug_events_; 84 std::vector<hwc2_display_t> displays_for_removal_list_; 85 86 uint32_t last_display_handle_ = kPrimaryDisplay; 87 }; 88 } // namespace android 89