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 | |
Saurabh Shah | 4fdde76 | 2013-04-30 18:47:33 -0700 | [diff] [blame] | 19 | #include <math.h> |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 20 | #include "hwc_mdpcomp.h" |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 21 | #include <sys/ioctl.h> |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 22 | #include "external.h" |
Ramkumar Radhakrishnan | 47573e2 | 2012-11-07 11:36:41 -0800 | [diff] [blame] | 23 | #include "qdMetaData.h" |
Ramkumar Radhakrishnan | 288f8c7 | 2013-01-15 11:37:54 -0800 | [diff] [blame] | 24 | #include "mdp_version.h" |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 25 | #include <overlayRotator.h> |
| 26 | |
Saurabh Shah | 85234ec | 2013-04-12 17:09:00 -0700 | [diff] [blame] | 27 | using namespace overlay; |
Saurabh Shah | bd2d083 | 2013-04-04 14:33:08 -0700 | [diff] [blame] | 28 | using namespace qdutils; |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 29 | using namespace overlay::utils; |
| 30 | namespace ovutils = overlay::utils; |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 31 | |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 32 | namespace qhwc { |
| 33 | |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 34 | //==============MDPComp======================================================== |
| 35 | |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 36 | IdleInvalidator *MDPComp::idleInvalidator = NULL; |
| 37 | bool MDPComp::sIdleFallBack = false; |
| 38 | bool MDPComp::sDebugLogs = false; |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 39 | bool MDPComp::sEnabled = false; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 40 | int MDPComp::sMaxPipesPerMixer = MAX_PIPES_PER_MIXER; |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 41 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 42 | MDPComp* MDPComp::getObject(const int& width, int dpy) { |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 43 | if(width <= MAX_DISPLAY_DIM) { |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 44 | return new MDPCompLowRes(dpy); |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 45 | } else { |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 46 | return new MDPCompHighRes(dpy); |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 47 | } |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 48 | } |
| 49 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 50 | MDPComp::MDPComp(int dpy):mDpy(dpy){}; |
| 51 | |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 52 | void MDPComp::dump(android::String8& buf) |
| 53 | { |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 54 | dumpsys_log(buf,"HWC Map for Dpy: %s \n", |
| 55 | mDpy ? "\"EXTERNAL\"" : "\"PRIMARY\""); |
| 56 | dumpsys_log(buf,"PREV_FRAME: layerCount:%2d mdpCount:%2d \ |
| 57 | cacheCount:%2d \n", mCachedFrame.layerCount, |
| 58 | mCachedFrame.mdpCount, mCachedFrame.cacheCount); |
| 59 | dumpsys_log(buf,"CURR_FRAME: layerCount:%2d mdpCount:%2d \ |
| 60 | fbCount:%2d \n", mCurrentFrame.layerCount, |
| 61 | mCurrentFrame.mdpCount, mCurrentFrame.fbCount); |
| 62 | dumpsys_log(buf,"needsFBRedraw:%3s pipesUsed:%2d MaxPipesPerMixer: %d \n", |
| 63 | (mCurrentFrame.needsRedraw? "YES" : "NO"), |
| 64 | mCurrentFrame.mdpCount, sMaxPipesPerMixer); |
| 65 | dumpsys_log(buf," --------------------------------------------- \n"); |
| 66 | dumpsys_log(buf," listIdx | cached? | mdpIndex | comptype | Z \n"); |
| 67 | dumpsys_log(buf," --------------------------------------------- \n"); |
| 68 | for(int index = 0; index < mCurrentFrame.layerCount; index++ ) |
| 69 | dumpsys_log(buf," %7d | %7s | %8d | %9s | %2d \n", |
| 70 | index, |
| 71 | (mCurrentFrame.isFBComposed[index] ? "YES" : "NO"), |
| 72 | mCurrentFrame.layerToMDP[index], |
| 73 | (mCurrentFrame.isFBComposed[index] ? |
| 74 | (mCurrentFrame.needsRedraw ? "GLES" : "CACHE") : "MDP"), |
| 75 | (mCurrentFrame.isFBComposed[index] ? mCurrentFrame.fbZ : |
| 76 | mCurrentFrame.mdpToLayer[mCurrentFrame.layerToMDP[index]].pipeInfo->zOrder)); |
| 77 | dumpsys_log(buf,"\n"); |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | bool MDPComp::init(hwc_context_t *ctx) { |
| 81 | |
| 82 | if(!ctx) { |
| 83 | ALOGE("%s: Invalid hwc context!!",__FUNCTION__); |
| 84 | return false; |
| 85 | } |
| 86 | |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 87 | char property[PROPERTY_VALUE_MAX]; |
| 88 | |
| 89 | sEnabled = false; |
| 90 | if((property_get("persist.hwc.mdpcomp.enable", property, NULL) > 0) && |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 91 | (!strncmp(property, "1", PROPERTY_VALUE_MAX ) || |
| 92 | (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) { |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 93 | sEnabled = true; |
Xiaoming Zhou | 944e02e | 2013-05-01 20:54:03 -0400 | [diff] [blame] | 94 | if(!setupBasePipe(ctx)) { |
| 95 | ALOGE("%s: Failed to setup primary base pipe", __FUNCTION__); |
| 96 | return false; |
| 97 | } |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 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; |
Saurabh Shah | 2f3895f | 2013-05-02 10:13:31 -0700 | [diff] [blame] | 225 | needsRedraw = true; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 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 | |
Sravan Kumar D.V.N | ad5d929 | 2013-04-24 14:23:04 +0530 | [diff] [blame] | 266 | bool MDPComp::isValidDimension(hwc_context_t *ctx, hwc_layer_1_t *layer) { |
Saurabh Shah | 4fdde76 | 2013-04-30 18:47:33 -0700 | [diff] [blame] | 267 | const int dpy = HWC_DISPLAY_PRIMARY; |
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 | |
Saurabh Shah | 4fdde76 | 2013-04-30 18:47:33 -0700 | [diff] [blame] | 278 | hwc_rect_t crop = layer->sourceCrop; |
| 279 | hwc_rect_t dst = layer->displayFrame; |
Jeykumar Sankaran | c18dbc2 | 2013-02-08 14:29:44 -0800 | [diff] [blame] | 280 | |
| 281 | if(dst.left < 0 || dst.top < 0 || dst.right > hw_w || dst.bottom > hw_h) { |
Saurabh Shah | 4fdde76 | 2013-04-30 18:47:33 -0700 | [diff] [blame] | 282 | hwc_rect_t scissor = {0, 0, hw_w, hw_h }; |
| 283 | qhwc::calculate_crop_rects(crop, dst, scissor, layer->transform); |
Jeykumar Sankaran | c18dbc2 | 2013-02-08 14:29:44 -0800 | [diff] [blame] | 284 | } |
| 285 | |
Saurabh Shah | 4fdde76 | 2013-04-30 18:47:33 -0700 | [diff] [blame] | 286 | int crop_w = crop.right - crop.left; |
| 287 | int crop_h = crop.bottom - crop.top; |
| 288 | int dst_w = dst.right - dst.left; |
| 289 | int dst_h = dst.bottom - dst.top; |
| 290 | float w_dscale = ceilf((float)crop_w / (float)dst_w); |
| 291 | float h_dscale = ceilf((float)crop_h / (float)dst_h); |
| 292 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 293 | /* Workaround for MDP HW limitation in DSI command mode panels where |
| 294 | * FPS will not go beyond 30 if buffers on RGB pipes are of width or height |
| 295 | * less than 5 pixels |
Sravan Kumar D.V.N | ad5d929 | 2013-04-24 14:23:04 +0530 | [diff] [blame] | 296 | * There also is a HW limilation in MDP, minimum block size is 2x2 |
| 297 | * Fallback to GPU if height is less than 2. |
| 298 | */ |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 299 | if((crop_w < 5)||(crop_h < 5)) |
Jeykumar Sankaran | c18dbc2 | 2013-02-08 14:29:44 -0800 | [diff] [blame] | 300 | return false; |
| 301 | |
Saurabh Shah | 4fdde76 | 2013-04-30 18:47:33 -0700 | [diff] [blame] | 302 | const uint32_t downscale = |
| 303 | qdutils::MDPVersion::getInstance().getMaxMDPDownscale(); |
| 304 | if(ctx->mMDP.version >= qdutils::MDSS_V5) { |
| 305 | /* Workaround for downscales larger than 4x. |
| 306 | * Will be removed once decimator block is enabled for MDSS |
| 307 | */ |
| 308 | if(!qdutils::MDPVersion::getInstance().supportsDecimation()) { |
| 309 | if(crop_w > MAX_DISPLAY_DIM || w_dscale > downscale || |
| 310 | h_dscale > downscale) |
| 311 | return false; |
| 312 | } else { |
| 313 | if(w_dscale > 64 || h_dscale > 64) |
| 314 | return false; |
| 315 | } |
| 316 | } else { //A-family |
| 317 | if(w_dscale > downscale || h_dscale > downscale) |
| 318 | return false; |
| 319 | } |
| 320 | |
Jeykumar Sankaran | c18dbc2 | 2013-02-08 14:29:44 -0800 | [diff] [blame] | 321 | return true; |
| 322 | } |
| 323 | |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 324 | ovutils::eDest MDPComp::getMdpPipe(hwc_context_t *ctx, ePipeType type) { |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 325 | overlay::Overlay& ov = *ctx->mOverlay; |
| 326 | ovutils::eDest mdp_pipe = ovutils::OV_INVALID; |
| 327 | |
| 328 | switch(type) { |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 329 | case MDPCOMP_OV_DMA: |
| 330 | mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_DMA, mDpy); |
| 331 | if(mdp_pipe != ovutils::OV_INVALID) { |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 332 | return mdp_pipe; |
| 333 | } |
| 334 | case MDPCOMP_OV_ANY: |
| 335 | case MDPCOMP_OV_RGB: |
| 336 | mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy); |
| 337 | if(mdp_pipe != ovutils::OV_INVALID) { |
| 338 | return mdp_pipe; |
| 339 | } |
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(type == MDPCOMP_OV_RGB) { |
| 342 | //Requested only for RGB pipe |
| 343 | break; |
| 344 | } |
| 345 | case MDPCOMP_OV_VG: |
| 346 | return ov.nextPipe(ovutils::OV_MDP_PIPE_VG, mDpy); |
| 347 | default: |
| 348 | ALOGE("%s: Invalid pipe type",__FUNCTION__); |
| 349 | return ovutils::OV_INVALID; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 350 | }; |
| 351 | return ovutils::OV_INVALID; |
| 352 | } |
| 353 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 354 | bool MDPComp::isFrameDoable(hwc_context_t *ctx) { |
| 355 | int numAppLayers = ctx->listStats[mDpy].numAppLayers; |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 356 | bool ret = true; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 357 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 358 | if(!isEnabled()) { |
| 359 | ALOGD_IF(isDebug(),"%s: MDP Comp. not enabled.", __FUNCTION__); |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 360 | ret = false; |
| 361 | } else if(ctx->mExtDispConfiguring) { |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 362 | ALOGD_IF( isDebug(),"%s: External Display connection is pending", |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 363 | __FUNCTION__); |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 364 | ret = false; |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 365 | } else if(ctx->isPaddingRound) { |
Saurabh Shah | 0ceeb6a | 2013-04-23 10:46:07 -0700 | [diff] [blame] | 366 | ctx->isPaddingRound = false; |
| 367 | ALOGD_IF(isDebug(), "%s: padding round",__FUNCTION__); |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 368 | ret = false; |
Ramkumar Radhakrishnan | e661f96 | 2013-06-05 17:21:38 -0700 | [diff] [blame] | 369 | } else if(numAppLayers > MAX_NUM_APP_LAYERS) { |
| 370 | ALOGD_IF(isDebug(), "%s: Number of App layers exceeded the limit ", |
| 371 | __FUNCTION__); |
| 372 | ret = false; |
Saurabh Shah | 0ceeb6a | 2013-04-23 10:46:07 -0700 | [diff] [blame] | 373 | } |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 374 | return ret; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | /* Checks for conditions where all the layers marked for MDP comp cannot be |
| 378 | * bypassed. On such conditions we try to bypass atleast YUV layers */ |
| 379 | bool MDPComp::isFullFrameDoable(hwc_context_t *ctx, |
| 380 | hwc_display_contents_1_t* list){ |
| 381 | |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 382 | const int numAppLayers = ctx->listStats[mDpy].numAppLayers; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 383 | |
Saurabh Shah | 2d998a9 | 2013-05-14 17:55:58 -0700 | [diff] [blame] | 384 | if(sIdleFallBack) { |
| 385 | ALOGD_IF(isDebug(), "%s: Idle fallback dpy %d",__FUNCTION__, mDpy); |
| 386 | return false; |
| 387 | } |
| 388 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 389 | if(mDpy > HWC_DISPLAY_PRIMARY){ |
| 390 | ALOGD_IF(isDebug(), "%s: Cannot support External display(s)", |
| 391 | __FUNCTION__); |
| 392 | return false; |
| 393 | } |
| 394 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 395 | if(isSkipPresent(ctx, mDpy)) { |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 396 | ALOGD_IF(isDebug(),"%s: SKIP present: %d", |
| 397 | __FUNCTION__, |
| 398 | isSkipPresent(ctx, mDpy)); |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 399 | return false; |
| 400 | } |
| 401 | |
Saurabh Shah | 9f084ad | 2013-05-02 11:28:09 -0700 | [diff] [blame] | 402 | if(ctx->listStats[mDpy].needsAlphaScale |
| 403 | && ctx->mMDP.version < qdutils::MDSS_V5) { |
| 404 | ALOGD_IF(isDebug(), "%s: frame needs alpha downscaling",__FUNCTION__); |
| 405 | return false; |
| 406 | } |
| 407 | |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 408 | //MDP composition is not efficient if layer needs rotator. |
| 409 | for(int i = 0; i < numAppLayers; ++i) { |
| 410 | // As MDP h/w supports flip operation, use MDP comp only for |
| 411 | // 180 transforms. Fail for any transform involving 90 (90, 270). |
| 412 | hwc_layer_1_t* layer = &list->hwLayers[i]; |
| 413 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
Jeykumar Sankaran | a37fdbf | 2013-03-06 18:59:28 -0800 | [diff] [blame] | 414 | |
Saurabh Shah | 4fdde76 | 2013-04-30 18:47:33 -0700 | [diff] [blame] | 415 | if((layer->transform & HWC_TRANSFORM_ROT_90) && !isYuvBuffer(hnd)) { |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 416 | ALOGD_IF(isDebug(), "%s: orientation involved",__FUNCTION__); |
| 417 | return false; |
| 418 | } |
| 419 | |
Saurabh Shah | 4fdde76 | 2013-04-30 18:47:33 -0700 | [diff] [blame] | 420 | if(!isValidDimension(ctx,layer)) { |
| 421 | ALOGD_IF(isDebug(), "%s: Buffer is of invalid width", |
| 422 | __FUNCTION__); |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 423 | return false; |
| 424 | } |
| 425 | } |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 426 | |
| 427 | //If all above hard conditions are met we can do full or partial MDP comp. |
| 428 | bool ret = false; |
| 429 | if(fullMDPComp(ctx, list)) { |
| 430 | ret = true; |
| 431 | } else if (partialMDPComp(ctx, list)) { |
| 432 | ret = true; |
| 433 | } |
| 434 | return ret; |
| 435 | } |
| 436 | |
| 437 | bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) { |
| 438 | //Setup mCurrentFrame |
| 439 | mCurrentFrame.mdpCount = mCurrentFrame.layerCount; |
| 440 | mCurrentFrame.fbCount = 0; |
| 441 | mCurrentFrame.fbZ = -1; |
| 442 | memset(&mCurrentFrame.isFBComposed, 0, sizeof(mCurrentFrame.isFBComposed)); |
| 443 | |
| 444 | int mdpCount = mCurrentFrame.mdpCount; |
| 445 | if(mdpCount > sMaxPipesPerMixer) { |
| 446 | ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__); |
| 447 | return false; |
| 448 | } |
| 449 | |
| 450 | int numPipesNeeded = pipesNeeded(ctx, list); |
| 451 | int availPipes = getAvailablePipes(ctx); |
| 452 | |
| 453 | if(numPipesNeeded > availPipes) { |
| 454 | ALOGD_IF(isDebug(), "%s: Insufficient MDP pipes, needed %d, avail %d", |
| 455 | __FUNCTION__, numPipesNeeded, availPipes); |
| 456 | return false; |
| 457 | } |
| 458 | |
| 459 | return true; |
| 460 | } |
| 461 | |
| 462 | bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) |
| 463 | { |
| 464 | int numAppLayers = ctx->listStats[mDpy].numAppLayers; |
| 465 | //Setup mCurrentFrame |
| 466 | mCurrentFrame.reset(numAppLayers); |
| 467 | updateLayerCache(ctx, list); |
| 468 | updateYUV(ctx, list); |
| 469 | batchLayers(); //sets up fbZ also |
| 470 | |
| 471 | int mdpCount = mCurrentFrame.mdpCount; |
| 472 | if(mdpCount > (sMaxPipesPerMixer - 1)) { // -1 since FB is used |
| 473 | ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__); |
| 474 | return false; |
| 475 | } |
| 476 | |
| 477 | int numPipesNeeded = pipesNeeded(ctx, list); |
| 478 | int availPipes = getAvailablePipes(ctx); |
| 479 | |
| 480 | if(numPipesNeeded > availPipes) { |
| 481 | ALOGD_IF(isDebug(), "%s: Insufficient MDP pipes, needed %d, avail %d", |
| 482 | __FUNCTION__, numPipesNeeded, availPipes); |
| 483 | return false; |
| 484 | } |
| 485 | |
| 486 | return true; |
| 487 | } |
| 488 | |
| 489 | bool MDPComp::isOnlyVideoDoable(hwc_context_t *ctx, |
| 490 | hwc_display_contents_1_t* list){ |
| 491 | int numAppLayers = ctx->listStats[mDpy].numAppLayers; |
| 492 | mCurrentFrame.reset(numAppLayers); |
| 493 | updateYUV(ctx, list); |
Saurabh Shah | 4fdde76 | 2013-04-30 18:47:33 -0700 | [diff] [blame] | 494 | int mdpCount = mCurrentFrame.mdpCount; |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 495 | int fbNeeded = int(mCurrentFrame.fbCount != 0); |
| 496 | |
| 497 | if(!isYuvPresent(ctx, mDpy)) { |
| 498 | return false; |
| 499 | } |
| 500 | |
Saurabh Shah | 4fdde76 | 2013-04-30 18:47:33 -0700 | [diff] [blame] | 501 | if(!mdpCount) |
| 502 | return false; |
| 503 | |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 504 | if(mdpCount > (sMaxPipesPerMixer - fbNeeded)) { |
| 505 | ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__); |
| 506 | return false; |
| 507 | } |
| 508 | |
| 509 | int numPipesNeeded = pipesNeeded(ctx, list); |
| 510 | int availPipes = getAvailablePipes(ctx); |
| 511 | if(numPipesNeeded > availPipes) { |
| 512 | ALOGD_IF(isDebug(), "%s: Insufficient MDP pipes, needed %d, avail %d", |
| 513 | __FUNCTION__, numPipesNeeded, availPipes); |
| 514 | return false; |
| 515 | } |
| 516 | |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 517 | return true; |
| 518 | } |
| 519 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 520 | /* Checks for conditions where YUV layers cannot be bypassed */ |
| 521 | bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) { |
Saurabh Shah | e247408 | 2013-05-15 16:32:13 -0700 | [diff] [blame] | 522 | bool extAnimBlockFeature = mDpy && ctx->listStats[mDpy].isDisplayAnimating; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 523 | |
Saurabh Shah | e247408 | 2013-05-15 16:32:13 -0700 | [diff] [blame] | 524 | if(isSkipLayer(layer) && !extAnimBlockFeature) { |
| 525 | ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy); |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 526 | return false; |
| 527 | } |
| 528 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 529 | if(isSecuring(ctx, layer)) { |
| 530 | ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__); |
| 531 | return false; |
| 532 | } |
| 533 | |
Saurabh Shah | 4fdde76 | 2013-04-30 18:47:33 -0700 | [diff] [blame] | 534 | if(!isValidDimension(ctx, layer)) { |
| 535 | ALOGD_IF(isDebug(), "%s: Buffer is of invalid width", |
| 536 | __FUNCTION__); |
| 537 | return false; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 538 | } |
Saurabh Shah | 4fdde76 | 2013-04-30 18:47:33 -0700 | [diff] [blame] | 539 | |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 540 | return true; |
| 541 | } |
| 542 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 543 | void MDPComp::batchLayers() { |
| 544 | /* Idea is to keep as many contiguous non-updating(cached) layers in FB and |
| 545 | * send rest of them through MDP. NEVER mark an updating layer for caching. |
| 546 | * But cached ones can be marked for MDP*/ |
| 547 | |
| 548 | int maxBatchStart = -1; |
| 549 | int maxBatchCount = 0; |
| 550 | |
| 551 | /* All or Nothing is cached. No batching needed */ |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 552 | if(!mCurrentFrame.fbCount) { |
| 553 | mCurrentFrame.fbZ = -1; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 554 | return; |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 555 | } |
| 556 | if(!mCurrentFrame.mdpCount) { |
| 557 | mCurrentFrame.fbZ = 0; |
| 558 | return; |
| 559 | } |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 560 | |
| 561 | /* Search for max number of contiguous (cached) layers */ |
| 562 | int i = 0; |
| 563 | while (i < mCurrentFrame.layerCount) { |
| 564 | int count = 0; |
| 565 | while(mCurrentFrame.isFBComposed[i] && i < mCurrentFrame.layerCount) { |
| 566 | count++; i++; |
| 567 | } |
| 568 | if(count > maxBatchCount) { |
| 569 | maxBatchCount = count; |
| 570 | maxBatchStart = i - count; |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 571 | mCurrentFrame.fbZ = maxBatchStart; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 572 | } |
| 573 | if(i < mCurrentFrame.layerCount) i++; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 574 | } |
| 575 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 576 | /* reset rest of the layers for MDP comp */ |
| 577 | for(int i = 0; i < mCurrentFrame.layerCount; i++) { |
| 578 | if(i != maxBatchStart){ |
| 579 | mCurrentFrame.isFBComposed[i] = false; |
| 580 | } else { |
| 581 | i += maxBatchCount; |
| 582 | } |
| 583 | } |
| 584 | |
| 585 | mCurrentFrame.fbCount = maxBatchCount; |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 586 | mCurrentFrame.mdpCount = mCurrentFrame.layerCount - |
| 587 | mCurrentFrame.fbCount; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 588 | |
| 589 | ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__, |
| 590 | mCurrentFrame.fbCount); |
| 591 | } |
Saurabh Shah | 85234ec | 2013-04-12 17:09:00 -0700 | [diff] [blame] | 592 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 593 | void MDPComp::updateLayerCache(hwc_context_t* ctx, |
| 594 | hwc_display_contents_1_t* list) { |
| 595 | |
| 596 | int numAppLayers = ctx->listStats[mDpy].numAppLayers; |
| 597 | int numCacheableLayers = 0; |
| 598 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 599 | for(int i = 0; i < numAppLayers; i++) { |
| 600 | if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) { |
| 601 | numCacheableLayers++; |
| 602 | mCurrentFrame.isFBComposed[i] = true; |
| 603 | } else { |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 604 | mCurrentFrame.isFBComposed[i] = false; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 605 | mCachedFrame.hnd[i] = list->hwLayers[i].handle; |
| 606 | } |
| 607 | } |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 608 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 609 | mCurrentFrame.fbCount = numCacheableLayers; |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 610 | mCurrentFrame.mdpCount = mCurrentFrame.layerCount - |
| 611 | mCurrentFrame.fbCount; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 612 | ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__, numCacheableLayers); |
| 613 | } |
| 614 | |
| 615 | int MDPComp::getAvailablePipes(hwc_context_t* ctx) { |
| 616 | int numDMAPipes = qdutils::MDPVersion::getInstance().getDMAPipes(); |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 617 | overlay::Overlay& ov = *ctx->mOverlay; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 618 | |
| 619 | int numAvailable = ov.availablePipes(mDpy); |
| 620 | |
| 621 | //Reserve DMA for rotator |
Saurabh Shah | 85234ec | 2013-04-12 17:09:00 -0700 | [diff] [blame] | 622 | if(Overlay::getDMAMode() == Overlay::DMA_BLOCK_MODE) |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 623 | numAvailable -= numDMAPipes; |
| 624 | |
| 625 | //Reserve pipe(s)for FB |
| 626 | if(mCurrentFrame.fbCount) |
| 627 | numAvailable -= pipesForFB(); |
| 628 | |
| 629 | return numAvailable; |
| 630 | } |
| 631 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 632 | void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list) { |
| 633 | |
| 634 | int nYuvCount = ctx->listStats[mDpy].yuvCount; |
Ramkumar Radhakrishnan | 59a1107 | 2013-04-15 16:14:49 -0700 | [diff] [blame] | 635 | if(!nYuvCount && mDpy) { |
| 636 | //Reset "No animation on external display" related parameters. |
| 637 | ctx->mPrevCropVideo.left = ctx->mPrevCropVideo.top = |
| 638 | ctx->mPrevCropVideo.right = ctx->mPrevCropVideo.bottom = 0; |
| 639 | ctx->mPrevDestVideo.left = ctx->mPrevDestVideo.top = |
| 640 | ctx->mPrevDestVideo.right = ctx->mPrevDestVideo.bottom = 0; |
| 641 | ctx->mPrevTransformVideo = 0; |
| 642 | return; |
| 643 | } |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 644 | for(int index = 0;index < nYuvCount; index++){ |
| 645 | int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index]; |
| 646 | hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex]; |
| 647 | |
| 648 | if(!isYUVDoable(ctx, layer)) { |
| 649 | if(!mCurrentFrame.isFBComposed[nYuvIndex]) { |
| 650 | mCurrentFrame.isFBComposed[nYuvIndex] = true; |
| 651 | mCurrentFrame.fbCount++; |
| 652 | } |
| 653 | } else { |
| 654 | if(mCurrentFrame.isFBComposed[nYuvIndex]) { |
| 655 | mCurrentFrame.isFBComposed[nYuvIndex] = false; |
| 656 | mCurrentFrame.fbCount--; |
| 657 | } |
| 658 | } |
| 659 | } |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 660 | |
| 661 | mCurrentFrame.mdpCount = mCurrentFrame.layerCount - |
| 662 | mCurrentFrame.fbCount; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 663 | ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__, |
| 664 | mCurrentFrame.fbCount); |
| 665 | } |
| 666 | |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 667 | 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] | 668 | if(!allocLayerPipes(ctx, list)) { |
| 669 | ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__); |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 670 | return false; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 671 | } |
| 672 | |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 673 | bool fbBatch = false; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 674 | for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount; |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 675 | index++) { |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 676 | if(!mCurrentFrame.isFBComposed[index]) { |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 677 | int mdpIndex = mCurrentFrame.layerToMDP[index]; |
| 678 | hwc_layer_1_t* layer = &list->hwLayers[index]; |
| 679 | |
| 680 | MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo; |
| 681 | cur_pipe->zOrder = mdpNextZOrder++; |
| 682 | |
| 683 | if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){ |
| 684 | ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \ |
| 685 | layer %d",__FUNCTION__, index); |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 686 | return false; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 687 | } |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 688 | } else if(fbBatch == false) { |
| 689 | mdpNextZOrder++; |
| 690 | fbBatch = true; |
| 691 | } |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 692 | } |
| 693 | |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 694 | return true; |
| 695 | } |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 696 | |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 697 | bool MDPComp::programYUV(hwc_context_t *ctx, hwc_display_contents_1_t* list) { |
| 698 | if(!allocLayerPipes(ctx, list)) { |
| 699 | ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__); |
| 700 | return false; |
| 701 | } |
| 702 | //If we are in this block, it means we have yuv + rgb layers both |
| 703 | int mdpIdx = 0; |
| 704 | for (int index = 0; index < mCurrentFrame.layerCount; index++) { |
| 705 | if(!mCurrentFrame.isFBComposed[index]) { |
| 706 | hwc_layer_1_t* layer = &list->hwLayers[index]; |
| 707 | int mdpIndex = mCurrentFrame.layerToMDP[index]; |
| 708 | MdpPipeInfo* cur_pipe = |
| 709 | mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo; |
| 710 | cur_pipe->zOrder = mdpIdx++; |
| 711 | |
| 712 | if(configure(ctx, layer, |
| 713 | mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){ |
| 714 | ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \ |
| 715 | layer %d",__FUNCTION__, index); |
| 716 | return false; |
| 717 | } |
| 718 | } |
| 719 | } |
| 720 | return true; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | 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] | 724 | |
| 725 | //reset old data |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 726 | const int numLayers = ctx->listStats[mDpy].numAppLayers; |
| 727 | mCurrentFrame.reset(numLayers); |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 728 | |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 729 | //Hard conditions, if not met, cannot do MDP comp |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 730 | if(!isFrameDoable(ctx)) { |
| 731 | ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame", |
| 732 | __FUNCTION__); |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 733 | mCurrentFrame.reset(numLayers); |
| 734 | mCachedFrame.cacheAll(list); |
| 735 | mCachedFrame.updateCounts(mCurrentFrame); |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 736 | return 0; |
| 737 | } |
| 738 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 739 | //Check whether layers marked for MDP Composition is actually doable. |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 740 | if(isFullFrameDoable(ctx, list)){ |
Saurabh Shah | 2f3895f | 2013-05-02 10:13:31 -0700 | [diff] [blame] | 741 | mCurrentFrame.map(); |
| 742 | //Acquire and Program MDP pipes |
| 743 | if(!programMDP(ctx, list)) { |
| 744 | mCurrentFrame.reset(numLayers); |
| 745 | mCachedFrame.cacheAll(list); |
| 746 | } else { //Success |
| 747 | //Any change in composition types needs an FB refresh |
| 748 | mCurrentFrame.needsRedraw = false; |
| 749 | if(mCurrentFrame.fbCount && |
| 750 | ((mCurrentFrame.mdpCount != mCachedFrame.mdpCount) || |
| 751 | (mCurrentFrame.fbCount != mCachedFrame.cacheCount) || |
| 752 | (mCurrentFrame.fbZ != mCachedFrame.fbZ) || |
| 753 | (!mCurrentFrame.mdpCount) || |
| 754 | (list->flags & HWC_GEOMETRY_CHANGED) || |
| 755 | isSkipPresent(ctx, mDpy) || |
| 756 | (mDpy > HWC_DISPLAY_PRIMARY))) { |
| 757 | mCurrentFrame.needsRedraw = true; |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 758 | } |
| 759 | } |
| 760 | } else if(isOnlyVideoDoable(ctx, list)) { |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 761 | //All layers marked for MDP comp cannot be bypassed. |
| 762 | //Try to compose atleast YUV layers through MDP comp and let |
| 763 | //all the RGB layers compose in FB |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 764 | //Destination over |
| 765 | mCurrentFrame.fbZ = -1; |
| 766 | if(mCurrentFrame.fbCount) |
| 767 | mCurrentFrame.fbZ = ctx->listStats[mDpy].yuvCount; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 768 | |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 769 | mCurrentFrame.map(); |
| 770 | if(!programYUV(ctx, list)) { |
| 771 | mCurrentFrame.reset(numLayers); |
| 772 | mCachedFrame.cacheAll(list); |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 773 | } |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 774 | } else { |
| 775 | mCurrentFrame.reset(numLayers); |
| 776 | mCachedFrame.cacheAll(list); |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 777 | } |
| 778 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 779 | //UpdateLayerFlags |
| 780 | setMDPCompLayerFlags(ctx, list); |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 781 | mCachedFrame.updateCounts(mCurrentFrame); |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 782 | |
| 783 | if(isDebug()) { |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 784 | ALOGD("GEOMETRY change: %d", (list->flags & HWC_GEOMETRY_CHANGED)); |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 785 | android::String8 sDump(""); |
| 786 | dump(sDump); |
| 787 | ALOGE("%s",sDump.string()); |
| 788 | } |
| 789 | |
| 790 | return mCurrentFrame.fbZ; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 791 | } |
| 792 | |
| 793 | //=============MDPCompLowRes=================================================== |
| 794 | |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 795 | /* |
| 796 | * Configures pipe(s) for MDP composition |
| 797 | */ |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 798 | int MDPCompLowRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer, |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 799 | PipeLayerPair& PipeLayerPair) { |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 800 | MdpPipeInfoLowRes& mdp_info = |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 801 | *(static_cast<MdpPipeInfoLowRes*>(PipeLayerPair.pipeInfo)); |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 802 | eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION; |
| 803 | eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder); |
| 804 | eIsFg isFg = IS_FG_OFF; |
| 805 | eDest dest = mdp_info.index; |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 806 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 807 | ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d", |
| 808 | __FUNCTION__, layer, zOrder, dest); |
| 809 | |
| 810 | return configureLowRes(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest, |
| 811 | &PipeLayerPair.rot); |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 812 | } |
| 813 | |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 814 | int MDPCompLowRes::pipesNeeded(hwc_context_t *ctx, |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 815 | hwc_display_contents_1_t* list) { |
| 816 | return mCurrentFrame.mdpCount; |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 817 | } |
| 818 | |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 819 | bool MDPCompLowRes::allocLayerPipes(hwc_context_t *ctx, |
Saurabh Shah | e51f8ca | 2013-05-06 17:26:16 -0700 | [diff] [blame] | 820 | hwc_display_contents_1_t* list) { |
| 821 | for(int index = 0; index < mCurrentFrame.layerCount; index++) { |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 822 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 823 | if(mCurrentFrame.isFBComposed[index]) continue; |
Saurabh Shah | e51f8ca | 2013-05-06 17:26:16 -0700 | [diff] [blame] | 824 | |
Jeykumar Sankaran | cf53700 | 2013-01-21 21:19:15 -0800 | [diff] [blame] | 825 | hwc_layer_1_t* layer = &list->hwLayers[index]; |
| 826 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 827 | int mdpIndex = mCurrentFrame.layerToMDP[index]; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 828 | PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex]; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 829 | info.pipeInfo = new MdpPipeInfoLowRes; |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 830 | info.rot = NULL; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 831 | MdpPipeInfoLowRes& pipe_info = *(MdpPipeInfoLowRes*)info.pipeInfo; |
Jeykumar Sankaran | a37fdbf | 2013-03-06 18:59:28 -0800 | [diff] [blame] | 832 | ePipeType type = MDPCOMP_OV_ANY; |
| 833 | |
Saurabh Shah | e51f8ca | 2013-05-06 17:26:16 -0700 | [diff] [blame] | 834 | if(isYuvBuffer(hnd)) { |
| 835 | type = MDPCOMP_OV_VG; |
Saurabh Shah | 8a11793 | 2013-05-23 12:48:13 -0700 | [diff] [blame] | 836 | } else if(!qhwc::needsScaling(ctx, layer, mDpy) |
Saurabh Shah | 85234ec | 2013-04-12 17:09:00 -0700 | [diff] [blame] | 837 | && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE |
| 838 | && ctx->mMDP.version >= qdutils::MDSS_V5) { |
Jeykumar Sankaran | a37fdbf | 2013-03-06 18:59:28 -0800 | [diff] [blame] | 839 | type = MDPCOMP_OV_DMA; |
| 840 | } |
| 841 | |
| 842 | pipe_info.index = getMdpPipe(ctx, type); |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 843 | if(pipe_info.index == ovutils::OV_INVALID) { |
Saurabh Shah | e51f8ca | 2013-05-06 17:26:16 -0700 | [diff] [blame] | 844 | ALOGD_IF(isDebug(), "%s: Unable to get pipe type = %d", |
| 845 | __FUNCTION__, (int) type); |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 846 | return false; |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 847 | } |
| 848 | } |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 849 | return true; |
| 850 | } |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 851 | |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 852 | 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] | 853 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 854 | if(!isEnabled()) { |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 855 | ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__); |
| 856 | return true; |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 857 | } |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 858 | |
| 859 | if(!ctx || !list) { |
| 860 | ALOGE("%s: invalid contxt or list",__FUNCTION__); |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 861 | return false; |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 862 | } |
| 863 | |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 864 | /* reset Invalidator */ |
Saurabh Shah | 2d998a9 | 2013-05-14 17:55:58 -0700 | [diff] [blame] | 865 | if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount) |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 866 | idleInvalidator->markForSleep(); |
| 867 | |
| 868 | overlay::Overlay& ov = *ctx->mOverlay; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 869 | LayerProp *layerProp = ctx->layerProp[mDpy]; |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 870 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 871 | int numHwLayers = ctx->listStats[mDpy].numAppLayers; |
| 872 | for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ ) |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 873 | { |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 874 | if(mCurrentFrame.isFBComposed[i]) continue; |
| 875 | |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 876 | hwc_layer_1_t *layer = &list->hwLayers[i]; |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 877 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
| 878 | if(!hnd) { |
| 879 | ALOGE("%s handle null", __FUNCTION__); |
| 880 | return false; |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 881 | } |
| 882 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 883 | int mdpIndex = mCurrentFrame.layerToMDP[i]; |
| 884 | |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 885 | MdpPipeInfoLowRes& pipe_info = |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 886 | *(MdpPipeInfoLowRes*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 887 | ovutils::eDest dest = pipe_info.index; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 888 | if(dest == ovutils::OV_INVALID) { |
| 889 | ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest); |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 890 | return false; |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 891 | } |
| 892 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 893 | if(!(layerProp[i].mFlags & HWC_MDPCOMP)) { |
| 894 | continue; |
| 895 | } |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 896 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 897 | ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \ |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 898 | using pipe: %d", __FUNCTION__, layer, |
| 899 | hnd, dest ); |
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 | int fd = hnd->fd; |
| 902 | uint32_t offset = hnd->offset; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 903 | Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot; |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 904 | if(rot) { |
| 905 | if(!rot->queueBuffer(fd, offset)) |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 906 | return false; |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 907 | fd = rot->getDstMemId(); |
| 908 | offset = rot->getDstOffset(); |
| 909 | } |
| 910 | |
| 911 | if (!ov.queueBuffer(fd, offset, dest)) { |
| 912 | ALOGE("%s: queueBuffer failed for external", __FUNCTION__); |
| 913 | return false; |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 914 | } |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 915 | |
| 916 | layerProp[i].mFlags &= ~HWC_MDPCOMP; |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 917 | } |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 918 | return true; |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 919 | } |
| 920 | |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 921 | //=============MDPCompHighRes=================================================== |
| 922 | |
| 923 | int MDPCompHighRes::pipesNeeded(hwc_context_t *ctx, |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 924 | hwc_display_contents_1_t* list) { |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 925 | int pipesNeeded = 0; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 926 | int hw_w = ctx->dpyAttr[mDpy].xres; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 927 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 928 | for(int i = 0; i < mCurrentFrame.layerCount; ++i) { |
| 929 | if(!mCurrentFrame.isFBComposed[i]) { |
| 930 | hwc_layer_1_t* layer = &list->hwLayers[i]; |
| 931 | hwc_rect_t dst = layer->displayFrame; |
| 932 | if(dst.left > hw_w/2) { |
| 933 | pipesNeeded++; |
| 934 | } else if(dst.right <= hw_w/2) { |
| 935 | pipesNeeded++; |
| 936 | } else { |
| 937 | pipesNeeded += 2; |
| 938 | } |
| 939 | } |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 940 | } |
| 941 | return pipesNeeded; |
| 942 | } |
| 943 | |
| 944 | bool MDPCompHighRes::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer, |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 945 | MdpPipeInfoHighRes& pipe_info, |
| 946 | ePipeType type) { |
| 947 | int hw_w = ctx->dpyAttr[mDpy].xres; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 948 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 949 | hwc_rect_t dst = layer->displayFrame; |
| 950 | if(dst.left > hw_w/2) { |
| 951 | pipe_info.lIndex = ovutils::OV_INVALID; |
| 952 | pipe_info.rIndex = getMdpPipe(ctx, type); |
| 953 | if(pipe_info.rIndex == ovutils::OV_INVALID) |
| 954 | return false; |
| 955 | } else if (dst.right <= hw_w/2) { |
| 956 | pipe_info.rIndex = ovutils::OV_INVALID; |
| 957 | pipe_info.lIndex = getMdpPipe(ctx, type); |
| 958 | if(pipe_info.lIndex == ovutils::OV_INVALID) |
| 959 | return false; |
| 960 | } else { |
| 961 | pipe_info.rIndex = getMdpPipe(ctx, type); |
| 962 | pipe_info.lIndex = getMdpPipe(ctx, type); |
| 963 | if(pipe_info.rIndex == ovutils::OV_INVALID || |
| 964 | pipe_info.lIndex == ovutils::OV_INVALID) |
| 965 | return false; |
| 966 | } |
| 967 | return true; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 968 | } |
| 969 | |
| 970 | bool MDPCompHighRes::allocLayerPipes(hwc_context_t *ctx, |
Saurabh Shah | e51f8ca | 2013-05-06 17:26:16 -0700 | [diff] [blame] | 971 | hwc_display_contents_1_t* list) { |
| 972 | for(int index = 0 ; index < mCurrentFrame.layerCount; index++) { |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 973 | |
Saurabh Shah | e51f8ca | 2013-05-06 17:26:16 -0700 | [diff] [blame] | 974 | if(mCurrentFrame.isFBComposed[index]) continue; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 975 | |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 976 | hwc_layer_1_t* layer = &list->hwLayers[index]; |
| 977 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 978 | PipeLayerPair& info = mCurrentFrame.mdpToLayer[index]; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 979 | info.pipeInfo = new MdpPipeInfoHighRes; |
Saurabh Shah | 9e3adb2 | 2013-03-26 11:16:27 -0700 | [diff] [blame] | 980 | info.rot = NULL; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 981 | MdpPipeInfoHighRes& pipe_info = *(MdpPipeInfoHighRes*)info.pipeInfo; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 982 | ePipeType type = MDPCOMP_OV_ANY; |
| 983 | |
Saurabh Shah | e51f8ca | 2013-05-06 17:26:16 -0700 | [diff] [blame] | 984 | if(isYuvBuffer(hnd)) { |
| 985 | type = MDPCOMP_OV_VG; |
Saurabh Shah | 8a11793 | 2013-05-23 12:48:13 -0700 | [diff] [blame] | 986 | } else if(!qhwc::needsScaling(ctx, layer, mDpy) |
Saurabh Shah | 85234ec | 2013-04-12 17:09:00 -0700 | [diff] [blame] | 987 | && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE |
Saurabh Shah | e51f8ca | 2013-05-06 17:26:16 -0700 | [diff] [blame] | 988 | && ctx->mMDP.version >= qdutils::MDSS_V5) { |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 989 | type = MDPCOMP_OV_DMA; |
Saurabh Shah | e51f8ca | 2013-05-06 17:26:16 -0700 | [diff] [blame] | 990 | } |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 991 | |
| 992 | if(!acquireMDPPipes(ctx, layer, pipe_info, type)) { |
Saurabh Shah | e51f8ca | 2013-05-06 17:26:16 -0700 | [diff] [blame] | 993 | ALOGD_IF(isDebug(), "%s: Unable to get pipe for type = %d", |
| 994 | __FUNCTION__, (int) type); |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 995 | return false; |
| 996 | } |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 997 | } |
| 998 | return true; |
| 999 | } |
| 1000 | /* |
| 1001 | * Configures pipe(s) for MDP composition |
| 1002 | */ |
| 1003 | int MDPCompHighRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer, |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1004 | PipeLayerPair& PipeLayerPair) { |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1005 | MdpPipeInfoHighRes& mdp_info = |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1006 | *(static_cast<MdpPipeInfoHighRes*>(PipeLayerPair.pipeInfo)); |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1007 | eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder); |
| 1008 | eIsFg isFg = IS_FG_OFF; |
| 1009 | eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION; |
| 1010 | eDest lDest = mdp_info.lIndex; |
| 1011 | eDest rDest = mdp_info.rIndex; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1012 | |
| 1013 | ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d" |
| 1014 | "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest); |
| 1015 | |
| 1016 | return configureHighRes(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest, |
| 1017 | rDest, &PipeLayerPair.rot); |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1018 | } |
| 1019 | |
| 1020 | bool MDPCompHighRes::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) { |
| 1021 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1022 | if(!isEnabled()) { |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1023 | ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__); |
| 1024 | return true; |
| 1025 | } |
| 1026 | |
| 1027 | if(!ctx || !list) { |
| 1028 | ALOGE("%s: invalid contxt or list",__FUNCTION__); |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 1029 | return false; |
| 1030 | } |
| 1031 | |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1032 | /* reset Invalidator */ |
Saurabh Shah | 2d998a9 | 2013-05-14 17:55:58 -0700 | [diff] [blame] | 1033 | if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount) |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1034 | idleInvalidator->markForSleep(); |
| 1035 | |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 1036 | overlay::Overlay& ov = *ctx->mOverlay; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1037 | LayerProp *layerProp = ctx->layerProp[mDpy]; |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 1038 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1039 | int numHwLayers = ctx->listStats[mDpy].numAppLayers; |
| 1040 | for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ ) |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1041 | { |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1042 | if(mCurrentFrame.isFBComposed[i]) continue; |
| 1043 | |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1044 | hwc_layer_1_t *layer = &list->hwLayers[i]; |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1045 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
| 1046 | if(!hnd) { |
| 1047 | ALOGE("%s handle null", __FUNCTION__); |
| 1048 | return false; |
| 1049 | } |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1050 | |
| 1051 | if(!(layerProp[i].mFlags & HWC_MDPCOMP)) { |
| 1052 | continue; |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 1053 | } |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 1054 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1055 | int mdpIndex = mCurrentFrame.layerToMDP[i]; |
| 1056 | |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1057 | MdpPipeInfoHighRes& pipe_info = |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1058 | *(MdpPipeInfoHighRes*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo; |
| 1059 | Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot; |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1060 | |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1061 | ovutils::eDest indexL = pipe_info.lIndex; |
| 1062 | ovutils::eDest indexR = pipe_info.rIndex; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1063 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1064 | int fd = hnd->fd; |
| 1065 | int offset = hnd->offset; |
| 1066 | |
| 1067 | if(rot) { |
| 1068 | rot->queueBuffer(fd, offset); |
| 1069 | fd = rot->getDstMemId(); |
| 1070 | offset = rot->getDstOffset(); |
| 1071 | } |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 1072 | |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1073 | //************* play left mixer ********** |
| 1074 | if(indexL != ovutils::OV_INVALID) { |
| 1075 | ovutils::eDest destL = (ovutils::eDest)indexL; |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1076 | ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \ |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1077 | using pipe: %d", __FUNCTION__, layer, hnd, indexL ); |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1078 | if (!ov.queueBuffer(fd, offset, destL)) { |
| 1079 | ALOGE("%s: queueBuffer failed for left mixer", __FUNCTION__); |
| 1080 | return false; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1081 | } |
| 1082 | } |
| 1083 | |
| 1084 | //************* play right mixer ********** |
| 1085 | if(indexR != ovutils::OV_INVALID) { |
| 1086 | ovutils::eDest destR = (ovutils::eDest)indexR; |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1087 | ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \ |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1088 | using pipe: %d", __FUNCTION__, layer, hnd, indexR ); |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1089 | if (!ov.queueBuffer(fd, offset, destR)) { |
| 1090 | ALOGE("%s: queueBuffer failed for right mixer", __FUNCTION__); |
| 1091 | return false; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1092 | } |
| 1093 | } |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1094 | |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1095 | layerProp[i].mFlags &= ~HWC_MDPCOMP; |
| 1096 | } |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1097 | |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1098 | return true; |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 1099 | } |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 1100 | }; //namespace |
| 1101 | |