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