blob: be3fbbc7c8bcdb1ad6004f49d9676a4485b8373d [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() &&
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700407 ctx->mVideoTransFlag && ctx->mVirtualDisplay->isConnected()) {
Saurabh Shahd4e65852013-06-17 11:33:53 -0700408 //1 Padding round to shift pipes across mixers
409 ALOGD_IF(isDebug(),"%s: MDP Comp. video transition padding round",
410 __FUNCTION__);
411 ret = false;
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700412 } else if(ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isConfiguring ||
413 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isConfiguring) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800414 ALOGD_IF( isDebug(),"%s: External Display connection is pending",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800415 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700416 ret = false;
Saurabh Shahaa236822013-04-24 18:07:26 -0700417 } else if(ctx->isPaddingRound) {
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700418 ctx->isPaddingRound = false;
419 ALOGD_IF(isDebug(), "%s: padding round",__FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700420 ret = false;
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700421 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700422 return ret;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800423}
424
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800425/*
426 * 1) Identify layers that are not visible in the updating ROI and drop them
427 * from composition.
428 * 2) If we have a scaling layers which needs cropping against generated ROI.
429 * Reset ROI to full resolution.
430 */
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700431bool MDPComp::validateAndApplyROI(hwc_context_t *ctx,
432 hwc_display_contents_1_t* list, hwc_rect_t roi) {
433 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
434
435 if(!isValidRect(roi))
436 return false;
437
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800438 hwc_rect_t visibleRect = roi;
439
440 for(int i = numAppLayers - 1; i >= 0; i--){
441
442 if(!isValidRect(visibleRect)) {
443 mCurrentFrame.drop[i] = true;
444 mCurrentFrame.dropCount++;
Jeykumar Sankaran65bc8022014-01-21 17:26:12 -0800445 continue;
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800446 }
447
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700448 const hwc_layer_1_t* layer = &list->hwLayers[i];
449
450 hwc_rect_t dstRect = layer->displayFrame;
Arun Kumar K.R91090c72013-10-28 19:40:18 -0700451 hwc_rect_t srcRect = integerizeSourceCrop(layer->sourceCropf);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700452 int transform = layer->transform;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700453
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800454 hwc_rect_t res = getIntersection(visibleRect, dstRect);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700455
456 int res_w = res.right - res.left;
457 int res_h = res.bottom - res.top;
458 int dst_w = dstRect.right - dstRect.left;
459 int dst_h = dstRect.bottom - dstRect.top;
460
461 if(!isValidRect(res)) {
462 mCurrentFrame.drop[i] = true;
463 mCurrentFrame.dropCount++;
464 }else {
465 /* Reset frame ROI when any layer which needs scaling also needs ROI
466 * cropping */
Jeykumar Sankaran65bc8022014-01-21 17:26:12 -0800467 if((res_w != dst_w || res_h != dst_h) && needsScaling (layer)) {
Arpita Banerjeed8965982013-11-08 17:27:33 -0800468 ALOGI("%s: Resetting ROI due to scaling", __FUNCTION__);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700469 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
470 mCurrentFrame.dropCount = 0;
471 return false;
472 }
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800473
Jeykumar Sankaran65bc8022014-01-21 17:26:12 -0800474 /* deduct any opaque region from visibleRect */
475 if (layer->blending == HWC_BLENDING_NONE)
476 visibleRect = deductRect(visibleRect, res);
477 }
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700478 }
479 return true;
480}
481
482void MDPComp::generateROI(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
483 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
484
485 if(!sEnablePartialFrameUpdate) {
486 return;
487 }
488
489 if(mDpy || isDisplaySplit(ctx, mDpy)){
490 ALOGE_IF(isDebug(), "%s: ROI not supported for"
491 "the (1) external / virtual display's (2) dual DSI displays",
492 __FUNCTION__);
493 return;
494 }
495
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800496 if(isSkipPresent(ctx, mDpy))
497 return;
498
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700499 if(list->flags & HWC_GEOMETRY_CHANGED)
500 return;
501
502 struct hwc_rect roi = (struct hwc_rect){0, 0, 0, 0};
503 for(int index = 0; index < numAppLayers; index++ ) {
504 if ((mCachedFrame.hnd[index] != list->hwLayers[index].handle) ||
505 isYuvBuffer((private_handle_t *)list->hwLayers[index].handle)) {
506 hwc_rect_t dstRect = list->hwLayers[index].displayFrame;
Arun Kumar K.R91090c72013-10-28 19:40:18 -0700507 hwc_rect_t srcRect = integerizeSourceCrop(
508 list->hwLayers[index].sourceCropf);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700509 int transform = list->hwLayers[index].transform;
510
511 /* Intersect against display boundaries */
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700512 roi = getUnion(roi, dstRect);
513 }
514 }
515
516 if(!validateAndApplyROI(ctx, list, roi)){
517 roi = (struct hwc_rect) {0, 0,
518 (int)ctx->dpyAttr[mDpy].xres, (int)ctx->dpyAttr[mDpy].yres};
519 }
520
521 ctx->listStats[mDpy].roi.x = roi.left;
522 ctx->listStats[mDpy].roi.y = roi.top;
523 ctx->listStats[mDpy].roi.w = roi.right - roi.left;
524 ctx->listStats[mDpy].roi.h = roi.bottom - roi.top;
525
526 ALOGD_IF(isDebug(),"%s: generated ROI: [%d, %d, %d, %d]", __FUNCTION__,
527 roi.left, roi.top, roi.right, roi.bottom);
528}
529
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800530/* Checks for conditions where all the layers marked for MDP comp cannot be
531 * bypassed. On such conditions we try to bypass atleast YUV layers */
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800532bool MDPComp::tryFullFrame(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800533 hwc_display_contents_1_t* list){
534
Saurabh Shahaa236822013-04-24 18:07:26 -0700535 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800536
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -0700537 if(sIdleFallBack && !ctx->listStats[mDpy].secureUI) {
Saurabh Shah2d998a92013-05-14 17:55:58 -0700538 ALOGD_IF(isDebug(), "%s: Idle fallback dpy %d",__FUNCTION__, mDpy);
539 return false;
540 }
541
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800542 if(isSkipPresent(ctx, mDpy)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700543 ALOGD_IF(isDebug(),"%s: SKIP present: %d",
544 __FUNCTION__,
545 isSkipPresent(ctx, mDpy));
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800546 return false;
547 }
548
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800549 // check for action safe flag and downscale mode which requires scaling.
550 if(ctx->dpyAttr[mDpy].mActionSafePresent
551 || ctx->dpyAttr[mDpy].mDownScaleMode) {
552 ALOGD_IF(isDebug(), "%s: Scaling needed for this frame",__FUNCTION__);
553 return false;
554 }
555
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800556 for(int i = 0; i < numAppLayers; ++i) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800557 hwc_layer_1_t* layer = &list->hwLayers[i];
558 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800559
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700560 if(isYuvBuffer(hnd) && has90Transform(layer)) {
561 if(!canUseRotator(ctx, mDpy)) {
562 ALOGD_IF(isDebug(), "%s: Can't use rotator for dpy %d",
563 __FUNCTION__, mDpy);
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700564 return false;
565 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800566 }
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530567
568 //For 8x26 with panel width>1k, if RGB layer needs HFLIP fail mdp comp
569 // may not need it if Gfx pre-rotation can handle all flips & rotations
570 if(qdutils::MDPVersion::getInstance().is8x26() &&
571 (ctx->dpyAttr[mDpy].xres > 1024) &&
572 (layer->transform & HWC_TRANSFORM_FLIP_H) &&
573 (!isYuvBuffer(hnd)))
574 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800575 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700576
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700577 if(ctx->mAD->isDoable()) {
578 return false;
579 }
580
Saurabh Shahaa236822013-04-24 18:07:26 -0700581 //If all above hard conditions are met we can do full or partial MDP comp.
582 bool ret = false;
583 if(fullMDPComp(ctx, list)) {
584 ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700585 } else if(partialMDPComp(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700586 ret = true;
587 }
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530588
Saurabh Shahaa236822013-04-24 18:07:26 -0700589 return ret;
590}
591
592bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700593 //Will benefit presentation / secondary-only layer.
594 if((mDpy > HWC_DISPLAY_PRIMARY) &&
595 (list->numHwLayers - 1) > MAX_SEC_LAYERS) {
596 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
597 return false;
598 }
599
600 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
601 for(int i = 0; i < numAppLayers; i++) {
602 hwc_layer_1_t* layer = &list->hwLayers[i];
603 if(not isSupportedForMDPComp(ctx, layer)) {
604 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",__FUNCTION__);
605 return false;
606 }
Yang Xu9c1eb2b2013-11-26 01:28:13 +0800607
608 //For 8x26, if there is only one layer which needs scale for secondary
609 //while no scale for primary display, DMA pipe is occupied by primary.
610 //If need to fall back to GLES composition, virtual display lacks DMA
611 //pipe and error is reported.
612 if(qdutils::MDPVersion::getInstance().is8x26() &&
613 mDpy >= HWC_DISPLAY_EXTERNAL &&
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530614 qhwc::needsScaling(layer))
Yang Xu9c1eb2b2013-11-26 01:28:13 +0800615 return false;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700616 }
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800617
Saurabh Shahaa236822013-04-24 18:07:26 -0700618 mCurrentFrame.fbCount = 0;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700619 memcpy(&mCurrentFrame.isFBComposed, &mCurrentFrame.drop,
620 sizeof(mCurrentFrame.isFBComposed));
621 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount -
622 mCurrentFrame.dropCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700623
radhakrishnac9a67412013-09-25 17:40:42 +0530624 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800625 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530626 }
627
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800628 if(!postHeuristicsHandling(ctx, list)) {
629 ALOGD_IF(isDebug(), "post heuristic handling failed");
630 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700631 return false;
632 }
633
Saurabh Shahaa236822013-04-24 18:07:26 -0700634 return true;
635}
636
637bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
638{
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700639 if(!sEnableMixedMode) {
640 //Mixed mode is disabled. No need to even try caching.
641 return false;
642 }
643
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700644 bool ret = false;
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800645 if(list->flags & HWC_GEOMETRY_CHANGED) { //Try load based first
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800646 ret = loadBasedComp(ctx, list) or
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800647 cacheBasedComp(ctx, list);
648 } else {
649 ret = cacheBasedComp(ctx, list) or
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800650 loadBasedComp(ctx, list);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700651 }
652
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700653 return ret;
654}
655
656bool MDPComp::cacheBasedComp(hwc_context_t *ctx,
657 hwc_display_contents_1_t* list) {
658 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700659 mCurrentFrame.reset(numAppLayers);
660 updateLayerCache(ctx, list);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700661
662 //If an MDP marked layer is unsupported cannot do partial MDP Comp
663 for(int i = 0; i < numAppLayers; i++) {
664 if(!mCurrentFrame.isFBComposed[i]) {
665 hwc_layer_1_t* layer = &list->hwLayers[i];
666 if(not isSupportedForMDPComp(ctx, layer)) {
667 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",
668 __FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800669 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700670 return false;
671 }
672 }
673 }
674
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700675 updateYUV(ctx, list, false /*secure only*/);
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530676 bool ret = markLayersForCaching(ctx, list); //sets up fbZ also
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700677 if(!ret) {
678 ALOGD_IF(isDebug(),"%s: batching failed, dpy %d",__FUNCTION__, mDpy);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800679 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700680 return false;
681 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700682
683 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700684
radhakrishnac9a67412013-09-25 17:40:42 +0530685 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800686 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530687 }
688
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700689 //Will benefit cases where a video has non-updating background.
690 if((mDpy > HWC_DISPLAY_PRIMARY) and
691 (mdpCount > MAX_SEC_LAYERS)) {
692 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800693 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700694 return false;
695 }
696
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800697 if(!postHeuristicsHandling(ctx, list)) {
698 ALOGD_IF(isDebug(), "post heuristic handling failed");
699 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700700 return false;
701 }
702
Saurabh Shahaa236822013-04-24 18:07:26 -0700703 return true;
704}
705
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800706bool MDPComp::loadBasedComp(hwc_context_t *ctx,
Saurabh Shahb772ae32013-11-18 15:40:02 -0800707 hwc_display_contents_1_t* list) {
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800708 if(not isLoadBasedCompDoable(ctx, list)) {
709 return false;
710 }
711
Saurabh Shahb772ae32013-11-18 15:40:02 -0800712 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800713 const int numNonDroppedLayers = numAppLayers - mCurrentFrame.dropCount;
714 const int stagesForMDP = min(sMaxPipesPerMixer,
715 ctx->mOverlay->availablePipes(mDpy, Overlay::MIXER_DEFAULT));
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800716
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800717 int mdpBatchSize = stagesForMDP - 1; //1 stage for FB
718 int fbBatchSize = numNonDroppedLayers - mdpBatchSize;
719 int lastMDPSupportedIndex = numAppLayers;
720 int dropCount = 0;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800721
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800722 //Find the minimum MDP batch size
723 for(int i = 0; i < numAppLayers;i++) {
724 if(mCurrentFrame.drop[i]) {
725 dropCount++;
Jeykumar Sankaran6279bc32014-01-23 21:59:58 -0800726 continue;
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800727 }
728 hwc_layer_1_t* layer = &list->hwLayers[i];
729 if(not isSupportedForMDPComp(ctx, layer)) {
730 lastMDPSupportedIndex = i;
731 mdpBatchSize = min(i - dropCount, stagesForMDP - 1);
732 fbBatchSize = numNonDroppedLayers - mdpBatchSize;
Jeykumar Sankaran6279bc32014-01-23 21:59:58 -0800733 break;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800734 }
Saurabh Shahb772ae32013-11-18 15:40:02 -0800735 }
736
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800737 ALOGD_IF(isDebug(), "%s:Before optimizing fbBatch, mdpbatch %d, fbbatch %d "
738 "dropped %d", __FUNCTION__, mdpBatchSize, fbBatchSize,
739 mCurrentFrame.dropCount);
740
741 //Start at a point where the fb batch should at least have 2 layers, for
742 //this mode to be justified.
743 while(fbBatchSize < 2) {
744 ++fbBatchSize;
745 --mdpBatchSize;
Jeykumar Sankaran6279bc32014-01-23 21:59:58 -0800746 }
Saurabh Shahb772ae32013-11-18 15:40:02 -0800747
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800748 //If there are no layers for MDP, this mode doesnt make sense.
749 if(mdpBatchSize < 1) {
750 ALOGD_IF(isDebug(), "%s: No MDP layers after optimizing for fbBatch",
751 __FUNCTION__);
Saurabh Shahb772ae32013-11-18 15:40:02 -0800752 return false;
753 }
754
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800755 mCurrentFrame.reset(numAppLayers);
756
757 //Try with successively smaller mdp batch sizes until we succeed or reach 1
758 while(mdpBatchSize > 0) {
759 //Mark layers for MDP comp
760 int mdpBatchLeft = mdpBatchSize;
761 for(int i = 0; i < lastMDPSupportedIndex and mdpBatchLeft; i++) {
762 if(mCurrentFrame.drop[i]) {
763 continue;
764 }
765 mCurrentFrame.isFBComposed[i] = false;
766 --mdpBatchLeft;
767 }
768
769 mCurrentFrame.fbZ = mdpBatchSize;
770 mCurrentFrame.fbCount = fbBatchSize;
771 mCurrentFrame.mdpCount = mdpBatchSize;
772
773 ALOGD_IF(isDebug(), "%s:Trying with: mdpbatch %d fbbatch %d dropped %d",
774 __FUNCTION__, mdpBatchSize, fbBatchSize,
775 mCurrentFrame.dropCount);
776
777 if(postHeuristicsHandling(ctx, list)) {
778 ALOGD_IF(isDebug(), "%s: Postheuristics handling succeeded",
779 __FUNCTION__);
780 return true;
781 }
782
783 reset(ctx);
784 --mdpBatchSize;
785 ++fbBatchSize;
786 }
787
788 return false;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800789}
790
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700791bool MDPComp::isLoadBasedCompDoable(hwc_context_t *ctx,
792 hwc_display_contents_1_t* list) {
Prabhanjan Kandula3dbbd882013-12-11 14:43:46 +0530793 if(mDpy or isSecurePresent(ctx, mDpy) or
794 isYuvPresent(ctx, mDpy)) {
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700795 return false;
796 }
797 return true;
798}
799
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800800bool MDPComp::tryVideoOnly(hwc_context_t *ctx,
801 hwc_display_contents_1_t* list) {
802 const bool secureOnly = true;
803 return videoOnlyComp(ctx, list, not secureOnly) or
804 videoOnlyComp(ctx, list, secureOnly);
805}
806
807bool MDPComp::videoOnlyComp(hwc_context_t *ctx,
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700808 hwc_display_contents_1_t* list, bool secureOnly) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700809 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700810
Saurabh Shahaa236822013-04-24 18:07:26 -0700811 mCurrentFrame.reset(numAppLayers);
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700812 updateYUV(ctx, list, secureOnly);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700813 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700814
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800815 if(!isYuvPresent(ctx, mDpy) or (mdpCount == 0)) {
816 reset(ctx);
Saurabh Shahaa236822013-04-24 18:07:26 -0700817 return false;
818 }
819
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -0800820 /* Bail out if we are processing only secured video layers
821 * and we dont have any */
822 if(!isSecurePresent(ctx, mDpy) && secureOnly){
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800823 reset(ctx);
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -0800824 return false;
825 }
826
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800827 if(mCurrentFrame.fbCount)
828 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
Saurabh Shah4fdde762013-04-30 18:47:33 -0700829
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800830 if(sEnable4k2kYUVSplit){
831 adjustForSourceSplit(ctx, list);
832 }
833
834 if(!postHeuristicsHandling(ctx, list)) {
835 ALOGD_IF(isDebug(), "post heuristic handling failed");
836 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700837 return false;
838 }
839
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800840 return true;
841}
842
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800843/* Checks for conditions where YUV layers cannot be bypassed */
844bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -0700845 if(isSkipLayer(layer)) {
Saurabh Shahe2474082013-05-15 16:32:13 -0700846 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800847 return false;
848 }
849
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700850 if(layer->transform & HWC_TRANSFORM_ROT_90 && !canUseRotator(ctx,mDpy)) {
851 ALOGD_IF(isDebug(), "%s: no free DMA pipe",__FUNCTION__);
852 return false;
853 }
854
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800855 if(isSecuring(ctx, layer)) {
856 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
857 return false;
858 }
859
Saurabh Shah4fdde762013-04-30 18:47:33 -0700860 if(!isValidDimension(ctx, layer)) {
861 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
862 __FUNCTION__);
863 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800864 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700865
Naseer Ahmeddc61a972013-07-10 17:50:54 -0400866 if(layer->planeAlpha < 0xFF) {
867 ALOGD_IF(isDebug(), "%s: Cannot handle YUV layer with plane alpha\
868 in video only mode",
869 __FUNCTION__);
870 return false;
871 }
872
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800873 return true;
874}
875
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530876/* starts at fromIndex and check for each layer to find
877 * if it it has overlapping with any Updating layer above it in zorder
878 * till the end of the batch. returns true if it finds any intersection */
879bool MDPComp::canPushBatchToTop(const hwc_display_contents_1_t* list,
880 int fromIndex, int toIndex) {
881 for(int i = fromIndex; i < toIndex; i++) {
882 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
883 if(intersectingUpdatingLayers(list, i+1, toIndex, i)) {
884 return false;
885 }
886 }
887 }
888 return true;
889}
890
891/* Checks if given layer at targetLayerIndex has any
892 * intersection with all the updating layers in beween
893 * fromIndex and toIndex. Returns true if it finds intersectiion */
894bool MDPComp::intersectingUpdatingLayers(const hwc_display_contents_1_t* list,
895 int fromIndex, int toIndex, int targetLayerIndex) {
896 for(int i = fromIndex; i <= toIndex; i++) {
897 if(!mCurrentFrame.isFBComposed[i]) {
898 if(areLayersIntersecting(&list->hwLayers[i],
899 &list->hwLayers[targetLayerIndex])) {
900 return true;
901 }
902 }
903 }
904 return false;
905}
906
907int MDPComp::getBatch(hwc_display_contents_1_t* list,
908 int& maxBatchStart, int& maxBatchEnd,
909 int& maxBatchCount) {
910 int i = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530911 int fbZOrder =-1;
Jeykumar Sankaran5a495da2014-01-20 12:25:32 -0800912 int droppedLayerCt = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530913 while (i < mCurrentFrame.layerCount) {
914 int batchCount = 0;
915 int batchStart = i;
916 int batchEnd = i;
Jeykumar Sankaran5a495da2014-01-20 12:25:32 -0800917 /* Adjust batch Z order with the dropped layers so far */
918 int fbZ = batchStart - droppedLayerCt;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530919 int firstZReverseIndex = -1;
Prabhanjan Kandula0ed2cc92013-12-06 12:39:04 +0530920 int updatingLayersAbove = 0;//Updating layer count in middle of batch
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530921 while(i < mCurrentFrame.layerCount) {
922 if(!mCurrentFrame.isFBComposed[i]) {
923 if(!batchCount) {
924 i++;
925 break;
926 }
927 updatingLayersAbove++;
928 i++;
929 continue;
930 } else {
931 if(mCurrentFrame.drop[i]) {
932 i++;
Jeykumar Sankaran5a495da2014-01-20 12:25:32 -0800933 droppedLayerCt++;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530934 continue;
935 } else if(updatingLayersAbove <= 0) {
936 batchCount++;
937 batchEnd = i;
938 i++;
939 continue;
940 } else { //Layer is FBComposed, not a drop & updatingLayer > 0
941
942 // We have a valid updating layer already. If layer-i not
943 // have overlapping with all updating layers in between
944 // batch-start and i, then we can add layer i to batch.
945 if(!intersectingUpdatingLayers(list, batchStart, i-1, i)) {
946 batchCount++;
947 batchEnd = i;
948 i++;
949 continue;
950 } else if(canPushBatchToTop(list, batchStart, i)) {
951 //If All the non-updating layers with in this batch
952 //does not have intersection with the updating layers
953 //above in z-order, then we can safely move the batch to
954 //higher z-order. Increment fbZ as it is moving up.
955 if( firstZReverseIndex < 0) {
956 firstZReverseIndex = i;
957 }
958 batchCount++;
959 batchEnd = i;
960 fbZ += updatingLayersAbove;
961 i++;
962 updatingLayersAbove = 0;
963 continue;
964 } else {
965 //both failed.start the loop again from here.
966 if(firstZReverseIndex >= 0) {
967 i = firstZReverseIndex;
968 }
969 break;
970 }
971 }
972 }
973 }
974 if(batchCount > maxBatchCount) {
975 maxBatchCount = batchCount;
976 maxBatchStart = batchStart;
977 maxBatchEnd = batchEnd;
978 fbZOrder = fbZ;
979 }
980 }
981 return fbZOrder;
982}
983
984bool MDPComp::markLayersForCaching(hwc_context_t* ctx,
985 hwc_display_contents_1_t* list) {
986 /* Idea is to keep as many non-updating(cached) layers in FB and
987 * send rest of them through MDP. This is done in 2 steps.
988 * 1. Find the maximum contiguous batch of non-updating layers.
989 * 2. See if we can improve this batch size for caching by adding
990 * opaque layers around the batch, if they don't have
991 * any overlapping with the updating layers in between.
992 * NEVER mark an updating layer for caching.
993 * But cached ones can be marked for MDP */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800994
995 int maxBatchStart = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700996 int maxBatchEnd = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800997 int maxBatchCount = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530998 int fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800999
Saurabh Shahce188452014-02-05 10:17:43 -08001000 /* Nothing is cached. No batching needed */
1001 if(mCurrentFrame.fbCount == 0) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001002 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -07001003 }
Saurabh Shahce188452014-02-05 10:17:43 -08001004
1005 /* No MDP comp layers, try to use other comp modes */
1006 if(mCurrentFrame.mdpCount == 0) {
1007 return false;
Saurabh Shahaa236822013-04-24 18:07:26 -07001008 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001009
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301010 fbZ = getBatch(list, maxBatchStart, maxBatchEnd, maxBatchCount);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001011
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301012 /* reset rest of the layers lying inside ROI for MDP comp */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001013 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001014 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001015 if((i < maxBatchStart || i > maxBatchEnd) &&
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301016 mCurrentFrame.isFBComposed[i]){
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001017 if(!mCurrentFrame.drop[i]){
1018 //If an unsupported layer is being attempted to
1019 //be pulled out we should fail
1020 if(not isSupportedForMDPComp(ctx, layer)) {
1021 return false;
1022 }
1023 mCurrentFrame.isFBComposed[i] = false;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001024 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001025 }
1026 }
1027
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301028 // update the frame data
1029 mCurrentFrame.fbZ = fbZ;
1030 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001031 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001032 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001033
1034 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301035 mCurrentFrame.fbCount);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001036
1037 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001038}
Saurabh Shah85234ec2013-04-12 17:09:00 -07001039
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001040void MDPComp::updateLayerCache(hwc_context_t* ctx,
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001041 hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001042 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001043 int fbCount = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001044
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001045 for(int i = 0; i < numAppLayers; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001046 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001047 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001048 if(!mCurrentFrame.drop[i])
1049 fbCount++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001050 mCurrentFrame.isFBComposed[i] = true;
1051 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -07001052 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001053 }
1054 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001055
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001056 mCurrentFrame.fbCount = fbCount;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001057 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount
1058 - mCurrentFrame.dropCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001059
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001060 ALOGD_IF(isDebug(),"%s: MDP count: %d FB count %d drop count: %d"
1061 ,__FUNCTION__, mCurrentFrame.mdpCount, mCurrentFrame.fbCount,
1062 mCurrentFrame.dropCount);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001063}
1064
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001065void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list,
1066 bool secureOnly) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001067 int nYuvCount = ctx->listStats[mDpy].yuvCount;
1068 for(int index = 0;index < nYuvCount; index++){
1069 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
1070 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
1071
1072 if(!isYUVDoable(ctx, layer)) {
1073 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
1074 mCurrentFrame.isFBComposed[nYuvIndex] = true;
1075 mCurrentFrame.fbCount++;
1076 }
1077 } else {
1078 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001079 private_handle_t *hnd = (private_handle_t *)layer->handle;
1080 if(!secureOnly || isSecureBuffer(hnd)) {
1081 mCurrentFrame.isFBComposed[nYuvIndex] = false;
1082 mCurrentFrame.fbCount--;
1083 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001084 }
1085 }
1086 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001087
1088 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001089 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
1090 ALOGD_IF(isDebug(),"%s: fb count: %d",__FUNCTION__,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001091 mCurrentFrame.fbCount);
1092}
1093
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001094bool MDPComp::postHeuristicsHandling(hwc_context_t *ctx,
1095 hwc_display_contents_1_t* list) {
1096
1097 //Capability checks
1098 if(!resourceCheck(ctx, list)) {
1099 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
1100 return false;
1101 }
1102
1103 //Limitations checks
1104 if(!hwLimitationsCheck(ctx, list)) {
1105 ALOGD_IF(isDebug(), "%s: HW limitations",__FUNCTION__);
1106 return false;
1107 }
1108
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001109 //Configure framebuffer first if applicable
1110 if(mCurrentFrame.fbZ >= 0) {
1111 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, mCurrentFrame.fbZ)) {
1112 ALOGD_IF(isDebug(), "%s configure framebuffer failed",
1113 __FUNCTION__);
1114 return false;
1115 }
1116 }
1117
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001118 mCurrentFrame.map();
1119
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001120 if(!allocLayerPipes(ctx, list)) {
1121 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -07001122 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001123 }
1124
1125 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001126 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001127 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001128 int mdpIndex = mCurrentFrame.layerToMDP[index];
1129 hwc_layer_1_t* layer = &list->hwLayers[index];
1130
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301131 //Leave fbZ for framebuffer. CACHE/GLES layers go here.
1132 if(mdpNextZOrder == mCurrentFrame.fbZ) {
1133 mdpNextZOrder++;
1134 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001135 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1136 cur_pipe->zOrder = mdpNextZOrder++;
1137
radhakrishnac9a67412013-09-25 17:40:42 +05301138 private_handle_t *hnd = (private_handle_t *)layer->handle;
1139 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1140 if(configure4k2kYuv(ctx, layer,
1141 mCurrentFrame.mdpToLayer[mdpIndex])
1142 != 0 ){
1143 ALOGD_IF(isDebug(), "%s: Failed to configure split pipes \
1144 for layer %d",__FUNCTION__, index);
1145 return false;
1146 }
1147 else{
1148 mdpNextZOrder++;
1149 }
1150 continue;
1151 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001152 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
1153 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
radhakrishnac9a67412013-09-25 17:40:42 +05301154 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -07001155 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001156 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001157 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001158 }
1159
Saurabh Shah450ac972013-12-16 18:18:39 -08001160 if(!ctx->mOverlay->validateAndSet(mDpy, ctx->dpyAttr[mDpy].fd)) {
1161 ALOGD_IF(isDebug(), "%s: Failed to validate and set overlay for dpy %d"
1162 ,__FUNCTION__, mDpy);
1163 return false;
1164 }
1165
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001166 setRedraw(ctx, list);
Saurabh Shahaa236822013-04-24 18:07:26 -07001167 return true;
1168}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001169
Saurabh Shah173f4242013-11-20 09:50:12 -08001170bool MDPComp::resourceCheck(hwc_context_t *ctx,
1171 hwc_display_contents_1_t *list) {
1172 const bool fbUsed = mCurrentFrame.fbCount;
1173 if(mCurrentFrame.mdpCount > sMaxPipesPerMixer - fbUsed) {
1174 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
1175 return false;
1176 }
Saurabh Shah173f4242013-11-20 09:50:12 -08001177 return true;
1178}
1179
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301180bool MDPComp::hwLimitationsCheck(hwc_context_t* ctx,
1181 hwc_display_contents_1_t* list) {
1182
1183 //A-family hw limitation:
1184 //If a layer need alpha scaling, MDP can not support.
1185 if(ctx->mMDP.version < qdutils::MDSS_V5) {
1186 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1187 if(!mCurrentFrame.isFBComposed[i] &&
1188 isAlphaScaled( &list->hwLayers[i])) {
1189 ALOGD_IF(isDebug(), "%s:frame needs alphaScaling",__FUNCTION__);
1190 return false;
1191 }
1192 }
1193 }
1194
1195 // On 8x26 & 8974 hw, we have a limitation of downscaling+blending.
1196 //If multiple layers requires downscaling and also they are overlapping
1197 //fall back to GPU since MDSS can not handle it.
1198 if(qdutils::MDPVersion::getInstance().is8x74v2() ||
1199 qdutils::MDPVersion::getInstance().is8x26()) {
1200 for(int i = 0; i < mCurrentFrame.layerCount-1; ++i) {
1201 hwc_layer_1_t* botLayer = &list->hwLayers[i];
1202 if(!mCurrentFrame.isFBComposed[i] &&
1203 isDownscaleRequired(botLayer)) {
1204 //if layer-i is marked for MDP and needs downscaling
1205 //check if any MDP layer on top of i & overlaps with layer-i
1206 for(int j = i+1; j < mCurrentFrame.layerCount; ++j) {
1207 hwc_layer_1_t* topLayer = &list->hwLayers[j];
1208 if(!mCurrentFrame.isFBComposed[j] &&
1209 isDownscaleRequired(topLayer)) {
1210 hwc_rect_t r = getIntersection(botLayer->displayFrame,
1211 topLayer->displayFrame);
1212 if(isValidRect(r))
1213 return false;
1214 }
1215 }
1216 }
1217 }
1218 }
1219 return true;
1220}
1221
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001222int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001223 int ret = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -07001224 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001225 MDPVersion& mdpVersion = qdutils::MDPVersion::getInstance();
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -07001226
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001227 //number of app layers exceeds MAX_NUM_APP_LAYERS fall back to GPU
1228 //do not cache the information for next draw cycle.
1229 if(numLayers > MAX_NUM_APP_LAYERS) {
1230 ALOGI("%s: Number of App layers exceeded the limit ",
1231 __FUNCTION__);
1232 mCachedFrame.reset();
1233 return -1;
1234 }
1235
Saurabh Shahb39f8152013-08-22 10:21:44 -07001236 //reset old data
1237 mCurrentFrame.reset(numLayers);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001238 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1239 mCurrentFrame.dropCount = 0;
Prabhanjan Kandula088bd892013-07-02 23:47:13 +05301240
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -07001241 // Detect the start of animation and fall back to GPU only once to cache
1242 // all the layers in FB and display FB content untill animation completes.
1243 if(ctx->listStats[mDpy].isDisplayAnimating) {
1244 mCurrentFrame.needsRedraw = false;
1245 if(ctx->mAnimationState[mDpy] == ANIMATION_STOPPED) {
1246 mCurrentFrame.needsRedraw = true;
1247 ctx->mAnimationState[mDpy] = ANIMATION_STARTED;
1248 }
1249 setMDPCompLayerFlags(ctx, list);
1250 mCachedFrame.updateCounts(mCurrentFrame);
1251 ret = -1;
1252 return ret;
1253 } else {
1254 ctx->mAnimationState[mDpy] = ANIMATION_STOPPED;
1255 }
1256
Saurabh Shahb39f8152013-08-22 10:21:44 -07001257 //Hard conditions, if not met, cannot do MDP comp
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001258 if(isFrameDoable(ctx)) {
1259 generateROI(ctx, list);
Saurabh Shahb39f8152013-08-22 10:21:44 -07001260
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001261 if(tryFullFrame(ctx, list) || tryVideoOnly(ctx, list)) {
1262 setMDPCompLayerFlags(ctx, list);
1263 } else {
1264 reset(ctx);
1265 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1266 mCurrentFrame.dropCount = 0;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001267 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001268 }
1269 } else {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001270 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
1271 __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001272 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001273 }
Saurabh Shahb39f8152013-08-22 10:21:44 -07001274
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001275 if(isDebug()) {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001276 ALOGD("GEOMETRY change: %d",
1277 (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001278 android::String8 sDump("");
1279 dump(sDump);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001280 ALOGD("%s",sDump.string());
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001281 }
1282
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001283 mCachedFrame.cacheAll(list);
1284 mCachedFrame.updateCounts(mCurrentFrame);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001285 return ret;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001286}
1287
radhakrishnac9a67412013-09-25 17:40:42 +05301288bool MDPComp::allocSplitVGPipesfor4k2k(hwc_context_t *ctx,
1289 hwc_display_contents_1_t* list, int index) {
1290
1291 bool bRet = true;
1292 hwc_layer_1_t* layer = &list->hwLayers[index];
1293 private_handle_t *hnd = (private_handle_t *)layer->handle;
1294 int mdpIndex = mCurrentFrame.layerToMDP[index];
1295 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
1296 info.pipeInfo = new MdpYUVPipeInfo;
1297 info.rot = NULL;
1298 MdpYUVPipeInfo& pipe_info = *(MdpYUVPipeInfo*)info.pipeInfo;
1299 ePipeType type = MDPCOMP_OV_VG;
1300
1301 pipe_info.lIndex = ovutils::OV_INVALID;
1302 pipe_info.rIndex = ovutils::OV_INVALID;
1303
1304 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
1305 if(pipe_info.lIndex == ovutils::OV_INVALID){
1306 bRet = false;
1307 ALOGD_IF(isDebug(),"%s: allocating first VG pipe failed",
1308 __FUNCTION__);
1309 }
1310 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
1311 if(pipe_info.rIndex == ovutils::OV_INVALID){
1312 bRet = false;
1313 ALOGD_IF(isDebug(),"%s: allocating second VG pipe failed",
1314 __FUNCTION__);
1315 }
1316 return bRet;
1317}
Saurabh Shah88e4d272013-09-03 13:31:29 -07001318//=============MDPCompNonSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001319
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001320void MDPCompNonSplit::adjustForSourceSplit(hwc_context_t *ctx,
radhakrishnac9a67412013-09-25 17:40:42 +05301321 hwc_display_contents_1_t* list){
1322 //As we split 4kx2k yuv layer and program to 2 VG pipes
1323 //(if available) increase mdpcount accordingly
1324 mCurrentFrame.mdpCount += ctx->listStats[mDpy].yuv4k2kCount;
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001325
1326 //If 4k2k Yuv layer split is possible, and if
1327 //fbz is above 4k2k layer, increment fb zorder by 1
1328 //as we split 4k2k layer and increment zorder for right half
1329 //of the layer
1330 if(mCurrentFrame.fbZ >= 0) {
1331 int n4k2kYuvCount = ctx->listStats[mDpy].yuv4k2kCount;
1332 for(int index = 0; index < n4k2kYuvCount; index++){
1333 int n4k2kYuvIndex =
1334 ctx->listStats[mDpy].yuv4k2kIndices[index];
1335 if(mCurrentFrame.fbZ > n4k2kYuvIndex){
1336 mCurrentFrame.fbZ += 1;
1337 }
1338 }
1339 }
radhakrishnac9a67412013-09-25 17:40:42 +05301340}
1341
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001342/*
1343 * Configures pipe(s) for MDP composition
1344 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001345int MDPCompNonSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001346 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001347 MdpPipeInfoNonSplit& mdp_info =
1348 *(static_cast<MdpPipeInfoNonSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001349 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
1350 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1351 eIsFg isFg = IS_FG_OFF;
1352 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001353
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001354 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
1355 __FUNCTION__, layer, zOrder, dest);
1356
Saurabh Shah88e4d272013-09-03 13:31:29 -07001357 return configureNonSplit(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001358 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001359}
1360
Saurabh Shah88e4d272013-09-03 13:31:29 -07001361bool MDPCompNonSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001362 hwc_display_contents_1_t* list) {
1363 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001364
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001365 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001366
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001367 hwc_layer_1_t* layer = &list->hwLayers[index];
1368 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301369 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1370 if(allocSplitVGPipesfor4k2k(ctx, list, index)){
1371 continue;
1372 }
1373 }
1374
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001375 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001376 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001377 info.pipeInfo = new MdpPipeInfoNonSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08001378 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001379 MdpPipeInfoNonSplit& pipe_info = *(MdpPipeInfoNonSplit*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001380 ePipeType type = MDPCOMP_OV_ANY;
1381
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001382 if(isYuvBuffer(hnd)) {
1383 type = MDPCOMP_OV_VG;
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301384 } else if(!qhwc::needsScaling(layer)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001385 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
1386 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001387 type = MDPCOMP_OV_DMA;
1388 }
1389
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001390 pipe_info.index = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001391 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001392 ALOGD_IF(isDebug(), "%s: Unable to get pipe type = %d",
1393 __FUNCTION__, (int) type);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001394 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001395 }
1396 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001397 return true;
1398}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001399
radhakrishnac9a67412013-09-25 17:40:42 +05301400int MDPCompNonSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1401 PipeLayerPair& PipeLayerPair) {
1402 MdpYUVPipeInfo& mdp_info =
1403 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1404 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1405 eIsFg isFg = IS_FG_OFF;
1406 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1407 eDest lDest = mdp_info.lIndex;
1408 eDest rDest = mdp_info.rIndex;
1409
1410 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1411 lDest, rDest, &PipeLayerPair.rot);
1412}
1413
Saurabh Shah88e4d272013-09-03 13:31:29 -07001414bool MDPCompNonSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001415
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001416 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001417 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1418 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -08001419 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001420
1421 if(!ctx || !list) {
1422 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001423 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001424 }
1425
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301426 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1427 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1428 return true;
1429 }
1430
Ramkumar Radhakrishnand8595ae2014-02-06 21:31:29 -08001431 // Set the Handle timeout to true for MDP or MIXED composition.
1432 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount) {
1433 sHandleTimeout = true;
1434 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001435
1436 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001437 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001438
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001439 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1440 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001441 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001442 if(mCurrentFrame.isFBComposed[i]) continue;
1443
Naseer Ahmed5b6708a2012-08-02 13:46:08 -07001444 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001445 private_handle_t *hnd = (private_handle_t *)layer->handle;
1446 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001447 if (!(layer->flags & HWC_COLOR_FILL)) {
1448 ALOGE("%s handle null", __FUNCTION__);
1449 return false;
1450 }
1451 // No PLAY for Color layer
1452 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1453 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001454 }
1455
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001456 int mdpIndex = mCurrentFrame.layerToMDP[i];
1457
radhakrishnac9a67412013-09-25 17:40:42 +05301458 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1459 {
1460 MdpYUVPipeInfo& pipe_info =
1461 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1462 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1463 ovutils::eDest indexL = pipe_info.lIndex;
1464 ovutils::eDest indexR = pipe_info.rIndex;
1465 int fd = hnd->fd;
1466 uint32_t offset = hnd->offset;
1467 if(rot) {
1468 rot->queueBuffer(fd, offset);
1469 fd = rot->getDstMemId();
1470 offset = rot->getDstOffset();
1471 }
1472 if(indexL != ovutils::OV_INVALID) {
1473 ovutils::eDest destL = (ovutils::eDest)indexL;
1474 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1475 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1476 if (!ov.queueBuffer(fd, offset, destL)) {
1477 ALOGE("%s: queueBuffer failed for display:%d",
1478 __FUNCTION__, mDpy);
1479 return false;
1480 }
1481 }
1482
1483 if(indexR != ovutils::OV_INVALID) {
1484 ovutils::eDest destR = (ovutils::eDest)indexR;
1485 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1486 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1487 if (!ov.queueBuffer(fd, offset, destR)) {
1488 ALOGE("%s: queueBuffer failed for display:%d",
1489 __FUNCTION__, mDpy);
1490 return false;
1491 }
1492 }
1493 }
1494 else{
1495 MdpPipeInfoNonSplit& pipe_info =
Saurabh Shah88e4d272013-09-03 13:31:29 -07001496 *(MdpPipeInfoNonSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
radhakrishnac9a67412013-09-25 17:40:42 +05301497 ovutils::eDest dest = pipe_info.index;
1498 if(dest == ovutils::OV_INVALID) {
1499 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001500 return false;
radhakrishnac9a67412013-09-25 17:40:42 +05301501 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001502
radhakrishnac9a67412013-09-25 17:40:42 +05301503 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1504 continue;
1505 }
1506
1507 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1508 using pipe: %d", __FUNCTION__, layer,
1509 hnd, dest );
1510
1511 int fd = hnd->fd;
1512 uint32_t offset = hnd->offset;
1513
1514 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1515 if(rot) {
1516 if(!rot->queueBuffer(fd, offset))
1517 return false;
1518 fd = rot->getDstMemId();
1519 offset = rot->getDstOffset();
1520 }
1521
1522 if (!ov.queueBuffer(fd, offset, dest)) {
1523 ALOGE("%s: queueBuffer failed for display:%d ",
1524 __FUNCTION__, mDpy);
1525 return false;
1526 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001527 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001528
1529 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001530 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001531 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001532}
1533
Saurabh Shah88e4d272013-09-03 13:31:29 -07001534//=============MDPCompSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001535
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001536void MDPCompSplit::adjustForSourceSplit(hwc_context_t *ctx,
radhakrishnac9a67412013-09-25 17:40:42 +05301537 hwc_display_contents_1_t* list){
1538 //if 4kx2k yuv layer is totally present in either in left half
1539 //or right half then try splitting the yuv layer to avoid decimation
1540 int n4k2kYuvCount = ctx->listStats[mDpy].yuv4k2kCount;
1541 const int lSplit = getLeftSplit(ctx, mDpy);
1542 for(int index = 0; index < n4k2kYuvCount; index++){
1543 int n4k2kYuvIndex = ctx->listStats[mDpy].yuv4k2kIndices[index];
1544 hwc_layer_1_t* layer = &list->hwLayers[n4k2kYuvIndex];
1545 hwc_rect_t dst = layer->displayFrame;
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001546 if((dst.left > lSplit) || (dst.right < lSplit)) {
radhakrishnac9a67412013-09-25 17:40:42 +05301547 mCurrentFrame.mdpCount += 1;
1548 }
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001549 if(mCurrentFrame.fbZ > n4k2kYuvIndex){
1550 mCurrentFrame.fbZ += 1;
1551 }
radhakrishnac9a67412013-09-25 17:40:42 +05301552 }
1553}
1554
Saurabh Shah88e4d272013-09-03 13:31:29 -07001555bool MDPCompSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
1556 MdpPipeInfoSplit& pipe_info,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001557 ePipeType type) {
1558 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001559 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001560
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001561 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001562 pipe_info.lIndex = ovutils::OV_INVALID;
1563 pipe_info.rIndex = ovutils::OV_INVALID;
1564
1565 if (dst.left < lSplit) {
1566 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_LEFT);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001567 if(pipe_info.lIndex == ovutils::OV_INVALID)
1568 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001569 }
1570
1571 if(dst.right > lSplit) {
1572 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_RIGHT);
1573 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001574 return false;
1575 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001576
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001577 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001578}
1579
Saurabh Shah88e4d272013-09-03 13:31:29 -07001580bool MDPCompSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001581 hwc_display_contents_1_t* list) {
1582 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001583
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001584 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001585
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001586 hwc_layer_1_t* layer = &list->hwLayers[index];
1587 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301588 hwc_rect_t dst = layer->displayFrame;
1589 const int lSplit = getLeftSplit(ctx, mDpy);
1590 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1591 if((dst.left > lSplit)||(dst.right < lSplit)){
1592 if(allocSplitVGPipesfor4k2k(ctx, list, index)){
1593 continue;
1594 }
1595 }
1596 }
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001597 int mdpIndex = mCurrentFrame.layerToMDP[index];
1598 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001599 info.pipeInfo = new MdpPipeInfoSplit;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001600 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001601 MdpPipeInfoSplit& pipe_info = *(MdpPipeInfoSplit*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001602 ePipeType type = MDPCOMP_OV_ANY;
1603
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001604 if(isYuvBuffer(hnd)) {
1605 type = MDPCOMP_OV_VG;
Sushil Chauhan15a2ea62013-09-04 18:28:36 -07001606 } else if(!qhwc::needsScalingWithSplit(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001607 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001608 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001609 type = MDPCOMP_OV_DMA;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001610 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001611
1612 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001613 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type = %d",
1614 __FUNCTION__, (int) type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001615 return false;
1616 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001617 }
1618 return true;
1619}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001620
radhakrishnac9a67412013-09-25 17:40:42 +05301621int MDPCompSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1622 PipeLayerPair& PipeLayerPair) {
1623 const int lSplit = getLeftSplit(ctx, mDpy);
1624 hwc_rect_t dst = layer->displayFrame;
1625 if((dst.left > lSplit)||(dst.right < lSplit)){
1626 MdpYUVPipeInfo& mdp_info =
1627 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1628 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1629 eIsFg isFg = IS_FG_OFF;
1630 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1631 eDest lDest = mdp_info.lIndex;
1632 eDest rDest = mdp_info.rIndex;
1633
1634 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1635 lDest, rDest, &PipeLayerPair.rot);
1636 }
1637 else{
1638 return configure(ctx, layer, PipeLayerPair);
1639 }
1640}
1641
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001642/*
1643 * Configures pipe(s) for MDP composition
1644 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001645int MDPCompSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001646 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001647 MdpPipeInfoSplit& mdp_info =
1648 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001649 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1650 eIsFg isFg = IS_FG_OFF;
1651 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1652 eDest lDest = mdp_info.lIndex;
1653 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001654
1655 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1656 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1657
Saurabh Shah88e4d272013-09-03 13:31:29 -07001658 return configureSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001659 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001660}
1661
Saurabh Shah88e4d272013-09-03 13:31:29 -07001662bool MDPCompSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001663
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001664 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001665 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1666 return true;
1667 }
1668
1669 if(!ctx || !list) {
1670 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001671 return false;
1672 }
1673
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301674 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1675 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1676 return true;
1677 }
1678
Ramkumar Radhakrishnand8595ae2014-02-06 21:31:29 -08001679 // Set the Handle timeout to true for MDP or MIXED composition.
1680 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount) {
1681 sHandleTimeout = true;
1682 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001683
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001684 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001685 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001686
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001687 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1688 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001689 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001690 if(mCurrentFrame.isFBComposed[i]) continue;
1691
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001692 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001693 private_handle_t *hnd = (private_handle_t *)layer->handle;
1694 if(!hnd) {
1695 ALOGE("%s handle null", __FUNCTION__);
1696 return false;
1697 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001698
1699 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1700 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001701 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001702
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001703 int mdpIndex = mCurrentFrame.layerToMDP[i];
1704
radhakrishnac9a67412013-09-25 17:40:42 +05301705 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1706 {
1707 MdpYUVPipeInfo& pipe_info =
1708 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1709 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1710 ovutils::eDest indexL = pipe_info.lIndex;
1711 ovutils::eDest indexR = pipe_info.rIndex;
1712 int fd = hnd->fd;
1713 uint32_t offset = hnd->offset;
1714 if(rot) {
1715 rot->queueBuffer(fd, offset);
1716 fd = rot->getDstMemId();
1717 offset = rot->getDstOffset();
1718 }
1719 if(indexL != ovutils::OV_INVALID) {
1720 ovutils::eDest destL = (ovutils::eDest)indexL;
1721 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1722 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1723 if (!ov.queueBuffer(fd, offset, destL)) {
1724 ALOGE("%s: queueBuffer failed for display:%d",
1725 __FUNCTION__, mDpy);
1726 return false;
1727 }
1728 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001729
radhakrishnac9a67412013-09-25 17:40:42 +05301730 if(indexR != ovutils::OV_INVALID) {
1731 ovutils::eDest destR = (ovutils::eDest)indexR;
1732 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1733 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1734 if (!ov.queueBuffer(fd, offset, destR)) {
1735 ALOGE("%s: queueBuffer failed for display:%d",
1736 __FUNCTION__, mDpy);
1737 return false;
1738 }
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001739 }
1740 }
radhakrishnac9a67412013-09-25 17:40:42 +05301741 else{
1742 MdpPipeInfoSplit& pipe_info =
1743 *(MdpPipeInfoSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1744 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001745
radhakrishnac9a67412013-09-25 17:40:42 +05301746 ovutils::eDest indexL = pipe_info.lIndex;
1747 ovutils::eDest indexR = pipe_info.rIndex;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001748
radhakrishnac9a67412013-09-25 17:40:42 +05301749 int fd = hnd->fd;
1750 int offset = hnd->offset;
1751
1752 if(ctx->mAD->isModeOn()) {
1753 if(ctx->mAD->draw(ctx, fd, offset)) {
1754 fd = ctx->mAD->getDstFd(ctx);
1755 offset = ctx->mAD->getDstOffset(ctx);
1756 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001757 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001758
radhakrishnac9a67412013-09-25 17:40:42 +05301759 if(rot) {
1760 rot->queueBuffer(fd, offset);
1761 fd = rot->getDstMemId();
1762 offset = rot->getDstOffset();
1763 }
1764
1765 //************* play left mixer **********
1766 if(indexL != ovutils::OV_INVALID) {
1767 ovutils::eDest destL = (ovutils::eDest)indexL;
1768 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1769 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1770 if (!ov.queueBuffer(fd, offset, destL)) {
1771 ALOGE("%s: queueBuffer failed for left mixer",
1772 __FUNCTION__);
1773 return false;
1774 }
1775 }
1776
1777 //************* play right mixer **********
1778 if(indexR != ovutils::OV_INVALID) {
1779 ovutils::eDest destR = (ovutils::eDest)indexR;
1780 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1781 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1782 if (!ov.queueBuffer(fd, offset, destR)) {
1783 ALOGE("%s: queueBuffer failed for right mixer",
1784 __FUNCTION__);
1785 return false;
1786 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001787 }
1788 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001789
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001790 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1791 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001792
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001793 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001794}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001795}; //namespace
1796