blob: ad84d2543d17c2cc5a7f5d259bc04d5c6cc80adb [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 }
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700106 CopyBit::prepare(ctx, list);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700107 }
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700108
Naseer Ahmed29a26812012-06-14 00:56:20 -0700109 return 0;
110}
111
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700112static int hwc_eventControl(struct hwc_composer_device* dev,
113 int event, int enabled)
114{
115 int ret = 0;
116 hwc_context_t* ctx = (hwc_context_t*)(dev);
117 private_module_t* m = reinterpret_cast<private_module_t*>(
118 ctx->mFbDev->common.module);
119 switch(event) {
120 case HWC_EVENT_VSYNC:
121 if(ioctl(m->framebuffer->fd, MSMFB_OVERLAY_VSYNC_CTRL, &enabled) < 0)
122 ret = -errno;
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700123
124 if(ctx->mExtDisplay->getExternalDisplay()) {
125 ret = ctx->mExtDisplay->enableHDMIVsync(enabled);
126 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700127 break;
128 default:
129 ret = -EINVAL;
130 }
131 return ret;
132}
133
134static int hwc_query(struct hwc_composer_device* dev,
135 int param, int* value)
136{
137 hwc_context_t* ctx = (hwc_context_t*)(dev);
138 private_module_t* m = reinterpret_cast<private_module_t*>(
139 ctx->mFbDev->common.module);
140
141 switch (param) {
142 case HWC_BACKGROUND_LAYER_SUPPORTED:
143 // Not supported for now
144 value[0] = 0;
145 break;
146 case HWC_VSYNC_PERIOD:
147 value[0] = 1000000000.0 / m->fps;
148 ALOGI("fps: %d", value[0]);
149 break;
150 default:
151 return -EINVAL;
152 }
153 return 0;
154
155}
156
Naseer Ahmed29a26812012-06-14 00:56:20 -0700157static int hwc_set(hwc_composer_device_t *dev,
158 hwc_display_t dpy,
159 hwc_surface_t sur,
160 hwc_layer_list_t* list)
161{
162 int ret = 0;
163 hwc_context_t* ctx = (hwc_context_t*)(dev);
164 if (LIKELY(list)) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700165 VideoOverlay::draw(ctx, list);
Naseer Ahmed4c588a22012-07-31 19:12:17 -0700166 ExtOnly::draw(ctx, list);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700167 CopyBit::draw(ctx, list, (EGLDisplay)dpy, (EGLSurface)sur);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700168 MDPComp::draw(ctx, list);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700169 EGLBoolean sucess = eglSwapBuffers((EGLDisplay)dpy, (EGLSurface)sur);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700170 UIMirrorOverlay::draw(ctx);
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700171 if(ctx->mExtDisplay->getExternalDisplay())
172 ctx->mExtDisplay->commit();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700173 } else {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700174 ctx->mOverlay->setState(ovutils::OV_CLOSED);
175 ctx->qbuf->unlockAllPrevious();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700176 }
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700177
178 if(!ctx->overlayInUse)
179 ctx->mOverlay->setState(ovutils::OV_CLOSED);
180
Naseer Ahmed29a26812012-06-14 00:56:20 -0700181 return ret;
182}
183
184static int hwc_device_close(struct hw_device_t *dev)
185{
186 if(!dev) {
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700187 ALOGE("%s: NULL device pointer", __FUNCTION__);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700188 return -1;
189 }
190 closeContext((hwc_context_t*)dev);
191 free(dev);
192
193 return 0;
194}
195
196static int hwc_device_open(const struct hw_module_t* module, const char* name,
197 struct hw_device_t** device)
198{
199 int status = -EINVAL;
200
201 if (!strcmp(name, HWC_HARDWARE_COMPOSER)) {
202 struct hwc_context_t *dev;
203 dev = (hwc_context_t*)malloc(sizeof(*dev));
204 memset(dev, 0, sizeof(*dev));
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700205
206 //Initialize hwc context
Naseer Ahmed29a26812012-06-14 00:56:20 -0700207 initContext(dev);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700208
209 //Setup HWC methods
210 hwc_methods_t *methods;
211 methods = (hwc_methods_t *)malloc(sizeof(*methods));
212 memset(methods, 0, sizeof(*methods));
213 methods->eventControl = hwc_eventControl;
214
Naseer Ahmed29a26812012-06-14 00:56:20 -0700215 dev->device.common.tag = HARDWARE_DEVICE_TAG;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700216 dev->device.common.version = HWC_DEVICE_API_VERSION_0_3;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700217 dev->device.common.module = const_cast<hw_module_t*>(module);
218 dev->device.common.close = hwc_device_close;
219 dev->device.prepare = hwc_prepare;
220 dev->device.set = hwc_set;
221 dev->device.registerProcs = hwc_registerProcs;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700222 dev->device.query = hwc_query;
223 dev->device.methods = methods;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700224 *device = &dev->device.common;
225 status = 0;
226 }
227 return status;
228}