Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1 | /* |
| 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 Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 23 | #include <EGL/egl.h> |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 24 | |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 25 | #include <overlay.h> |
| 26 | #include <fb_priv.h> |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 27 | #include "hwc_utils.h" |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 28 | #include "hwc_qbuf.h" |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 29 | #include "hwc_video.h" |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 30 | #include "hwc_uimirror.h" |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 31 | #include "hwc_copybit.h" |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 32 | #include "hwc_external.h" |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame^] | 33 | #include "hwc_mdpcomp.h" |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 34 | |
| 35 | using namespace qhwc; |
| 36 | |
| 37 | static int hwc_device_open(const struct hw_module_t* module, |
| 38 | const char* name, |
| 39 | struct hw_device_t** device); |
| 40 | |
| 41 | static struct hw_module_methods_t hwc_module_methods = { |
| 42 | open: hwc_device_open |
| 43 | }; |
| 44 | |
| 45 | hwc_module_t HAL_MODULE_INFO_SYM = { |
| 46 | common: { |
| 47 | tag: HARDWARE_MODULE_TAG, |
| 48 | version_major: 2, |
| 49 | version_minor: 0, |
| 50 | id: HWC_HARDWARE_MODULE_ID, |
| 51 | name: "Qualcomm Hardware Composer Module", |
| 52 | author: "CodeAurora Forum", |
| 53 | methods: &hwc_module_methods, |
| 54 | dso: 0, |
| 55 | reserved: {0}, |
| 56 | } |
| 57 | }; |
| 58 | |
| 59 | /* |
| 60 | * Save callback functions registered to HWC |
| 61 | */ |
| 62 | static void hwc_registerProcs(struct hwc_composer_device* dev, |
| 63 | hwc_procs_t const* procs) |
| 64 | { |
| 65 | hwc_context_t* ctx = (hwc_context_t*)(dev); |
| 66 | if(!ctx) { |
| 67 | ALOGE("%s: Invalid context", __FUNCTION__); |
| 68 | return; |
| 69 | } |
| 70 | ctx->device.reserved_proc[0] = (void*)procs; |
| 71 | } |
| 72 | |
| 73 | static int hwc_prepare(hwc_composer_device_t *dev, hwc_layer_list_t* list) |
| 74 | { |
| 75 | hwc_context_t* ctx = (hwc_context_t*)(dev); |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 76 | ctx->overlayInUse = false; |
| 77 | |
| 78 | //Prepare is called after a vsync, so unlock previous buffers here. |
| 79 | ctx->qbuf->unlockAllPrevious(); |
Ajay Dudani | e217fbf | 2012-07-25 17:46:07 -0700 | [diff] [blame] | 80 | return 0; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 81 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 82 | if (LIKELY(list)) { |
| 83 | getLayerStats(ctx, list); |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 84 | if(VideoOverlay::prepare(ctx, list)) { |
| 85 | ctx->overlayInUse = true; |
| 86 | //Nothing here |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 87 | } else if(UIMirrorOverlay::prepare(ctx, list)) { |
| 88 | ctx->overlayInUse = true; |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame^] | 89 | } else if(MDPComp::configure(dev, list)) { |
| 90 | ctx->overlayInUse = true; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 91 | } else if (0) { |
| 92 | //Other features |
| 93 | ctx->overlayInUse = true; |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 94 | } else { // Else set this flag to false, otherwise video cases |
| 95 | // fail in non-overlay targets. |
| 96 | ctx->overlayInUse = false; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 97 | } |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 98 | CopyBit::prepare(ctx, list); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 99 | } |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 100 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 101 | return 0; |
| 102 | } |
| 103 | |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 104 | static int hwc_eventControl(struct hwc_composer_device* dev, |
| 105 | int event, int enabled) |
| 106 | { |
| 107 | int ret = 0; |
| 108 | hwc_context_t* ctx = (hwc_context_t*)(dev); |
| 109 | private_module_t* m = reinterpret_cast<private_module_t*>( |
| 110 | ctx->mFbDev->common.module); |
| 111 | switch(event) { |
| 112 | case HWC_EVENT_VSYNC: |
| 113 | if(ioctl(m->framebuffer->fd, MSMFB_OVERLAY_VSYNC_CTRL, &enabled) < 0) |
| 114 | ret = -errno; |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 115 | |
| 116 | if(ctx->mExtDisplay->getExternalDisplay()) { |
| 117 | ret = ctx->mExtDisplay->enableHDMIVsync(enabled); |
| 118 | } |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 119 | break; |
| 120 | default: |
| 121 | ret = -EINVAL; |
| 122 | } |
| 123 | return ret; |
| 124 | } |
| 125 | |
| 126 | static int hwc_query(struct hwc_composer_device* dev, |
| 127 | int param, int* value) |
| 128 | { |
| 129 | hwc_context_t* ctx = (hwc_context_t*)(dev); |
| 130 | private_module_t* m = reinterpret_cast<private_module_t*>( |
| 131 | ctx->mFbDev->common.module); |
| 132 | |
| 133 | switch (param) { |
| 134 | case HWC_BACKGROUND_LAYER_SUPPORTED: |
| 135 | // Not supported for now |
| 136 | value[0] = 0; |
| 137 | break; |
| 138 | case HWC_VSYNC_PERIOD: |
| 139 | value[0] = 1000000000.0 / m->fps; |
| 140 | ALOGI("fps: %d", value[0]); |
| 141 | break; |
| 142 | default: |
| 143 | return -EINVAL; |
| 144 | } |
| 145 | return 0; |
| 146 | |
| 147 | } |
| 148 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 149 | static int hwc_set(hwc_composer_device_t *dev, |
| 150 | hwc_display_t dpy, |
| 151 | hwc_surface_t sur, |
| 152 | hwc_layer_list_t* list) |
| 153 | { |
| 154 | int ret = 0; |
| 155 | hwc_context_t* ctx = (hwc_context_t*)(dev); |
| 156 | if (LIKELY(list)) { |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 157 | VideoOverlay::draw(ctx, list); |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 158 | CopyBit::draw(ctx, list, (EGLDisplay)dpy, (EGLSurface)sur); |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame^] | 159 | MDPComp::draw(ctx, list); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 160 | EGLBoolean sucess = eglSwapBuffers((EGLDisplay)dpy, (EGLSurface)sur); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 161 | UIMirrorOverlay::draw(ctx); |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 162 | if(ctx->mExtDisplay->getExternalDisplay()) |
| 163 | ctx->mExtDisplay->commit(); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 164 | } else { |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 165 | ctx->mOverlay->setState(ovutils::OV_CLOSED); |
| 166 | ctx->qbuf->unlockAllPrevious(); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 167 | } |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 168 | |
| 169 | if(!ctx->overlayInUse) |
| 170 | ctx->mOverlay->setState(ovutils::OV_CLOSED); |
| 171 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 172 | return ret; |
| 173 | } |
| 174 | |
| 175 | static int hwc_device_close(struct hw_device_t *dev) |
| 176 | { |
| 177 | if(!dev) { |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 178 | ALOGE("%s: NULL device pointer", __FUNCTION__); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 179 | return -1; |
| 180 | } |
| 181 | closeContext((hwc_context_t*)dev); |
| 182 | free(dev); |
| 183 | |
| 184 | return 0; |
| 185 | } |
| 186 | |
| 187 | static int hwc_device_open(const struct hw_module_t* module, const char* name, |
| 188 | struct hw_device_t** device) |
| 189 | { |
| 190 | int status = -EINVAL; |
| 191 | |
| 192 | if (!strcmp(name, HWC_HARDWARE_COMPOSER)) { |
| 193 | struct hwc_context_t *dev; |
| 194 | dev = (hwc_context_t*)malloc(sizeof(*dev)); |
| 195 | memset(dev, 0, sizeof(*dev)); |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 196 | |
| 197 | //Initialize hwc context |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 198 | initContext(dev); |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 199 | |
| 200 | //Setup HWC methods |
| 201 | hwc_methods_t *methods; |
| 202 | methods = (hwc_methods_t *)malloc(sizeof(*methods)); |
| 203 | memset(methods, 0, sizeof(*methods)); |
| 204 | methods->eventControl = hwc_eventControl; |
| 205 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 206 | dev->device.common.tag = HARDWARE_DEVICE_TAG; |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 207 | dev->device.common.version = HWC_DEVICE_API_VERSION_0_3; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 208 | dev->device.common.module = const_cast<hw_module_t*>(module); |
| 209 | dev->device.common.close = hwc_device_close; |
| 210 | dev->device.prepare = hwc_prepare; |
| 211 | dev->device.set = hwc_set; |
| 212 | dev->device.registerProcs = hwc_registerProcs; |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 213 | dev->device.query = hwc_query; |
| 214 | dev->device.methods = methods; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 215 | *device = &dev->device.common; |
| 216 | status = 0; |
| 217 | } |
| 218 | return status; |
| 219 | } |