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