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