summaryrefslogtreecommitdiff
path: root/hwc2/hwc2.cpp
blob: 036f4881ec0ac9b35c770cba4bf2a673409f6d09 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <cutils/log.h>

#include <inttypes.h>
#include <cstdlib>
#include <new>
#include <array>

#include "hwc2.h"

static int hwc2_device_open(const struct hw_module_t *module, const char *name,
    struct hw_device_t **device);

static int32_t hwc2_device_close(struct hw_device_t *device);

static struct hw_module_methods_t hwc2_module_methods = {
    .open = hwc2_device_open
};

hw_module_t HAL_MODULE_INFO_SYM = {
    .tag = HARDWARE_MODULE_TAG,
    .id = HWC_HARDWARE_MODULE_ID,
    .name = "NVIDIA Tegra hwcomposer module",
    .author = "AOSP",
    .methods = &hwc2_module_methods,
};


hwc2_error_t create_virtual_display(hwc2_device_t* /*device*/,
        uint32_t /*width*/, uint32_t /*height*/,
        android_pixel_format_t* /*format*/,
        hwc2_display_t* /*out_display*/)
{
    return HWC2_ERROR_NONE;
}

hwc2_error_t destroy_virtual_display(hwc2_device_t* /*device*/,
        hwc2_display_t /*display*/)
{
    return HWC2_ERROR_NONE;
}

void dump(hwc2_device_t* /*device*/, uint32_t* /*out_size*/,
        char* /*out_buffer*/)
{
    return;
}

uint32_t get_max_virtual_display_count(hwc2_device_t* /*device*/)
{
    return HWC2_ERROR_NONE;
}

hwc2_error_t register_callback(hwc2_device_t *device,
        hwc2_callback_descriptor_t descriptor,
        hwc2_callback_data_t callback_data, hwc2_function_pointer_t pointer)
{
    hwc2_dev *dev = reinterpret_cast<hwc2_context *>(device)->hwc2_dev;
    return dev->register_callback(descriptor, callback_data, pointer);
}

hwc2_error_t accept_display_changes(hwc2_device_t* /*device*/,
        hwc2_display_t /*display*/)
{
    return HWC2_ERROR_NONE;
}

hwc2_error_t create_layer(hwc2_device_t* /*device*/, hwc2_display_t /*display*/,
        hwc2_layer_t* /*out_layer*/)
{
    return HWC2_ERROR_NONE;
}

hwc2_error_t destroy_layer(hwc2_device_t* /*device*/,
        hwc2_display_t /*display*/, hwc2_layer_t /*layer*/)
{
    return HWC2_ERROR_NONE;
}

hwc2_error_t get_active_config(hwc2_device_t* /*device*/,
        hwc2_display_t /*display*/, hwc2_config_t* /*out_config*/)
{
    return HWC2_ERROR_NONE;
}

hwc2_error_t get_changed_composition_types(hwc2_device_t* /*device*/,
        hwc2_display_t /*display*/, uint32_t* /*out_num_elements*/,
        hwc2_layer_t* /*out_layers*/, hwc2_composition_t* /*out_types*/)
{
    return HWC2_ERROR_NONE;
}

hwc2_error_t get_client_target_support(hwc2_device_t* /*device*/,
        hwc2_display_t /*display*/, uint32_t /*width*/, uint32_t /*height*/,
        android_pixel_format_t /*format*/, android_dataspace_t /*dataspace*/)
{
    return HWC2_ERROR_NONE;
}

hwc2_error_t get_color_modes(hwc2_device_t* /*device*/,
        hwc2_display_t /*display*/, uint32_t* /*out_num_modes*/,
        android_color_mode_t* /*out_modes*/)
{
    return HWC2_ERROR_NONE;
}

hwc2_error_t get_display_attribute(hwc2_device_t* /*device*/,
        hwc2_display_t /*display*/, hwc2_config_t /*config*/,
        hwc2_attribute_t /*attribute*/, int32_t* /*out_value*/)
{
    return HWC2_ERROR_NONE;
}

hwc2_error_t get_display_configs(hwc2_device_t* /*device*/,
        hwc2_display_t /*display*/, uint32_t* /*out_num_configs*/,
        hwc2_config_t* /*out_configs*/)
{
    return HWC2_ERROR_NONE;
}

hwc2_error_t get_display_name(hwc2_device_t* /*device*/,
        hwc2_display_t /*display*/, uint32_t* /*out_size*/, char* /*out_name*/)
{
    return HWC2_ERROR_NONE;
}

hwc2_error_t get_display_requests(hwc2_device_t* /*device*/,
        hwc2_display_t /*display*/,
        hwc2_display_request_t* /*out_display_requests*/,
        uint32_t* /*out_num_elements*/, hwc2_layer_t* /*out_layers*/,
        hwc2_layer_request_t* /*out_layer_requests*/)
{
    return HWC2_ERROR_NONE;
}

hwc2_error_t get_display_type(hwc2_device_t *device, hwc2_display_t display,
        hwc2_display_type_t *out_type)
{
    hwc2_dev *dev = reinterpret_cast<hwc2_context *>(device)->hwc2_dev;
    return dev->get_display_type(display, out_type);
}

hwc2_error_t get_doze_support(hwc2_device_t* /*device*/,
        hwc2_display_t /*display*/, int32_t* /*out_support*/)
{
    return HWC2_ERROR_NONE;
}

hwc2_error_t get_hdr_capabilities(hwc2_device_t* /*device*/,
        hwc2_display_t /*display*/, uint32_t* /*out_num_types*/,
        android_hdr_t* /*out_types*/, float* /*out_max_luminance*/,
        float* /*out_max_average_luminance*/, float* /*out_min_luminance*/)
{
    return HWC2_ERROR_NONE;
}

hwc2_error_t get_release_fences(hwc2_device_t* /*device*/,
        hwc2_display_t /*display*/, uint32_t* /*out_num_elements*/,
        hwc2_layer_t* /*out_layers*/, int32_t* /*out_fences*/)
{
    return HWC2_ERROR_NONE;
}

hwc2_error_t present_display(hwc2_device_t* /*device*/,
        hwc2_display_t /*display*/, int32_t* /*out_present_fence*/)
{
    return HWC2_ERROR_NONE;
}

hwc2_error_t set_active_config(hwc2_device_t* /*device*/,
        hwc2_display_t /*display*/, hwc2_config_t /*config*/)
{
    return HWC2_ERROR_NONE;
}

hwc2_error_t set_client_target(hwc2_device_t* /*device*/,
        hwc2_display_t /*display*/, buffer_handle_t /*target*/,
        int32_t /*acquire_fence*/, android_dataspace_t /*dataspace*/,
        hwc_region_t /*damage*/)
{
    return HWC2_ERROR_NONE;
}

hwc2_error_t set_color_mode(hwc2_device_t* /*device*/,
        hwc2_display_t /*display*/, android_color_mode_t /*mode*/)
{
    return HWC2_ERROR_NONE;
}

hwc2_error_t set_color_transform(hwc2_device_t* /*device*/,
        hwc2_display_t /*display*/, const float* /*matrix*/,
        android_color_transform_t /*hint*/)
{
    return HWC2_ERROR_NONE;
}

hwc2_error_t set_output_buffer(hwc2_device_t* /*device*/,
        hwc2_display_t /*display*/, buffer_handle_t /*buffer*/,
        int32_t /*release_fence*/)
{
    return HWC2_ERROR_NONE;
}

hwc2_error_t set_power_mode(hwc2_device_t* /*device*/,
        hwc2_display_t /*display*/, hwc2_power_mode_t /*mode*/)
{
    return HWC2_ERROR_NONE;
}

hwc2_error_t set_vsync_enabled(hwc2_device_t* /*device*/,
        hwc2_display_t /*display*/, hwc2_vsync_t /*enabled*/)
{
    return HWC2_ERROR_NONE;
}

hwc2_error_t validate_display(hwc2_device_t* /*device*/,
        hwc2_display_t /*display*/, uint32_t* /*out_num_types*/,
        uint32_t* /*out_num_requests*/)
{
    return HWC2_ERROR_NONE;
}

hwc2_error_t set_cursor_position(hwc2_device_t* /*device*/,
        hwc2_display_t /*display*/, hwc2_layer_t /*layer*/, int32_t /*x*/,
        int32_t /*y*/)
{
    return HWC2_ERROR_NONE;
}

hwc2_error_t set_layer_buffer(hwc2_device_t* /*device*/,
        hwc2_display_t /*display*/, hwc2_layer_t /*layer*/,
        buffer_handle_t /*buffer*/, int32_t /*acquire_fence*/)
{
    return HWC2_ERROR_NONE;
}

hwc2_error_t set_layer_surface_damage(hwc2_device_t* /*device*/,
        hwc2_display_t /*display*/, hwc2_layer_t /*layer*/,
        hwc_region_t /*damage*/)
{
    return HWC2_ERROR_NONE;
}

hwc2_error_t set_layer_blend_mode(hwc2_device_t* /*device*/,
        hwc2_display_t /*display*/, hwc2_layer_t /*layer*/,
        hwc2_blend_mode_t /*mode*/)
{
    return HWC2_ERROR_NONE;
}

hwc2_error_t set_layer_color(hwc2_device_t* /*device*/,
        hwc2_display_t /*display*/, hwc2_layer_t /*layer*/,
        hwc_color_t /*color*/)
{
    return HWC2_ERROR_NONE;
}

hwc2_error_t set_layer_composition_type(hwc2_device_t* /*device*/,
        hwc2_display_t /*display*/, hwc2_layer_t /*layer*/,
        hwc2_composition_t /*type*/)
{
    return HWC2_ERROR_NONE;
}

hwc2_error_t set_layer_dataspace(hwc2_device_t* /*device*/,
        hwc2_display_t /*display*/, hwc2_layer_t /*layer*/,
        android_dataspace_t /*dataspace*/)
{
    return HWC2_ERROR_NONE;
}

hwc2_error_t set_layer_display_frame(hwc2_device_t* /*device*/,
        hwc2_display_t /*display*/, hwc2_layer_t /*layer*/,
        hwc_rect_t /*frame*/)
{
    return HWC2_ERROR_NONE;
}

hwc2_error_t set_layer_plane_alpha(hwc2_device_t* /*device*/,
        hwc2_display_t /*display*/, hwc2_layer_t /*layer*/, float /*alpha*/)
{
    return HWC2_ERROR_NONE;
}

hwc2_error_t set_layer_source_crop(hwc2_device_t* /*device*/,
        hwc2_display_t /*display*/, hwc2_layer_t /*layer*/,
        hwc_frect_t /*crop*/)
{
    return HWC2_ERROR_NONE;
}

hwc2_error_t set_layer_transform(hwc2_device_t* /*device*/,
        hwc2_display_t /*display*/, hwc2_layer_t /*layer*/,
        hwc_transform_t /*transform*/)
{
    return HWC2_ERROR_NONE;
}

hwc2_error_t set_layer_visible_region(hwc2_device_t* /*device*/,
        hwc2_display_t /*display*/, hwc2_layer_t /*layer*/,
        hwc_region_t /*visible*/)
{
    return HWC2_ERROR_NONE;
}

hwc2_error_t set_layer_z_order(hwc2_device_t* /*device*/,
        hwc2_display_t /*display*/, hwc2_layer_t /*layer*/, uint32_t /*z*/)
{
    return HWC2_ERROR_NONE;
}

/* Indexed using the hwc2_function_descriptor_t enum to find the corresponding
 * function */
static const std::array<hwc2_function_pointer_t, 44> hwc2_func_ptrs = {{
    /* Index 0 corresponds to HWC2_FUNCTION_INVALID */
    (hwc2_function_pointer_t) nullptr,
    (hwc2_function_pointer_t) accept_display_changes,
    (hwc2_function_pointer_t) create_layer,
    (hwc2_function_pointer_t) create_virtual_display,
    (hwc2_function_pointer_t) destroy_layer,
    (hwc2_function_pointer_t) destroy_virtual_display,
    (hwc2_function_pointer_t) dump,
    (hwc2_function_pointer_t) get_active_config,
    (hwc2_function_pointer_t) get_changed_composition_types,
    (hwc2_function_pointer_t) get_client_target_support,
    (hwc2_function_pointer_t) get_color_modes,
    (hwc2_function_pointer_t) get_display_attribute,
    (hwc2_function_pointer_t) get_display_configs,
    (hwc2_function_pointer_t) get_display_name,
    (hwc2_function_pointer_t) get_display_requests,
    (hwc2_function_pointer_t) get_display_type,
    (hwc2_function_pointer_t) get_doze_support,
    (hwc2_function_pointer_t) get_hdr_capabilities,
    (hwc2_function_pointer_t) get_max_virtual_display_count,
    (hwc2_function_pointer_t) get_release_fences,
    (hwc2_function_pointer_t) present_display,
    (hwc2_function_pointer_t) register_callback,
    (hwc2_function_pointer_t) set_active_config,
    (hwc2_function_pointer_t) set_client_target,
    (hwc2_function_pointer_t) set_color_mode,
    (hwc2_function_pointer_t) set_color_transform,
    (hwc2_function_pointer_t) set_cursor_position,
    (hwc2_function_pointer_t) set_layer_blend_mode,
    (hwc2_function_pointer_t) set_layer_buffer,
    (hwc2_function_pointer_t) set_layer_color,
    (hwc2_function_pointer_t) set_layer_composition_type,
    (hwc2_function_pointer_t) set_layer_dataspace,
    (hwc2_function_pointer_t) set_layer_display_frame,
    (hwc2_function_pointer_t) set_layer_plane_alpha,
    (hwc2_function_pointer_t) nullptr, /*set_layer_sideband_stream unsupported*/
    (hwc2_function_pointer_t) set_layer_source_crop,
    (hwc2_function_pointer_t) set_layer_surface_damage,
    (hwc2_function_pointer_t) set_layer_transform,
    (hwc2_function_pointer_t) set_layer_visible_region,
    (hwc2_function_pointer_t) set_layer_z_order,
    (hwc2_function_pointer_t) set_output_buffer,
    (hwc2_function_pointer_t) set_power_mode,
    (hwc2_function_pointer_t) set_vsync_enabled,
    (hwc2_function_pointer_t) validate_display,
}};

hwc2_function_pointer_t get_function(struct hwc2_device* /*device*/,
        /*hwc2_function_descriptor_t*/ int32_t descriptor)
{
    if (descriptor == HWC2_FUNCTION_INVALID ||
            static_cast<size_t>(descriptor) >= hwc2_func_ptrs.size()) {
        ALOGW("invalid descriptor");
        return nullptr;
    }
    return hwc2_func_ptrs[descriptor];
}

void get_capabilities(struct hwc2_device* /*device*/, uint32_t *out_count,
        /*hwc2_capability_t*/ int32_t* /*outCapabilities*/)
{
    *out_count = 0;
}

static int32_t hwc2_device_close(struct hw_device_t *device)
{
    hwc2_context *ctx = reinterpret_cast<hwc2_context *>(device);
    delete ctx->hwc2_dev;
    delete ctx;
    return 0;
}

static int hwc2_device_open(const struct hw_module_t *module, const char *name,
        struct hw_device_t **hw_device)
{
    if (strcmp(name, HWC_HARDWARE_COMPOSER))
        return -EINVAL;

    hwc2_context *ctx = new hwc2_context();
    if (!ctx) {
        ALOGE("failed to allocate hwc2_context");
        return -ENOMEM;
    }

    ctx->hwc2_device.common.tag = HARDWARE_DEVICE_TAG;
    ctx->hwc2_device.common.version = HWC_DEVICE_API_VERSION_2_0;
    ctx->hwc2_device.common.module = const_cast<hw_module_t *>(module);
    ctx->hwc2_device.common.close = hwc2_device_close;
    ctx->hwc2_device.getFunction = get_function;
    ctx->hwc2_device.getCapabilities = get_capabilities;

    ctx->hwc2_dev = new hwc2_dev();
    if (!ctx->hwc2_dev) {
        ALOGE("failed to allocate hwc2_dev");
        delete ctx;
        return -ENOMEM;
    }

    int ret = ctx->hwc2_dev->open_adf_device();
    if (ret < 0) {
        ALOGE("failed to open adf device: %s", strerror(ret));
        delete ctx->hwc2_dev;
        delete ctx;
        return ret;
    }

    *hw_device = &ctx->hwc2_device.common;

    return 0;
}