blob: 13d6274bf4ec6d233c45aa7a2a4dd62106cdd7a6 [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 Ahmed29a26812012-06-14 00:56:20 -070035
36using namespace qhwc;
37
38static int hwc_device_open(const struct hw_module_t* module,
39 const char* name,
40 struct hw_device_t** device);
41
42static struct hw_module_methods_t hwc_module_methods = {
43 open: hwc_device_open
44};
45
46hwc_module_t HAL_MODULE_INFO_SYM = {
47 common: {
48 tag: HARDWARE_MODULE_TAG,
49 version_major: 2,
50 version_minor: 0,
51 id: HWC_HARDWARE_MODULE_ID,
52 name: "Qualcomm Hardware Composer Module",
53 author: "CodeAurora Forum",
54 methods: &hwc_module_methods,
55 dso: 0,
56 reserved: {0},
57 }
58};
59
60/*
61 * Save callback functions registered to HWC
62 */
63static void hwc_registerProcs(struct hwc_composer_device* dev,
64 hwc_procs_t const* procs)
65{
66 hwc_context_t* ctx = (hwc_context_t*)(dev);
67 if(!ctx) {
68 ALOGE("%s: Invalid context", __FUNCTION__);
69 return;
70 }
71 ctx->device.reserved_proc[0] = (void*)procs;
72}
73
74static int hwc_prepare(hwc_composer_device_t *dev, hwc_layer_list_t* list)
75{
76 hwc_context_t* ctx = (hwc_context_t*)(dev);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070077 ctx->overlayInUse = false;
78
79 //Prepare is called after a vsync, so unlock previous buffers here.
80 ctx->qbuf->unlockAllPrevious();
Ajay Dudanie217fbf2012-07-25 17:46:07 -070081 return 0;
Naseer Ahmedf48aef62012-07-20 09:05:53 -070082
Naseer Ahmed29a26812012-06-14 00:56:20 -070083 if (LIKELY(list)) {
84 getLayerStats(ctx, list);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070085 if(VideoOverlay::prepare(ctx, list)) {
86 ctx->overlayInUse = true;
87 //Nothing here
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070088 } else if(UIMirrorOverlay::prepare(ctx, list)) {
89 ctx->overlayInUse = true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070090 } else if(MDPComp::configure(dev, list)) {
91 ctx->overlayInUse = true;
Naseer Ahmedf48aef62012-07-20 09:05:53 -070092 } else if (0) {
93 //Other features
94 ctx->overlayInUse = true;
Naseer Ahmed31da0b12012-07-31 18:55:33 -070095 } else { // Else set this flag to false, otherwise video cases
96 // fail in non-overlay targets.
97 ctx->overlayInUse = false;
Naseer Ahmed29a26812012-06-14 00:56:20 -070098 }
Naseer Ahmed31da0b12012-07-31 18:55:33 -070099 CopyBit::prepare(ctx, list);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700100 }
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700101
Naseer Ahmed29a26812012-06-14 00:56:20 -0700102 return 0;
103}
104
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700105static int hwc_eventControl(struct hwc_composer_device* dev,
106 int event, int enabled)
107{
108 int ret = 0;
109 hwc_context_t* ctx = (hwc_context_t*)(dev);
110 private_module_t* m = reinterpret_cast<private_module_t*>(
111 ctx->mFbDev->common.module);
112 switch(event) {
113 case HWC_EVENT_VSYNC:
114 if(ioctl(m->framebuffer->fd, MSMFB_OVERLAY_VSYNC_CTRL, &enabled) < 0)
115 ret = -errno;
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700116
117 if(ctx->mExtDisplay->getExternalDisplay()) {
118 ret = ctx->mExtDisplay->enableHDMIVsync(enabled);
119 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700120 break;
121 default:
122 ret = -EINVAL;
123 }
124 return ret;
125}
126
127static int hwc_query(struct hwc_composer_device* dev,
128 int param, int* value)
129{
130 hwc_context_t* ctx = (hwc_context_t*)(dev);
131 private_module_t* m = reinterpret_cast<private_module_t*>(
132 ctx->mFbDev->common.module);
133
134 switch (param) {
135 case HWC_BACKGROUND_LAYER_SUPPORTED:
136 // Not supported for now
137 value[0] = 0;
138 break;
139 case HWC_VSYNC_PERIOD:
140 value[0] = 1000000000.0 / m->fps;
141 ALOGI("fps: %d", value[0]);
142 break;
143 default:
144 return -EINVAL;
145 }
146 return 0;
147
148}
149
Naseer Ahmed29a26812012-06-14 00:56:20 -0700150static int hwc_set(hwc_composer_device_t *dev,
151 hwc_display_t dpy,
152 hwc_surface_t sur,
153 hwc_layer_list_t* list)
154{
155 int ret = 0;
156 hwc_context_t* ctx = (hwc_context_t*)(dev);
157 if (LIKELY(list)) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700158 VideoOverlay::draw(ctx, list);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700159 CopyBit::draw(ctx, list, (EGLDisplay)dpy, (EGLSurface)sur);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700160 MDPComp::draw(ctx, list);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700161 EGLBoolean sucess = eglSwapBuffers((EGLDisplay)dpy, (EGLSurface)sur);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700162 UIMirrorOverlay::draw(ctx);
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700163 if(ctx->mExtDisplay->getExternalDisplay())
164 ctx->mExtDisplay->commit();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700165 } else {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700166 ctx->mOverlay->setState(ovutils::OV_CLOSED);
167 ctx->qbuf->unlockAllPrevious();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700168 }
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700169
170 if(!ctx->overlayInUse)
171 ctx->mOverlay->setState(ovutils::OV_CLOSED);
172
Naseer Ahmed29a26812012-06-14 00:56:20 -0700173 return ret;
174}
175
176static int hwc_device_close(struct hw_device_t *dev)
177{
178 if(!dev) {
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700179 ALOGE("%s: NULL device pointer", __FUNCTION__);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700180 return -1;
181 }
182 closeContext((hwc_context_t*)dev);
183 free(dev);
184
185 return 0;
186}
187
188static int hwc_device_open(const struct hw_module_t* module, const char* name,
189 struct hw_device_t** device)
190{
191 int status = -EINVAL;
192
193 if (!strcmp(name, HWC_HARDWARE_COMPOSER)) {
194 struct hwc_context_t *dev;
195 dev = (hwc_context_t*)malloc(sizeof(*dev));
196 memset(dev, 0, sizeof(*dev));
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700197
198 //Initialize hwc context
Naseer Ahmed29a26812012-06-14 00:56:20 -0700199 initContext(dev);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700200
201 //Setup HWC methods
202 hwc_methods_t *methods;
203 methods = (hwc_methods_t *)malloc(sizeof(*methods));
204 memset(methods, 0, sizeof(*methods));
205 methods->eventControl = hwc_eventControl;
206
Naseer Ahmed29a26812012-06-14 00:56:20 -0700207 dev->device.common.tag = HARDWARE_DEVICE_TAG;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700208 dev->device.common.version = HWC_DEVICE_API_VERSION_0_3;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700209 dev->device.common.module = const_cast<hw_module_t*>(module);
210 dev->device.common.close = hwc_device_close;
211 dev->device.prepare = hwc_prepare;
212 dev->device.set = hwc_set;
213 dev->device.registerProcs = hwc_registerProcs;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700214 dev->device.query = hwc_query;
215 dev->device.methods = methods;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700216 *device = &dev->device.common;
217 status = 0;
218 }
219 return status;
220}