blob: e30e06b55feebe7247a8e6df3f191dbc71e12130 [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 Ahmed45a99602012-07-31 19:15:24 -070090 // Mark all layers to COPYBIT initially
91 CopyBit::prepare(ctx, list);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070092 if(VideoOverlay::prepare(ctx, list)) {
93 ctx->overlayInUse = true;
94 //Nothing here
Naseer Ahmed4c588a22012-07-31 19:12:17 -070095 } else if(ExtOnly::prepare(ctx, list)) {
96 ctx->overlayInUse = true;
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070097 } else if(UIMirrorOverlay::prepare(ctx, list)) {
98 ctx->overlayInUse = true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070099 } else if(MDPComp::configure(dev, list)) {
100 ctx->overlayInUse = true;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700101 } else if (0) {
102 //Other features
103 ctx->overlayInUse = true;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700104 } else { // Else set this flag to false, otherwise video cases
105 // fail in non-overlay targets.
106 ctx->overlayInUse = false;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700107 }
108 }
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700109
Naseer Ahmed29a26812012-06-14 00:56:20 -0700110 return 0;
111}
112
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700113static int hwc_eventControl(struct hwc_composer_device* dev,
114 int event, int enabled)
115{
116 int ret = 0;
117 hwc_context_t* ctx = (hwc_context_t*)(dev);
118 private_module_t* m = reinterpret_cast<private_module_t*>(
119 ctx->mFbDev->common.module);
120 switch(event) {
121 case HWC_EVENT_VSYNC:
122 if(ioctl(m->framebuffer->fd, MSMFB_OVERLAY_VSYNC_CTRL, &enabled) < 0)
123 ret = -errno;
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700124
125 if(ctx->mExtDisplay->getExternalDisplay()) {
126 ret = ctx->mExtDisplay->enableHDMIVsync(enabled);
127 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700128 break;
129 default:
130 ret = -EINVAL;
131 }
132 return ret;
133}
134
135static int hwc_query(struct hwc_composer_device* dev,
136 int param, int* value)
137{
138 hwc_context_t* ctx = (hwc_context_t*)(dev);
139 private_module_t* m = reinterpret_cast<private_module_t*>(
140 ctx->mFbDev->common.module);
141
142 switch (param) {
143 case HWC_BACKGROUND_LAYER_SUPPORTED:
144 // Not supported for now
145 value[0] = 0;
146 break;
147 case HWC_VSYNC_PERIOD:
148 value[0] = 1000000000.0 / m->fps;
149 ALOGI("fps: %d", value[0]);
150 break;
151 default:
152 return -EINVAL;
153 }
154 return 0;
155
156}
157
Naseer Ahmed29a26812012-06-14 00:56:20 -0700158static int hwc_set(hwc_composer_device_t *dev,
159 hwc_display_t dpy,
160 hwc_surface_t sur,
161 hwc_layer_list_t* list)
162{
163 int ret = 0;
164 hwc_context_t* ctx = (hwc_context_t*)(dev);
165 if (LIKELY(list)) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700166 VideoOverlay::draw(ctx, list);
Naseer Ahmed4c588a22012-07-31 19:12:17 -0700167 ExtOnly::draw(ctx, list);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700168 CopyBit::draw(ctx, list, (EGLDisplay)dpy, (EGLSurface)sur);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700169 MDPComp::draw(ctx, list);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700170 EGLBoolean sucess = eglSwapBuffers((EGLDisplay)dpy, (EGLSurface)sur);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700171 UIMirrorOverlay::draw(ctx);
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700172 if(ctx->mExtDisplay->getExternalDisplay())
173 ctx->mExtDisplay->commit();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700174 } else {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700175 ctx->mOverlay->setState(ovutils::OV_CLOSED);
176 ctx->qbuf->unlockAllPrevious();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700177 }
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700178
179 if(!ctx->overlayInUse)
180 ctx->mOverlay->setState(ovutils::OV_CLOSED);
181
Naseer Ahmed29a26812012-06-14 00:56:20 -0700182 return ret;
183}
184
185static int hwc_device_close(struct hw_device_t *dev)
186{
187 if(!dev) {
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700188 ALOGE("%s: NULL device pointer", __FUNCTION__);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700189 return -1;
190 }
191 closeContext((hwc_context_t*)dev);
192 free(dev);
193
194 return 0;
195}
196
197static int hwc_device_open(const struct hw_module_t* module, const char* name,
198 struct hw_device_t** device)
199{
200 int status = -EINVAL;
201
202 if (!strcmp(name, HWC_HARDWARE_COMPOSER)) {
203 struct hwc_context_t *dev;
204 dev = (hwc_context_t*)malloc(sizeof(*dev));
205 memset(dev, 0, sizeof(*dev));
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700206
207 //Initialize hwc context
Naseer Ahmed29a26812012-06-14 00:56:20 -0700208 initContext(dev);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700209
210 //Setup HWC methods
211 hwc_methods_t *methods;
212 methods = (hwc_methods_t *)malloc(sizeof(*methods));
213 memset(methods, 0, sizeof(*methods));
214 methods->eventControl = hwc_eventControl;
215
Naseer Ahmed29a26812012-06-14 00:56:20 -0700216 dev->device.common.tag = HARDWARE_DEVICE_TAG;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700217 dev->device.common.version = HWC_DEVICE_API_VERSION_0_3;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700218 dev->device.common.module = const_cast<hw_module_t*>(module);
219 dev->device.common.close = hwc_device_close;
220 dev->device.prepare = hwc_prepare;
221 dev->device.set = hwc_set;
222 dev->device.registerProcs = hwc_registerProcs;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700223 dev->device.query = hwc_query;
224 dev->device.methods = methods;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700225 *device = &dev->device.common;
226 status = 0;
227 }
228 return status;
229}