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 | 96c4c95 | 2012-07-25 18:27:14 -0700 | [diff] [blame] | 27 | #include <mdp_version.h> |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 28 | #include "hwc_utils.h" |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 29 | #include "hwc_qbuf.h" |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 30 | #include "hwc_video.h" |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 31 | #include "hwc_uimirror.h" |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 32 | #include "hwc_copybit.h" |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 33 | #include "hwc_external.h" |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 34 | #include "hwc_mdpcomp.h" |
Naseer Ahmed | 4c588a2 | 2012-07-31 19:12:17 -0700 | [diff] [blame] | 35 | #include "hwc_extonly.h" |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 36 | |
| 37 | using namespace qhwc; |
| 38 | |
| 39 | static int hwc_device_open(const struct hw_module_t* module, |
| 40 | const char* name, |
| 41 | struct hw_device_t** device); |
| 42 | |
| 43 | static struct hw_module_methods_t hwc_module_methods = { |
| 44 | open: hwc_device_open |
| 45 | }; |
| 46 | |
| 47 | hwc_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 Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame^] | 64 | static void hwc_registerProcs(struct hwc_composer_device_1* dev, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 65 | 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 Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame^] | 75 | static int hwc_prepare(hwc_composer_device_1 *dev, size_t numDisplays, |
| 76 | hwc_display_contents_1_t** displays) |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 77 | { |
| 78 | hwc_context_t* ctx = (hwc_context_t*)(dev); |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 79 | ctx->overlayInUse = false; |
| 80 | |
| 81 | //Prepare is called after a vsync, so unlock previous buffers here. |
| 82 | ctx->qbuf->unlockAllPrevious(); |
Ajay Dudani | e217fbf | 2012-07-25 17:46:07 -0700 | [diff] [blame] | 83 | return 0; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 84 | |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame^] | 85 | 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 Ahmed | 4c588a2 | 2012-07-31 19:12:17 -0700 | [diff] [blame] | 93 | |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame^] | 94 | 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 Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 111 | } |
| 112 | } |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 113 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 114 | return 0; |
| 115 | } |
| 116 | |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame^] | 117 | static int hwc_eventControl(struct hwc_composer_device_1* dev, int dpy, |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 118 | 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 Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame^] | 124 | //XXX: Handle dpy |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 125 | switch(event) { |
| 126 | case HWC_EVENT_VSYNC: |
| 127 | if(ioctl(m->framebuffer->fd, MSMFB_OVERLAY_VSYNC_CTRL, &enabled) < 0) |
| 128 | ret = -errno; |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 129 | |
| 130 | if(ctx->mExtDisplay->getExternalDisplay()) { |
| 131 | ret = ctx->mExtDisplay->enableHDMIVsync(enabled); |
| 132 | } |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 133 | break; |
| 134 | default: |
| 135 | ret = -EINVAL; |
| 136 | } |
| 137 | return ret; |
| 138 | } |
| 139 | |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame^] | 140 | static 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 | |
| 151 | static int hwc_query(struct hwc_composer_device_1* dev, |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 152 | 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 Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame^] | 174 | static int hwc_set(hwc_composer_device_1 *dev, |
| 175 | size_t numDisplays, |
| 176 | hwc_display_contents_1_t** displays) |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 177 | { |
| 178 | int ret = 0; |
| 179 | hwc_context_t* ctx = (hwc_context_t*)(dev); |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame^] | 180 | 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 Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 199 | } |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 200 | return ret; |
| 201 | } |
| 202 | |
| 203 | static int hwc_device_close(struct hw_device_t *dev) |
| 204 | { |
| 205 | if(!dev) { |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 206 | ALOGE("%s: NULL device pointer", __FUNCTION__); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 207 | return -1; |
| 208 | } |
| 209 | closeContext((hwc_context_t*)dev); |
| 210 | free(dev); |
| 211 | |
| 212 | return 0; |
| 213 | } |
| 214 | |
| 215 | static 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 Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 224 | |
| 225 | //Initialize hwc context |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 226 | initContext(dev); |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 227 | |
| 228 | //Setup HWC methods |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame^] | 229 | hwc_methods_1_t *methods; |
| 230 | methods = (hwc_methods_1_t *) malloc(sizeof(*methods)); |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 231 | memset(methods, 0, sizeof(*methods)); |
| 232 | methods->eventControl = hwc_eventControl; |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame^] | 233 | methods->blank = hwc_blank; |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 234 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 235 | dev->device.common.tag = HARDWARE_DEVICE_TAG; |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame^] | 236 | dev->device.common.version = HWC_DEVICE_API_VERSION_1_0; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 237 | 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 Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 242 | dev->device.query = hwc_query; |
| 243 | dev->device.methods = methods; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 244 | *device = &dev->device.common; |
| 245 | status = 0; |
| 246 | } |
| 247 | return status; |
| 248 | } |