summaryrefslogtreecommitdiff
path: root/hwc2/Hwc2Module.cpp (plain)
blob: 366ebbd2d356043dae94751916fa30ea849300b9
1/*
2 * Copyright (c) 2017 Amlogic, Inc. All rights reserved.
3 *
4 * This source code is subject to the terms and conditions defined in the
5 * file 'LICENSE' which is part of this source code package.
6 *
7 * Description:
8 */
9
10#include <hardware/hardware.h>
11#include <hardware/hwcomposer.h>
12#include <hardware/hwcomposer2.h>
13
14#include <MesonLog.h>
15
16#include "MesonHwc2.h"
17
18typedef struct hwc2_impl {
19 hwc2_device_t base;
20 MesonHwc2 * impl;
21} hwc2_impl_t;
22
23#define GET_MESON_HWC() \
24 hwc2_impl_t * hwc = reinterpret_cast<hwc2_impl_t *>(device); \
25 MesonHwc2 * mesonhwc = hwc->impl;
26
27int32_t hwc2_create_virtual_display(
28 hwc2_device_t* device, uint32_t width, uint32_t height,
29 int32_t* format, hwc2_display_t* outDisplay) {
30 GET_MESON_HWC();
31 return mesonhwc->createVirtualDisplay(width, height, format, outDisplay);
32}
33
34int32_t hwc2_destroy_virtual_display(
35 hwc2_device_t* device, hwc2_display_t display) {
36 GET_MESON_HWC();
37 return mesonhwc->destroyVirtualDisplay(display);
38}
39
40void hwc2_dump(
41 hwc2_device_t* device, uint32_t* outSize, char* outBuffer) {
42 GET_MESON_HWC();
43 return mesonhwc->dump(outSize, outBuffer);
44}
45
46uint32_t hwc2_get_max_virtual_display_count(
47 hwc2_device_t* device) {
48 GET_MESON_HWC();
49 return mesonhwc->getMaxVirtualDisplayCount();
50}
51
52int32_t hwc2_accept_display_changes(
53 hwc2_device_t* device, hwc2_display_t display) {
54 GET_MESON_HWC();
55 return mesonhwc->acceptDisplayChanges(display);
56}
57
58int32_t hwc2_create_layer(hwc2_device_t* device,
59 hwc2_display_t display, hwc2_layer_t* outLayer) {
60 GET_MESON_HWC();
61 return mesonhwc->createLayer(display, outLayer);
62}
63
64int32_t hwc2_destroy_layer(
65 hwc2_device_t* device, hwc2_display_t display, hwc2_layer_t layer) {
66 GET_MESON_HWC();
67 return mesonhwc->destroyLayer(display, layer);
68}
69
70int32_t hwc2_get_active_config(
71 hwc2_device_t* device, hwc2_display_t display,
72 hwc2_config_t* outConfig) {
73 GET_MESON_HWC();
74 return mesonhwc->getActiveConfig(display, outConfig);
75}
76
77int32_t hwc2_get_changed_composition_types(
78 hwc2_device_t* device, hwc2_display_t display,
79 uint32_t* outNumElements, hwc2_layer_t* outLayers,
80 int32_t* outTypes) {
81 GET_MESON_HWC();
82 return mesonhwc->getChangedCompositionTypes(display, outNumElements,
83 outLayers, outTypes);
84}
85
86int32_t hwc2_get_client_target_support(
87 hwc2_device_t* device, hwc2_display_t display, uint32_t width,
88 uint32_t height, int32_t format, int32_t dataspace) {
89 GET_MESON_HWC();
90 return mesonhwc->getClientTargetSupport(display, width, height, format, dataspace);
91}
92
93int32_t hwc2_get_color_modes(
94 hwc2_device_t* device, hwc2_display_t display,
95 uint32_t* outNumModes, int32_t* outModes) {
96 GET_MESON_HWC();
97 return mesonhwc->getColorModes(display, outNumModes, outModes);
98}
99
100int32_t hwc2_get_display_attribute(
101 hwc2_device_t* device, hwc2_display_t display, hwc2_config_t config,
102 int32_t attribute, int32_t* outValue) {
103 GET_MESON_HWC();
104 return mesonhwc->getDisplayAttribute(display, config, attribute, outValue);
105}
106
107int32_t hwc2_get_display_configs(
108 hwc2_device_t* device, hwc2_display_t display,
109 uint32_t* outNumConfigs, hwc2_config_t* outConfigs) {
110 GET_MESON_HWC();
111 return mesonhwc->getDisplayConfigs(display, outNumConfigs, outConfigs);
112}
113
114int32_t hwc2_get_display_name(
115 hwc2_device_t* device, hwc2_display_t display,
116 uint32_t* outSize, char* outName) {
117 GET_MESON_HWC();
118 return mesonhwc->getDisplayName(display, outSize, outName);
119}
120
121int32_t hwc2_get_display_requests(
122 hwc2_device_t* device, hwc2_display_t display,
123 int32_t* outDisplayRequests, uint32_t* outNumElements,
124 hwc2_layer_t* outLayers, int32_t* outLayerRequests) {
125 GET_MESON_HWC();
126 return mesonhwc->getDisplayRequests(display, outDisplayRequests, outNumElements,
127 outLayers, outLayerRequests);
128}
129
130int32_t hwc2_get_display_type(
131 hwc2_device_t* device, hwc2_display_t display,
132 int32_t* outType) {
133 GET_MESON_HWC();
134 return mesonhwc->getDisplayType(display, outType);
135}
136
137int32_t hwc2_get_doze_support(
138 hwc2_device_t* device, hwc2_display_t display, int32_t* outSupport) {
139 GET_MESON_HWC();
140 return mesonhwc->getDozeSupport(display, outSupport);
141}
142
143int32_t hwc2_get_hdr_capabilities(
144 hwc2_device_t* device, hwc2_display_t display, uint32_t* outNumTypes,
145 int32_t* outTypes, float* outMaxLuminance,
146 float* outMaxAverageLuminance, float* outMinLuminance) {
147 GET_MESON_HWC();
148 return mesonhwc->getHdrCapabilities(display, outNumTypes, outTypes,
149 outMaxLuminance, outMaxAverageLuminance, outMinLuminance);
150}
151
152int32_t hwc2_get_release_fences(
153 hwc2_device_t* device, hwc2_display_t display, uint32_t* outNumElements,
154 hwc2_layer_t* outLayers, int32_t* outFences) {
155 GET_MESON_HWC();
156 return mesonhwc->getReleaseFences(display, outNumElements,
157 outLayers, outFences);
158}
159
160int32_t hwc2_present_display(
161 hwc2_device_t* device, hwc2_display_t display, int32_t* outPresentFence) {
162 GET_MESON_HWC();
163 return mesonhwc->presentDisplay(display, outPresentFence);
164}
165
166int32_t hwc2_register_callback(
167 hwc2_device_t* device, int32_t descriptor,
168 hwc2_callback_data_t callbackData, hwc2_function_pointer_t pointer) {
169 GET_MESON_HWC();
170 return mesonhwc->registerCallback(descriptor, callbackData, pointer);
171}
172
173int32_t hwc2_set_active_config(
174 hwc2_device_t* device, hwc2_display_t display, hwc2_config_t config) {
175 GET_MESON_HWC();
176 return mesonhwc->setActiveConfig(display, config);
177}
178
179int32_t hwc2_set_client_target(
180 hwc2_device_t* device, hwc2_display_t display, buffer_handle_t target,
181 int32_t acquireFence, int32_t dataspace, hwc_region_t damage) {
182 GET_MESON_HWC();
183 return mesonhwc->setClientTarget(display, target, acquireFence, dataspace, damage);
184}
185
186int32_t hwc2_set_color_mode(
187 hwc2_device_t* device, hwc2_display_t display, int32_t mode) {
188 GET_MESON_HWC();
189 return mesonhwc->setColorMode(display, mode);
190}
191
192int32_t hwc2_set_color_transform(
193 hwc2_device_t* device, hwc2_display_t display, const float* matrix, int32_t hint) {
194 GET_MESON_HWC();
195 return mesonhwc->setColorTransform(display, matrix, hint);
196}
197
198int32_t hwc2_set_output_buffer(
199 hwc2_device_t* device, hwc2_display_t display, buffer_handle_t buffer,
200 int32_t releaseFence) {
201 GET_MESON_HWC();
202 return mesonhwc->setOutputBuffer(display, buffer, releaseFence);
203}
204
205int32_t hwc2_set_power_mode(
206 hwc2_device_t* device, hwc2_display_t display, int32_t mode) {
207 GET_MESON_HWC();
208 return mesonhwc->setPowerMode(display, mode);
209}
210
211int32_t hwc2_set_vsync_enabled(
212 hwc2_device_t* device, hwc2_display_t display, int32_t enabled) {
213 GET_MESON_HWC();
214 return mesonhwc->setVsyncEnable(display, enabled);
215}
216
217int32_t hwc2_validate_display(
218 hwc2_device_t* device, hwc2_display_t display,
219 uint32_t* outNumTypes, uint32_t* outNumRequests) {
220 GET_MESON_HWC();
221 return mesonhwc->validateDisplay(display, outNumTypes, outNumRequests);
222}
223
224int32_t hwc2_set_cursor_position(
225 hwc2_device_t* device, hwc2_display_t display, hwc2_layer_t layer,
226 int32_t x, int32_t y) {
227 GET_MESON_HWC();
228 return mesonhwc->setCursorPosition(display, layer, x, y);
229}
230
231int32_t hwc2_set_layer_buffer(
232 hwc2_device_t* device, hwc2_display_t display, hwc2_layer_t layer,
233 buffer_handle_t buffer, int32_t acquireFence) {
234 GET_MESON_HWC();
235 return mesonhwc->setLayerBuffer(display, layer, buffer, acquireFence);
236}
237
238int32_t hwc2_set_layer_surface_damage(
239 hwc2_device_t* device, hwc2_display_t display, hwc2_layer_t layer,
240 hwc_region_t damage) {
241 GET_MESON_HWC();
242 return mesonhwc->setLayerSurfaceDamage(display, layer, damage);
243}
244
245int32_t hwc2_set_layer_blend_mode(
246 hwc2_device_t* device, hwc2_display_t display, hwc2_layer_t layer,
247 int32_t mode) {
248 GET_MESON_HWC();
249 return mesonhwc->setLayerBlendMode(display, layer, mode);
250}
251
252int32_t hwc2_set_layer_color(
253 hwc2_device_t* device, hwc2_display_t display, hwc2_layer_t layer,
254 hwc_color_t color) {
255 GET_MESON_HWC();
256 return mesonhwc->setLayerColor(display, layer, color);
257}
258
259int32_t hwc2_set_layer_composition_type(
260 hwc2_device_t* device, hwc2_display_t display, hwc2_layer_t layer,
261 int32_t type) {
262 GET_MESON_HWC();
263 return mesonhwc->setLayerCompositionType(display, layer, type);
264}
265
266int32_t hwc2_set_layer_dataspace(
267 hwc2_device_t* device, hwc2_display_t display, hwc2_layer_t layer,
268 int32_t dataspace) {
269 GET_MESON_HWC();
270 return mesonhwc->setLayerDataspace(display, layer, dataspace);
271}
272
273int32_t hwc2_set_layer_display_frame(
274 hwc2_device_t* device, hwc2_display_t display, hwc2_layer_t layer,
275 hwc_rect_t frame) {
276 GET_MESON_HWC();
277 return mesonhwc->setLayerDisplayFrame(display, layer, frame);
278}
279
280int32_t hwc2_set_layer_plane_alpha(
281 hwc2_device_t* device, hwc2_display_t display, hwc2_layer_t layer,
282 float alpha) {
283 GET_MESON_HWC();
284 return mesonhwc->setLayerPlaneAlpha(display, layer, alpha);
285}
286
287int32_t hwc2_set_layer_sideband_stream(
288 hwc2_device_t* device, hwc2_display_t display, hwc2_layer_t layer,
289 const native_handle_t* stream) {
290 GET_MESON_HWC();
291 return mesonhwc->setLayerSidebandStream(display, layer, stream);
292}
293
294int32_t hwc2_set_layer_source_crop(
295 hwc2_device_t* device, hwc2_display_t display, hwc2_layer_t layer,
296 hwc_frect_t crop) {
297 GET_MESON_HWC();
298 return mesonhwc->setLayerSourceCrop(display, layer, crop);
299}
300
301int32_t hwc2_set_layer_transform(
302 hwc2_device_t* device, hwc2_display_t display, hwc2_layer_t layer,
303 int32_t transform) {
304 GET_MESON_HWC();
305 return mesonhwc->setLayerTransform(display, layer, transform);
306}
307
308int32_t hwc2_set_layer_visible_region(
309 hwc2_device_t* device, hwc2_display_t display, hwc2_layer_t layer,
310 hwc_region_t visible) {
311 GET_MESON_HWC();
312 return mesonhwc->setLayerVisibleRegion(display, layer, visible);
313}
314
315int32_t hwc2_set_layer_z_order(
316 hwc2_device_t* device, hwc2_display_t display, hwc2_layer_t layer,
317 uint32_t z) {
318 GET_MESON_HWC();
319 return mesonhwc->setLayerZorder(display, layer, z);
320}
321
322#ifdef HWC_HDR_METADATA_SUPPORT
323int32_t setLayerPerFrameMetadata(
324 hwc2_device_t* device, hwc2_display_t display, hwc2_layer_t layer,
325 uint32_t numElements, const int32_t* /*hw2_per_frame_metadata_key_t*/ keys,
326 const float* metadata) {
327 GET_MESON_HWC();
328 return mesonhwc->setLayerPerFrameMetadata(display, layer, numElements, keys, metadata);
329}
330
331int32_t getPerFrameMetadataKeys(
332 hwc2_device_t* device, hwc2_display_t display, uint32_t* outNumKeys,
333 int32_t* /*hwc2_per_frame_metadata_key_t*/ outKeys) {
334 GET_MESON_HWC();
335 return mesonhwc->getPerFrameMetadataKeys(display, outNumKeys, outKeys);
336}
337#endif
338
339int32_t getRenderIntents(
340 hwc2_device_t* device, hwc2_display_t display, int32_t mode,
341 uint32_t* outNumIntents,
342 int32_t* /*android_render_intent_v1_1_t*/ outIntents) {
343 GET_MESON_HWC();
344 return mesonhwc->getRenderIntents(display, mode, outNumIntents, outIntents);
345}
346
347int32_t setColorModeWithRenderIntent (
348 hwc2_device_t* device, hwc2_display_t display,
349 int32_t /*android_color_mode_t*/ mode,
350 int32_t /*android_render_intent_v1_1_t */ intent) {
351 GET_MESON_HWC();
352 return mesonhwc->setColorModeWithRenderIntent(display, mode, intent);
353}
354
355int32_t getDisplayIdentificationData (
356 hwc2_device_t* device, hwc2_display_t display, uint8_t* outPort,
357 uint32_t* outDataSize, uint8_t* outData) {
358 GET_MESON_HWC();
359 return mesonhwc->getDisplayIdentificationData(display, outPort, outDataSize, outData);
360}
361
362int32_t getDisplayCapabilities (
363 hwc2_device_t* device, hwc2_display_t display, uint32_t* outNumCapabilities,
364 uint32_t* outCapabilities) {
365 GET_MESON_HWC();
366 return mesonhwc->getDisplayCapabilities(display, outNumCapabilities, outCapabilities);
367}
368
369int32_t getDisplayBrightnessSupport (hwc2_device_t* device,
370 hwc2_display_t display, bool* outSupport) {
371 GET_MESON_HWC();
372 return mesonhwc->getDisplayBrightnessSupport(display, outSupport);
373}
374
375int32_t setDisplayBrightness (hwc2_device_t* device,
376 hwc2_display_t display, float brightness) {
377 GET_MESON_HWC();
378 return mesonhwc->setDisplayBrightness(display, brightness);
379}
380
381
382
383hwc2_function_pointer_t hwc2_getFunction(struct hwc2_device* device __unused,
384 int32_t descriptor) {
385 switch (descriptor) {
386 case HWC2_FUNCTION_ACCEPT_DISPLAY_CHANGES:
387 return reinterpret_cast<hwc2_function_pointer_t>(hwc2_accept_display_changes);
388 case HWC2_FUNCTION_CREATE_LAYER:
389 return reinterpret_cast<hwc2_function_pointer_t>(hwc2_create_layer);
390 case HWC2_FUNCTION_CREATE_VIRTUAL_DISPLAY:
391 return reinterpret_cast<hwc2_function_pointer_t>(hwc2_create_virtual_display);
392 case HWC2_FUNCTION_DESTROY_LAYER:
393 return reinterpret_cast<hwc2_function_pointer_t>(hwc2_destroy_layer);
394 case HWC2_FUNCTION_DESTROY_VIRTUAL_DISPLAY:
395 return reinterpret_cast<hwc2_function_pointer_t>(hwc2_destroy_virtual_display);
396 case HWC2_FUNCTION_DUMP:
397 return reinterpret_cast<hwc2_function_pointer_t>(hwc2_dump);
398 case HWC2_FUNCTION_GET_ACTIVE_CONFIG:
399 return reinterpret_cast<hwc2_function_pointer_t>(hwc2_get_active_config);
400 case HWC2_FUNCTION_GET_CHANGED_COMPOSITION_TYPES:
401 return reinterpret_cast<hwc2_function_pointer_t>(hwc2_get_changed_composition_types);
402 case HWC2_FUNCTION_GET_CLIENT_TARGET_SUPPORT:
403 return reinterpret_cast<hwc2_function_pointer_t>(hwc2_get_client_target_support);
404 case HWC2_FUNCTION_GET_COLOR_MODES:
405 return reinterpret_cast<hwc2_function_pointer_t>(hwc2_get_color_modes);
406 case HWC2_FUNCTION_GET_DISPLAY_ATTRIBUTE:
407 return reinterpret_cast<hwc2_function_pointer_t>(hwc2_get_display_attribute);
408 case HWC2_FUNCTION_GET_DISPLAY_CONFIGS:
409 return reinterpret_cast<hwc2_function_pointer_t>(hwc2_get_display_configs);
410 case HWC2_FUNCTION_GET_DISPLAY_NAME:
411 return reinterpret_cast<hwc2_function_pointer_t>(hwc2_get_display_name);
412 case HWC2_FUNCTION_GET_DISPLAY_REQUESTS:
413 return reinterpret_cast<hwc2_function_pointer_t>(hwc2_get_display_requests);
414 case HWC2_FUNCTION_GET_DISPLAY_TYPE:
415 return reinterpret_cast<hwc2_function_pointer_t>(hwc2_get_display_type);
416 case HWC2_FUNCTION_GET_DOZE_SUPPORT:
417 return reinterpret_cast<hwc2_function_pointer_t>(hwc2_get_doze_support);
418 case HWC2_FUNCTION_GET_HDR_CAPABILITIES:
419 return reinterpret_cast<hwc2_function_pointer_t>(hwc2_get_hdr_capabilities);
420 case HWC2_FUNCTION_GET_MAX_VIRTUAL_DISPLAY_COUNT:
421 return reinterpret_cast<hwc2_function_pointer_t>(hwc2_get_max_virtual_display_count);
422 case HWC2_FUNCTION_GET_RELEASE_FENCES:
423 return reinterpret_cast<hwc2_function_pointer_t>(hwc2_get_release_fences);
424 case HWC2_FUNCTION_PRESENT_DISPLAY:
425 return reinterpret_cast<hwc2_function_pointer_t>(hwc2_present_display);
426 case HWC2_FUNCTION_REGISTER_CALLBACK:
427 return reinterpret_cast<hwc2_function_pointer_t>(hwc2_register_callback);
428 case HWC2_FUNCTION_SET_ACTIVE_CONFIG:
429 return reinterpret_cast<hwc2_function_pointer_t>(hwc2_set_active_config);
430 case HWC2_FUNCTION_SET_CLIENT_TARGET:
431 return reinterpret_cast<hwc2_function_pointer_t>(hwc2_set_client_target);
432 case HWC2_FUNCTION_SET_COLOR_MODE:
433 return reinterpret_cast<hwc2_function_pointer_t>(hwc2_set_color_mode);
434 case HWC2_FUNCTION_SET_COLOR_TRANSFORM:
435 return reinterpret_cast<hwc2_function_pointer_t>(hwc2_set_color_transform);
436 case HWC2_FUNCTION_SET_CURSOR_POSITION:
437 return reinterpret_cast<hwc2_function_pointer_t>(hwc2_set_cursor_position);
438 case HWC2_FUNCTION_SET_LAYER_BLEND_MODE:
439 return reinterpret_cast<hwc2_function_pointer_t>(hwc2_set_layer_blend_mode);
440 case HWC2_FUNCTION_SET_LAYER_BUFFER:
441 return reinterpret_cast<hwc2_function_pointer_t>(hwc2_set_layer_buffer);
442 case HWC2_FUNCTION_SET_LAYER_COLOR:
443 return reinterpret_cast<hwc2_function_pointer_t>(hwc2_set_layer_color);
444 case HWC2_FUNCTION_SET_LAYER_COMPOSITION_TYPE:
445 return reinterpret_cast<hwc2_function_pointer_t>(hwc2_set_layer_composition_type);
446 case HWC2_FUNCTION_SET_LAYER_DATASPACE:
447 return reinterpret_cast<hwc2_function_pointer_t>(hwc2_set_layer_dataspace);
448 case HWC2_FUNCTION_SET_LAYER_DISPLAY_FRAME:
449 return reinterpret_cast<hwc2_function_pointer_t>(hwc2_set_layer_display_frame);
450 case HWC2_FUNCTION_SET_LAYER_PLANE_ALPHA:
451 return reinterpret_cast<hwc2_function_pointer_t>(hwc2_set_layer_plane_alpha);
452 case HWC2_FUNCTION_SET_LAYER_SIDEBAND_STREAM:
453 return reinterpret_cast<hwc2_function_pointer_t>(hwc2_set_layer_sideband_stream);
454 case HWC2_FUNCTION_SET_LAYER_SOURCE_CROP:
455 return reinterpret_cast<hwc2_function_pointer_t>(hwc2_set_layer_source_crop);
456 case HWC2_FUNCTION_SET_LAYER_SURFACE_DAMAGE:
457 return reinterpret_cast<hwc2_function_pointer_t>(hwc2_set_layer_surface_damage);
458 case HWC2_FUNCTION_SET_LAYER_TRANSFORM:
459 return reinterpret_cast<hwc2_function_pointer_t>(hwc2_set_layer_transform);
460 case HWC2_FUNCTION_SET_LAYER_VISIBLE_REGION:
461 return reinterpret_cast<hwc2_function_pointer_t>(hwc2_set_layer_visible_region);
462 case HWC2_FUNCTION_SET_LAYER_Z_ORDER:
463 return reinterpret_cast<hwc2_function_pointer_t>(hwc2_set_layer_z_order);
464 case HWC2_FUNCTION_SET_OUTPUT_BUFFER:
465 return reinterpret_cast<hwc2_function_pointer_t>(hwc2_set_output_buffer);
466 case HWC2_FUNCTION_SET_POWER_MODE:
467 return reinterpret_cast<hwc2_function_pointer_t>(hwc2_set_power_mode);
468 case HWC2_FUNCTION_SET_VSYNC_ENABLED:
469 return reinterpret_cast<hwc2_function_pointer_t>(hwc2_set_vsync_enabled);
470 case HWC2_FUNCTION_VALIDATE_DISPLAY:
471 return reinterpret_cast<hwc2_function_pointer_t>(hwc2_validate_display);
472#ifdef HWC_HDR_METADATA_SUPPORT
473 case HWC2_FUNCTION_SET_LAYER_PER_FRAME_METADATA:
474 return reinterpret_cast<hwc2_function_pointer_t>(setLayerPerFrameMetadata);
475 case HWC2_FUNCTION_GET_PER_FRAME_METADATA_KEYS:
476 return reinterpret_cast<hwc2_function_pointer_t>(getPerFrameMetadataKeys);
477#endif
478 case HWC2_FUNCTION_GET_RENDER_INTENTS:
479 return reinterpret_cast<hwc2_function_pointer_t>(getRenderIntents);
480 case HWC2_FUNCTION_SET_COLOR_MODE_WITH_RENDER_INTENT:
481 return reinterpret_cast<hwc2_function_pointer_t>(setColorModeWithRenderIntent);
482 case HWC2_FUNCTION_GET_DISPLAY_IDENTIFICATION_DATA:
483 return reinterpret_cast<hwc2_function_pointer_t>(getDisplayIdentificationData);
484 case HWC2_FUNCTION_GET_DISPLAY_CAPABILITIES:
485 return reinterpret_cast<hwc2_function_pointer_t>(getDisplayCapabilities);
486 case HWC2_FUNCTION_GET_DISPLAY_BRIGHTNESS_SUPPORT:
487 return reinterpret_cast<hwc2_function_pointer_t>(getDisplayBrightnessSupport);
488 case HWC2_FUNCTION_SET_DISPLAY_BRIGHTNESS:
489 return reinterpret_cast<hwc2_function_pointer_t>(setDisplayBrightness);
490 default:
491 MESON_LOGE("Unkown function description (%d)", descriptor);
492 break;
493 };
494 return NULL;
495}
496
497void hwc2_getCapabilities(struct hwc2_device* device, uint32_t* outCount,
498 int32_t* outCapabilities) {
499 GET_MESON_HWC();
500 mesonhwc->getCapabilities(outCount, outCapabilities);
501}
502
503static int hwc2_device_close(struct hw_device_t *dev) {
504 MESON_LOGV("close hwc2 (%p)", dev);
505
506 hwc2_impl_t * hwc = reinterpret_cast<hwc2_impl_t *>(dev);
507 if (hwc->impl) {
508 delete hwc->impl;
509 }
510 free(hwc);
511
512 return 0;
513}
514
515static int hwc2_device_open(
516 const struct hw_module_t* module,
517 const char* name,
518 struct hw_device_t** device) {
519 if (!name) {
520 return -EINVAL;
521 }
522
523 MESON_LOGV("open hwc2 (%s)", name);
524
525 if (strcmp(name, HWC_HARDWARE_COMPOSER) != 0) {
526 MESON_LOGE("Not supported composer (%s)", name);
527 return -EINVAL;
528 }
529
530 /*init hwc device. */
531 hwc2_impl_t * hwc = (hwc2_impl_t*)calloc(1, sizeof(hwc2_impl_t));
532 hwc->impl = new MesonHwc2();
533
534 hwc->base.common.module = const_cast<hw_module_t*>(module);
535 hwc->base.common.version = HWC_DEVICE_API_VERSION_2_0;
536 hwc->base.common.close = hwc2_device_close;
537 hwc->base.getCapabilities = hwc2_getCapabilities;
538 hwc->base.getFunction = hwc2_getFunction;
539
540 *device = reinterpret_cast<hw_device_t*>(hwc);
541
542 return 0;
543}
544
545static struct hw_module_methods_t hwc2_module_methods = {
546 .open = hwc2_device_open
547};
548
549typedef struct hwc2_module {
550 struct hw_module_t common;
551 /* add extra info below.*/
552} hwc2_module_t;
553
554hwc_module_t HAL_MODULE_INFO_SYM = {
555 .common = {
556 .tag = HARDWARE_MODULE_TAG,
557 .version_major = 2,
558 .version_minor = 3,
559 .id = HWC_HARDWARE_MODULE_ID,
560 .name = "amlogic hwc module",
561 .author = "Amlogic Graphic",
562 .methods = &hwc2_module_methods,
563 .dso = NULL,
564 .reserved = {0},
565 }
566};
567
568
569