2 * Copyright (C) 2012 Intel Corporation. All rights reserved.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include <hardware/hardware.h>
18 #include <hardware/hwcomposer.h>
19 #include <hardware/gralloc.h>
21 #include <gralloc_drm.h>
22 #include <gralloc_drm_priv.h>
23 #include <gralloc_drm_handle.h>
28 #include <cutils/log.h>
29 #include <cutils/atomic.h>
31 #include <hardware/hwcomposer.h>
35 struct hwc_context_t {
36 hwc_composer_device_t device;
37 struct drm_module_t *gralloc_module;
40 static int hwc_device_open(const struct hw_module_t* module, const char* name,
41 struct hw_device_t** device);
43 static struct hw_module_methods_t hwc_module_methods = {
47 hwc_module_t HAL_MODULE_INFO_SYM = {
49 tag: HARDWARE_MODULE_TAG,
52 id: HWC_HARDWARE_MODULE_ID,
53 name: "Intel hwcomposer module",
55 methods: &hwc_module_methods,
60 static int hwc_prepare(hwc_composer_device_t *dev, hwc_layer_list_t* list)
62 struct hwc_context_t* ctx = (struct hwc_context_t *) &dev->common;
64 // SurfaceFlinger wants to handle the complete composition
65 if (!list || list->numHwLayers == 0)
68 int topmost = list->numHwLayers;
69 if (list->numHwLayers > 0)
72 if (list->flags & HWC_GEOMETRY_CHANGED) {
73 for (int i=topmost; i>=0; i--) {
74 list->hwLayers[i].compositionType = HWC_FRAMEBUFFER;
81 static int hwc_set(hwc_composer_device_t *dev,
84 hwc_layer_list_t* list)
86 struct hwc_context_t* ctx = (struct hwc_context_t*)dev;
89 // display is turning off
90 if (!dpy && !sur && !list)
93 success = eglSwapBuffers((EGLDisplay)dpy, (EGLSurface)sur);
101 static int hwc_device_close(struct hw_device_t *dev)
103 struct hwc_context_t* ctx = (struct hwc_context_t*)dev;
111 /*****************************************************************************/
113 static int hwc_device_open(const struct hw_module_t* module, const char* name,
114 struct hw_device_t** device)
116 int status = -EINVAL;
117 if (strcmp(name, HWC_HARDWARE_COMPOSER))
120 struct hwc_context_t *dev;
121 dev = (hwc_context_t*)calloc(1, sizeof(*dev));
123 /* initialize the procs */
124 dev->device.common.tag = HARDWARE_DEVICE_TAG;
125 dev->device.common.version = 0;
126 dev->device.common.module = const_cast<hw_module_t*>(module);
127 dev->device.common.close = hwc_device_close;
129 dev->device.prepare = hwc_prepare;
130 dev->device.set = hwc_set;
132 *device = &dev->device.common;
134 int err = hw_get_module(GRALLOC_HARDWARE_MODULE_ID,
135 (const hw_module_t **)&dev->gralloc_module);
137 ALOGD("Intel hwcomposer module");