blob: c28cf0375613762cb80f2a27f568ab854a12342e [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>
Naseer Ahmed72cf9762012-07-21 12:17:13 -070023#include <EGL/egl.h>
Naseer Ahmed29a26812012-06-14 00:56:20 -070024
Naseer Ahmed72cf9762012-07-21 12:17:13 -070025#include <overlay.h>
26#include <fb_priv.h>
Naseer Ahmed29a26812012-06-14 00:56:20 -070027#include "hwc_utils.h"
Naseer Ahmed72cf9762012-07-21 12:17:13 -070028#include "hwc_qbuf.h"
Naseer Ahmedf48aef62012-07-20 09:05:53 -070029#include "hwc_video.h"
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070030#include "hwc_uimirror.h"
Naseer Ahmed31da0b12012-07-31 18:55:33 -070031#include "hwc_copybit.h"
Naseer Ahmedf8ec1622012-07-31 18:56:23 -070032#include "hwc_external.h"
Naseer Ahmed7c958d42012-07-31 18:57:03 -070033#include "hwc_mdpcomp.h"
Naseer Ahmed29a26812012-06-14 00:56:20 -070034
35using namespace qhwc;
36
37static int hwc_device_open(const struct hw_module_t* module,
38 const char* name,
39 struct hw_device_t** device);
40
41static struct hw_module_methods_t hwc_module_methods = {
42 open: hwc_device_open
43};
44
45hwc_module_t HAL_MODULE_INFO_SYM = {
46 common: {
47 tag: HARDWARE_MODULE_TAG,
48 version_major: 2,
49 version_minor: 0,
50 id: HWC_HARDWARE_MODULE_ID,
51 name: "Qualcomm Hardware Composer Module",
52 author: "CodeAurora Forum",
53 methods: &hwc_module_methods,
54 dso: 0,
55 reserved: {0},
56 }
57};
58
59/*
60 * Save callback functions registered to HWC
61 */
62static void hwc_registerProcs(struct hwc_composer_device* dev,
63 hwc_procs_t const* procs)
64{
65 hwc_context_t* ctx = (hwc_context_t*)(dev);
66 if(!ctx) {
67 ALOGE("%s: Invalid context", __FUNCTION__);
68 return;
69 }
70 ctx->device.reserved_proc[0] = (void*)procs;
71}
72
73static int hwc_prepare(hwc_composer_device_t *dev, hwc_layer_list_t* list)
74{
75 hwc_context_t* ctx = (hwc_context_t*)(dev);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070076 ctx->overlayInUse = false;
77
78 //Prepare is called after a vsync, so unlock previous buffers here.
79 ctx->qbuf->unlockAllPrevious();
Ajay Dudanie217fbf2012-07-25 17:46:07 -070080 return 0;
Naseer Ahmedf48aef62012-07-20 09:05:53 -070081
Naseer Ahmed29a26812012-06-14 00:56:20 -070082 if (LIKELY(list)) {
83 getLayerStats(ctx, list);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070084 if(VideoOverlay::prepare(ctx, list)) {
85 ctx->overlayInUse = true;
86 //Nothing here
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070087 } else if(UIMirrorOverlay::prepare(ctx, list)) {
88 ctx->overlayInUse = true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070089 } else if(MDPComp::configure(dev, list)) {
90 ctx->overlayInUse = true;
Naseer Ahmedf48aef62012-07-20 09:05:53 -070091 } else if (0) {
92 //Other features
93 ctx->overlayInUse = true;
Naseer Ahmed31da0b12012-07-31 18:55:33 -070094 } else { // Else set this flag to false, otherwise video cases
95 // fail in non-overlay targets.
96 ctx->overlayInUse = false;
Naseer Ahmed29a26812012-06-14 00:56:20 -070097 }
Naseer Ahmed31da0b12012-07-31 18:55:33 -070098 CopyBit::prepare(ctx, list);
Naseer Ahmed29a26812012-06-14 00:56:20 -070099 }
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700100
Naseer Ahmed29a26812012-06-14 00:56:20 -0700101 return 0;
102}
103
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700104static int hwc_eventControl(struct hwc_composer_device* dev,
105 int event, int enabled)
106{
107 int ret = 0;
108 hwc_context_t* ctx = (hwc_context_t*)(dev);
109 private_module_t* m = reinterpret_cast<private_module_t*>(
110 ctx->mFbDev->common.module);
111 switch(event) {
112 case HWC_EVENT_VSYNC:
113 if(ioctl(m->framebuffer->fd, MSMFB_OVERLAY_VSYNC_CTRL, &enabled) < 0)
114 ret = -errno;
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700115
116 if(ctx->mExtDisplay->getExternalDisplay()) {
117 ret = ctx->mExtDisplay->enableHDMIVsync(enabled);
118 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700119 break;
120 default:
121 ret = -EINVAL;
122 }
123 return ret;
124}
125
126static int hwc_query(struct hwc_composer_device* dev,
127 int param, int* value)
128{
129 hwc_context_t* ctx = (hwc_context_t*)(dev);
130 private_module_t* m = reinterpret_cast<private_module_t*>(
131 ctx->mFbDev->common.module);
132
133 switch (param) {
134 case HWC_BACKGROUND_LAYER_SUPPORTED:
135 // Not supported for now
136 value[0] = 0;
137 break;
138 case HWC_VSYNC_PERIOD:
139 value[0] = 1000000000.0 / m->fps;
140 ALOGI("fps: %d", value[0]);
141 break;
142 default:
143 return -EINVAL;
144 }
145 return 0;
146
147}
148
Naseer Ahmed29a26812012-06-14 00:56:20 -0700149static int hwc_set(hwc_composer_device_t *dev,
150 hwc_display_t dpy,
151 hwc_surface_t sur,
152 hwc_layer_list_t* list)
153{
154 int ret = 0;
155 hwc_context_t* ctx = (hwc_context_t*)(dev);
156 if (LIKELY(list)) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700157 VideoOverlay::draw(ctx, list);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700158 CopyBit::draw(ctx, list, (EGLDisplay)dpy, (EGLSurface)sur);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700159 MDPComp::draw(ctx, list);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700160 EGLBoolean sucess = eglSwapBuffers((EGLDisplay)dpy, (EGLSurface)sur);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700161 UIMirrorOverlay::draw(ctx);
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700162 if(ctx->mExtDisplay->getExternalDisplay())
163 ctx->mExtDisplay->commit();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700164 } else {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700165 ctx->mOverlay->setState(ovutils::OV_CLOSED);
166 ctx->qbuf->unlockAllPrevious();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700167 }
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700168
169 if(!ctx->overlayInUse)
170 ctx->mOverlay->setState(ovutils::OV_CLOSED);
171
Naseer Ahmed29a26812012-06-14 00:56:20 -0700172 return ret;
173}
174
175static int hwc_device_close(struct hw_device_t *dev)
176{
177 if(!dev) {
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700178 ALOGE("%s: NULL device pointer", __FUNCTION__);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700179 return -1;
180 }
181 closeContext((hwc_context_t*)dev);
182 free(dev);
183
184 return 0;
185}
186
187static int hwc_device_open(const struct hw_module_t* module, const char* name,
188 struct hw_device_t** device)
189{
190 int status = -EINVAL;
191
192 if (!strcmp(name, HWC_HARDWARE_COMPOSER)) {
193 struct hwc_context_t *dev;
194 dev = (hwc_context_t*)malloc(sizeof(*dev));
195 memset(dev, 0, sizeof(*dev));
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700196
197 //Initialize hwc context
Naseer Ahmed29a26812012-06-14 00:56:20 -0700198 initContext(dev);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700199
200 //Setup HWC methods
201 hwc_methods_t *methods;
202 methods = (hwc_methods_t *)malloc(sizeof(*methods));
203 memset(methods, 0, sizeof(*methods));
204 methods->eventControl = hwc_eventControl;
205
Naseer Ahmed29a26812012-06-14 00:56:20 -0700206 dev->device.common.tag = HARDWARE_DEVICE_TAG;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700207 dev->device.common.version = HWC_DEVICE_API_VERSION_0_3;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700208 dev->device.common.module = const_cast<hw_module_t*>(module);
209 dev->device.common.close = hwc_device_close;
210 dev->device.prepare = hwc_prepare;
211 dev->device.set = hwc_set;
212 dev->device.registerProcs = hwc_registerProcs;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700213 dev->device.query = hwc_query;
214 dev->device.methods = methods;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700215 *device = &dev->device.common;
216 status = 0;
217 }
218 return status;
219}