Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
Arun Kumar K.R | ba9eed5 | 2013-01-04 00:51:29 -0800 | [diff] [blame] | 3 | * Copyright (C) 2012-2013, The Linux Foundation. All rights reserved. |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 4 | * |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 5 | * Not a Contribution, Apache license notifications and license are retained |
| 6 | * for attribution purposes only. |
| 7 | * |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 8 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 | * you may not use this file except in compliance with the License. |
| 10 | * You may obtain a copy of the License at |
| 11 | * |
| 12 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | * |
| 14 | * Unless required by applicable law or agreed to in writing, software |
| 15 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | * See the License for the specific language governing permissions and |
| 18 | * limitations under the License. |
| 19 | */ |
| 20 | |
| 21 | #include <fcntl.h> |
| 22 | #include <errno.h> |
| 23 | |
| 24 | #include <cutils/log.h> |
| 25 | #include <cutils/atomic.h> |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 26 | #include <EGL/egl.h> |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 27 | |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 28 | #include <overlay.h> |
| 29 | #include <fb_priv.h> |
Naseer Ahmed | 96c4c95 | 2012-07-25 18:27:14 -0700 | [diff] [blame] | 30 | #include <mdp_version.h> |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 31 | #include "hwc_utils.h" |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 32 | #include "hwc_video.h" |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 33 | #include "hwc_fbupdate.h" |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 34 | #include "hwc_mdpcomp.h" |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 35 | #include "external.h" |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 36 | #include "hwc_copybit.h" |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 37 | |
| 38 | using namespace qhwc; |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 39 | #define VSYNC_DEBUG 0 |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 40 | |
| 41 | static int hwc_device_open(const struct hw_module_t* module, |
| 42 | const char* name, |
| 43 | struct hw_device_t** device); |
| 44 | |
| 45 | static struct hw_module_methods_t hwc_module_methods = { |
| 46 | open: hwc_device_open |
| 47 | }; |
| 48 | |
| 49 | hwc_module_t HAL_MODULE_INFO_SYM = { |
| 50 | common: { |
| 51 | tag: HARDWARE_MODULE_TAG, |
| 52 | version_major: 2, |
| 53 | version_minor: 0, |
| 54 | id: HWC_HARDWARE_MODULE_ID, |
| 55 | name: "Qualcomm Hardware Composer Module", |
| 56 | author: "CodeAurora Forum", |
| 57 | methods: &hwc_module_methods, |
| 58 | dso: 0, |
| 59 | reserved: {0}, |
| 60 | } |
| 61 | }; |
| 62 | |
| 63 | /* |
| 64 | * Save callback functions registered to HWC |
| 65 | */ |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 66 | static void hwc_registerProcs(struct hwc_composer_device_1* dev, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 67 | hwc_procs_t const* procs) |
| 68 | { |
Iliyan Malchev | 0f9c397 | 2012-10-11 15:16:15 -0700 | [diff] [blame] | 69 | ALOGI("%s", __FUNCTION__); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 70 | hwc_context_t* ctx = (hwc_context_t*)(dev); |
| 71 | if(!ctx) { |
| 72 | ALOGE("%s: Invalid context", __FUNCTION__); |
| 73 | return; |
| 74 | } |
Jesse Hall | 3be78d9 | 2012-08-21 15:12:23 -0700 | [diff] [blame] | 75 | ctx->proc = procs; |
| 76 | |
Naseer Ahmed | ff4f025 | 2012-10-01 13:03:01 -0400 | [diff] [blame] | 77 | // Now that we have the functions needed, kick off |
| 78 | // the uevent & vsync threads |
Jesse Hall | 3be78d9 | 2012-08-21 15:12:23 -0700 | [diff] [blame] | 79 | init_uevent_thread(ctx); |
Naseer Ahmed | ff4f025 | 2012-10-01 13:03:01 -0400 | [diff] [blame] | 80 | init_vsync_thread(ctx); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 81 | } |
| 82 | |
Saurabh Shah | 649cda6 | 2012-09-16 16:05:58 -0700 | [diff] [blame] | 83 | //Helper |
Naseer Ahmed | b1c7632 | 2012-10-17 00:32:50 -0400 | [diff] [blame] | 84 | static void reset(hwc_context_t *ctx, int numDisplays, |
| 85 | hwc_display_contents_1_t** displays) { |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 86 | memset(ctx->listStats, 0, sizeof(ctx->listStats)); |
Saurabh Shah | 1a8cda0 | 2012-10-12 17:00:39 -0700 | [diff] [blame] | 87 | for(int i = 0; i < HWC_NUM_DISPLAY_TYPES; i++){ |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 88 | ctx->listStats[i].yuvIndex = -1; |
Naseer Ahmed | b1c7632 | 2012-10-17 00:32:50 -0400 | [diff] [blame] | 89 | hwc_display_contents_1_t *list = displays[i]; |
| 90 | // XXX:SurfaceFlinger no longer guarantees that this |
| 91 | // value is reset on every prepare. However, for the layer |
| 92 | // cache we need to reset it. |
| 93 | // We can probably rethink that later on |
| 94 | if (LIKELY(list && list->numHwLayers > 1)) { |
| 95 | for(uint32_t j = 0; j < list->numHwLayers; j++) { |
| 96 | if(list->hwLayers[j].compositionType != HWC_FRAMEBUFFER_TARGET) |
| 97 | list->hwLayers[j].compositionType = HWC_FRAMEBUFFER; |
| 98 | } |
| 99 | } |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 100 | |
| 101 | if(ctx->mFBUpdate[i]) |
| 102 | ctx->mFBUpdate[i]->reset(); |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 103 | |
| 104 | if(ctx->mCopyBit[i]) |
| 105 | ctx->mCopyBit[i]->reset(); |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 106 | } |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 107 | VideoOverlay::reset(); |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 108 | } |
| 109 | |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 110 | //clear prev layer prop flags and realloc for current frame |
| 111 | static void reset_layer_prop(hwc_context_t* ctx, int dpy) { |
| 112 | int layer_count = ctx->listStats[dpy].numAppLayers; |
| 113 | |
| 114 | if(ctx->layerProp[dpy]) { |
| 115 | delete[] ctx->layerProp[dpy]; |
| 116 | ctx->layerProp[dpy] = NULL; |
| 117 | } |
| 118 | |
| 119 | if(layer_count) { |
| 120 | ctx->layerProp[dpy] = new LayerProp[layer_count]; |
| 121 | } |
| 122 | } |
| 123 | |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 124 | static int hwc_prepare_primary(hwc_composer_device_1 *dev, |
| 125 | hwc_display_contents_1_t *list) { |
| 126 | hwc_context_t* ctx = (hwc_context_t*)(dev); |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 127 | const int dpy = HWC_DISPLAY_PRIMARY; |
Saurabh Shah | 1a8cda0 | 2012-10-12 17:00:39 -0700 | [diff] [blame] | 128 | |
| 129 | if (LIKELY(list && list->numHwLayers > 1) && |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 130 | ctx->dpyAttr[dpy].isActive) { |
Saurabh Shah | 1a8cda0 | 2012-10-12 17:00:39 -0700 | [diff] [blame] | 131 | |
Saurabh Shah | 86623d7 | 2012-09-25 19:39:17 -0700 | [diff] [blame] | 132 | uint32_t last = list->numHwLayers - 1; |
Saurabh Shah | 1a8cda0 | 2012-10-12 17:00:39 -0700 | [diff] [blame] | 133 | hwc_layer_1_t *fbLayer = &list->hwLayers[last]; |
| 134 | if(fbLayer->handle) { |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 135 | setListStats(ctx, list, dpy); |
| 136 | reset_layer_prop(ctx, dpy); |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 137 | int ret = ctx->mMDPComp->prepare(ctx, list); |
| 138 | if(!ret) { |
| 139 | // IF MDPcomp fails use this route |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 140 | VideoOverlay::prepare(ctx, list, dpy); |
| 141 | ctx->mFBUpdate[dpy]->prepare(ctx, fbLayer); |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 142 | } |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 143 | ctx->mLayerCache[dpy]->updateLayerCache(list); |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 144 | // Use Copybit, when MDP comp fails |
| 145 | if(!ret && ctx->mCopyBit[dpy]) |
| 146 | ctx->mCopyBit[dpy]->prepare(ctx, list, dpy); |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 147 | } |
| 148 | } |
| 149 | return 0; |
| 150 | } |
| 151 | |
| 152 | static int hwc_prepare_external(hwc_composer_device_1 *dev, |
| 153 | hwc_display_contents_1_t *list) { |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 154 | hwc_context_t* ctx = (hwc_context_t*)(dev); |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 155 | const int dpy = HWC_DISPLAY_EXTERNAL; |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 156 | |
Saurabh Shah | ae823e7 | 2012-10-05 00:08:11 -0400 | [diff] [blame] | 157 | if (LIKELY(list && list->numHwLayers > 1) && |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 158 | ctx->dpyAttr[dpy].isActive && |
| 159 | ctx->dpyAttr[dpy].connected) { |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 160 | |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 161 | uint32_t last = list->numHwLayers - 1; |
Saurabh Shah | 1a8cda0 | 2012-10-12 17:00:39 -0700 | [diff] [blame] | 162 | hwc_layer_1_t *fbLayer = &list->hwLayers[last]; |
| 163 | if(fbLayer->handle) { |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 164 | setListStats(ctx, list, dpy); |
| 165 | reset_layer_prop(ctx, dpy); |
| 166 | VideoOverlay::prepare(ctx, list, dpy); |
| 167 | ctx->mFBUpdate[dpy]->prepare(ctx, fbLayer); |
| 168 | ctx->mLayerCache[dpy]->updateLayerCache(list); |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 169 | if(ctx->mCopyBit[dpy]) |
| 170 | ctx->mCopyBit[dpy]->prepare(ctx, list, dpy); |
Amara Venkata Mastan Manoj Kumar | 75526f5 | 2012-12-27 18:27:01 -0800 | [diff] [blame] | 171 | ctx->mExtDispConfiguring = false; |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 172 | } |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 173 | } |
| 174 | return 0; |
Saurabh Shah | 649cda6 | 2012-09-16 16:05:58 -0700 | [diff] [blame] | 175 | } |
| 176 | |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 177 | static int hwc_prepare(hwc_composer_device_1 *dev, size_t numDisplays, |
| 178 | hwc_display_contents_1_t** displays) |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 179 | { |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 180 | int ret = 0; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 181 | hwc_context_t* ctx = (hwc_context_t*)(dev); |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 182 | Locker::Autolock _l(ctx->mBlankLock); |
Naseer Ahmed | b1c7632 | 2012-10-17 00:32:50 -0400 | [diff] [blame] | 183 | reset(ctx, numDisplays, displays); |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 184 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 185 | ctx->mOverlay->configBegin(); |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 186 | |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 187 | for (int32_t i = numDisplays - 1; i >= 0; i--) { |
| 188 | hwc_display_contents_1_t *list = displays[i]; |
| 189 | switch(i) { |
| 190 | case HWC_DISPLAY_PRIMARY: |
| 191 | ret = hwc_prepare_primary(dev, list); |
| 192 | break; |
| 193 | case HWC_DISPLAY_EXTERNAL: |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 194 | ret = hwc_prepare_external(dev, list); |
| 195 | break; |
| 196 | default: |
| 197 | ret = -EINVAL; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 198 | } |
| 199 | } |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 200 | |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 201 | ctx->mOverlay->configDone(); |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 202 | return ret; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 203 | } |
| 204 | |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 205 | static int hwc_eventControl(struct hwc_composer_device_1* dev, int dpy, |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 206 | int event, int enabled) |
| 207 | { |
| 208 | int ret = 0; |
Naseer Ahmed | ff4f025 | 2012-10-01 13:03:01 -0400 | [diff] [blame] | 209 | |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 210 | hwc_context_t* ctx = (hwc_context_t*)(dev); |
| 211 | private_module_t* m = reinterpret_cast<private_module_t*>( |
| 212 | ctx->mFbDev->common.module); |
Iliyan Malchev | eac8965 | 2012-10-04 10:38:28 -0700 | [diff] [blame] | 213 | pthread_mutex_lock(&ctx->vstate.lock); |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 214 | switch(event) { |
| 215 | case HWC_EVENT_VSYNC: |
Omprakash Dhyade | 1ef881c | 2012-10-03 02:26:55 -0700 | [diff] [blame] | 216 | if (ctx->vstate.enable == enabled) |
| 217 | break; |
Iliyan Malchev | eac8965 | 2012-10-04 10:38:28 -0700 | [diff] [blame] | 218 | ctx->vstate.enable = !!enabled; |
Naseer Ahmed | c7faa70 | 2012-10-04 15:10:30 -0400 | [diff] [blame] | 219 | pthread_cond_signal(&ctx->vstate.cond); |
Iliyan Malchev | eac8965 | 2012-10-04 10:38:28 -0700 | [diff] [blame] | 220 | ALOGD_IF (VSYNC_DEBUG, "VSYNC state changed to %s", |
| 221 | (enabled)?"ENABLED":"DISABLED"); |
| 222 | break; |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 223 | default: |
| 224 | ret = -EINVAL; |
| 225 | } |
Iliyan Malchev | eac8965 | 2012-10-04 10:38:28 -0700 | [diff] [blame] | 226 | pthread_mutex_unlock(&ctx->vstate.lock); |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 227 | return ret; |
| 228 | } |
| 229 | |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 230 | static int hwc_blank(struct hwc_composer_device_1* dev, int dpy, int blank) |
| 231 | { |
Naseer Ahmed | 934790c | 2012-08-16 18:11:09 -0700 | [diff] [blame] | 232 | hwc_context_t* ctx = (hwc_context_t*)(dev); |
| 233 | private_module_t* m = reinterpret_cast<private_module_t*>( |
| 234 | ctx->mFbDev->common.module); |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 235 | Locker::Autolock _l(ctx->mBlankLock); |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 236 | int ret = 0; |
| 237 | ALOGD("%s: Doing Dpy=%d, blank=%d", __FUNCTION__, dpy, blank); |
| 238 | switch(dpy) { |
| 239 | case HWC_DISPLAY_PRIMARY: |
| 240 | if(blank) { |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 241 | ctx->mOverlay->configBegin(); |
| 242 | ctx->mOverlay->configDone(); |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 243 | ret = ioctl(m->framebuffer->fd, FBIOBLANK, FB_BLANK_POWERDOWN); |
| 244 | } else { |
| 245 | ret = ioctl(m->framebuffer->fd, FBIOBLANK, FB_BLANK_UNBLANK); |
| 246 | } |
| 247 | break; |
| 248 | case HWC_DISPLAY_EXTERNAL: |
| 249 | if(blank) { |
Arun Kumar K.R | ba9eed5 | 2013-01-04 00:51:29 -0800 | [diff] [blame] | 250 | // External Display post commits the changes to display |
| 251 | // Call this on blank, so that any pipe unsets gets committed |
| 252 | if (!ctx->mExtDisplay->post()) { |
| 253 | ret = -1; |
| 254 | ALOGE("%s:ctx->mExtDisplay->post fail!! ", __FUNCTION__); |
| 255 | } |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 256 | } else { |
| 257 | } |
| 258 | break; |
| 259 | default: |
| 260 | return -EINVAL; |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 261 | } |
Arun Kumar K.R | f6f49a1 | 2012-11-27 11:46:50 -0800 | [diff] [blame] | 262 | // Enable HPD here, as during bootup unblank is called |
| 263 | // when SF is completely initialized |
| 264 | ctx->mExtDisplay->setHPD(1); |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 265 | |
| 266 | if(ret < 0) { |
| 267 | ALOGE("%s: failed. Dpy=%d, blank=%d : %s", |
| 268 | __FUNCTION__, dpy, blank, strerror(errno)); |
| 269 | return ret; |
| 270 | } |
| 271 | ALOGD("%s: Done Dpy=%d, blank=%d", __FUNCTION__, dpy, blank); |
| 272 | ctx->dpyAttr[dpy].isActive = !blank; |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 273 | return 0; |
| 274 | } |
| 275 | |
| 276 | static int hwc_query(struct hwc_composer_device_1* dev, |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 277 | int param, int* value) |
| 278 | { |
| 279 | hwc_context_t* ctx = (hwc_context_t*)(dev); |
| 280 | private_module_t* m = reinterpret_cast<private_module_t*>( |
| 281 | ctx->mFbDev->common.module); |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 282 | int supported = HWC_DISPLAY_PRIMARY_BIT; |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 283 | |
| 284 | switch (param) { |
| 285 | case HWC_BACKGROUND_LAYER_SUPPORTED: |
| 286 | // Not supported for now |
| 287 | value[0] = 0; |
| 288 | break; |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 289 | case HWC_VSYNC_PERIOD: //Not used for hwc > 1.1 |
Saurabh Shah | 2e2798c | 2012-08-30 14:47:10 -0700 | [diff] [blame] | 290 | value[0] = m->fps; |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 291 | ALOGI("fps: %d", value[0]); |
| 292 | break; |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 293 | case HWC_DISPLAY_TYPES_SUPPORTED: |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 294 | if(ctx->mMDP.hasOverlay) |
| 295 | supported |= HWC_DISPLAY_EXTERNAL_BIT; |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 296 | value[0] = supported; |
| 297 | break; |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 298 | default: |
| 299 | return -EINVAL; |
| 300 | } |
| 301 | return 0; |
| 302 | |
| 303 | } |
| 304 | |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 305 | 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] | 306 | int ret = 0; |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 307 | const int dpy = HWC_DISPLAY_PRIMARY; |
Saurabh Shah | eaf6791 | 2012-10-10 17:33:14 -0700 | [diff] [blame] | 308 | |
Saurabh Shah | ae823e7 | 2012-10-05 00:08:11 -0400 | [diff] [blame] | 309 | if (LIKELY(list && list->numHwLayers > 1) && |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 310 | ctx->dpyAttr[dpy].isActive) { |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 311 | uint32_t last = list->numHwLayers - 1; |
| 312 | hwc_layer_1_t *fbLayer = &list->hwLayers[last]; |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 313 | int fd = -1; //FenceFD from the Copybit(valid in async mode) |
| 314 | if(ctx->mCopyBit[dpy]) |
| 315 | ctx->mCopyBit[dpy]->draw(ctx, list, dpy, &fd); |
| 316 | hwc_sync(ctx, list, dpy, fd); |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 317 | if (!VideoOverlay::draw(ctx, list, dpy)) { |
Saurabh Shah | eaf6791 | 2012-10-10 17:33:14 -0700 | [diff] [blame] | 318 | ALOGE("%s: VideoOverlay::draw fail!", __FUNCTION__); |
| 319 | ret = -1; |
| 320 | } |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 321 | if (!ctx->mMDPComp->draw(ctx, list)) { |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 322 | ALOGE("%s: MDPComp::draw fail!", __FUNCTION__); |
| 323 | ret = -1; |
| 324 | } |
| 325 | |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 326 | //TODO We dont check for SKIP flag on this layer because we need PAN |
| 327 | //always. Last layer is always FB |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 328 | private_handle_t *hnd = (private_handle_t *)fbLayer->handle; |
| 329 | if(fbLayer->compositionType == HWC_FRAMEBUFFER_TARGET && hnd) { |
| 330 | if(!(fbLayer->flags & HWC_SKIP_LAYER)) { |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 331 | if (!ctx->mFBUpdate[dpy]->draw(ctx, fbLayer)) { |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 332 | ALOGE("%s: FBUpdate::draw fail!", __FUNCTION__); |
| 333 | ret = -1; |
| 334 | } |
| 335 | } |
Saurabh Shah | eaf6791 | 2012-10-10 17:33:14 -0700 | [diff] [blame] | 336 | if (ctx->mFbDev->post(ctx->mFbDev, fbLayer->handle)) { |
| 337 | ALOGE("%s: ctx->mFbDev->post fail!", __FUNCTION__); |
| 338 | return -1; |
| 339 | } |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 340 | } |
| 341 | } |
Saurabh Shah | eaf6791 | 2012-10-10 17:33:14 -0700 | [diff] [blame] | 342 | return ret; |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | static int hwc_set_external(hwc_context_t *ctx, |
| 346 | hwc_display_contents_1_t* list) { |
Saurabh Shah | eaf6791 | 2012-10-10 17:33:14 -0700 | [diff] [blame] | 347 | int ret = 0; |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 348 | const int dpy = HWC_DISPLAY_EXTERNAL; |
| 349 | |
Kinjal Bhavsar | f83d448 | 2012-10-10 15:56:21 -0700 | [diff] [blame] | 350 | Locker::Autolock _l(ctx->mExtSetLock); |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 351 | |
Saurabh Shah | ae823e7 | 2012-10-05 00:08:11 -0400 | [diff] [blame] | 352 | if (LIKELY(list && list->numHwLayers > 1) && |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 353 | ctx->dpyAttr[dpy].isActive && |
| 354 | ctx->dpyAttr[dpy].connected) { |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 355 | uint32_t last = list->numHwLayers - 1; |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 356 | hwc_layer_1_t *fbLayer = &list->hwLayers[last]; |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 357 | int fd = -1; //FenceFD from the Copybit(valid in async mode) |
| 358 | if(ctx->mCopyBit[dpy]) |
| 359 | ctx->mCopyBit[dpy]->draw(ctx, list, dpy, &fd); |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 360 | |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 361 | hwc_sync(ctx, list, dpy, fd); |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 362 | |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 363 | if (!VideoOverlay::draw(ctx, list, dpy)) { |
Saurabh Shah | eaf6791 | 2012-10-10 17:33:14 -0700 | [diff] [blame] | 364 | ALOGE("%s: VideoOverlay::draw fail!", __FUNCTION__); |
| 365 | ret = -1; |
| 366 | } |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 367 | |
| 368 | private_handle_t *hnd = (private_handle_t *)fbLayer->handle; |
Saurabh Shah | 150806a | 2012-10-09 15:38:23 -0700 | [diff] [blame] | 369 | if(fbLayer->compositionType == HWC_FRAMEBUFFER_TARGET && |
| 370 | !(fbLayer->flags & HWC_SKIP_LAYER) && hnd) { |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 371 | if (!ctx->mFBUpdate[dpy]->draw(ctx, fbLayer)) { |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 372 | ALOGE("%s: FBUpdate::draw fail!", __FUNCTION__); |
Saurabh Shah | eaf6791 | 2012-10-10 17:33:14 -0700 | [diff] [blame] | 373 | ret = -1; |
| 374 | } |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 375 | } |
Saurabh Shah | eaf6791 | 2012-10-10 17:33:14 -0700 | [diff] [blame] | 376 | if (!ctx->mExtDisplay->post()) { |
| 377 | ALOGE("%s: ctx->mExtDisplay->post fail!", __FUNCTION__); |
| 378 | return -1; |
| 379 | } |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 380 | } |
Saurabh Shah | eaf6791 | 2012-10-10 17:33:14 -0700 | [diff] [blame] | 381 | return ret; |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 382 | } |
| 383 | |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 384 | static int hwc_set(hwc_composer_device_1 *dev, |
| 385 | size_t numDisplays, |
| 386 | hwc_display_contents_1_t** displays) |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 387 | { |
| 388 | int ret = 0; |
| 389 | hwc_context_t* ctx = (hwc_context_t*)(dev); |
Naseer Ahmed | 32ff225 | 2012-09-29 01:41:21 -0400 | [diff] [blame] | 390 | Locker::Autolock _l(ctx->mBlankLock); |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 391 | for (uint32_t i = 0; i < numDisplays; i++) { |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 392 | hwc_display_contents_1_t* list = displays[i]; |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 393 | switch(i) { |
| 394 | case HWC_DISPLAY_PRIMARY: |
| 395 | ret = hwc_set_primary(ctx, list); |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 396 | break; |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 397 | case HWC_DISPLAY_EXTERNAL: |
| 398 | ret = hwc_set_external(ctx, list); |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 399 | break; |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 400 | default: |
| 401 | ret = -EINVAL; |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 402 | } |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 403 | } |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 404 | return ret; |
| 405 | } |
| 406 | |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 407 | int hwc_getDisplayConfigs(struct hwc_composer_device_1* dev, int disp, |
| 408 | uint32_t* configs, size_t* numConfigs) { |
| 409 | int ret = 0; |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 410 | hwc_context_t* ctx = (hwc_context_t*)(dev); |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 411 | //in 1.1 there is no way to choose a config, report as config id # 0 |
| 412 | //This config is passed to getDisplayAttributes. Ignore for now. |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 413 | switch(disp) { |
| 414 | case HWC_DISPLAY_PRIMARY: |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 415 | if(*numConfigs > 0) { |
| 416 | configs[0] = 0; |
| 417 | *numConfigs = 1; |
| 418 | } |
| 419 | ret = 0; //NO_ERROR |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 420 | break; |
| 421 | case HWC_DISPLAY_EXTERNAL: |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 422 | ret = -1; //Not connected |
| 423 | if(ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected) { |
| 424 | ret = 0; //NO_ERROR |
| 425 | if(*numConfigs > 0) { |
| 426 | configs[0] = 0; |
| 427 | *numConfigs = 1; |
| 428 | } |
| 429 | } |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 430 | break; |
| 431 | } |
| 432 | return ret; |
| 433 | } |
| 434 | |
| 435 | int hwc_getDisplayAttributes(struct hwc_composer_device_1* dev, int disp, |
| 436 | uint32_t config, const uint32_t* attributes, int32_t* values) { |
| 437 | |
| 438 | hwc_context_t* ctx = (hwc_context_t*)(dev); |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 439 | //If hotpluggable displays are inactive return error |
| 440 | if(disp == HWC_DISPLAY_EXTERNAL && !ctx->dpyAttr[disp].connected) { |
| 441 | return -1; |
| 442 | } |
| 443 | |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 444 | //From HWComposer |
| 445 | static const uint32_t DISPLAY_ATTRIBUTES[] = { |
| 446 | HWC_DISPLAY_VSYNC_PERIOD, |
| 447 | HWC_DISPLAY_WIDTH, |
| 448 | HWC_DISPLAY_HEIGHT, |
| 449 | HWC_DISPLAY_DPI_X, |
| 450 | HWC_DISPLAY_DPI_Y, |
| 451 | HWC_DISPLAY_NO_ATTRIBUTE, |
| 452 | }; |
| 453 | |
| 454 | const int NUM_DISPLAY_ATTRIBUTES = (sizeof(DISPLAY_ATTRIBUTES) / |
| 455 | sizeof(DISPLAY_ATTRIBUTES)[0]); |
| 456 | |
| 457 | for (size_t i = 0; i < NUM_DISPLAY_ATTRIBUTES - 1; i++) { |
| 458 | switch (attributes[i]) { |
| 459 | case HWC_DISPLAY_VSYNC_PERIOD: |
| 460 | values[i] = ctx->dpyAttr[disp].vsync_period; |
| 461 | break; |
| 462 | case HWC_DISPLAY_WIDTH: |
| 463 | values[i] = ctx->dpyAttr[disp].xres; |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 464 | ALOGD("%s disp = %d, width = %d",__FUNCTION__, disp, |
| 465 | ctx->dpyAttr[disp].xres); |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 466 | break; |
| 467 | case HWC_DISPLAY_HEIGHT: |
| 468 | values[i] = ctx->dpyAttr[disp].yres; |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 469 | ALOGD("%s disp = %d, height = %d",__FUNCTION__, disp, |
| 470 | ctx->dpyAttr[disp].yres); |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 471 | break; |
| 472 | case HWC_DISPLAY_DPI_X: |
Naseer Ahmed | 7b80d9c | 2012-09-26 20:14:38 -0400 | [diff] [blame] | 473 | values[i] = (int32_t) (ctx->dpyAttr[disp].xdpi*1000.0); |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 474 | break; |
| 475 | case HWC_DISPLAY_DPI_Y: |
Naseer Ahmed | 7b80d9c | 2012-09-26 20:14:38 -0400 | [diff] [blame] | 476 | values[i] = (int32_t) (ctx->dpyAttr[disp].ydpi*1000.0); |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 477 | break; |
| 478 | default: |
| 479 | ALOGE("Unknown display attribute %d", |
| 480 | attributes[i]); |
| 481 | return -EINVAL; |
| 482 | } |
| 483 | } |
| 484 | return 0; |
| 485 | } |
| 486 | |
Naseer Ahmed | 1d183f5 | 2012-11-26 12:35:16 -0500 | [diff] [blame] | 487 | void hwc_dump(struct hwc_composer_device_1* dev, char *buff, int buff_len) |
| 488 | { |
| 489 | hwc_context_t* ctx = (hwc_context_t*)(dev); |
| 490 | android::String8 buf(""); |
| 491 | dumpsys_log(buf, "Qualcomm HWC state:\n"); |
| 492 | dumpsys_log(buf, " MDPVersion=%d\n", ctx->mMDP.version); |
| 493 | dumpsys_log(buf, " DisplayPanel=%c\n", ctx->mMDP.panel); |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 494 | ctx->mMDPComp->dump(buf); |
Naseer Ahmed | 1d183f5 | 2012-11-26 12:35:16 -0500 | [diff] [blame] | 495 | //XXX: Call Other dump functions |
| 496 | strlcpy(buff, buf.string(), buff_len); |
| 497 | } |
| 498 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 499 | static int hwc_device_close(struct hw_device_t *dev) |
| 500 | { |
| 501 | if(!dev) { |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 502 | ALOGE("%s: NULL device pointer", __FUNCTION__); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 503 | return -1; |
| 504 | } |
| 505 | closeContext((hwc_context_t*)dev); |
| 506 | free(dev); |
| 507 | |
| 508 | return 0; |
| 509 | } |
| 510 | |
| 511 | static int hwc_device_open(const struct hw_module_t* module, const char* name, |
| 512 | struct hw_device_t** device) |
| 513 | { |
| 514 | int status = -EINVAL; |
| 515 | |
| 516 | if (!strcmp(name, HWC_HARDWARE_COMPOSER)) { |
| 517 | struct hwc_context_t *dev; |
| 518 | dev = (hwc_context_t*)malloc(sizeof(*dev)); |
| 519 | memset(dev, 0, sizeof(*dev)); |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 520 | |
| 521 | //Initialize hwc context |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 522 | initContext(dev); |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 523 | |
| 524 | //Setup HWC methods |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 525 | dev->device.common.tag = HARDWARE_DEVICE_TAG; |
| 526 | dev->device.common.version = HWC_DEVICE_API_VERSION_1_1; |
| 527 | dev->device.common.module = const_cast<hw_module_t*>(module); |
| 528 | dev->device.common.close = hwc_device_close; |
| 529 | dev->device.prepare = hwc_prepare; |
| 530 | dev->device.set = hwc_set; |
| 531 | dev->device.eventControl = hwc_eventControl; |
| 532 | dev->device.blank = hwc_blank; |
| 533 | dev->device.query = hwc_query; |
| 534 | dev->device.registerProcs = hwc_registerProcs; |
Naseer Ahmed | 1d183f5 | 2012-11-26 12:35:16 -0500 | [diff] [blame] | 535 | dev->device.dump = hwc_dump; |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 536 | dev->device.getDisplayConfigs = hwc_getDisplayConfigs; |
| 537 | dev->device.getDisplayAttributes = hwc_getDisplayAttributes; |
| 538 | *device = &dev->device.common; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 539 | status = 0; |
| 540 | } |
| 541 | return status; |
| 542 | } |