blob: a5e31ef0768116a212a7f01c2c49a70f6e345ae9 [file] [log] [blame]
Naseer Ahmed29a26812012-06-14 00:56:20 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 * Copyright (C) 2012, Code Aurora Forum. All rights reserved.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#include <fcntl.h>
19#include <errno.h>
20
21#include <cutils/log.h>
22#include <cutils/atomic.h>
23#include <EGL/egl.h>
24
25#include "hwc_utils.h"
26
27using namespace qhwc;
28
29static int hwc_device_open(const struct hw_module_t* module,
30 const char* name,
31 struct hw_device_t** device);
32
33static struct hw_module_methods_t hwc_module_methods = {
34 open: hwc_device_open
35};
36
37hwc_module_t HAL_MODULE_INFO_SYM = {
38 common: {
39 tag: HARDWARE_MODULE_TAG,
40 version_major: 2,
41 version_minor: 0,
42 id: HWC_HARDWARE_MODULE_ID,
43 name: "Qualcomm Hardware Composer Module",
44 author: "CodeAurora Forum",
45 methods: &hwc_module_methods,
46 dso: 0,
47 reserved: {0},
48 }
49};
50
51/*
52 * Save callback functions registered to HWC
53 */
54static void hwc_registerProcs(struct hwc_composer_device* dev,
55 hwc_procs_t const* procs)
56{
57 hwc_context_t* ctx = (hwc_context_t*)(dev);
58 if(!ctx) {
59 ALOGE("%s: Invalid context", __FUNCTION__);
60 return;
61 }
62 ctx->device.reserved_proc[0] = (void*)procs;
63}
64
65static int hwc_prepare(hwc_composer_device_t *dev, hwc_layer_list_t* list)
66{
67 hwc_context_t* ctx = (hwc_context_t*)(dev);
68 if (LIKELY(list)) {
69 getLayerStats(ctx, list);
70 cleanOverlays(ctx);
71 for (int i=list->numHwLayers-1; i >= 0 ; i--) {
72 private_handle_t *hnd =
73 (private_handle_t *)list->hwLayers[i].handle;
74 if (isSkipLayer(&list->hwLayers[i])) {
75 break;
76 } else if(isYuvBuffer(hnd)) {
77 handleYUV(ctx,&list->hwLayers[i]);
78 } else {
79 list->hwLayers[i].compositionType = HWC_FRAMEBUFFER;
80 }
81 }
82 }
83 return 0;
84}
85
86static int hwc_set(hwc_composer_device_t *dev,
87 hwc_display_t dpy,
88 hwc_surface_t sur,
89 hwc_layer_list_t* list)
90{
91 int ret = 0;
92 hwc_context_t* ctx = (hwc_context_t*)(dev);
93 if (LIKELY(list)) {
94 for (size_t i=0; i<list->numHwLayers; i++) {
95 if (list->hwLayers[i].flags & HWC_SKIP_LAYER) {
96 continue;
Naseer Ahmeda87da602012-07-01 23:54:19 -070097 } else if (list->hwLayers[i].compositionType == HWC_OVERLAY) {
Naseer Ahmed29a26812012-06-14 00:56:20 -070098 drawLayerUsingOverlay(ctx, &(list->hwLayers[i]));
99 }
100 }
101 //XXX: Handle vsync with FBIO_WAITFORVSYNC ioctl
102 //All other operations (including pan display) should be NOWAIT
103 EGLBoolean sucess = eglSwapBuffers((EGLDisplay)dpy, (EGLSurface)sur);
104 } else {
105 //XXX: put in a wrapper for non overlay targets
106 setOverlayState(ctx, ovutils::OV_CLOSED);
107 }
108 ctx->qbuf->unlockAllPrevious();
109 return ret;
110}
111
112static int hwc_device_close(struct hw_device_t *dev)
113{
114 if(!dev) {
115 ALOGE("hwc_device_close null device pointer");
116 return -1;
117 }
118 closeContext((hwc_context_t*)dev);
119 free(dev);
120
121 return 0;
122}
123
124static int hwc_device_open(const struct hw_module_t* module, const char* name,
125 struct hw_device_t** device)
126{
127 int status = -EINVAL;
128
129 if (!strcmp(name, HWC_HARDWARE_COMPOSER)) {
130 struct hwc_context_t *dev;
131 dev = (hwc_context_t*)malloc(sizeof(*dev));
132 memset(dev, 0, sizeof(*dev));
133 initContext(dev);
134 dev->device.common.tag = HARDWARE_DEVICE_TAG;
135 dev->device.common.version = 0;
136 dev->device.common.module = const_cast<hw_module_t*>(module);
137 dev->device.common.close = hwc_device_close;
138 dev->device.prepare = hwc_prepare;
139 dev->device.set = hwc_set;
140 dev->device.registerProcs = hwc_registerProcs;
141 *device = &dev->device.common;
142 status = 0;
143 }
144 return status;
145}