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