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