blob: 4cc050ce28c3702045d8fff9a4e41e14f353a119 [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>
18#include <hardware/overlay.h>
19
20#include <fcntl.h>
21#include <errno.h>
22
23#include <cutils/log.h>
24#include <cutils/atomic.h>
25
26#include <hardware/hwcomposer.h>
27
28#include <EGL/egl.h>
29
30/*****************************************************************************/
31
32struct hwc_context_t {
33 hwc_composer_device_t device;
34 /* 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 = {
41 open: hwc_device_open
42};
43
44hwc_module_t HAL_MODULE_INFO_SYM = {
45 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,
53 }
54};
55
56/*****************************************************************************/
57
58static int hwc_prepare(hwc_composer_device_t *dev, hwc_layer_list_t* list) {
59 if (list && (list->flags & HWC_GEOMETRY_CHANGED)) {
60 for (size_t i=0 ; i<list->numHwLayers ; i++) {
61 list->hwLayers[i].compositionType = HWC_FRAMEBUFFER;
62 }
63 }
64 return 0;
65}
66
67static int hwc_set(hwc_composer_device_t *dev,
68 hwc_display_t dpy,
69 hwc_surface_t sur,
70 hwc_layer_list_t* list)
71{
72 EGLBoolean sucess = eglSwapBuffers((EGLDisplay)dpy, (EGLSurface)sur);
73 if (!sucess) {
74 return HWC_EGL_ERROR;
75 }
76 return 0;
77}
78
79static int hwc_device_close(struct hw_device_t *dev)
80{
81 struct hwc_context_t* ctx = (struct hwc_context_t*)dev;
82 if (ctx) {
83 free(ctx);
84 }
85 return 0;
86}
87
88/*****************************************************************************/
89
90static int hwc_device_open(const struct hw_module_t* module, const char* name,
91 struct hw_device_t** device)
92{
93 int status = -EINVAL;
94 if (!strcmp(name, HWC_HARDWARE_COMPOSER)) {
95 struct hwc_context_t *dev;
96 dev = (hwc_context_t*)malloc(sizeof(*dev));
97
98 /* initialize our state here */
99 memset(dev, 0, sizeof(*dev));
100
101 /* initialize the procs */
102 dev->device.common.tag = HARDWARE_DEVICE_TAG;
103 dev->device.common.version = 0;
104 dev->device.common.module = const_cast<hw_module_t*>(module);
105 dev->device.common.close = hwc_device_close;
106
107 dev->device.prepare = hwc_prepare;
108 dev->device.set = hwc_set;
109
110 *device = &dev->device.common;
111 status = 0;
112 }
113 return status;
114}