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 | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 29 | #include "hwc_video.h" |
Saurabh Shah | 86623d7 | 2012-09-25 19:39:17 -0700 | [diff] [blame] | 30 | #include "hwc_uimirror.h" |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 31 | #include "external.h" |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 32 | #include "hwc_mdpcomp.h" |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 33 | |
Naseer Ahmed | ff4f025 | 2012-10-01 13:03:01 -0400 | [diff] [blame] | 34 | #define VSYNC_DEBUG 0 |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 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 | */ |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 62 | static void hwc_registerProcs(struct hwc_composer_device_1* dev, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 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 | } |
Jesse Hall | 3be78d9 | 2012-08-21 15:12:23 -0700 | [diff] [blame] | 70 | ctx->proc = procs; |
| 71 | |
Naseer Ahmed | ff4f025 | 2012-10-01 13:03:01 -0400 | [diff] [blame] | 72 | // Now that we have the functions needed, kick off |
| 73 | // the uevent & vsync threads |
Jesse Hall | 3be78d9 | 2012-08-21 15:12:23 -0700 | [diff] [blame] | 74 | init_uevent_thread(ctx); |
Naseer Ahmed | ff4f025 | 2012-10-01 13:03:01 -0400 | [diff] [blame] | 75 | init_vsync_thread(ctx); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 76 | } |
| 77 | |
Saurabh Shah | 649cda6 | 2012-09-16 16:05:58 -0700 | [diff] [blame] | 78 | //Helper |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 79 | static void reset(hwc_context_t *ctx, int numDisplays) { |
| 80 | memset(ctx->listStats, 0, sizeof(ctx->listStats)); |
| 81 | for(int i = 0; i < numDisplays; i++){ |
| 82 | ctx->listStats[i].yuvIndex = -1; |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | static int hwc_prepare_primary(hwc_composer_device_1 *dev, |
| 87 | hwc_display_contents_1_t *list) { |
| 88 | hwc_context_t* ctx = (hwc_context_t*)(dev); |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 89 | ctx->overlayInUse[HWC_DISPLAY_PRIMARY] = false; |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 90 | if (LIKELY(list && list->numHwLayers)) { |
Saurabh Shah | 86623d7 | 2012-09-25 19:39:17 -0700 | [diff] [blame] | 91 | uint32_t last = list->numHwLayers - 1; |
| 92 | hwc_layer_1_t *fblayer = &list->hwLayers[last]; |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 93 | setListStats(ctx, list, HWC_DISPLAY_PRIMARY); |
| 94 | if(VideoOverlay::prepare(ctx, list, HWC_DISPLAY_PRIMARY)) { |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 95 | ctx->overlayInUse[HWC_DISPLAY_PRIMARY] = true; |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 96 | } else if(MDPComp::configure(ctx, list)) { |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 97 | ctx->overlayInUse[HWC_DISPLAY_PRIMARY] = true; |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 98 | } else { |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 99 | ctx->overlayInUse[HWC_DISPLAY_PRIMARY] = false; |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 100 | } |
| 101 | } |
| 102 | return 0; |
| 103 | } |
| 104 | |
| 105 | static int hwc_prepare_external(hwc_composer_device_1 *dev, |
| 106 | hwc_display_contents_1_t *list) { |
| 107 | |
| 108 | hwc_context_t* ctx = (hwc_context_t*)(dev); |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 109 | ctx->overlayInUse[HWC_DISPLAY_EXTERNAL] = false; |
| 110 | |
| 111 | if (LIKELY(list && list->numHwLayers) && |
| 112 | ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isActive && |
| 113 | ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected) { |
| 114 | |
| 115 | setListStats(ctx, list, HWC_DISPLAY_EXTERNAL); |
| 116 | |
| 117 | uint32_t last = list->numHwLayers - 1; |
| 118 | hwc_layer_1_t *fblayer = &list->hwLayers[last]; |
| 119 | if(UIMirrorOverlay::prepare(ctx, fblayer)) { |
| 120 | ctx->overlayInUse[HWC_DISPLAY_EXTERNAL] = true; |
| 121 | } |
| 122 | |
| 123 | if(VideoOverlay::prepare(ctx, list, HWC_DISPLAY_EXTERNAL)) { |
| 124 | ctx->overlayInUse[HWC_DISPLAY_EXTERNAL] = true; |
| 125 | } else { |
| 126 | ctx->mOverlay[HWC_DISPLAY_EXTERNAL]->setState(ovutils::OV_UI_MIRROR); |
| 127 | } |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 128 | } |
| 129 | return 0; |
Saurabh Shah | 649cda6 | 2012-09-16 16:05:58 -0700 | [diff] [blame] | 130 | } |
| 131 | |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 132 | static int hwc_prepare(hwc_composer_device_1 *dev, size_t numDisplays, |
| 133 | hwc_display_contents_1_t** displays) |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 134 | { |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 135 | int ret = 0; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 136 | hwc_context_t* ctx = (hwc_context_t*)(dev); |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 137 | |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 138 | reset(ctx, numDisplays); |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 139 | |
| 140 | //If securing of h/w in progress skip comp using overlay. |
| 141 | if(ctx->mSecuring == true) return 0; |
| 142 | |
Saurabh Shah | 9171ec6 | 2012-09-13 09:33:51 -0700 | [diff] [blame] | 143 | for (uint32_t i = 0; i < numDisplays; i++) { |
| 144 | hwc_display_contents_1_t *list = displays[i]; |
Naseer Ahmed | 6282c95 | 2012-09-26 18:33:58 -0400 | [diff] [blame] | 145 | if(list && list->numHwLayers) { |
| 146 | uint32_t last = list->numHwLayers - 1; |
| 147 | if(list->hwLayers[last].handle != NULL) { |
| 148 | switch(i) { |
| 149 | case HWC_DISPLAY_PRIMARY: |
| 150 | ret = hwc_prepare_primary(dev, list); |
| 151 | break; |
| 152 | case HWC_DISPLAY_EXTERNAL: |
| 153 | ret = hwc_prepare_external(dev, list); |
| 154 | break; |
| 155 | default: |
| 156 | ret = -EINVAL; |
| 157 | } |
| 158 | } |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 159 | } |
| 160 | } |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 161 | return ret; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 162 | } |
| 163 | |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 164 | static int hwc_eventControl(struct hwc_composer_device_1* dev, int dpy, |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 165 | int event, int enabled) |
| 166 | { |
| 167 | int ret = 0; |
Naseer Ahmed | ff4f025 | 2012-10-01 13:03:01 -0400 | [diff] [blame] | 168 | static int prev_value; |
| 169 | |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 170 | hwc_context_t* ctx = (hwc_context_t*)(dev); |
| 171 | private_module_t* m = reinterpret_cast<private_module_t*>( |
| 172 | ctx->mFbDev->common.module); |
| 173 | switch(event) { |
| 174 | case HWC_EVENT_VSYNC: |
Omprakash Dhyade | 1ef881c | 2012-10-03 02:26:55 -0700 | [diff] [blame^] | 175 | if (ctx->vstate.enable == enabled) |
| 176 | break; |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 177 | if(ioctl(ctx->dpyAttr[dpy].fd, MSMFB_OVERLAY_VSYNC_CTRL, |
Naseer Ahmed | ff4f025 | 2012-10-01 13:03:01 -0400 | [diff] [blame] | 178 | &enabled) < 0) { |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 179 | ALOGE("%s: vsync control failed. Dpy=%d, enabled=%d : %s", |
Naseer Ahmed | ff4f025 | 2012-10-01 13:03:01 -0400 | [diff] [blame] | 180 | __FUNCTION__, dpy, enabled, strerror(errno)); |
| 181 | |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 182 | ret = -errno; |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 183 | } |
Naseer Ahmed | ff4f025 | 2012-10-01 13:03:01 -0400 | [diff] [blame] | 184 | /* vsync state change logic */ |
| 185 | if (enabled == 1) { |
| 186 | //unblock vsync thread |
| 187 | pthread_mutex_lock(&ctx->vstate.lock); |
| 188 | ctx->vstate.enable = true; |
| 189 | pthread_cond_signal(&ctx->vstate.cond); |
| 190 | pthread_mutex_unlock(&ctx->vstate.lock); |
| 191 | } else if (enabled == 0 && ctx->vstate.enable) { |
| 192 | //vsync thread will block |
| 193 | pthread_mutex_lock(&ctx->vstate.lock); |
| 194 | ctx->vstate.enable = false; |
| 195 | pthread_mutex_unlock(&ctx->vstate.lock); |
| 196 | } |
| 197 | ALOGD_IF (VSYNC_DEBUG, "VSYNC state changed from %s to %s", |
| 198 | (prev_value)?"ENABLED":"DISABLED", (enabled)?"ENABLED":"DISABLED"); |
| 199 | prev_value = enabled; |
| 200 | /* vsync state change logic - end*/ |
| 201 | break; |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 202 | default: |
| 203 | ret = -EINVAL; |
| 204 | } |
| 205 | return ret; |
| 206 | } |
| 207 | |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 208 | static int hwc_blank(struct hwc_composer_device_1* dev, int dpy, int blank) |
| 209 | { |
Naseer Ahmed | 934790c | 2012-08-16 18:11:09 -0700 | [diff] [blame] | 210 | hwc_context_t* ctx = (hwc_context_t*)(dev); |
| 211 | private_module_t* m = reinterpret_cast<private_module_t*>( |
| 212 | ctx->mFbDev->common.module); |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 213 | int ret = 0; |
| 214 | ALOGD("%s: Doing Dpy=%d, blank=%d", __FUNCTION__, dpy, blank); |
| 215 | switch(dpy) { |
| 216 | case HWC_DISPLAY_PRIMARY: |
| 217 | if(blank) { |
Naseer Ahmed | 32ff225 | 2012-09-29 01:41:21 -0400 | [diff] [blame] | 218 | Locker::Autolock _l(ctx->mBlankLock); |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 219 | ctx->mOverlay[dpy]->setState(ovutils::OV_CLOSED); |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 220 | ret = ioctl(m->framebuffer->fd, FBIOBLANK, FB_BLANK_POWERDOWN); |
| 221 | } else { |
| 222 | ret = ioctl(m->framebuffer->fd, FBIOBLANK, FB_BLANK_UNBLANK); |
| 223 | } |
| 224 | break; |
| 225 | case HWC_DISPLAY_EXTERNAL: |
| 226 | if(blank) { |
| 227 | //TODO actual |
| 228 | } else { |
| 229 | } |
| 230 | break; |
| 231 | default: |
| 232 | return -EINVAL; |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 233 | } |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 234 | |
| 235 | if(ret < 0) { |
| 236 | ALOGE("%s: failed. Dpy=%d, blank=%d : %s", |
| 237 | __FUNCTION__, dpy, blank, strerror(errno)); |
| 238 | return ret; |
| 239 | } |
| 240 | ALOGD("%s: Done Dpy=%d, blank=%d", __FUNCTION__, dpy, blank); |
| 241 | ctx->dpyAttr[dpy].isActive = !blank; |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 242 | return 0; |
| 243 | } |
| 244 | |
| 245 | static int hwc_query(struct hwc_composer_device_1* dev, |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 246 | int param, int* value) |
| 247 | { |
| 248 | hwc_context_t* ctx = (hwc_context_t*)(dev); |
| 249 | private_module_t* m = reinterpret_cast<private_module_t*>( |
| 250 | ctx->mFbDev->common.module); |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 251 | int supported = HWC_DISPLAY_PRIMARY_BIT; |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 252 | |
| 253 | switch (param) { |
| 254 | case HWC_BACKGROUND_LAYER_SUPPORTED: |
| 255 | // Not supported for now |
| 256 | value[0] = 0; |
| 257 | break; |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 258 | case HWC_VSYNC_PERIOD: //Not used for hwc > 1.1 |
Saurabh Shah | 2e2798c | 2012-08-30 14:47:10 -0700 | [diff] [blame] | 259 | value[0] = m->fps; |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 260 | ALOGI("fps: %d", value[0]); |
| 261 | break; |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 262 | case HWC_DISPLAY_TYPES_SUPPORTED: |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 263 | if(ctx->mMDP.hasOverlay) |
| 264 | supported |= HWC_DISPLAY_EXTERNAL_BIT; |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 265 | value[0] = supported; |
| 266 | break; |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 267 | default: |
| 268 | return -EINVAL; |
| 269 | } |
| 270 | return 0; |
| 271 | |
| 272 | } |
| 273 | |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 274 | static int hwc_set_primary(hwc_context_t *ctx, hwc_display_contents_1_t* list) { |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 275 | if(!ctx->overlayInUse[HWC_DISPLAY_PRIMARY]) |
| 276 | ctx->mOverlay[HWC_DISPLAY_PRIMARY]->setState(ovutils::OV_CLOSED); |
| 277 | |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 278 | if (LIKELY(list && list->numHwLayers)) { |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 279 | uint32_t last = list->numHwLayers - 1; |
| 280 | hwc_layer_1_t *fbLayer = &list->hwLayers[last]; |
| 281 | |
Saurabh Shah | 8c8bfd2 | 2012-09-26 21:09:40 -0700 | [diff] [blame] | 282 | hwc_sync(ctx, list, HWC_DISPLAY_PRIMARY); |
| 283 | |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 284 | VideoOverlay::draw(ctx, list, HWC_DISPLAY_PRIMARY); |
| 285 | MDPComp::draw(ctx, list); |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 286 | |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 287 | //TODO We dont check for SKIP flag on this layer because we need PAN |
| 288 | //always. Last layer is always FB |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 289 | if(list->hwLayers[last].compositionType == HWC_FRAMEBUFFER_TARGET) { |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 290 | ctx->mFbDev->post(ctx->mFbDev, fbLayer->handle); |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 291 | } |
| 292 | } |
| 293 | return 0; |
| 294 | } |
| 295 | |
| 296 | static int hwc_set_external(hwc_context_t *ctx, |
| 297 | hwc_display_contents_1_t* list) { |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 298 | |
| 299 | if(!ctx->overlayInUse[HWC_DISPLAY_EXTERNAL]) |
| 300 | ctx->mOverlay[HWC_DISPLAY_EXTERNAL]->setState(ovutils::OV_CLOSED); |
| 301 | |
| 302 | if (LIKELY(list && list->numHwLayers) && |
| 303 | ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isActive && |
| 304 | ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected) { |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 305 | uint32_t last = list->numHwLayers - 1; |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 306 | hwc_layer_1_t *fbLayer = &list->hwLayers[last]; |
| 307 | |
| 308 | hwc_sync(ctx, list, HWC_DISPLAY_EXTERNAL); |
| 309 | |
| 310 | VideoOverlay::draw(ctx, list, HWC_DISPLAY_EXTERNAL); |
| 311 | |
| 312 | private_handle_t *hnd = (private_handle_t *)fbLayer->handle; |
| 313 | if(fbLayer->compositionType == HWC_FRAMEBUFFER_TARGET && hnd) { |
| 314 | UIMirrorOverlay::draw(ctx, fbLayer); |
| 315 | ctx->mExtDisplay->post(); |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 316 | } |
| 317 | } |
| 318 | return 0; |
| 319 | } |
| 320 | |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 321 | static bool isGpuUsed(hwc_context_t *ctx, |
| 322 | size_t numDisplays, |
| 323 | hwc_display_contents_1_t** displays) |
| 324 | { |
| 325 | bool isUsed = false; |
| 326 | for (uint32_t i = 0; i < numDisplays; i++) { |
| 327 | hwc_display_contents_1_t* list = displays[i]; |
| 328 | if (list && list->numHwLayers) { |
| 329 | uint32_t last = list->numHwLayers - 1; |
| 330 | hwc_layer_1_t *fbLayer = &list->hwLayers[last]; |
| 331 | if(!(fbLayer->flags & HWC_SKIP_LAYER)) { |
| 332 | isUsed = true; |
| 333 | break; |
| 334 | } |
| 335 | |
| 336 | } |
| 337 | } |
| 338 | return isUsed; |
| 339 | } |
| 340 | |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 341 | static int hwc_set(hwc_composer_device_1 *dev, |
| 342 | size_t numDisplays, |
| 343 | hwc_display_contents_1_t** displays) |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 344 | { |
| 345 | int ret = 0; |
| 346 | hwc_context_t* ctx = (hwc_context_t*)(dev); |
Naseer Ahmed | 32ff225 | 2012-09-29 01:41:21 -0400 | [diff] [blame] | 347 | Locker::Autolock _l(ctx->mBlankLock); |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 348 | |
| 349 | if(isGpuUsed(ctx, numDisplays, displays)) { |
| 350 | //Call glFinish, only if gpu is used |
| 351 | ctx->mFbDev->compositionComplete(ctx->mFbDev); |
| 352 | } |
Naseer Ahmed | aee5e6e | 2012-09-27 13:17:59 -0400 | [diff] [blame] | 353 | |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 354 | for (uint32_t i = 0; i < numDisplays; i++) { |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 355 | hwc_display_contents_1_t* list = displays[i]; |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 356 | switch(i) { |
| 357 | case HWC_DISPLAY_PRIMARY: |
| 358 | ret = hwc_set_primary(ctx, list); |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 359 | break; |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 360 | case HWC_DISPLAY_EXTERNAL: |
| 361 | ret = hwc_set_external(ctx, list); |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 362 | break; |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 363 | default: |
| 364 | ret = -EINVAL; |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 365 | } |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 366 | } |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 367 | return ret; |
| 368 | } |
| 369 | |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 370 | int hwc_getDisplayConfigs(struct hwc_composer_device_1* dev, int disp, |
| 371 | uint32_t* configs, size_t* numConfigs) { |
| 372 | int ret = 0; |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 373 | hwc_context_t* ctx = (hwc_context_t*)(dev); |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 374 | //in 1.1 there is no way to choose a config, report as config id # 0 |
| 375 | //This config is passed to getDisplayAttributes. Ignore for now. |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 376 | switch(disp) { |
| 377 | case HWC_DISPLAY_PRIMARY: |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 378 | if(*numConfigs > 0) { |
| 379 | configs[0] = 0; |
| 380 | *numConfigs = 1; |
| 381 | } |
| 382 | ret = 0; //NO_ERROR |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 383 | break; |
| 384 | case HWC_DISPLAY_EXTERNAL: |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 385 | ret = -1; //Not connected |
| 386 | if(ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected) { |
| 387 | ret = 0; //NO_ERROR |
| 388 | if(*numConfigs > 0) { |
| 389 | configs[0] = 0; |
| 390 | *numConfigs = 1; |
| 391 | } |
| 392 | } |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 393 | break; |
| 394 | } |
| 395 | return ret; |
| 396 | } |
| 397 | |
| 398 | int hwc_getDisplayAttributes(struct hwc_composer_device_1* dev, int disp, |
| 399 | uint32_t config, const uint32_t* attributes, int32_t* values) { |
| 400 | |
| 401 | hwc_context_t* ctx = (hwc_context_t*)(dev); |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 402 | //If hotpluggable displays are inactive return error |
| 403 | if(disp == HWC_DISPLAY_EXTERNAL && !ctx->dpyAttr[disp].connected) { |
| 404 | return -1; |
| 405 | } |
| 406 | |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 407 | //From HWComposer |
| 408 | static const uint32_t DISPLAY_ATTRIBUTES[] = { |
| 409 | HWC_DISPLAY_VSYNC_PERIOD, |
| 410 | HWC_DISPLAY_WIDTH, |
| 411 | HWC_DISPLAY_HEIGHT, |
| 412 | HWC_DISPLAY_DPI_X, |
| 413 | HWC_DISPLAY_DPI_Y, |
| 414 | HWC_DISPLAY_NO_ATTRIBUTE, |
| 415 | }; |
| 416 | |
| 417 | const int NUM_DISPLAY_ATTRIBUTES = (sizeof(DISPLAY_ATTRIBUTES) / |
| 418 | sizeof(DISPLAY_ATTRIBUTES)[0]); |
| 419 | |
| 420 | for (size_t i = 0; i < NUM_DISPLAY_ATTRIBUTES - 1; i++) { |
| 421 | switch (attributes[i]) { |
| 422 | case HWC_DISPLAY_VSYNC_PERIOD: |
| 423 | values[i] = ctx->dpyAttr[disp].vsync_period; |
| 424 | break; |
| 425 | case HWC_DISPLAY_WIDTH: |
| 426 | values[i] = ctx->dpyAttr[disp].xres; |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 427 | ALOGD("%s disp = %d, width = %d",__FUNCTION__, disp, |
| 428 | ctx->dpyAttr[disp].xres); |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 429 | break; |
| 430 | case HWC_DISPLAY_HEIGHT: |
| 431 | values[i] = ctx->dpyAttr[disp].yres; |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 432 | ALOGD("%s disp = %d, height = %d",__FUNCTION__, disp, |
| 433 | ctx->dpyAttr[disp].yres); |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 434 | break; |
| 435 | case HWC_DISPLAY_DPI_X: |
Naseer Ahmed | 7b80d9c | 2012-09-26 20:14:38 -0400 | [diff] [blame] | 436 | values[i] = (int32_t) (ctx->dpyAttr[disp].xdpi*1000.0); |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 437 | break; |
| 438 | case HWC_DISPLAY_DPI_Y: |
Naseer Ahmed | 7b80d9c | 2012-09-26 20:14:38 -0400 | [diff] [blame] | 439 | values[i] = (int32_t) (ctx->dpyAttr[disp].ydpi*1000.0); |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 440 | break; |
| 441 | default: |
| 442 | ALOGE("Unknown display attribute %d", |
| 443 | attributes[i]); |
| 444 | return -EINVAL; |
| 445 | } |
| 446 | } |
| 447 | return 0; |
| 448 | } |
| 449 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 450 | static int hwc_device_close(struct hw_device_t *dev) |
| 451 | { |
| 452 | if(!dev) { |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 453 | ALOGE("%s: NULL device pointer", __FUNCTION__); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 454 | return -1; |
| 455 | } |
| 456 | closeContext((hwc_context_t*)dev); |
| 457 | free(dev); |
| 458 | |
| 459 | return 0; |
| 460 | } |
| 461 | |
| 462 | static int hwc_device_open(const struct hw_module_t* module, const char* name, |
| 463 | struct hw_device_t** device) |
| 464 | { |
| 465 | int status = -EINVAL; |
| 466 | |
| 467 | if (!strcmp(name, HWC_HARDWARE_COMPOSER)) { |
| 468 | struct hwc_context_t *dev; |
| 469 | dev = (hwc_context_t*)malloc(sizeof(*dev)); |
| 470 | memset(dev, 0, sizeof(*dev)); |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 471 | |
| 472 | //Initialize hwc context |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 473 | initContext(dev); |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 474 | |
| 475 | //Setup HWC methods |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 476 | dev->device.common.tag = HARDWARE_DEVICE_TAG; |
| 477 | dev->device.common.version = HWC_DEVICE_API_VERSION_1_1; |
| 478 | dev->device.common.module = const_cast<hw_module_t*>(module); |
| 479 | dev->device.common.close = hwc_device_close; |
| 480 | dev->device.prepare = hwc_prepare; |
| 481 | dev->device.set = hwc_set; |
| 482 | dev->device.eventControl = hwc_eventControl; |
| 483 | dev->device.blank = hwc_blank; |
| 484 | dev->device.query = hwc_query; |
| 485 | dev->device.registerProcs = hwc_registerProcs; |
| 486 | dev->device.dump = NULL; |
| 487 | dev->device.getDisplayConfigs = hwc_getDisplayConfigs; |
| 488 | dev->device.getDisplayAttributes = hwc_getDisplayAttributes; |
| 489 | *device = &dev->device.common; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 490 | status = 0; |
| 491 | } |
| 492 | return status; |
| 493 | } |