blob: cc0d873a4a44c48a45710521eba0c84ce33da4a8 [file] [log] [blame]
Mathias Agopian5d3de302010-08-05 15:24:35 -07001/*
2 * Copyright (C) 2010 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
Mathias Agopian5d3de302010-08-05 15:24:35 -070017#include <errno.h>
Elliott Hughes84b9ff82015-01-28 19:54:13 -080018#include <fcntl.h>
19#include <malloc.h>
Jiyong Park32dde032017-09-06 12:16:25 +090020#include <string.h>
Mathias Agopian5d3de302010-08-05 15:24:35 -070021
Mathias Agopian5d3de302010-08-05 15:24:35 -070022#include <cutils/atomic.h>
Mark Salyzynd88dfe82017-04-11 08:56:09 -070023#include <log/log.h>
Mathias Agopian5d3de302010-08-05 15:24:35 -070024
Mark Salyzynd88dfe82017-04-11 08:56:09 -070025#include <hardware/hardware.h>
Mathias Agopian5d3de302010-08-05 15:24:35 -070026#include <hardware/hwcomposer.h>
27
28#include <EGL/egl.h>
29
30/*****************************************************************************/
31
32struct hwc_context_t {
Jesse Halld479ad22012-06-05 23:41:37 -070033 hwc_composer_device_1_t device;
Mathias Agopian5d3de302010-08-05 15:24:35 -070034 /* our private state goes below here */
35};
36
37static int hwc_device_open(const struct hw_module_t* module, const char* name,
38 struct hw_device_t** device);
39
40static struct hw_module_methods_t hwc_module_methods = {
Greg Kaiser8f35d922016-06-30 16:43:40 -070041 .open = hwc_device_open
Mathias Agopian5d3de302010-08-05 15:24:35 -070042};
43
44hwc_module_t HAL_MODULE_INFO_SYM = {
Greg Kaiser8f35d922016-06-30 16:43:40 -070045 .common = {
46 .tag = HARDWARE_MODULE_TAG,
47 .version_major = 1,
48 .version_minor = 0,
49 .id = HWC_HARDWARE_MODULE_ID,
50 .name = "Sample hwcomposer module",
51 .author = "The Android Open Source Project",
52 .methods = &hwc_module_methods,
Mathias Agopian5d3de302010-08-05 15:24:35 -070053 }
54};
55
56/*****************************************************************************/
57
Chih-Hung Hsieh1f601b12017-11-14 16:05:46 -080058#if 0
Jesse Halld479ad22012-06-05 23:41:37 -070059static void dump_layer(hwc_layer_1_t const* l) {
Steve Blockcee85012011-12-20 16:25:12 +000060 ALOGD("\ttype=%d, flags=%08x, handle=%p, tr=%02x, blend=%04x, {%d,%d,%d,%d}, {%d,%d,%d,%d}",
Mathias Agopiane6b5c052010-08-11 16:15:42 -070061 l->compositionType, l->flags, l->handle, l->transform, l->blending,
62 l->sourceCrop.left,
63 l->sourceCrop.top,
64 l->sourceCrop.right,
65 l->sourceCrop.bottom,
66 l->displayFrame.left,
67 l->displayFrame.top,
68 l->displayFrame.right,
69 l->displayFrame.bottom);
70}
Chih-Hung Hsieh1f601b12017-11-14 16:05:46 -080071#endif
Mathias Agopiane6b5c052010-08-11 16:15:42 -070072
Greg Kaiser8f35d922016-06-30 16:43:40 -070073static int hwc_prepare(hwc_composer_device_1_t * /*dev*/,
74 size_t /*numDisplays*/, hwc_display_contents_1_t** displays) {
Jesse Hallf9d6cd72012-07-31 14:29:00 -070075 if (displays && (displays[0]->flags & HWC_GEOMETRY_CHANGED)) {
76 for (size_t i=0 ; i<displays[0]->numHwLayers ; i++) {
Mathias Agopiane6b5c052010-08-11 16:15:42 -070077 //dump_layer(&list->hwLayers[i]);
Jesse Hallf9d6cd72012-07-31 14:29:00 -070078 displays[0]->hwLayers[i].compositionType = HWC_FRAMEBUFFER;
Mathias Agopian5d3de302010-08-05 15:24:35 -070079 }
80 }
81 return 0;
82}
83
Greg Kaiser8f35d922016-06-30 16:43:40 -070084static int hwc_set(hwc_composer_device_1_t * /*dev*/,
85 size_t /*numDisplays*/, hwc_display_contents_1_t** displays)
Mathias Agopian5d3de302010-08-05 15:24:35 -070086{
Mathias Agopiane6b5c052010-08-11 16:15:42 -070087 //for (size_t i=0 ; i<list->numHwLayers ; i++) {
88 // dump_layer(&list->hwLayers[i]);
89 //}
90
Greg Kaiser8f35d922016-06-30 16:43:40 -070091 EGLBoolean success = eglSwapBuffers((EGLDisplay)displays[0]->dpy,
Jesse Hallf9d6cd72012-07-31 14:29:00 -070092 (EGLSurface)displays[0]->sur);
Greg Kaiser8f35d922016-06-30 16:43:40 -070093 if (!success) {
Mathias Agopian5d3de302010-08-05 15:24:35 -070094 return HWC_EGL_ERROR;
95 }
96 return 0;
97}
98
99static int hwc_device_close(struct hw_device_t *dev)
100{
101 struct hwc_context_t* ctx = (struct hwc_context_t*)dev;
102 if (ctx) {
103 free(ctx);
104 }
105 return 0;
106}
107
108/*****************************************************************************/
109
110static int hwc_device_open(const struct hw_module_t* module, const char* name,
111 struct hw_device_t** device)
112{
113 int status = -EINVAL;
114 if (!strcmp(name, HWC_HARDWARE_COMPOSER)) {
115 struct hwc_context_t *dev;
116 dev = (hwc_context_t*)malloc(sizeof(*dev));
117
118 /* initialize our state here */
119 memset(dev, 0, sizeof(*dev));
120
121 /* initialize the procs */
122 dev->device.common.tag = HARDWARE_DEVICE_TAG;
Jesse Halld479ad22012-06-05 23:41:37 -0700123 dev->device.common.version = HWC_DEVICE_API_VERSION_1_0;
Mathias Agopian5d3de302010-08-05 15:24:35 -0700124 dev->device.common.module = const_cast<hw_module_t*>(module);
125 dev->device.common.close = hwc_device_close;
126
127 dev->device.prepare = hwc_prepare;
128 dev->device.set = hwc_set;
129
130 *device = &dev->device.common;
131 status = 0;
132 }
133 return status;
134}