Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 1 | /* |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 2 | * Copyright (C) 2012-2013, The Linux Foundation. All rights reserved. |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 3 | * Not a Contribution, Apache license notifications and license are retained |
| 4 | * for attribution purposes only. |
| 5 | * |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | */ |
| 18 | |
| 19 | #include "hwc_mdpcomp.h" |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 20 | #include <sys/ioctl.h> |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 21 | #include "external.h" |
Ramkumar Radhakrishnan | 47573e2 | 2012-11-07 11:36:41 -0800 | [diff] [blame] | 22 | #include "qdMetaData.h" |
Ramkumar Radhakrishnan | 288f8c7 | 2013-01-15 11:37:54 -0800 | [diff] [blame] | 23 | #include "mdp_version.h" |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 24 | #include <overlayRotator.h> |
| 25 | |
Saurabh Shah | 85234ec | 2013-04-12 17:09:00 -0700 | [diff] [blame] | 26 | using namespace overlay; |
Saurabh Shah | bd2d083 | 2013-04-04 14:33:08 -0700 | [diff] [blame] | 27 | using namespace qdutils; |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 28 | using namespace overlay::utils; |
| 29 | namespace ovutils = overlay::utils; |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 30 | |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 31 | namespace qhwc { |
| 32 | |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 33 | //==============MDPComp======================================================== |
| 34 | |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 35 | IdleInvalidator *MDPComp::idleInvalidator = NULL; |
| 36 | bool MDPComp::sIdleFallBack = false; |
| 37 | bool MDPComp::sDebugLogs = false; |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 38 | bool MDPComp::sEnabled = false; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 39 | int MDPComp::sMaxPipesPerMixer = MAX_PIPES_PER_MIXER; |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 40 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 41 | MDPComp* MDPComp::getObject(const int& width, int dpy) { |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 42 | if(width <= MAX_DISPLAY_DIM) { |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 43 | return new MDPCompLowRes(dpy); |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 44 | } else { |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 45 | return new MDPCompHighRes(dpy); |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 46 | } |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 47 | } |
| 48 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 49 | MDPComp::MDPComp(int dpy):mDpy(dpy){}; |
| 50 | |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 51 | void MDPComp::dump(android::String8& buf) |
| 52 | { |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 53 | dumpsys_log(buf,"HWC Map for Dpy: %s \n", |
| 54 | mDpy ? "\"EXTERNAL\"" : "\"PRIMARY\""); |
| 55 | dumpsys_log(buf,"PREV_FRAME: layerCount:%2d mdpCount:%2d \ |
| 56 | cacheCount:%2d \n", mCachedFrame.layerCount, |
| 57 | mCachedFrame.mdpCount, mCachedFrame.cacheCount); |
| 58 | dumpsys_log(buf,"CURR_FRAME: layerCount:%2d mdpCount:%2d \ |
| 59 | fbCount:%2d \n", mCurrentFrame.layerCount, |
| 60 | mCurrentFrame.mdpCount, mCurrentFrame.fbCount); |
| 61 | dumpsys_log(buf,"needsFBRedraw:%3s pipesUsed:%2d MaxPipesPerMixer: %d \n", |
| 62 | (mCurrentFrame.needsRedraw? "YES" : "NO"), |
| 63 | mCurrentFrame.mdpCount, sMaxPipesPerMixer); |
| 64 | dumpsys_log(buf," --------------------------------------------- \n"); |
| 65 | dumpsys_log(buf," listIdx | cached? | mdpIndex | comptype | Z \n"); |
| 66 | dumpsys_log(buf," --------------------------------------------- \n"); |
| 67 | for(int index = 0; index < mCurrentFrame.layerCount; index++ ) |
| 68 | dumpsys_log(buf," %7d | %7s | %8d | %9s | %2d \n", |
| 69 | index, |
| 70 | (mCurrentFrame.isFBComposed[index] ? "YES" : "NO"), |
| 71 | mCurrentFrame.layerToMDP[index], |
| 72 | (mCurrentFrame.isFBComposed[index] ? |
| 73 | (mCurrentFrame.needsRedraw ? "GLES" : "CACHE") : "MDP"), |
| 74 | (mCurrentFrame.isFBComposed[index] ? mCurrentFrame.fbZ : |
| 75 | mCurrentFrame.mdpToLayer[mCurrentFrame.layerToMDP[index]].pipeInfo->zOrder)); |
| 76 | dumpsys_log(buf,"\n"); |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | bool MDPComp::init(hwc_context_t *ctx) { |
| 80 | |
| 81 | if(!ctx) { |
| 82 | ALOGE("%s: Invalid hwc context!!",__FUNCTION__); |
| 83 | return false; |
| 84 | } |
| 85 | |
| 86 | if(!setupBasePipe(ctx)) { |
| 87 | ALOGE("%s: Failed to setup primary base pipe", __FUNCTION__); |
| 88 | return false; |
| 89 | } |
| 90 | |
| 91 | char property[PROPERTY_VALUE_MAX]; |
| 92 | |
| 93 | sEnabled = false; |
| 94 | if((property_get("persist.hwc.mdpcomp.enable", property, NULL) > 0) && |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 95 | (!strncmp(property, "1", PROPERTY_VALUE_MAX ) || |
| 96 | (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) { |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 97 | sEnabled = true; |
| 98 | } |
| 99 | |
| 100 | sDebugLogs = false; |
| 101 | if(property_get("debug.mdpcomp.logs", property, NULL) > 0) { |
| 102 | if(atoi(property) != 0) |
| 103 | sDebugLogs = true; |
| 104 | } |
| 105 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 106 | sMaxPipesPerMixer = MAX_PIPES_PER_MIXER; |
Saurabh Shah | 85234ec | 2013-04-12 17:09:00 -0700 | [diff] [blame] | 107 | if(property_get("debug.mdpcomp.maxpermixer", property, "-1") > 0) { |
| 108 | int val = atoi(property); |
| 109 | if(val >= 0) |
| 110 | sMaxPipesPerMixer = min(val, MAX_PIPES_PER_MIXER); |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 111 | } |
| 112 | |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 113 | unsigned long idle_timeout = DEFAULT_IDLE_TIME; |
| 114 | if(property_get("debug.mdpcomp.idletime", property, NULL) > 0) { |
| 115 | if(atoi(property) != 0) |
| 116 | idle_timeout = atoi(property); |
| 117 | } |
| 118 | |
| 119 | //create Idle Invalidator |
| 120 | idleInvalidator = IdleInvalidator::getInstance(); |
| 121 | |
| 122 | if(idleInvalidator == NULL) { |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 123 | ALOGE("%s: failed to instantiate idleInvalidator object", __FUNCTION__); |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 124 | } else { |
| 125 | idleInvalidator->init(timeout_handler, ctx, idle_timeout); |
| 126 | } |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 127 | return true; |
| 128 | } |
| 129 | |
| 130 | void MDPComp::timeout_handler(void *udata) { |
| 131 | struct hwc_context_t* ctx = (struct hwc_context_t*)(udata); |
| 132 | |
| 133 | if(!ctx) { |
| 134 | ALOGE("%s: received empty data in timer callback", __FUNCTION__); |
| 135 | return; |
| 136 | } |
| 137 | |
Jesse Hall | 3be78d9 | 2012-08-21 15:12:23 -0700 | [diff] [blame] | 138 | if(!ctx->proc) { |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 139 | ALOGE("%s: HWC proc not registered", __FUNCTION__); |
| 140 | return; |
| 141 | } |
| 142 | sIdleFallBack = true; |
| 143 | /* Trigger SF to redraw the current frame */ |
Jesse Hall | 3be78d9 | 2012-08-21 15:12:23 -0700 | [diff] [blame] | 144 | ctx->proc->invalidate(ctx->proc); |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 145 | } |
| 146 | |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 147 | void MDPComp::setMDPCompLayerFlags(hwc_context_t *ctx, |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 148 | hwc_display_contents_1_t* list) { |
| 149 | LayerProp *layerProp = ctx->layerProp[mDpy]; |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 150 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 151 | for(int index = 0; index < ctx->listStats[mDpy].numAppLayers; index++) { |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 152 | hwc_layer_1_t* layer = &(list->hwLayers[index]); |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 153 | if(!mCurrentFrame.isFBComposed[index]) { |
| 154 | layerProp[index].mFlags |= HWC_MDPCOMP; |
| 155 | layer->compositionType = HWC_OVERLAY; |
| 156 | layer->hints |= HWC_HINT_CLEAR_FB; |
| 157 | mCachedFrame.hnd[index] = NULL; |
| 158 | } else { |
| 159 | if(!mCurrentFrame.needsRedraw) |
| 160 | layer->compositionType = HWC_OVERLAY; |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 161 | } |
| 162 | } |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 163 | } |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 164 | |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 165 | /* |
| 166 | * Sets up BORDERFILL as default base pipe and detaches RGB0. |
| 167 | * Framebuffer is always updated using PLAY ioctl. |
| 168 | */ |
| 169 | bool MDPComp::setupBasePipe(hwc_context_t *ctx) { |
| 170 | const int dpy = HWC_DISPLAY_PRIMARY; |
| 171 | int fb_stride = ctx->dpyAttr[dpy].stride; |
| 172 | int fb_width = ctx->dpyAttr[dpy].xres; |
| 173 | int fb_height = ctx->dpyAttr[dpy].yres; |
| 174 | int fb_fd = ctx->dpyAttr[dpy].fd; |
| 175 | |
| 176 | mdp_overlay ovInfo; |
| 177 | msmfb_overlay_data ovData; |
| 178 | memset(&ovInfo, 0, sizeof(mdp_overlay)); |
| 179 | memset(&ovData, 0, sizeof(msmfb_overlay_data)); |
| 180 | |
| 181 | ovInfo.src.format = MDP_RGB_BORDERFILL; |
| 182 | ovInfo.src.width = fb_width; |
| 183 | ovInfo.src.height = fb_height; |
| 184 | ovInfo.src_rect.w = fb_width; |
| 185 | ovInfo.src_rect.h = fb_height; |
| 186 | ovInfo.dst_rect.w = fb_width; |
| 187 | ovInfo.dst_rect.h = fb_height; |
| 188 | ovInfo.id = MSMFB_NEW_REQUEST; |
| 189 | |
| 190 | if (ioctl(fb_fd, MSMFB_OVERLAY_SET, &ovInfo) < 0) { |
| 191 | ALOGE("Failed to call ioctl MSMFB_OVERLAY_SET err=%s", |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 192 | strerror(errno)); |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 193 | return false; |
| 194 | } |
| 195 | |
| 196 | ovData.id = ovInfo.id; |
| 197 | if (ioctl(fb_fd, MSMFB_OVERLAY_PLAY, &ovData) < 0) { |
| 198 | ALOGE("Failed to call ioctl MSMFB_OVERLAY_PLAY err=%s", |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 199 | strerror(errno)); |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 200 | return false; |
| 201 | } |
| 202 | return true; |
| 203 | } |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 204 | MDPComp::FrameInfo::FrameInfo() { |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame^] | 205 | reset(0); |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 206 | } |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 207 | |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame^] | 208 | void MDPComp::FrameInfo::reset(const int& numLayers) { |
| 209 | for(int i = 0 ; i < MAX_PIPES_PER_MIXER && numLayers; i++ ) { |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 210 | if(mdpToLayer[i].pipeInfo) { |
| 211 | delete mdpToLayer[i].pipeInfo; |
| 212 | mdpToLayer[i].pipeInfo = NULL; |
| 213 | //We dont own the rotator |
| 214 | mdpToLayer[i].rot = NULL; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 215 | } |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 216 | } |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 217 | |
| 218 | memset(&mdpToLayer, 0, sizeof(mdpToLayer)); |
| 219 | memset(&layerToMDP, -1, sizeof(layerToMDP)); |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame^] | 220 | memset(&isFBComposed, 1, sizeof(isFBComposed)); |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 221 | |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame^] | 222 | layerCount = numLayers; |
| 223 | fbCount = numLayers; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 224 | mdpCount = 0; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 225 | needsRedraw = false; |
| 226 | fbZ = 0; |
| 227 | } |
| 228 | |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame^] | 229 | void MDPComp::FrameInfo::map() { |
| 230 | // populate layer and MDP maps |
| 231 | int mdpIdx = 0; |
| 232 | for(int idx = 0; idx < layerCount; idx++) { |
| 233 | if(!isFBComposed[idx]) { |
| 234 | mdpToLayer[mdpIdx].listIndex = idx; |
| 235 | layerToMDP[idx] = mdpIdx++; |
| 236 | } |
| 237 | } |
| 238 | } |
| 239 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 240 | MDPComp::LayerCache::LayerCache() { |
| 241 | reset(); |
| 242 | } |
| 243 | |
| 244 | void MDPComp::LayerCache::reset() { |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame^] | 245 | memset(&hnd, 0, sizeof(hnd)); |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 246 | mdpCount = 0; |
| 247 | cacheCount = 0; |
| 248 | layerCount = 0; |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame^] | 249 | fbZ = -1; |
| 250 | } |
| 251 | |
| 252 | void MDPComp::LayerCache::cacheAll(hwc_display_contents_1_t* list) { |
| 253 | const int numAppLayers = list->numHwLayers - 1; |
| 254 | for(int i = 0; i < numAppLayers; i++) { |
| 255 | hnd[i] = list->hwLayers[i].handle; |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | void MDPComp::LayerCache::updateCounts(const FrameInfo& curFrame) { |
| 260 | mdpCount = curFrame.mdpCount; |
| 261 | cacheCount = curFrame.fbCount; |
| 262 | layerCount = curFrame.layerCount; |
| 263 | fbZ = curFrame.fbZ; |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 264 | } |
| 265 | |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 266 | bool MDPComp::isWidthValid(hwc_context_t *ctx, hwc_layer_1_t *layer) { |
Jeykumar Sankaran | c18dbc2 | 2013-02-08 14:29:44 -0800 | [diff] [blame] | 267 | |
Jeykumar Sankaran | c18dbc2 | 2013-02-08 14:29:44 -0800 | [diff] [blame] | 268 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
| 269 | |
| 270 | if(!hnd) { |
| 271 | ALOGE("%s: layer handle is NULL", __FUNCTION__); |
| 272 | return false; |
| 273 | } |
| 274 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 275 | int hw_w = ctx->dpyAttr[mDpy].xres; |
| 276 | int hw_h = ctx->dpyAttr[mDpy].yres; |
Jeykumar Sankaran | c18dbc2 | 2013-02-08 14:29:44 -0800 | [diff] [blame] | 277 | |
| 278 | hwc_rect_t sourceCrop = layer->sourceCrop; |
| 279 | hwc_rect_t displayFrame = layer->displayFrame; |
| 280 | |
| 281 | hwc_rect_t crop = sourceCrop; |
| 282 | int crop_w = crop.right - crop.left; |
| 283 | int crop_h = crop.bottom - crop.top; |
| 284 | |
| 285 | hwc_rect_t dst = displayFrame; |
| 286 | int dst_w = dst.right - dst.left; |
| 287 | int dst_h = dst.bottom - dst.top; |
| 288 | |
| 289 | if(dst.left < 0 || dst.top < 0 || dst.right > hw_w || dst.bottom > hw_h) { |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 290 | hwc_rect_t scissor = {0, 0, hw_w, hw_h }; |
| 291 | qhwc::calculate_crop_rects(crop, dst, scissor, layer->transform); |
| 292 | crop_w = crop.right - crop.left; |
| 293 | crop_h = crop.bottom - crop.top; |
Jeykumar Sankaran | c18dbc2 | 2013-02-08 14:29:44 -0800 | [diff] [blame] | 294 | } |
| 295 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 296 | /* Workaround for MDP HW limitation in DSI command mode panels where |
| 297 | * FPS will not go beyond 30 if buffers on RGB pipes are of width or height |
| 298 | * less than 5 pixels |
| 299 | * */ |
Jeykumar Sankaran | c18dbc2 | 2013-02-08 14:29:44 -0800 | [diff] [blame] | 300 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 301 | if((crop_w < 5)||(crop_h < 5)) |
Jeykumar Sankaran | c18dbc2 | 2013-02-08 14:29:44 -0800 | [diff] [blame] | 302 | return false; |
| 303 | |
| 304 | return true; |
| 305 | } |
| 306 | |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 307 | ovutils::eDest MDPComp::getMdpPipe(hwc_context_t *ctx, ePipeType type) { |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 308 | overlay::Overlay& ov = *ctx->mOverlay; |
| 309 | ovutils::eDest mdp_pipe = ovutils::OV_INVALID; |
| 310 | |
| 311 | switch(type) { |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 312 | case MDPCOMP_OV_DMA: |
| 313 | mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_DMA, mDpy); |
| 314 | if(mdp_pipe != ovutils::OV_INVALID) { |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 315 | return mdp_pipe; |
| 316 | } |
| 317 | case MDPCOMP_OV_ANY: |
| 318 | case MDPCOMP_OV_RGB: |
| 319 | mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy); |
| 320 | if(mdp_pipe != ovutils::OV_INVALID) { |
| 321 | return mdp_pipe; |
| 322 | } |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 323 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 324 | if(type == MDPCOMP_OV_RGB) { |
| 325 | //Requested only for RGB pipe |
| 326 | break; |
| 327 | } |
| 328 | case MDPCOMP_OV_VG: |
| 329 | return ov.nextPipe(ovutils::OV_MDP_PIPE_VG, mDpy); |
| 330 | default: |
| 331 | ALOGE("%s: Invalid pipe type",__FUNCTION__); |
| 332 | return ovutils::OV_INVALID; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 333 | }; |
| 334 | return ovutils::OV_INVALID; |
| 335 | } |
| 336 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 337 | bool MDPComp::isFrameDoable(hwc_context_t *ctx) { |
| 338 | int numAppLayers = ctx->listStats[mDpy].numAppLayers; |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame^] | 339 | bool ret = true; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 340 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 341 | if(!isEnabled()) { |
| 342 | ALOGD_IF(isDebug(),"%s: MDP Comp. not enabled.", __FUNCTION__); |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame^] | 343 | ret = false; |
| 344 | } else if(ctx->mExtDispConfiguring) { |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 345 | ALOGD_IF( isDebug(),"%s: External Display connection is pending", |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 346 | __FUNCTION__); |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame^] | 347 | ret = false; |
| 348 | } else if(ctx->listStats[mDpy].needsAlphaScale |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 349 | && ctx->mMDP.version < qdutils::MDSS_V5) { |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 350 | ALOGD_IF(isDebug(), "%s: frame needs alpha downscaling",__FUNCTION__); |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame^] | 351 | ret = false; |
| 352 | } else if(ctx->isPaddingRound) { |
Saurabh Shah | 0ceeb6a | 2013-04-23 10:46:07 -0700 | [diff] [blame] | 353 | ctx->isPaddingRound = false; |
| 354 | ALOGD_IF(isDebug(), "%s: padding round",__FUNCTION__); |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame^] | 355 | ret = false; |
| 356 | } else if(sIdleFallBack) { |
| 357 | sIdleFallBack = false; |
| 358 | ALOGD_IF(isDebug(), "%s: idle fallback",__FUNCTION__); |
| 359 | ret = false; |
Saurabh Shah | 0ceeb6a | 2013-04-23 10:46:07 -0700 | [diff] [blame] | 360 | } |
| 361 | |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame^] | 362 | return ret; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | /* Checks for conditions where all the layers marked for MDP comp cannot be |
| 366 | * bypassed. On such conditions we try to bypass atleast YUV layers */ |
| 367 | bool MDPComp::isFullFrameDoable(hwc_context_t *ctx, |
| 368 | hwc_display_contents_1_t* list){ |
| 369 | |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame^] | 370 | const int numAppLayers = ctx->listStats[mDpy].numAppLayers; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 371 | |
| 372 | if(mDpy > HWC_DISPLAY_PRIMARY){ |
| 373 | ALOGD_IF(isDebug(), "%s: Cannot support External display(s)", |
| 374 | __FUNCTION__); |
| 375 | return false; |
| 376 | } |
| 377 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 378 | if(isSkipPresent(ctx, mDpy)) { |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame^] | 379 | ALOGD_IF(isDebug(),"%s: SKIP present: %d", |
| 380 | __FUNCTION__, |
| 381 | isSkipPresent(ctx, mDpy)); |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 382 | return false; |
| 383 | } |
| 384 | |
| 385 | //MDP composition is not efficient if layer needs rotator. |
| 386 | for(int i = 0; i < numAppLayers; ++i) { |
| 387 | // As MDP h/w supports flip operation, use MDP comp only for |
| 388 | // 180 transforms. Fail for any transform involving 90 (90, 270). |
| 389 | hwc_layer_1_t* layer = &list->hwLayers[i]; |
| 390 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
Jeykumar Sankaran | a37fdbf | 2013-03-06 18:59:28 -0800 | [diff] [blame] | 391 | |
| 392 | if(layer->transform & HWC_TRANSFORM_ROT_90 && !isYuvBuffer(hnd)) { |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 393 | ALOGD_IF(isDebug(), "%s: orientation involved",__FUNCTION__); |
| 394 | return false; |
| 395 | } |
| 396 | |
| 397 | if(!isYuvBuffer(hnd) && !isWidthValid(ctx,layer)) { |
| 398 | ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",__FUNCTION__); |
| 399 | return false; |
| 400 | } |
| 401 | } |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame^] | 402 | |
| 403 | //If all above hard conditions are met we can do full or partial MDP comp. |
| 404 | bool ret = false; |
| 405 | if(fullMDPComp(ctx, list)) { |
| 406 | ret = true; |
| 407 | } else if (partialMDPComp(ctx, list)) { |
| 408 | ret = true; |
| 409 | } |
| 410 | return ret; |
| 411 | } |
| 412 | |
| 413 | bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) { |
| 414 | //Setup mCurrentFrame |
| 415 | mCurrentFrame.mdpCount = mCurrentFrame.layerCount; |
| 416 | mCurrentFrame.fbCount = 0; |
| 417 | mCurrentFrame.fbZ = -1; |
| 418 | memset(&mCurrentFrame.isFBComposed, 0, sizeof(mCurrentFrame.isFBComposed)); |
| 419 | |
| 420 | int mdpCount = mCurrentFrame.mdpCount; |
| 421 | if(mdpCount > sMaxPipesPerMixer) { |
| 422 | ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__); |
| 423 | return false; |
| 424 | } |
| 425 | |
| 426 | int numPipesNeeded = pipesNeeded(ctx, list); |
| 427 | int availPipes = getAvailablePipes(ctx); |
| 428 | |
| 429 | if(numPipesNeeded > availPipes) { |
| 430 | ALOGD_IF(isDebug(), "%s: Insufficient MDP pipes, needed %d, avail %d", |
| 431 | __FUNCTION__, numPipesNeeded, availPipes); |
| 432 | return false; |
| 433 | } |
| 434 | |
| 435 | return true; |
| 436 | } |
| 437 | |
| 438 | bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) |
| 439 | { |
| 440 | int numAppLayers = ctx->listStats[mDpy].numAppLayers; |
| 441 | //Setup mCurrentFrame |
| 442 | mCurrentFrame.reset(numAppLayers); |
| 443 | updateLayerCache(ctx, list); |
| 444 | updateYUV(ctx, list); |
| 445 | batchLayers(); //sets up fbZ also |
| 446 | |
| 447 | int mdpCount = mCurrentFrame.mdpCount; |
| 448 | if(mdpCount > (sMaxPipesPerMixer - 1)) { // -1 since FB is used |
| 449 | ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__); |
| 450 | return false; |
| 451 | } |
| 452 | |
| 453 | int numPipesNeeded = pipesNeeded(ctx, list); |
| 454 | int availPipes = getAvailablePipes(ctx); |
| 455 | |
| 456 | if(numPipesNeeded > availPipes) { |
| 457 | ALOGD_IF(isDebug(), "%s: Insufficient MDP pipes, needed %d, avail %d", |
| 458 | __FUNCTION__, numPipesNeeded, availPipes); |
| 459 | return false; |
| 460 | } |
| 461 | |
| 462 | return true; |
| 463 | } |
| 464 | |
| 465 | bool MDPComp::isOnlyVideoDoable(hwc_context_t *ctx, |
| 466 | hwc_display_contents_1_t* list){ |
| 467 | int numAppLayers = ctx->listStats[mDpy].numAppLayers; |
| 468 | mCurrentFrame.reset(numAppLayers); |
| 469 | updateYUV(ctx, list); |
| 470 | int mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount; |
| 471 | int fbNeeded = int(mCurrentFrame.fbCount != 0); |
| 472 | |
| 473 | if(!isYuvPresent(ctx, mDpy)) { |
| 474 | return false; |
| 475 | } |
| 476 | |
| 477 | if(mdpCount > (sMaxPipesPerMixer - fbNeeded)) { |
| 478 | ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__); |
| 479 | return false; |
| 480 | } |
| 481 | |
| 482 | int numPipesNeeded = pipesNeeded(ctx, list); |
| 483 | int availPipes = getAvailablePipes(ctx); |
| 484 | if(numPipesNeeded > availPipes) { |
| 485 | ALOGD_IF(isDebug(), "%s: Insufficient MDP pipes, needed %d, avail %d", |
| 486 | __FUNCTION__, numPipesNeeded, availPipes); |
| 487 | return false; |
| 488 | } |
| 489 | |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 490 | return true; |
| 491 | } |
| 492 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 493 | /* Checks for conditions where YUV layers cannot be bypassed */ |
| 494 | bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) { |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 495 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 496 | if(isSkipLayer(layer)) { |
| 497 | ALOGE("%s: Unable to bypass skipped YUV", __FUNCTION__); |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 498 | return false; |
| 499 | } |
| 500 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 501 | if(isSecuring(ctx, layer)) { |
| 502 | ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__); |
| 503 | return false; |
| 504 | } |
| 505 | |
Saurabh Shah | bd2d083 | 2013-04-04 14:33:08 -0700 | [diff] [blame] | 506 | if(!qdutils::MDPVersion::getInstance().supportsDecimation()) { |
| 507 | const uint32_t downscale = |
| 508 | qdutils::MDPVersion::getInstance().getMaxMDPDownscale(); |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 509 | hwc_rect_t crop = layer->sourceCrop; |
| 510 | hwc_rect_t dst = layer->displayFrame; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 511 | int cWidth = crop.right - crop.left; |
| 512 | int cHeight = crop.bottom - crop.top; |
| 513 | int dWidth = dst.right - dst.left; |
| 514 | int dHeight = dst.bottom - dst.top; |
| 515 | |
Amara Venkata Mastan Manoj Kumar | 6fa8672 | 2013-04-12 17:11:14 -0700 | [diff] [blame] | 516 | if(layer->transform & HAL_TRANSFORM_ROT_90) { |
| 517 | swap(cWidth, cHeight); |
| 518 | } |
| 519 | |
Saurabh Shah | bd2d083 | 2013-04-04 14:33:08 -0700 | [diff] [blame] | 520 | if(cWidth > MAX_DISPLAY_DIM || (cWidth/dWidth) > downscale || |
| 521 | (cHeight/dHeight) > downscale) |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 522 | return false; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 523 | } |
| 524 | return true; |
| 525 | } |
| 526 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 527 | void MDPComp::batchLayers() { |
| 528 | /* Idea is to keep as many contiguous non-updating(cached) layers in FB and |
| 529 | * send rest of them through MDP. NEVER mark an updating layer for caching. |
| 530 | * But cached ones can be marked for MDP*/ |
| 531 | |
| 532 | int maxBatchStart = -1; |
| 533 | int maxBatchCount = 0; |
| 534 | |
| 535 | /* All or Nothing is cached. No batching needed */ |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame^] | 536 | if(!mCurrentFrame.fbCount) { |
| 537 | mCurrentFrame.fbZ = -1; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 538 | return; |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame^] | 539 | } |
| 540 | if(!mCurrentFrame.mdpCount) { |
| 541 | mCurrentFrame.fbZ = 0; |
| 542 | return; |
| 543 | } |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 544 | |
| 545 | /* Search for max number of contiguous (cached) layers */ |
| 546 | int i = 0; |
| 547 | while (i < mCurrentFrame.layerCount) { |
| 548 | int count = 0; |
| 549 | while(mCurrentFrame.isFBComposed[i] && i < mCurrentFrame.layerCount) { |
| 550 | count++; i++; |
| 551 | } |
| 552 | if(count > maxBatchCount) { |
| 553 | maxBatchCount = count; |
| 554 | maxBatchStart = i - count; |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame^] | 555 | mCurrentFrame.fbZ = maxBatchStart; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 556 | } |
| 557 | if(i < mCurrentFrame.layerCount) i++; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 558 | } |
| 559 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 560 | /* reset rest of the layers for MDP comp */ |
| 561 | for(int i = 0; i < mCurrentFrame.layerCount; i++) { |
| 562 | if(i != maxBatchStart){ |
| 563 | mCurrentFrame.isFBComposed[i] = false; |
| 564 | } else { |
| 565 | i += maxBatchCount; |
| 566 | } |
| 567 | } |
| 568 | |
| 569 | mCurrentFrame.fbCount = maxBatchCount; |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame^] | 570 | mCurrentFrame.mdpCount = mCurrentFrame.layerCount - |
| 571 | mCurrentFrame.fbCount; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 572 | |
| 573 | ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__, |
| 574 | mCurrentFrame.fbCount); |
| 575 | } |
Saurabh Shah | 85234ec | 2013-04-12 17:09:00 -0700 | [diff] [blame] | 576 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 577 | void MDPComp::updateLayerCache(hwc_context_t* ctx, |
| 578 | hwc_display_contents_1_t* list) { |
| 579 | |
| 580 | int numAppLayers = ctx->listStats[mDpy].numAppLayers; |
| 581 | int numCacheableLayers = 0; |
| 582 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 583 | for(int i = 0; i < numAppLayers; i++) { |
| 584 | if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) { |
| 585 | numCacheableLayers++; |
| 586 | mCurrentFrame.isFBComposed[i] = true; |
| 587 | } else { |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame^] | 588 | mCurrentFrame.isFBComposed[i] = false; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 589 | mCachedFrame.hnd[i] = list->hwLayers[i].handle; |
| 590 | } |
| 591 | } |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame^] | 592 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 593 | mCurrentFrame.fbCount = numCacheableLayers; |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame^] | 594 | mCurrentFrame.mdpCount = mCurrentFrame.layerCount - |
| 595 | mCurrentFrame.fbCount; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 596 | ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__, numCacheableLayers); |
| 597 | } |
| 598 | |
| 599 | int MDPComp::getAvailablePipes(hwc_context_t* ctx) { |
| 600 | int numDMAPipes = qdutils::MDPVersion::getInstance().getDMAPipes(); |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 601 | overlay::Overlay& ov = *ctx->mOverlay; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 602 | |
| 603 | int numAvailable = ov.availablePipes(mDpy); |
| 604 | |
| 605 | //Reserve DMA for rotator |
Saurabh Shah | 85234ec | 2013-04-12 17:09:00 -0700 | [diff] [blame] | 606 | if(Overlay::getDMAMode() == Overlay::DMA_BLOCK_MODE) |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 607 | numAvailable -= numDMAPipes; |
| 608 | |
| 609 | //Reserve pipe(s)for FB |
| 610 | if(mCurrentFrame.fbCount) |
| 611 | numAvailable -= pipesForFB(); |
| 612 | |
| 613 | return numAvailable; |
| 614 | } |
| 615 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 616 | void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list) { |
| 617 | |
| 618 | int nYuvCount = ctx->listStats[mDpy].yuvCount; |
| 619 | for(int index = 0;index < nYuvCount; index++){ |
| 620 | int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index]; |
| 621 | hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex]; |
| 622 | |
| 623 | if(!isYUVDoable(ctx, layer)) { |
| 624 | if(!mCurrentFrame.isFBComposed[nYuvIndex]) { |
| 625 | mCurrentFrame.isFBComposed[nYuvIndex] = true; |
| 626 | mCurrentFrame.fbCount++; |
| 627 | } |
| 628 | } else { |
| 629 | if(mCurrentFrame.isFBComposed[nYuvIndex]) { |
| 630 | mCurrentFrame.isFBComposed[nYuvIndex] = false; |
| 631 | mCurrentFrame.fbCount--; |
| 632 | } |
| 633 | } |
| 634 | } |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame^] | 635 | |
| 636 | mCurrentFrame.mdpCount = mCurrentFrame.layerCount - |
| 637 | mCurrentFrame.fbCount; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 638 | ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__, |
| 639 | mCurrentFrame.fbCount); |
| 640 | } |
| 641 | |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame^] | 642 | bool MDPComp::programMDP(hwc_context_t *ctx, hwc_display_contents_1_t* list) { |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 643 | if(!allocLayerPipes(ctx, list)) { |
| 644 | ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__); |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame^] | 645 | return false; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 646 | } |
| 647 | |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame^] | 648 | bool fbBatch = false; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 649 | for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount; |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame^] | 650 | index++) { |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 651 | if(!mCurrentFrame.isFBComposed[index]) { |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 652 | int mdpIndex = mCurrentFrame.layerToMDP[index]; |
| 653 | hwc_layer_1_t* layer = &list->hwLayers[index]; |
| 654 | |
| 655 | MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo; |
| 656 | cur_pipe->zOrder = mdpNextZOrder++; |
| 657 | |
| 658 | if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){ |
| 659 | ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \ |
| 660 | layer %d",__FUNCTION__, index); |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame^] | 661 | return false; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 662 | } |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame^] | 663 | } else if(fbBatch == false) { |
| 664 | mdpNextZOrder++; |
| 665 | fbBatch = true; |
| 666 | } |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 667 | } |
| 668 | |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame^] | 669 | return true; |
| 670 | } |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 671 | |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame^] | 672 | bool MDPComp::programYUV(hwc_context_t *ctx, hwc_display_contents_1_t* list) { |
| 673 | if(!allocLayerPipes(ctx, list)) { |
| 674 | ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__); |
| 675 | return false; |
| 676 | } |
| 677 | //If we are in this block, it means we have yuv + rgb layers both |
| 678 | int mdpIdx = 0; |
| 679 | for (int index = 0; index < mCurrentFrame.layerCount; index++) { |
| 680 | if(!mCurrentFrame.isFBComposed[index]) { |
| 681 | hwc_layer_1_t* layer = &list->hwLayers[index]; |
| 682 | int mdpIndex = mCurrentFrame.layerToMDP[index]; |
| 683 | MdpPipeInfo* cur_pipe = |
| 684 | mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo; |
| 685 | cur_pipe->zOrder = mdpIdx++; |
| 686 | |
| 687 | if(configure(ctx, layer, |
| 688 | mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){ |
| 689 | ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \ |
| 690 | layer %d",__FUNCTION__, index); |
| 691 | return false; |
| 692 | } |
| 693 | } |
| 694 | } |
| 695 | return true; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 696 | } |
| 697 | |
| 698 | int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) { |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 699 | |
| 700 | //reset old data |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame^] | 701 | const int numLayers = ctx->listStats[mDpy].numAppLayers; |
| 702 | mCurrentFrame.reset(numLayers); |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 703 | |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame^] | 704 | //Hard conditions, if not met, cannot do MDP comp |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 705 | if(!isFrameDoable(ctx)) { |
| 706 | ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame", |
| 707 | __FUNCTION__); |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame^] | 708 | mCurrentFrame.reset(numLayers); |
| 709 | mCachedFrame.cacheAll(list); |
| 710 | mCachedFrame.updateCounts(mCurrentFrame); |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 711 | return 0; |
| 712 | } |
| 713 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 714 | //Check whether layers marked for MDP Composition is actually doable. |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame^] | 715 | if(isFullFrameDoable(ctx, list)){ |
| 716 | if(mCurrentFrame.mdpCount) { |
| 717 | mCurrentFrame.map(); |
| 718 | //Acquire and Program MDP pipes |
| 719 | if(!programMDP(ctx, list)) { |
| 720 | mCurrentFrame.reset(numLayers); |
| 721 | mCachedFrame.cacheAll(list); |
| 722 | } |
| 723 | } |
| 724 | } else if(isOnlyVideoDoable(ctx, list)) { |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 725 | //All layers marked for MDP comp cannot be bypassed. |
| 726 | //Try to compose atleast YUV layers through MDP comp and let |
| 727 | //all the RGB layers compose in FB |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame^] | 728 | //Destination over |
| 729 | mCurrentFrame.fbZ = -1; |
| 730 | if(mCurrentFrame.fbCount) |
| 731 | mCurrentFrame.fbZ = ctx->listStats[mDpy].yuvCount; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 732 | |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame^] | 733 | mCurrentFrame.map(); |
| 734 | if(!programYUV(ctx, list)) { |
| 735 | mCurrentFrame.reset(numLayers); |
| 736 | mCachedFrame.cacheAll(list); |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 737 | } |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame^] | 738 | } else { |
| 739 | mCurrentFrame.reset(numLayers); |
| 740 | mCachedFrame.cacheAll(list); |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 741 | } |
| 742 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 743 | /* Any change in composition types needs an FB refresh*/ |
| 744 | if(mCurrentFrame.fbCount && |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame^] | 745 | ((mCurrentFrame.mdpCount != mCachedFrame.mdpCount) || |
| 746 | (mCurrentFrame.fbCount != mCachedFrame.cacheCount) || |
| 747 | (mCurrentFrame.fbZ != mCachedFrame.fbZ) || |
| 748 | (!mCurrentFrame.mdpCount) || |
| 749 | (list->flags & HWC_GEOMETRY_CHANGED) || |
| 750 | isSkipPresent(ctx, mDpy) || |
| 751 | (mDpy > HWC_DISPLAY_PRIMARY))) { |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 752 | mCurrentFrame.needsRedraw = true; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 753 | } |
| 754 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 755 | //UpdateLayerFlags |
| 756 | setMDPCompLayerFlags(ctx, list); |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame^] | 757 | mCachedFrame.updateCounts(mCurrentFrame); |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 758 | |
| 759 | if(isDebug()) { |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame^] | 760 | ALOGD("GEOMETRY change: %d", (list->flags & HWC_GEOMETRY_CHANGED)); |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 761 | android::String8 sDump(""); |
| 762 | dump(sDump); |
| 763 | ALOGE("%s",sDump.string()); |
| 764 | } |
| 765 | |
| 766 | return mCurrentFrame.fbZ; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 767 | } |
| 768 | |
| 769 | //=============MDPCompLowRes=================================================== |
| 770 | |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 771 | /* |
| 772 | * Configures pipe(s) for MDP composition |
| 773 | */ |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 774 | int MDPCompLowRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer, |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 775 | PipeLayerPair& PipeLayerPair) { |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 776 | MdpPipeInfoLowRes& mdp_info = |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 777 | *(static_cast<MdpPipeInfoLowRes*>(PipeLayerPair.pipeInfo)); |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 778 | eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION; |
| 779 | eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder); |
| 780 | eIsFg isFg = IS_FG_OFF; |
| 781 | eDest dest = mdp_info.index; |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 782 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 783 | ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d", |
| 784 | __FUNCTION__, layer, zOrder, dest); |
| 785 | |
| 786 | return configureLowRes(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest, |
| 787 | &PipeLayerPair.rot); |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 788 | } |
| 789 | |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 790 | int MDPCompLowRes::pipesNeeded(hwc_context_t *ctx, |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 791 | hwc_display_contents_1_t* list) { |
| 792 | return mCurrentFrame.mdpCount; |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 793 | } |
| 794 | |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 795 | bool MDPCompLowRes::allocLayerPipes(hwc_context_t *ctx, |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 796 | hwc_display_contents_1_t* list) { |
| 797 | if(isYuvPresent(ctx, mDpy)) { |
| 798 | int nYuvCount = ctx->listStats[mDpy].yuvCount; |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 799 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 800 | for(int index = 0; index < nYuvCount ; index ++) { |
| 801 | int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index]; |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 802 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 803 | if(mCurrentFrame.isFBComposed[nYuvIndex]) |
| 804 | continue; |
Jeykumar Sankaran | cf53700 | 2013-01-21 21:19:15 -0800 | [diff] [blame] | 805 | |
Jeykumar Sankaran | cf53700 | 2013-01-21 21:19:15 -0800 | [diff] [blame] | 806 | hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex]; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 807 | |
| 808 | int mdpIndex = mCurrentFrame.layerToMDP[nYuvIndex]; |
| 809 | |
| 810 | PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex]; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 811 | info.pipeInfo = new MdpPipeInfoLowRes; |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 812 | info.rot = NULL; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 813 | MdpPipeInfoLowRes& pipe_info = *(MdpPipeInfoLowRes*)info.pipeInfo; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 814 | |
Jeykumar Sankaran | cf53700 | 2013-01-21 21:19:15 -0800 | [diff] [blame] | 815 | pipe_info.index = getMdpPipe(ctx, MDPCOMP_OV_VG); |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 816 | if(pipe_info.index == ovutils::OV_INVALID) { |
Jeykumar Sankaran | cf53700 | 2013-01-21 21:19:15 -0800 | [diff] [blame] | 817 | ALOGD_IF(isDebug(), "%s: Unable to get pipe for Videos", |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 818 | __FUNCTION__); |
Jeykumar Sankaran | cf53700 | 2013-01-21 21:19:15 -0800 | [diff] [blame] | 819 | return false; |
| 820 | } |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 821 | } |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 822 | } |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 823 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 824 | for(int index = 0 ; index < mCurrentFrame.layerCount; index++ ) { |
| 825 | if(mCurrentFrame.isFBComposed[index]) continue; |
Jeykumar Sankaran | cf53700 | 2013-01-21 21:19:15 -0800 | [diff] [blame] | 826 | hwc_layer_1_t* layer = &list->hwLayers[index]; |
| 827 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
| 828 | |
| 829 | if(isYuvBuffer(hnd)) |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 830 | continue; |
| 831 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 832 | int mdpIndex = mCurrentFrame.layerToMDP[index]; |
| 833 | |
| 834 | PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex]; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 835 | info.pipeInfo = new MdpPipeInfoLowRes; |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 836 | info.rot = NULL; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 837 | MdpPipeInfoLowRes& pipe_info = *(MdpPipeInfoLowRes*)info.pipeInfo; |
| 838 | |
Jeykumar Sankaran | a37fdbf | 2013-03-06 18:59:28 -0800 | [diff] [blame] | 839 | ePipeType type = MDPCOMP_OV_ANY; |
| 840 | |
Saurabh Shah | 85234ec | 2013-04-12 17:09:00 -0700 | [diff] [blame] | 841 | if(!qhwc::needsScaling(layer) |
| 842 | && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE |
| 843 | && ctx->mMDP.version >= qdutils::MDSS_V5) { |
Jeykumar Sankaran | a37fdbf | 2013-03-06 18:59:28 -0800 | [diff] [blame] | 844 | type = MDPCOMP_OV_DMA; |
| 845 | } |
| 846 | |
| 847 | pipe_info.index = getMdpPipe(ctx, type); |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 848 | if(pipe_info.index == ovutils::OV_INVALID) { |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 849 | ALOGD_IF(isDebug(), "%s: Unable to get pipe for UI", __FUNCTION__); |
| 850 | return false; |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 851 | } |
| 852 | } |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 853 | return true; |
| 854 | } |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 855 | |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 856 | bool MDPCompLowRes::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) { |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 857 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 858 | if(!isEnabled()) { |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 859 | ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__); |
| 860 | return true; |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 861 | } |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 862 | |
| 863 | if(!ctx || !list) { |
| 864 | ALOGE("%s: invalid contxt or list",__FUNCTION__); |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 865 | return false; |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 866 | } |
| 867 | |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 868 | /* reset Invalidator */ |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 869 | if(idleInvalidator && mCurrentFrame.mdpCount) |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 870 | idleInvalidator->markForSleep(); |
| 871 | |
| 872 | overlay::Overlay& ov = *ctx->mOverlay; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 873 | LayerProp *layerProp = ctx->layerProp[mDpy]; |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 874 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 875 | int numHwLayers = ctx->listStats[mDpy].numAppLayers; |
| 876 | for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ ) |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 877 | { |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 878 | if(mCurrentFrame.isFBComposed[i]) continue; |
| 879 | |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 880 | hwc_layer_1_t *layer = &list->hwLayers[i]; |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 881 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
| 882 | if(!hnd) { |
| 883 | ALOGE("%s handle null", __FUNCTION__); |
| 884 | return false; |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 885 | } |
| 886 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 887 | int mdpIndex = mCurrentFrame.layerToMDP[i]; |
| 888 | |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 889 | MdpPipeInfoLowRes& pipe_info = |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 890 | *(MdpPipeInfoLowRes*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 891 | ovutils::eDest dest = pipe_info.index; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 892 | if(dest == ovutils::OV_INVALID) { |
| 893 | ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest); |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 894 | return false; |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 895 | } |
| 896 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 897 | if(!(layerProp[i].mFlags & HWC_MDPCOMP)) { |
| 898 | continue; |
| 899 | } |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 900 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 901 | ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \ |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 902 | using pipe: %d", __FUNCTION__, layer, |
| 903 | hnd, dest ); |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 904 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 905 | int fd = hnd->fd; |
| 906 | uint32_t offset = hnd->offset; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 907 | Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot; |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 908 | if(rot) { |
| 909 | if(!rot->queueBuffer(fd, offset)) |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 910 | return false; |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 911 | fd = rot->getDstMemId(); |
| 912 | offset = rot->getDstOffset(); |
| 913 | } |
| 914 | |
| 915 | if (!ov.queueBuffer(fd, offset, dest)) { |
| 916 | ALOGE("%s: queueBuffer failed for external", __FUNCTION__); |
| 917 | return false; |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 918 | } |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 919 | |
| 920 | layerProp[i].mFlags &= ~HWC_MDPCOMP; |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 921 | } |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 922 | return true; |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 923 | } |
| 924 | |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 925 | //=============MDPCompHighRes=================================================== |
| 926 | |
| 927 | int MDPCompHighRes::pipesNeeded(hwc_context_t *ctx, |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 928 | hwc_display_contents_1_t* list) { |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 929 | int pipesNeeded = 0; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 930 | int hw_w = ctx->dpyAttr[mDpy].xres; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 931 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 932 | for(int i = 0; i < mCurrentFrame.layerCount; ++i) { |
| 933 | if(!mCurrentFrame.isFBComposed[i]) { |
| 934 | hwc_layer_1_t* layer = &list->hwLayers[i]; |
| 935 | hwc_rect_t dst = layer->displayFrame; |
| 936 | if(dst.left > hw_w/2) { |
| 937 | pipesNeeded++; |
| 938 | } else if(dst.right <= hw_w/2) { |
| 939 | pipesNeeded++; |
| 940 | } else { |
| 941 | pipesNeeded += 2; |
| 942 | } |
| 943 | } |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 944 | } |
| 945 | return pipesNeeded; |
| 946 | } |
| 947 | |
| 948 | bool MDPCompHighRes::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer, |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 949 | MdpPipeInfoHighRes& pipe_info, |
| 950 | ePipeType type) { |
| 951 | int hw_w = ctx->dpyAttr[mDpy].xres; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 952 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 953 | hwc_rect_t dst = layer->displayFrame; |
| 954 | if(dst.left > hw_w/2) { |
| 955 | pipe_info.lIndex = ovutils::OV_INVALID; |
| 956 | pipe_info.rIndex = getMdpPipe(ctx, type); |
| 957 | if(pipe_info.rIndex == ovutils::OV_INVALID) |
| 958 | return false; |
| 959 | } else if (dst.right <= hw_w/2) { |
| 960 | pipe_info.rIndex = ovutils::OV_INVALID; |
| 961 | pipe_info.lIndex = getMdpPipe(ctx, type); |
| 962 | if(pipe_info.lIndex == ovutils::OV_INVALID) |
| 963 | return false; |
| 964 | } else { |
| 965 | pipe_info.rIndex = getMdpPipe(ctx, type); |
| 966 | pipe_info.lIndex = getMdpPipe(ctx, type); |
| 967 | if(pipe_info.rIndex == ovutils::OV_INVALID || |
| 968 | pipe_info.lIndex == ovutils::OV_INVALID) |
| 969 | return false; |
| 970 | } |
| 971 | return true; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 972 | } |
| 973 | |
| 974 | bool MDPCompHighRes::allocLayerPipes(hwc_context_t *ctx, |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 975 | hwc_display_contents_1_t* list) { |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 976 | overlay::Overlay& ov = *ctx->mOverlay; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 977 | int layer_count = ctx->listStats[mDpy].numAppLayers; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 978 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 979 | if(isYuvPresent(ctx, mDpy)) { |
| 980 | int nYuvCount = ctx->listStats[mDpy].yuvCount; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 981 | |
| 982 | for(int index = 0; index < nYuvCount; index ++) { |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 983 | int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index]; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 984 | hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex]; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 985 | PipeLayerPair& info = mCurrentFrame.mdpToLayer[nYuvIndex]; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 986 | info.pipeInfo = new MdpPipeInfoHighRes; |
Saurabh Shah | 9e3adb2 | 2013-03-26 11:16:27 -0700 | [diff] [blame] | 987 | info.rot = NULL; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 988 | MdpPipeInfoHighRes& pipe_info = *(MdpPipeInfoHighRes*)info.pipeInfo; |
| 989 | if(!acquireMDPPipes(ctx, layer, pipe_info,MDPCOMP_OV_VG)) { |
| 990 | ALOGD_IF(isDebug(),"%s: Unable to get pipe for videos", |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 991 | __FUNCTION__); |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 992 | //TODO: windback pipebook data on fail |
| 993 | return false; |
| 994 | } |
| 995 | pipe_info.zOrder = nYuvIndex; |
| 996 | } |
| 997 | } |
| 998 | |
| 999 | for(int index = 0 ; index < layer_count ; index++ ) { |
| 1000 | hwc_layer_1_t* layer = &list->hwLayers[index]; |
| 1001 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
| 1002 | |
| 1003 | if(isYuvBuffer(hnd)) |
| 1004 | continue; |
| 1005 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1006 | PipeLayerPair& info = mCurrentFrame.mdpToLayer[index]; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1007 | info.pipeInfo = new MdpPipeInfoHighRes; |
Saurabh Shah | 9e3adb2 | 2013-03-26 11:16:27 -0700 | [diff] [blame] | 1008 | info.rot = NULL; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1009 | MdpPipeInfoHighRes& pipe_info = *(MdpPipeInfoHighRes*)info.pipeInfo; |
| 1010 | |
| 1011 | ePipeType type = MDPCOMP_OV_ANY; |
| 1012 | |
Saurabh Shah | 85234ec | 2013-04-12 17:09:00 -0700 | [diff] [blame] | 1013 | if(!qhwc::needsScaling(layer) |
| 1014 | && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE |
| 1015 | && ctx->mMDP.version >= qdutils::MDSS_V5) |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1016 | type = MDPCOMP_OV_DMA; |
| 1017 | |
| 1018 | if(!acquireMDPPipes(ctx, layer, pipe_info, type)) { |
| 1019 | ALOGD_IF(isDebug(), "%s: Unable to get pipe for UI", __FUNCTION__); |
| 1020 | //TODO: windback pipebook data on fail |
| 1021 | return false; |
| 1022 | } |
| 1023 | pipe_info.zOrder = index; |
| 1024 | } |
| 1025 | return true; |
| 1026 | } |
| 1027 | /* |
| 1028 | * Configures pipe(s) for MDP composition |
| 1029 | */ |
| 1030 | int MDPCompHighRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer, |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1031 | PipeLayerPair& PipeLayerPair) { |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1032 | MdpPipeInfoHighRes& mdp_info = |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1033 | *(static_cast<MdpPipeInfoHighRes*>(PipeLayerPair.pipeInfo)); |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1034 | eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder); |
| 1035 | eIsFg isFg = IS_FG_OFF; |
| 1036 | eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION; |
| 1037 | eDest lDest = mdp_info.lIndex; |
| 1038 | eDest rDest = mdp_info.rIndex; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1039 | |
| 1040 | ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d" |
| 1041 | "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest); |
| 1042 | |
| 1043 | return configureHighRes(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest, |
| 1044 | rDest, &PipeLayerPair.rot); |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1045 | } |
| 1046 | |
| 1047 | bool MDPCompHighRes::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) { |
| 1048 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1049 | if(!isEnabled()) { |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1050 | ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__); |
| 1051 | return true; |
| 1052 | } |
| 1053 | |
| 1054 | if(!ctx || !list) { |
| 1055 | ALOGE("%s: invalid contxt or list",__FUNCTION__); |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 1056 | return false; |
| 1057 | } |
| 1058 | |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1059 | /* reset Invalidator */ |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1060 | if(idleInvalidator && mCurrentFrame.mdpCount) |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1061 | idleInvalidator->markForSleep(); |
| 1062 | |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 1063 | overlay::Overlay& ov = *ctx->mOverlay; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1064 | LayerProp *layerProp = ctx->layerProp[mDpy]; |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 1065 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1066 | int numHwLayers = ctx->listStats[mDpy].numAppLayers; |
| 1067 | for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ ) |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1068 | { |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1069 | if(mCurrentFrame.isFBComposed[i]) continue; |
| 1070 | |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1071 | hwc_layer_1_t *layer = &list->hwLayers[i]; |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1072 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
| 1073 | if(!hnd) { |
| 1074 | ALOGE("%s handle null", __FUNCTION__); |
| 1075 | return false; |
| 1076 | } |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1077 | |
| 1078 | if(!(layerProp[i].mFlags & HWC_MDPCOMP)) { |
| 1079 | continue; |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 1080 | } |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 1081 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1082 | int mdpIndex = mCurrentFrame.layerToMDP[i]; |
| 1083 | |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1084 | MdpPipeInfoHighRes& pipe_info = |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1085 | *(MdpPipeInfoHighRes*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo; |
| 1086 | Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot; |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1087 | |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1088 | ovutils::eDest indexL = pipe_info.lIndex; |
| 1089 | ovutils::eDest indexR = pipe_info.rIndex; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1090 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1091 | int fd = hnd->fd; |
| 1092 | int offset = hnd->offset; |
| 1093 | |
| 1094 | if(rot) { |
| 1095 | rot->queueBuffer(fd, offset); |
| 1096 | fd = rot->getDstMemId(); |
| 1097 | offset = rot->getDstOffset(); |
| 1098 | } |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 1099 | |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1100 | //************* play left mixer ********** |
| 1101 | if(indexL != ovutils::OV_INVALID) { |
| 1102 | ovutils::eDest destL = (ovutils::eDest)indexL; |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1103 | ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \ |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1104 | using pipe: %d", __FUNCTION__, layer, hnd, indexL ); |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1105 | if (!ov.queueBuffer(fd, offset, destL)) { |
| 1106 | ALOGE("%s: queueBuffer failed for left mixer", __FUNCTION__); |
| 1107 | return false; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1108 | } |
| 1109 | } |
| 1110 | |
| 1111 | //************* play right mixer ********** |
| 1112 | if(indexR != ovutils::OV_INVALID) { |
| 1113 | ovutils::eDest destR = (ovutils::eDest)indexR; |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1114 | ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \ |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1115 | using pipe: %d", __FUNCTION__, layer, hnd, indexR ); |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1116 | if (!ov.queueBuffer(fd, offset, destR)) { |
| 1117 | ALOGE("%s: queueBuffer failed for right mixer", __FUNCTION__); |
| 1118 | return false; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1119 | } |
| 1120 | } |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1121 | |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1122 | layerProp[i].mFlags &= ~HWC_MDPCOMP; |
| 1123 | } |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1124 | |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1125 | return true; |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 1126 | } |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 1127 | }; //namespace |
| 1128 | |