blob: fb2dcd023ce5c1c16293c9e2222148e2a1db4b89 [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
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700166void 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 }
Ramkumar Radhakrishnand8595ae2014-02-06 21:31:29 -0800173 Locker::Autolock _l(ctx->mDrawLock);
174 // Handle timeout event only if the previous composition is MDP or MIXED.
175 if(!sHandleTimeout) {
176 ALOGD_IF(isDebug(), "%s:Do not handle this timeout", __FUNCTION__);
177 return;
178 }
Jesse Hall3be78d92012-08-21 15:12:23 -0700179 if(!ctx->proc) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700180 ALOGE("%s: HWC proc not registered", __FUNCTION__);
181 return;
182 }
183 sIdleFallBack = true;
184 /* Trigger SF to redraw the current frame */
Jesse Hall3be78d92012-08-21 15:12:23 -0700185 ctx->proc->invalidate(ctx->proc);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700186}
187
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800188void MDPComp::setMDPCompLayerFlags(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800189 hwc_display_contents_1_t* list) {
190 LayerProp *layerProp = ctx->layerProp[mDpy];
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800191
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800192 for(int index = 0; index < ctx->listStats[mDpy].numAppLayers; index++) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800193 hwc_layer_1_t* layer = &(list->hwLayers[index]);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800194 if(!mCurrentFrame.isFBComposed[index]) {
195 layerProp[index].mFlags |= HWC_MDPCOMP;
196 layer->compositionType = HWC_OVERLAY;
197 layer->hints |= HWC_HINT_CLEAR_FB;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800198 } else {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700199 /* Drop the layer when its already present in FB OR when it lies
200 * outside frame's ROI */
201 if(!mCurrentFrame.needsRedraw || mCurrentFrame.drop[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800202 layer->compositionType = HWC_OVERLAY;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700203 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800204 }
205 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700206}
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500207
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800208void MDPComp::setRedraw(hwc_context_t *ctx,
209 hwc_display_contents_1_t* list) {
210 mCurrentFrame.needsRedraw = false;
211 if(!mCachedFrame.isSameFrame(mCurrentFrame, list) ||
212 (list->flags & HWC_GEOMETRY_CHANGED) ||
213 isSkipPresent(ctx, mDpy)) {
214 mCurrentFrame.needsRedraw = true;
215 }
216}
217
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800218MDPComp::FrameInfo::FrameInfo() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700219 reset(0);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800220}
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800221
Saurabh Shahaa236822013-04-24 18:07:26 -0700222void MDPComp::FrameInfo::reset(const int& numLayers) {
223 for(int i = 0 ; i < MAX_PIPES_PER_MIXER && numLayers; i++ ) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800224 if(mdpToLayer[i].pipeInfo) {
225 delete mdpToLayer[i].pipeInfo;
226 mdpToLayer[i].pipeInfo = NULL;
227 //We dont own the rotator
228 mdpToLayer[i].rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800229 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800230 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800231
232 memset(&mdpToLayer, 0, sizeof(mdpToLayer));
233 memset(&layerToMDP, -1, sizeof(layerToMDP));
Saurabh Shahaa236822013-04-24 18:07:26 -0700234 memset(&isFBComposed, 1, sizeof(isFBComposed));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800235
Saurabh Shahaa236822013-04-24 18:07:26 -0700236 layerCount = numLayers;
237 fbCount = numLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800238 mdpCount = 0;
Saurabh Shah2f3895f2013-05-02 10:13:31 -0700239 needsRedraw = true;
Saurabh Shahce188452014-02-05 10:17:43 -0800240 fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800241}
242
Saurabh Shahaa236822013-04-24 18:07:26 -0700243void MDPComp::FrameInfo::map() {
244 // populate layer and MDP maps
245 int mdpIdx = 0;
246 for(int idx = 0; idx < layerCount; idx++) {
247 if(!isFBComposed[idx]) {
248 mdpToLayer[mdpIdx].listIndex = idx;
249 layerToMDP[idx] = mdpIdx++;
250 }
251 }
252}
253
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800254MDPComp::LayerCache::LayerCache() {
255 reset();
256}
257
258void MDPComp::LayerCache::reset() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700259 memset(&hnd, 0, sizeof(hnd));
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530260 memset(&isFBComposed, true, sizeof(isFBComposed));
261 memset(&drop, false, sizeof(drop));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800262 layerCount = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -0700263}
264
265void MDPComp::LayerCache::cacheAll(hwc_display_contents_1_t* list) {
266 const int numAppLayers = list->numHwLayers - 1;
267 for(int i = 0; i < numAppLayers; i++) {
268 hnd[i] = list->hwLayers[i].handle;
269 }
270}
271
272void MDPComp::LayerCache::updateCounts(const FrameInfo& curFrame) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700273 layerCount = curFrame.layerCount;
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530274 memcpy(&isFBComposed, &curFrame.isFBComposed, sizeof(isFBComposed));
275 memcpy(&drop, &curFrame.drop, sizeof(drop));
276}
277
Jeykumar Sankaran988d3682013-11-15 11:57:16 -0800278bool MDPComp::LayerCache::isSameFrame(const FrameInfo& curFrame,
279 hwc_display_contents_1_t* list) {
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530280 if(layerCount != curFrame.layerCount)
281 return false;
282 for(int i = 0; i < curFrame.layerCount; i++) {
283 if((curFrame.isFBComposed[i] != isFBComposed[i]) ||
284 (curFrame.drop[i] != drop[i])) {
285 return false;
286 }
Jeykumar Sankaran988d3682013-11-15 11:57:16 -0800287 if(curFrame.isFBComposed[i] &&
288 (hnd[i] != list->hwLayers[i].handle)){
289 return false;
290 }
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530291 }
292 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800293}
294
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700295bool MDPComp::isSupportedForMDPComp(hwc_context_t *ctx, hwc_layer_1_t* layer) {
296 private_handle_t *hnd = (private_handle_t *)layer->handle;
297 if((not isYuvBuffer(hnd) and has90Transform(layer)) or
298 (not isValidDimension(ctx,layer))
299 //More conditions here, SKIP, sRGB+Blend etc
300 ) {
301 return false;
302 }
303 return true;
304}
305
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530306bool MDPComp::isValidDimension(hwc_context_t *ctx, hwc_layer_1_t *layer) {
Saurabh Shah4fdde762013-04-30 18:47:33 -0700307 const int dpy = HWC_DISPLAY_PRIMARY;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800308 private_handle_t *hnd = (private_handle_t *)layer->handle;
309
310 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -0700311 if (layer->flags & HWC_COLOR_FILL) {
312 // Color layer
313 return true;
314 }
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800315 ALOGE("%s: layer handle is NULL", __FUNCTION__);
316 return false;
317 }
318
Naseer Ahmede850a802013-09-06 13:12:52 -0400319 //XXX: Investigate doing this with pixel phase on MDSS
Naseer Ahmede77f8082013-10-10 13:42:48 -0400320 if(!isSecureBuffer(hnd) && isNonIntegralSourceCrop(layer->sourceCropf))
Naseer Ahmede850a802013-09-06 13:12:52 -0400321 return false;
322
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800323 int hw_w = ctx->dpyAttr[mDpy].xres;
324 int hw_h = ctx->dpyAttr[mDpy].yres;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800325
Saurabh Shah62e1d732013-09-17 10:44:05 -0700326 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700327 hwc_rect_t dst = layer->displayFrame;
Saurabh Shah4fdde762013-04-30 18:47:33 -0700328 int crop_w = crop.right - crop.left;
329 int crop_h = crop.bottom - crop.top;
330 int dst_w = dst.right - dst.left;
331 int dst_h = dst.bottom - dst.top;
332 float w_dscale = ceilf((float)crop_w / (float)dst_w);
333 float h_dscale = ceilf((float)crop_h / (float)dst_h);
334
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800335 /* Workaround for MDP HW limitation in DSI command mode panels where
336 * FPS will not go beyond 30 if buffers on RGB pipes are of width or height
337 * less than 5 pixels
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530338 * There also is a HW limilation in MDP, minimum block size is 2x2
339 * Fallback to GPU if height is less than 2.
340 */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800341 if((crop_w < 5)||(crop_h < 5))
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800342 return false;
343
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800344 if((w_dscale > 1.0f) || (h_dscale > 1.0f)) {
345 const uint32_t downscale =
Saurabh Shah4fdde762013-04-30 18:47:33 -0700346 qdutils::MDPVersion::getInstance().getMaxMDPDownscale();
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800347 if(ctx->mMDP.version >= qdutils::MDSS_V5) {
348 /* Workaround for downscales larger than 4x.
349 * Will be removed once decimator block is enabled for MDSS
350 */
351 if(!qdutils::MDPVersion::getInstance().supportsDecimation()) {
352 if(crop_w > MAX_DISPLAY_DIM || w_dscale > downscale ||
353 h_dscale > downscale)
354 return false;
355 } else {
356 if(w_dscale > 64 || h_dscale > 64)
357 return false;
358 }
359 } else { //A-family
360 if(w_dscale > downscale || h_dscale > downscale)
Saurabh Shah4fdde762013-04-30 18:47:33 -0700361 return false;
362 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700363 }
364
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800365 return true;
366}
367
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700368ovutils::eDest MDPComp::getMdpPipe(hwc_context_t *ctx, ePipeType type,
369 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800370 overlay::Overlay& ov = *ctx->mOverlay;
371 ovutils::eDest mdp_pipe = ovutils::OV_INVALID;
372
373 switch(type) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800374 case MDPCOMP_OV_DMA:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700375 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_DMA, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800376 if(mdp_pipe != ovutils::OV_INVALID) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800377 return mdp_pipe;
378 }
379 case MDPCOMP_OV_ANY:
380 case MDPCOMP_OV_RGB:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700381 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800382 if(mdp_pipe != ovutils::OV_INVALID) {
383 return mdp_pipe;
384 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800385
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800386 if(type == MDPCOMP_OV_RGB) {
387 //Requested only for RGB pipe
388 break;
389 }
390 case MDPCOMP_OV_VG:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700391 return ov.nextPipe(ovutils::OV_MDP_PIPE_VG, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800392 default:
393 ALOGE("%s: Invalid pipe type",__FUNCTION__);
394 return ovutils::OV_INVALID;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800395 };
396 return ovutils::OV_INVALID;
397}
398
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800399bool MDPComp::isFrameDoable(hwc_context_t *ctx) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700400 bool ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700401 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800402
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800403 if(!isEnabled()) {
404 ALOGD_IF(isDebug(),"%s: MDP Comp. not enabled.", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700405 ret = false;
Saurabh Shahd4e65852013-06-17 11:33:53 -0700406 } else if(qdutils::MDPVersion::getInstance().is8x26() &&
Tatenda Chipeperekwa75a41812014-04-01 12:54:13 -0700407 ctx->mVideoTransFlag &&
408 isSecondaryConnected(ctx)) {
Saurabh Shahd4e65852013-06-17 11:33:53 -0700409 //1 Padding round to shift pipes across mixers
410 ALOGD_IF(isDebug(),"%s: MDP Comp. video transition padding round",
411 __FUNCTION__);
412 ret = false;
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700413 } else if(ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isConfiguring ||
414 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isConfiguring) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800415 ALOGD_IF( isDebug(),"%s: External Display connection is pending",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800416 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700417 ret = false;
Saurabh Shahaa236822013-04-24 18:07:26 -0700418 } else if(ctx->isPaddingRound) {
Raj Kamalfc5b9222014-02-07 16:15:17 +0530419 ALOGD_IF(isDebug(), "%s: padding round invoked for dpy %d",
420 __FUNCTION__,mDpy);
Saurabh Shahaa236822013-04-24 18:07:26 -0700421 ret = false;
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700422 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700423 return ret;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800424}
425
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800426/*
427 * 1) Identify layers that are not visible in the updating ROI and drop them
428 * from composition.
429 * 2) If we have a scaling layers which needs cropping against generated ROI.
430 * Reset ROI to full resolution.
431 */
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700432bool MDPComp::validateAndApplyROI(hwc_context_t *ctx,
433 hwc_display_contents_1_t* list, hwc_rect_t roi) {
434 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
435
436 if(!isValidRect(roi))
437 return false;
438
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800439 hwc_rect_t visibleRect = roi;
440
441 for(int i = numAppLayers - 1; i >= 0; i--){
442
443 if(!isValidRect(visibleRect)) {
444 mCurrentFrame.drop[i] = true;
445 mCurrentFrame.dropCount++;
Jeykumar Sankaran65bc8022014-01-21 17:26:12 -0800446 continue;
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800447 }
448
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700449 const hwc_layer_1_t* layer = &list->hwLayers[i];
450
451 hwc_rect_t dstRect = layer->displayFrame;
Arun Kumar K.R91090c72013-10-28 19:40:18 -0700452 hwc_rect_t srcRect = integerizeSourceCrop(layer->sourceCropf);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700453 int transform = layer->transform;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700454
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800455 hwc_rect_t res = getIntersection(visibleRect, dstRect);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700456
457 int res_w = res.right - res.left;
458 int res_h = res.bottom - res.top;
459 int dst_w = dstRect.right - dstRect.left;
460 int dst_h = dstRect.bottom - dstRect.top;
461
462 if(!isValidRect(res)) {
463 mCurrentFrame.drop[i] = true;
464 mCurrentFrame.dropCount++;
465 }else {
466 /* Reset frame ROI when any layer which needs scaling also needs ROI
467 * cropping */
Jeykumar Sankaran65bc8022014-01-21 17:26:12 -0800468 if((res_w != dst_w || res_h != dst_h) && needsScaling (layer)) {
Arpita Banerjeed8965982013-11-08 17:27:33 -0800469 ALOGI("%s: Resetting ROI due to scaling", __FUNCTION__);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700470 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
471 mCurrentFrame.dropCount = 0;
472 return false;
473 }
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800474
Jeykumar Sankaran65bc8022014-01-21 17:26:12 -0800475 /* deduct any opaque region from visibleRect */
476 if (layer->blending == HWC_BLENDING_NONE)
477 visibleRect = deductRect(visibleRect, res);
478 }
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700479 }
480 return true;
481}
482
Jeykumar Sankaran4d76a382014-02-26 18:26:58 -0800483bool MDPComp::canDoPartialUpdate(hwc_context_t *ctx,
484 hwc_display_contents_1_t* list){
485 if(!qdutils::MDPVersion::getInstance().isPartialUpdateEnabled() || mDpy ||
486 isSkipPresent(ctx, mDpy) || (list->flags & HWC_GEOMETRY_CHANGED)||
487 isDisplaySplit(ctx, mDpy)) {
488 return false;
489 }
490 return true;
491}
492
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700493void MDPComp::generateROI(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
494 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
495
Jeykumar Sankaran4d76a382014-02-26 18:26:58 -0800496 if(!canDoPartialUpdate(ctx, list))
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700497 return;
498
499 struct hwc_rect roi = (struct hwc_rect){0, 0, 0, 0};
500 for(int index = 0; index < numAppLayers; index++ ) {
Jeykumar Sankaran4d76a382014-02-26 18:26:58 -0800501 hwc_layer_1_t* layer = &list->hwLayers[index];
502 if ((mCachedFrame.hnd[index] != layer->handle) ||
503 isYuvBuffer((private_handle_t *)layer->handle)) {
504 hwc_rect_t updatingRect = layer->displayFrame;
505#ifdef QCOM_BSP
506 if(!needsScaling(layer))
507 updatingRect = layer->dirtyRect;
508#endif
509 roi = getUnion(roi, updatingRect);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700510 }
511 }
512
Jeykumar Sankaran4d76a382014-02-26 18:26:58 -0800513 hwc_rect fullFrame = (struct hwc_rect) {0, 0,(int)ctx->dpyAttr[mDpy].xres,
514 (int)ctx->dpyAttr[mDpy].yres};
515
516 // Align ROI coordinates to panel restrictions
517 roi = sanitizeROI(roi, fullFrame);
518
519 if(!validateAndApplyROI(ctx, list, roi))
520 roi = fullFrame;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700521
522 ctx->listStats[mDpy].roi.x = roi.left;
523 ctx->listStats[mDpy].roi.y = roi.top;
524 ctx->listStats[mDpy].roi.w = roi.right - roi.left;
525 ctx->listStats[mDpy].roi.h = roi.bottom - roi.top;
526
527 ALOGD_IF(isDebug(),"%s: generated ROI: [%d, %d, %d, %d]", __FUNCTION__,
528 roi.left, roi.top, roi.right, roi.bottom);
529}
530
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800531/* Checks for conditions where all the layers marked for MDP comp cannot be
532 * bypassed. On such conditions we try to bypass atleast YUV layers */
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800533bool MDPComp::tryFullFrame(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800534 hwc_display_contents_1_t* list){
535
Saurabh Shahaa236822013-04-24 18:07:26 -0700536 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800537
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -0700538 if(sIdleFallBack && !ctx->listStats[mDpy].secureUI) {
Saurabh Shah2d998a92013-05-14 17:55:58 -0700539 ALOGD_IF(isDebug(), "%s: Idle fallback dpy %d",__FUNCTION__, mDpy);
540 return false;
541 }
542
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800543 if(isSkipPresent(ctx, mDpy)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700544 ALOGD_IF(isDebug(),"%s: SKIP present: %d",
545 __FUNCTION__,
546 isSkipPresent(ctx, mDpy));
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800547 return false;
548 }
549
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800550 // check for action safe flag and downscale mode which requires scaling.
551 if(ctx->dpyAttr[mDpy].mActionSafePresent
552 || ctx->dpyAttr[mDpy].mDownScaleMode) {
553 ALOGD_IF(isDebug(), "%s: Scaling needed for this frame",__FUNCTION__);
554 return false;
555 }
556
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800557 for(int i = 0; i < numAppLayers; ++i) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800558 hwc_layer_1_t* layer = &list->hwLayers[i];
559 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800560
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700561 if(isYuvBuffer(hnd) && has90Transform(layer)) {
562 if(!canUseRotator(ctx, mDpy)) {
563 ALOGD_IF(isDebug(), "%s: Can't use rotator for dpy %d",
564 __FUNCTION__, mDpy);
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700565 return false;
566 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800567 }
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530568
569 //For 8x26 with panel width>1k, if RGB layer needs HFLIP fail mdp comp
570 // may not need it if Gfx pre-rotation can handle all flips & rotations
Sushil Chauhand8ef93f2014-03-20 11:08:41 -0700571 int transform = (layer->flags & HWC_COLOR_FILL) ? 0 : layer->transform;
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530572 if(qdutils::MDPVersion::getInstance().is8x26() &&
573 (ctx->dpyAttr[mDpy].xres > 1024) &&
Sushil Chauhand8ef93f2014-03-20 11:08:41 -0700574 (transform & HWC_TRANSFORM_FLIP_H) &&
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530575 (!isYuvBuffer(hnd)))
576 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800577 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700578
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700579 if(ctx->mAD->isDoable()) {
580 return false;
581 }
582
Saurabh Shahaa236822013-04-24 18:07:26 -0700583 //If all above hard conditions are met we can do full or partial MDP comp.
584 bool ret = false;
585 if(fullMDPComp(ctx, list)) {
586 ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700587 } else if(partialMDPComp(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700588 ret = true;
589 }
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530590
Saurabh Shahaa236822013-04-24 18:07:26 -0700591 return ret;
592}
593
594bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700595 //Will benefit presentation / secondary-only layer.
596 if((mDpy > HWC_DISPLAY_PRIMARY) &&
597 (list->numHwLayers - 1) > MAX_SEC_LAYERS) {
598 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
599 return false;
600 }
601
602 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
603 for(int i = 0; i < numAppLayers; i++) {
604 hwc_layer_1_t* layer = &list->hwLayers[i];
605 if(not isSupportedForMDPComp(ctx, layer)) {
606 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",__FUNCTION__);
607 return false;
608 }
609 }
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800610
Saurabh Shahaa236822013-04-24 18:07:26 -0700611 mCurrentFrame.fbCount = 0;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700612 memcpy(&mCurrentFrame.isFBComposed, &mCurrentFrame.drop,
613 sizeof(mCurrentFrame.isFBComposed));
614 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount -
615 mCurrentFrame.dropCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700616
radhakrishnac9a67412013-09-25 17:40:42 +0530617 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800618 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530619 }
620
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800621 if(!postHeuristicsHandling(ctx, list)) {
622 ALOGD_IF(isDebug(), "post heuristic handling failed");
623 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700624 return false;
625 }
626
Saurabh Shahaa236822013-04-24 18:07:26 -0700627 return true;
628}
629
630bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
631{
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700632 if(!sEnableMixedMode) {
633 //Mixed mode is disabled. No need to even try caching.
634 return false;
635 }
636
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700637 bool ret = false;
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800638 if(list->flags & HWC_GEOMETRY_CHANGED) { //Try load based first
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800639 ret = loadBasedComp(ctx, list) or
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800640 cacheBasedComp(ctx, list);
641 } else {
642 ret = cacheBasedComp(ctx, list) or
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800643 loadBasedComp(ctx, list);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700644 }
645
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700646 return ret;
647}
648
649bool MDPComp::cacheBasedComp(hwc_context_t *ctx,
650 hwc_display_contents_1_t* list) {
651 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700652 mCurrentFrame.reset(numAppLayers);
653 updateLayerCache(ctx, list);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700654
655 //If an MDP marked layer is unsupported cannot do partial MDP Comp
656 for(int i = 0; i < numAppLayers; i++) {
657 if(!mCurrentFrame.isFBComposed[i]) {
658 hwc_layer_1_t* layer = &list->hwLayers[i];
659 if(not isSupportedForMDPComp(ctx, layer)) {
660 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",
661 __FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800662 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700663 return false;
664 }
665 }
666 }
667
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700668 updateYUV(ctx, list, false /*secure only*/);
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530669 bool ret = markLayersForCaching(ctx, list); //sets up fbZ also
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700670 if(!ret) {
671 ALOGD_IF(isDebug(),"%s: batching failed, dpy %d",__FUNCTION__, mDpy);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800672 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700673 return false;
674 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700675
676 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700677
radhakrishnac9a67412013-09-25 17:40:42 +0530678 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800679 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530680 }
681
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700682 //Will benefit cases where a video has non-updating background.
683 if((mDpy > HWC_DISPLAY_PRIMARY) and
684 (mdpCount > MAX_SEC_LAYERS)) {
685 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800686 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700687 return false;
688 }
689
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800690 if(!postHeuristicsHandling(ctx, list)) {
691 ALOGD_IF(isDebug(), "post heuristic handling failed");
692 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700693 return false;
694 }
695
Saurabh Shahaa236822013-04-24 18:07:26 -0700696 return true;
697}
698
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800699bool MDPComp::loadBasedComp(hwc_context_t *ctx,
Saurabh Shahb772ae32013-11-18 15:40:02 -0800700 hwc_display_contents_1_t* list) {
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800701 if(not isLoadBasedCompDoable(ctx, list)) {
702 return false;
703 }
704
Saurabh Shahb772ae32013-11-18 15:40:02 -0800705 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800706 const int numNonDroppedLayers = numAppLayers - mCurrentFrame.dropCount;
707 const int stagesForMDP = min(sMaxPipesPerMixer,
708 ctx->mOverlay->availablePipes(mDpy, Overlay::MIXER_DEFAULT));
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800709
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800710 int mdpBatchSize = stagesForMDP - 1; //1 stage for FB
711 int fbBatchSize = numNonDroppedLayers - mdpBatchSize;
712 int lastMDPSupportedIndex = numAppLayers;
713 int dropCount = 0;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800714
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800715 //Find the minimum MDP batch size
716 for(int i = 0; i < numAppLayers;i++) {
717 if(mCurrentFrame.drop[i]) {
718 dropCount++;
Jeykumar Sankaran6279bc32014-01-23 21:59:58 -0800719 continue;
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800720 }
721 hwc_layer_1_t* layer = &list->hwLayers[i];
722 if(not isSupportedForMDPComp(ctx, layer)) {
723 lastMDPSupportedIndex = i;
724 mdpBatchSize = min(i - dropCount, stagesForMDP - 1);
725 fbBatchSize = numNonDroppedLayers - mdpBatchSize;
Jeykumar Sankaran6279bc32014-01-23 21:59:58 -0800726 break;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800727 }
Saurabh Shahb772ae32013-11-18 15:40:02 -0800728 }
729
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800730 ALOGD_IF(isDebug(), "%s:Before optimizing fbBatch, mdpbatch %d, fbbatch %d "
731 "dropped %d", __FUNCTION__, mdpBatchSize, fbBatchSize,
732 mCurrentFrame.dropCount);
733
734 //Start at a point where the fb batch should at least have 2 layers, for
735 //this mode to be justified.
736 while(fbBatchSize < 2) {
737 ++fbBatchSize;
738 --mdpBatchSize;
Jeykumar Sankaran6279bc32014-01-23 21:59:58 -0800739 }
Saurabh Shahb772ae32013-11-18 15:40:02 -0800740
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800741 //If there are no layers for MDP, this mode doesnt make sense.
742 if(mdpBatchSize < 1) {
743 ALOGD_IF(isDebug(), "%s: No MDP layers after optimizing for fbBatch",
744 __FUNCTION__);
Saurabh Shahb772ae32013-11-18 15:40:02 -0800745 return false;
746 }
747
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800748 mCurrentFrame.reset(numAppLayers);
749
750 //Try with successively smaller mdp batch sizes until we succeed or reach 1
751 while(mdpBatchSize > 0) {
752 //Mark layers for MDP comp
753 int mdpBatchLeft = mdpBatchSize;
754 for(int i = 0; i < lastMDPSupportedIndex and mdpBatchLeft; i++) {
755 if(mCurrentFrame.drop[i]) {
756 continue;
757 }
758 mCurrentFrame.isFBComposed[i] = false;
759 --mdpBatchLeft;
760 }
761
762 mCurrentFrame.fbZ = mdpBatchSize;
763 mCurrentFrame.fbCount = fbBatchSize;
764 mCurrentFrame.mdpCount = mdpBatchSize;
765
766 ALOGD_IF(isDebug(), "%s:Trying with: mdpbatch %d fbbatch %d dropped %d",
767 __FUNCTION__, mdpBatchSize, fbBatchSize,
768 mCurrentFrame.dropCount);
769
770 if(postHeuristicsHandling(ctx, list)) {
771 ALOGD_IF(isDebug(), "%s: Postheuristics handling succeeded",
772 __FUNCTION__);
773 return true;
774 }
775
776 reset(ctx);
777 --mdpBatchSize;
778 ++fbBatchSize;
779 }
780
781 return false;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800782}
783
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700784bool MDPComp::isLoadBasedCompDoable(hwc_context_t *ctx,
785 hwc_display_contents_1_t* list) {
Prabhanjan Kandula3dbbd882013-12-11 14:43:46 +0530786 if(mDpy or isSecurePresent(ctx, mDpy) or
787 isYuvPresent(ctx, mDpy)) {
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700788 return false;
789 }
790 return true;
791}
792
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800793bool MDPComp::tryVideoOnly(hwc_context_t *ctx,
794 hwc_display_contents_1_t* list) {
795 const bool secureOnly = true;
796 return videoOnlyComp(ctx, list, not secureOnly) or
797 videoOnlyComp(ctx, list, secureOnly);
798}
799
800bool MDPComp::videoOnlyComp(hwc_context_t *ctx,
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700801 hwc_display_contents_1_t* list, bool secureOnly) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700802 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700803
Saurabh Shahaa236822013-04-24 18:07:26 -0700804 mCurrentFrame.reset(numAppLayers);
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700805 updateYUV(ctx, list, secureOnly);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700806 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700807
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800808 if(!isYuvPresent(ctx, mDpy) or (mdpCount == 0)) {
809 reset(ctx);
Saurabh Shahaa236822013-04-24 18:07:26 -0700810 return false;
811 }
812
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -0800813 /* Bail out if we are processing only secured video layers
814 * and we dont have any */
815 if(!isSecurePresent(ctx, mDpy) && secureOnly){
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800816 reset(ctx);
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -0800817 return false;
818 }
819
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800820 if(mCurrentFrame.fbCount)
821 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
Saurabh Shah4fdde762013-04-30 18:47:33 -0700822
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800823 if(sEnable4k2kYUVSplit){
824 adjustForSourceSplit(ctx, list);
825 }
826
827 if(!postHeuristicsHandling(ctx, list)) {
828 ALOGD_IF(isDebug(), "post heuristic handling failed");
829 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700830 return false;
831 }
832
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800833 return true;
834}
835
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800836/* Checks for conditions where YUV layers cannot be bypassed */
837bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -0700838 if(isSkipLayer(layer)) {
Saurabh Shahe2474082013-05-15 16:32:13 -0700839 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800840 return false;
841 }
842
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700843 if(layer->transform & HWC_TRANSFORM_ROT_90 && !canUseRotator(ctx,mDpy)) {
844 ALOGD_IF(isDebug(), "%s: no free DMA pipe",__FUNCTION__);
845 return false;
846 }
847
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800848 if(isSecuring(ctx, layer)) {
849 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
850 return false;
851 }
852
Saurabh Shah4fdde762013-04-30 18:47:33 -0700853 if(!isValidDimension(ctx, layer)) {
854 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
855 __FUNCTION__);
856 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800857 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700858
Naseer Ahmeddc61a972013-07-10 17:50:54 -0400859 if(layer->planeAlpha < 0xFF) {
860 ALOGD_IF(isDebug(), "%s: Cannot handle YUV layer with plane alpha\
861 in video only mode",
862 __FUNCTION__);
863 return false;
864 }
865
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800866 return true;
867}
868
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530869/* starts at fromIndex and check for each layer to find
870 * if it it has overlapping with any Updating layer above it in zorder
871 * till the end of the batch. returns true if it finds any intersection */
872bool MDPComp::canPushBatchToTop(const hwc_display_contents_1_t* list,
873 int fromIndex, int toIndex) {
874 for(int i = fromIndex; i < toIndex; i++) {
875 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
876 if(intersectingUpdatingLayers(list, i+1, toIndex, i)) {
877 return false;
878 }
879 }
880 }
881 return true;
882}
883
884/* Checks if given layer at targetLayerIndex has any
885 * intersection with all the updating layers in beween
886 * fromIndex and toIndex. Returns true if it finds intersectiion */
887bool MDPComp::intersectingUpdatingLayers(const hwc_display_contents_1_t* list,
888 int fromIndex, int toIndex, int targetLayerIndex) {
889 for(int i = fromIndex; i <= toIndex; i++) {
890 if(!mCurrentFrame.isFBComposed[i]) {
891 if(areLayersIntersecting(&list->hwLayers[i],
892 &list->hwLayers[targetLayerIndex])) {
893 return true;
894 }
895 }
896 }
897 return false;
898}
899
900int MDPComp::getBatch(hwc_display_contents_1_t* list,
901 int& maxBatchStart, int& maxBatchEnd,
902 int& maxBatchCount) {
903 int i = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530904 int fbZOrder =-1;
Jeykumar Sankaran5a495da2014-01-20 12:25:32 -0800905 int droppedLayerCt = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530906 while (i < mCurrentFrame.layerCount) {
907 int batchCount = 0;
908 int batchStart = i;
909 int batchEnd = i;
Jeykumar Sankaran5a495da2014-01-20 12:25:32 -0800910 /* Adjust batch Z order with the dropped layers so far */
911 int fbZ = batchStart - droppedLayerCt;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530912 int firstZReverseIndex = -1;
Prabhanjan Kandula0ed2cc92013-12-06 12:39:04 +0530913 int updatingLayersAbove = 0;//Updating layer count in middle of batch
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530914 while(i < mCurrentFrame.layerCount) {
915 if(!mCurrentFrame.isFBComposed[i]) {
916 if(!batchCount) {
917 i++;
918 break;
919 }
920 updatingLayersAbove++;
921 i++;
922 continue;
923 } else {
924 if(mCurrentFrame.drop[i]) {
925 i++;
Jeykumar Sankaran5a495da2014-01-20 12:25:32 -0800926 droppedLayerCt++;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530927 continue;
928 } else if(updatingLayersAbove <= 0) {
929 batchCount++;
930 batchEnd = i;
931 i++;
932 continue;
933 } else { //Layer is FBComposed, not a drop & updatingLayer > 0
934
935 // We have a valid updating layer already. If layer-i not
936 // have overlapping with all updating layers in between
937 // batch-start and i, then we can add layer i to batch.
938 if(!intersectingUpdatingLayers(list, batchStart, i-1, i)) {
939 batchCount++;
940 batchEnd = i;
941 i++;
942 continue;
943 } else if(canPushBatchToTop(list, batchStart, i)) {
944 //If All the non-updating layers with in this batch
945 //does not have intersection with the updating layers
946 //above in z-order, then we can safely move the batch to
947 //higher z-order. Increment fbZ as it is moving up.
948 if( firstZReverseIndex < 0) {
949 firstZReverseIndex = i;
950 }
951 batchCount++;
952 batchEnd = i;
953 fbZ += updatingLayersAbove;
954 i++;
955 updatingLayersAbove = 0;
956 continue;
957 } else {
958 //both failed.start the loop again from here.
959 if(firstZReverseIndex >= 0) {
960 i = firstZReverseIndex;
961 }
962 break;
963 }
964 }
965 }
966 }
967 if(batchCount > maxBatchCount) {
968 maxBatchCount = batchCount;
969 maxBatchStart = batchStart;
970 maxBatchEnd = batchEnd;
971 fbZOrder = fbZ;
972 }
973 }
974 return fbZOrder;
975}
976
977bool MDPComp::markLayersForCaching(hwc_context_t* ctx,
978 hwc_display_contents_1_t* list) {
979 /* Idea is to keep as many non-updating(cached) layers in FB and
980 * send rest of them through MDP. This is done in 2 steps.
981 * 1. Find the maximum contiguous batch of non-updating layers.
982 * 2. See if we can improve this batch size for caching by adding
983 * opaque layers around the batch, if they don't have
984 * any overlapping with the updating layers in between.
985 * NEVER mark an updating layer for caching.
986 * But cached ones can be marked for MDP */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800987
988 int maxBatchStart = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700989 int maxBatchEnd = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800990 int maxBatchCount = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530991 int fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800992
Saurabh Shahce188452014-02-05 10:17:43 -0800993 /* Nothing is cached. No batching needed */
994 if(mCurrentFrame.fbCount == 0) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700995 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -0700996 }
Saurabh Shahce188452014-02-05 10:17:43 -0800997
998 /* No MDP comp layers, try to use other comp modes */
999 if(mCurrentFrame.mdpCount == 0) {
1000 return false;
Saurabh Shahaa236822013-04-24 18:07:26 -07001001 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001002
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301003 fbZ = getBatch(list, maxBatchStart, maxBatchEnd, maxBatchCount);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001004
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301005 /* reset rest of the layers lying inside ROI for MDP comp */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001006 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001007 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001008 if((i < maxBatchStart || i > maxBatchEnd) &&
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301009 mCurrentFrame.isFBComposed[i]){
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001010 if(!mCurrentFrame.drop[i]){
1011 //If an unsupported layer is being attempted to
1012 //be pulled out we should fail
1013 if(not isSupportedForMDPComp(ctx, layer)) {
1014 return false;
1015 }
1016 mCurrentFrame.isFBComposed[i] = false;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001017 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001018 }
1019 }
1020
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301021 // update the frame data
1022 mCurrentFrame.fbZ = fbZ;
1023 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001024 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001025 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001026
1027 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301028 mCurrentFrame.fbCount);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001029
1030 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001031}
Saurabh Shah85234ec2013-04-12 17:09:00 -07001032
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001033void MDPComp::updateLayerCache(hwc_context_t* ctx,
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001034 hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001035 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001036 int fbCount = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001037
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001038 for(int i = 0; i < numAppLayers; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001039 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001040 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001041 if(!mCurrentFrame.drop[i])
1042 fbCount++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001043 mCurrentFrame.isFBComposed[i] = true;
1044 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -07001045 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001046 }
1047 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001048
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001049 mCurrentFrame.fbCount = fbCount;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001050 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount
1051 - mCurrentFrame.dropCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001052
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001053 ALOGD_IF(isDebug(),"%s: MDP count: %d FB count %d drop count: %d"
1054 ,__FUNCTION__, mCurrentFrame.mdpCount, mCurrentFrame.fbCount,
1055 mCurrentFrame.dropCount);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001056}
1057
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001058void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list,
1059 bool secureOnly) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001060 int nYuvCount = ctx->listStats[mDpy].yuvCount;
1061 for(int index = 0;index < nYuvCount; index++){
1062 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
1063 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
1064
1065 if(!isYUVDoable(ctx, layer)) {
1066 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
1067 mCurrentFrame.isFBComposed[nYuvIndex] = true;
1068 mCurrentFrame.fbCount++;
1069 }
1070 } else {
1071 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001072 private_handle_t *hnd = (private_handle_t *)layer->handle;
1073 if(!secureOnly || isSecureBuffer(hnd)) {
1074 mCurrentFrame.isFBComposed[nYuvIndex] = false;
1075 mCurrentFrame.fbCount--;
1076 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001077 }
1078 }
1079 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001080
1081 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001082 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
1083 ALOGD_IF(isDebug(),"%s: fb count: %d",__FUNCTION__,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001084 mCurrentFrame.fbCount);
1085}
1086
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001087bool MDPComp::postHeuristicsHandling(hwc_context_t *ctx,
1088 hwc_display_contents_1_t* list) {
1089
1090 //Capability checks
1091 if(!resourceCheck(ctx, list)) {
1092 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
1093 return false;
1094 }
1095
1096 //Limitations checks
1097 if(!hwLimitationsCheck(ctx, list)) {
1098 ALOGD_IF(isDebug(), "%s: HW limitations",__FUNCTION__);
1099 return false;
1100 }
1101
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001102 //Configure framebuffer first if applicable
1103 if(mCurrentFrame.fbZ >= 0) {
1104 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, mCurrentFrame.fbZ)) {
1105 ALOGD_IF(isDebug(), "%s configure framebuffer failed",
1106 __FUNCTION__);
1107 return false;
1108 }
1109 }
1110
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001111 mCurrentFrame.map();
1112
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001113 if(!allocLayerPipes(ctx, list)) {
1114 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -07001115 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001116 }
1117
1118 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001119 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001120 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001121 int mdpIndex = mCurrentFrame.layerToMDP[index];
1122 hwc_layer_1_t* layer = &list->hwLayers[index];
1123
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301124 //Leave fbZ for framebuffer. CACHE/GLES layers go here.
1125 if(mdpNextZOrder == mCurrentFrame.fbZ) {
1126 mdpNextZOrder++;
1127 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001128 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1129 cur_pipe->zOrder = mdpNextZOrder++;
1130
radhakrishnac9a67412013-09-25 17:40:42 +05301131 private_handle_t *hnd = (private_handle_t *)layer->handle;
1132 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1133 if(configure4k2kYuv(ctx, layer,
1134 mCurrentFrame.mdpToLayer[mdpIndex])
1135 != 0 ){
1136 ALOGD_IF(isDebug(), "%s: Failed to configure split pipes \
1137 for layer %d",__FUNCTION__, index);
1138 return false;
1139 }
1140 else{
1141 mdpNextZOrder++;
1142 }
1143 continue;
1144 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001145 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
1146 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
radhakrishnac9a67412013-09-25 17:40:42 +05301147 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -07001148 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001149 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001150 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001151 }
1152
Saurabh Shah450ac972013-12-16 18:18:39 -08001153 if(!ctx->mOverlay->validateAndSet(mDpy, ctx->dpyAttr[mDpy].fd)) {
1154 ALOGD_IF(isDebug(), "%s: Failed to validate and set overlay for dpy %d"
1155 ,__FUNCTION__, mDpy);
1156 return false;
1157 }
1158
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001159 setRedraw(ctx, list);
Saurabh Shahaa236822013-04-24 18:07:26 -07001160 return true;
1161}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001162
Saurabh Shah173f4242013-11-20 09:50:12 -08001163bool MDPComp::resourceCheck(hwc_context_t *ctx,
1164 hwc_display_contents_1_t *list) {
1165 const bool fbUsed = mCurrentFrame.fbCount;
1166 if(mCurrentFrame.mdpCount > sMaxPipesPerMixer - fbUsed) {
1167 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
1168 return false;
1169 }
Saurabh Shah173f4242013-11-20 09:50:12 -08001170 return true;
1171}
1172
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301173bool MDPComp::hwLimitationsCheck(hwc_context_t* ctx,
1174 hwc_display_contents_1_t* list) {
1175
1176 //A-family hw limitation:
1177 //If a layer need alpha scaling, MDP can not support.
1178 if(ctx->mMDP.version < qdutils::MDSS_V5) {
1179 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1180 if(!mCurrentFrame.isFBComposed[i] &&
1181 isAlphaScaled( &list->hwLayers[i])) {
1182 ALOGD_IF(isDebug(), "%s:frame needs alphaScaling",__FUNCTION__);
1183 return false;
1184 }
1185 }
1186 }
1187
1188 // On 8x26 & 8974 hw, we have a limitation of downscaling+blending.
1189 //If multiple layers requires downscaling and also they are overlapping
1190 //fall back to GPU since MDSS can not handle it.
1191 if(qdutils::MDPVersion::getInstance().is8x74v2() ||
1192 qdutils::MDPVersion::getInstance().is8x26()) {
1193 for(int i = 0; i < mCurrentFrame.layerCount-1; ++i) {
1194 hwc_layer_1_t* botLayer = &list->hwLayers[i];
1195 if(!mCurrentFrame.isFBComposed[i] &&
1196 isDownscaleRequired(botLayer)) {
1197 //if layer-i is marked for MDP and needs downscaling
1198 //check if any MDP layer on top of i & overlaps with layer-i
1199 for(int j = i+1; j < mCurrentFrame.layerCount; ++j) {
1200 hwc_layer_1_t* topLayer = &list->hwLayers[j];
1201 if(!mCurrentFrame.isFBComposed[j] &&
1202 isDownscaleRequired(topLayer)) {
1203 hwc_rect_t r = getIntersection(botLayer->displayFrame,
1204 topLayer->displayFrame);
1205 if(isValidRect(r))
1206 return false;
1207 }
1208 }
1209 }
1210 }
1211 }
1212 return true;
1213}
1214
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001215int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001216 int ret = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -07001217 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001218 MDPVersion& mdpVersion = qdutils::MDPVersion::getInstance();
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -07001219
Raj Kamalfc5b9222014-02-07 16:15:17 +05301220 //Do not cache the information for next draw cycle.
1221 if(numLayers > MAX_NUM_APP_LAYERS or (!numLayers)) {
1222 ALOGI("%s: Unsupported layer count for mdp composition",
1223 __FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001224 mCachedFrame.reset();
1225 return -1;
1226 }
1227
Saurabh Shahb39f8152013-08-22 10:21:44 -07001228 //reset old data
1229 mCurrentFrame.reset(numLayers);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001230 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1231 mCurrentFrame.dropCount = 0;
Prabhanjan Kandula088bd892013-07-02 23:47:13 +05301232
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -07001233 // Detect the start of animation and fall back to GPU only once to cache
1234 // all the layers in FB and display FB content untill animation completes.
1235 if(ctx->listStats[mDpy].isDisplayAnimating) {
1236 mCurrentFrame.needsRedraw = false;
1237 if(ctx->mAnimationState[mDpy] == ANIMATION_STOPPED) {
1238 mCurrentFrame.needsRedraw = true;
1239 ctx->mAnimationState[mDpy] = ANIMATION_STARTED;
1240 }
1241 setMDPCompLayerFlags(ctx, list);
1242 mCachedFrame.updateCounts(mCurrentFrame);
1243 ret = -1;
1244 return ret;
1245 } else {
1246 ctx->mAnimationState[mDpy] = ANIMATION_STOPPED;
1247 }
1248
Saurabh Shahb39f8152013-08-22 10:21:44 -07001249 //Hard conditions, if not met, cannot do MDP comp
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001250 if(isFrameDoable(ctx)) {
1251 generateROI(ctx, list);
Saurabh Shahb39f8152013-08-22 10:21:44 -07001252
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001253 if(tryFullFrame(ctx, list) || tryVideoOnly(ctx, list)) {
1254 setMDPCompLayerFlags(ctx, list);
1255 } else {
1256 reset(ctx);
1257 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1258 mCurrentFrame.dropCount = 0;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001259 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001260 }
1261 } else {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001262 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
1263 __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001264 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001265 }
Saurabh Shahb39f8152013-08-22 10:21:44 -07001266
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001267 if(isDebug()) {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001268 ALOGD("GEOMETRY change: %d",
1269 (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001270 android::String8 sDump("");
1271 dump(sDump);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001272 ALOGD("%s",sDump.string());
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001273 }
1274
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001275 mCachedFrame.cacheAll(list);
1276 mCachedFrame.updateCounts(mCurrentFrame);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001277 return ret;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001278}
1279
radhakrishnac9a67412013-09-25 17:40:42 +05301280bool MDPComp::allocSplitVGPipesfor4k2k(hwc_context_t *ctx,
1281 hwc_display_contents_1_t* list, int index) {
1282
1283 bool bRet = true;
1284 hwc_layer_1_t* layer = &list->hwLayers[index];
1285 private_handle_t *hnd = (private_handle_t *)layer->handle;
1286 int mdpIndex = mCurrentFrame.layerToMDP[index];
1287 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
1288 info.pipeInfo = new MdpYUVPipeInfo;
1289 info.rot = NULL;
1290 MdpYUVPipeInfo& pipe_info = *(MdpYUVPipeInfo*)info.pipeInfo;
1291 ePipeType type = MDPCOMP_OV_VG;
1292
1293 pipe_info.lIndex = ovutils::OV_INVALID;
1294 pipe_info.rIndex = ovutils::OV_INVALID;
1295
1296 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
1297 if(pipe_info.lIndex == ovutils::OV_INVALID){
1298 bRet = false;
1299 ALOGD_IF(isDebug(),"%s: allocating first VG pipe failed",
1300 __FUNCTION__);
1301 }
1302 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
1303 if(pipe_info.rIndex == ovutils::OV_INVALID){
1304 bRet = false;
1305 ALOGD_IF(isDebug(),"%s: allocating second VG pipe failed",
1306 __FUNCTION__);
1307 }
1308 return bRet;
1309}
Saurabh Shah88e4d272013-09-03 13:31:29 -07001310//=============MDPCompNonSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001311
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001312void MDPCompNonSplit::adjustForSourceSplit(hwc_context_t *ctx,
radhakrishnac9a67412013-09-25 17:40:42 +05301313 hwc_display_contents_1_t* list){
1314 //As we split 4kx2k yuv layer and program to 2 VG pipes
1315 //(if available) increase mdpcount accordingly
1316 mCurrentFrame.mdpCount += ctx->listStats[mDpy].yuv4k2kCount;
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001317
1318 //If 4k2k Yuv layer split is possible, and if
1319 //fbz is above 4k2k layer, increment fb zorder by 1
1320 //as we split 4k2k layer and increment zorder for right half
1321 //of the layer
1322 if(mCurrentFrame.fbZ >= 0) {
1323 int n4k2kYuvCount = ctx->listStats[mDpy].yuv4k2kCount;
1324 for(int index = 0; index < n4k2kYuvCount; index++){
1325 int n4k2kYuvIndex =
1326 ctx->listStats[mDpy].yuv4k2kIndices[index];
Dileep Kumar Reddi60aafff2014-04-01 12:57:08 +05301327 if(mCurrentFrame.fbZ >= n4k2kYuvIndex){
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001328 mCurrentFrame.fbZ += 1;
1329 }
1330 }
1331 }
radhakrishnac9a67412013-09-25 17:40:42 +05301332}
1333
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001334/*
1335 * Configures pipe(s) for MDP composition
1336 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001337int MDPCompNonSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001338 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001339 MdpPipeInfoNonSplit& mdp_info =
1340 *(static_cast<MdpPipeInfoNonSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001341 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
1342 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1343 eIsFg isFg = IS_FG_OFF;
1344 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001345
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001346 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
1347 __FUNCTION__, layer, zOrder, dest);
1348
Saurabh Shah88e4d272013-09-03 13:31:29 -07001349 return configureNonSplit(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001350 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001351}
1352
Saurabh Shah88e4d272013-09-03 13:31:29 -07001353bool MDPCompNonSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001354 hwc_display_contents_1_t* list) {
1355 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001356
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001357 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001358
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001359 hwc_layer_1_t* layer = &list->hwLayers[index];
1360 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301361 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1362 if(allocSplitVGPipesfor4k2k(ctx, list, index)){
1363 continue;
1364 }
1365 }
1366
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001367 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001368 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001369 info.pipeInfo = new MdpPipeInfoNonSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08001370 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001371 MdpPipeInfoNonSplit& pipe_info = *(MdpPipeInfoNonSplit*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001372 ePipeType type = MDPCOMP_OV_ANY;
1373
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001374 if(isYuvBuffer(hnd)) {
1375 type = MDPCOMP_OV_VG;
Prabhanjan Kandula5b8913e2014-01-22 23:01:45 +05301376 } else if(qdutils::MDPVersion::getInstance().is8x26() &&
1377 (ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres > 1024)) {
1378 if(qhwc::needsScaling(layer))
1379 type = MDPCOMP_OV_RGB;
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301380 } else if(!qhwc::needsScaling(layer)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001381 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
1382 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001383 type = MDPCOMP_OV_DMA;
1384 }
1385
Xu Yang5c2b3af2014-04-08 13:56:47 +08001386 // for 8x26, never allow primary display occupy DMA pipe
1387 // when external display is connected
1388 if(qdutils::MDPVersion::getInstance().is8x26()
1389 && ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isActive
1390 && ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected
1391 && !ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isPause
1392 && mDpy == HWC_DISPLAY_PRIMARY
1393 && type == MDPCOMP_OV_DMA) {
1394 type = MDPCOMP_OV_RGB;
1395 }
1396
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001397 pipe_info.index = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001398 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001399 ALOGD_IF(isDebug(), "%s: Unable to get pipe type = %d",
1400 __FUNCTION__, (int) type);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001401 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001402 }
1403 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001404 return true;
1405}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001406
radhakrishnac9a67412013-09-25 17:40:42 +05301407int MDPCompNonSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1408 PipeLayerPair& PipeLayerPair) {
1409 MdpYUVPipeInfo& mdp_info =
1410 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1411 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1412 eIsFg isFg = IS_FG_OFF;
1413 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1414 eDest lDest = mdp_info.lIndex;
1415 eDest rDest = mdp_info.rIndex;
1416
1417 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1418 lDest, rDest, &PipeLayerPair.rot);
1419}
1420
Saurabh Shah88e4d272013-09-03 13:31:29 -07001421bool MDPCompNonSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001422
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001423 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001424 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1425 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -08001426 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001427
1428 if(!ctx || !list) {
1429 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001430 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001431 }
1432
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301433 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1434 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1435 return true;
1436 }
1437
Ramkumar Radhakrishnand8595ae2014-02-06 21:31:29 -08001438 // Set the Handle timeout to true for MDP or MIXED composition.
1439 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount) {
1440 sHandleTimeout = true;
1441 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001442
1443 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001444 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001445
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001446 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1447 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001448 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001449 if(mCurrentFrame.isFBComposed[i]) continue;
1450
Naseer Ahmed5b6708a2012-08-02 13:46:08 -07001451 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001452 private_handle_t *hnd = (private_handle_t *)layer->handle;
1453 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001454 if (!(layer->flags & HWC_COLOR_FILL)) {
1455 ALOGE("%s handle null", __FUNCTION__);
1456 return false;
1457 }
1458 // No PLAY for Color layer
1459 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1460 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001461 }
1462
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001463 int mdpIndex = mCurrentFrame.layerToMDP[i];
1464
radhakrishnac9a67412013-09-25 17:40:42 +05301465 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1466 {
1467 MdpYUVPipeInfo& pipe_info =
1468 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1469 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1470 ovutils::eDest indexL = pipe_info.lIndex;
1471 ovutils::eDest indexR = pipe_info.rIndex;
1472 int fd = hnd->fd;
1473 uint32_t offset = hnd->offset;
1474 if(rot) {
1475 rot->queueBuffer(fd, offset);
1476 fd = rot->getDstMemId();
1477 offset = rot->getDstOffset();
1478 }
1479 if(indexL != ovutils::OV_INVALID) {
1480 ovutils::eDest destL = (ovutils::eDest)indexL;
1481 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1482 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1483 if (!ov.queueBuffer(fd, offset, destL)) {
1484 ALOGE("%s: queueBuffer failed for display:%d",
1485 __FUNCTION__, mDpy);
1486 return false;
1487 }
1488 }
1489
1490 if(indexR != ovutils::OV_INVALID) {
1491 ovutils::eDest destR = (ovutils::eDest)indexR;
1492 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1493 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1494 if (!ov.queueBuffer(fd, offset, destR)) {
1495 ALOGE("%s: queueBuffer failed for display:%d",
1496 __FUNCTION__, mDpy);
1497 return false;
1498 }
1499 }
1500 }
1501 else{
1502 MdpPipeInfoNonSplit& pipe_info =
Saurabh Shah88e4d272013-09-03 13:31:29 -07001503 *(MdpPipeInfoNonSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
radhakrishnac9a67412013-09-25 17:40:42 +05301504 ovutils::eDest dest = pipe_info.index;
1505 if(dest == ovutils::OV_INVALID) {
1506 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001507 return false;
radhakrishnac9a67412013-09-25 17:40:42 +05301508 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001509
radhakrishnac9a67412013-09-25 17:40:42 +05301510 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1511 continue;
1512 }
1513
1514 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1515 using pipe: %d", __FUNCTION__, layer,
1516 hnd, dest );
1517
1518 int fd = hnd->fd;
1519 uint32_t offset = hnd->offset;
1520
1521 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1522 if(rot) {
1523 if(!rot->queueBuffer(fd, offset))
1524 return false;
1525 fd = rot->getDstMemId();
1526 offset = rot->getDstOffset();
1527 }
1528
1529 if (!ov.queueBuffer(fd, offset, dest)) {
1530 ALOGE("%s: queueBuffer failed for display:%d ",
1531 __FUNCTION__, mDpy);
1532 return false;
1533 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001534 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001535
1536 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001537 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001538 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001539}
1540
Saurabh Shah88e4d272013-09-03 13:31:29 -07001541//=============MDPCompSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001542
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001543void MDPCompSplit::adjustForSourceSplit(hwc_context_t *ctx,
radhakrishnac9a67412013-09-25 17:40:42 +05301544 hwc_display_contents_1_t* list){
1545 //if 4kx2k yuv layer is totally present in either in left half
1546 //or right half then try splitting the yuv layer to avoid decimation
1547 int n4k2kYuvCount = ctx->listStats[mDpy].yuv4k2kCount;
1548 const int lSplit = getLeftSplit(ctx, mDpy);
1549 for(int index = 0; index < n4k2kYuvCount; index++){
1550 int n4k2kYuvIndex = ctx->listStats[mDpy].yuv4k2kIndices[index];
1551 hwc_layer_1_t* layer = &list->hwLayers[n4k2kYuvIndex];
1552 hwc_rect_t dst = layer->displayFrame;
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001553 if((dst.left > lSplit) || (dst.right < lSplit)) {
radhakrishnac9a67412013-09-25 17:40:42 +05301554 mCurrentFrame.mdpCount += 1;
1555 }
Dileep Kumar Reddi60aafff2014-04-01 12:57:08 +05301556 if(mCurrentFrame.fbZ >= n4k2kYuvIndex){
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001557 mCurrentFrame.fbZ += 1;
1558 }
radhakrishnac9a67412013-09-25 17:40:42 +05301559 }
1560}
1561
Saurabh Shah88e4d272013-09-03 13:31:29 -07001562bool MDPCompSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
1563 MdpPipeInfoSplit& pipe_info,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001564 ePipeType type) {
1565 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001566 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001567
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001568 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001569 pipe_info.lIndex = ovutils::OV_INVALID;
1570 pipe_info.rIndex = ovutils::OV_INVALID;
1571
1572 if (dst.left < lSplit) {
1573 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_LEFT);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001574 if(pipe_info.lIndex == ovutils::OV_INVALID)
1575 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001576 }
1577
1578 if(dst.right > lSplit) {
1579 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_RIGHT);
1580 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001581 return false;
1582 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001583
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001584 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001585}
1586
Saurabh Shah88e4d272013-09-03 13:31:29 -07001587bool MDPCompSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001588 hwc_display_contents_1_t* list) {
1589 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001590
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001591 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001592
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001593 hwc_layer_1_t* layer = &list->hwLayers[index];
1594 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301595 hwc_rect_t dst = layer->displayFrame;
1596 const int lSplit = getLeftSplit(ctx, mDpy);
1597 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1598 if((dst.left > lSplit)||(dst.right < lSplit)){
1599 if(allocSplitVGPipesfor4k2k(ctx, list, index)){
1600 continue;
1601 }
1602 }
1603 }
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001604 int mdpIndex = mCurrentFrame.layerToMDP[index];
1605 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001606 info.pipeInfo = new MdpPipeInfoSplit;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001607 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001608 MdpPipeInfoSplit& pipe_info = *(MdpPipeInfoSplit*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001609 ePipeType type = MDPCOMP_OV_ANY;
1610
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001611 if(isYuvBuffer(hnd)) {
1612 type = MDPCOMP_OV_VG;
Sushil Chauhan15a2ea62013-09-04 18:28:36 -07001613 } else if(!qhwc::needsScalingWithSplit(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001614 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001615 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001616 type = MDPCOMP_OV_DMA;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001617 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001618
1619 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001620 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type = %d",
1621 __FUNCTION__, (int) type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001622 return false;
1623 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001624 }
1625 return true;
1626}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001627
radhakrishnac9a67412013-09-25 17:40:42 +05301628int MDPCompSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1629 PipeLayerPair& PipeLayerPair) {
1630 const int lSplit = getLeftSplit(ctx, mDpy);
1631 hwc_rect_t dst = layer->displayFrame;
1632 if((dst.left > lSplit)||(dst.right < lSplit)){
1633 MdpYUVPipeInfo& mdp_info =
1634 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1635 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1636 eIsFg isFg = IS_FG_OFF;
1637 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1638 eDest lDest = mdp_info.lIndex;
1639 eDest rDest = mdp_info.rIndex;
1640
1641 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1642 lDest, rDest, &PipeLayerPair.rot);
1643 }
1644 else{
1645 return configure(ctx, layer, PipeLayerPair);
1646 }
1647}
1648
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001649/*
1650 * Configures pipe(s) for MDP composition
1651 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001652int MDPCompSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001653 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001654 MdpPipeInfoSplit& mdp_info =
1655 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001656 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1657 eIsFg isFg = IS_FG_OFF;
1658 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1659 eDest lDest = mdp_info.lIndex;
1660 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001661
1662 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1663 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1664
Saurabh Shah88e4d272013-09-03 13:31:29 -07001665 return configureSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001666 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001667}
1668
Saurabh Shah88e4d272013-09-03 13:31:29 -07001669bool MDPCompSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001670
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001671 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001672 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1673 return true;
1674 }
1675
1676 if(!ctx || !list) {
1677 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001678 return false;
1679 }
1680
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301681 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1682 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1683 return true;
1684 }
1685
Ramkumar Radhakrishnand8595ae2014-02-06 21:31:29 -08001686 // Set the Handle timeout to true for MDP or MIXED composition.
1687 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount) {
1688 sHandleTimeout = true;
1689 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001690
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001691 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001692 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001693
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001694 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1695 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001696 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001697 if(mCurrentFrame.isFBComposed[i]) continue;
1698
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001699 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001700 private_handle_t *hnd = (private_handle_t *)layer->handle;
1701 if(!hnd) {
1702 ALOGE("%s handle null", __FUNCTION__);
1703 return false;
1704 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001705
1706 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1707 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001708 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001709
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001710 int mdpIndex = mCurrentFrame.layerToMDP[i];
1711
radhakrishnac9a67412013-09-25 17:40:42 +05301712 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1713 {
1714 MdpYUVPipeInfo& pipe_info =
1715 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1716 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1717 ovutils::eDest indexL = pipe_info.lIndex;
1718 ovutils::eDest indexR = pipe_info.rIndex;
1719 int fd = hnd->fd;
1720 uint32_t offset = hnd->offset;
1721 if(rot) {
1722 rot->queueBuffer(fd, offset);
1723 fd = rot->getDstMemId();
1724 offset = rot->getDstOffset();
1725 }
1726 if(indexL != ovutils::OV_INVALID) {
1727 ovutils::eDest destL = (ovutils::eDest)indexL;
1728 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1729 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1730 if (!ov.queueBuffer(fd, offset, destL)) {
1731 ALOGE("%s: queueBuffer failed for display:%d",
1732 __FUNCTION__, mDpy);
1733 return false;
1734 }
1735 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001736
radhakrishnac9a67412013-09-25 17:40:42 +05301737 if(indexR != ovutils::OV_INVALID) {
1738 ovutils::eDest destR = (ovutils::eDest)indexR;
1739 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1740 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1741 if (!ov.queueBuffer(fd, offset, destR)) {
1742 ALOGE("%s: queueBuffer failed for display:%d",
1743 __FUNCTION__, mDpy);
1744 return false;
1745 }
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001746 }
1747 }
radhakrishnac9a67412013-09-25 17:40:42 +05301748 else{
1749 MdpPipeInfoSplit& pipe_info =
1750 *(MdpPipeInfoSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1751 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001752
radhakrishnac9a67412013-09-25 17:40:42 +05301753 ovutils::eDest indexL = pipe_info.lIndex;
1754 ovutils::eDest indexR = pipe_info.rIndex;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001755
radhakrishnac9a67412013-09-25 17:40:42 +05301756 int fd = hnd->fd;
1757 int offset = hnd->offset;
1758
1759 if(ctx->mAD->isModeOn()) {
1760 if(ctx->mAD->draw(ctx, fd, offset)) {
1761 fd = ctx->mAD->getDstFd(ctx);
1762 offset = ctx->mAD->getDstOffset(ctx);
1763 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001764 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001765
radhakrishnac9a67412013-09-25 17:40:42 +05301766 if(rot) {
1767 rot->queueBuffer(fd, offset);
1768 fd = rot->getDstMemId();
1769 offset = rot->getDstOffset();
1770 }
1771
1772 //************* play left mixer **********
1773 if(indexL != ovutils::OV_INVALID) {
1774 ovutils::eDest destL = (ovutils::eDest)indexL;
1775 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1776 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1777 if (!ov.queueBuffer(fd, offset, destL)) {
1778 ALOGE("%s: queueBuffer failed for left mixer",
1779 __FUNCTION__);
1780 return false;
1781 }
1782 }
1783
1784 //************* play right mixer **********
1785 if(indexR != ovutils::OV_INVALID) {
1786 ovutils::eDest destR = (ovutils::eDest)indexR;
1787 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1788 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1789 if (!ov.queueBuffer(fd, offset, destR)) {
1790 ALOGE("%s: queueBuffer failed for right mixer",
1791 __FUNCTION__);
1792 return false;
1793 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001794 }
1795 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001796
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001797 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1798 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001799
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001800 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001801}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001802}; //namespace
1803