blob: 8efcaa646c1706b9db8d3b399c6a0c8a5b506b86 [file] [log] [blame]
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001/*
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002 * Copyright (C) 2012-2013, The Linux Foundation. All rights reserved.
Naseer Ahmed7c958d42012-07-31 18:57:03 -07003 * 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 Shah4fdde762013-04-30 18:47:33 -070019#include <math.h>
Naseer Ahmed7c958d42012-07-31 18:57:03 -070020#include "hwc_mdpcomp.h"
Naseer Ahmed54821fe2012-11-28 18:44:38 -050021#include <sys/ioctl.h>
Saurabh Shah56f610d2012-08-07 15:27:06 -070022#include "external.h"
Jeykumar Sankaran27dee262013-08-01 17:09:54 -070023#include "virtual.h"
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -080024#include "qdMetaData.h"
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -080025#include "mdp_version.h"
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -070026#include "hwc_fbupdate.h"
Saurabh Shaha9da08f2013-07-03 13:27:53 -070027#include "hwc_ad.h"
Saurabh Shahacf10202013-02-26 10:15:15 -080028#include <overlayRotator.h>
29
Saurabh Shah85234ec2013-04-12 17:09:00 -070030using namespace overlay;
Saurabh Shahbd2d0832013-04-04 14:33:08 -070031using namespace qdutils;
Saurabh Shahacf10202013-02-26 10:15:15 -080032using namespace overlay::utils;
33namespace ovutils = overlay::utils;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070034
Naseer Ahmed7c958d42012-07-31 18:57:03 -070035namespace qhwc {
36
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080037//==============MDPComp========================================================
38
Naseer Ahmed7c958d42012-07-31 18:57:03 -070039IdleInvalidator *MDPComp::idleInvalidator = NULL;
40bool MDPComp::sIdleFallBack = false;
Ramkumar Radhakrishnand8595ae2014-02-06 21:31:29 -080041bool MDPComp::sHandleTimeout = false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070042bool MDPComp::sDebugLogs = false;
Naseer Ahmed54821fe2012-11-28 18:44:38 -050043bool MDPComp::sEnabled = false;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -070044bool MDPComp::sEnableMixedMode = true;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -070045bool MDPComp::sEnablePartialFrameUpdate = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080046int MDPComp::sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
radhakrishnac9a67412013-09-25 17:40:42 +053047bool MDPComp::sEnable4k2kYUVSplit = false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070048
Saurabh Shah88e4d272013-09-03 13:31:29 -070049MDPComp* MDPComp::getObject(hwc_context_t *ctx, const int& dpy) {
50 if(isDisplaySplit(ctx, dpy)) {
51 return new MDPCompSplit(dpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080052 }
Saurabh Shah88e4d272013-09-03 13:31:29 -070053 return new MDPCompNonSplit(dpy);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080054}
55
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080056MDPComp::MDPComp(int dpy):mDpy(dpy){};
57
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080058void MDPComp::dump(android::String8& buf)
59{
Jeykumar Sankaran3c6bb042013-08-15 14:01:04 -070060 if(mCurrentFrame.layerCount > MAX_NUM_APP_LAYERS)
61 return;
62
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080063 dumpsys_log(buf,"HWC Map for Dpy: %s \n",
Jeykumar Sankaran27dee262013-08-01 17:09:54 -070064 (mDpy == 0) ? "\"PRIMARY\"" :
65 (mDpy == 1) ? "\"EXTERNAL\"" : "\"VIRTUAL\"");
Saurabh Shahe9bc60f2013-08-29 12:58:06 -070066 dumpsys_log(buf,"CURR_FRAME: layerCount:%2d mdpCount:%2d "
67 "fbCount:%2d \n", mCurrentFrame.layerCount,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080068 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 Sankaran6a9bb9e2013-08-01 14:19:26 -070079 mCurrentFrame.layerToMDP[index],
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080080 (mCurrentFrame.isFBComposed[index] ?
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -070081 (mCurrentFrame.drop[index] ? "DROP" :
82 (mCurrentFrame.needsRedraw ? "GLES" : "CACHE")) : "MDP"),
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080083 (mCurrentFrame.isFBComposed[index] ? mCurrentFrame.fbZ :
84 mCurrentFrame.mdpToLayer[mCurrentFrame.layerToMDP[index]].pipeInfo->zOrder));
85 dumpsys_log(buf,"\n");
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080086}
87
88bool MDPComp::init(hwc_context_t *ctx) {
89
90 if(!ctx) {
91 ALOGE("%s: Invalid hwc context!!",__FUNCTION__);
92 return false;
93 }
94
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080095 char property[PROPERTY_VALUE_MAX];
96
97 sEnabled = false;
98 if((property_get("persist.hwc.mdpcomp.enable", property, NULL) > 0) &&
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080099 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
100 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800101 sEnabled = true;
102 }
103
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700104 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 Shahcbf7ccc2012-12-19 16:45:51 -0800111 if(property_get("debug.mdpcomp.logs", property, NULL) > 0) {
112 if(atoi(property) != 0)
113 sDebugLogs = true;
114 }
115
Jeykumar Sankaran18469742014-02-19 12:40:57 -0800116 if(property_get("persist.hwc.partialupdate", property, NULL) > 0) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700117 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 Sankaran85977e32013-02-25 17:06:08 -0800124 sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
Saurabh Shah85234ec2013-04-12 17:09:00 -0700125 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 Sankaran85977e32013-02-25 17:06:08 -0800129 }
130
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400131 if(ctx->mMDP.panel != MIPI_CMD_PANEL) {
132 // Idle invalidation is not necessary on command mode panels
133 long idle_timeout = DEFAULT_IDLE_TIME;
134 if(property_get("debug.mdpcomp.idletime", property, NULL) > 0) {
135 if(atoi(property) != 0)
136 idle_timeout = atoi(property);
137 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800138
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400139 //create Idle Invalidator only when not disabled through property
140 if(idle_timeout != -1)
141 idleInvalidator = IdleInvalidator::getInstance();
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800142
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400143 if(idleInvalidator == NULL) {
144 ALOGE("%s: failed to instantiate idleInvalidator object",
145 __FUNCTION__);
146 } else {
147 idleInvalidator->init(timeout_handler, ctx, idle_timeout);
148 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800149 }
radhakrishnac9a67412013-09-25 17:40:42 +0530150
151 if((property_get("debug.mdpcomp.4k2kSplit", property, "0") > 0) &&
152 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
153 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
154 sEnable4k2kYUVSplit = true;
155 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700156 return true;
157}
158
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800159void MDPComp::reset(hwc_context_t *ctx) {
160 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700161 mCurrentFrame.reset(numLayers);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800162 ctx->mOverlay->clear(mDpy);
163 ctx->mLayerRotMap[mDpy]->clear();
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700164}
165
Raj Kamal5166b312014-06-06 13:45:20 +0530166void MDPComp::reset() {
167 sHandleTimeout = false;
168 mModeOn = false;
169}
170
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700171void MDPComp::timeout_handler(void *udata) {
172 struct hwc_context_t* ctx = (struct hwc_context_t*)(udata);
173
174 if(!ctx) {
175 ALOGE("%s: received empty data in timer callback", __FUNCTION__);
176 return;
177 }
Ramkumar Radhakrishnand8595ae2014-02-06 21:31:29 -0800178 Locker::Autolock _l(ctx->mDrawLock);
179 // Handle timeout event only if the previous composition is MDP or MIXED.
180 if(!sHandleTimeout) {
181 ALOGD_IF(isDebug(), "%s:Do not handle this timeout", __FUNCTION__);
182 return;
183 }
Jesse Hall3be78d92012-08-21 15:12:23 -0700184 if(!ctx->proc) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700185 ALOGE("%s: HWC proc not registered", __FUNCTION__);
186 return;
187 }
188 sIdleFallBack = true;
189 /* Trigger SF to redraw the current frame */
Jesse Hall3be78d92012-08-21 15:12:23 -0700190 ctx->proc->invalidate(ctx->proc);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700191}
192
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800193void MDPComp::setMDPCompLayerFlags(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800194 hwc_display_contents_1_t* list) {
195 LayerProp *layerProp = ctx->layerProp[mDpy];
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800196
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800197 for(int index = 0; index < ctx->listStats[mDpy].numAppLayers; index++) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800198 hwc_layer_1_t* layer = &(list->hwLayers[index]);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800199 if(!mCurrentFrame.isFBComposed[index]) {
200 layerProp[index].mFlags |= HWC_MDPCOMP;
201 layer->compositionType = HWC_OVERLAY;
202 layer->hints |= HWC_HINT_CLEAR_FB;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800203 } else {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700204 /* Drop the layer when its already present in FB OR when it lies
205 * outside frame's ROI */
206 if(!mCurrentFrame.needsRedraw || mCurrentFrame.drop[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800207 layer->compositionType = HWC_OVERLAY;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700208 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800209 }
210 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700211}
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500212
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800213void MDPComp::setRedraw(hwc_context_t *ctx,
214 hwc_display_contents_1_t* list) {
215 mCurrentFrame.needsRedraw = false;
216 if(!mCachedFrame.isSameFrame(mCurrentFrame, list) ||
217 (list->flags & HWC_GEOMETRY_CHANGED) ||
218 isSkipPresent(ctx, mDpy)) {
219 mCurrentFrame.needsRedraw = true;
220 }
221}
222
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800223MDPComp::FrameInfo::FrameInfo() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700224 reset(0);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800225}
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800226
Saurabh Shahaa236822013-04-24 18:07:26 -0700227void MDPComp::FrameInfo::reset(const int& numLayers) {
228 for(int i = 0 ; i < MAX_PIPES_PER_MIXER && numLayers; i++ ) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800229 if(mdpToLayer[i].pipeInfo) {
230 delete mdpToLayer[i].pipeInfo;
231 mdpToLayer[i].pipeInfo = NULL;
232 //We dont own the rotator
233 mdpToLayer[i].rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800234 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800235 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800236
237 memset(&mdpToLayer, 0, sizeof(mdpToLayer));
238 memset(&layerToMDP, -1, sizeof(layerToMDP));
Saurabh Shahaa236822013-04-24 18:07:26 -0700239 memset(&isFBComposed, 1, sizeof(isFBComposed));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800240
Saurabh Shahaa236822013-04-24 18:07:26 -0700241 layerCount = numLayers;
242 fbCount = numLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800243 mdpCount = 0;
Saurabh Shah2f3895f2013-05-02 10:13:31 -0700244 needsRedraw = true;
Saurabh Shahce188452014-02-05 10:17:43 -0800245 fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800246}
247
Saurabh Shahaa236822013-04-24 18:07:26 -0700248void MDPComp::FrameInfo::map() {
249 // populate layer and MDP maps
250 int mdpIdx = 0;
251 for(int idx = 0; idx < layerCount; idx++) {
252 if(!isFBComposed[idx]) {
253 mdpToLayer[mdpIdx].listIndex = idx;
254 layerToMDP[idx] = mdpIdx++;
255 }
256 }
257}
258
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800259MDPComp::LayerCache::LayerCache() {
260 reset();
261}
262
263void MDPComp::LayerCache::reset() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700264 memset(&hnd, 0, sizeof(hnd));
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530265 memset(&isFBComposed, true, sizeof(isFBComposed));
266 memset(&drop, false, sizeof(drop));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800267 layerCount = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -0700268}
269
270void MDPComp::LayerCache::cacheAll(hwc_display_contents_1_t* list) {
271 const int numAppLayers = list->numHwLayers - 1;
272 for(int i = 0; i < numAppLayers; i++) {
273 hnd[i] = list->hwLayers[i].handle;
274 }
275}
276
277void MDPComp::LayerCache::updateCounts(const FrameInfo& curFrame) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700278 layerCount = curFrame.layerCount;
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530279 memcpy(&isFBComposed, &curFrame.isFBComposed, sizeof(isFBComposed));
280 memcpy(&drop, &curFrame.drop, sizeof(drop));
281}
282
Jeykumar Sankaran988d3682013-11-15 11:57:16 -0800283bool MDPComp::LayerCache::isSameFrame(const FrameInfo& curFrame,
284 hwc_display_contents_1_t* list) {
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530285 if(layerCount != curFrame.layerCount)
286 return false;
287 for(int i = 0; i < curFrame.layerCount; i++) {
288 if((curFrame.isFBComposed[i] != isFBComposed[i]) ||
289 (curFrame.drop[i] != drop[i])) {
290 return false;
291 }
Jeykumar Sankaran988d3682013-11-15 11:57:16 -0800292 if(curFrame.isFBComposed[i] &&
293 (hnd[i] != list->hwLayers[i].handle)){
294 return false;
295 }
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530296 }
297 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800298}
299
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700300bool MDPComp::isSupportedForMDPComp(hwc_context_t *ctx, hwc_layer_1_t* layer) {
301 private_handle_t *hnd = (private_handle_t *)layer->handle;
302 if((not isYuvBuffer(hnd) and has90Transform(layer)) or
303 (not isValidDimension(ctx,layer))
304 //More conditions here, SKIP, sRGB+Blend etc
305 ) {
306 return false;
307 }
308 return true;
309}
310
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530311bool MDPComp::isValidDimension(hwc_context_t *ctx, hwc_layer_1_t *layer) {
Saurabh Shah4fdde762013-04-30 18:47:33 -0700312 const int dpy = HWC_DISPLAY_PRIMARY;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800313 private_handle_t *hnd = (private_handle_t *)layer->handle;
314
315 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -0700316 if (layer->flags & HWC_COLOR_FILL) {
317 // Color layer
318 return true;
319 }
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800320 ALOGE("%s: layer handle is NULL", __FUNCTION__);
321 return false;
322 }
323
Naseer Ahmede850a802013-09-06 13:12:52 -0400324 //XXX: Investigate doing this with pixel phase on MDSS
Naseer Ahmede77f8082013-10-10 13:42:48 -0400325 if(!isSecureBuffer(hnd) && isNonIntegralSourceCrop(layer->sourceCropf))
Naseer Ahmede850a802013-09-06 13:12:52 -0400326 return false;
327
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800328 int hw_w = ctx->dpyAttr[mDpy].xres;
329 int hw_h = ctx->dpyAttr[mDpy].yres;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800330
Saurabh Shah62e1d732013-09-17 10:44:05 -0700331 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700332 hwc_rect_t dst = layer->displayFrame;
Saurabh Shah4fdde762013-04-30 18:47:33 -0700333 int crop_w = crop.right - crop.left;
334 int crop_h = crop.bottom - crop.top;
335 int dst_w = dst.right - dst.left;
336 int dst_h = dst.bottom - dst.top;
337 float w_dscale = ceilf((float)crop_w / (float)dst_w);
338 float h_dscale = ceilf((float)crop_h / (float)dst_h);
339
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800340 /* Workaround for MDP HW limitation in DSI command mode panels where
341 * FPS will not go beyond 30 if buffers on RGB pipes are of width or height
342 * less than 5 pixels
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530343 * There also is a HW limilation in MDP, minimum block size is 2x2
344 * Fallback to GPU if height is less than 2.
345 */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800346 if((crop_w < 5)||(crop_h < 5))
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800347 return false;
348
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800349 if((w_dscale > 1.0f) || (h_dscale > 1.0f)) {
350 const uint32_t downscale =
Saurabh Shah4fdde762013-04-30 18:47:33 -0700351 qdutils::MDPVersion::getInstance().getMaxMDPDownscale();
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800352 if(ctx->mMDP.version >= qdutils::MDSS_V5) {
353 /* Workaround for downscales larger than 4x.
354 * Will be removed once decimator block is enabled for MDSS
355 */
356 if(!qdutils::MDPVersion::getInstance().supportsDecimation()) {
357 if(crop_w > MAX_DISPLAY_DIM || w_dscale > downscale ||
358 h_dscale > downscale)
359 return false;
360 } else {
361 if(w_dscale > 64 || h_dscale > 64)
362 return false;
363 }
364 } else { //A-family
365 if(w_dscale > downscale || h_dscale > downscale)
Saurabh Shah4fdde762013-04-30 18:47:33 -0700366 return false;
367 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700368 }
369
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800370 return true;
371}
372
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700373ovutils::eDest MDPComp::getMdpPipe(hwc_context_t *ctx, ePipeType type,
374 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800375 overlay::Overlay& ov = *ctx->mOverlay;
376 ovutils::eDest mdp_pipe = ovutils::OV_INVALID;
377
378 switch(type) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800379 case MDPCOMP_OV_DMA:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700380 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_DMA, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800381 if(mdp_pipe != ovutils::OV_INVALID) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800382 return mdp_pipe;
383 }
384 case MDPCOMP_OV_ANY:
385 case MDPCOMP_OV_RGB:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700386 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800387 if(mdp_pipe != ovutils::OV_INVALID) {
388 return mdp_pipe;
389 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800390
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800391 if(type == MDPCOMP_OV_RGB) {
392 //Requested only for RGB pipe
393 break;
394 }
395 case MDPCOMP_OV_VG:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700396 return ov.nextPipe(ovutils::OV_MDP_PIPE_VG, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800397 default:
398 ALOGE("%s: Invalid pipe type",__FUNCTION__);
399 return ovutils::OV_INVALID;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800400 };
401 return ovutils::OV_INVALID;
402}
403
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800404bool MDPComp::isFrameDoable(hwc_context_t *ctx) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700405 bool ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700406 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800407
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800408 if(!isEnabled()) {
409 ALOGD_IF(isDebug(),"%s: MDP Comp. not enabled.", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700410 ret = false;
Saurabh Shahd4e65852013-06-17 11:33:53 -0700411 } else if(qdutils::MDPVersion::getInstance().is8x26() &&
Tatenda Chipeperekwa75a41812014-04-01 12:54:13 -0700412 ctx->mVideoTransFlag &&
413 isSecondaryConnected(ctx)) {
Saurabh Shahd4e65852013-06-17 11:33:53 -0700414 //1 Padding round to shift pipes across mixers
415 ALOGD_IF(isDebug(),"%s: MDP Comp. video transition padding round",
416 __FUNCTION__);
417 ret = false;
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700418 } else if(ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isConfiguring ||
419 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isConfiguring) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800420 ALOGD_IF( isDebug(),"%s: External Display connection is pending",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800421 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700422 ret = false;
Saurabh Shahaa236822013-04-24 18:07:26 -0700423 } else if(ctx->isPaddingRound) {
Raj Kamalfc5b9222014-02-07 16:15:17 +0530424 ALOGD_IF(isDebug(), "%s: padding round invoked for dpy %d",
425 __FUNCTION__,mDpy);
Saurabh Shahaa236822013-04-24 18:07:26 -0700426 ret = false;
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700427 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700428 return ret;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800429}
430
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800431/*
432 * 1) Identify layers that are not visible in the updating ROI and drop them
433 * from composition.
434 * 2) If we have a scaling layers which needs cropping against generated ROI.
435 * Reset ROI to full resolution.
436 */
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700437bool MDPComp::validateAndApplyROI(hwc_context_t *ctx,
438 hwc_display_contents_1_t* list, hwc_rect_t roi) {
439 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
440
441 if(!isValidRect(roi))
442 return false;
443
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800444 hwc_rect_t visibleRect = roi;
445
446 for(int i = numAppLayers - 1; i >= 0; i--){
447
448 if(!isValidRect(visibleRect)) {
449 mCurrentFrame.drop[i] = true;
450 mCurrentFrame.dropCount++;
Jeykumar Sankaran65bc8022014-01-21 17:26:12 -0800451 continue;
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800452 }
453
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700454 const hwc_layer_1_t* layer = &list->hwLayers[i];
455
456 hwc_rect_t dstRect = layer->displayFrame;
Arun Kumar K.R91090c72013-10-28 19:40:18 -0700457 hwc_rect_t srcRect = integerizeSourceCrop(layer->sourceCropf);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700458 int transform = layer->transform;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700459
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800460 hwc_rect_t res = getIntersection(visibleRect, dstRect);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700461
462 int res_w = res.right - res.left;
463 int res_h = res.bottom - res.top;
464 int dst_w = dstRect.right - dstRect.left;
465 int dst_h = dstRect.bottom - dstRect.top;
466
467 if(!isValidRect(res)) {
468 mCurrentFrame.drop[i] = true;
469 mCurrentFrame.dropCount++;
470 }else {
471 /* Reset frame ROI when any layer which needs scaling also needs ROI
472 * cropping */
Jeykumar Sankaran65bc8022014-01-21 17:26:12 -0800473 if((res_w != dst_w || res_h != dst_h) && needsScaling (layer)) {
Arpita Banerjeed8965982013-11-08 17:27:33 -0800474 ALOGI("%s: Resetting ROI due to scaling", __FUNCTION__);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700475 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
476 mCurrentFrame.dropCount = 0;
477 return false;
478 }
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800479
Jeykumar Sankaran65bc8022014-01-21 17:26:12 -0800480 /* deduct any opaque region from visibleRect */
radhakrishna31858932014-11-03 13:19:27 +0530481 if (layer->blending == HWC_BLENDING_NONE &&
482 layer->planeAlpha == 0xFF)
Jeykumar Sankaran65bc8022014-01-21 17:26:12 -0800483 visibleRect = deductRect(visibleRect, res);
484 }
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700485 }
486 return true;
487}
488
Jeykumar Sankaran4d76a382014-02-26 18:26:58 -0800489bool MDPComp::canDoPartialUpdate(hwc_context_t *ctx,
490 hwc_display_contents_1_t* list){
491 if(!qdutils::MDPVersion::getInstance().isPartialUpdateEnabled() || mDpy ||
492 isSkipPresent(ctx, mDpy) || (list->flags & HWC_GEOMETRY_CHANGED)||
493 isDisplaySplit(ctx, mDpy)) {
494 return false;
495 }
496 return true;
497}
498
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700499void MDPComp::generateROI(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
500 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
501
Jeykumar Sankaran4d76a382014-02-26 18:26:58 -0800502 if(!canDoPartialUpdate(ctx, list))
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700503 return;
504
505 struct hwc_rect roi = (struct hwc_rect){0, 0, 0, 0};
506 for(int index = 0; index < numAppLayers; index++ ) {
Jeykumar Sankaran4d76a382014-02-26 18:26:58 -0800507 hwc_layer_1_t* layer = &list->hwLayers[index];
508 if ((mCachedFrame.hnd[index] != layer->handle) ||
Jeykumar Sankaran78893422014-05-07 16:23:14 -0700509 isYuvBuffer((private_handle_t *)layer->handle)) {
510 hwc_rect_t dst = layer->displayFrame;
511 hwc_rect_t updatingRect = dst;
512
Jeykumar Sankaran4d76a382014-02-26 18:26:58 -0800513#ifdef QCOM_BSP
Jeykumar Sankaran78893422014-05-07 16:23:14 -0700514 if(!needsScaling(layer) && !layer->transform)
515 {
516 hwc_rect_t src = integerizeSourceCrop(layer->sourceCropf);
517 int x_off = dst.left - src.left;
518 int y_off = dst.top - src.top;
519 updatingRect = moveRect(layer->dirtyRect, x_off, y_off);
520 }
Jeykumar Sankaran4d76a382014-02-26 18:26:58 -0800521#endif
522 roi = getUnion(roi, updatingRect);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700523 }
524 }
525
Jeykumar Sankaran4d76a382014-02-26 18:26:58 -0800526 hwc_rect fullFrame = (struct hwc_rect) {0, 0,(int)ctx->dpyAttr[mDpy].xres,
527 (int)ctx->dpyAttr[mDpy].yres};
528
529 // Align ROI coordinates to panel restrictions
530 roi = sanitizeROI(roi, fullFrame);
531
532 if(!validateAndApplyROI(ctx, list, roi))
533 roi = fullFrame;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700534
535 ctx->listStats[mDpy].roi.x = roi.left;
536 ctx->listStats[mDpy].roi.y = roi.top;
537 ctx->listStats[mDpy].roi.w = roi.right - roi.left;
538 ctx->listStats[mDpy].roi.h = roi.bottom - roi.top;
539
540 ALOGD_IF(isDebug(),"%s: generated ROI: [%d, %d, %d, %d]", __FUNCTION__,
541 roi.left, roi.top, roi.right, roi.bottom);
542}
543
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800544/* Checks for conditions where all the layers marked for MDP comp cannot be
545 * bypassed. On such conditions we try to bypass atleast YUV layers */
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800546bool MDPComp::tryFullFrame(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800547 hwc_display_contents_1_t* list){
548
Saurabh Shahaa236822013-04-24 18:07:26 -0700549 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800550
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -0700551 if(sIdleFallBack && !ctx->listStats[mDpy].secureUI) {
Saurabh Shah2d998a92013-05-14 17:55:58 -0700552 ALOGD_IF(isDebug(), "%s: Idle fallback dpy %d",__FUNCTION__, mDpy);
553 return false;
554 }
555
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800556 if(isSkipPresent(ctx, mDpy)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700557 ALOGD_IF(isDebug(),"%s: SKIP present: %d",
558 __FUNCTION__,
559 isSkipPresent(ctx, mDpy));
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800560 return false;
561 }
562
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800563 // check for action safe flag and downscale mode which requires scaling.
564 if(ctx->dpyAttr[mDpy].mActionSafePresent
565 || ctx->dpyAttr[mDpy].mDownScaleMode) {
566 ALOGD_IF(isDebug(), "%s: Scaling needed for this frame",__FUNCTION__);
567 return false;
568 }
569
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800570 for(int i = 0; i < numAppLayers; ++i) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800571 hwc_layer_1_t* layer = &list->hwLayers[i];
572 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800573
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700574 if(isYuvBuffer(hnd) && has90Transform(layer)) {
575 if(!canUseRotator(ctx, mDpy)) {
576 ALOGD_IF(isDebug(), "%s: Can't use rotator for dpy %d",
577 __FUNCTION__, mDpy);
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700578 return false;
579 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800580 }
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530581
582 //For 8x26 with panel width>1k, if RGB layer needs HFLIP fail mdp comp
583 // may not need it if Gfx pre-rotation can handle all flips & rotations
Sushil Chauhand8ef93f2014-03-20 11:08:41 -0700584 int transform = (layer->flags & HWC_COLOR_FILL) ? 0 : layer->transform;
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530585 if(qdutils::MDPVersion::getInstance().is8x26() &&
586 (ctx->dpyAttr[mDpy].xres > 1024) &&
Sushil Chauhand8ef93f2014-03-20 11:08:41 -0700587 (transform & HWC_TRANSFORM_FLIP_H) &&
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530588 (!isYuvBuffer(hnd)))
589 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800590 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700591
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700592 if(ctx->mAD->isDoable()) {
593 return false;
594 }
595
Saurabh Shahaa236822013-04-24 18:07:26 -0700596 //If all above hard conditions are met we can do full or partial MDP comp.
597 bool ret = false;
598 if(fullMDPComp(ctx, list)) {
599 ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700600 } else if(partialMDPComp(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700601 ret = true;
602 }
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530603
Saurabh Shahaa236822013-04-24 18:07:26 -0700604 return ret;
605}
606
607bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700608 //Will benefit presentation / secondary-only layer.
609 if((mDpy > HWC_DISPLAY_PRIMARY) &&
610 (list->numHwLayers - 1) > MAX_SEC_LAYERS) {
611 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
612 return false;
613 }
614
615 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
616 for(int i = 0; i < numAppLayers; i++) {
617 hwc_layer_1_t* layer = &list->hwLayers[i];
618 if(not isSupportedForMDPComp(ctx, layer)) {
619 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",__FUNCTION__);
620 return false;
621 }
622 }
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800623
Saurabh Shahaa236822013-04-24 18:07:26 -0700624 mCurrentFrame.fbCount = 0;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700625 memcpy(&mCurrentFrame.isFBComposed, &mCurrentFrame.drop,
626 sizeof(mCurrentFrame.isFBComposed));
627 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount -
628 mCurrentFrame.dropCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700629
radhakrishnac9a67412013-09-25 17:40:42 +0530630 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800631 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530632 }
633
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800634 if(!postHeuristicsHandling(ctx, list)) {
635 ALOGD_IF(isDebug(), "post heuristic handling failed");
636 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700637 return false;
638 }
639
Saurabh Shahaa236822013-04-24 18:07:26 -0700640 return true;
641}
642
643bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
644{
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700645 if(!sEnableMixedMode) {
646 //Mixed mode is disabled. No need to even try caching.
647 return false;
648 }
649
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700650 bool ret = false;
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800651 if(list->flags & HWC_GEOMETRY_CHANGED) { //Try load based first
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800652 ret = loadBasedComp(ctx, list) or
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800653 cacheBasedComp(ctx, list);
654 } else {
655 ret = cacheBasedComp(ctx, list) or
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800656 loadBasedComp(ctx, list);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700657 }
658
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700659 return ret;
660}
661
662bool MDPComp::cacheBasedComp(hwc_context_t *ctx,
663 hwc_display_contents_1_t* list) {
664 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700665 mCurrentFrame.reset(numAppLayers);
666 updateLayerCache(ctx, list);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700667
668 //If an MDP marked layer is unsupported cannot do partial MDP Comp
669 for(int i = 0; i < numAppLayers; i++) {
670 if(!mCurrentFrame.isFBComposed[i]) {
671 hwc_layer_1_t* layer = &list->hwLayers[i];
672 if(not isSupportedForMDPComp(ctx, layer)) {
673 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",
674 __FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800675 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700676 return false;
677 }
678 }
679 }
680
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700681 updateYUV(ctx, list, false /*secure only*/);
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530682 bool ret = markLayersForCaching(ctx, list); //sets up fbZ also
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700683 if(!ret) {
684 ALOGD_IF(isDebug(),"%s: batching failed, dpy %d",__FUNCTION__, mDpy);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800685 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700686 return false;
687 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700688
689 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700690
radhakrishnac9a67412013-09-25 17:40:42 +0530691 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800692 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530693 }
694
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700695 //Will benefit cases where a video has non-updating background.
696 if((mDpy > HWC_DISPLAY_PRIMARY) and
697 (mdpCount > MAX_SEC_LAYERS)) {
698 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800699 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700700 return false;
701 }
702
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800703 if(!postHeuristicsHandling(ctx, list)) {
704 ALOGD_IF(isDebug(), "post heuristic handling failed");
705 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700706 return false;
707 }
708
Saurabh Shahaa236822013-04-24 18:07:26 -0700709 return true;
710}
711
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800712bool MDPComp::loadBasedComp(hwc_context_t *ctx,
Saurabh Shahb772ae32013-11-18 15:40:02 -0800713 hwc_display_contents_1_t* list) {
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800714 if(not isLoadBasedCompDoable(ctx, list)) {
715 return false;
716 }
717
Saurabh Shahb772ae32013-11-18 15:40:02 -0800718 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800719 const int numNonDroppedLayers = numAppLayers - mCurrentFrame.dropCount;
720 const int stagesForMDP = min(sMaxPipesPerMixer,
721 ctx->mOverlay->availablePipes(mDpy, Overlay::MIXER_DEFAULT));
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800722
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800723 int mdpBatchSize = stagesForMDP - 1; //1 stage for FB
724 int fbBatchSize = numNonDroppedLayers - mdpBatchSize;
725 int lastMDPSupportedIndex = numAppLayers;
726 int dropCount = 0;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800727
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800728 //Find the minimum MDP batch size
729 for(int i = 0; i < numAppLayers;i++) {
730 if(mCurrentFrame.drop[i]) {
731 dropCount++;
Jeykumar Sankaran6279bc32014-01-23 21:59:58 -0800732 continue;
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800733 }
734 hwc_layer_1_t* layer = &list->hwLayers[i];
735 if(not isSupportedForMDPComp(ctx, layer)) {
736 lastMDPSupportedIndex = i;
737 mdpBatchSize = min(i - dropCount, stagesForMDP - 1);
738 fbBatchSize = numNonDroppedLayers - mdpBatchSize;
Jeykumar Sankaran6279bc32014-01-23 21:59:58 -0800739 break;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800740 }
Saurabh Shahb772ae32013-11-18 15:40:02 -0800741 }
742
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800743 ALOGD_IF(isDebug(), "%s:Before optimizing fbBatch, mdpbatch %d, fbbatch %d "
744 "dropped %d", __FUNCTION__, mdpBatchSize, fbBatchSize,
745 mCurrentFrame.dropCount);
746
747 //Start at a point where the fb batch should at least have 2 layers, for
748 //this mode to be justified.
749 while(fbBatchSize < 2) {
750 ++fbBatchSize;
751 --mdpBatchSize;
Jeykumar Sankaran6279bc32014-01-23 21:59:58 -0800752 }
Saurabh Shahb772ae32013-11-18 15:40:02 -0800753
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800754 //If there are no layers for MDP, this mode doesnt make sense.
755 if(mdpBatchSize < 1) {
756 ALOGD_IF(isDebug(), "%s: No MDP layers after optimizing for fbBatch",
757 __FUNCTION__);
Saurabh Shahb772ae32013-11-18 15:40:02 -0800758 return false;
759 }
760
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800761 mCurrentFrame.reset(numAppLayers);
762
763 //Try with successively smaller mdp batch sizes until we succeed or reach 1
764 while(mdpBatchSize > 0) {
765 //Mark layers for MDP comp
766 int mdpBatchLeft = mdpBatchSize;
767 for(int i = 0; i < lastMDPSupportedIndex and mdpBatchLeft; i++) {
768 if(mCurrentFrame.drop[i]) {
769 continue;
770 }
771 mCurrentFrame.isFBComposed[i] = false;
772 --mdpBatchLeft;
773 }
774
775 mCurrentFrame.fbZ = mdpBatchSize;
776 mCurrentFrame.fbCount = fbBatchSize;
777 mCurrentFrame.mdpCount = mdpBatchSize;
778
779 ALOGD_IF(isDebug(), "%s:Trying with: mdpbatch %d fbbatch %d dropped %d",
780 __FUNCTION__, mdpBatchSize, fbBatchSize,
781 mCurrentFrame.dropCount);
782
783 if(postHeuristicsHandling(ctx, list)) {
784 ALOGD_IF(isDebug(), "%s: Postheuristics handling succeeded",
785 __FUNCTION__);
786 return true;
787 }
788
789 reset(ctx);
790 --mdpBatchSize;
791 ++fbBatchSize;
792 }
793
794 return false;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800795}
796
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700797bool MDPComp::isLoadBasedCompDoable(hwc_context_t *ctx,
798 hwc_display_contents_1_t* list) {
Prabhanjan Kandula3dbbd882013-12-11 14:43:46 +0530799 if(mDpy or isSecurePresent(ctx, mDpy) or
800 isYuvPresent(ctx, mDpy)) {
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700801 return false;
802 }
803 return true;
804}
805
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800806bool MDPComp::tryVideoOnly(hwc_context_t *ctx,
807 hwc_display_contents_1_t* list) {
808 const bool secureOnly = true;
809 return videoOnlyComp(ctx, list, not secureOnly) or
810 videoOnlyComp(ctx, list, secureOnly);
811}
812
813bool MDPComp::videoOnlyComp(hwc_context_t *ctx,
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700814 hwc_display_contents_1_t* list, bool secureOnly) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700815 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700816
Saurabh Shahaa236822013-04-24 18:07:26 -0700817 mCurrentFrame.reset(numAppLayers);
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700818 updateYUV(ctx, list, secureOnly);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700819 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700820
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800821 if(!isYuvPresent(ctx, mDpy) or (mdpCount == 0)) {
822 reset(ctx);
Saurabh Shahaa236822013-04-24 18:07:26 -0700823 return false;
824 }
825
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -0800826 /* Bail out if we are processing only secured video layers
827 * and we dont have any */
828 if(!isSecurePresent(ctx, mDpy) && secureOnly){
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800829 reset(ctx);
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -0800830 return false;
831 }
832
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800833 if(mCurrentFrame.fbCount)
834 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
Saurabh Shah4fdde762013-04-30 18:47:33 -0700835
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800836 if(sEnable4k2kYUVSplit){
837 adjustForSourceSplit(ctx, list);
838 }
839
840 if(!postHeuristicsHandling(ctx, list)) {
841 ALOGD_IF(isDebug(), "post heuristic handling failed");
842 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700843 return false;
844 }
845
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800846 return true;
847}
848
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800849/* Checks for conditions where YUV layers cannot be bypassed */
850bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -0700851 if(isSkipLayer(layer)) {
Saurabh Shahe2474082013-05-15 16:32:13 -0700852 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800853 return false;
854 }
855
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700856 if(layer->transform & HWC_TRANSFORM_ROT_90 && !canUseRotator(ctx,mDpy)) {
857 ALOGD_IF(isDebug(), "%s: no free DMA pipe",__FUNCTION__);
858 return false;
859 }
860
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800861 if(isSecuring(ctx, layer)) {
862 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
863 return false;
864 }
865
Saurabh Shah4fdde762013-04-30 18:47:33 -0700866 if(!isValidDimension(ctx, layer)) {
867 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
868 __FUNCTION__);
869 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800870 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700871
Naseer Ahmeddc61a972013-07-10 17:50:54 -0400872 if(layer->planeAlpha < 0xFF) {
873 ALOGD_IF(isDebug(), "%s: Cannot handle YUV layer with plane alpha\
874 in video only mode",
875 __FUNCTION__);
876 return false;
877 }
878
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800879 return true;
880}
881
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530882/* starts at fromIndex and check for each layer to find
883 * if it it has overlapping with any Updating layer above it in zorder
884 * till the end of the batch. returns true if it finds any intersection */
885bool MDPComp::canPushBatchToTop(const hwc_display_contents_1_t* list,
886 int fromIndex, int toIndex) {
887 for(int i = fromIndex; i < toIndex; i++) {
888 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
889 if(intersectingUpdatingLayers(list, i+1, toIndex, i)) {
890 return false;
891 }
892 }
893 }
894 return true;
895}
896
897/* Checks if given layer at targetLayerIndex has any
898 * intersection with all the updating layers in beween
899 * fromIndex and toIndex. Returns true if it finds intersectiion */
900bool MDPComp::intersectingUpdatingLayers(const hwc_display_contents_1_t* list,
901 int fromIndex, int toIndex, int targetLayerIndex) {
902 for(int i = fromIndex; i <= toIndex; i++) {
903 if(!mCurrentFrame.isFBComposed[i]) {
904 if(areLayersIntersecting(&list->hwLayers[i],
905 &list->hwLayers[targetLayerIndex])) {
906 return true;
907 }
908 }
909 }
910 return false;
911}
912
913int MDPComp::getBatch(hwc_display_contents_1_t* list,
914 int& maxBatchStart, int& maxBatchEnd,
915 int& maxBatchCount) {
916 int i = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530917 int fbZOrder =-1;
Jeykumar Sankaran5a495da2014-01-20 12:25:32 -0800918 int droppedLayerCt = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530919 while (i < mCurrentFrame.layerCount) {
920 int batchCount = 0;
921 int batchStart = i;
922 int batchEnd = i;
Jeykumar Sankaran5a495da2014-01-20 12:25:32 -0800923 /* Adjust batch Z order with the dropped layers so far */
924 int fbZ = batchStart - droppedLayerCt;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530925 int firstZReverseIndex = -1;
Prabhanjan Kandula0ed2cc92013-12-06 12:39:04 +0530926 int updatingLayersAbove = 0;//Updating layer count in middle of batch
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530927 while(i < mCurrentFrame.layerCount) {
928 if(!mCurrentFrame.isFBComposed[i]) {
929 if(!batchCount) {
930 i++;
931 break;
932 }
933 updatingLayersAbove++;
934 i++;
935 continue;
936 } else {
937 if(mCurrentFrame.drop[i]) {
938 i++;
Jeykumar Sankaran5a495da2014-01-20 12:25:32 -0800939 droppedLayerCt++;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530940 continue;
941 } else if(updatingLayersAbove <= 0) {
942 batchCount++;
943 batchEnd = i;
944 i++;
945 continue;
946 } else { //Layer is FBComposed, not a drop & updatingLayer > 0
947
948 // We have a valid updating layer already. If layer-i not
949 // have overlapping with all updating layers in between
950 // batch-start and i, then we can add layer i to batch.
951 if(!intersectingUpdatingLayers(list, batchStart, i-1, i)) {
952 batchCount++;
953 batchEnd = i;
954 i++;
955 continue;
956 } else if(canPushBatchToTop(list, batchStart, i)) {
957 //If All the non-updating layers with in this batch
958 //does not have intersection with the updating layers
959 //above in z-order, then we can safely move the batch to
960 //higher z-order. Increment fbZ as it is moving up.
961 if( firstZReverseIndex < 0) {
962 firstZReverseIndex = i;
963 }
964 batchCount++;
965 batchEnd = i;
966 fbZ += updatingLayersAbove;
967 i++;
968 updatingLayersAbove = 0;
969 continue;
970 } else {
971 //both failed.start the loop again from here.
972 if(firstZReverseIndex >= 0) {
973 i = firstZReverseIndex;
974 }
975 break;
976 }
977 }
978 }
979 }
980 if(batchCount > maxBatchCount) {
981 maxBatchCount = batchCount;
982 maxBatchStart = batchStart;
983 maxBatchEnd = batchEnd;
984 fbZOrder = fbZ;
985 }
986 }
987 return fbZOrder;
988}
989
990bool MDPComp::markLayersForCaching(hwc_context_t* ctx,
991 hwc_display_contents_1_t* list) {
992 /* Idea is to keep as many non-updating(cached) layers in FB and
993 * send rest of them through MDP. This is done in 2 steps.
994 * 1. Find the maximum contiguous batch of non-updating layers.
995 * 2. See if we can improve this batch size for caching by adding
996 * opaque layers around the batch, if they don't have
997 * any overlapping with the updating layers in between.
998 * NEVER mark an updating layer for caching.
999 * But cached ones can be marked for MDP */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001000
1001 int maxBatchStart = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001002 int maxBatchEnd = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001003 int maxBatchCount = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301004 int fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001005
Saurabh Shahce188452014-02-05 10:17:43 -08001006 /* Nothing is cached. No batching needed */
1007 if(mCurrentFrame.fbCount == 0) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001008 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -07001009 }
Saurabh Shahce188452014-02-05 10:17:43 -08001010
1011 /* No MDP comp layers, try to use other comp modes */
1012 if(mCurrentFrame.mdpCount == 0) {
1013 return false;
Saurabh Shahaa236822013-04-24 18:07:26 -07001014 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001015
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301016 fbZ = getBatch(list, maxBatchStart, maxBatchEnd, maxBatchCount);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001017
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301018 /* reset rest of the layers lying inside ROI for MDP comp */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001019 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001020 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001021 if((i < maxBatchStart || i > maxBatchEnd) &&
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301022 mCurrentFrame.isFBComposed[i]){
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001023 if(!mCurrentFrame.drop[i]){
1024 //If an unsupported layer is being attempted to
1025 //be pulled out we should fail
1026 if(not isSupportedForMDPComp(ctx, layer)) {
1027 return false;
1028 }
1029 mCurrentFrame.isFBComposed[i] = false;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001030 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001031 }
1032 }
1033
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301034 // update the frame data
1035 mCurrentFrame.fbZ = fbZ;
1036 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001037 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001038 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001039
1040 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301041 mCurrentFrame.fbCount);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001042
1043 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001044}
Saurabh Shah85234ec2013-04-12 17:09:00 -07001045
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001046void MDPComp::updateLayerCache(hwc_context_t* ctx,
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001047 hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001048 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001049 int fbCount = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001050
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001051 for(int i = 0; i < numAppLayers; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001052 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001053 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001054 if(!mCurrentFrame.drop[i])
1055 fbCount++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001056 mCurrentFrame.isFBComposed[i] = true;
1057 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -07001058 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001059 }
1060 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001061
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001062 mCurrentFrame.fbCount = fbCount;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001063 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount
1064 - mCurrentFrame.dropCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001065
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001066 ALOGD_IF(isDebug(),"%s: MDP count: %d FB count %d drop count: %d"
1067 ,__FUNCTION__, mCurrentFrame.mdpCount, mCurrentFrame.fbCount,
1068 mCurrentFrame.dropCount);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001069}
1070
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001071void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list,
1072 bool secureOnly) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001073 int nYuvCount = ctx->listStats[mDpy].yuvCount;
1074 for(int index = 0;index < nYuvCount; index++){
1075 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
1076 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
1077
1078 if(!isYUVDoable(ctx, layer)) {
1079 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
1080 mCurrentFrame.isFBComposed[nYuvIndex] = true;
1081 mCurrentFrame.fbCount++;
1082 }
1083 } else {
1084 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001085 private_handle_t *hnd = (private_handle_t *)layer->handle;
1086 if(!secureOnly || isSecureBuffer(hnd)) {
1087 mCurrentFrame.isFBComposed[nYuvIndex] = false;
1088 mCurrentFrame.fbCount--;
1089 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001090 }
1091 }
1092 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001093
1094 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001095 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
1096 ALOGD_IF(isDebug(),"%s: fb count: %d",__FUNCTION__,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001097 mCurrentFrame.fbCount);
1098}
1099
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001100bool MDPComp::postHeuristicsHandling(hwc_context_t *ctx,
1101 hwc_display_contents_1_t* list) {
1102
1103 //Capability checks
1104 if(!resourceCheck(ctx, list)) {
1105 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
1106 return false;
1107 }
1108
1109 //Limitations checks
1110 if(!hwLimitationsCheck(ctx, list)) {
1111 ALOGD_IF(isDebug(), "%s: HW limitations",__FUNCTION__);
1112 return false;
1113 }
1114
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001115 //Configure framebuffer first if applicable
1116 if(mCurrentFrame.fbZ >= 0) {
1117 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, mCurrentFrame.fbZ)) {
1118 ALOGD_IF(isDebug(), "%s configure framebuffer failed",
1119 __FUNCTION__);
1120 return false;
1121 }
1122 }
1123
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001124 mCurrentFrame.map();
1125
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001126 if(!allocLayerPipes(ctx, list)) {
1127 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -07001128 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001129 }
1130
1131 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001132 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001133 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001134 int mdpIndex = mCurrentFrame.layerToMDP[index];
1135 hwc_layer_1_t* layer = &list->hwLayers[index];
1136
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301137 //Leave fbZ for framebuffer. CACHE/GLES layers go here.
1138 if(mdpNextZOrder == mCurrentFrame.fbZ) {
1139 mdpNextZOrder++;
1140 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001141 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1142 cur_pipe->zOrder = mdpNextZOrder++;
1143
radhakrishnac9a67412013-09-25 17:40:42 +05301144 private_handle_t *hnd = (private_handle_t *)layer->handle;
1145 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1146 if(configure4k2kYuv(ctx, layer,
1147 mCurrentFrame.mdpToLayer[mdpIndex])
1148 != 0 ){
1149 ALOGD_IF(isDebug(), "%s: Failed to configure split pipes \
1150 for layer %d",__FUNCTION__, index);
1151 return false;
1152 }
1153 else{
1154 mdpNextZOrder++;
1155 }
1156 continue;
1157 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001158 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
1159 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
radhakrishnac9a67412013-09-25 17:40:42 +05301160 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -07001161 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001162 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001163 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001164 }
1165
Saurabh Shah450ac972013-12-16 18:18:39 -08001166 if(!ctx->mOverlay->validateAndSet(mDpy, ctx->dpyAttr[mDpy].fd)) {
1167 ALOGD_IF(isDebug(), "%s: Failed to validate and set overlay for dpy %d"
1168 ,__FUNCTION__, mDpy);
1169 return false;
1170 }
1171
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001172 setRedraw(ctx, list);
Saurabh Shahaa236822013-04-24 18:07:26 -07001173 return true;
1174}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001175
Saurabh Shah173f4242013-11-20 09:50:12 -08001176bool MDPComp::resourceCheck(hwc_context_t *ctx,
1177 hwc_display_contents_1_t *list) {
1178 const bool fbUsed = mCurrentFrame.fbCount;
1179 if(mCurrentFrame.mdpCount > sMaxPipesPerMixer - fbUsed) {
1180 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
1181 return false;
1182 }
Saurabh Shah173f4242013-11-20 09:50:12 -08001183 return true;
1184}
1185
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301186bool MDPComp::hwLimitationsCheck(hwc_context_t* ctx,
1187 hwc_display_contents_1_t* list) {
1188
1189 //A-family hw limitation:
1190 //If a layer need alpha scaling, MDP can not support.
1191 if(ctx->mMDP.version < qdutils::MDSS_V5) {
1192 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1193 if(!mCurrentFrame.isFBComposed[i] &&
1194 isAlphaScaled( &list->hwLayers[i])) {
1195 ALOGD_IF(isDebug(), "%s:frame needs alphaScaling",__FUNCTION__);
1196 return false;
1197 }
1198 }
1199 }
1200
1201 // On 8x26 & 8974 hw, we have a limitation of downscaling+blending.
1202 //If multiple layers requires downscaling and also they are overlapping
1203 //fall back to GPU since MDSS can not handle it.
1204 if(qdutils::MDPVersion::getInstance().is8x74v2() ||
1205 qdutils::MDPVersion::getInstance().is8x26()) {
1206 for(int i = 0; i < mCurrentFrame.layerCount-1; ++i) {
1207 hwc_layer_1_t* botLayer = &list->hwLayers[i];
1208 if(!mCurrentFrame.isFBComposed[i] &&
1209 isDownscaleRequired(botLayer)) {
1210 //if layer-i is marked for MDP and needs downscaling
1211 //check if any MDP layer on top of i & overlaps with layer-i
1212 for(int j = i+1; j < mCurrentFrame.layerCount; ++j) {
1213 hwc_layer_1_t* topLayer = &list->hwLayers[j];
1214 if(!mCurrentFrame.isFBComposed[j] &&
1215 isDownscaleRequired(topLayer)) {
1216 hwc_rect_t r = getIntersection(botLayer->displayFrame,
1217 topLayer->displayFrame);
1218 if(isValidRect(r))
1219 return false;
1220 }
1221 }
1222 }
1223 }
1224 }
1225 return true;
1226}
1227
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001228int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001229 int ret = 0;
Raj Kamal5166b312014-06-06 13:45:20 +05301230
1231 if(!ctx || !list) {
1232 ALOGE("%s: Invalid context or list",__FUNCTION__);
1233 mCachedFrame.reset();
1234 return -1;
1235 }
1236
Saurabh Shahaa236822013-04-24 18:07:26 -07001237 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001238 MDPVersion& mdpVersion = qdutils::MDPVersion::getInstance();
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -07001239
Raj Kamalfc5b9222014-02-07 16:15:17 +05301240 //Do not cache the information for next draw cycle.
1241 if(numLayers > MAX_NUM_APP_LAYERS or (!numLayers)) {
1242 ALOGI("%s: Unsupported layer count for mdp composition",
1243 __FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001244 mCachedFrame.reset();
1245 return -1;
1246 }
1247
Saurabh Shahb39f8152013-08-22 10:21:44 -07001248 //reset old data
1249 mCurrentFrame.reset(numLayers);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001250 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1251 mCurrentFrame.dropCount = 0;
Prabhanjan Kandula088bd892013-07-02 23:47:13 +05301252
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -07001253 // Detect the start of animation and fall back to GPU only once to cache
1254 // all the layers in FB and display FB content untill animation completes.
1255 if(ctx->listStats[mDpy].isDisplayAnimating) {
1256 mCurrentFrame.needsRedraw = false;
1257 if(ctx->mAnimationState[mDpy] == ANIMATION_STOPPED) {
1258 mCurrentFrame.needsRedraw = true;
1259 ctx->mAnimationState[mDpy] = ANIMATION_STARTED;
1260 }
1261 setMDPCompLayerFlags(ctx, list);
1262 mCachedFrame.updateCounts(mCurrentFrame);
1263 ret = -1;
1264 return ret;
1265 } else {
1266 ctx->mAnimationState[mDpy] = ANIMATION_STOPPED;
1267 }
1268
Saurabh Shahb39f8152013-08-22 10:21:44 -07001269 //Hard conditions, if not met, cannot do MDP comp
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001270 if(isFrameDoable(ctx)) {
1271 generateROI(ctx, list);
Saurabh Shahb39f8152013-08-22 10:21:44 -07001272
Raj Kamal5166b312014-06-06 13:45:20 +05301273 mModeOn = tryFullFrame(ctx, list) || tryVideoOnly(ctx, list);
1274 if(mModeOn) {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001275 setMDPCompLayerFlags(ctx, list);
1276 } else {
1277 reset(ctx);
1278 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1279 mCurrentFrame.dropCount = 0;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001280 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001281 }
1282 } else {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001283 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
1284 __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001285 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001286 }
Saurabh Shahb39f8152013-08-22 10:21:44 -07001287
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001288 if(isDebug()) {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001289 ALOGD("GEOMETRY change: %d",
1290 (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001291 android::String8 sDump("");
1292 dump(sDump);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001293 ALOGD("%s",sDump.string());
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001294 }
1295
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001296 mCachedFrame.cacheAll(list);
1297 mCachedFrame.updateCounts(mCurrentFrame);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001298 return ret;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001299}
1300
radhakrishnac9a67412013-09-25 17:40:42 +05301301bool MDPComp::allocSplitVGPipesfor4k2k(hwc_context_t *ctx,
1302 hwc_display_contents_1_t* list, int index) {
1303
1304 bool bRet = true;
1305 hwc_layer_1_t* layer = &list->hwLayers[index];
1306 private_handle_t *hnd = (private_handle_t *)layer->handle;
1307 int mdpIndex = mCurrentFrame.layerToMDP[index];
1308 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
1309 info.pipeInfo = new MdpYUVPipeInfo;
1310 info.rot = NULL;
1311 MdpYUVPipeInfo& pipe_info = *(MdpYUVPipeInfo*)info.pipeInfo;
1312 ePipeType type = MDPCOMP_OV_VG;
1313
1314 pipe_info.lIndex = ovutils::OV_INVALID;
1315 pipe_info.rIndex = ovutils::OV_INVALID;
1316
1317 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
1318 if(pipe_info.lIndex == ovutils::OV_INVALID){
1319 bRet = false;
1320 ALOGD_IF(isDebug(),"%s: allocating first VG pipe failed",
1321 __FUNCTION__);
1322 }
1323 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
1324 if(pipe_info.rIndex == ovutils::OV_INVALID){
1325 bRet = false;
1326 ALOGD_IF(isDebug(),"%s: allocating second VG pipe failed",
1327 __FUNCTION__);
1328 }
1329 return bRet;
1330}
Saurabh Shah88e4d272013-09-03 13:31:29 -07001331//=============MDPCompNonSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001332
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001333void MDPCompNonSplit::adjustForSourceSplit(hwc_context_t *ctx,
radhakrishnac9a67412013-09-25 17:40:42 +05301334 hwc_display_contents_1_t* list){
1335 //As we split 4kx2k yuv layer and program to 2 VG pipes
1336 //(if available) increase mdpcount accordingly
1337 mCurrentFrame.mdpCount += ctx->listStats[mDpy].yuv4k2kCount;
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001338
1339 //If 4k2k Yuv layer split is possible, and if
1340 //fbz is above 4k2k layer, increment fb zorder by 1
1341 //as we split 4k2k layer and increment zorder for right half
1342 //of the layer
1343 if(mCurrentFrame.fbZ >= 0) {
Dileep Kumar Reddi2268dd72014-05-22 22:24:53 +05301344 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
1345 index++) {
1346 if(!mCurrentFrame.isFBComposed[index]) {
1347 if(mdpNextZOrder == mCurrentFrame.fbZ) {
1348 mdpNextZOrder++;
1349 }
1350 mdpNextZOrder++;
1351 hwc_layer_1_t* layer = &list->hwLayers[index];
1352 private_handle_t *hnd = (private_handle_t *)layer->handle;
1353 if(is4kx2kYuvBuffer(hnd)) {
1354 if(mdpNextZOrder <= mCurrentFrame.fbZ)
1355 mCurrentFrame.fbZ += 1;
1356 mdpNextZOrder++;
1357 //As we split 4kx2k yuv layer and program to 2 VG pipes
1358 //(if available) increase mdpcount by 1.
1359 mCurrentFrame.mdpCount++;
1360 }
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001361 }
1362 }
1363 }
radhakrishnac9a67412013-09-25 17:40:42 +05301364}
1365
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001366/*
1367 * Configures pipe(s) for MDP composition
1368 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001369int MDPCompNonSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001370 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001371 MdpPipeInfoNonSplit& mdp_info =
1372 *(static_cast<MdpPipeInfoNonSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001373 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
1374 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1375 eIsFg isFg = IS_FG_OFF;
1376 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001377
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001378 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
1379 __FUNCTION__, layer, zOrder, dest);
1380
Saurabh Shah88e4d272013-09-03 13:31:29 -07001381 return configureNonSplit(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001382 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001383}
1384
Saurabh Shah88e4d272013-09-03 13:31:29 -07001385bool MDPCompNonSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001386 hwc_display_contents_1_t* list) {
1387 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001388
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001389 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001390
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001391 hwc_layer_1_t* layer = &list->hwLayers[index];
1392 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301393 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1394 if(allocSplitVGPipesfor4k2k(ctx, list, index)){
1395 continue;
1396 }
1397 }
1398
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001399 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001400 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001401 info.pipeInfo = new MdpPipeInfoNonSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08001402 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001403 MdpPipeInfoNonSplit& pipe_info = *(MdpPipeInfoNonSplit*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001404 ePipeType type = MDPCOMP_OV_ANY;
1405
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001406 if(isYuvBuffer(hnd)) {
1407 type = MDPCOMP_OV_VG;
Prabhanjan Kandula5b8913e2014-01-22 23:01:45 +05301408 } else if(qdutils::MDPVersion::getInstance().is8x26() &&
1409 (ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres > 1024)) {
1410 if(qhwc::needsScaling(layer))
1411 type = MDPCOMP_OV_RGB;
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301412 } else if(!qhwc::needsScaling(layer)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001413 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
1414 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001415 type = MDPCOMP_OV_DMA;
1416 }
1417
Xu Yang5c2b3af2014-04-08 13:56:47 +08001418 // for 8x26, never allow primary display occupy DMA pipe
1419 // when external display is connected
1420 if(qdutils::MDPVersion::getInstance().is8x26()
1421 && ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isActive
1422 && ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected
1423 && !ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isPause
1424 && mDpy == HWC_DISPLAY_PRIMARY
1425 && type == MDPCOMP_OV_DMA) {
1426 type = MDPCOMP_OV_RGB;
1427 }
1428
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001429 pipe_info.index = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001430 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001431 ALOGD_IF(isDebug(), "%s: Unable to get pipe type = %d",
1432 __FUNCTION__, (int) type);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001433 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001434 }
1435 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001436 return true;
1437}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001438
radhakrishnac9a67412013-09-25 17:40:42 +05301439int MDPCompNonSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1440 PipeLayerPair& PipeLayerPair) {
1441 MdpYUVPipeInfo& mdp_info =
1442 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1443 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1444 eIsFg isFg = IS_FG_OFF;
1445 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1446 eDest lDest = mdp_info.lIndex;
1447 eDest rDest = mdp_info.rIndex;
1448
1449 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1450 lDest, rDest, &PipeLayerPair.rot);
1451}
1452
Saurabh Shah88e4d272013-09-03 13:31:29 -07001453bool MDPCompNonSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001454
Raj Kamal5166b312014-06-06 13:45:20 +05301455 if(!isEnabled() or !mModeOn) {
1456 ALOGD_IF(isDebug(),"%s: MDP Comp not enabled/configured", __FUNCTION__);
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301457 return true;
1458 }
1459
Ramkumar Radhakrishnand8595ae2014-02-06 21:31:29 -08001460 // Set the Handle timeout to true for MDP or MIXED composition.
1461 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount) {
1462 sHandleTimeout = true;
1463 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001464
1465 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001466 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001467
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001468 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1469 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001470 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001471 if(mCurrentFrame.isFBComposed[i]) continue;
1472
Naseer Ahmed5b6708a2012-08-02 13:46:08 -07001473 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001474 private_handle_t *hnd = (private_handle_t *)layer->handle;
1475 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001476 if (!(layer->flags & HWC_COLOR_FILL)) {
1477 ALOGE("%s handle null", __FUNCTION__);
1478 return false;
1479 }
1480 // No PLAY for Color layer
1481 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1482 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001483 }
1484
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001485 int mdpIndex = mCurrentFrame.layerToMDP[i];
1486
radhakrishnac9a67412013-09-25 17:40:42 +05301487 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1488 {
1489 MdpYUVPipeInfo& pipe_info =
1490 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1491 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1492 ovutils::eDest indexL = pipe_info.lIndex;
1493 ovutils::eDest indexR = pipe_info.rIndex;
1494 int fd = hnd->fd;
1495 uint32_t offset = hnd->offset;
1496 if(rot) {
1497 rot->queueBuffer(fd, offset);
1498 fd = rot->getDstMemId();
1499 offset = rot->getDstOffset();
1500 }
1501 if(indexL != ovutils::OV_INVALID) {
1502 ovutils::eDest destL = (ovutils::eDest)indexL;
1503 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1504 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1505 if (!ov.queueBuffer(fd, offset, destL)) {
1506 ALOGE("%s: queueBuffer failed for display:%d",
1507 __FUNCTION__, mDpy);
1508 return false;
1509 }
1510 }
1511
1512 if(indexR != ovutils::OV_INVALID) {
1513 ovutils::eDest destR = (ovutils::eDest)indexR;
1514 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1515 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1516 if (!ov.queueBuffer(fd, offset, destR)) {
1517 ALOGE("%s: queueBuffer failed for display:%d",
1518 __FUNCTION__, mDpy);
1519 return false;
1520 }
1521 }
1522 }
1523 else{
1524 MdpPipeInfoNonSplit& pipe_info =
Saurabh Shah88e4d272013-09-03 13:31:29 -07001525 *(MdpPipeInfoNonSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
radhakrishnac9a67412013-09-25 17:40:42 +05301526 ovutils::eDest dest = pipe_info.index;
1527 if(dest == ovutils::OV_INVALID) {
1528 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001529 return false;
radhakrishnac9a67412013-09-25 17:40:42 +05301530 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001531
radhakrishnac9a67412013-09-25 17:40:42 +05301532 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1533 continue;
1534 }
1535
1536 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1537 using pipe: %d", __FUNCTION__, layer,
1538 hnd, dest );
1539
1540 int fd = hnd->fd;
1541 uint32_t offset = hnd->offset;
1542
1543 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1544 if(rot) {
1545 if(!rot->queueBuffer(fd, offset))
1546 return false;
1547 fd = rot->getDstMemId();
1548 offset = rot->getDstOffset();
1549 }
1550
1551 if (!ov.queueBuffer(fd, offset, dest)) {
1552 ALOGE("%s: queueBuffer failed for display:%d ",
1553 __FUNCTION__, mDpy);
1554 return false;
1555 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001556 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001557
1558 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001559 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001560 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001561}
1562
Saurabh Shah88e4d272013-09-03 13:31:29 -07001563//=============MDPCompSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001564
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001565void MDPCompSplit::adjustForSourceSplit(hwc_context_t *ctx,
radhakrishnac9a67412013-09-25 17:40:42 +05301566 hwc_display_contents_1_t* list){
1567 //if 4kx2k yuv layer is totally present in either in left half
1568 //or right half then try splitting the yuv layer to avoid decimation
radhakrishnac9a67412013-09-25 17:40:42 +05301569 const int lSplit = getLeftSplit(ctx, mDpy);
Dileep Kumar Reddi2268dd72014-05-22 22:24:53 +05301570 if(mCurrentFrame.fbZ >= 0) {
1571 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
1572 index++) {
1573 if(!mCurrentFrame.isFBComposed[index]) {
1574 if(mdpNextZOrder == mCurrentFrame.fbZ) {
1575 mdpNextZOrder++;
1576 }
1577 mdpNextZOrder++;
1578 hwc_layer_1_t* layer = &list->hwLayers[index];
1579 private_handle_t *hnd = (private_handle_t *)layer->handle;
1580 if(is4kx2kYuvBuffer(hnd)) {
1581 hwc_rect_t dst = layer->displayFrame;
1582 if((dst.left > lSplit) || (dst.right < lSplit)) {
1583 mCurrentFrame.mdpCount += 1;
1584 }
1585 if(mdpNextZOrder <= mCurrentFrame.fbZ)
1586 mCurrentFrame.fbZ += 1;
1587 mdpNextZOrder++;
1588 }
1589 }
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001590 }
radhakrishnac9a67412013-09-25 17:40:42 +05301591 }
1592}
1593
Saurabh Shah88e4d272013-09-03 13:31:29 -07001594bool MDPCompSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
1595 MdpPipeInfoSplit& pipe_info,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001596 ePipeType type) {
1597 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001598 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001599
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001600 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001601 pipe_info.lIndex = ovutils::OV_INVALID;
1602 pipe_info.rIndex = ovutils::OV_INVALID;
1603
1604 if (dst.left < lSplit) {
1605 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_LEFT);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001606 if(pipe_info.lIndex == ovutils::OV_INVALID)
1607 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001608 }
1609
1610 if(dst.right > lSplit) {
1611 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_RIGHT);
1612 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001613 return false;
1614 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001615
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001616 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001617}
1618
Saurabh Shah88e4d272013-09-03 13:31:29 -07001619bool MDPCompSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001620 hwc_display_contents_1_t* list) {
1621 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001622
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001623 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001624
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001625 hwc_layer_1_t* layer = &list->hwLayers[index];
1626 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301627 hwc_rect_t dst = layer->displayFrame;
1628 const int lSplit = getLeftSplit(ctx, mDpy);
1629 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1630 if((dst.left > lSplit)||(dst.right < lSplit)){
1631 if(allocSplitVGPipesfor4k2k(ctx, list, index)){
1632 continue;
1633 }
1634 }
1635 }
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001636 int mdpIndex = mCurrentFrame.layerToMDP[index];
1637 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001638 info.pipeInfo = new MdpPipeInfoSplit;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001639 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001640 MdpPipeInfoSplit& pipe_info = *(MdpPipeInfoSplit*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001641 ePipeType type = MDPCOMP_OV_ANY;
1642
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001643 if(isYuvBuffer(hnd)) {
1644 type = MDPCOMP_OV_VG;
Sushil Chauhan15a2ea62013-09-04 18:28:36 -07001645 } else if(!qhwc::needsScalingWithSplit(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001646 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001647 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001648 type = MDPCOMP_OV_DMA;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001649 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001650
1651 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001652 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type = %d",
1653 __FUNCTION__, (int) type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001654 return false;
1655 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001656 }
1657 return true;
1658}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001659
radhakrishnac9a67412013-09-25 17:40:42 +05301660int MDPCompSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1661 PipeLayerPair& PipeLayerPair) {
1662 const int lSplit = getLeftSplit(ctx, mDpy);
1663 hwc_rect_t dst = layer->displayFrame;
1664 if((dst.left > lSplit)||(dst.right < lSplit)){
1665 MdpYUVPipeInfo& mdp_info =
1666 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1667 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1668 eIsFg isFg = IS_FG_OFF;
1669 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1670 eDest lDest = mdp_info.lIndex;
1671 eDest rDest = mdp_info.rIndex;
1672
1673 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1674 lDest, rDest, &PipeLayerPair.rot);
1675 }
1676 else{
1677 return configure(ctx, layer, PipeLayerPair);
1678 }
1679}
1680
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001681/*
1682 * Configures pipe(s) for MDP composition
1683 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001684int MDPCompSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001685 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001686 MdpPipeInfoSplit& mdp_info =
1687 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001688 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1689 eIsFg isFg = IS_FG_OFF;
1690 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1691 eDest lDest = mdp_info.lIndex;
1692 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001693
1694 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1695 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1696
Saurabh Shah88e4d272013-09-03 13:31:29 -07001697 return configureSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001698 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001699}
1700
Saurabh Shah88e4d272013-09-03 13:31:29 -07001701bool MDPCompSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001702
Raj Kamal5166b312014-06-06 13:45:20 +05301703 if(!isEnabled() or !mModeOn) {
1704 ALOGD_IF(isDebug(),"%s: MDP Comp not enabled/configured", __FUNCTION__);
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301705 return true;
1706 }
1707
Ramkumar Radhakrishnand8595ae2014-02-06 21:31:29 -08001708 // Set the Handle timeout to true for MDP or MIXED composition.
1709 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount) {
1710 sHandleTimeout = true;
1711 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001712
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001713 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001714 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001715
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001716 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1717 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001718 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001719 if(mCurrentFrame.isFBComposed[i]) continue;
1720
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001721 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001722 private_handle_t *hnd = (private_handle_t *)layer->handle;
1723 if(!hnd) {
1724 ALOGE("%s handle null", __FUNCTION__);
1725 return false;
1726 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001727
1728 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1729 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001730 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001731
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001732 int mdpIndex = mCurrentFrame.layerToMDP[i];
1733
radhakrishnac9a67412013-09-25 17:40:42 +05301734 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1735 {
1736 MdpYUVPipeInfo& pipe_info =
1737 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1738 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1739 ovutils::eDest indexL = pipe_info.lIndex;
1740 ovutils::eDest indexR = pipe_info.rIndex;
1741 int fd = hnd->fd;
1742 uint32_t offset = hnd->offset;
1743 if(rot) {
1744 rot->queueBuffer(fd, offset);
1745 fd = rot->getDstMemId();
1746 offset = rot->getDstOffset();
1747 }
1748 if(indexL != ovutils::OV_INVALID) {
1749 ovutils::eDest destL = (ovutils::eDest)indexL;
1750 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1751 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1752 if (!ov.queueBuffer(fd, offset, destL)) {
1753 ALOGE("%s: queueBuffer failed for display:%d",
1754 __FUNCTION__, mDpy);
1755 return false;
1756 }
1757 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001758
radhakrishnac9a67412013-09-25 17:40:42 +05301759 if(indexR != ovutils::OV_INVALID) {
1760 ovutils::eDest destR = (ovutils::eDest)indexR;
1761 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1762 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1763 if (!ov.queueBuffer(fd, offset, destR)) {
1764 ALOGE("%s: queueBuffer failed for display:%d",
1765 __FUNCTION__, mDpy);
1766 return false;
1767 }
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001768 }
1769 }
radhakrishnac9a67412013-09-25 17:40:42 +05301770 else{
1771 MdpPipeInfoSplit& pipe_info =
1772 *(MdpPipeInfoSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1773 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001774
radhakrishnac9a67412013-09-25 17:40:42 +05301775 ovutils::eDest indexL = pipe_info.lIndex;
1776 ovutils::eDest indexR = pipe_info.rIndex;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001777
radhakrishnac9a67412013-09-25 17:40:42 +05301778 int fd = hnd->fd;
1779 int offset = hnd->offset;
1780
Tatenda Chipeperekwa2f8cd2b2014-04-14 10:36:06 -07001781 if(ctx->mAD->draw(ctx, fd, offset)) {
1782 fd = ctx->mAD->getDstFd(ctx);
1783 offset = ctx->mAD->getDstOffset(ctx);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001784 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001785
radhakrishnac9a67412013-09-25 17:40:42 +05301786 if(rot) {
1787 rot->queueBuffer(fd, offset);
1788 fd = rot->getDstMemId();
1789 offset = rot->getDstOffset();
1790 }
1791
1792 //************* play left mixer **********
1793 if(indexL != ovutils::OV_INVALID) {
1794 ovutils::eDest destL = (ovutils::eDest)indexL;
1795 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1796 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1797 if (!ov.queueBuffer(fd, offset, destL)) {
1798 ALOGE("%s: queueBuffer failed for left mixer",
1799 __FUNCTION__);
1800 return false;
1801 }
1802 }
1803
1804 //************* play right mixer **********
1805 if(indexR != ovutils::OV_INVALID) {
1806 ovutils::eDest destR = (ovutils::eDest)indexR;
1807 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1808 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1809 if (!ov.queueBuffer(fd, offset, destR)) {
1810 ALOGE("%s: queueBuffer failed for right mixer",
1811 __FUNCTION__);
1812 return false;
1813 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001814 }
1815 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001816
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001817 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1818 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001819
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001820 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001821}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001822}; //namespace
1823