blob: eb74f3217c4ddc5ba109177e8247ecd4d585bd5d [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
Matvii Zorinef3c7972020-08-11 15:15:44 +0300270 const Backend *backend() const {
271 return backend_.get();
272 }
273 void set_backend(std::unique_ptr<Backend> backend) {
274 backend_ = std::move(backend);
275 }
276
Matvii Zorin373de712020-08-11 14:05:12 +0300277 const std::vector<DrmPlane *> &primary_planes() const {
278 return primary_planes_;
279 }
280
281 const std::vector<DrmPlane *> &overlay_planes() const {
282 return overlay_planes_;
283 }
284
285 std::map<hwc2_layer_t, HwcLayer> &layers() {
286 return layers_;
287 }
288
289 const DrmDisplayCompositor &compositor() const {
290 return compositor_;
291 }
292
293 const DrmDevice *drm() const {
294 return drm_;
295 }
296
297 const DrmConnector *connector() const {
298 return connector_;
299 }
300
Matvii Zorin373de712020-08-11 14:05:12 +0300301 ResourceManager *resource_manager() const {
302 return resource_manager_;
303 }
304
305 android_color_transform_t &color_transform_hint() {
306 return color_transform_hint_;
307 }
308
309 Stats &total_stats() {
310 return total_stats_;
311 }
312
Roman Stratiienkoe8c06792021-09-30 10:09:31 +0300313 /* returns true if composition should be sent to client */
314 bool ProcessClientFlatteningState(bool skip) {
315 int flattenning_state = flattenning_state_;
316 if (flattenning_state == ClientFlattenningState::Disabled) {
317 return false;
318 }
319
320 if (skip) {
321 flattenning_state_ = ClientFlattenningState::NotRequired;
322 return false;
323 }
324
325 if (flattenning_state == ClientFlattenningState::ClientRefreshRequested) {
326 flattenning_state_ = ClientFlattenningState::Flattened;
327 return true;
328 }
329
330 flattening_vsync_worker_.VSyncControl(true);
331 flattenning_state_ = ClientFlattenningState::VsyncCountdownMax;
332 return false;
333 }
334
Sean Pauled2ec4b2016-03-10 15:35:40 -0500335 private:
Roman Stratiienkoe8c06792021-09-30 10:09:31 +0300336 enum ClientFlattenningState : int32_t {
337 Disabled = -3,
338 NotRequired = -2,
339 Flattened = -1,
340 ClientRefreshRequested = 0,
341 VsyncCountdownMax = 60, /* 1 sec @ 60FPS */
342 };
343
344 std::atomic_int flattenning_state_{ClientFlattenningState::NotRequired};
345 VSyncWorker flattening_vsync_worker_;
346
Roman Kovalivskyi12b91a32019-12-11 19:09:51 +0200347 constexpr static size_t MATRIX_SIZE = 16;
348
Roman Stratiienko863a3c22021-09-29 13:00:29 +0300349 DrmHwcTwo *hwc2_;
350
Roman Stratiienkof81d2c82022-01-11 19:47:24 +0200351 std::optional<DrmMode> staged_mode;
352
Alexandru Gheorghe6f0030f2018-05-01 17:25:48 +0100353 ResourceManager *resource_manager_;
Alexandru Gheorghe0f5abd72018-05-01 14:37:10 +0100354 DrmDevice *drm_;
Sean Paulac874152016-03-10 16:00:26 -0500355 DrmDisplayCompositor compositor_;
Sean Paulac874152016-03-10 16:00:26 -0500356 std::unique_ptr<Planner> planner_;
Sean Paulac874152016-03-10 16:00:26 -0500357
358 std::vector<DrmPlane *> primary_planes_;
359 std::vector<DrmPlane *> overlay_planes_;
360
Matvii Zorinef3c7972020-08-11 15:15:44 +0300361 std::unique_ptr<Backend> backend_;
362
Sean Paulac874152016-03-10 16:00:26 -0500363 VSyncWorker vsync_worker_;
364 DrmConnector *connector_ = NULL;
365 DrmCrtc *crtc_ = NULL;
366 hwc2_display_t handle_;
367 HWC2::DisplayType type_;
368 uint32_t layer_idx_ = 0;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500369 std::map<hwc2_layer_t, HwcLayer> layers_;
Sean Paulac874152016-03-10 16:00:26 -0500370 HwcLayer client_layer_;
Roman Stratiienkob3b5c1e2021-02-15 13:44:19 +0200371 int32_t color_mode_{};
372 std::array<float, MATRIX_SIZE> color_transform_matrix_{};
Roman Kovalivskyi12b91a32019-12-11 19:09:51 +0200373 android_color_transform_t color_transform_hint_;
Sean Paulac874152016-03-10 16:00:26 -0500374
375 uint32_t frame_no_ = 0;
Matvii Zorin373de712020-08-11 14:05:12 +0300376 Stats total_stats_;
377 Stats prev_stats_;
Roman Stratiienko0d1a2cd2019-11-28 17:51:16 +0200378 std::string DumpDelta(DrmHwcTwo::HwcDisplay::Stats delta);
Sean Pauled2ec4b2016-03-10 15:35:40 -0500379 };
380
Matvii Zorine0e7c5c2020-07-27 18:35:39 +0300381 private:
Sean Pauled2ec4b2016-03-10 15:35:40 -0500382 static DrmHwcTwo *toDrmHwcTwo(hwc2_device_t *dev) {
383 return static_cast<DrmHwcTwo *>(dev);
384 }
385
386 template <typename PFN, typename T>
387 static hwc2_function_pointer_t ToHook(T function) {
388 static_assert(std::is_same<PFN, T>::value, "Incompatible fn pointer");
389 return reinterpret_cast<hwc2_function_pointer_t>(function);
390 }
391
392 template <typename T, typename HookType, HookType func, typename... Args>
393 static T DeviceHook(hwc2_device_t *dev, Args... args) {
394 DrmHwcTwo *hwc = toDrmHwcTwo(dev);
395 return static_cast<T>(((*hwc).*func)(std::forward<Args>(args)...));
396 }
397
Vincent Donnefort315444c2019-10-09 14:23:42 +0100398 static HwcDisplay *GetDisplay(DrmHwcTwo *hwc, hwc2_display_t display_handle) {
399 auto it = hwc->displays_.find(display_handle);
400 if (it == hwc->displays_.end())
401 return nullptr;
402
403 return &it->second;
404 }
405
Sean Pauled2ec4b2016-03-10 15:35:40 -0500406 template <typename HookType, HookType func, typename... Args>
407 static int32_t DisplayHook(hwc2_device_t *dev, hwc2_display_t display_handle,
408 Args... args) {
Vincent Donnefort315444c2019-10-09 14:23:42 +0100409 HwcDisplay *display = GetDisplay(toDrmHwcTwo(dev), display_handle);
410 if (!display)
411 return static_cast<int32_t>(HWC2::Error::BadDisplay);
412
413 return static_cast<int32_t>((display->*func)(std::forward<Args>(args)...));
Sean Pauled2ec4b2016-03-10 15:35:40 -0500414 }
415
416 template <typename HookType, HookType func, typename... Args>
417 static int32_t LayerHook(hwc2_device_t *dev, hwc2_display_t display_handle,
418 hwc2_layer_t layer_handle, Args... args) {
Vincent Donnefort315444c2019-10-09 14:23:42 +0100419 HwcDisplay *display = GetDisplay(toDrmHwcTwo(dev), display_handle);
420 if (!display)
421 return static_cast<int32_t>(HWC2::Error::BadDisplay);
422
Vincent Donnefort9abec032019-10-09 15:43:43 +0100423 HwcLayer *layer = display->get_layer(layer_handle);
424 if (!layer)
425 return static_cast<int32_t>(HWC2::Error::BadLayer);
426
427 return static_cast<int32_t>((layer->*func)(std::forward<Args>(args)...));
Sean Pauled2ec4b2016-03-10 15:35:40 -0500428 }
429
430 // hwc2_device_t hooks
431 static int HookDevClose(hw_device_t *dev);
432 static void HookDevGetCapabilities(hwc2_device_t *dev, uint32_t *out_count,
433 int32_t *out_capabilities);
434 static hwc2_function_pointer_t HookDevGetFunction(struct hwc2_device *device,
435 int32_t descriptor);
436
437 // Device functions
438 HWC2::Error CreateVirtualDisplay(uint32_t width, uint32_t height,
Sean Paulf72cccd2018-08-27 13:59:08 -0400439 int32_t *format, hwc2_display_t *display);
Sean Pauled2ec4b2016-03-10 15:35:40 -0500440 HWC2::Error DestroyVirtualDisplay(hwc2_display_t display);
Roman Stratiienko0d1a2cd2019-11-28 17:51:16 +0200441 void Dump(uint32_t *outSize, char *outBuffer);
Sean Pauled2ec4b2016-03-10 15:35:40 -0500442 uint32_t GetMaxVirtualDisplayCount();
443 HWC2::Error RegisterCallback(int32_t descriptor, hwc2_callback_data_t data,
444 hwc2_function_pointer_t function);
Andrii Chepurnyi495e4cc2018-08-01 17:42:56 +0300445 HWC2::Error CreateDisplay(hwc2_display_t displ, HWC2::DisplayType type);
446 void HandleDisplayHotplug(hwc2_display_t displayid, int state);
447 void HandleInitialHotplugState(DrmDevice *drmDevice);
Sean Pauled2ec4b2016-03-10 15:35:40 -0500448
Roman Stratiienko1e053b42021-10-25 22:54:20 +0300449 void HandleHotplugUEvent();
450
Alexandru Gheorghec5463582018-03-27 15:52:02 +0100451 ResourceManager resource_manager_;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500452 std::map<hwc2_display_t, HwcDisplay> displays_;
Roman Stratiienko0d1a2cd2019-11-28 17:51:16 +0200453
454 std::string mDumpString;
Sean Pauled2ec4b2016-03-10 15:35:40 -0500455};
Sean Paulf72cccd2018-08-27 13:59:08 -0400456} // namespace android
Matvii Zorin0ddc3292020-07-27 18:29:15 +0300457
458#endif