Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame^] | 3 | * Copyright (C) 2012, The Linux Foundation. All rights reserved. |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 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" |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame^] | 33 | #include "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 | } |
Jesse Hall | 3be78d9 | 2012-08-21 15:12:23 -0700 | [diff] [blame] | 72 | ctx->proc = procs; |
| 73 | |
| 74 | // don't start listening for events until we can do something with them |
| 75 | init_uevent_thread(ctx); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 76 | } |
| 77 | |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 78 | static int hwc_prepare(hwc_composer_device_1 *dev, size_t numDisplays, |
| 79 | hwc_display_contents_1_t** displays) |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 80 | { |
| 81 | hwc_context_t* ctx = (hwc_context_t*)(dev); |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 82 | ctx->overlayInUse = false; |
| 83 | |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame^] | 84 | //reset for this draw round |
| 85 | VideoOverlay::reset(); |
| 86 | ExtOnly::reset(); |
| 87 | UIMirrorOverlay::reset(); |
| 88 | |
| 89 | //If securing of h/w in progress skip comp using overlay. |
| 90 | if(ctx->mSecuring == true) return 0; |
| 91 | |
Saurabh Shah | 9171ec6 | 2012-09-13 09:33:51 -0700 | [diff] [blame] | 92 | for (uint32_t i = 0; i < numDisplays; i++) { |
| 93 | hwc_display_contents_1_t *list = displays[i]; |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 94 | //XXX: Actually handle the multiple displays |
Saurabh Shah | 9171ec6 | 2012-09-13 09:33:51 -0700 | [diff] [blame] | 95 | if (LIKELY(list && list->numHwLayers)) { |
| 96 | ctx->dpys[i] = list->dpy; |
Naseer Ahmed | 4c588a2 | 2012-07-31 19:12:17 -0700 | [diff] [blame] | 97 | |
Saurabh Shah | 9171ec6 | 2012-09-13 09:33:51 -0700 | [diff] [blame] | 98 | if(ctx->isPoweredDown) |
| 99 | ALOGW("SF called %s after a POWERDOWN", __FUNCTION__); |
| 100 | |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 101 | getLayerStats(ctx, list); |
| 102 | if(VideoOverlay::prepare(ctx, list)) { |
| 103 | ctx->overlayInUse = true; |
| 104 | //Nothing here |
| 105 | } else if(ExtOnly::prepare(ctx, list)) { |
| 106 | ctx->overlayInUse = true; |
| 107 | } else if(UIMirrorOverlay::prepare(ctx, list)) { |
| 108 | ctx->overlayInUse = true; |
| 109 | } else if(MDPComp::configure(dev, list)) { |
| 110 | ctx->overlayInUse = true; |
| 111 | } else if (0) { |
| 112 | //Other features |
| 113 | ctx->overlayInUse = true; |
| 114 | } else { // Else set this flag to false, otherwise video cases |
| 115 | // fail in non-overlay targets. |
| 116 | ctx->overlayInUse = false; |
| 117 | } |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 118 | } |
| 119 | } |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 120 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 121 | return 0; |
| 122 | } |
| 123 | |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 124 | static int hwc_eventControl(struct hwc_composer_device_1* dev, int dpy, |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 125 | int event, int enabled) |
| 126 | { |
| 127 | int ret = 0; |
| 128 | hwc_context_t* ctx = (hwc_context_t*)(dev); |
| 129 | private_module_t* m = reinterpret_cast<private_module_t*>( |
| 130 | ctx->mFbDev->common.module); |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 131 | //XXX: Handle dpy |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 132 | switch(event) { |
| 133 | case HWC_EVENT_VSYNC: |
| 134 | if(ioctl(m->framebuffer->fd, MSMFB_OVERLAY_VSYNC_CTRL, &enabled) < 0) |
| 135 | ret = -errno; |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 136 | |
| 137 | if(ctx->mExtDisplay->getExternalDisplay()) { |
| 138 | ret = ctx->mExtDisplay->enableHDMIVsync(enabled); |
| 139 | } |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 140 | break; |
| 141 | default: |
| 142 | ret = -EINVAL; |
| 143 | } |
| 144 | return ret; |
| 145 | } |
| 146 | |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 147 | static int hwc_blank(struct hwc_composer_device_1* dev, int dpy, int blank) |
| 148 | { |
| 149 | //XXX: Handle based on dpy |
Naseer Ahmed | 934790c | 2012-08-16 18:11:09 -0700 | [diff] [blame] | 150 | hwc_context_t* ctx = (hwc_context_t*)(dev); |
| 151 | private_module_t* m = reinterpret_cast<private_module_t*>( |
| 152 | ctx->mFbDev->common.module); |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 153 | if(blank) { |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 154 | ctx->mOverlay->setState(ovutils::OV_CLOSED); |
| 155 | ctx->qbuf->unlockAllPrevious(); |
Saurabh Shah | aa537df | 2012-09-12 13:21:11 -0700 | [diff] [blame] | 156 | ALOGD("HWC Calling POWERDOWN ..."); |
Naseer Ahmed | 934790c | 2012-08-16 18:11:09 -0700 | [diff] [blame] | 157 | ioctl(m->framebuffer->fd, FBIOBLANK, FB_BLANK_POWERDOWN); |
Iliyan Malchev | 80692ef | 2012-09-17 23:16:53 -0700 | [diff] [blame] | 158 | ALOGD("HWC Done POWERDOWN ..."); |
Saurabh Shah | aa537df | 2012-09-12 13:21:11 -0700 | [diff] [blame] | 159 | ctx->isPoweredDown = true; |
Naseer Ahmed | 934790c | 2012-08-16 18:11:09 -0700 | [diff] [blame] | 160 | } else { |
Saurabh Shah | aa537df | 2012-09-12 13:21:11 -0700 | [diff] [blame] | 161 | ALOGD("HWC Calling UNBLANK ..."); |
Naseer Ahmed | 934790c | 2012-08-16 18:11:09 -0700 | [diff] [blame] | 162 | ioctl(m->framebuffer->fd, FBIOBLANK, FB_BLANK_UNBLANK); |
Iliyan Malchev | 80692ef | 2012-09-17 23:16:53 -0700 | [diff] [blame] | 163 | ALOGD("HWC Done UNBLANK ..."); |
Saurabh Shah | aa537df | 2012-09-12 13:21:11 -0700 | [diff] [blame] | 164 | ctx->isPoweredDown = false; |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 165 | } |
| 166 | return 0; |
| 167 | } |
| 168 | |
| 169 | static int hwc_query(struct hwc_composer_device_1* dev, |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 170 | int param, int* value) |
| 171 | { |
| 172 | hwc_context_t* ctx = (hwc_context_t*)(dev); |
| 173 | private_module_t* m = reinterpret_cast<private_module_t*>( |
| 174 | ctx->mFbDev->common.module); |
| 175 | |
| 176 | switch (param) { |
| 177 | case HWC_BACKGROUND_LAYER_SUPPORTED: |
| 178 | // Not supported for now |
| 179 | value[0] = 0; |
| 180 | break; |
| 181 | case HWC_VSYNC_PERIOD: |
Saurabh Shah | 2e2798c | 2012-08-30 14:47:10 -0700 | [diff] [blame] | 182 | value[0] = m->fps; |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 183 | ALOGI("fps: %d", value[0]); |
| 184 | break; |
| 185 | default: |
| 186 | return -EINVAL; |
| 187 | } |
| 188 | return 0; |
| 189 | |
| 190 | } |
| 191 | |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 192 | static int hwc_set(hwc_composer_device_1 *dev, |
| 193 | size_t numDisplays, |
| 194 | hwc_display_contents_1_t** displays) |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 195 | { |
| 196 | int ret = 0; |
| 197 | hwc_context_t* ctx = (hwc_context_t*)(dev); |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 198 | for (uint32_t i = 0; i <numDisplays; i++) { |
| 199 | hwc_display_contents_1_t* list = displays[i]; |
| 200 | //XXX: Actually handle the multiple displays |
| 201 | if (LIKELY(list)) { |
| 202 | VideoOverlay::draw(ctx, list); |
| 203 | ExtOnly::draw(ctx, list); |
| 204 | MDPComp::draw(ctx, list); |
| 205 | EGLBoolean success = eglSwapBuffers((EGLDisplay)list->dpy, |
| 206 | (EGLSurface)list->sur); |
Saurabh Shah | fc2acbe | 2012-08-17 19:47:52 -0700 | [diff] [blame] | 207 | wait4fbPost(ctx); |
| 208 | //Can draw to HDMI only when fb_post is reached |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 209 | UIMirrorOverlay::draw(ctx); |
Saurabh Shah | fc2acbe | 2012-08-17 19:47:52 -0700 | [diff] [blame] | 210 | //HDMI commit and primary commit (PAN) happening in parallel |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 211 | if(ctx->mExtDisplay->getExternalDisplay()) |
| 212 | ctx->mExtDisplay->commit(); |
Saurabh Shah | fc2acbe | 2012-08-17 19:47:52 -0700 | [diff] [blame] | 213 | //Virtual barrier for threads to finish |
| 214 | wait4Pan(ctx); |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 215 | } else { |
| 216 | ctx->mOverlay->setState(ovutils::OV_CLOSED); |
Saurabh Shah | 83523d8 | 2012-08-16 10:19:07 -0700 | [diff] [blame] | 217 | ctx->qbuf->unlockAll(); |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | if(!ctx->overlayInUse) |
| 221 | ctx->mOverlay->setState(ovutils::OV_CLOSED); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 222 | } |
Saurabh Shah | df72771 | 2012-08-23 08:41:05 -0700 | [diff] [blame] | 223 | ctx->qbuf->unlockAllPrevious(); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 224 | return ret; |
| 225 | } |
| 226 | |
| 227 | static int hwc_device_close(struct hw_device_t *dev) |
| 228 | { |
| 229 | if(!dev) { |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 230 | ALOGE("%s: NULL device pointer", __FUNCTION__); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 231 | return -1; |
| 232 | } |
| 233 | closeContext((hwc_context_t*)dev); |
| 234 | free(dev); |
| 235 | |
| 236 | return 0; |
| 237 | } |
| 238 | |
| 239 | static int hwc_device_open(const struct hw_module_t* module, const char* name, |
| 240 | struct hw_device_t** device) |
| 241 | { |
| 242 | int status = -EINVAL; |
| 243 | |
| 244 | if (!strcmp(name, HWC_HARDWARE_COMPOSER)) { |
| 245 | struct hwc_context_t *dev; |
| 246 | dev = (hwc_context_t*)malloc(sizeof(*dev)); |
| 247 | memset(dev, 0, sizeof(*dev)); |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 248 | |
| 249 | //Initialize hwc context |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 250 | initContext(dev); |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 251 | |
| 252 | //Setup HWC methods |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 253 | dev->device.common.tag = HARDWARE_DEVICE_TAG; |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 254 | dev->device.common.version = HWC_DEVICE_API_VERSION_1_0; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 255 | dev->device.common.module = const_cast<hw_module_t*>(module); |
| 256 | dev->device.common.close = hwc_device_close; |
| 257 | dev->device.prepare = hwc_prepare; |
| 258 | dev->device.set = hwc_set; |
Jesse Hall | 3be78d9 | 2012-08-21 15:12:23 -0700 | [diff] [blame] | 259 | dev->device.eventControl = hwc_eventControl; |
| 260 | dev->device.blank = hwc_blank; |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 261 | dev->device.query = hwc_query; |
Jesse Hall | 3be78d9 | 2012-08-21 15:12:23 -0700 | [diff] [blame] | 262 | dev->device.registerProcs = hwc_registerProcs; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 263 | *device = &dev->device.common; |
| 264 | status = 0; |
| 265 | } |
| 266 | return status; |
| 267 | } |