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