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