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" |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame] | 23 | #include "virtual.h" |
Ramkumar Radhakrishnan | 47573e2 | 2012-11-07 11:36:41 -0800 | [diff] [blame] | 24 | #include "qdMetaData.h" |
Ramkumar Radhakrishnan | 288f8c7 | 2013-01-15 11:37:54 -0800 | [diff] [blame] | 25 | #include "mdp_version.h" |
Saurabh Shah | 2a4eb1b | 2013-07-22 16:33:23 -0700 | [diff] [blame] | 26 | #include "hwc_fbupdate.h" |
Saurabh Shah | a9da08f | 2013-07-03 13:27:53 -0700 | [diff] [blame] | 27 | #include "hwc_ad.h" |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 28 | #include <overlayRotator.h> |
| 29 | |
Saurabh Shah | 85234ec | 2013-04-12 17:09:00 -0700 | [diff] [blame] | 30 | using namespace overlay; |
Saurabh Shah | bd2d083 | 2013-04-04 14:33:08 -0700 | [diff] [blame] | 31 | using namespace qdutils; |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 32 | using namespace overlay::utils; |
| 33 | namespace ovutils = overlay::utils; |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 34 | |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 35 | namespace qhwc { |
| 36 | |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 37 | //==============MDPComp======================================================== |
| 38 | |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 39 | IdleInvalidator *MDPComp::idleInvalidator = NULL; |
| 40 | bool MDPComp::sIdleFallBack = false; |
| 41 | bool MDPComp::sDebugLogs = false; |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 42 | bool MDPComp::sEnabled = false; |
Jeykumar Sankaran | 24c199d | 2013-05-24 09:40:36 -0700 | [diff] [blame] | 43 | bool MDPComp::sEnableMixedMode = true; |
Jeykumar Sankaran | 6a9bb9e | 2013-08-01 14:19:26 -0700 | [diff] [blame] | 44 | bool MDPComp::sEnablePartialFrameUpdate = false; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 45 | int MDPComp::sMaxPipesPerMixer = MAX_PIPES_PER_MIXER; |
Saurabh Shah | 8c5c852 | 2013-08-29 17:32:49 -0700 | [diff] [blame] | 46 | float MDPComp::sMaxBw = 2.3f; |
| 47 | uint32_t MDPComp::sCompBytesClaimed = 0; |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 48 | |
Saurabh Shah | 88e4d27 | 2013-09-03 13:31:29 -0700 | [diff] [blame] | 49 | MDPComp* MDPComp::getObject(hwc_context_t *ctx, const int& dpy) { |
| 50 | if(isDisplaySplit(ctx, dpy)) { |
| 51 | return new MDPCompSplit(dpy); |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 52 | } |
Saurabh Shah | 88e4d27 | 2013-09-03 13:31:29 -0700 | [diff] [blame] | 53 | return new MDPCompNonSplit(dpy); |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 54 | } |
| 55 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 56 | MDPComp::MDPComp(int dpy):mDpy(dpy){}; |
| 57 | |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 58 | void MDPComp::dump(android::String8& buf) |
| 59 | { |
Jeykumar Sankaran | 3c6bb04 | 2013-08-15 14:01:04 -0700 | [diff] [blame] | 60 | if(mCurrentFrame.layerCount > MAX_NUM_APP_LAYERS) |
| 61 | return; |
| 62 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 63 | dumpsys_log(buf,"HWC Map for Dpy: %s \n", |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame] | 64 | (mDpy == 0) ? "\"PRIMARY\"" : |
| 65 | (mDpy == 1) ? "\"EXTERNAL\"" : "\"VIRTUAL\""); |
Saurabh Shah | e9bc60f | 2013-08-29 12:58:06 -0700 | [diff] [blame] | 66 | dumpsys_log(buf,"CURR_FRAME: layerCount:%2d mdpCount:%2d " |
| 67 | "fbCount:%2d \n", mCurrentFrame.layerCount, |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 68 | mCurrentFrame.mdpCount, mCurrentFrame.fbCount); |
| 69 | dumpsys_log(buf,"needsFBRedraw:%3s pipesUsed:%2d MaxPipesPerMixer: %d \n", |
| 70 | (mCurrentFrame.needsRedraw? "YES" : "NO"), |
| 71 | mCurrentFrame.mdpCount, sMaxPipesPerMixer); |
| 72 | dumpsys_log(buf," --------------------------------------------- \n"); |
| 73 | dumpsys_log(buf," listIdx | cached? | mdpIndex | comptype | Z \n"); |
| 74 | dumpsys_log(buf," --------------------------------------------- \n"); |
| 75 | for(int index = 0; index < mCurrentFrame.layerCount; index++ ) |
| 76 | dumpsys_log(buf," %7d | %7s | %8d | %9s | %2d \n", |
| 77 | index, |
| 78 | (mCurrentFrame.isFBComposed[index] ? "YES" : "NO"), |
Jeykumar Sankaran | 6a9bb9e | 2013-08-01 14:19:26 -0700 | [diff] [blame] | 79 | mCurrentFrame.layerToMDP[index], |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 80 | (mCurrentFrame.isFBComposed[index] ? |
Jeykumar Sankaran | 6a9bb9e | 2013-08-01 14:19:26 -0700 | [diff] [blame] | 81 | (mCurrentFrame.drop[index] ? "DROP" : |
| 82 | (mCurrentFrame.needsRedraw ? "GLES" : "CACHE")) : "MDP"), |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 83 | (mCurrentFrame.isFBComposed[index] ? mCurrentFrame.fbZ : |
| 84 | mCurrentFrame.mdpToLayer[mCurrentFrame.layerToMDP[index]].pipeInfo->zOrder)); |
| 85 | dumpsys_log(buf,"\n"); |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | bool MDPComp::init(hwc_context_t *ctx) { |
| 89 | |
| 90 | if(!ctx) { |
| 91 | ALOGE("%s: Invalid hwc context!!",__FUNCTION__); |
| 92 | return false; |
| 93 | } |
| 94 | |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 95 | char property[PROPERTY_VALUE_MAX]; |
| 96 | |
| 97 | sEnabled = false; |
| 98 | if((property_get("persist.hwc.mdpcomp.enable", property, NULL) > 0) && |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 99 | (!strncmp(property, "1", PROPERTY_VALUE_MAX ) || |
| 100 | (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) { |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 101 | sEnabled = true; |
| 102 | } |
| 103 | |
Jeykumar Sankaran | 24c199d | 2013-05-24 09:40:36 -0700 | [diff] [blame] | 104 | sEnableMixedMode = true; |
| 105 | if((property_get("debug.mdpcomp.mixedmode.disable", property, NULL) > 0) && |
| 106 | (!strncmp(property, "1", PROPERTY_VALUE_MAX ) || |
| 107 | (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) { |
| 108 | sEnableMixedMode = false; |
| 109 | } |
| 110 | |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 111 | if(property_get("debug.mdpcomp.logs", property, NULL) > 0) { |
| 112 | if(atoi(property) != 0) |
| 113 | sDebugLogs = true; |
| 114 | } |
| 115 | |
Jeykumar Sankaran | 6a9bb9e | 2013-08-01 14:19:26 -0700 | [diff] [blame] | 116 | if(property_get("persist.hwc.partialupdate.enable", property, NULL) > 0) { |
| 117 | if((atoi(property) != 0) && ctx->mMDP.panel == MIPI_CMD_PANEL && |
| 118 | qdutils::MDPVersion::getInstance().is8x74v2()) |
| 119 | sEnablePartialFrameUpdate = true; |
| 120 | } |
| 121 | ALOGE_IF(isDebug(), "%s: Partial Update applicable?: %d",__FUNCTION__, |
| 122 | sEnablePartialFrameUpdate); |
| 123 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 124 | sMaxPipesPerMixer = MAX_PIPES_PER_MIXER; |
Saurabh Shah | 85234ec | 2013-04-12 17:09:00 -0700 | [diff] [blame] | 125 | if(property_get("debug.mdpcomp.maxpermixer", property, "-1") > 0) { |
| 126 | int val = atoi(property); |
| 127 | if(val >= 0) |
| 128 | sMaxPipesPerMixer = min(val, MAX_PIPES_PER_MIXER); |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 129 | } |
| 130 | |
Saurabh Shah | 8c5c852 | 2013-08-29 17:32:49 -0700 | [diff] [blame] | 131 | if(property_get("debug.mdpcomp.bw", property, "0") > 0) { |
| 132 | float val = atof(property); |
| 133 | if(val > 0.0f) { |
| 134 | sMaxBw = val; |
| 135 | } |
| 136 | } |
| 137 | |
Naseer Ahmed | f40f2c8 | 2013-08-14 16:42:40 -0400 | [diff] [blame] | 138 | if(ctx->mMDP.panel != MIPI_CMD_PANEL) { |
| 139 | // Idle invalidation is not necessary on command mode panels |
| 140 | long idle_timeout = DEFAULT_IDLE_TIME; |
| 141 | if(property_get("debug.mdpcomp.idletime", property, NULL) > 0) { |
| 142 | if(atoi(property) != 0) |
| 143 | idle_timeout = atoi(property); |
| 144 | } |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 145 | |
Naseer Ahmed | f40f2c8 | 2013-08-14 16:42:40 -0400 | [diff] [blame] | 146 | //create Idle Invalidator only when not disabled through property |
| 147 | if(idle_timeout != -1) |
| 148 | idleInvalidator = IdleInvalidator::getInstance(); |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 149 | |
Naseer Ahmed | f40f2c8 | 2013-08-14 16:42:40 -0400 | [diff] [blame] | 150 | if(idleInvalidator == NULL) { |
| 151 | ALOGE("%s: failed to instantiate idleInvalidator object", |
| 152 | __FUNCTION__); |
| 153 | } else { |
| 154 | idleInvalidator->init(timeout_handler, ctx, idle_timeout); |
| 155 | } |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 156 | } |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 157 | return true; |
| 158 | } |
| 159 | |
Saurabh Shah | 2a4eb1b | 2013-07-22 16:33:23 -0700 | [diff] [blame] | 160 | void MDPComp::reset(const int& numLayers, hwc_display_contents_1_t* list) { |
| 161 | mCurrentFrame.reset(numLayers); |
| 162 | mCachedFrame.cacheAll(list); |
| 163 | mCachedFrame.updateCounts(mCurrentFrame); |
| 164 | } |
| 165 | |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 166 | void MDPComp::timeout_handler(void *udata) { |
| 167 | struct hwc_context_t* ctx = (struct hwc_context_t*)(udata); |
| 168 | |
| 169 | if(!ctx) { |
| 170 | ALOGE("%s: received empty data in timer callback", __FUNCTION__); |
| 171 | return; |
| 172 | } |
| 173 | |
Jesse Hall | 3be78d9 | 2012-08-21 15:12:23 -0700 | [diff] [blame] | 174 | if(!ctx->proc) { |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 175 | ALOGE("%s: HWC proc not registered", __FUNCTION__); |
| 176 | return; |
| 177 | } |
| 178 | sIdleFallBack = true; |
| 179 | /* Trigger SF to redraw the current frame */ |
Jesse Hall | 3be78d9 | 2012-08-21 15:12:23 -0700 | [diff] [blame] | 180 | ctx->proc->invalidate(ctx->proc); |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 181 | } |
| 182 | |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 183 | void MDPComp::setMDPCompLayerFlags(hwc_context_t *ctx, |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 184 | hwc_display_contents_1_t* list) { |
| 185 | LayerProp *layerProp = ctx->layerProp[mDpy]; |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 186 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 187 | for(int index = 0; index < ctx->listStats[mDpy].numAppLayers; index++) { |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 188 | hwc_layer_1_t* layer = &(list->hwLayers[index]); |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 189 | if(!mCurrentFrame.isFBComposed[index]) { |
| 190 | layerProp[index].mFlags |= HWC_MDPCOMP; |
| 191 | layer->compositionType = HWC_OVERLAY; |
| 192 | layer->hints |= HWC_HINT_CLEAR_FB; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 193 | } else { |
Jeykumar Sankaran | 6a9bb9e | 2013-08-01 14:19:26 -0700 | [diff] [blame] | 194 | /* Drop the layer when its already present in FB OR when it lies |
| 195 | * outside frame's ROI */ |
| 196 | if(!mCurrentFrame.needsRedraw || mCurrentFrame.drop[index]) { |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 197 | layer->compositionType = HWC_OVERLAY; |
Jeykumar Sankaran | 6a9bb9e | 2013-08-01 14:19:26 -0700 | [diff] [blame] | 198 | } |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 199 | } |
| 200 | } |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 201 | } |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 202 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 203 | MDPComp::FrameInfo::FrameInfo() { |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 204 | reset(0); |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 205 | } |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 206 | |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 207 | void MDPComp::FrameInfo::reset(const int& numLayers) { |
| 208 | for(int i = 0 ; i < MAX_PIPES_PER_MIXER && numLayers; i++ ) { |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 209 | if(mdpToLayer[i].pipeInfo) { |
| 210 | delete mdpToLayer[i].pipeInfo; |
| 211 | mdpToLayer[i].pipeInfo = NULL; |
| 212 | //We dont own the rotator |
| 213 | mdpToLayer[i].rot = NULL; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 214 | } |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 215 | } |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 216 | |
| 217 | memset(&mdpToLayer, 0, sizeof(mdpToLayer)); |
| 218 | memset(&layerToMDP, -1, sizeof(layerToMDP)); |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 219 | memset(&isFBComposed, 1, sizeof(isFBComposed)); |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 220 | |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 221 | layerCount = numLayers; |
| 222 | fbCount = numLayers; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 223 | mdpCount = 0; |
Saurabh Shah | 2f3895f | 2013-05-02 10:13:31 -0700 | [diff] [blame] | 224 | needsRedraw = true; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 225 | fbZ = 0; |
| 226 | } |
| 227 | |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 228 | void MDPComp::FrameInfo::map() { |
| 229 | // populate layer and MDP maps |
| 230 | int mdpIdx = 0; |
| 231 | for(int idx = 0; idx < layerCount; idx++) { |
| 232 | if(!isFBComposed[idx]) { |
| 233 | mdpToLayer[mdpIdx].listIndex = idx; |
| 234 | layerToMDP[idx] = mdpIdx++; |
| 235 | } |
| 236 | } |
| 237 | } |
| 238 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 239 | MDPComp::LayerCache::LayerCache() { |
| 240 | reset(); |
| 241 | } |
| 242 | |
| 243 | void MDPComp::LayerCache::reset() { |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 244 | memset(&hnd, 0, sizeof(hnd)); |
Prabhanjan Kandula | 2243aa6 | 2013-10-24 12:58:55 +0530 | [diff] [blame] | 245 | memset(&isFBComposed, true, sizeof(isFBComposed)); |
| 246 | memset(&drop, false, sizeof(drop)); |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 247 | layerCount = 0; |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | void MDPComp::LayerCache::cacheAll(hwc_display_contents_1_t* list) { |
| 251 | const int numAppLayers = list->numHwLayers - 1; |
| 252 | for(int i = 0; i < numAppLayers; i++) { |
| 253 | hnd[i] = list->hwLayers[i].handle; |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | void MDPComp::LayerCache::updateCounts(const FrameInfo& curFrame) { |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 258 | layerCount = curFrame.layerCount; |
Prabhanjan Kandula | 2243aa6 | 2013-10-24 12:58:55 +0530 | [diff] [blame] | 259 | memcpy(&isFBComposed, &curFrame.isFBComposed, sizeof(isFBComposed)); |
| 260 | memcpy(&drop, &curFrame.drop, sizeof(drop)); |
| 261 | } |
| 262 | |
| 263 | bool MDPComp::LayerCache::isSameFrame(const FrameInfo& curFrame) { |
| 264 | if(layerCount != curFrame.layerCount) |
| 265 | return false; |
| 266 | for(int i = 0; i < curFrame.layerCount; i++) { |
| 267 | if((curFrame.isFBComposed[i] != isFBComposed[i]) || |
| 268 | (curFrame.drop[i] != drop[i])) { |
| 269 | return false; |
| 270 | } |
| 271 | } |
| 272 | return true; |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 273 | } |
| 274 | |
Saurabh Shah | e9bc60f | 2013-08-29 12:58:06 -0700 | [diff] [blame] | 275 | bool MDPComp::isSupportedForMDPComp(hwc_context_t *ctx, hwc_layer_1_t* layer) { |
| 276 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
| 277 | if((not isYuvBuffer(hnd) and has90Transform(layer)) or |
| 278 | (not isValidDimension(ctx,layer)) |
| 279 | //More conditions here, SKIP, sRGB+Blend etc |
| 280 | ) { |
| 281 | return false; |
| 282 | } |
| 283 | return true; |
| 284 | } |
| 285 | |
Sravan Kumar D.V.N | ad5d929 | 2013-04-24 14:23:04 +0530 | [diff] [blame] | 286 | bool MDPComp::isValidDimension(hwc_context_t *ctx, hwc_layer_1_t *layer) { |
Saurabh Shah | 4fdde76 | 2013-04-30 18:47:33 -0700 | [diff] [blame] | 287 | const int dpy = HWC_DISPLAY_PRIMARY; |
Jeykumar Sankaran | c18dbc2 | 2013-02-08 14:29:44 -0800 | [diff] [blame] | 288 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
| 289 | |
| 290 | if(!hnd) { |
| 291 | ALOGE("%s: layer handle is NULL", __FUNCTION__); |
| 292 | return false; |
| 293 | } |
| 294 | |
Naseer Ahmed | e850a80 | 2013-09-06 13:12:52 -0400 | [diff] [blame^] | 295 | //XXX: Investigate doing this with pixel phase on MDSS |
| 296 | if(isNonIntegralSourceCrop(layer->sourceCropf)) |
| 297 | return false; |
| 298 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 299 | int hw_w = ctx->dpyAttr[mDpy].xres; |
| 300 | int hw_h = ctx->dpyAttr[mDpy].yres; |
Jeykumar Sankaran | c18dbc2 | 2013-02-08 14:29:44 -0800 | [diff] [blame] | 301 | |
Saurabh Shah | 62e1d73 | 2013-09-17 10:44:05 -0700 | [diff] [blame] | 302 | hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf); |
Saurabh Shah | 4fdde76 | 2013-04-30 18:47:33 -0700 | [diff] [blame] | 303 | hwc_rect_t dst = layer->displayFrame; |
Jeykumar Sankaran | c18dbc2 | 2013-02-08 14:29:44 -0800 | [diff] [blame] | 304 | |
| 305 | 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] | 306 | hwc_rect_t scissor = {0, 0, hw_w, hw_h }; |
| 307 | qhwc::calculate_crop_rects(crop, dst, scissor, layer->transform); |
Jeykumar Sankaran | c18dbc2 | 2013-02-08 14:29:44 -0800 | [diff] [blame] | 308 | } |
| 309 | |
Saurabh Shah | 4fdde76 | 2013-04-30 18:47:33 -0700 | [diff] [blame] | 310 | int crop_w = crop.right - crop.left; |
| 311 | int crop_h = crop.bottom - crop.top; |
| 312 | int dst_w = dst.right - dst.left; |
| 313 | int dst_h = dst.bottom - dst.top; |
| 314 | float w_dscale = ceilf((float)crop_w / (float)dst_w); |
| 315 | float h_dscale = ceilf((float)crop_h / (float)dst_h); |
| 316 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 317 | /* Workaround for MDP HW limitation in DSI command mode panels where |
| 318 | * FPS will not go beyond 30 if buffers on RGB pipes are of width or height |
| 319 | * less than 5 pixels |
Sravan Kumar D.V.N | ad5d929 | 2013-04-24 14:23:04 +0530 | [diff] [blame] | 320 | * There also is a HW limilation in MDP, minimum block size is 2x2 |
| 321 | * Fallback to GPU if height is less than 2. |
| 322 | */ |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 323 | if((crop_w < 5)||(crop_h < 5)) |
Jeykumar Sankaran | c18dbc2 | 2013-02-08 14:29:44 -0800 | [diff] [blame] | 324 | return false; |
| 325 | |
Saurabh Shah | 4fdde76 | 2013-04-30 18:47:33 -0700 | [diff] [blame] | 326 | const uint32_t downscale = |
| 327 | qdutils::MDPVersion::getInstance().getMaxMDPDownscale(); |
| 328 | if(ctx->mMDP.version >= qdutils::MDSS_V5) { |
| 329 | /* Workaround for downscales larger than 4x. |
| 330 | * Will be removed once decimator block is enabled for MDSS |
| 331 | */ |
| 332 | if(!qdutils::MDPVersion::getInstance().supportsDecimation()) { |
| 333 | if(crop_w > MAX_DISPLAY_DIM || w_dscale > downscale || |
| 334 | h_dscale > downscale) |
| 335 | return false; |
| 336 | } else { |
| 337 | if(w_dscale > 64 || h_dscale > 64) |
| 338 | return false; |
| 339 | } |
| 340 | } else { //A-family |
| 341 | if(w_dscale > downscale || h_dscale > downscale) |
| 342 | return false; |
| 343 | } |
| 344 | |
Jeykumar Sankaran | c18dbc2 | 2013-02-08 14:29:44 -0800 | [diff] [blame] | 345 | return true; |
| 346 | } |
| 347 | |
Saurabh Shah | af5f597 | 2013-07-30 13:56:35 -0700 | [diff] [blame] | 348 | ovutils::eDest MDPComp::getMdpPipe(hwc_context_t *ctx, ePipeType type, |
| 349 | int mixer) { |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 350 | overlay::Overlay& ov = *ctx->mOverlay; |
| 351 | ovutils::eDest mdp_pipe = ovutils::OV_INVALID; |
| 352 | |
| 353 | switch(type) { |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 354 | case MDPCOMP_OV_DMA: |
Saurabh Shah | af5f597 | 2013-07-30 13:56:35 -0700 | [diff] [blame] | 355 | mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_DMA, mDpy, mixer); |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 356 | if(mdp_pipe != ovutils::OV_INVALID) { |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 357 | return mdp_pipe; |
| 358 | } |
| 359 | case MDPCOMP_OV_ANY: |
| 360 | case MDPCOMP_OV_RGB: |
Saurabh Shah | af5f597 | 2013-07-30 13:56:35 -0700 | [diff] [blame] | 361 | mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy, mixer); |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 362 | if(mdp_pipe != ovutils::OV_INVALID) { |
| 363 | return mdp_pipe; |
| 364 | } |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 365 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 366 | if(type == MDPCOMP_OV_RGB) { |
| 367 | //Requested only for RGB pipe |
| 368 | break; |
| 369 | } |
| 370 | case MDPCOMP_OV_VG: |
Saurabh Shah | af5f597 | 2013-07-30 13:56:35 -0700 | [diff] [blame] | 371 | return ov.nextPipe(ovutils::OV_MDP_PIPE_VG, mDpy, mixer); |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 372 | default: |
| 373 | ALOGE("%s: Invalid pipe type",__FUNCTION__); |
| 374 | return ovutils::OV_INVALID; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 375 | }; |
| 376 | return ovutils::OV_INVALID; |
| 377 | } |
| 378 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 379 | bool MDPComp::isFrameDoable(hwc_context_t *ctx) { |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 380 | bool ret = true; |
Jeykumar Sankaran | 24c199d | 2013-05-24 09:40:36 -0700 | [diff] [blame] | 381 | const int numAppLayers = ctx->listStats[mDpy].numAppLayers; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 382 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 383 | if(!isEnabled()) { |
| 384 | ALOGD_IF(isDebug(),"%s: MDP Comp. not enabled.", __FUNCTION__); |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 385 | ret = false; |
Saurabh Shah | d4e6585 | 2013-06-17 11:33:53 -0700 | [diff] [blame] | 386 | } else if(qdutils::MDPVersion::getInstance().is8x26() && |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame] | 387 | ctx->mVideoTransFlag && ctx->mVirtualDisplay->isConnected()) { |
Saurabh Shah | d4e6585 | 2013-06-17 11:33:53 -0700 | [diff] [blame] | 388 | //1 Padding round to shift pipes across mixers |
| 389 | ALOGD_IF(isDebug(),"%s: MDP Comp. video transition padding round", |
| 390 | __FUNCTION__); |
| 391 | ret = false; |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame] | 392 | } else if(ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isConfiguring || |
| 393 | ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isConfiguring) { |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 394 | ALOGD_IF( isDebug(),"%s: External Display connection is pending", |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 395 | __FUNCTION__); |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 396 | ret = false; |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 397 | } else if(ctx->isPaddingRound) { |
Saurabh Shah | 0ceeb6a | 2013-04-23 10:46:07 -0700 | [diff] [blame] | 398 | ctx->isPaddingRound = false; |
| 399 | ALOGD_IF(isDebug(), "%s: padding round",__FUNCTION__); |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 400 | ret = false; |
Saurabh Shah | 0ceeb6a | 2013-04-23 10:46:07 -0700 | [diff] [blame] | 401 | } |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 402 | return ret; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 403 | } |
| 404 | |
Jeykumar Sankaran | 6a9bb9e | 2013-08-01 14:19:26 -0700 | [diff] [blame] | 405 | bool MDPComp::validateAndApplyROI(hwc_context_t *ctx, |
| 406 | hwc_display_contents_1_t* list, hwc_rect_t roi) { |
| 407 | int numAppLayers = ctx->listStats[mDpy].numAppLayers; |
| 408 | |
| 409 | if(!isValidRect(roi)) |
| 410 | return false; |
| 411 | |
| 412 | for(int i = 0; i < numAppLayers; i++){ |
| 413 | const hwc_layer_1_t* layer = &list->hwLayers[i]; |
| 414 | |
| 415 | hwc_rect_t dstRect = layer->displayFrame; |
| 416 | hwc_rect_t srcRect = layer->sourceCrop; |
| 417 | int transform = layer->transform; |
| 418 | trimLayer(ctx, mDpy, transform, srcRect, dstRect); |
| 419 | |
| 420 | hwc_rect_t res = getIntersection(roi, dstRect); |
| 421 | |
| 422 | int res_w = res.right - res.left; |
| 423 | int res_h = res.bottom - res.top; |
| 424 | int dst_w = dstRect.right - dstRect.left; |
| 425 | int dst_h = dstRect.bottom - dstRect.top; |
| 426 | |
| 427 | if(!isValidRect(res)) { |
| 428 | mCurrentFrame.drop[i] = true; |
| 429 | mCurrentFrame.dropCount++; |
| 430 | }else { |
| 431 | /* Reset frame ROI when any layer which needs scaling also needs ROI |
| 432 | * cropping */ |
| 433 | if((res_w != dst_w || res_h != dst_h) && |
| 434 | needsScaling (ctx, layer, mDpy)) { |
| 435 | ALOGE("%s: Resetting ROI due to scaling", __FUNCTION__); |
| 436 | memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop)); |
| 437 | mCurrentFrame.dropCount = 0; |
| 438 | return false; |
| 439 | } |
| 440 | } |
| 441 | } |
| 442 | return true; |
| 443 | } |
| 444 | |
| 445 | void MDPComp::generateROI(hwc_context_t *ctx, hwc_display_contents_1_t* list) { |
| 446 | int numAppLayers = ctx->listStats[mDpy].numAppLayers; |
| 447 | |
| 448 | if(!sEnablePartialFrameUpdate) { |
| 449 | return; |
| 450 | } |
| 451 | |
| 452 | if(mDpy || isDisplaySplit(ctx, mDpy)){ |
| 453 | ALOGE_IF(isDebug(), "%s: ROI not supported for" |
| 454 | "the (1) external / virtual display's (2) dual DSI displays", |
| 455 | __FUNCTION__); |
| 456 | return; |
| 457 | } |
| 458 | |
| 459 | if(list->flags & HWC_GEOMETRY_CHANGED) |
| 460 | return; |
| 461 | |
| 462 | struct hwc_rect roi = (struct hwc_rect){0, 0, 0, 0}; |
| 463 | for(int index = 0; index < numAppLayers; index++ ) { |
| 464 | if ((mCachedFrame.hnd[index] != list->hwLayers[index].handle) || |
| 465 | isYuvBuffer((private_handle_t *)list->hwLayers[index].handle)) { |
| 466 | hwc_rect_t dstRect = list->hwLayers[index].displayFrame; |
| 467 | hwc_rect_t srcRect = list->hwLayers[index].sourceCrop; |
| 468 | int transform = list->hwLayers[index].transform; |
| 469 | |
| 470 | /* Intersect against display boundaries */ |
| 471 | trimLayer(ctx, mDpy, transform, srcRect, dstRect); |
| 472 | roi = getUnion(roi, dstRect); |
| 473 | } |
| 474 | } |
| 475 | |
| 476 | if(!validateAndApplyROI(ctx, list, roi)){ |
| 477 | roi = (struct hwc_rect) {0, 0, |
| 478 | (int)ctx->dpyAttr[mDpy].xres, (int)ctx->dpyAttr[mDpy].yres}; |
| 479 | } |
| 480 | |
| 481 | ctx->listStats[mDpy].roi.x = roi.left; |
| 482 | ctx->listStats[mDpy].roi.y = roi.top; |
| 483 | ctx->listStats[mDpy].roi.w = roi.right - roi.left; |
| 484 | ctx->listStats[mDpy].roi.h = roi.bottom - roi.top; |
| 485 | |
| 486 | ALOGD_IF(isDebug(),"%s: generated ROI: [%d, %d, %d, %d]", __FUNCTION__, |
| 487 | roi.left, roi.top, roi.right, roi.bottom); |
| 488 | } |
| 489 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 490 | /* Checks for conditions where all the layers marked for MDP comp cannot be |
| 491 | * bypassed. On such conditions we try to bypass atleast YUV layers */ |
| 492 | bool MDPComp::isFullFrameDoable(hwc_context_t *ctx, |
| 493 | hwc_display_contents_1_t* list){ |
| 494 | |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 495 | const int numAppLayers = ctx->listStats[mDpy].numAppLayers; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 496 | |
Ramkumar Radhakrishnan | ba71338 | 2013-08-30 18:41:07 -0700 | [diff] [blame] | 497 | if(sIdleFallBack && !ctx->listStats[mDpy].secureUI) { |
Saurabh Shah | 2d998a9 | 2013-05-14 17:55:58 -0700 | [diff] [blame] | 498 | ALOGD_IF(isDebug(), "%s: Idle fallback dpy %d",__FUNCTION__, mDpy); |
| 499 | return false; |
| 500 | } |
| 501 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 502 | if(isSkipPresent(ctx, mDpy)) { |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 503 | ALOGD_IF(isDebug(),"%s: SKIP present: %d", |
| 504 | __FUNCTION__, |
| 505 | isSkipPresent(ctx, mDpy)); |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 506 | return false; |
| 507 | } |
| 508 | |
Saurabh Shah | 9f084ad | 2013-05-02 11:28:09 -0700 | [diff] [blame] | 509 | if(ctx->listStats[mDpy].needsAlphaScale |
| 510 | && ctx->mMDP.version < qdutils::MDSS_V5) { |
| 511 | ALOGD_IF(isDebug(), "%s: frame needs alpha downscaling",__FUNCTION__); |
| 512 | return false; |
| 513 | } |
| 514 | |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 515 | for(int i = 0; i < numAppLayers; ++i) { |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 516 | hwc_layer_1_t* layer = &list->hwLayers[i]; |
| 517 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
Jeykumar Sankaran | a37fdbf | 2013-03-06 18:59:28 -0800 | [diff] [blame] | 518 | |
Saurabh Shah | e9bc60f | 2013-08-29 12:58:06 -0700 | [diff] [blame] | 519 | if(isYuvBuffer(hnd) && has90Transform(layer)) { |
| 520 | if(!canUseRotator(ctx, mDpy)) { |
| 521 | ALOGD_IF(isDebug(), "%s: Can't use rotator for dpy %d", |
| 522 | __FUNCTION__, mDpy); |
Amara Venkata Mastan Manoj Kumar | 9d373c0 | 2013-08-20 14:30:09 -0700 | [diff] [blame] | 523 | return false; |
| 524 | } |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 525 | } |
Prabhanjan Kandula | 9fb032a | 2013-06-18 17:37:22 +0530 | [diff] [blame] | 526 | |
| 527 | //For 8x26 with panel width>1k, if RGB layer needs HFLIP fail mdp comp |
| 528 | // may not need it if Gfx pre-rotation can handle all flips & rotations |
| 529 | if(qdutils::MDPVersion::getInstance().is8x26() && |
| 530 | (ctx->dpyAttr[mDpy].xres > 1024) && |
| 531 | (layer->transform & HWC_TRANSFORM_FLIP_H) && |
| 532 | (!isYuvBuffer(hnd))) |
| 533 | return false; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 534 | } |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 535 | |
Saurabh Shah | a9da08f | 2013-07-03 13:27:53 -0700 | [diff] [blame] | 536 | if(ctx->mAD->isDoable()) { |
| 537 | return false; |
| 538 | } |
| 539 | |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 540 | //If all above hard conditions are met we can do full or partial MDP comp. |
| 541 | bool ret = false; |
| 542 | if(fullMDPComp(ctx, list)) { |
| 543 | ret = true; |
Jeykumar Sankaran | 24c199d | 2013-05-24 09:40:36 -0700 | [diff] [blame] | 544 | } else if(partialMDPComp(ctx, list)) { |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 545 | ret = true; |
| 546 | } |
| 547 | return ret; |
| 548 | } |
| 549 | |
| 550 | bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) { |
Saurabh Shah | e9bc60f | 2013-08-29 12:58:06 -0700 | [diff] [blame] | 551 | //Will benefit presentation / secondary-only layer. |
| 552 | if((mDpy > HWC_DISPLAY_PRIMARY) && |
| 553 | (list->numHwLayers - 1) > MAX_SEC_LAYERS) { |
| 554 | ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__); |
| 555 | return false; |
| 556 | } |
| 557 | |
| 558 | const int numAppLayers = ctx->listStats[mDpy].numAppLayers; |
| 559 | for(int i = 0; i < numAppLayers; i++) { |
| 560 | hwc_layer_1_t* layer = &list->hwLayers[i]; |
| 561 | if(not isSupportedForMDPComp(ctx, layer)) { |
| 562 | ALOGD_IF(isDebug(), "%s: Unsupported layer in list",__FUNCTION__); |
| 563 | return false; |
| 564 | } |
| 565 | } |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 566 | mCurrentFrame.fbCount = 0; |
| 567 | mCurrentFrame.fbZ = -1; |
Jeykumar Sankaran | 6a9bb9e | 2013-08-01 14:19:26 -0700 | [diff] [blame] | 568 | memcpy(&mCurrentFrame.isFBComposed, &mCurrentFrame.drop, |
| 569 | sizeof(mCurrentFrame.isFBComposed)); |
| 570 | mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount - |
| 571 | mCurrentFrame.dropCount; |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 572 | |
Jeykumar Sankaran | 6a9bb9e | 2013-08-01 14:19:26 -0700 | [diff] [blame] | 573 | if(mCurrentFrame.mdpCount > sMaxPipesPerMixer) { |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 574 | ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__); |
| 575 | return false; |
| 576 | } |
| 577 | |
Saurabh Shah | af5f597 | 2013-07-30 13:56:35 -0700 | [diff] [blame] | 578 | if(!arePipesAvailable(ctx, list)) { |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 579 | return false; |
| 580 | } |
| 581 | |
Saurabh Shah | 8c5c852 | 2013-08-29 17:32:49 -0700 | [diff] [blame] | 582 | uint32_t size = calcMDPBytesRead(ctx, list); |
| 583 | if(!bandwidthCheck(ctx, size)) { |
| 584 | ALOGD_IF(isDebug(), "%s: Exceeds bandwidth",__FUNCTION__); |
| 585 | return false; |
| 586 | } |
| 587 | |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 588 | return true; |
| 589 | } |
| 590 | |
| 591 | bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) |
| 592 | { |
Jeykumar Sankaran | 24c199d | 2013-05-24 09:40:36 -0700 | [diff] [blame] | 593 | if(!sEnableMixedMode) { |
| 594 | //Mixed mode is disabled. No need to even try caching. |
| 595 | return false; |
| 596 | } |
| 597 | |
Saurabh Shah | 8028e3b | 2013-10-15 12:27:59 -0700 | [diff] [blame] | 598 | bool ret = false; |
| 599 | if(isLoadBasedCompDoable(ctx, list)) { |
| 600 | ret = loadBasedComp(ctx, list); |
| 601 | } |
| 602 | |
| 603 | if(!ret) { |
| 604 | ret = cacheBasedComp(ctx, list); |
| 605 | } |
| 606 | |
| 607 | return ret; |
| 608 | } |
| 609 | |
| 610 | bool MDPComp::cacheBasedComp(hwc_context_t *ctx, |
| 611 | hwc_display_contents_1_t* list) { |
| 612 | int numAppLayers = ctx->listStats[mDpy].numAppLayers; |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 613 | mCurrentFrame.reset(numAppLayers); |
| 614 | updateLayerCache(ctx, list); |
Saurabh Shah | e9bc60f | 2013-08-29 12:58:06 -0700 | [diff] [blame] | 615 | |
| 616 | //If an MDP marked layer is unsupported cannot do partial MDP Comp |
| 617 | for(int i = 0; i < numAppLayers; i++) { |
| 618 | if(!mCurrentFrame.isFBComposed[i]) { |
| 619 | hwc_layer_1_t* layer = &list->hwLayers[i]; |
| 620 | if(not isSupportedForMDPComp(ctx, layer)) { |
| 621 | ALOGD_IF(isDebug(), "%s: Unsupported layer in list", |
| 622 | __FUNCTION__); |
| 623 | return false; |
| 624 | } |
| 625 | } |
| 626 | } |
| 627 | |
Saurabh Shah | 90b7b9b | 2013-09-12 16:36:08 -0700 | [diff] [blame] | 628 | updateYUV(ctx, list, false /*secure only*/); |
Prabhanjan Kandula | 9bd5f64 | 2013-09-25 17:00:36 +0530 | [diff] [blame] | 629 | bool ret = markLayersForCaching(ctx, list); //sets up fbZ also |
Saurabh Shah | e9bc60f | 2013-08-29 12:58:06 -0700 | [diff] [blame] | 630 | if(!ret) { |
| 631 | ALOGD_IF(isDebug(),"%s: batching failed, dpy %d",__FUNCTION__, mDpy); |
| 632 | return false; |
| 633 | } |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 634 | |
| 635 | int mdpCount = mCurrentFrame.mdpCount; |
Saurabh Shah | e9bc60f | 2013-08-29 12:58:06 -0700 | [diff] [blame] | 636 | |
| 637 | //Will benefit cases where a video has non-updating background. |
| 638 | if((mDpy > HWC_DISPLAY_PRIMARY) and |
| 639 | (mdpCount > MAX_SEC_LAYERS)) { |
| 640 | ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__); |
| 641 | return false; |
| 642 | } |
| 643 | |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 644 | if(mdpCount > (sMaxPipesPerMixer - 1)) { // -1 since FB is used |
| 645 | ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__); |
| 646 | return false; |
| 647 | } |
| 648 | |
Saurabh Shah | af5f597 | 2013-07-30 13:56:35 -0700 | [diff] [blame] | 649 | if(!arePipesAvailable(ctx, list)) { |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 650 | return false; |
| 651 | } |
| 652 | |
Saurabh Shah | 8c5c852 | 2013-08-29 17:32:49 -0700 | [diff] [blame] | 653 | uint32_t size = calcMDPBytesRead(ctx, list); |
| 654 | if(!bandwidthCheck(ctx, size)) { |
| 655 | ALOGD_IF(isDebug(), "%s: Exceeds bandwidth",__FUNCTION__); |
| 656 | return false; |
| 657 | } |
| 658 | |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 659 | return true; |
| 660 | } |
| 661 | |
Saurabh Shah | 8028e3b | 2013-10-15 12:27:59 -0700 | [diff] [blame] | 662 | bool MDPComp::loadBasedComp(hwc_context_t *ctx, |
| 663 | hwc_display_contents_1_t* list) { |
| 664 | int numAppLayers = ctx->listStats[mDpy].numAppLayers; |
| 665 | mCurrentFrame.reset(numAppLayers); |
| 666 | |
| 667 | //TODO BatchSize could be optimized further based on available pipes, split |
| 668 | //displays etc. |
| 669 | const int batchSize = numAppLayers - (sMaxPipesPerMixer - 1); |
| 670 | if(batchSize <= 0) { |
| 671 | ALOGD_IF(isDebug(), "%s: Not attempting", __FUNCTION__); |
| 672 | return false; |
| 673 | } |
| 674 | |
| 675 | int minBatchStart = -1; |
| 676 | size_t minBatchPixelCount = SIZE_MAX; |
| 677 | |
| 678 | for(int i = 0; i <= numAppLayers - batchSize; i++) { |
| 679 | uint32_t batchPixelCount = 0; |
| 680 | for(int j = i; j < i + batchSize; j++) { |
| 681 | hwc_layer_1_t* layer = &list->hwLayers[j]; |
| 682 | hwc_rect_t crop = layer->sourceCrop; |
| 683 | batchPixelCount += (crop.right - crop.left) * |
| 684 | (crop.bottom - crop.top); |
| 685 | } |
| 686 | |
| 687 | if(batchPixelCount < minBatchPixelCount) { |
| 688 | minBatchPixelCount = batchPixelCount; |
| 689 | minBatchStart = i; |
| 690 | } |
| 691 | } |
| 692 | |
| 693 | if(minBatchStart < 0) { |
| 694 | ALOGD_IF(isDebug(), "%s: No batch found batchSize %d numAppLayers %d", |
| 695 | __FUNCTION__, batchSize, numAppLayers); |
| 696 | return false; |
| 697 | } |
| 698 | |
| 699 | for(int i = 0; i < numAppLayers; i++) { |
| 700 | if(i < minBatchStart || i >= minBatchStart + batchSize) { |
| 701 | hwc_layer_1_t* layer = &list->hwLayers[i]; |
| 702 | if(not isSupportedForMDPComp(ctx, layer)) { |
| 703 | ALOGD_IF(isDebug(), "%s: MDP unsupported layer found at %d", |
| 704 | __FUNCTION__, i); |
| 705 | return false; |
| 706 | } |
| 707 | mCurrentFrame.isFBComposed[i] = false; |
| 708 | } |
| 709 | } |
| 710 | |
| 711 | mCurrentFrame.fbZ = minBatchStart; |
| 712 | mCurrentFrame.fbCount = batchSize; |
| 713 | mCurrentFrame.mdpCount = mCurrentFrame.layerCount - batchSize; |
| 714 | |
| 715 | if(!arePipesAvailable(ctx, list)) { |
| 716 | return false; |
| 717 | } |
| 718 | |
| 719 | ALOGD_IF(isDebug(), "%s: fbZ %d batchSize %d", |
| 720 | __FUNCTION__, mCurrentFrame.fbZ, batchSize); |
| 721 | return true; |
| 722 | } |
| 723 | |
| 724 | bool MDPComp::isLoadBasedCompDoable(hwc_context_t *ctx, |
| 725 | hwc_display_contents_1_t* list) { |
| 726 | if(mDpy or isSecurePresent(ctx, mDpy) or |
| 727 | not (list->flags & HWC_GEOMETRY_CHANGED)) { |
| 728 | return false; |
| 729 | } |
| 730 | return true; |
| 731 | } |
| 732 | |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 733 | bool MDPComp::isOnlyVideoDoable(hwc_context_t *ctx, |
Saurabh Shah | 90b7b9b | 2013-09-12 16:36:08 -0700 | [diff] [blame] | 734 | hwc_display_contents_1_t* list, bool secureOnly) { |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 735 | int numAppLayers = ctx->listStats[mDpy].numAppLayers; |
Jeykumar Sankaran | 6a9bb9e | 2013-08-01 14:19:26 -0700 | [diff] [blame] | 736 | |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 737 | mCurrentFrame.reset(numAppLayers); |
Saurabh Shah | 90b7b9b | 2013-09-12 16:36:08 -0700 | [diff] [blame] | 738 | updateYUV(ctx, list, secureOnly); |
Saurabh Shah | 4fdde76 | 2013-04-30 18:47:33 -0700 | [diff] [blame] | 739 | int mdpCount = mCurrentFrame.mdpCount; |
Jeykumar Sankaran | 6a9bb9e | 2013-08-01 14:19:26 -0700 | [diff] [blame] | 740 | int fbNeeded = (mCurrentFrame.fbCount != 0); |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 741 | |
| 742 | if(!isYuvPresent(ctx, mDpy)) { |
| 743 | return false; |
| 744 | } |
| 745 | |
Saurabh Shah | 4fdde76 | 2013-04-30 18:47:33 -0700 | [diff] [blame] | 746 | if(!mdpCount) |
| 747 | return false; |
| 748 | |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 749 | if(mdpCount > (sMaxPipesPerMixer - fbNeeded)) { |
| 750 | ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__); |
| 751 | return false; |
| 752 | } |
| 753 | |
Saurabh Shah | af5f597 | 2013-07-30 13:56:35 -0700 | [diff] [blame] | 754 | if(!arePipesAvailable(ctx, list)) { |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 755 | return false; |
| 756 | } |
| 757 | |
Saurabh Shah | 8c5c852 | 2013-08-29 17:32:49 -0700 | [diff] [blame] | 758 | uint32_t size = calcMDPBytesRead(ctx, list); |
| 759 | if(!bandwidthCheck(ctx, size)) { |
| 760 | ALOGD_IF(isDebug(), "%s: Exceeds bandwidth",__FUNCTION__); |
| 761 | return false; |
| 762 | } |
| 763 | |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 764 | return true; |
| 765 | } |
| 766 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 767 | /* Checks for conditions where YUV layers cannot be bypassed */ |
| 768 | bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) { |
Saurabh Shah | e247408 | 2013-05-15 16:32:13 -0700 | [diff] [blame] | 769 | bool extAnimBlockFeature = mDpy && ctx->listStats[mDpy].isDisplayAnimating; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 770 | |
Saurabh Shah | e247408 | 2013-05-15 16:32:13 -0700 | [diff] [blame] | 771 | if(isSkipLayer(layer) && !extAnimBlockFeature) { |
| 772 | ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy); |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 773 | return false; |
| 774 | } |
| 775 | |
Amara Venkata Mastan Manoj Kumar | 9d373c0 | 2013-08-20 14:30:09 -0700 | [diff] [blame] | 776 | if(layer->transform & HWC_TRANSFORM_ROT_90 && !canUseRotator(ctx,mDpy)) { |
| 777 | ALOGD_IF(isDebug(), "%s: no free DMA pipe",__FUNCTION__); |
| 778 | return false; |
| 779 | } |
| 780 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 781 | if(isSecuring(ctx, layer)) { |
| 782 | ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__); |
| 783 | return false; |
| 784 | } |
| 785 | |
Saurabh Shah | 4fdde76 | 2013-04-30 18:47:33 -0700 | [diff] [blame] | 786 | if(!isValidDimension(ctx, layer)) { |
| 787 | ALOGD_IF(isDebug(), "%s: Buffer is of invalid width", |
| 788 | __FUNCTION__); |
| 789 | return false; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 790 | } |
Saurabh Shah | 4fdde76 | 2013-04-30 18:47:33 -0700 | [diff] [blame] | 791 | |
Naseer Ahmed | dc61a97 | 2013-07-10 17:50:54 -0400 | [diff] [blame] | 792 | if(layer->planeAlpha < 0xFF) { |
| 793 | ALOGD_IF(isDebug(), "%s: Cannot handle YUV layer with plane alpha\ |
| 794 | in video only mode", |
| 795 | __FUNCTION__); |
| 796 | return false; |
| 797 | } |
| 798 | |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 799 | return true; |
| 800 | } |
| 801 | |
Prabhanjan Kandula | 9bd5f64 | 2013-09-25 17:00:36 +0530 | [diff] [blame] | 802 | /* starts at fromIndex and check for each layer to find |
| 803 | * if it it has overlapping with any Updating layer above it in zorder |
| 804 | * till the end of the batch. returns true if it finds any intersection */ |
| 805 | bool MDPComp::canPushBatchToTop(const hwc_display_contents_1_t* list, |
| 806 | int fromIndex, int toIndex) { |
| 807 | for(int i = fromIndex; i < toIndex; i++) { |
| 808 | if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) { |
| 809 | if(intersectingUpdatingLayers(list, i+1, toIndex, i)) { |
| 810 | return false; |
| 811 | } |
| 812 | } |
| 813 | } |
| 814 | return true; |
| 815 | } |
| 816 | |
| 817 | /* Checks if given layer at targetLayerIndex has any |
| 818 | * intersection with all the updating layers in beween |
| 819 | * fromIndex and toIndex. Returns true if it finds intersectiion */ |
| 820 | bool MDPComp::intersectingUpdatingLayers(const hwc_display_contents_1_t* list, |
| 821 | int fromIndex, int toIndex, int targetLayerIndex) { |
| 822 | for(int i = fromIndex; i <= toIndex; i++) { |
| 823 | if(!mCurrentFrame.isFBComposed[i]) { |
| 824 | if(areLayersIntersecting(&list->hwLayers[i], |
| 825 | &list->hwLayers[targetLayerIndex])) { |
| 826 | return true; |
| 827 | } |
| 828 | } |
| 829 | } |
| 830 | return false; |
| 831 | } |
| 832 | |
| 833 | int MDPComp::getBatch(hwc_display_contents_1_t* list, |
| 834 | int& maxBatchStart, int& maxBatchEnd, |
| 835 | int& maxBatchCount) { |
| 836 | int i = 0; |
| 837 | int updatingLayersAbove = 0;//Updating layer count in middle of batch |
| 838 | int fbZOrder =-1; |
| 839 | while (i < mCurrentFrame.layerCount) { |
| 840 | int batchCount = 0; |
| 841 | int batchStart = i; |
| 842 | int batchEnd = i; |
| 843 | int fbZ = batchStart; |
| 844 | int firstZReverseIndex = -1; |
| 845 | while(i < mCurrentFrame.layerCount) { |
| 846 | if(!mCurrentFrame.isFBComposed[i]) { |
| 847 | if(!batchCount) { |
| 848 | i++; |
| 849 | break; |
| 850 | } |
| 851 | updatingLayersAbove++; |
| 852 | i++; |
| 853 | continue; |
| 854 | } else { |
| 855 | if(mCurrentFrame.drop[i]) { |
| 856 | i++; |
| 857 | continue; |
| 858 | } else if(updatingLayersAbove <= 0) { |
| 859 | batchCount++; |
| 860 | batchEnd = i; |
| 861 | i++; |
| 862 | continue; |
| 863 | } else { //Layer is FBComposed, not a drop & updatingLayer > 0 |
| 864 | |
| 865 | // We have a valid updating layer already. If layer-i not |
| 866 | // have overlapping with all updating layers in between |
| 867 | // batch-start and i, then we can add layer i to batch. |
| 868 | if(!intersectingUpdatingLayers(list, batchStart, i-1, i)) { |
| 869 | batchCount++; |
| 870 | batchEnd = i; |
| 871 | i++; |
| 872 | continue; |
| 873 | } else if(canPushBatchToTop(list, batchStart, i)) { |
| 874 | //If All the non-updating layers with in this batch |
| 875 | //does not have intersection with the updating layers |
| 876 | //above in z-order, then we can safely move the batch to |
| 877 | //higher z-order. Increment fbZ as it is moving up. |
| 878 | if( firstZReverseIndex < 0) { |
| 879 | firstZReverseIndex = i; |
| 880 | } |
| 881 | batchCount++; |
| 882 | batchEnd = i; |
| 883 | fbZ += updatingLayersAbove; |
| 884 | i++; |
| 885 | updatingLayersAbove = 0; |
| 886 | continue; |
| 887 | } else { |
| 888 | //both failed.start the loop again from here. |
| 889 | if(firstZReverseIndex >= 0) { |
| 890 | i = firstZReverseIndex; |
| 891 | } |
| 892 | break; |
| 893 | } |
| 894 | } |
| 895 | } |
| 896 | } |
| 897 | if(batchCount > maxBatchCount) { |
| 898 | maxBatchCount = batchCount; |
| 899 | maxBatchStart = batchStart; |
| 900 | maxBatchEnd = batchEnd; |
| 901 | fbZOrder = fbZ; |
| 902 | } |
| 903 | } |
| 904 | return fbZOrder; |
| 905 | } |
| 906 | |
| 907 | bool MDPComp::markLayersForCaching(hwc_context_t* ctx, |
| 908 | hwc_display_contents_1_t* list) { |
| 909 | /* Idea is to keep as many non-updating(cached) layers in FB and |
| 910 | * send rest of them through MDP. This is done in 2 steps. |
| 911 | * 1. Find the maximum contiguous batch of non-updating layers. |
| 912 | * 2. See if we can improve this batch size for caching by adding |
| 913 | * opaque layers around the batch, if they don't have |
| 914 | * any overlapping with the updating layers in between. |
| 915 | * NEVER mark an updating layer for caching. |
| 916 | * But cached ones can be marked for MDP */ |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 917 | |
| 918 | int maxBatchStart = -1; |
Jeykumar Sankaran | 6a9bb9e | 2013-08-01 14:19:26 -0700 | [diff] [blame] | 919 | int maxBatchEnd = -1; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 920 | int maxBatchCount = 0; |
Prabhanjan Kandula | 9bd5f64 | 2013-09-25 17:00:36 +0530 | [diff] [blame] | 921 | int fbZ = -1; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 922 | |
| 923 | /* All or Nothing is cached. No batching needed */ |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 924 | if(!mCurrentFrame.fbCount) { |
| 925 | mCurrentFrame.fbZ = -1; |
Saurabh Shah | e9bc60f | 2013-08-29 12:58:06 -0700 | [diff] [blame] | 926 | return true; |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 927 | } |
| 928 | if(!mCurrentFrame.mdpCount) { |
| 929 | mCurrentFrame.fbZ = 0; |
Saurabh Shah | e9bc60f | 2013-08-29 12:58:06 -0700 | [diff] [blame] | 930 | return true; |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 931 | } |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 932 | |
Prabhanjan Kandula | 9bd5f64 | 2013-09-25 17:00:36 +0530 | [diff] [blame] | 933 | fbZ = getBatch(list, maxBatchStart, maxBatchEnd, maxBatchCount); |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 934 | |
Prabhanjan Kandula | 9bd5f64 | 2013-09-25 17:00:36 +0530 | [diff] [blame] | 935 | /* reset rest of the layers lying inside ROI for MDP comp */ |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 936 | for(int i = 0; i < mCurrentFrame.layerCount; i++) { |
Saurabh Shah | e9bc60f | 2013-08-29 12:58:06 -0700 | [diff] [blame] | 937 | hwc_layer_1_t* layer = &list->hwLayers[i]; |
Jeykumar Sankaran | 6a9bb9e | 2013-08-01 14:19:26 -0700 | [diff] [blame] | 938 | if((i < maxBatchStart || i > maxBatchEnd) && |
Prabhanjan Kandula | 9bd5f64 | 2013-09-25 17:00:36 +0530 | [diff] [blame] | 939 | mCurrentFrame.isFBComposed[i]){ |
Jeykumar Sankaran | 6a9bb9e | 2013-08-01 14:19:26 -0700 | [diff] [blame] | 940 | if(!mCurrentFrame.drop[i]){ |
| 941 | //If an unsupported layer is being attempted to |
| 942 | //be pulled out we should fail |
| 943 | if(not isSupportedForMDPComp(ctx, layer)) { |
| 944 | return false; |
| 945 | } |
| 946 | mCurrentFrame.isFBComposed[i] = false; |
Saurabh Shah | e9bc60f | 2013-08-29 12:58:06 -0700 | [diff] [blame] | 947 | } |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 948 | } |
| 949 | } |
| 950 | |
Prabhanjan Kandula | 9bd5f64 | 2013-09-25 17:00:36 +0530 | [diff] [blame] | 951 | // update the frame data |
| 952 | mCurrentFrame.fbZ = fbZ; |
| 953 | mCurrentFrame.fbCount = maxBatchCount; |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 954 | mCurrentFrame.mdpCount = mCurrentFrame.layerCount - |
Jeykumar Sankaran | 6a9bb9e | 2013-08-01 14:19:26 -0700 | [diff] [blame] | 955 | mCurrentFrame.fbCount - mCurrentFrame.dropCount; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 956 | |
| 957 | ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__, |
Prabhanjan Kandula | 9bd5f64 | 2013-09-25 17:00:36 +0530 | [diff] [blame] | 958 | mCurrentFrame.fbCount); |
Saurabh Shah | e9bc60f | 2013-08-29 12:58:06 -0700 | [diff] [blame] | 959 | |
| 960 | return true; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 961 | } |
Saurabh Shah | 85234ec | 2013-04-12 17:09:00 -0700 | [diff] [blame] | 962 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 963 | void MDPComp::updateLayerCache(hwc_context_t* ctx, |
Saurabh Shah | e9bc60f | 2013-08-29 12:58:06 -0700 | [diff] [blame] | 964 | hwc_display_contents_1_t* list) { |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 965 | int numAppLayers = ctx->listStats[mDpy].numAppLayers; |
Saurabh Shah | e9bc60f | 2013-08-29 12:58:06 -0700 | [diff] [blame] | 966 | int fbCount = 0; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 967 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 968 | for(int i = 0; i < numAppLayers; i++) { |
Saurabh Shah | e9bc60f | 2013-08-29 12:58:06 -0700 | [diff] [blame] | 969 | hwc_layer_1_t* layer = &list->hwLayers[i]; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 970 | if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) { |
Jeykumar Sankaran | 6a9bb9e | 2013-08-01 14:19:26 -0700 | [diff] [blame] | 971 | if(!mCurrentFrame.drop[i]) |
| 972 | fbCount++; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 973 | mCurrentFrame.isFBComposed[i] = true; |
| 974 | } else { |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 975 | mCurrentFrame.isFBComposed[i] = false; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 976 | mCachedFrame.hnd[i] = list->hwLayers[i].handle; |
| 977 | } |
| 978 | } |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 979 | |
Saurabh Shah | e9bc60f | 2013-08-29 12:58:06 -0700 | [diff] [blame] | 980 | mCurrentFrame.fbCount = fbCount; |
Jeykumar Sankaran | 6a9bb9e | 2013-08-01 14:19:26 -0700 | [diff] [blame] | 981 | mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount |
| 982 | - mCurrentFrame.dropCount; |
Saurabh Shah | e9bc60f | 2013-08-29 12:58:06 -0700 | [diff] [blame] | 983 | |
Jeykumar Sankaran | 6a9bb9e | 2013-08-01 14:19:26 -0700 | [diff] [blame] | 984 | ALOGD_IF(isDebug(),"%s: MDP count: %d FB count %d drop count: %d" |
| 985 | ,__FUNCTION__, mCurrentFrame.mdpCount, mCurrentFrame.fbCount, |
| 986 | mCurrentFrame.dropCount); |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 987 | } |
| 988 | |
Saurabh Shah | 90b7b9b | 2013-09-12 16:36:08 -0700 | [diff] [blame] | 989 | void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list, |
| 990 | bool secureOnly) { |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 991 | int nYuvCount = ctx->listStats[mDpy].yuvCount; |
Ramkumar Radhakrishnan | 59a1107 | 2013-04-15 16:14:49 -0700 | [diff] [blame] | 992 | if(!nYuvCount && mDpy) { |
| 993 | //Reset "No animation on external display" related parameters. |
| 994 | ctx->mPrevCropVideo.left = ctx->mPrevCropVideo.top = |
| 995 | ctx->mPrevCropVideo.right = ctx->mPrevCropVideo.bottom = 0; |
| 996 | ctx->mPrevDestVideo.left = ctx->mPrevDestVideo.top = |
| 997 | ctx->mPrevDestVideo.right = ctx->mPrevDestVideo.bottom = 0; |
| 998 | ctx->mPrevTransformVideo = 0; |
| 999 | return; |
| 1000 | } |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1001 | for(int index = 0;index < nYuvCount; index++){ |
| 1002 | int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index]; |
| 1003 | hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex]; |
| 1004 | |
| 1005 | if(!isYUVDoable(ctx, layer)) { |
| 1006 | if(!mCurrentFrame.isFBComposed[nYuvIndex]) { |
| 1007 | mCurrentFrame.isFBComposed[nYuvIndex] = true; |
| 1008 | mCurrentFrame.fbCount++; |
| 1009 | } |
| 1010 | } else { |
| 1011 | if(mCurrentFrame.isFBComposed[nYuvIndex]) { |
Saurabh Shah | 90b7b9b | 2013-09-12 16:36:08 -0700 | [diff] [blame] | 1012 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
| 1013 | if(!secureOnly || isSecureBuffer(hnd)) { |
| 1014 | mCurrentFrame.isFBComposed[nYuvIndex] = false; |
| 1015 | mCurrentFrame.fbCount--; |
| 1016 | } |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1017 | } |
| 1018 | } |
| 1019 | } |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 1020 | |
| 1021 | mCurrentFrame.mdpCount = mCurrentFrame.layerCount - |
Jeykumar Sankaran | 6a9bb9e | 2013-08-01 14:19:26 -0700 | [diff] [blame] | 1022 | mCurrentFrame.fbCount - mCurrentFrame.dropCount; |
| 1023 | ALOGD_IF(isDebug(),"%s: fb count: %d",__FUNCTION__, |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1024 | mCurrentFrame.fbCount); |
| 1025 | } |
| 1026 | |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 1027 | 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] | 1028 | if(!allocLayerPipes(ctx, list)) { |
| 1029 | ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__); |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 1030 | return false; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1031 | } |
| 1032 | |
| 1033 | for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount; |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 1034 | index++) { |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1035 | if(!mCurrentFrame.isFBComposed[index]) { |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1036 | int mdpIndex = mCurrentFrame.layerToMDP[index]; |
| 1037 | hwc_layer_1_t* layer = &list->hwLayers[index]; |
| 1038 | |
Prabhanjan Kandula | 9bd5f64 | 2013-09-25 17:00:36 +0530 | [diff] [blame] | 1039 | //Leave fbZ for framebuffer. CACHE/GLES layers go here. |
| 1040 | if(mdpNextZOrder == mCurrentFrame.fbZ) { |
| 1041 | mdpNextZOrder++; |
| 1042 | } |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1043 | MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo; |
| 1044 | cur_pipe->zOrder = mdpNextZOrder++; |
| 1045 | |
Prabhanjan Kandula | 9bd5f64 | 2013-09-25 17:00:36 +0530 | [diff] [blame] | 1046 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1047 | if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){ |
| 1048 | ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \ |
| 1049 | layer %d",__FUNCTION__, index); |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 1050 | return false; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1051 | } |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 1052 | } |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1053 | } |
| 1054 | |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 1055 | return true; |
| 1056 | } |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1057 | |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 1058 | bool MDPComp::programYUV(hwc_context_t *ctx, hwc_display_contents_1_t* list) { |
| 1059 | if(!allocLayerPipes(ctx, list)) { |
| 1060 | ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__); |
| 1061 | return false; |
| 1062 | } |
| 1063 | //If we are in this block, it means we have yuv + rgb layers both |
| 1064 | int mdpIdx = 0; |
| 1065 | for (int index = 0; index < mCurrentFrame.layerCount; index++) { |
| 1066 | if(!mCurrentFrame.isFBComposed[index]) { |
| 1067 | hwc_layer_1_t* layer = &list->hwLayers[index]; |
| 1068 | int mdpIndex = mCurrentFrame.layerToMDP[index]; |
| 1069 | MdpPipeInfo* cur_pipe = |
| 1070 | mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo; |
| 1071 | cur_pipe->zOrder = mdpIdx++; |
| 1072 | |
| 1073 | if(configure(ctx, layer, |
| 1074 | mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){ |
| 1075 | ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \ |
| 1076 | layer %d",__FUNCTION__, index); |
| 1077 | return false; |
| 1078 | } |
| 1079 | } |
| 1080 | } |
| 1081 | return true; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1082 | } |
| 1083 | |
Saurabh Shah | 8c5c852 | 2013-08-29 17:32:49 -0700 | [diff] [blame] | 1084 | uint32_t MDPComp::calcMDPBytesRead(hwc_context_t *ctx, |
| 1085 | hwc_display_contents_1_t* list) { |
| 1086 | uint32_t size = 0; |
| 1087 | |
Terence Hampson | 9cd5fa9 | 2013-09-10 17:06:37 -0400 | [diff] [blame] | 1088 | if(!qdutils::MDPVersion::getInstance().is8x74v2()) |
| 1089 | return 0; |
| 1090 | |
Saurabh Shah | 8c5c852 | 2013-08-29 17:32:49 -0700 | [diff] [blame] | 1091 | for (uint32_t i = 0; i < list->numHwLayers - 1; i++) { |
| 1092 | if(!mCurrentFrame.isFBComposed[i]) { |
| 1093 | hwc_layer_1_t* layer = &list->hwLayers[i]; |
| 1094 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
Terence Hampson | 9cd5fa9 | 2013-09-10 17:06:37 -0400 | [diff] [blame] | 1095 | if (hnd) { |
Saurabh Shah | 62e1d73 | 2013-09-17 10:44:05 -0700 | [diff] [blame] | 1096 | hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf); |
Saurabh Shah | 9078916 | 2013-09-16 10:29:20 -0700 | [diff] [blame] | 1097 | hwc_rect_t dst = layer->displayFrame; |
| 1098 | trimLayer(ctx, mDpy, layer->transform, crop, dst); |
Terence Hampson | 9cd5fa9 | 2013-09-10 17:06:37 -0400 | [diff] [blame] | 1099 | float bpp = ((float)hnd->size) / (hnd->width * hnd->height); |
Saurabh Shah | 9078916 | 2013-09-16 10:29:20 -0700 | [diff] [blame] | 1100 | size += bpp * (crop.right - crop.left) * |
| 1101 | (crop.bottom - crop.top) * |
| 1102 | ctx->dpyAttr[mDpy].yres / (dst.bottom - dst.top); |
Terence Hampson | 9cd5fa9 | 2013-09-10 17:06:37 -0400 | [diff] [blame] | 1103 | } |
Saurabh Shah | 8c5c852 | 2013-08-29 17:32:49 -0700 | [diff] [blame] | 1104 | } |
| 1105 | } |
| 1106 | |
| 1107 | if(mCurrentFrame.fbCount) { |
| 1108 | hwc_layer_1_t* layer = &list->hwLayers[list->numHwLayers - 1]; |
| 1109 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
Terence Hampson | 9cd5fa9 | 2013-09-10 17:06:37 -0400 | [diff] [blame] | 1110 | if (hnd) |
| 1111 | size += hnd->size; |
Saurabh Shah | 8c5c852 | 2013-08-29 17:32:49 -0700 | [diff] [blame] | 1112 | } |
| 1113 | |
| 1114 | return size; |
| 1115 | } |
| 1116 | |
| 1117 | bool MDPComp::bandwidthCheck(hwc_context_t *ctx, const uint32_t& size) { |
| 1118 | //Will be added for other targets if we run into bandwidth issues and when |
| 1119 | //we have profiling data to set an upper limit. |
| 1120 | if(qdutils::MDPVersion::getInstance().is8x74v2()) { |
| 1121 | const uint32_t ONE_GIG = 1024 * 1024 * 1024; |
| 1122 | double panelRefRate = |
| 1123 | 1000000000.0 / ctx->dpyAttr[mDpy].vsync_period; |
| 1124 | if((size + sCompBytesClaimed) > ((sMaxBw / panelRefRate) * ONE_GIG)) { |
| 1125 | return false; |
| 1126 | } |
| 1127 | } |
| 1128 | return true; |
| 1129 | } |
| 1130 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1131 | int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) { |
Saurabh Shah | 8c5c852 | 2013-08-29 17:32:49 -0700 | [diff] [blame] | 1132 | int ret = 0; |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 1133 | const int numLayers = ctx->listStats[mDpy].numAppLayers; |
Ramkumar Radhakrishnan | c5893f1 | 2013-06-06 19:43:53 -0700 | [diff] [blame] | 1134 | |
Saurabh Shah | b39f815 | 2013-08-22 10:21:44 -0700 | [diff] [blame] | 1135 | //reset old data |
| 1136 | mCurrentFrame.reset(numLayers); |
Jeykumar Sankaran | 6a9bb9e | 2013-08-01 14:19:26 -0700 | [diff] [blame] | 1137 | memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop)); |
| 1138 | mCurrentFrame.dropCount = 0; |
Prabhanjan Kandula | 088bd89 | 2013-07-02 23:47:13 +0530 | [diff] [blame] | 1139 | |
Saurabh Shah | b39f815 | 2013-08-22 10:21:44 -0700 | [diff] [blame] | 1140 | //number of app layers exceeds MAX_NUM_APP_LAYERS fall back to GPU |
| 1141 | //do not cache the information for next draw cycle. |
| 1142 | if(numLayers > MAX_NUM_APP_LAYERS) { |
Prabhanjan Kandula | 25469a5 | 2013-07-12 16:19:31 +0530 | [diff] [blame] | 1143 | mCachedFrame.updateCounts(mCurrentFrame); |
Tatenda Chipeperekwa | 835337a | 2013-09-27 16:58:43 -0700 | [diff] [blame] | 1144 | ALOGE("%s: Number of App layers exceeded the limit ", |
| 1145 | __FUNCTION__); |
Saurabh Shah | 8c5c852 | 2013-08-29 17:32:49 -0700 | [diff] [blame] | 1146 | ret = -1; |
Tatenda Chipeperekwa | 835337a | 2013-09-27 16:58:43 -0700 | [diff] [blame] | 1147 | return ret; |
Saurabh Shah | b39f815 | 2013-08-22 10:21:44 -0700 | [diff] [blame] | 1148 | } |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1149 | |
Saurabh Shah | b39f815 | 2013-08-22 10:21:44 -0700 | [diff] [blame] | 1150 | //Hard conditions, if not met, cannot do MDP comp |
| 1151 | if(!isFrameDoable(ctx)) { |
| 1152 | ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame", |
| 1153 | __FUNCTION__); |
| 1154 | reset(numLayers, list); |
Saurabh Shah | 8c5c852 | 2013-08-29 17:32:49 -0700 | [diff] [blame] | 1155 | ret = -1; |
| 1156 | goto exit; |
Saurabh Shah | b39f815 | 2013-08-22 10:21:44 -0700 | [diff] [blame] | 1157 | } |
| 1158 | |
Jeykumar Sankaran | 6a9bb9e | 2013-08-01 14:19:26 -0700 | [diff] [blame] | 1159 | generateROI(ctx, list); |
| 1160 | |
Saurabh Shah | b39f815 | 2013-08-22 10:21:44 -0700 | [diff] [blame] | 1161 | //Check whether layers marked for MDP Composition is actually doable. |
| 1162 | if(isFullFrameDoable(ctx, list)) { |
| 1163 | mCurrentFrame.map(); |
| 1164 | //Configure framebuffer first if applicable |
| 1165 | if(mCurrentFrame.fbZ >= 0) { |
| 1166 | if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, |
| 1167 | mCurrentFrame.fbZ)) { |
| 1168 | ALOGE("%s configure framebuffer failed", __func__); |
| 1169 | reset(numLayers, list); |
Saurabh Shah | 6be7c78 | 2013-08-28 15:13:52 -0700 | [diff] [blame] | 1170 | ctx->mOverlay->clear(mDpy); |
Saurabh Shah | 8c5c852 | 2013-08-29 17:32:49 -0700 | [diff] [blame] | 1171 | ret = -1; |
| 1172 | goto exit; |
Saurabh Shah | b39f815 | 2013-08-22 10:21:44 -0700 | [diff] [blame] | 1173 | } |
| 1174 | } |
| 1175 | //Acquire and Program MDP pipes |
| 1176 | if(!programMDP(ctx, list)) { |
| 1177 | reset(numLayers, list); |
Saurabh Shah | 6be7c78 | 2013-08-28 15:13:52 -0700 | [diff] [blame] | 1178 | ctx->mOverlay->clear(mDpy); |
Saurabh Shah | 8c5c852 | 2013-08-29 17:32:49 -0700 | [diff] [blame] | 1179 | ret = -1; |
| 1180 | goto exit; |
Saurabh Shah | b39f815 | 2013-08-22 10:21:44 -0700 | [diff] [blame] | 1181 | } else { //Success |
| 1182 | //Any change in composition types needs an FB refresh |
| 1183 | mCurrentFrame.needsRedraw = false; |
Prabhanjan Kandula | 2243aa6 | 2013-10-24 12:58:55 +0530 | [diff] [blame] | 1184 | if(!mCachedFrame.isSameFrame(mCurrentFrame) || |
Saurabh Shah | b39f815 | 2013-08-22 10:21:44 -0700 | [diff] [blame] | 1185 | (list->flags & HWC_GEOMETRY_CHANGED) || |
Prabhanjan Kandula | 2243aa6 | 2013-10-24 12:58:55 +0530 | [diff] [blame] | 1186 | isSkipPresent(ctx, mDpy)) { |
Saurabh Shah | b39f815 | 2013-08-22 10:21:44 -0700 | [diff] [blame] | 1187 | mCurrentFrame.needsRedraw = true; |
| 1188 | } |
| 1189 | } |
Saurabh Shah | 90b7b9b | 2013-09-12 16:36:08 -0700 | [diff] [blame] | 1190 | } else if(isOnlyVideoDoable(ctx, list, false /*secure only*/) || |
| 1191 | isOnlyVideoDoable(ctx, list, true /*secure only*/)) { |
Saurabh Shah | b39f815 | 2013-08-22 10:21:44 -0700 | [diff] [blame] | 1192 | //All layers marked for MDP comp cannot be bypassed. |
| 1193 | //Try to compose atleast YUV layers through MDP comp and let |
| 1194 | //all the RGB layers compose in FB |
| 1195 | //Destination over |
| 1196 | mCurrentFrame.fbZ = -1; |
| 1197 | if(mCurrentFrame.fbCount) |
| 1198 | mCurrentFrame.fbZ = mCurrentFrame.mdpCount; |
| 1199 | |
| 1200 | mCurrentFrame.map(); |
| 1201 | |
| 1202 | //Configure framebuffer first if applicable |
| 1203 | if(mCurrentFrame.fbZ >= 0) { |
| 1204 | if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, mCurrentFrame.fbZ)) { |
| 1205 | ALOGE("%s configure framebuffer failed", __func__); |
| 1206 | reset(numLayers, list); |
Saurabh Shah | 6be7c78 | 2013-08-28 15:13:52 -0700 | [diff] [blame] | 1207 | ctx->mOverlay->clear(mDpy); |
Saurabh Shah | 8c5c852 | 2013-08-29 17:32:49 -0700 | [diff] [blame] | 1208 | ret = -1; |
| 1209 | goto exit; |
Saurabh Shah | b39f815 | 2013-08-22 10:21:44 -0700 | [diff] [blame] | 1210 | } |
| 1211 | } |
| 1212 | if(!programYUV(ctx, list)) { |
| 1213 | reset(numLayers, list); |
Saurabh Shah | 6be7c78 | 2013-08-28 15:13:52 -0700 | [diff] [blame] | 1214 | ctx->mOverlay->clear(mDpy); |
Saurabh Shah | 8c5c852 | 2013-08-29 17:32:49 -0700 | [diff] [blame] | 1215 | ret = -1; |
| 1216 | goto exit; |
Saurabh Shah | b39f815 | 2013-08-22 10:21:44 -0700 | [diff] [blame] | 1217 | } |
| 1218 | } else { |
| 1219 | reset(numLayers, list); |
Saurabh Shah | 8c5c852 | 2013-08-29 17:32:49 -0700 | [diff] [blame] | 1220 | ret = -1; |
| 1221 | goto exit; |
Saurabh Shah | b39f815 | 2013-08-22 10:21:44 -0700 | [diff] [blame] | 1222 | } |
| 1223 | |
| 1224 | //UpdateLayerFlags |
| 1225 | setMDPCompLayerFlags(ctx, list); |
Jeykumar Sankaran | 6a9bb9e | 2013-08-01 14:19:26 -0700 | [diff] [blame] | 1226 | mCachedFrame.cacheAll(list); |
Saurabh Shah | b39f815 | 2013-08-22 10:21:44 -0700 | [diff] [blame] | 1227 | mCachedFrame.updateCounts(mCurrentFrame); |
| 1228 | |
Prabhanjan Kandula | 25469a5 | 2013-07-12 16:19:31 +0530 | [diff] [blame] | 1229 | // unlock it before calling dump function to avoid deadlock |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1230 | if(isDebug()) { |
Saurabh Shah | aa23682 | 2013-04-24 18:07:26 -0700 | [diff] [blame] | 1231 | ALOGD("GEOMETRY change: %d", (list->flags & HWC_GEOMETRY_CHANGED)); |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1232 | android::String8 sDump(""); |
| 1233 | dump(sDump); |
| 1234 | ALOGE("%s",sDump.string()); |
| 1235 | } |
| 1236 | |
Saurabh Shah | 8c5c852 | 2013-08-29 17:32:49 -0700 | [diff] [blame] | 1237 | exit: |
| 1238 | sCompBytesClaimed += calcMDPBytesRead(ctx, list); |
| 1239 | return ret; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1240 | } |
| 1241 | |
Saurabh Shah | 88e4d27 | 2013-09-03 13:31:29 -0700 | [diff] [blame] | 1242 | //=============MDPCompNonSplit=================================================== |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1243 | |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 1244 | /* |
| 1245 | * Configures pipe(s) for MDP composition |
| 1246 | */ |
Saurabh Shah | 88e4d27 | 2013-09-03 13:31:29 -0700 | [diff] [blame] | 1247 | int MDPCompNonSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer, |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1248 | PipeLayerPair& PipeLayerPair) { |
Saurabh Shah | 88e4d27 | 2013-09-03 13:31:29 -0700 | [diff] [blame] | 1249 | MdpPipeInfoNonSplit& mdp_info = |
| 1250 | *(static_cast<MdpPipeInfoNonSplit*>(PipeLayerPair.pipeInfo)); |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1251 | eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION; |
| 1252 | eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder); |
| 1253 | eIsFg isFg = IS_FG_OFF; |
| 1254 | eDest dest = mdp_info.index; |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 1255 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1256 | ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d", |
| 1257 | __FUNCTION__, layer, zOrder, dest); |
| 1258 | |
Saurabh Shah | 88e4d27 | 2013-09-03 13:31:29 -0700 | [diff] [blame] | 1259 | return configureNonSplit(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest, |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1260 | &PipeLayerPair.rot); |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 1261 | } |
| 1262 | |
Saurabh Shah | 88e4d27 | 2013-09-03 13:31:29 -0700 | [diff] [blame] | 1263 | bool MDPCompNonSplit::arePipesAvailable(hwc_context_t *ctx, |
Saurabh Shah | af5f597 | 2013-07-30 13:56:35 -0700 | [diff] [blame] | 1264 | hwc_display_contents_1_t* list) { |
| 1265 | overlay::Overlay& ov = *ctx->mOverlay; |
| 1266 | int numPipesNeeded = mCurrentFrame.mdpCount; |
| 1267 | int availPipes = ov.availablePipes(mDpy, Overlay::MIXER_DEFAULT); |
| 1268 | |
| 1269 | //Reserve pipe for FB |
| 1270 | if(mCurrentFrame.fbCount) |
| 1271 | availPipes -= 1; |
| 1272 | |
| 1273 | if(numPipesNeeded > availPipes) { |
| 1274 | ALOGD_IF(isDebug(), "%s: Insufficient pipes, dpy %d needed %d, avail %d", |
| 1275 | __FUNCTION__, mDpy, numPipesNeeded, availPipes); |
| 1276 | return false; |
| 1277 | } |
| 1278 | |
Saurabh Shah | 90b7b9b | 2013-09-12 16:36:08 -0700 | [diff] [blame] | 1279 | if(not areVGPipesAvailable(ctx, list)) { |
| 1280 | return false; |
| 1281 | } |
| 1282 | |
| 1283 | return true; |
| 1284 | } |
| 1285 | |
| 1286 | bool MDPCompNonSplit::areVGPipesAvailable(hwc_context_t *ctx, |
| 1287 | hwc_display_contents_1_t* list) { |
| 1288 | overlay::Overlay& ov = *ctx->mOverlay; |
| 1289 | int pipesNeeded = 0; |
| 1290 | for(int i = 0; i < mCurrentFrame.layerCount; ++i) { |
| 1291 | if(!mCurrentFrame.isFBComposed[i]) { |
| 1292 | hwc_layer_1_t* layer = &list->hwLayers[i]; |
| 1293 | hwc_rect_t dst = layer->displayFrame; |
| 1294 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
| 1295 | if(isYuvBuffer(hnd)) { |
| 1296 | pipesNeeded++; |
| 1297 | } |
| 1298 | } |
| 1299 | } |
| 1300 | |
| 1301 | int availableVGPipes = ov.availablePipes(mDpy, ovutils::OV_MDP_PIPE_VG); |
| 1302 | if(pipesNeeded > availableVGPipes) { |
| 1303 | ALOGD_IF(isDebug(), "%s: Insufficient VG pipes for video layers" |
| 1304 | "dpy %d needed %d, avail %d", |
| 1305 | __FUNCTION__, mDpy, pipesNeeded, availableVGPipes); |
| 1306 | return false; |
| 1307 | } |
| 1308 | |
Saurabh Shah | af5f597 | 2013-07-30 13:56:35 -0700 | [diff] [blame] | 1309 | return true; |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 1310 | } |
| 1311 | |
Saurabh Shah | 88e4d27 | 2013-09-03 13:31:29 -0700 | [diff] [blame] | 1312 | bool MDPCompNonSplit::allocLayerPipes(hwc_context_t *ctx, |
Saurabh Shah | e51f8ca | 2013-05-06 17:26:16 -0700 | [diff] [blame] | 1313 | hwc_display_contents_1_t* list) { |
| 1314 | for(int index = 0; index < mCurrentFrame.layerCount; index++) { |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 1315 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1316 | if(mCurrentFrame.isFBComposed[index]) continue; |
Saurabh Shah | e51f8ca | 2013-05-06 17:26:16 -0700 | [diff] [blame] | 1317 | |
Jeykumar Sankaran | cf53700 | 2013-01-21 21:19:15 -0800 | [diff] [blame] | 1318 | hwc_layer_1_t* layer = &list->hwLayers[index]; |
| 1319 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1320 | int mdpIndex = mCurrentFrame.layerToMDP[index]; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1321 | PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex]; |
Saurabh Shah | 88e4d27 | 2013-09-03 13:31:29 -0700 | [diff] [blame] | 1322 | info.pipeInfo = new MdpPipeInfoNonSplit; |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1323 | info.rot = NULL; |
Saurabh Shah | 88e4d27 | 2013-09-03 13:31:29 -0700 | [diff] [blame] | 1324 | MdpPipeInfoNonSplit& pipe_info = *(MdpPipeInfoNonSplit*)info.pipeInfo; |
Jeykumar Sankaran | a37fdbf | 2013-03-06 18:59:28 -0800 | [diff] [blame] | 1325 | ePipeType type = MDPCOMP_OV_ANY; |
| 1326 | |
Saurabh Shah | e51f8ca | 2013-05-06 17:26:16 -0700 | [diff] [blame] | 1327 | if(isYuvBuffer(hnd)) { |
| 1328 | type = MDPCOMP_OV_VG; |
Saurabh Shah | 8a11793 | 2013-05-23 12:48:13 -0700 | [diff] [blame] | 1329 | } else if(!qhwc::needsScaling(ctx, layer, mDpy) |
Saurabh Shah | 85234ec | 2013-04-12 17:09:00 -0700 | [diff] [blame] | 1330 | && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE |
| 1331 | && ctx->mMDP.version >= qdutils::MDSS_V5) { |
Jeykumar Sankaran | a37fdbf | 2013-03-06 18:59:28 -0800 | [diff] [blame] | 1332 | type = MDPCOMP_OV_DMA; |
| 1333 | } |
| 1334 | |
Saurabh Shah | af5f597 | 2013-07-30 13:56:35 -0700 | [diff] [blame] | 1335 | pipe_info.index = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT); |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1336 | if(pipe_info.index == ovutils::OV_INVALID) { |
Saurabh Shah | e51f8ca | 2013-05-06 17:26:16 -0700 | [diff] [blame] | 1337 | ALOGD_IF(isDebug(), "%s: Unable to get pipe type = %d", |
| 1338 | __FUNCTION__, (int) type); |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 1339 | return false; |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 1340 | } |
| 1341 | } |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 1342 | return true; |
| 1343 | } |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 1344 | |
Saurabh Shah | 88e4d27 | 2013-09-03 13:31:29 -0700 | [diff] [blame] | 1345 | bool MDPCompNonSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) { |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 1346 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1347 | if(!isEnabled()) { |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 1348 | ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__); |
| 1349 | return true; |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 1350 | } |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 1351 | |
| 1352 | if(!ctx || !list) { |
| 1353 | ALOGE("%s: invalid contxt or list",__FUNCTION__); |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 1354 | return false; |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 1355 | } |
| 1356 | |
Prabhanjan Kandula | 08222fc | 2013-07-10 17:20:59 +0530 | [diff] [blame] | 1357 | if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) { |
| 1358 | ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__); |
| 1359 | return true; |
| 1360 | } |
| 1361 | |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 1362 | /* reset Invalidator */ |
Saurabh Shah | 2d998a9 | 2013-05-14 17:55:58 -0700 | [diff] [blame] | 1363 | if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount) |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 1364 | idleInvalidator->markForSleep(); |
| 1365 | |
| 1366 | overlay::Overlay& ov = *ctx->mOverlay; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1367 | LayerProp *layerProp = ctx->layerProp[mDpy]; |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 1368 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1369 | int numHwLayers = ctx->listStats[mDpy].numAppLayers; |
| 1370 | for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ ) |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 1371 | { |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1372 | if(mCurrentFrame.isFBComposed[i]) continue; |
| 1373 | |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 1374 | hwc_layer_1_t *layer = &list->hwLayers[i]; |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1375 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
| 1376 | if(!hnd) { |
| 1377 | ALOGE("%s handle null", __FUNCTION__); |
| 1378 | return false; |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 1379 | } |
| 1380 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1381 | int mdpIndex = mCurrentFrame.layerToMDP[i]; |
| 1382 | |
Saurabh Shah | 88e4d27 | 2013-09-03 13:31:29 -0700 | [diff] [blame] | 1383 | MdpPipeInfoNonSplit& pipe_info = |
| 1384 | *(MdpPipeInfoNonSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1385 | ovutils::eDest dest = pipe_info.index; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1386 | if(dest == ovutils::OV_INVALID) { |
| 1387 | ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest); |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 1388 | return false; |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 1389 | } |
| 1390 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1391 | if(!(layerProp[i].mFlags & HWC_MDPCOMP)) { |
| 1392 | continue; |
| 1393 | } |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 1394 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1395 | ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \ |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1396 | using pipe: %d", __FUNCTION__, layer, |
| 1397 | hnd, dest ); |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 1398 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1399 | int fd = hnd->fd; |
| 1400 | uint32_t offset = hnd->offset; |
Saurabh Shah | a9da08f | 2013-07-03 13:27:53 -0700 | [diff] [blame] | 1401 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1402 | Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot; |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1403 | if(rot) { |
| 1404 | if(!rot->queueBuffer(fd, offset)) |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 1405 | return false; |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1406 | fd = rot->getDstMemId(); |
| 1407 | offset = rot->getDstOffset(); |
| 1408 | } |
| 1409 | |
| 1410 | if (!ov.queueBuffer(fd, offset, dest)) { |
Prabhanjan Kandula | 08222fc | 2013-07-10 17:20:59 +0530 | [diff] [blame] | 1411 | ALOGE("%s: queueBuffer failed for display:%d ", __FUNCTION__, mDpy); |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1412 | return false; |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 1413 | } |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 1414 | |
| 1415 | layerProp[i].mFlags &= ~HWC_MDPCOMP; |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 1416 | } |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 1417 | return true; |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 1418 | } |
| 1419 | |
Saurabh Shah | 88e4d27 | 2013-09-03 13:31:29 -0700 | [diff] [blame] | 1420 | //=============MDPCompSplit=================================================== |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1421 | |
Saurabh Shah | 88e4d27 | 2013-09-03 13:31:29 -0700 | [diff] [blame] | 1422 | int MDPCompSplit::pipesNeeded(hwc_context_t *ctx, |
Saurabh Shah | af5f597 | 2013-07-30 13:56:35 -0700 | [diff] [blame] | 1423 | hwc_display_contents_1_t* list, |
| 1424 | int mixer) { |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1425 | int pipesNeeded = 0; |
Saurabh Shah | 67a38c3 | 2013-06-10 16:23:15 -0700 | [diff] [blame] | 1426 | const int xres = ctx->dpyAttr[mDpy].xres; |
Saurabh Shah | 07a8ca8 | 2013-08-06 18:45:42 -0700 | [diff] [blame] | 1427 | |
| 1428 | const int lSplit = getLeftSplit(ctx, mDpy); |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1429 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1430 | for(int i = 0; i < mCurrentFrame.layerCount; ++i) { |
| 1431 | if(!mCurrentFrame.isFBComposed[i]) { |
| 1432 | hwc_layer_1_t* layer = &list->hwLayers[i]; |
| 1433 | hwc_rect_t dst = layer->displayFrame; |
Saurabh Shah | af5f597 | 2013-07-30 13:56:35 -0700 | [diff] [blame] | 1434 | if(mixer == Overlay::MIXER_LEFT && dst.left < lSplit) { |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1435 | pipesNeeded++; |
Saurabh Shah | af5f597 | 2013-07-30 13:56:35 -0700 | [diff] [blame] | 1436 | } else if(mixer == Overlay::MIXER_RIGHT && dst.right > lSplit) { |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1437 | pipesNeeded++; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1438 | } |
| 1439 | } |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1440 | } |
| 1441 | return pipesNeeded; |
| 1442 | } |
| 1443 | |
Saurabh Shah | 88e4d27 | 2013-09-03 13:31:29 -0700 | [diff] [blame] | 1444 | bool MDPCompSplit::arePipesAvailable(hwc_context_t *ctx, |
Saurabh Shah | af5f597 | 2013-07-30 13:56:35 -0700 | [diff] [blame] | 1445 | hwc_display_contents_1_t* list) { |
| 1446 | overlay::Overlay& ov = *ctx->mOverlay; |
Saurabh Shah | 082468e | 2013-09-12 10:05:32 -0700 | [diff] [blame] | 1447 | int totalPipesNeeded = 0; |
Saurabh Shah | af5f597 | 2013-07-30 13:56:35 -0700 | [diff] [blame] | 1448 | |
| 1449 | for(int i = 0; i < Overlay::MIXER_MAX; i++) { |
| 1450 | int numPipesNeeded = pipesNeeded(ctx, list, i); |
| 1451 | int availPipes = ov.availablePipes(mDpy, i); |
| 1452 | |
| 1453 | //Reserve pipe(s)for FB |
| 1454 | if(mCurrentFrame.fbCount) |
Saurabh Shah | 082468e | 2013-09-12 10:05:32 -0700 | [diff] [blame] | 1455 | numPipesNeeded += 1; |
Saurabh Shah | af5f597 | 2013-07-30 13:56:35 -0700 | [diff] [blame] | 1456 | |
Saurabh Shah | 082468e | 2013-09-12 10:05:32 -0700 | [diff] [blame] | 1457 | totalPipesNeeded += numPipesNeeded; |
| 1458 | |
| 1459 | //Per mixer check. |
Saurabh Shah | af5f597 | 2013-07-30 13:56:35 -0700 | [diff] [blame] | 1460 | if(numPipesNeeded > availPipes) { |
| 1461 | ALOGD_IF(isDebug(), "%s: Insufficient pipes for " |
| 1462 | "dpy %d mixer %d needed %d, avail %d", |
| 1463 | __FUNCTION__, mDpy, i, numPipesNeeded, availPipes); |
| 1464 | return false; |
| 1465 | } |
| 1466 | } |
Saurabh Shah | 082468e | 2013-09-12 10:05:32 -0700 | [diff] [blame] | 1467 | |
| 1468 | //Per display check, since unused pipes can get counted twice. |
| 1469 | int totalPipesAvailable = ov.availablePipes(mDpy); |
| 1470 | if(totalPipesNeeded > totalPipesAvailable) { |
| 1471 | ALOGD_IF(isDebug(), "%s: Insufficient pipes for " |
| 1472 | "dpy %d needed %d, avail %d", |
| 1473 | __FUNCTION__, mDpy, totalPipesNeeded, totalPipesAvailable); |
| 1474 | return false; |
| 1475 | } |
| 1476 | |
Saurabh Shah | 90b7b9b | 2013-09-12 16:36:08 -0700 | [diff] [blame] | 1477 | if(not areVGPipesAvailable(ctx, list)) { |
| 1478 | return false; |
| 1479 | } |
| 1480 | |
| 1481 | return true; |
| 1482 | } |
| 1483 | |
| 1484 | bool MDPCompSplit::areVGPipesAvailable(hwc_context_t *ctx, |
| 1485 | hwc_display_contents_1_t* list) { |
| 1486 | overlay::Overlay& ov = *ctx->mOverlay; |
| 1487 | int pipesNeeded = 0; |
| 1488 | const int lSplit = getLeftSplit(ctx, mDpy); |
| 1489 | for(int i = 0; i < mCurrentFrame.layerCount; ++i) { |
| 1490 | if(!mCurrentFrame.isFBComposed[i]) { |
| 1491 | hwc_layer_1_t* layer = &list->hwLayers[i]; |
| 1492 | hwc_rect_t dst = layer->displayFrame; |
| 1493 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
| 1494 | if(isYuvBuffer(hnd)) { |
| 1495 | if(dst.left < lSplit) { |
| 1496 | pipesNeeded++; |
| 1497 | } |
| 1498 | if(dst.right > lSplit) { |
| 1499 | pipesNeeded++; |
| 1500 | } |
| 1501 | } |
| 1502 | } |
| 1503 | } |
| 1504 | |
| 1505 | int availableVGPipes = ov.availablePipes(mDpy, ovutils::OV_MDP_PIPE_VG); |
| 1506 | if(pipesNeeded > availableVGPipes) { |
| 1507 | ALOGD_IF(isDebug(), "%s: Insufficient VG pipes for video layers" |
| 1508 | "dpy %d needed %d, avail %d", |
| 1509 | __FUNCTION__, mDpy, pipesNeeded, availableVGPipes); |
| 1510 | return false; |
| 1511 | } |
| 1512 | |
Saurabh Shah | af5f597 | 2013-07-30 13:56:35 -0700 | [diff] [blame] | 1513 | return true; |
| 1514 | } |
| 1515 | |
Saurabh Shah | 88e4d27 | 2013-09-03 13:31:29 -0700 | [diff] [blame] | 1516 | bool MDPCompSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer, |
| 1517 | MdpPipeInfoSplit& pipe_info, |
Saurabh Shah | 67a38c3 | 2013-06-10 16:23:15 -0700 | [diff] [blame] | 1518 | ePipeType type) { |
| 1519 | const int xres = ctx->dpyAttr[mDpy].xres; |
Saurabh Shah | 07a8ca8 | 2013-08-06 18:45:42 -0700 | [diff] [blame] | 1520 | const int lSplit = getLeftSplit(ctx, mDpy); |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1521 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1522 | hwc_rect_t dst = layer->displayFrame; |
Saurabh Shah | af5f597 | 2013-07-30 13:56:35 -0700 | [diff] [blame] | 1523 | pipe_info.lIndex = ovutils::OV_INVALID; |
| 1524 | pipe_info.rIndex = ovutils::OV_INVALID; |
| 1525 | |
| 1526 | if (dst.left < lSplit) { |
| 1527 | pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_LEFT); |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1528 | if(pipe_info.lIndex == ovutils::OV_INVALID) |
| 1529 | return false; |
Saurabh Shah | af5f597 | 2013-07-30 13:56:35 -0700 | [diff] [blame] | 1530 | } |
| 1531 | |
| 1532 | if(dst.right > lSplit) { |
| 1533 | pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_RIGHT); |
| 1534 | if(pipe_info.rIndex == ovutils::OV_INVALID) |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1535 | return false; |
| 1536 | } |
Saurabh Shah | af5f597 | 2013-07-30 13:56:35 -0700 | [diff] [blame] | 1537 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1538 | return true; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1539 | } |
| 1540 | |
Saurabh Shah | 88e4d27 | 2013-09-03 13:31:29 -0700 | [diff] [blame] | 1541 | bool MDPCompSplit::allocLayerPipes(hwc_context_t *ctx, |
Saurabh Shah | e51f8ca | 2013-05-06 17:26:16 -0700 | [diff] [blame] | 1542 | hwc_display_contents_1_t* list) { |
| 1543 | for(int index = 0 ; index < mCurrentFrame.layerCount; index++) { |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1544 | |
Saurabh Shah | e51f8ca | 2013-05-06 17:26:16 -0700 | [diff] [blame] | 1545 | if(mCurrentFrame.isFBComposed[index]) continue; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1546 | |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1547 | hwc_layer_1_t* layer = &list->hwLayers[index]; |
| 1548 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
Saurabh Shah | 0d65dbe | 2013-06-06 18:33:16 -0700 | [diff] [blame] | 1549 | int mdpIndex = mCurrentFrame.layerToMDP[index]; |
| 1550 | PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex]; |
Saurabh Shah | 88e4d27 | 2013-09-03 13:31:29 -0700 | [diff] [blame] | 1551 | info.pipeInfo = new MdpPipeInfoSplit; |
Saurabh Shah | 9e3adb2 | 2013-03-26 11:16:27 -0700 | [diff] [blame] | 1552 | info.rot = NULL; |
Saurabh Shah | 88e4d27 | 2013-09-03 13:31:29 -0700 | [diff] [blame] | 1553 | MdpPipeInfoSplit& pipe_info = *(MdpPipeInfoSplit*)info.pipeInfo; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1554 | ePipeType type = MDPCOMP_OV_ANY; |
| 1555 | |
Saurabh Shah | e51f8ca | 2013-05-06 17:26:16 -0700 | [diff] [blame] | 1556 | if(isYuvBuffer(hnd)) { |
| 1557 | type = MDPCOMP_OV_VG; |
Sushil Chauhan | 15a2ea6 | 2013-09-04 18:28:36 -0700 | [diff] [blame] | 1558 | } else if(!qhwc::needsScalingWithSplit(ctx, layer, mDpy) |
Saurabh Shah | 85234ec | 2013-04-12 17:09:00 -0700 | [diff] [blame] | 1559 | && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE |
Saurabh Shah | e51f8ca | 2013-05-06 17:26:16 -0700 | [diff] [blame] | 1560 | && ctx->mMDP.version >= qdutils::MDSS_V5) { |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1561 | type = MDPCOMP_OV_DMA; |
Saurabh Shah | e51f8ca | 2013-05-06 17:26:16 -0700 | [diff] [blame] | 1562 | } |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1563 | |
| 1564 | if(!acquireMDPPipes(ctx, layer, pipe_info, type)) { |
Saurabh Shah | e51f8ca | 2013-05-06 17:26:16 -0700 | [diff] [blame] | 1565 | ALOGD_IF(isDebug(), "%s: Unable to get pipe for type = %d", |
| 1566 | __FUNCTION__, (int) type); |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1567 | return false; |
| 1568 | } |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1569 | } |
| 1570 | return true; |
| 1571 | } |
Saurabh Shah | af5f597 | 2013-07-30 13:56:35 -0700 | [diff] [blame] | 1572 | |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1573 | /* |
| 1574 | * Configures pipe(s) for MDP composition |
| 1575 | */ |
Saurabh Shah | 88e4d27 | 2013-09-03 13:31:29 -0700 | [diff] [blame] | 1576 | int MDPCompSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer, |
Saurabh Shah | 67a38c3 | 2013-06-10 16:23:15 -0700 | [diff] [blame] | 1577 | PipeLayerPair& PipeLayerPair) { |
Saurabh Shah | 88e4d27 | 2013-09-03 13:31:29 -0700 | [diff] [blame] | 1578 | MdpPipeInfoSplit& mdp_info = |
| 1579 | *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo)); |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1580 | eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder); |
| 1581 | eIsFg isFg = IS_FG_OFF; |
| 1582 | eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION; |
| 1583 | eDest lDest = mdp_info.lIndex; |
| 1584 | eDest rDest = mdp_info.rIndex; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1585 | |
| 1586 | ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d" |
| 1587 | "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest); |
| 1588 | |
Saurabh Shah | 88e4d27 | 2013-09-03 13:31:29 -0700 | [diff] [blame] | 1589 | return configureSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest, |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1590 | rDest, &PipeLayerPair.rot); |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1591 | } |
| 1592 | |
Saurabh Shah | 88e4d27 | 2013-09-03 13:31:29 -0700 | [diff] [blame] | 1593 | bool MDPCompSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) { |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1594 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1595 | if(!isEnabled()) { |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1596 | ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__); |
| 1597 | return true; |
| 1598 | } |
| 1599 | |
| 1600 | if(!ctx || !list) { |
| 1601 | ALOGE("%s: invalid contxt or list",__FUNCTION__); |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 1602 | return false; |
| 1603 | } |
| 1604 | |
Prabhanjan Kandula | 08222fc | 2013-07-10 17:20:59 +0530 | [diff] [blame] | 1605 | if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) { |
| 1606 | ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__); |
| 1607 | return true; |
| 1608 | } |
| 1609 | |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1610 | /* reset Invalidator */ |
Saurabh Shah | 2d998a9 | 2013-05-14 17:55:58 -0700 | [diff] [blame] | 1611 | if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount) |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1612 | idleInvalidator->markForSleep(); |
| 1613 | |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 1614 | overlay::Overlay& ov = *ctx->mOverlay; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1615 | LayerProp *layerProp = ctx->layerProp[mDpy]; |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 1616 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1617 | int numHwLayers = ctx->listStats[mDpy].numAppLayers; |
| 1618 | for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ ) |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1619 | { |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1620 | if(mCurrentFrame.isFBComposed[i]) continue; |
| 1621 | |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1622 | hwc_layer_1_t *layer = &list->hwLayers[i]; |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1623 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
| 1624 | if(!hnd) { |
| 1625 | ALOGE("%s handle null", __FUNCTION__); |
| 1626 | return false; |
| 1627 | } |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1628 | |
| 1629 | if(!(layerProp[i].mFlags & HWC_MDPCOMP)) { |
| 1630 | continue; |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 1631 | } |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 1632 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1633 | int mdpIndex = mCurrentFrame.layerToMDP[i]; |
| 1634 | |
Saurabh Shah | 88e4d27 | 2013-09-03 13:31:29 -0700 | [diff] [blame] | 1635 | MdpPipeInfoSplit& pipe_info = |
| 1636 | *(MdpPipeInfoSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1637 | Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot; |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1638 | |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1639 | ovutils::eDest indexL = pipe_info.lIndex; |
| 1640 | ovutils::eDest indexR = pipe_info.rIndex; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1641 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1642 | int fd = hnd->fd; |
| 1643 | int offset = hnd->offset; |
| 1644 | |
Saurabh Shah | a9da08f | 2013-07-03 13:27:53 -0700 | [diff] [blame] | 1645 | if(ctx->mAD->isModeOn()) { |
| 1646 | if(ctx->mAD->draw(ctx, fd, offset)) { |
| 1647 | fd = ctx->mAD->getDstFd(ctx); |
| 1648 | offset = ctx->mAD->getDstOffset(ctx); |
| 1649 | } |
| 1650 | } |
| 1651 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1652 | if(rot) { |
| 1653 | rot->queueBuffer(fd, offset); |
| 1654 | fd = rot->getDstMemId(); |
| 1655 | offset = rot->getDstOffset(); |
| 1656 | } |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 1657 | |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1658 | //************* play left mixer ********** |
| 1659 | if(indexL != ovutils::OV_INVALID) { |
| 1660 | ovutils::eDest destL = (ovutils::eDest)indexL; |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1661 | ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \ |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1662 | using pipe: %d", __FUNCTION__, layer, hnd, indexL ); |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1663 | if (!ov.queueBuffer(fd, offset, destL)) { |
| 1664 | ALOGE("%s: queueBuffer failed for left mixer", __FUNCTION__); |
| 1665 | return false; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1666 | } |
| 1667 | } |
| 1668 | |
| 1669 | //************* play right mixer ********** |
| 1670 | if(indexR != ovutils::OV_INVALID) { |
| 1671 | ovutils::eDest destR = (ovutils::eDest)indexR; |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1672 | ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \ |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1673 | using pipe: %d", __FUNCTION__, layer, hnd, indexR ); |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1674 | if (!ov.queueBuffer(fd, offset, destR)) { |
| 1675 | ALOGE("%s: queueBuffer failed for right mixer", __FUNCTION__); |
| 1676 | return false; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1677 | } |
| 1678 | } |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1679 | |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1680 | layerProp[i].mFlags &= ~HWC_MDPCOMP; |
| 1681 | } |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1682 | |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1683 | return true; |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 1684 | } |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 1685 | }; //namespace |
| 1686 | |