blob: db6597d0668f9d45af0b15d153aeb932a6503a8a [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 Ahmed96c4c952012-07-25 18:27:14 -070027#include <mdp_version.h>
Naseer Ahmed29a26812012-06-14 00:56:20 -070028#include "hwc_utils.h"
Naseer Ahmed72cf9762012-07-21 12:17:13 -070029#include "hwc_qbuf.h"
Naseer Ahmedf48aef62012-07-20 09:05:53 -070030#include "hwc_video.h"
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070031#include "hwc_uimirror.h"
Naseer Ahmed31da0b12012-07-31 18:55:33 -070032#include "hwc_copybit.h"
Naseer Ahmedf8ec1622012-07-31 18:56:23 -070033#include "hwc_external.h"
Naseer Ahmed7c958d42012-07-31 18:57:03 -070034#include "hwc_mdpcomp.h"
Naseer Ahmed4c588a22012-07-31 19:12:17 -070035#include "hwc_extonly.h"
Naseer Ahmed29a26812012-06-14 00:56:20 -070036
37using namespace qhwc;
38
39static int hwc_device_open(const struct hw_module_t* module,
40 const char* name,
41 struct hw_device_t** device);
42
43static struct hw_module_methods_t hwc_module_methods = {
44 open: hwc_device_open
45};
46
47hwc_module_t HAL_MODULE_INFO_SYM = {
48 common: {
49 tag: HARDWARE_MODULE_TAG,
50 version_major: 2,
51 version_minor: 0,
52 id: HWC_HARDWARE_MODULE_ID,
53 name: "Qualcomm Hardware Composer Module",
54 author: "CodeAurora Forum",
55 methods: &hwc_module_methods,
56 dso: 0,
57 reserved: {0},
58 }
59};
60
61/*
62 * Save callback functions registered to HWC
63 */
64static void hwc_registerProcs(struct hwc_composer_device* dev,
65 hwc_procs_t const* procs)
66{
67 hwc_context_t* ctx = (hwc_context_t*)(dev);
68 if(!ctx) {
69 ALOGE("%s: Invalid context", __FUNCTION__);
70 return;
71 }
72 ctx->device.reserved_proc[0] = (void*)procs;
73}
74
75static int hwc_prepare(hwc_composer_device_t *dev, hwc_layer_list_t* list)
76{
77 hwc_context_t* ctx = (hwc_context_t*)(dev);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070078 ctx->overlayInUse = false;
79
80 //Prepare is called after a vsync, so unlock previous buffers here.
81 ctx->qbuf->unlockAllPrevious();
Ajay Dudanie217fbf2012-07-25 17:46:07 -070082 return 0;
Naseer Ahmedf48aef62012-07-20 09:05:53 -070083
Naseer Ahmed29a26812012-06-14 00:56:20 -070084 if (LIKELY(list)) {
Naseer Ahmed4c588a22012-07-31 19:12:17 -070085 //reset for this draw round
86 VideoOverlay::reset();
87 ExtOnly::reset();
88
Naseer Ahmed29a26812012-06-14 00:56:20 -070089 getLayerStats(ctx, list);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070090 if(VideoOverlay::prepare(ctx, list)) {
91 ctx->overlayInUse = true;
92 //Nothing here
Naseer Ahmed4c588a22012-07-31 19:12:17 -070093 } else if(ExtOnly::prepare(ctx, list)) {
94 ctx->overlayInUse = true;
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070095 } else if(UIMirrorOverlay::prepare(ctx, list)) {
96 ctx->overlayInUse = true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070097 } else if(MDPComp::configure(dev, list)) {
98 ctx->overlayInUse = true;
Naseer Ahmedf48aef62012-07-20 09:05:53 -070099 } else if (0) {
100 //Other features
101 ctx->overlayInUse = true;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700102 } else { // Else set this flag to false, otherwise video cases
103 // fail in non-overlay targets.
104 ctx->overlayInUse = false;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700105 }
106 }
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700107
Naseer Ahmed29a26812012-06-14 00:56:20 -0700108 return 0;
109}
110
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700111static int hwc_eventControl(struct hwc_composer_device* dev,
112 int event, int enabled)
113{
114 int ret = 0;
115 hwc_context_t* ctx = (hwc_context_t*)(dev);
116 private_module_t* m = reinterpret_cast<private_module_t*>(
117 ctx->mFbDev->common.module);
118 switch(event) {
119 case HWC_EVENT_VSYNC:
120 if(ioctl(m->framebuffer->fd, MSMFB_OVERLAY_VSYNC_CTRL, &enabled) < 0)
121 ret = -errno;
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700122
123 if(ctx->mExtDisplay->getExternalDisplay()) {
124 ret = ctx->mExtDisplay->enableHDMIVsync(enabled);
125 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700126 break;
127 default:
128 ret = -EINVAL;
129 }
130 return ret;
131}
132
133static int hwc_query(struct hwc_composer_device* dev,
134 int param, int* value)
135{
136 hwc_context_t* ctx = (hwc_context_t*)(dev);
137 private_module_t* m = reinterpret_cast<private_module_t*>(
138 ctx->mFbDev->common.module);
139
140 switch (param) {
141 case HWC_BACKGROUND_LAYER_SUPPORTED:
142 // Not supported for now
143 value[0] = 0;
144 break;
145 case HWC_VSYNC_PERIOD:
146 value[0] = 1000000000.0 / m->fps;
147 ALOGI("fps: %d", value[0]);
148 break;
149 default:
150 return -EINVAL;
151 }
152 return 0;
153
154}
155
Naseer Ahmed29a26812012-06-14 00:56:20 -0700156static int hwc_set(hwc_composer_device_t *dev,
157 hwc_display_t dpy,
158 hwc_surface_t sur,
159 hwc_layer_list_t* list)
160{
161 int ret = 0;
162 hwc_context_t* ctx = (hwc_context_t*)(dev);
163 if (LIKELY(list)) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700164 VideoOverlay::draw(ctx, list);
Naseer Ahmed4c588a22012-07-31 19:12:17 -0700165 ExtOnly::draw(ctx, list);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700166 MDPComp::draw(ctx, list);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700167 EGLBoolean sucess = eglSwapBuffers((EGLDisplay)dpy, (EGLSurface)sur);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700168 UIMirrorOverlay::draw(ctx);
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700169 if(ctx->mExtDisplay->getExternalDisplay())
170 ctx->mExtDisplay->commit();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700171 } else {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700172 ctx->mOverlay->setState(ovutils::OV_CLOSED);
173 ctx->qbuf->unlockAllPrevious();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700174 }
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700175
176 if(!ctx->overlayInUse)
177 ctx->mOverlay->setState(ovutils::OV_CLOSED);
178
Naseer Ahmed29a26812012-06-14 00:56:20 -0700179 return ret;
180}
181
182static int hwc_device_close(struct hw_device_t *dev)
183{
184 if(!dev) {
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700185 ALOGE("%s: NULL device pointer", __FUNCTION__);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700186 return -1;
187 }
188 closeContext((hwc_context_t*)dev);
189 free(dev);
190
191 return 0;
192}
193
194static int hwc_device_open(const struct hw_module_t* module, const char* name,
195 struct hw_device_t** device)
196{
197 int status = -EINVAL;
198
199 if (!strcmp(name, HWC_HARDWARE_COMPOSER)) {
200 struct hwc_context_t *dev;
201 dev = (hwc_context_t*)malloc(sizeof(*dev));
202 memset(dev, 0, sizeof(*dev));
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700203
204 //Initialize hwc context
Naseer Ahmed29a26812012-06-14 00:56:20 -0700205 initContext(dev);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700206
207 //Setup HWC methods
208 hwc_methods_t *methods;
209 methods = (hwc_methods_t *)malloc(sizeof(*methods));
210 memset(methods, 0, sizeof(*methods));
211 methods->eventControl = hwc_eventControl;
212
Naseer Ahmed29a26812012-06-14 00:56:20 -0700213 dev->device.common.tag = HARDWARE_DEVICE_TAG;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700214 dev->device.common.version = HWC_DEVICE_API_VERSION_0_3;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700215 dev->device.common.module = const_cast<hw_module_t*>(module);
216 dev->device.common.close = hwc_device_close;
217 dev->device.prepare = hwc_prepare;
218 dev->device.set = hwc_set;
219 dev->device.registerProcs = hwc_registerProcs;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700220 dev->device.query = hwc_query;
221 dev->device.methods = methods;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700222 *device = &dev->device.common;
223 status = 0;
224 }
225 return status;
226}