blob: beb2e5fcc9e883de4fb9e95f21b05a16012b8baa [file] [log] [blame]
Sean Pauled2ec4b2016-03-10 15:35:40 -05001/*
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
Matvii Zorin0ddc3292020-07-27 18:29:15 +030017#ifndef ANDROID_DRM_HWC_TWO_H_
18#define ANDROID_DRM_HWC_TWO_H_
19
Sean Pauled2ec4b2016-03-10 15:35:40 -050020#include <hardware/hwcomposer2.h>
Roman Stratiienko65f2ba82019-12-20 17:04:01 +020021#include <math.h>
Roman Stratiienkoaa3cd542020-08-29 11:26:16 +030022
Roman Kovalivskyi12b91a32019-12-11 19:09:51 +020023#include <array>
Sean Pauled2ec4b2016-03-10 15:35:40 -050024#include <map>
Roman Stratiienkof81d2c82022-01-11 19:47:24 +020025#include <optional>
Sean Pauled2ec4b2016-03-10 15:35:40 -050026
Roman Stratiienko13cc3662020-08-29 21:35:39 +030027#include "compositor/DrmDisplayCompositor.h"
Roman Stratiienkob2e9fe22020-10-03 10:52:36 +030028#include "compositor/Planner.h"
Roman Stratiienko13cc3662020-08-29 21:35:39 +030029#include "drm/ResourceManager.h"
30#include "drm/VSyncWorker.h"
Roman Stratiienkoaa3cd542020-08-29 11:26:16 +030031#include "drmhwcomposer.h"
Roman Stratiienkoaa3cd542020-08-29 11:26:16 +030032
Sean Pauled2ec4b2016-03-10 15:35:40 -050033namespace android {
34
Matvii Zorinef3c7972020-08-11 15:15:44 +030035class Backend;
36
Sean Pauled2ec4b2016-03-10 15:35:40 -050037class DrmHwcTwo : public hwc2_device_t {
38 public:
Sean Paulac874152016-03-10 16:00:26 -050039 static int HookDevOpen(const struct hw_module_t *module, const char *name,
40 struct hw_device_t **dev);
41
Sean Pauled2ec4b2016-03-10 15:35:40 -050042 DrmHwcTwo();
43
Sean Paulac874152016-03-10 16:00:26 -050044 HWC2::Error Init();
45
Roman Stratiienko863a3c22021-09-29 13:00:29 +030046 std::pair<HWC2_PFN_HOTPLUG, hwc2_callback_data_t> hotplug_callback_{};
47 std::pair<HWC2_PFN_VSYNC, hwc2_callback_data_t> vsync_callback_{};
Roman Stratiienko11ef8c52021-09-29 13:01:39 +030048#if PLATFORM_SDK_VERSION > 29
49 std::pair<HWC2_PFN_VSYNC_2_4, hwc2_callback_data_t> vsync_2_4_callback_{};
50#endif
Roman Stratiienko863a3c22021-09-29 13:00:29 +030051 std::pair<HWC2_PFN_REFRESH, hwc2_callback_data_t> refresh_callback_{};
Roman Stratiienko23701092020-09-26 02:08:41 +030052
Roman Stratiienko863a3c22021-09-29 13:00:29 +030053 std::mutex callback_lock_;
Roman Stratiienko23701092020-09-26 02:08:41 +030054
Sean Pauled2ec4b2016-03-10 15:35:40 -050055 class HwcLayer {
56 public:
Sean Paulac874152016-03-10 16:00:26 -050057 HWC2::Composition sf_type() const {
58 return sf_type_;
59 }
60 HWC2::Composition validated_type() const {
61 return validated_type_;
62 }
63 void accept_type_change() {
64 sf_type_ = validated_type_;
65 }
66 void set_validated_type(HWC2::Composition type) {
67 validated_type_ = type;
68 }
69 bool type_changed() const {
70 return sf_type_ != validated_type_;
71 }
72
73 uint32_t z_order() const {
74 return z_order_;
75 }
76
77 buffer_handle_t buffer() {
78 return buffer_;
79 }
80 void set_buffer(buffer_handle_t buffer) {
81 buffer_ = buffer;
82 }
83
Roman Stratiienko0d1a2cd2019-11-28 17:51:16 +020084 hwc_rect_t display_frame() {
85 return display_frame_;
86 }
87
Sean Paulac874152016-03-10 16:00:26 -050088 void PopulateDrmLayer(DrmHwcLayer *layer);
89
Roman Stratiienko65f2ba82019-12-20 17:04:01 +020090 bool RequireScalingOrPhasing() {
91 float src_width = source_crop_.right - source_crop_.left;
92 float src_height = source_crop_.bottom - source_crop_.top;
93
94 float dest_width = display_frame_.right - display_frame_.left;
95 float dest_height = display_frame_.bottom - display_frame_.top;
96
97 bool scaling = src_width != dest_width || src_height != dest_height;
98 bool phasing = (source_crop_.left - floor(source_crop_.left) != 0) ||
99 (source_crop_.top - floor(source_crop_.top) != 0);
100 return scaling || phasing;
101 }
102
Sean Paulac874152016-03-10 16:00:26 -0500103 // Layer hooks
Roman Stratiienkoaaaa4692021-09-29 12:50:10 +0300104 HWC2::Error SetCursorPosition(int32_t /*x*/, int32_t /*y*/);
Sean Pauled2ec4b2016-03-10 15:35:40 -0500105 HWC2::Error SetLayerBlendMode(int32_t mode);
106 HWC2::Error SetLayerBuffer(buffer_handle_t buffer, int32_t acquire_fence);
Roman Stratiienkoaaaa4692021-09-29 12:50:10 +0300107 HWC2::Error SetLayerColor(hwc_color_t /*color*/);
Sean Pauled2ec4b2016-03-10 15:35:40 -0500108 HWC2::Error SetLayerCompositionType(int32_t type);
109 HWC2::Error SetLayerDataspace(int32_t dataspace);
110 HWC2::Error SetLayerDisplayFrame(hwc_rect_t frame);
111 HWC2::Error SetLayerPlaneAlpha(float alpha);
112 HWC2::Error SetLayerSidebandStream(const native_handle_t *stream);
113 HWC2::Error SetLayerSourceCrop(hwc_frect_t crop);
114 HWC2::Error SetLayerSurfaceDamage(hwc_region_t damage);
115 HWC2::Error SetLayerTransform(int32_t transform);
116 HWC2::Error SetLayerVisibleRegion(hwc_region_t visible);
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +0200117 HWC2::Error SetLayerZOrder(uint32_t order);
Sean Paulac874152016-03-10 16:00:26 -0500118
Roman Stratiienko0fade372021-02-20 13:59:55 +0200119 UniqueFd acquire_fence_;
120
Roman Stratiienko3e2f9e72021-05-21 14:33:28 +0300121 /*
122 * Release fence is not used.
123 * There is no release fence support available in the DRM/KMS. In case no
124 * release fence provided application will use this buffer for writing when
125 * the next frame present fence is signaled.
126 */
Roman Stratiienko0fade372021-02-20 13:59:55 +0200127 UniqueFd release_fence_;
128
Sean Paulac874152016-03-10 16:00:26 -0500129 private:
130 // sf_type_ stores the initial type given to us by surfaceflinger,
131 // validated_type_ stores the type after running ValidateDisplay
132 HWC2::Composition sf_type_ = HWC2::Composition::Invalid;
133 HWC2::Composition validated_type_ = HWC2::Composition::Invalid;
134
John Stultz62307032019-02-27 21:35:03 -0800135 buffer_handle_t buffer_ = NULL;
Sean Paulac874152016-03-10 16:00:26 -0500136 hwc_rect_t display_frame_;
137 float alpha_ = 1.0f;
138 hwc_frect_t source_crop_;
Roman Stratiienko2ed4cbe2021-09-29 12:47:35 +0300139 DrmHwcTransform transform_ = DrmHwcTransform::kIdentity;
Sean Paulac874152016-03-10 16:00:26 -0500140 uint32_t z_order_ = 0;
Roman Stratiienko5063d532021-09-29 12:47:31 +0300141 DrmHwcBlending blending_ = DrmHwcBlending::kNone;
Roman Stratiienko515da8f2021-09-29 12:47:21 +0300142 DrmHwcColorSpace color_space_ = DrmHwcColorSpace::kUndefined;
143 DrmHwcSampleRange sample_range_ = DrmHwcSampleRange::kUndefined;
Sean Paulac874152016-03-10 16:00:26 -0500144 };
145
Sean Pauled2ec4b2016-03-10 15:35:40 -0500146 class HwcDisplay {
147 public:
Alexandru Gheorghe6f0030f2018-05-01 17:25:48 +0100148 HwcDisplay(ResourceManager *resource_manager, DrmDevice *drm,
Roman Stratiienko863a3c22021-09-29 13:00:29 +0300149 hwc2_display_t handle, HWC2::DisplayType type, DrmHwcTwo *hwc2);
Sean Paulac874152016-03-10 16:00:26 -0500150 HwcDisplay(const HwcDisplay &) = delete;
151 HWC2::Error Init(std::vector<DrmPlane *> *planes);
152
Roman Stratiienko2a1f1ae2021-10-23 17:47:35 +0300153 HWC2::Error CreateComposition(AtomicCommitArgs &a_args);
Matvii Zorined90ef92021-01-29 18:32:06 +0200154 std::vector<DrmHwcTwo::HwcLayer *> GetOrderLayersByZPos();
Roman Kovalivskyi8fae1562020-01-30 20:20:47 +0200155
Andrii Chepurnyi495e4cc2018-08-01 17:42:56 +0300156 void ClearDisplay();
Sean Paulac874152016-03-10 16:00:26 -0500157
Roman Stratiienko0d1a2cd2019-11-28 17:51:16 +0200158 std::string Dump();
159
Sean Pauled2ec4b2016-03-10 15:35:40 -0500160 // HWC Hooks
161 HWC2::Error AcceptDisplayChanges();
162 HWC2::Error CreateLayer(hwc2_layer_t *layer);
163 HWC2::Error DestroyLayer(hwc2_layer_t layer);
Roman Stratiienkoa148f212021-11-16 18:23:18 +0200164 HWC2::Error GetActiveConfig(hwc2_config_t *config) const;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500165 HWC2::Error GetChangedCompositionTypes(uint32_t *num_elements,
166 hwc2_layer_t *layers,
167 int32_t *types);
168 HWC2::Error GetClientTargetSupport(uint32_t width, uint32_t height,
169 int32_t format, int32_t dataspace);
170 HWC2::Error GetColorModes(uint32_t *num_modes, int32_t *modes);
171 HWC2::Error GetDisplayAttribute(hwc2_config_t config, int32_t attribute,
172 int32_t *value);
173 HWC2::Error GetDisplayConfigs(uint32_t *num_configs,
174 hwc2_config_t *configs);
175 HWC2::Error GetDisplayName(uint32_t *size, char *name);
176 HWC2::Error GetDisplayRequests(int32_t *display_requests,
177 uint32_t *num_elements, hwc2_layer_t *layers,
178 int32_t *layer_requests);
179 HWC2::Error GetDisplayType(int32_t *type);
Andrii Chepurnyi50d37452020-04-24 14:20:24 +0300180#if PLATFORM_SDK_VERSION > 27
181 HWC2::Error GetRenderIntents(int32_t mode, uint32_t *outNumIntents,
182 int32_t *outIntents);
Andrii Chepurnyi857a53f2020-04-29 23:15:28 +0300183 HWC2::Error SetColorModeWithIntent(int32_t mode, int32_t intent);
Andrii Chepurnyi50d37452020-04-24 14:20:24 +0300184#endif
John Stultz8c7229d2020-02-07 21:31:08 +0000185#if PLATFORM_SDK_VERSION > 28
Lowry Li (Arm Technology China)b3d81782019-12-18 14:28:22 +0800186 HWC2::Error GetDisplayIdentificationData(uint8_t *outPort,
187 uint32_t *outDataSize,
188 uint8_t *outData);
189 HWC2::Error GetDisplayCapabilities(uint32_t *outNumCapabilities,
190 uint32_t *outCapabilities);
Andrii Chepurnyi2619aab2020-07-03 11:21:33 +0300191 HWC2::Error GetDisplayBrightnessSupport(bool *supported);
192 HWC2::Error SetDisplayBrightness(float);
John Stultz8c7229d2020-02-07 21:31:08 +0000193#endif
Roman Stratiienko6f5df172020-09-27 22:48:08 +0300194#if PLATFORM_SDK_VERSION > 29
195 HWC2::Error GetDisplayConnectionType(uint32_t *outType);
196 HWC2::Error GetDisplayVsyncPeriod(hwc2_vsync_period_t *outVsyncPeriod);
197
198 HWC2::Error SetActiveConfigWithConstraints(
199 hwc2_config_t config,
200 hwc_vsync_period_change_constraints_t *vsyncPeriodChangeConstraints,
201 hwc_vsync_period_change_timeline_t *outTimeline);
202 HWC2::Error SetAutoLowLatencyMode(bool on);
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +0200203 HWC2::Error GetSupportedContentTypes(
204 uint32_t *outNumSupportedContentTypes,
205 const uint32_t *outSupportedContentTypes);
Roman Stratiienko6f5df172020-09-27 22:48:08 +0300206
207 HWC2::Error SetContentType(int32_t contentType);
208#endif
209
Sean Pauled2ec4b2016-03-10 15:35:40 -0500210 HWC2::Error GetDozeSupport(int32_t *support);
Sean Paulac874152016-03-10 16:00:26 -0500211 HWC2::Error GetHdrCapabilities(uint32_t *num_types, int32_t *types,
212 float *max_luminance,
213 float *max_average_luminance,
214 float *min_luminance);
Sean Pauled2ec4b2016-03-10 15:35:40 -0500215 HWC2::Error GetReleaseFences(uint32_t *num_elements, hwc2_layer_t *layers,
216 int32_t *fences);
Matteo Franchinc56eede2019-12-03 17:10:38 +0000217 HWC2::Error PresentDisplay(int32_t *present_fence);
Sean Pauled2ec4b2016-03-10 15:35:40 -0500218 HWC2::Error SetActiveConfig(hwc2_config_t config);
Andrii Chepurnyi495e4cc2018-08-01 17:42:56 +0300219 HWC2::Error ChosePreferredConfig();
Sean Pauled2ec4b2016-03-10 15:35:40 -0500220 HWC2::Error SetClientTarget(buffer_handle_t target, int32_t acquire_fence,
221 int32_t dataspace, hwc_region_t damage);
222 HWC2::Error SetColorMode(int32_t mode);
223 HWC2::Error SetColorTransform(const float *matrix, int32_t hint);
224 HWC2::Error SetOutputBuffer(buffer_handle_t buffer, int32_t release_fence);
225 HWC2::Error SetPowerMode(int32_t mode);
226 HWC2::Error SetVsyncEnabled(int32_t enabled);
227 HWC2::Error ValidateDisplay(uint32_t *num_types, uint32_t *num_requests);
Vincent Donnefort9abec032019-10-09 15:43:43 +0100228 HwcLayer *get_layer(hwc2_layer_t layer) {
229 auto it = layers_.find(layer);
230 if (it == layers_.end())
231 return nullptr;
232 return &it->second;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500233 }
234
Matvii Zorin373de712020-08-11 14:05:12 +0300235 /* Statistics */
236 struct Stats {
237 Stats minus(Stats b) {
238 return {total_frames_ - b.total_frames_,
239 total_pixops_ - b.total_pixops_,
240 gpu_pixops_ - b.gpu_pixops_,
241 failed_kms_validate_ - b.failed_kms_validate_,
242 failed_kms_present_ - b.failed_kms_present_,
243 frames_flattened_ - b.frames_flattened_};
244 }
245
246 uint32_t total_frames_ = 0;
247 uint64_t total_pixops_ = 0;
248 uint64_t gpu_pixops_ = 0;
249 uint32_t failed_kms_validate_ = 0;
250 uint32_t failed_kms_present_ = 0;
251 uint32_t frames_flattened_ = 0;
252 };
253
Roman Stratiienkoa148f212021-11-16 18:23:18 +0200254 struct HwcDisplayConfig {
255 int id{};
256 int group_id{};
257 DrmMode mode;
258 bool disabled{};
259
260 bool IsInterlaced() {
261 return (mode.flags() & DRM_MODE_FLAG_INTERLACE) != 0;
262 }
263 };
264
265 std::map<int /*config_id*/, struct HwcDisplayConfig> hwc_configs_;
266
267 int active_config_id_ = 0;
268 int preferred_config_id_ = 0;
269
Roman Stratiienko24a7fc42021-12-23 16:25:20 +0200270 const Backend *backend() const;
271 void set_backend(std::unique_ptr<Backend> backend);
Matvii Zorinef3c7972020-08-11 15:15:44 +0300272
Matvii Zorin373de712020-08-11 14:05:12 +0300273 const std::vector<DrmPlane *> &primary_planes() const {
274 return primary_planes_;
275 }
276
277 const std::vector<DrmPlane *> &overlay_planes() const {
278 return overlay_planes_;
279 }
280
281 std::map<hwc2_layer_t, HwcLayer> &layers() {
282 return layers_;
283 }
284
285 const DrmDisplayCompositor &compositor() const {
286 return compositor_;
287 }
288
289 const DrmDevice *drm() const {
290 return drm_;
291 }
292
293 const DrmConnector *connector() const {
294 return connector_;
295 }
296
Matvii Zorin373de712020-08-11 14:05:12 +0300297 ResourceManager *resource_manager() const {
298 return resource_manager_;
299 }
300
301 android_color_transform_t &color_transform_hint() {
302 return color_transform_hint_;
303 }
304
305 Stats &total_stats() {
306 return total_stats_;
307 }
308
Roman Stratiienkoe8c06792021-09-30 10:09:31 +0300309 /* returns true if composition should be sent to client */
310 bool ProcessClientFlatteningState(bool skip) {
311 int flattenning_state = flattenning_state_;
312 if (flattenning_state == ClientFlattenningState::Disabled) {
313 return false;
314 }
315
316 if (skip) {
317 flattenning_state_ = ClientFlattenningState::NotRequired;
318 return false;
319 }
320
321 if (flattenning_state == ClientFlattenningState::ClientRefreshRequested) {
322 flattenning_state_ = ClientFlattenningState::Flattened;
323 return true;
324 }
325
326 flattening_vsync_worker_.VSyncControl(true);
327 flattenning_state_ = ClientFlattenningState::VsyncCountdownMax;
328 return false;
329 }
330
Sean Pauled2ec4b2016-03-10 15:35:40 -0500331 private:
Roman Stratiienkoe8c06792021-09-30 10:09:31 +0300332 enum ClientFlattenningState : int32_t {
333 Disabled = -3,
334 NotRequired = -2,
335 Flattened = -1,
336 ClientRefreshRequested = 0,
337 VsyncCountdownMax = 60, /* 1 sec @ 60FPS */
338 };
339
340 std::atomic_int flattenning_state_{ClientFlattenningState::NotRequired};
341 VSyncWorker flattening_vsync_worker_;
342
Roman Kovalivskyi12b91a32019-12-11 19:09:51 +0200343 constexpr static size_t MATRIX_SIZE = 16;
344
Roman Stratiienko863a3c22021-09-29 13:00:29 +0300345 DrmHwcTwo *hwc2_;
346
Roman Stratiienkof81d2c82022-01-11 19:47:24 +0200347 std::optional<DrmMode> staged_mode;
348
Alexandru Gheorghe6f0030f2018-05-01 17:25:48 +0100349 ResourceManager *resource_manager_;
Alexandru Gheorghe0f5abd72018-05-01 14:37:10 +0100350 DrmDevice *drm_;
Sean Paulac874152016-03-10 16:00:26 -0500351 DrmDisplayCompositor compositor_;
Sean Paulac874152016-03-10 16:00:26 -0500352 std::unique_ptr<Planner> planner_;
Sean Paulac874152016-03-10 16:00:26 -0500353
354 std::vector<DrmPlane *> primary_planes_;
355 std::vector<DrmPlane *> overlay_planes_;
356
Matvii Zorinef3c7972020-08-11 15:15:44 +0300357 std::unique_ptr<Backend> backend_;
358
Sean Paulac874152016-03-10 16:00:26 -0500359 VSyncWorker vsync_worker_;
360 DrmConnector *connector_ = NULL;
361 DrmCrtc *crtc_ = NULL;
362 hwc2_display_t handle_;
363 HWC2::DisplayType type_;
364 uint32_t layer_idx_ = 0;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500365 std::map<hwc2_layer_t, HwcLayer> layers_;
Sean Paulac874152016-03-10 16:00:26 -0500366 HwcLayer client_layer_;
Roman Stratiienkob3b5c1e2021-02-15 13:44:19 +0200367 int32_t color_mode_{};
368 std::array<float, MATRIX_SIZE> color_transform_matrix_{};
Roman Kovalivskyi12b91a32019-12-11 19:09:51 +0200369 android_color_transform_t color_transform_hint_;
Sean Paulac874152016-03-10 16:00:26 -0500370
371 uint32_t frame_no_ = 0;
Matvii Zorin373de712020-08-11 14:05:12 +0300372 Stats total_stats_;
373 Stats prev_stats_;
Roman Stratiienko0d1a2cd2019-11-28 17:51:16 +0200374 std::string DumpDelta(DrmHwcTwo::HwcDisplay::Stats delta);
Sean Pauled2ec4b2016-03-10 15:35:40 -0500375 };
376
Matvii Zorine0e7c5c2020-07-27 18:35:39 +0300377 private:
Sean Pauled2ec4b2016-03-10 15:35:40 -0500378 static DrmHwcTwo *toDrmHwcTwo(hwc2_device_t *dev) {
379 return static_cast<DrmHwcTwo *>(dev);
380 }
381
382 template <typename PFN, typename T>
383 static hwc2_function_pointer_t ToHook(T function) {
384 static_assert(std::is_same<PFN, T>::value, "Incompatible fn pointer");
385 return reinterpret_cast<hwc2_function_pointer_t>(function);
386 }
387
388 template <typename T, typename HookType, HookType func, typename... Args>
389 static T DeviceHook(hwc2_device_t *dev, Args... args) {
390 DrmHwcTwo *hwc = toDrmHwcTwo(dev);
391 return static_cast<T>(((*hwc).*func)(std::forward<Args>(args)...));
392 }
393
Vincent Donnefort315444c2019-10-09 14:23:42 +0100394 static HwcDisplay *GetDisplay(DrmHwcTwo *hwc, hwc2_display_t display_handle) {
395 auto it = hwc->displays_.find(display_handle);
396 if (it == hwc->displays_.end())
397 return nullptr;
398
399 return &it->second;
400 }
401
Sean Pauled2ec4b2016-03-10 15:35:40 -0500402 template <typename HookType, HookType func, typename... Args>
403 static int32_t DisplayHook(hwc2_device_t *dev, hwc2_display_t display_handle,
404 Args... args) {
Vincent Donnefort315444c2019-10-09 14:23:42 +0100405 HwcDisplay *display = GetDisplay(toDrmHwcTwo(dev), display_handle);
406 if (!display)
407 return static_cast<int32_t>(HWC2::Error::BadDisplay);
408
409 return static_cast<int32_t>((display->*func)(std::forward<Args>(args)...));
Sean Pauled2ec4b2016-03-10 15:35:40 -0500410 }
411
412 template <typename HookType, HookType func, typename... Args>
413 static int32_t LayerHook(hwc2_device_t *dev, hwc2_display_t display_handle,
414 hwc2_layer_t layer_handle, Args... args) {
Vincent Donnefort315444c2019-10-09 14:23:42 +0100415 HwcDisplay *display = GetDisplay(toDrmHwcTwo(dev), display_handle);
416 if (!display)
417 return static_cast<int32_t>(HWC2::Error::BadDisplay);
418
Vincent Donnefort9abec032019-10-09 15:43:43 +0100419 HwcLayer *layer = display->get_layer(layer_handle);
420 if (!layer)
421 return static_cast<int32_t>(HWC2::Error::BadLayer);
422
423 return static_cast<int32_t>((layer->*func)(std::forward<Args>(args)...));
Sean Pauled2ec4b2016-03-10 15:35:40 -0500424 }
425
426 // hwc2_device_t hooks
427 static int HookDevClose(hw_device_t *dev);
428 static void HookDevGetCapabilities(hwc2_device_t *dev, uint32_t *out_count,
429 int32_t *out_capabilities);
430 static hwc2_function_pointer_t HookDevGetFunction(struct hwc2_device *device,
431 int32_t descriptor);
432
433 // Device functions
434 HWC2::Error CreateVirtualDisplay(uint32_t width, uint32_t height,
Sean Paulf72cccd2018-08-27 13:59:08 -0400435 int32_t *format, hwc2_display_t *display);
Sean Pauled2ec4b2016-03-10 15:35:40 -0500436 HWC2::Error DestroyVirtualDisplay(hwc2_display_t display);
Roman Stratiienko0d1a2cd2019-11-28 17:51:16 +0200437 void Dump(uint32_t *outSize, char *outBuffer);
Sean Pauled2ec4b2016-03-10 15:35:40 -0500438 uint32_t GetMaxVirtualDisplayCount();
439 HWC2::Error RegisterCallback(int32_t descriptor, hwc2_callback_data_t data,
440 hwc2_function_pointer_t function);
Andrii Chepurnyi495e4cc2018-08-01 17:42:56 +0300441 HWC2::Error CreateDisplay(hwc2_display_t displ, HWC2::DisplayType type);
442 void HandleDisplayHotplug(hwc2_display_t displayid, int state);
443 void HandleInitialHotplugState(DrmDevice *drmDevice);
Sean Pauled2ec4b2016-03-10 15:35:40 -0500444
Roman Stratiienko1e053b42021-10-25 22:54:20 +0300445 void HandleHotplugUEvent();
446
Alexandru Gheorghec5463582018-03-27 15:52:02 +0100447 ResourceManager resource_manager_;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500448 std::map<hwc2_display_t, HwcDisplay> displays_;
Roman Stratiienko0d1a2cd2019-11-28 17:51:16 +0200449
450 std::string mDumpString;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500451};
Sean Paulf72cccd2018-08-27 13:59:08 -0400452} // namespace android
Matvii Zorin0ddc3292020-07-27 18:29:15 +0300453
454#endif