blob: 3be2def2da5756bed8608294d62f0c8188230444 [file] [log] [blame]
Naseer Ahmed29a26812012-06-14 00:56:20 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
Saurabh Shah56f610d2012-08-07 15:27:06 -07003 * Copyright (C) 2012, The Linux Foundation. All rights reserved.
Naseer Ahmed29a26812012-06-14 00:56:20 -07004 *
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 Ahmedf48aef62012-07-20 09:05:53 -070029#include "hwc_video.h"
Saurabh Shah56f610d2012-08-07 15:27:06 -070030#include "external.h"
Naseer Ahmed7c958d42012-07-31 18:57:03 -070031#include "hwc_mdpcomp.h"
Naseer Ahmed29a26812012-06-14 00:56:20 -070032
33using namespace qhwc;
34
35static int hwc_device_open(const struct hw_module_t* module,
36 const char* name,
37 struct hw_device_t** device);
38
39static struct hw_module_methods_t hwc_module_methods = {
40 open: hwc_device_open
41};
42
43hwc_module_t HAL_MODULE_INFO_SYM = {
44 common: {
45 tag: HARDWARE_MODULE_TAG,
46 version_major: 2,
47 version_minor: 0,
48 id: HWC_HARDWARE_MODULE_ID,
49 name: "Qualcomm Hardware Composer Module",
50 author: "CodeAurora Forum",
51 methods: &hwc_module_methods,
52 dso: 0,
53 reserved: {0},
54 }
55};
56
57/*
58 * Save callback functions registered to HWC
59 */
Naseer Ahmed5b6708a2012-08-02 13:46:08 -070060static void hwc_registerProcs(struct hwc_composer_device_1* dev,
Naseer Ahmed29a26812012-06-14 00:56:20 -070061 hwc_procs_t const* procs)
62{
63 hwc_context_t* ctx = (hwc_context_t*)(dev);
64 if(!ctx) {
65 ALOGE("%s: Invalid context", __FUNCTION__);
66 return;
67 }
Jesse Hall3be78d92012-08-21 15:12:23 -070068 ctx->proc = procs;
69
70 // don't start listening for events until we can do something with them
71 init_uevent_thread(ctx);
Naseer Ahmed29a26812012-06-14 00:56:20 -070072}
73
Saurabh Shah649cda62012-09-16 16:05:58 -070074//Helper
Saurabh Shah3e858eb2012-09-17 16:53:21 -070075static void reset(hwc_context_t *ctx, int numDisplays) {
76 memset(ctx->listStats, 0, sizeof(ctx->listStats));
77 for(int i = 0; i < numDisplays; i++){
78 ctx->listStats[i].yuvIndex = -1;
79 }
80}
81
82static int hwc_prepare_primary(hwc_composer_device_1 *dev,
83 hwc_display_contents_1_t *list) {
84 hwc_context_t* ctx = (hwc_context_t*)(dev);
85 if (LIKELY(list && list->numHwLayers)) {
86 setListStats(ctx, list, HWC_DISPLAY_PRIMARY);
87 if(VideoOverlay::prepare(ctx, list, HWC_DISPLAY_PRIMARY)) {
88 ctx->overlayInUse = true;
89 } else if(MDPComp::configure(ctx, list)) {
90 ctx->overlayInUse = true;
91 } else {
92 ctx->overlayInUse = false;
93 }
94 }
95 return 0;
96}
97
98static int hwc_prepare_external(hwc_composer_device_1 *dev,
99 hwc_display_contents_1_t *list) {
100
101 hwc_context_t* ctx = (hwc_context_t*)(dev);
102 if (LIKELY(list && list->numHwLayers)) {
103 setListStats(ctx, list, HWC_DISPLAY_EXTERNAL);
104 //Nothing to do for now
105 }
106 return 0;
Saurabh Shah649cda62012-09-16 16:05:58 -0700107}
108
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700109static int hwc_prepare(hwc_composer_device_1 *dev, size_t numDisplays,
110 hwc_display_contents_1_t** displays)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700111{
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700112 int ret = 0;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700113 hwc_context_t* ctx = (hwc_context_t*)(dev);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700114 ctx->overlayInUse = false;
115
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700116 reset(ctx, numDisplays);
Saurabh Shah56f610d2012-08-07 15:27:06 -0700117
118 //If securing of h/w in progress skip comp using overlay.
119 if(ctx->mSecuring == true) return 0;
120
Saurabh Shah9171ec62012-09-13 09:33:51 -0700121 for (uint32_t i = 0; i < numDisplays; i++) {
122 hwc_display_contents_1_t *list = displays[i];
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700123 switch(i) {
124 case HWC_DISPLAY_PRIMARY:
125 ret = hwc_prepare_primary(dev, list);
126 break;
127 case HWC_DISPLAY_EXTERNAL:
128 ret = hwc_prepare_external(dev, list);
129 break;
130 default:
131 ret = -EINVAL;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700132 }
133 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700134 return ret;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700135}
136
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700137static int hwc_eventControl(struct hwc_composer_device_1* dev, int dpy,
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700138 int event, int enabled)
139{
140 int ret = 0;
141 hwc_context_t* ctx = (hwc_context_t*)(dev);
142 private_module_t* m = reinterpret_cast<private_module_t*>(
143 ctx->mFbDev->common.module);
144 switch(event) {
145 case HWC_EVENT_VSYNC:
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700146 if(ioctl(ctx->dpyAttr[dpy].fd, MSMFB_OVERLAY_VSYNC_CTRL,
147 &enabled) < 0) {
148 ALOGE("%s: vsync control failed. Dpy=%d, enabled=%d : %s",
149 __FUNCTION__, dpy, enabled, strerror(errno));
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700150 ret = -errno;
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700151 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700152 break;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700153 default:
154 ret = -EINVAL;
155 }
156 return ret;
157}
158
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700159static int hwc_blank(struct hwc_composer_device_1* dev, int dpy, int blank)
160{
Naseer Ahmed934790c2012-08-16 18:11:09 -0700161 hwc_context_t* ctx = (hwc_context_t*)(dev);
162 private_module_t* m = reinterpret_cast<private_module_t*>(
163 ctx->mFbDev->common.module);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700164 int ret = 0;
165 ALOGD("%s: Doing Dpy=%d, blank=%d", __FUNCTION__, dpy, blank);
166 switch(dpy) {
167 case HWC_DISPLAY_PRIMARY:
168 if(blank) {
169 ctx->mOverlay->setState(ovutils::OV_CLOSED);
170 ret = ioctl(m->framebuffer->fd, FBIOBLANK, FB_BLANK_POWERDOWN);
171 } else {
172 ret = ioctl(m->framebuffer->fd, FBIOBLANK, FB_BLANK_UNBLANK);
173 }
174 break;
175 case HWC_DISPLAY_EXTERNAL:
176 if(blank) {
177 //TODO actual
178 } else {
179 }
180 break;
181 default:
182 return -EINVAL;
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700183 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700184
185 if(ret < 0) {
186 ALOGE("%s: failed. Dpy=%d, blank=%d : %s",
187 __FUNCTION__, dpy, blank, strerror(errno));
188 return ret;
189 }
190 ALOGD("%s: Done Dpy=%d, blank=%d", __FUNCTION__, dpy, blank);
191 ctx->dpyAttr[dpy].isActive = !blank;
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700192 return 0;
193}
194
195static int hwc_query(struct hwc_composer_device_1* dev,
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700196 int param, int* value)
197{
198 hwc_context_t* ctx = (hwc_context_t*)(dev);
199 private_module_t* m = reinterpret_cast<private_module_t*>(
200 ctx->mFbDev->common.module);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700201 int supported = HWC_DISPLAY_PRIMARY_BIT;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700202
203 switch (param) {
204 case HWC_BACKGROUND_LAYER_SUPPORTED:
205 // Not supported for now
206 value[0] = 0;
207 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700208 case HWC_VSYNC_PERIOD: //Not used for hwc > 1.1
Saurabh Shah2e2798c2012-08-30 14:47:10 -0700209 value[0] = m->fps;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700210 ALOGI("fps: %d", value[0]);
211 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700212 case HWC_DISPLAY_TYPES_SUPPORTED:
213 //Enable later
214 //if(ctx->mMDP.hasOverlay)
215 //supported |= HWC_DISPLAY_EXTERNAL_BIT;
216 value[0] = supported;
217 break;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700218 default:
219 return -EINVAL;
220 }
221 return 0;
222
223}
224
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700225static int hwc_set_primary(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
226 if (LIKELY(list && list->numHwLayers)) {
227 VideoOverlay::draw(ctx, list, HWC_DISPLAY_PRIMARY);
228 MDPComp::draw(ctx, list);
229 hwc_sync(ctx, list, HWC_DISPLAY_PRIMARY);
230 //TODO We dont check for SKIP flag on this layer because we need PAN
231 //always. Last layer is always FB
232 uint32_t last = list->numHwLayers - 1;
233 if(list->hwLayers[last].compositionType == HWC_FRAMEBUFFER_TARGET) {
234 ctx->mFbDev->post(ctx->mFbDev, list->hwLayers[last].handle);
235 }
236 }
237 return 0;
238}
239
240static int hwc_set_external(hwc_context_t *ctx,
241 hwc_display_contents_1_t* list) {
242 if (LIKELY(list && list->numHwLayers)) {
243 hwc_sync(ctx, list, HWC_DISPLAY_EXTERNAL);
244 uint32_t last = list->numHwLayers - 1;
245 if(list->hwLayers[last].compositionType == HWC_FRAMEBUFFER_TARGET &&
246 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isActive) {
247 //ctx->mExtDisplay->post(list->hwLayers[last].handle);
248 }
249 }
250 return 0;
251}
252
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700253static int hwc_set(hwc_composer_device_1 *dev,
254 size_t numDisplays,
255 hwc_display_contents_1_t** displays)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700256{
257 int ret = 0;
258 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700259 for (uint32_t i = 0; i < numDisplays; i++) {
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700260 hwc_display_contents_1_t* list = displays[i];
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700261 switch(i) {
262 case HWC_DISPLAY_PRIMARY:
263 ret = hwc_set_primary(ctx, list);
264 case HWC_DISPLAY_EXTERNAL:
265 ret = hwc_set_external(ctx, list);
266 default:
267 ret = -EINVAL;
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700268 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700269 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700270 if(!ctx->overlayInUse)
271 ctx->mOverlay->setState(ovutils::OV_CLOSED);
272
Naseer Ahmed29a26812012-06-14 00:56:20 -0700273 return ret;
274}
275
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700276int hwc_getDisplayConfigs(struct hwc_composer_device_1* dev, int disp,
277 uint32_t* configs, size_t* numConfigs) {
278 int ret = 0;
279 //in 1.1 there is no way to choose a config, report as config id # 0
280 //This config is passed to getDisplayAttributes. Ignore for now.
281 if(*numConfigs == 1)
282 *configs = 0;
283 switch(disp) {
284 case HWC_DISPLAY_PRIMARY:
285 ret = 0;
286 break;
287 case HWC_DISPLAY_EXTERNAL:
288 //Hack until hotplug is supported.
289 //This makes framework ignore external display.
290 ret = -1;
291 break;
292 }
293 return ret;
294}
295
296int hwc_getDisplayAttributes(struct hwc_composer_device_1* dev, int disp,
297 uint32_t config, const uint32_t* attributes, int32_t* values) {
298
299 hwc_context_t* ctx = (hwc_context_t*)(dev);
300 //From HWComposer
301 static const uint32_t DISPLAY_ATTRIBUTES[] = {
302 HWC_DISPLAY_VSYNC_PERIOD,
303 HWC_DISPLAY_WIDTH,
304 HWC_DISPLAY_HEIGHT,
305 HWC_DISPLAY_DPI_X,
306 HWC_DISPLAY_DPI_Y,
307 HWC_DISPLAY_NO_ATTRIBUTE,
308 };
309
310 const int NUM_DISPLAY_ATTRIBUTES = (sizeof(DISPLAY_ATTRIBUTES) /
311 sizeof(DISPLAY_ATTRIBUTES)[0]);
312
313 for (size_t i = 0; i < NUM_DISPLAY_ATTRIBUTES - 1; i++) {
314 switch (attributes[i]) {
315 case HWC_DISPLAY_VSYNC_PERIOD:
316 values[i] = ctx->dpyAttr[disp].vsync_period;
317 break;
318 case HWC_DISPLAY_WIDTH:
319 values[i] = ctx->dpyAttr[disp].xres;
320 ALOGD("%s width = %d",__FUNCTION__, ctx->dpyAttr[disp].xres);
321 break;
322 case HWC_DISPLAY_HEIGHT:
323 values[i] = ctx->dpyAttr[disp].yres;
324 ALOGD("%s height = %d",__FUNCTION__, ctx->dpyAttr[disp].yres);
325 break;
326 case HWC_DISPLAY_DPI_X:
327 values[i] = ctx->dpyAttr[disp].xdpi;
328 break;
329 case HWC_DISPLAY_DPI_Y:
330 values[i] = ctx->dpyAttr[disp].ydpi;
331 break;
332 default:
333 ALOGE("Unknown display attribute %d",
334 attributes[i]);
335 return -EINVAL;
336 }
337 }
338 return 0;
339}
340
Naseer Ahmed29a26812012-06-14 00:56:20 -0700341static int hwc_device_close(struct hw_device_t *dev)
342{
343 if(!dev) {
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700344 ALOGE("%s: NULL device pointer", __FUNCTION__);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700345 return -1;
346 }
347 closeContext((hwc_context_t*)dev);
348 free(dev);
349
350 return 0;
351}
352
353static int hwc_device_open(const struct hw_module_t* module, const char* name,
354 struct hw_device_t** device)
355{
356 int status = -EINVAL;
357
358 if (!strcmp(name, HWC_HARDWARE_COMPOSER)) {
359 struct hwc_context_t *dev;
360 dev = (hwc_context_t*)malloc(sizeof(*dev));
361 memset(dev, 0, sizeof(*dev));
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700362
363 //Initialize hwc context
Naseer Ahmed29a26812012-06-14 00:56:20 -0700364 initContext(dev);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700365
366 //Setup HWC methods
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700367 dev->device.common.tag = HARDWARE_DEVICE_TAG;
368 dev->device.common.version = HWC_DEVICE_API_VERSION_1_1;
369 dev->device.common.module = const_cast<hw_module_t*>(module);
370 dev->device.common.close = hwc_device_close;
371 dev->device.prepare = hwc_prepare;
372 dev->device.set = hwc_set;
373 dev->device.eventControl = hwc_eventControl;
374 dev->device.blank = hwc_blank;
375 dev->device.query = hwc_query;
376 dev->device.registerProcs = hwc_registerProcs;
377 dev->device.dump = NULL;
378 dev->device.getDisplayConfigs = hwc_getDisplayConfigs;
379 dev->device.getDisplayAttributes = hwc_getDisplayAttributes;
380 *device = &dev->device.common;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700381 status = 0;
382 }
383 return status;
384}