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