blob: c132f16993ff8ec6dbc94638b996031eebdf1eb2 [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();
Ajay Dudanie217fbf2012-07-25 17:46:07 -070083 return 0;
Naseer Ahmedf48aef62012-07-20 09:05:53 -070084
Naseer Ahmed5b6708a2012-08-02 13:46:08 -070085 for (uint32_t i = 0; i <numDisplays; i++) {
86 hwc_display_contents_1_t* list = displays[i];
87 ctx->dpys[i] = list->dpy;
88 //XXX: Actually handle the multiple displays
89 if (LIKELY(list)) {
90 //reset for this draw round
91 VideoOverlay::reset();
92 ExtOnly::reset();
Naseer Ahmed4c588a22012-07-31 19:12:17 -070093
Naseer Ahmed5b6708a2012-08-02 13:46:08 -070094 getLayerStats(ctx, list);
95 if(VideoOverlay::prepare(ctx, list)) {
96 ctx->overlayInUse = true;
97 //Nothing here
98 } else if(ExtOnly::prepare(ctx, list)) {
99 ctx->overlayInUse = true;
100 } else if(UIMirrorOverlay::prepare(ctx, list)) {
101 ctx->overlayInUse = true;
102 } else if(MDPComp::configure(dev, list)) {
103 ctx->overlayInUse = true;
104 } else if (0) {
105 //Other features
106 ctx->overlayInUse = true;
107 } else { // Else set this flag to false, otherwise video cases
108 // fail in non-overlay targets.
109 ctx->overlayInUse = false;
110 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700111 }
112 }
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700113
Naseer Ahmed29a26812012-06-14 00:56:20 -0700114 return 0;
115}
116
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700117static int hwc_eventControl(struct hwc_composer_device_1* dev, int dpy,
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700118 int event, int enabled)
119{
120 int ret = 0;
121 hwc_context_t* ctx = (hwc_context_t*)(dev);
122 private_module_t* m = reinterpret_cast<private_module_t*>(
123 ctx->mFbDev->common.module);
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700124 //XXX: Handle dpy
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700125 switch(event) {
126 case HWC_EVENT_VSYNC:
127 if(ioctl(m->framebuffer->fd, MSMFB_OVERLAY_VSYNC_CTRL, &enabled) < 0)
128 ret = -errno;
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700129
130 if(ctx->mExtDisplay->getExternalDisplay()) {
131 ret = ctx->mExtDisplay->enableHDMIVsync(enabled);
132 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700133 break;
134 default:
135 ret = -EINVAL;
136 }
137 return ret;
138}
139
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700140static int hwc_blank(struct hwc_composer_device_1* dev, int dpy, int blank)
141{
142 //XXX: Handle based on dpy
143 if(blank) {
144 hwc_context_t* ctx = (hwc_context_t*)(dev);
145 ctx->mOverlay->setState(ovutils::OV_CLOSED);
146 ctx->qbuf->unlockAllPrevious();
147 }
148 return 0;
149}
150
151static int hwc_query(struct hwc_composer_device_1* dev,
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700152 int param, int* value)
153{
154 hwc_context_t* ctx = (hwc_context_t*)(dev);
155 private_module_t* m = reinterpret_cast<private_module_t*>(
156 ctx->mFbDev->common.module);
157
158 switch (param) {
159 case HWC_BACKGROUND_LAYER_SUPPORTED:
160 // Not supported for now
161 value[0] = 0;
162 break;
163 case HWC_VSYNC_PERIOD:
164 value[0] = 1000000000.0 / m->fps;
165 ALOGI("fps: %d", value[0]);
166 break;
167 default:
168 return -EINVAL;
169 }
170 return 0;
171
172}
173
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700174static int hwc_set(hwc_composer_device_1 *dev,
175 size_t numDisplays,
176 hwc_display_contents_1_t** displays)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700177{
178 int ret = 0;
179 hwc_context_t* ctx = (hwc_context_t*)(dev);
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700180 for (uint32_t i = 0; i <numDisplays; i++) {
181 hwc_display_contents_1_t* list = displays[i];
182 //XXX: Actually handle the multiple displays
183 if (LIKELY(list)) {
184 VideoOverlay::draw(ctx, list);
185 ExtOnly::draw(ctx, list);
186 MDPComp::draw(ctx, list);
187 EGLBoolean success = eglSwapBuffers((EGLDisplay)list->dpy,
188 (EGLSurface)list->sur);
189 UIMirrorOverlay::draw(ctx);
190 if(ctx->mExtDisplay->getExternalDisplay())
191 ctx->mExtDisplay->commit();
192 } else {
193 ctx->mOverlay->setState(ovutils::OV_CLOSED);
194 ctx->qbuf->unlockAllPrevious();
195 }
196
197 if(!ctx->overlayInUse)
198 ctx->mOverlay->setState(ovutils::OV_CLOSED);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700199 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700200 return ret;
201}
202
203static int hwc_device_close(struct hw_device_t *dev)
204{
205 if(!dev) {
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700206 ALOGE("%s: NULL device pointer", __FUNCTION__);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700207 return -1;
208 }
209 closeContext((hwc_context_t*)dev);
210 free(dev);
211
212 return 0;
213}
214
215static int hwc_device_open(const struct hw_module_t* module, const char* name,
216 struct hw_device_t** device)
217{
218 int status = -EINVAL;
219
220 if (!strcmp(name, HWC_HARDWARE_COMPOSER)) {
221 struct hwc_context_t *dev;
222 dev = (hwc_context_t*)malloc(sizeof(*dev));
223 memset(dev, 0, sizeof(*dev));
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700224
225 //Initialize hwc context
Naseer Ahmed29a26812012-06-14 00:56:20 -0700226 initContext(dev);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700227
228 //Setup HWC methods
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700229 hwc_methods_1_t *methods;
230 methods = (hwc_methods_1_t *) malloc(sizeof(*methods));
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700231 memset(methods, 0, sizeof(*methods));
232 methods->eventControl = hwc_eventControl;
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700233 methods->blank = hwc_blank;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700234
Naseer Ahmed29a26812012-06-14 00:56:20 -0700235 dev->device.common.tag = HARDWARE_DEVICE_TAG;
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700236 dev->device.common.version = HWC_DEVICE_API_VERSION_1_0;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700237 dev->device.common.module = const_cast<hw_module_t*>(module);
238 dev->device.common.close = hwc_device_close;
239 dev->device.prepare = hwc_prepare;
240 dev->device.set = hwc_set;
241 dev->device.registerProcs = hwc_registerProcs;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700242 dev->device.query = hwc_query;
243 dev->device.methods = methods;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700244 *device = &dev->device.common;
245 status = 0;
246 }
247 return status;
248}