blob: 0e04cac4b5ec81c394ebff5e5259831465e5c400 [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
17#include <hardware/hardware.h>
Mathias Agopian5d3de302010-08-05 15:24:35 -070018
19#include <fcntl.h>
20#include <errno.h>
21
22#include <cutils/log.h>
23#include <cutils/atomic.h>
24
25#include <hardware/hwcomposer.h>
26
27#include <EGL/egl.h>
28
29/*****************************************************************************/
30
31struct hwc_context_t {
32 hwc_composer_device_t device;
33 /* our private state goes below here */
34};
35
36static int hwc_device_open(const struct hw_module_t* module, const char* name,
37 struct hw_device_t** device);
38
39static struct hw_module_methods_t hwc_module_methods = {
40 open: hwc_device_open
41};
42
43hwc_module_t HAL_MODULE_INFO_SYM = {
44 common: {
45 tag: HARDWARE_MODULE_TAG,
46 version_major: 1,
47 version_minor: 0,
48 id: HWC_HARDWARE_MODULE_ID,
49 name: "Sample hwcomposer module",
50 author: "The Android Open Source Project",
51 methods: &hwc_module_methods,
52 }
53};
54
55/*****************************************************************************/
56
Mathias Agopiane6b5c052010-08-11 16:15:42 -070057static void dump_layer(hwc_layer_t const* l) {
Steve Blockcee85012011-12-20 16:25:12 +000058 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 -070059 l->compositionType, l->flags, l->handle, l->transform, l->blending,
60 l->sourceCrop.left,
61 l->sourceCrop.top,
62 l->sourceCrop.right,
63 l->sourceCrop.bottom,
64 l->displayFrame.left,
65 l->displayFrame.top,
66 l->displayFrame.right,
67 l->displayFrame.bottom);
68}
69
Mathias Agopian5d3de302010-08-05 15:24:35 -070070static int hwc_prepare(hwc_composer_device_t *dev, hwc_layer_list_t* list) {
71 if (list && (list->flags & HWC_GEOMETRY_CHANGED)) {
72 for (size_t i=0 ; i<list->numHwLayers ; i++) {
Mathias Agopiane6b5c052010-08-11 16:15:42 -070073 //dump_layer(&list->hwLayers[i]);
Mathias Agopian5d3de302010-08-05 15:24:35 -070074 list->hwLayers[i].compositionType = HWC_FRAMEBUFFER;
75 }
76 }
77 return 0;
78}
79
80static int hwc_set(hwc_composer_device_t *dev,
81 hwc_display_t dpy,
82 hwc_surface_t sur,
83 hwc_layer_list_t* list)
84{
Mathias Agopiane6b5c052010-08-11 16:15:42 -070085 //for (size_t i=0 ; i<list->numHwLayers ; i++) {
86 // dump_layer(&list->hwLayers[i]);
87 //}
88
Mathias Agopian5d3de302010-08-05 15:24:35 -070089 EGLBoolean sucess = eglSwapBuffers((EGLDisplay)dpy, (EGLSurface)sur);
90 if (!sucess) {
91 return HWC_EGL_ERROR;
92 }
93 return 0;
94}
95
96static int hwc_device_close(struct hw_device_t *dev)
97{
98 struct hwc_context_t* ctx = (struct hwc_context_t*)dev;
99 if (ctx) {
100 free(ctx);
101 }
102 return 0;
103}
104
105/*****************************************************************************/
106
107static int hwc_device_open(const struct hw_module_t* module, const char* name,
108 struct hw_device_t** device)
109{
110 int status = -EINVAL;
111 if (!strcmp(name, HWC_HARDWARE_COMPOSER)) {
112 struct hwc_context_t *dev;
113 dev = (hwc_context_t*)malloc(sizeof(*dev));
114
115 /* initialize our state here */
116 memset(dev, 0, sizeof(*dev));
117
118 /* initialize the procs */
119 dev->device.common.tag = HARDWARE_DEVICE_TAG;
120 dev->device.common.version = 0;
121 dev->device.common.module = const_cast<hw_module_t*>(module);
122 dev->device.common.close = hwc_device_close;
123
124 dev->device.prepare = hwc_prepare;
125 dev->device.set = hwc_set;
126
127 *device = &dev->device.common;
128 status = 0;
129 }
130 return status;
131}