blob: ab5b144ef2ecb7753826f3b24afc03cabf838111 [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 */
Naseer Ahmed5b6708a2012-08-02 13:46:08 -070064static void hwc_registerProcs(struct hwc_composer_device_1* dev,
Naseer Ahmed29a26812012-06-14 00:56:20 -070065 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
Naseer Ahmed5b6708a2012-08-02 13:46:08 -070075static int hwc_prepare(hwc_composer_device_1 *dev, size_t numDisplays,
76 hwc_display_contents_1_t** displays)
Naseer Ahmed29a26812012-06-14 00:56:20 -070077{
78 hwc_context_t* ctx = (hwc_context_t*)(dev);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070079 ctx->overlayInUse = false;
80
81 //Prepare is called after a vsync, so unlock previous buffers here.
82 ctx->qbuf->unlockAllPrevious();
83
Naseer Ahmed5b6708a2012-08-02 13:46:08 -070084 for (uint32_t i = 0; i <numDisplays; i++) {
85 hwc_display_contents_1_t* list = displays[i];
86 ctx->dpys[i] = list->dpy;
87 //XXX: Actually handle the multiple displays
88 if (LIKELY(list)) {
89 //reset for this draw round
90 VideoOverlay::reset();
91 ExtOnly::reset();
Naseer Ahmed4c588a22012-07-31 19:12:17 -070092
Naseer Ahmed5b6708a2012-08-02 13:46:08 -070093 getLayerStats(ctx, list);
94 if(VideoOverlay::prepare(ctx, list)) {
95 ctx->overlayInUse = true;
96 //Nothing here
97 } else if(ExtOnly::prepare(ctx, list)) {
98 ctx->overlayInUse = true;
99 } else if(UIMirrorOverlay::prepare(ctx, list)) {
100 ctx->overlayInUse = true;
101 } else if(MDPComp::configure(dev, list)) {
102 ctx->overlayInUse = true;
103 } else if (0) {
104 //Other features
105 ctx->overlayInUse = true;
106 } else { // Else set this flag to false, otherwise video cases
107 // fail in non-overlay targets.
108 ctx->overlayInUse = false;
109 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700110 }
111 }
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700112
Naseer Ahmed29a26812012-06-14 00:56:20 -0700113 return 0;
114}
115
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700116static int hwc_eventControl(struct hwc_composer_device_1* dev, int dpy,
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700117 int event, int enabled)
118{
119 int ret = 0;
120 hwc_context_t* ctx = (hwc_context_t*)(dev);
121 private_module_t* m = reinterpret_cast<private_module_t*>(
122 ctx->mFbDev->common.module);
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700123 //XXX: Handle dpy
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700124 switch(event) {
125 case HWC_EVENT_VSYNC:
126 if(ioctl(m->framebuffer->fd, MSMFB_OVERLAY_VSYNC_CTRL, &enabled) < 0)
127 ret = -errno;
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700128
129 if(ctx->mExtDisplay->getExternalDisplay()) {
130 ret = ctx->mExtDisplay->enableHDMIVsync(enabled);
131 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700132 break;
133 default:
134 ret = -EINVAL;
135 }
136 return ret;
137}
138
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700139static int hwc_blank(struct hwc_composer_device_1* dev, int dpy, int blank)
140{
141 //XXX: Handle based on dpy
142 if(blank) {
143 hwc_context_t* ctx = (hwc_context_t*)(dev);
144 ctx->mOverlay->setState(ovutils::OV_CLOSED);
145 ctx->qbuf->unlockAllPrevious();
146 }
147 return 0;
148}
149
150static int hwc_query(struct hwc_composer_device_1* dev,
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700151 int param, int* value)
152{
153 hwc_context_t* ctx = (hwc_context_t*)(dev);
154 private_module_t* m = reinterpret_cast<private_module_t*>(
155 ctx->mFbDev->common.module);
156
157 switch (param) {
158 case HWC_BACKGROUND_LAYER_SUPPORTED:
159 // Not supported for now
160 value[0] = 0;
161 break;
162 case HWC_VSYNC_PERIOD:
163 value[0] = 1000000000.0 / m->fps;
164 ALOGI("fps: %d", value[0]);
165 break;
166 default:
167 return -EINVAL;
168 }
169 return 0;
170
171}
172
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700173static int hwc_set(hwc_composer_device_1 *dev,
174 size_t numDisplays,
175 hwc_display_contents_1_t** displays)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700176{
177 int ret = 0;
178 hwc_context_t* ctx = (hwc_context_t*)(dev);
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700179 for (uint32_t i = 0; i <numDisplays; i++) {
180 hwc_display_contents_1_t* list = displays[i];
181 //XXX: Actually handle the multiple displays
182 if (LIKELY(list)) {
183 VideoOverlay::draw(ctx, list);
184 ExtOnly::draw(ctx, list);
185 MDPComp::draw(ctx, list);
186 EGLBoolean success = eglSwapBuffers((EGLDisplay)list->dpy,
187 (EGLSurface)list->sur);
188 UIMirrorOverlay::draw(ctx);
189 if(ctx->mExtDisplay->getExternalDisplay())
190 ctx->mExtDisplay->commit();
191 } else {
192 ctx->mOverlay->setState(ovutils::OV_CLOSED);
193 ctx->qbuf->unlockAllPrevious();
194 }
195
196 if(!ctx->overlayInUse)
197 ctx->mOverlay->setState(ovutils::OV_CLOSED);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700198 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700199 return ret;
200}
201
202static int hwc_device_close(struct hw_device_t *dev)
203{
204 if(!dev) {
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700205 ALOGE("%s: NULL device pointer", __FUNCTION__);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700206 return -1;
207 }
208 closeContext((hwc_context_t*)dev);
209 free(dev);
210
211 return 0;
212}
213
214static int hwc_device_open(const struct hw_module_t* module, const char* name,
215 struct hw_device_t** device)
216{
217 int status = -EINVAL;
218
219 if (!strcmp(name, HWC_HARDWARE_COMPOSER)) {
220 struct hwc_context_t *dev;
221 dev = (hwc_context_t*)malloc(sizeof(*dev));
222 memset(dev, 0, sizeof(*dev));
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700223
224 //Initialize hwc context
Naseer Ahmed29a26812012-06-14 00:56:20 -0700225 initContext(dev);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700226
227 //Setup HWC methods
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700228 hwc_methods_1_t *methods;
229 methods = (hwc_methods_1_t *) malloc(sizeof(*methods));
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700230 memset(methods, 0, sizeof(*methods));
231 methods->eventControl = hwc_eventControl;
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700232 methods->blank = hwc_blank;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700233
Naseer Ahmed29a26812012-06-14 00:56:20 -0700234 dev->device.common.tag = HARDWARE_DEVICE_TAG;
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700235 dev->device.common.version = HWC_DEVICE_API_VERSION_1_0;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700236 dev->device.common.module = const_cast<hw_module_t*>(module);
237 dev->device.common.close = hwc_device_close;
238 dev->device.prepare = hwc_prepare;
239 dev->device.set = hwc_set;
240 dev->device.registerProcs = hwc_registerProcs;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700241 dev->device.query = hwc_query;
242 dev->device.methods = methods;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700243 *device = &dev->device.common;
244 status = 0;
245 }
246 return status;
247}