blob: 431f55d0fead7880ca8267c7e6c351cfc571510c [file] [log] [blame]
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001/*
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08002 * Copyright (C) 2012-2014, 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>
Sushil Chauhandefd3522014-05-13 18:17:12 -070029#include "hwc_copybit.h"
Saurabh Shahacf10202013-02-26 10:15:15 -080030
Saurabh Shah85234ec2013-04-12 17:09:00 -070031using namespace overlay;
Saurabh Shahbd2d0832013-04-04 14:33:08 -070032using namespace qdutils;
Saurabh Shahacf10202013-02-26 10:15:15 -080033using namespace overlay::utils;
34namespace ovutils = overlay::utils;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070035
Naseer Ahmed7c958d42012-07-31 18:57:03 -070036namespace qhwc {
37
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080038//==============MDPComp========================================================
39
Naseer Ahmed7c958d42012-07-31 18:57:03 -070040IdleInvalidator *MDPComp::idleInvalidator = NULL;
41bool MDPComp::sIdleFallBack = false;
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -080042bool MDPComp::sHandleTimeout = false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070043bool MDPComp::sDebugLogs = false;
Naseer Ahmed54821fe2012-11-28 18:44:38 -050044bool MDPComp::sEnabled = false;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -070045bool MDPComp::sEnableMixedMode = true;
Jeykumar Sankaran0ad97c42014-03-09 23:00:53 -070046int MDPComp::sSimulationFlags = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080047int MDPComp::sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
radhakrishnac9a67412013-09-25 17:40:42 +053048bool MDPComp::sEnable4k2kYUVSplit = false;
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -070049bool MDPComp::sSrcSplitEnabled = false;
Saurabh Shah88e4d272013-09-03 13:31:29 -070050MDPComp* MDPComp::getObject(hwc_context_t *ctx, const int& dpy) {
Saurabh Shah60e8bde2014-04-30 14:46:03 -070051 if(qdutils::MDPVersion::getInstance().isSrcSplit()) {
52 sSrcSplitEnabled = true;
53 return new MDPCompSrcSplit(dpy);
54 } else if(isDisplaySplit(ctx, dpy)) {
Saurabh Shah88e4d272013-09-03 13:31:29 -070055 return new MDPCompSplit(dpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080056 }
Saurabh Shah88e4d272013-09-03 13:31:29 -070057 return new MDPCompNonSplit(dpy);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080058}
59
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080060MDPComp::MDPComp(int dpy):mDpy(dpy){};
61
Jeykumar Sankaran6850ac62014-05-27 10:07:26 -070062void MDPComp::dump(android::String8& buf, hwc_context_t *ctx)
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080063{
Jeykumar Sankaran3c6bb042013-08-15 14:01:04 -070064 if(mCurrentFrame.layerCount > MAX_NUM_APP_LAYERS)
65 return;
66
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080067 dumpsys_log(buf,"HWC Map for Dpy: %s \n",
Jeykumar Sankaran27dee262013-08-01 17:09:54 -070068 (mDpy == 0) ? "\"PRIMARY\"" :
69 (mDpy == 1) ? "\"EXTERNAL\"" : "\"VIRTUAL\"");
Saurabh Shahe9bc60f2013-08-29 12:58:06 -070070 dumpsys_log(buf,"CURR_FRAME: layerCount:%2d mdpCount:%2d "
71 "fbCount:%2d \n", mCurrentFrame.layerCount,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080072 mCurrentFrame.mdpCount, mCurrentFrame.fbCount);
73 dumpsys_log(buf,"needsFBRedraw:%3s pipesUsed:%2d MaxPipesPerMixer: %d \n",
74 (mCurrentFrame.needsRedraw? "YES" : "NO"),
75 mCurrentFrame.mdpCount, sMaxPipesPerMixer);
Jeykumar Sankaran6850ac62014-05-27 10:07:26 -070076 if(isDisplaySplit(ctx, mDpy)) {
77 dumpsys_log(buf, "Programmed ROI's: Left: [%d, %d, %d, %d] "
78 "Right: [%d, %d, %d, %d] \n",
79 ctx->listStats[mDpy].lRoi.left, ctx->listStats[mDpy].lRoi.top,
80 ctx->listStats[mDpy].lRoi.right,
81 ctx->listStats[mDpy].lRoi.bottom,
82 ctx->listStats[mDpy].rRoi.left,ctx->listStats[mDpy].rRoi.top,
83 ctx->listStats[mDpy].rRoi.right,
84 ctx->listStats[mDpy].rRoi.bottom);
85 } else {
86 dumpsys_log(buf, "Programmed ROI: [%d, %d, %d, %d] \n",
87 ctx->listStats[mDpy].lRoi.left,ctx->listStats[mDpy].lRoi.top,
88 ctx->listStats[mDpy].lRoi.right,
89 ctx->listStats[mDpy].lRoi.bottom);
90 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080091 dumpsys_log(buf," --------------------------------------------- \n");
92 dumpsys_log(buf," listIdx | cached? | mdpIndex | comptype | Z \n");
93 dumpsys_log(buf," --------------------------------------------- \n");
94 for(int index = 0; index < mCurrentFrame.layerCount; index++ )
95 dumpsys_log(buf," %7d | %7s | %8d | %9s | %2d \n",
96 index,
97 (mCurrentFrame.isFBComposed[index] ? "YES" : "NO"),
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -070098 mCurrentFrame.layerToMDP[index],
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080099 (mCurrentFrame.isFBComposed[index] ?
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700100 (mCurrentFrame.drop[index] ? "DROP" :
101 (mCurrentFrame.needsRedraw ? "GLES" : "CACHE")) : "MDP"),
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800102 (mCurrentFrame.isFBComposed[index] ? mCurrentFrame.fbZ :
103 mCurrentFrame.mdpToLayer[mCurrentFrame.layerToMDP[index]].pipeInfo->zOrder));
104 dumpsys_log(buf,"\n");
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800105}
106
107bool MDPComp::init(hwc_context_t *ctx) {
108
109 if(!ctx) {
110 ALOGE("%s: Invalid hwc context!!",__FUNCTION__);
111 return false;
112 }
113
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800114 char property[PROPERTY_VALUE_MAX];
115
116 sEnabled = false;
117 if((property_get("persist.hwc.mdpcomp.enable", property, NULL) > 0) &&
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800118 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
119 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800120 sEnabled = true;
121 }
122
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700123 sEnableMixedMode = true;
124 if((property_get("debug.mdpcomp.mixedmode.disable", property, NULL) > 0) &&
125 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
126 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
127 sEnableMixedMode = false;
128 }
129
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800130 if(property_get("debug.mdpcomp.logs", property, NULL) > 0) {
131 if(atoi(property) != 0)
132 sDebugLogs = true;
133 }
134
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800135 sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
Saurabh Shah85234ec2013-04-12 17:09:00 -0700136 if(property_get("debug.mdpcomp.maxpermixer", property, "-1") > 0) {
137 int val = atoi(property);
138 if(val >= 0)
139 sMaxPipesPerMixer = min(val, MAX_PIPES_PER_MIXER);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800140 }
141
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400142 if(ctx->mMDP.panel != MIPI_CMD_PANEL) {
143 // Idle invalidation is not necessary on command mode panels
144 long idle_timeout = DEFAULT_IDLE_TIME;
145 if(property_get("debug.mdpcomp.idletime", property, NULL) > 0) {
146 if(atoi(property) != 0)
147 idle_timeout = atoi(property);
148 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800149
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400150 //create Idle Invalidator only when not disabled through property
151 if(idle_timeout != -1)
152 idleInvalidator = IdleInvalidator::getInstance();
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800153
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400154 if(idleInvalidator == NULL) {
155 ALOGE("%s: failed to instantiate idleInvalidator object",
156 __FUNCTION__);
157 } else {
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530158 idleInvalidator->init(timeout_handler, ctx,
159 (unsigned int)idle_timeout);
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400160 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800161 }
radhakrishnac9a67412013-09-25 17:40:42 +0530162
Saurabh Shah7c727642014-06-02 15:47:14 -0700163 if(!qdutils::MDPVersion::getInstance().isSrcSplit() &&
164 property_get("persist.mdpcomp.4k2kSplit", property, "0") > 0 &&
165 (!strncmp(property, "1", PROPERTY_VALUE_MAX) ||
166 !strncasecmp(property,"true", PROPERTY_VALUE_MAX))) {
radhakrishnac9a67412013-09-25 17:40:42 +0530167 sEnable4k2kYUVSplit = true;
168 }
Sushil Chauhandefd3522014-05-13 18:17:12 -0700169
170 if ((property_get("persist.hwc.ptor.enable", property, NULL) > 0) &&
171 ((!strncasecmp(property, "true", PROPERTY_VALUE_MAX )) ||
172 (!strncmp(property, "1", PROPERTY_VALUE_MAX )))) {
173 ctx->mCopyBit[HWC_DISPLAY_PRIMARY] = new CopyBit(ctx,
174 HWC_DISPLAY_PRIMARY);
175 }
176
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700177 return true;
178}
179
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800180void MDPComp::reset(hwc_context_t *ctx) {
181 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700182 mCurrentFrame.reset(numLayers);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800183 ctx->mOverlay->clear(mDpy);
184 ctx->mLayerRotMap[mDpy]->clear();
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700185}
186
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700187void MDPComp::timeout_handler(void *udata) {
188 struct hwc_context_t* ctx = (struct hwc_context_t*)(udata);
189
190 if(!ctx) {
191 ALOGE("%s: received empty data in timer callback", __FUNCTION__);
192 return;
193 }
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -0800194 Locker::Autolock _l(ctx->mDrawLock);
195 // Handle timeout event only if the previous composition is MDP or MIXED.
196 if(!sHandleTimeout) {
197 ALOGD_IF(isDebug(), "%s:Do not handle this timeout", __FUNCTION__);
198 return;
199 }
Jesse Hall3be78d92012-08-21 15:12:23 -0700200 if(!ctx->proc) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700201 ALOGE("%s: HWC proc not registered", __FUNCTION__);
202 return;
203 }
204 sIdleFallBack = true;
205 /* Trigger SF to redraw the current frame */
Jesse Hall3be78d92012-08-21 15:12:23 -0700206 ctx->proc->invalidate(ctx->proc);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700207}
208
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800209void MDPComp::setMDPCompLayerFlags(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800210 hwc_display_contents_1_t* list) {
211 LayerProp *layerProp = ctx->layerProp[mDpy];
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800212
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800213 for(int index = 0; index < ctx->listStats[mDpy].numAppLayers; index++) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800214 hwc_layer_1_t* layer = &(list->hwLayers[index]);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800215 if(!mCurrentFrame.isFBComposed[index]) {
216 layerProp[index].mFlags |= HWC_MDPCOMP;
217 layer->compositionType = HWC_OVERLAY;
218 layer->hints |= HWC_HINT_CLEAR_FB;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800219 } else {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700220 /* Drop the layer when its already present in FB OR when it lies
221 * outside frame's ROI */
222 if(!mCurrentFrame.needsRedraw || mCurrentFrame.drop[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800223 layer->compositionType = HWC_OVERLAY;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700224 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800225 }
226 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700227}
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500228
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800229void MDPComp::setRedraw(hwc_context_t *ctx,
230 hwc_display_contents_1_t* list) {
231 mCurrentFrame.needsRedraw = false;
232 if(!mCachedFrame.isSameFrame(mCurrentFrame, list) ||
233 (list->flags & HWC_GEOMETRY_CHANGED) ||
234 isSkipPresent(ctx, mDpy)) {
235 mCurrentFrame.needsRedraw = true;
236 }
237}
238
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800239MDPComp::FrameInfo::FrameInfo() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700240 reset(0);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800241}
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800242
Saurabh Shahaa236822013-04-24 18:07:26 -0700243void MDPComp::FrameInfo::reset(const int& numLayers) {
244 for(int i = 0 ; i < MAX_PIPES_PER_MIXER && numLayers; i++ ) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800245 if(mdpToLayer[i].pipeInfo) {
246 delete mdpToLayer[i].pipeInfo;
247 mdpToLayer[i].pipeInfo = NULL;
248 //We dont own the rotator
249 mdpToLayer[i].rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800250 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800251 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800252
253 memset(&mdpToLayer, 0, sizeof(mdpToLayer));
254 memset(&layerToMDP, -1, sizeof(layerToMDP));
Saurabh Shahaa236822013-04-24 18:07:26 -0700255 memset(&isFBComposed, 1, sizeof(isFBComposed));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800256
Saurabh Shahaa236822013-04-24 18:07:26 -0700257 layerCount = numLayers;
258 fbCount = numLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800259 mdpCount = 0;
Saurabh Shah2f3895f2013-05-02 10:13:31 -0700260 needsRedraw = true;
Saurabh Shahd53bc5f2014-02-05 10:17:43 -0800261 fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800262}
263
Saurabh Shahaa236822013-04-24 18:07:26 -0700264void MDPComp::FrameInfo::map() {
265 // populate layer and MDP maps
266 int mdpIdx = 0;
267 for(int idx = 0; idx < layerCount; idx++) {
268 if(!isFBComposed[idx]) {
269 mdpToLayer[mdpIdx].listIndex = idx;
270 layerToMDP[idx] = mdpIdx++;
271 }
272 }
273}
274
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800275MDPComp::LayerCache::LayerCache() {
276 reset();
277}
278
279void MDPComp::LayerCache::reset() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700280 memset(&hnd, 0, sizeof(hnd));
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530281 memset(&isFBComposed, true, sizeof(isFBComposed));
282 memset(&drop, false, sizeof(drop));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800283 layerCount = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -0700284}
285
286void MDPComp::LayerCache::cacheAll(hwc_display_contents_1_t* list) {
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530287 const int numAppLayers = (int)list->numHwLayers - 1;
Saurabh Shahaa236822013-04-24 18:07:26 -0700288 for(int i = 0; i < numAppLayers; i++) {
289 hnd[i] = list->hwLayers[i].handle;
290 }
291}
292
293void MDPComp::LayerCache::updateCounts(const FrameInfo& curFrame) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700294 layerCount = curFrame.layerCount;
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530295 memcpy(&isFBComposed, &curFrame.isFBComposed, sizeof(isFBComposed));
296 memcpy(&drop, &curFrame.drop, sizeof(drop));
297}
298
Jeykumar Sankaran988d3682013-11-15 11:57:16 -0800299bool MDPComp::LayerCache::isSameFrame(const FrameInfo& curFrame,
300 hwc_display_contents_1_t* list) {
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530301 if(layerCount != curFrame.layerCount)
302 return false;
303 for(int i = 0; i < curFrame.layerCount; i++) {
304 if((curFrame.isFBComposed[i] != isFBComposed[i]) ||
305 (curFrame.drop[i] != drop[i])) {
306 return false;
307 }
Jeykumar Sankaran988d3682013-11-15 11:57:16 -0800308 if(curFrame.isFBComposed[i] &&
309 (hnd[i] != list->hwLayers[i].handle)){
310 return false;
311 }
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530312 }
313 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800314}
315
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700316bool MDPComp::isSupportedForMDPComp(hwc_context_t *ctx, hwc_layer_1_t* layer) {
317 private_handle_t *hnd = (private_handle_t *)layer->handle;
318 if((not isYuvBuffer(hnd) and has90Transform(layer)) or
319 (not isValidDimension(ctx,layer))
320 //More conditions here, SKIP, sRGB+Blend etc
321 ) {
322 return false;
323 }
324 return true;
325}
326
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530327bool MDPComp::isValidDimension(hwc_context_t *ctx, hwc_layer_1_t *layer) {
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800328 private_handle_t *hnd = (private_handle_t *)layer->handle;
329
330 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -0700331 if (layer->flags & HWC_COLOR_FILL) {
332 // Color layer
333 return true;
334 }
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800335 ALOGE("%s: layer handle is NULL", __FUNCTION__);
336 return false;
337 }
338
Naseer Ahmede850a802013-09-06 13:12:52 -0400339 //XXX: Investigate doing this with pixel phase on MDSS
Naseer Ahmede77f8082013-10-10 13:42:48 -0400340 if(!isSecureBuffer(hnd) && isNonIntegralSourceCrop(layer->sourceCropf))
Naseer Ahmede850a802013-09-06 13:12:52 -0400341 return false;
342
Saurabh Shah62e1d732013-09-17 10:44:05 -0700343 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700344 hwc_rect_t dst = layer->displayFrame;
Saurabh Shah4fdde762013-04-30 18:47:33 -0700345 int crop_w = crop.right - crop.left;
346 int crop_h = crop.bottom - crop.top;
347 int dst_w = dst.right - dst.left;
348 int dst_h = dst.bottom - dst.top;
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800349 float w_scale = ((float)crop_w / (float)dst_w);
350 float h_scale = ((float)crop_h / (float)dst_h);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700351
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800352 /* Workaround for MDP HW limitation in DSI command mode panels where
353 * FPS will not go beyond 30 if buffers on RGB pipes are of width or height
354 * less than 5 pixels
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530355 * There also is a HW limilation in MDP, minimum block size is 2x2
356 * Fallback to GPU if height is less than 2.
357 */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800358 if((crop_w < 5)||(crop_h < 5))
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800359 return false;
360
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800361 if((w_scale > 1.0f) || (h_scale > 1.0f)) {
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700362 const uint32_t maxMDPDownscale =
Saurabh Shah4fdde762013-04-30 18:47:33 -0700363 qdutils::MDPVersion::getInstance().getMaxMDPDownscale();
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800364 const float w_dscale = w_scale;
365 const float h_dscale = h_scale;
366
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800367 if(ctx->mMDP.version >= qdutils::MDSS_V5) {
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700368
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800369 if(!qdutils::MDPVersion::getInstance().supportsDecimation()) {
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700370 /* On targets that doesnt support Decimation (eg.,8x26)
371 * maximum downscale support is overlay pipe downscale.
372 */
373 if(crop_w > MAX_DISPLAY_DIM || w_dscale > maxMDPDownscale ||
374 h_dscale > maxMDPDownscale)
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800375 return false;
376 } else {
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700377 // Decimation on macrotile format layers is not supported.
378 if(isTileRendered(hnd)) {
379 /* MDP can read maximum MAX_DISPLAY_DIM width.
380 * Bail out if
381 * 1. Src crop > MAX_DISPLAY_DIM on nonsplit MDPComp
382 * 2. exceeds maximum downscale limit
383 */
384 if(((crop_w > MAX_DISPLAY_DIM) && !sSrcSplitEnabled) ||
385 w_dscale > maxMDPDownscale ||
386 h_dscale > maxMDPDownscale) {
387 return false;
388 }
389 } else if(w_dscale > 64 || h_dscale > 64)
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800390 return false;
391 }
392 } else { //A-family
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700393 if(w_dscale > maxMDPDownscale || h_dscale > maxMDPDownscale)
Saurabh Shah4fdde762013-04-30 18:47:33 -0700394 return false;
395 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700396 }
397
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800398 if((w_scale < 1.0f) || (h_scale < 1.0f)) {
399 const uint32_t upscale =
400 qdutils::MDPVersion::getInstance().getMaxMDPUpscale();
401 const float w_uscale = 1.0f / w_scale;
402 const float h_uscale = 1.0f / h_scale;
403
404 if(w_uscale > upscale || h_uscale > upscale)
405 return false;
406 }
407
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800408 return true;
409}
410
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800411bool MDPComp::isFrameDoable(hwc_context_t *ctx) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700412 bool ret = true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800413
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800414 if(!isEnabled()) {
415 ALOGD_IF(isDebug(),"%s: MDP Comp. not enabled.", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700416 ret = false;
Raj Kamal068f4572014-04-14 16:14:06 +0530417 } else if((qdutils::MDPVersion::getInstance().is8x26() ||
Prabhanjan Kandula958ffa92014-05-12 14:56:56 +0530418 qdutils::MDPVersion::getInstance().is8x16() ||
419 qdutils::MDPVersion::getInstance().is8x39()) &&
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -0800420 ctx->mVideoTransFlag &&
421 isSecondaryConnected(ctx)) {
Saurabh Shahd4e65852013-06-17 11:33:53 -0700422 //1 Padding round to shift pipes across mixers
423 ALOGD_IF(isDebug(),"%s: MDP Comp. video transition padding round",
424 __FUNCTION__);
425 ret = false;
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -0800426 } else if(isSecondaryConfiguring(ctx)) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800427 ALOGD_IF( isDebug(),"%s: External Display connection is pending",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800428 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700429 ret = false;
Saurabh Shahaa236822013-04-24 18:07:26 -0700430 } else if(ctx->isPaddingRound) {
Raj Kamal9ed3d6b2014-02-07 16:15:17 +0530431 ALOGD_IF(isDebug(), "%s: padding round invoked for dpy %d",
432 __FUNCTION__,mDpy);
Saurabh Shahaa236822013-04-24 18:07:26 -0700433 ret = false;
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700434 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700435 return ret;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800436}
437
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800438void MDPCompNonSplit::trimAgainstROI(hwc_context_t *ctx, hwc_rect_t& fbRect) {
439 hwc_rect_t roi = ctx->listStats[mDpy].lRoi;
440 fbRect = getIntersection(fbRect, roi);
441}
442
443/* 1) Identify layers that are not visible or lying outside the updating ROI and
444 * drop them from composition.
445 * 2) If we have a scaling layer which needs cropping against generated
446 * ROI, reset ROI to full resolution. */
447bool MDPCompNonSplit::validateAndApplyROI(hwc_context_t *ctx,
448 hwc_display_contents_1_t* list) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700449 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800450 hwc_rect_t visibleRect = ctx->listStats[mDpy].lRoi;
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800451
452 for(int i = numAppLayers - 1; i >= 0; i--){
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800453 if(!isValidRect(visibleRect)) {
454 mCurrentFrame.drop[i] = true;
455 mCurrentFrame.dropCount++;
Jeykumar Sankaran0b961452014-01-21 17:26:12 -0800456 continue;
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800457 }
458
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700459 const hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700460 hwc_rect_t dstRect = layer->displayFrame;
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800461 hwc_rect_t res = getIntersection(visibleRect, dstRect);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700462
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700463 if(!isValidRect(res)) {
464 mCurrentFrame.drop[i] = true;
465 mCurrentFrame.dropCount++;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800466 } else {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700467 /* Reset frame ROI when any layer which needs scaling also needs ROI
468 * cropping */
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800469 if(!isSameRect(res, dstRect) && needsScaling (layer)) {
Arpita Banerjeed8965982013-11-08 17:27:33 -0800470 ALOGI("%s: Resetting ROI due to scaling", __FUNCTION__);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700471 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
472 mCurrentFrame.dropCount = 0;
473 return false;
474 }
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800475
Jeykumar Sankaran0b961452014-01-21 17:26:12 -0800476 /* deduct any opaque region from visibleRect */
477 if (layer->blending == HWC_BLENDING_NONE)
478 visibleRect = deductRect(visibleRect, res);
479 }
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700480 }
481 return true;
482}
483
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800484/* Calculate ROI for the frame by accounting all the layer's dispalyFrame which
485 * are updating. If DirtyRegion is applicable, calculate it by accounting all
486 * the changing layer's dirtyRegion. */
487void MDPCompNonSplit::generateROI(hwc_context_t *ctx,
488 hwc_display_contents_1_t* list) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700489 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800490 if(!canPartialUpdate(ctx, list))
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700491 return;
492
493 struct hwc_rect roi = (struct hwc_rect){0, 0, 0, 0};
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800494 hwc_rect fullFrame = (struct hwc_rect) {0, 0,(int)ctx->dpyAttr[mDpy].xres,
495 (int)ctx->dpyAttr[mDpy].yres};
496
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700497 for(int index = 0; index < numAppLayers; index++ ) {
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800498 hwc_layer_1_t* layer = &list->hwLayers[index];
499 if ((mCachedFrame.hnd[index] != layer->handle) ||
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800500 isYuvBuffer((private_handle_t *)layer->handle)) {
Jeykumar Sankaran455678c2014-05-30 10:22:38 -0700501 hwc_rect_t dst = layer->displayFrame;
502 hwc_rect_t updatingRect = dst;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800503
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800504#ifdef QCOM_BSP
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800505 if(!needsScaling(layer) && !layer->transform)
Jeykumar Sankaran455678c2014-05-30 10:22:38 -0700506 {
507 hwc_rect_t src = integerizeSourceCrop(layer->sourceCropf);
508 int x_off = dst.left - src.left;
509 int y_off = dst.top - src.top;
510 updatingRect = moveRect(layer->dirtyRect, x_off, y_off);
511 }
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800512#endif
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800513
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800514 roi = getUnion(roi, updatingRect);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700515 }
516 }
517
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800518 /* No layer is updating. Still SF wants a refresh.*/
519 if(!isValidRect(roi))
520 return;
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800521
522 // Align ROI coordinates to panel restrictions
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800523 roi = getSanitizeROI(roi, fullFrame);
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800524
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800525 ctx->listStats[mDpy].lRoi = roi;
526 if(!validateAndApplyROI(ctx, list))
527 resetROI(ctx, mDpy);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700528
529 ALOGD_IF(isDebug(),"%s: generated ROI: [%d, %d, %d, %d]", __FUNCTION__,
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800530 ctx->listStats[mDpy].lRoi.left, ctx->listStats[mDpy].lRoi.top,
531 ctx->listStats[mDpy].lRoi.right, ctx->listStats[mDpy].lRoi.bottom);
532}
533
534void MDPCompSplit::trimAgainstROI(hwc_context_t *ctx, hwc_rect_t& fbRect) {
535 hwc_rect l_roi = ctx->listStats[mDpy].lRoi;
536 hwc_rect r_roi = ctx->listStats[mDpy].rRoi;
537
538 hwc_rect_t l_fbRect = getIntersection(fbRect, l_roi);
539 hwc_rect_t r_fbRect = getIntersection(fbRect, r_roi);
540 fbRect = getUnion(l_fbRect, r_fbRect);
541}
542/* 1) Identify layers that are not visible or lying outside BOTH the updating
543 * ROI's and drop them from composition. If a layer is spanning across both
544 * the halves of the screen but needed by only ROI, the non-contributing
545 * half will not be programmed for MDP.
546 * 2) If we have a scaling layer which needs cropping against generated
547 * ROI, reset ROI to full resolution. */
548bool MDPCompSplit::validateAndApplyROI(hwc_context_t *ctx,
549 hwc_display_contents_1_t* list) {
550
551 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
552
553 hwc_rect_t visibleRectL = ctx->listStats[mDpy].lRoi;
554 hwc_rect_t visibleRectR = ctx->listStats[mDpy].rRoi;
555
556 for(int i = numAppLayers - 1; i >= 0; i--){
557 if(!isValidRect(visibleRectL) && !isValidRect(visibleRectR))
558 {
559 mCurrentFrame.drop[i] = true;
560 mCurrentFrame.dropCount++;
561 continue;
562 }
563
564 const hwc_layer_1_t* layer = &list->hwLayers[i];
565 hwc_rect_t dstRect = layer->displayFrame;
566
567 hwc_rect_t l_res = getIntersection(visibleRectL, dstRect);
568 hwc_rect_t r_res = getIntersection(visibleRectR, dstRect);
569 hwc_rect_t res = getUnion(l_res, r_res);
570
571 if(!isValidRect(l_res) && !isValidRect(r_res)) {
572 mCurrentFrame.drop[i] = true;
573 mCurrentFrame.dropCount++;
574 } else {
575 /* Reset frame ROI when any layer which needs scaling also needs ROI
576 * cropping */
577 if(!isSameRect(res, dstRect) && needsScaling (layer)) {
578 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
579 mCurrentFrame.dropCount = 0;
580 return false;
581 }
582
583 if (layer->blending == HWC_BLENDING_NONE) {
584 visibleRectL = deductRect(visibleRectL, l_res);
585 visibleRectR = deductRect(visibleRectR, r_res);
586 }
587 }
588 }
589 return true;
590}
591/* Calculate ROI for the frame by accounting all the layer's dispalyFrame which
592 * are updating. If DirtyRegion is applicable, calculate it by accounting all
593 * the changing layer's dirtyRegion. */
594void MDPCompSplit::generateROI(hwc_context_t *ctx,
595 hwc_display_contents_1_t* list) {
596 if(!canPartialUpdate(ctx, list))
597 return;
598
599 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
600 int lSplit = getLeftSplit(ctx, mDpy);
601
602 int hw_h = (int)ctx->dpyAttr[mDpy].yres;
603 int hw_w = (int)ctx->dpyAttr[mDpy].xres;
604
605 struct hwc_rect l_frame = (struct hwc_rect){0, 0, lSplit, hw_h};
606 struct hwc_rect r_frame = (struct hwc_rect){lSplit, 0, hw_w, hw_h};
607
608 struct hwc_rect l_roi = (struct hwc_rect){0, 0, 0, 0};
609 struct hwc_rect r_roi = (struct hwc_rect){0, 0, 0, 0};
610
611 for(int index = 0; index < numAppLayers; index++ ) {
612 hwc_layer_1_t* layer = &list->hwLayers[index];
613 if ((mCachedFrame.hnd[index] != layer->handle) ||
614 isYuvBuffer((private_handle_t *)layer->handle)) {
Jeykumar Sankaran71e597c2014-05-07 16:23:14 -0700615 hwc_rect_t dst = layer->displayFrame;
616 hwc_rect_t updatingRect = dst;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800617
618#ifdef QCOM_BSP
619 if(!needsScaling(layer) && !layer->transform)
Jeykumar Sankaran71e597c2014-05-07 16:23:14 -0700620 {
621 hwc_rect_t src = integerizeSourceCrop(layer->sourceCropf);
622 int x_off = dst.left - src.left;
623 int y_off = dst.top - src.top;
624 updatingRect = moveRect(layer->dirtyRect, x_off, y_off);
625 }
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800626#endif
627
628 hwc_rect_t l_dst = getIntersection(l_frame, updatingRect);
629 if(isValidRect(l_dst))
630 l_roi = getUnion(l_roi, l_dst);
631
632 hwc_rect_t r_dst = getIntersection(r_frame, updatingRect);
633 if(isValidRect(r_dst))
634 r_roi = getUnion(r_roi, r_dst);
635 }
636 }
637
Jeykumar Sankarana40a9342014-04-25 09:37:10 -0700638 /* For panels that cannot accept commands in both the interfaces, we cannot
639 * send two ROI's (for each half). We merge them into single ROI and split
640 * them across lSplit for MDP mixer use. The ROI's will be merged again
641 * finally before udpating the panel in the driver. */
642 if(qdutils::MDPVersion::getInstance().needsROIMerge()) {
643 hwc_rect_t temp_roi = getUnion(l_roi, r_roi);
644 l_roi = getIntersection(temp_roi, l_frame);
645 r_roi = getIntersection(temp_roi, r_frame);
646 }
647
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800648 /* No layer is updating. Still SF wants a refresh. */
649 if(!isValidRect(l_roi) && !isValidRect(r_roi))
650 return;
651
652 l_roi = getSanitizeROI(l_roi, l_frame);
653 r_roi = getSanitizeROI(r_roi, r_frame);
654
655 ctx->listStats[mDpy].lRoi = l_roi;
656 ctx->listStats[mDpy].rRoi = r_roi;
657
658 if(!validateAndApplyROI(ctx, list))
659 resetROI(ctx, mDpy);
660
661 ALOGD_IF(isDebug(),"%s: generated L_ROI: [%d, %d, %d, %d]"
662 "R_ROI: [%d, %d, %d, %d]", __FUNCTION__,
663 ctx->listStats[mDpy].lRoi.left, ctx->listStats[mDpy].lRoi.top,
664 ctx->listStats[mDpy].lRoi.right, ctx->listStats[mDpy].lRoi.bottom,
665 ctx->listStats[mDpy].rRoi.left, ctx->listStats[mDpy].rRoi.top,
666 ctx->listStats[mDpy].rRoi.right, ctx->listStats[mDpy].rRoi.bottom);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700667}
668
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800669/* Checks for conditions where all the layers marked for MDP comp cannot be
670 * bypassed. On such conditions we try to bypass atleast YUV layers */
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800671bool MDPComp::tryFullFrame(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800672 hwc_display_contents_1_t* list){
673
Saurabh Shahaa236822013-04-24 18:07:26 -0700674 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Arun Kumar K.R2e2871c2014-01-10 12:47:06 -0800675 int priDispW = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800676
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -0700677 if(sIdleFallBack && !ctx->listStats[mDpy].secureUI) {
Saurabh Shah2d998a92013-05-14 17:55:58 -0700678 ALOGD_IF(isDebug(), "%s: Idle fallback dpy %d",__FUNCTION__, mDpy);
679 return false;
680 }
681
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800682 if(isSkipPresent(ctx, mDpy)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700683 ALOGD_IF(isDebug(),"%s: SKIP present: %d",
684 __FUNCTION__,
685 isSkipPresent(ctx, mDpy));
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800686 return false;
687 }
688
Arun Kumar K.R2e2871c2014-01-10 12:47:06 -0800689 if(mDpy > HWC_DISPLAY_PRIMARY && (priDispW > MAX_DISPLAY_DIM) &&
690 (ctx->dpyAttr[mDpy].xres < MAX_DISPLAY_DIM)) {
691 // Disable MDP comp on Secondary when the primary is highres panel and
692 // the secondary is a normal 1080p, because, MDP comp on secondary under
693 // in such usecase, decimation gets used for downscale and there will be
694 // a quality mismatch when there will be a fallback to GPU comp
695 ALOGD_IF(isDebug(), "%s: Disable MDP Compositon for Secondary Disp",
696 __FUNCTION__);
697 return false;
698 }
699
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800700 // check for action safe flag and downscale mode which requires scaling.
701 if(ctx->dpyAttr[mDpy].mActionSafePresent
702 || ctx->dpyAttr[mDpy].mDownScaleMode) {
703 ALOGD_IF(isDebug(), "%s: Scaling needed for this frame",__FUNCTION__);
704 return false;
705 }
706
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800707 for(int i = 0; i < numAppLayers; ++i) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800708 hwc_layer_1_t* layer = &list->hwLayers[i];
709 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800710
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700711 if(isYuvBuffer(hnd) && has90Transform(layer)) {
712 if(!canUseRotator(ctx, mDpy)) {
713 ALOGD_IF(isDebug(), "%s: Can't use rotator for dpy %d",
714 __FUNCTION__, mDpy);
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700715 return false;
716 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800717 }
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530718
719 //For 8x26 with panel width>1k, if RGB layer needs HFLIP fail mdp comp
720 // may not need it if Gfx pre-rotation can handle all flips & rotations
Sushil Chauhanfda00fc2014-03-20 11:08:41 -0700721 int transform = (layer->flags & HWC_COLOR_FILL) ? 0 : layer->transform;
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530722 if(qdutils::MDPVersion::getInstance().is8x26() &&
723 (ctx->dpyAttr[mDpy].xres > 1024) &&
Sushil Chauhanfda00fc2014-03-20 11:08:41 -0700724 (transform & HWC_TRANSFORM_FLIP_H) &&
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530725 (!isYuvBuffer(hnd)))
726 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800727 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700728
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700729 if(ctx->mAD->isDoable()) {
730 return false;
731 }
732
Saurabh Shahaa236822013-04-24 18:07:26 -0700733 //If all above hard conditions are met we can do full or partial MDP comp.
734 bool ret = false;
735 if(fullMDPComp(ctx, list)) {
736 ret = true;
Sushil Chauhandefd3522014-05-13 18:17:12 -0700737 } else if(fullMDPCompWithPTOR(ctx, list)) {
738 ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700739 } else if(partialMDPComp(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700740 ret = true;
741 }
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530742
Saurabh Shahaa236822013-04-24 18:07:26 -0700743 return ret;
744}
745
746bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaran0ad97c42014-03-09 23:00:53 -0700747
748 if(sSimulationFlags & MDPCOMP_AVOID_FULL_MDP)
749 return false;
750
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700751 //Will benefit presentation / secondary-only layer.
752 if((mDpy > HWC_DISPLAY_PRIMARY) &&
753 (list->numHwLayers - 1) > MAX_SEC_LAYERS) {
754 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
755 return false;
756 }
757
758 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
759 for(int i = 0; i < numAppLayers; i++) {
760 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran880da832014-04-18 10:22:35 -0700761 if(not mCurrentFrame.drop[i] and
762 not isSupportedForMDPComp(ctx, layer)) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700763 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",__FUNCTION__);
764 return false;
765 }
766 }
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800767
Saurabh Shahaa236822013-04-24 18:07:26 -0700768 mCurrentFrame.fbCount = 0;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700769 memcpy(&mCurrentFrame.isFBComposed, &mCurrentFrame.drop,
770 sizeof(mCurrentFrame.isFBComposed));
771 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount -
772 mCurrentFrame.dropCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700773
radhakrishnac9a67412013-09-25 17:40:42 +0530774 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800775 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530776 }
777
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800778 if(!postHeuristicsHandling(ctx, list)) {
779 ALOGD_IF(isDebug(), "post heuristic handling failed");
780 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700781 return false;
782 }
Jeykumar Sankaran0ad97c42014-03-09 23:00:53 -0700783 ALOGD_IF(sSimulationFlags,"%s: FULL_MDP_COMP SUCCEEDED",
784 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700785 return true;
786}
787
Sushil Chauhandefd3522014-05-13 18:17:12 -0700788/* Full MDP Composition with Peripheral Tiny Overlap Removal.
789 * MDP bandwidth limitations can be avoided, if the overlap region
790 * covered by the smallest layer at a higher z-order, gets composed
791 * by Copybit on a render buffer, which can be queued to MDP.
792 */
793bool MDPComp::fullMDPCompWithPTOR(hwc_context_t *ctx,
794 hwc_display_contents_1_t* list) {
795
796 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
797 const int stagesForMDP = min(sMaxPipesPerMixer,
798 ctx->mOverlay->availablePipes(mDpy, Overlay::MIXER_DEFAULT));
799
800 // Hard checks where we cannot use this mode
801 if (mDpy || !ctx->mCopyBit[mDpy] || isDisplaySplit(ctx, mDpy)) {
802 ALOGD_IF(isDebug(), "%s: Feature not supported!", __FUNCTION__);
803 return false;
804 }
805
806 // Frame level checks
807 if ((numAppLayers > stagesForMDP) || isSkipPresent(ctx, mDpy) ||
808 isYuvPresent(ctx, mDpy) || mCurrentFrame.dropCount ||
809 isSecurePresent(ctx, mDpy)) {
810 ALOGD_IF(isDebug(), "%s: Frame not supported!", __FUNCTION__);
811 return false;
812 }
813
814 // Find overlap index
815 int overlapIdx = numAppLayers - 1;
816 uint32_t layerPixelCount, minPixelCount = 0;
817 for (int i = numAppLayers - 1; i >= 0; i--) {
818 hwc_layer_1_t* layer = &list->hwLayers[i];
819 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
820 layerPixelCount = (crop.right - crop.left) * (crop.bottom - crop.top);
821 if (!minPixelCount || (layerPixelCount < minPixelCount)) {
822 minPixelCount = layerPixelCount;
823 overlapIdx = i;
824 }
825 }
826
827 // No overlap
828 if (!overlapIdx)
829 return false;
830
831 /* We cannot use this composition mode, if:
832 1. A below layer needs scaling.
833 2. Overlap is not peripheral to display.
834 3. Overlap or a below layer has 90 degree transform.
835 4. Intersection of Overlap layer with a below layer is not valid.
836 5. Overlap area > (1/3 * FrameBuffer) area, based on Perf inputs.
837 */
838
839 hwc_rect_t overlap = list->hwLayers[overlapIdx].displayFrame;
840 if (!isPeripheral(overlap, ctx->mViewFrame[mDpy]))
841 return false;
842
843 if ((3 * (overlap.right - overlap.left) * (overlap.bottom - overlap.top)) >
844 ((int)ctx->dpyAttr[mDpy].xres * (int)ctx->dpyAttr[mDpy].yres))
845 return false;
846
847 for (int i = overlapIdx; i >= 0; i--) {
848 hwc_layer_1_t* layer = &list->hwLayers[i];
849 hwc_rect_t dispFrame = layer->displayFrame;
850
851 if (has90Transform(layer))
852 return false;
853
854 if (i < overlapIdx) {
855 if (needsScaling(layer) ||
856 !isValidRect(getIntersection(dispFrame, overlap)))
857 return false;
858 }
859 }
860
861 mOverlapIndex = overlapIdx;
862 if (!ctx->mCopyBit[mDpy]->prepareOverlap(ctx, list, overlapIdx)) {
863 ALOGD_IF(isDebug(), "%s: Overlap prepare failed!",__FUNCTION__);
864 mOverlapIndex = -1;
865 return false;
866 }
867
868 hwc_rect_t sourceCrop[overlapIdx];
869 hwc_rect_t displayFrame[overlapIdx];
870
871 // Remove overlap from crop & displayFrame of below layers
872 for (int i = 0; i < overlapIdx; i++) {
873 hwc_layer_1_t* layer = &list->hwLayers[i];
874 displayFrame[i] = layer->displayFrame;
875 sourceCrop[i] = integerizeSourceCrop(layer->sourceCropf);
876
877 // Update layer attributes
878 hwc_rect_t srcCrop = integerizeSourceCrop(layer->sourceCropf);
879 hwc_rect_t destRect = deductRect(layer->displayFrame, overlap);
880 qhwc::calculate_crop_rects(srcCrop, layer->displayFrame, destRect,
881 layer->transform);
882
883 layer->sourceCropf.left = (float)srcCrop.left;
884 layer->sourceCropf.top = (float)srcCrop.top;
885 layer->sourceCropf.right = (float)srcCrop.right;
886 layer->sourceCropf.bottom = (float)srcCrop.bottom;
887 }
888
889 mCurrentFrame.mdpCount = numAppLayers;
890 mCurrentFrame.fbCount = 0;
891 mCurrentFrame.fbZ = -1;
892
893 for (int j = 0; j < numAppLayers; j++)
894 mCurrentFrame.isFBComposed[j] = false;
895
896 bool result = postHeuristicsHandling(ctx, list);
897
898 // Restore layer attributes
899 for (int i = 0; i < overlapIdx; i++) {
900 hwc_layer_1_t* layer = &list->hwLayers[i];
901 layer->displayFrame = displayFrame[i];
902 layer->sourceCropf.left = (float)sourceCrop[i].left;
903 layer->sourceCropf.top = (float)sourceCrop[i].top;
904 layer->sourceCropf.right = (float)sourceCrop[i].right;
905 layer->sourceCropf.bottom = (float)sourceCrop[i].bottom;
906 }
907
908 if (!result) {
909 mOverlapIndex = -1;
910 reset(ctx);
911 }
912
913 ALOGD_IF(isDebug(), "%s: Postheuristics %s!, Overlap index = %d",
914 __FUNCTION__, (result ? "successful" : "failed"), mOverlapIndex);
915 return result;
916}
917
Saurabh Shahaa236822013-04-24 18:07:26 -0700918bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
919{
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700920 if(!sEnableMixedMode) {
921 //Mixed mode is disabled. No need to even try caching.
922 return false;
923 }
924
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700925 bool ret = false;
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800926 if(list->flags & HWC_GEOMETRY_CHANGED) { //Try load based first
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800927 ret = loadBasedComp(ctx, list) or
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800928 cacheBasedComp(ctx, list);
929 } else {
930 ret = cacheBasedComp(ctx, list) or
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800931 loadBasedComp(ctx, list);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700932 }
933
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700934 return ret;
935}
936
937bool MDPComp::cacheBasedComp(hwc_context_t *ctx,
938 hwc_display_contents_1_t* list) {
Jeykumar Sankaran0ad97c42014-03-09 23:00:53 -0700939 if(sSimulationFlags & MDPCOMP_AVOID_CACHE_MDP)
940 return false;
941
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700942 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700943 mCurrentFrame.reset(numAppLayers);
944 updateLayerCache(ctx, list);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700945
946 //If an MDP marked layer is unsupported cannot do partial MDP Comp
947 for(int i = 0; i < numAppLayers; i++) {
948 if(!mCurrentFrame.isFBComposed[i]) {
949 hwc_layer_1_t* layer = &list->hwLayers[i];
950 if(not isSupportedForMDPComp(ctx, layer)) {
951 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",
952 __FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800953 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700954 return false;
955 }
956 }
957 }
958
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700959 updateYUV(ctx, list, false /*secure only*/);
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530960 bool ret = markLayersForCaching(ctx, list); //sets up fbZ also
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700961 if(!ret) {
962 ALOGD_IF(isDebug(),"%s: batching failed, dpy %d",__FUNCTION__, mDpy);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800963 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700964 return false;
965 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700966
967 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700968
radhakrishnac9a67412013-09-25 17:40:42 +0530969 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800970 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530971 }
972
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700973 //Will benefit cases where a video has non-updating background.
974 if((mDpy > HWC_DISPLAY_PRIMARY) and
975 (mdpCount > MAX_SEC_LAYERS)) {
976 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800977 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700978 return false;
979 }
980
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800981 if(!postHeuristicsHandling(ctx, list)) {
982 ALOGD_IF(isDebug(), "post heuristic handling failed");
983 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700984 return false;
985 }
Jeykumar Sankaran0ad97c42014-03-09 23:00:53 -0700986 ALOGD_IF(sSimulationFlags,"%s: CACHE_MDP_COMP SUCCEEDED",
987 __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700988
Saurabh Shahaa236822013-04-24 18:07:26 -0700989 return true;
990}
991
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800992bool MDPComp::loadBasedComp(hwc_context_t *ctx,
Saurabh Shahb772ae32013-11-18 15:40:02 -0800993 hwc_display_contents_1_t* list) {
Jeykumar Sankaran0ad97c42014-03-09 23:00:53 -0700994 if(sSimulationFlags & MDPCOMP_AVOID_LOAD_MDP)
995 return false;
996
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -0800997 if(not isLoadBasedCompDoable(ctx)) {
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800998 return false;
999 }
1000
Saurabh Shahb772ae32013-11-18 15:40:02 -08001001 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahbe7bd322014-02-20 16:18:45 -08001002 const int numNonDroppedLayers = numAppLayers - mCurrentFrame.dropCount;
1003 const int stagesForMDP = min(sMaxPipesPerMixer,
1004 ctx->mOverlay->availablePipes(mDpy, Overlay::MIXER_DEFAULT));
Saurabh Shahf2de00f2013-12-11 17:52:53 -08001005
Saurabh Shahbe7bd322014-02-20 16:18:45 -08001006 int mdpBatchSize = stagesForMDP - 1; //1 stage for FB
1007 int fbBatchSize = numNonDroppedLayers - mdpBatchSize;
1008 int lastMDPSupportedIndex = numAppLayers;
1009 int dropCount = 0;
Saurabh Shahb772ae32013-11-18 15:40:02 -08001010
Saurabh Shahbe7bd322014-02-20 16:18:45 -08001011 //Find the minimum MDP batch size
1012 for(int i = 0; i < numAppLayers;i++) {
1013 if(mCurrentFrame.drop[i]) {
1014 dropCount++;
Jeykumar Sankaran846e2792014-01-23 21:59:58 -08001015 continue;
Saurabh Shahbe7bd322014-02-20 16:18:45 -08001016 }
1017 hwc_layer_1_t* layer = &list->hwLayers[i];
1018 if(not isSupportedForMDPComp(ctx, layer)) {
1019 lastMDPSupportedIndex = i;
1020 mdpBatchSize = min(i - dropCount, stagesForMDP - 1);
1021 fbBatchSize = numNonDroppedLayers - mdpBatchSize;
Jeykumar Sankaran846e2792014-01-23 21:59:58 -08001022 break;
Saurabh Shahb772ae32013-11-18 15:40:02 -08001023 }
Saurabh Shahb772ae32013-11-18 15:40:02 -08001024 }
1025
Saurabh Shahbe7bd322014-02-20 16:18:45 -08001026 ALOGD_IF(isDebug(), "%s:Before optimizing fbBatch, mdpbatch %d, fbbatch %d "
1027 "dropped %d", __FUNCTION__, mdpBatchSize, fbBatchSize,
1028 mCurrentFrame.dropCount);
1029
1030 //Start at a point where the fb batch should at least have 2 layers, for
1031 //this mode to be justified.
1032 while(fbBatchSize < 2) {
1033 ++fbBatchSize;
1034 --mdpBatchSize;
Jeykumar Sankaran846e2792014-01-23 21:59:58 -08001035 }
Saurabh Shahb772ae32013-11-18 15:40:02 -08001036
Saurabh Shahbe7bd322014-02-20 16:18:45 -08001037 //If there are no layers for MDP, this mode doesnt make sense.
1038 if(mdpBatchSize < 1) {
1039 ALOGD_IF(isDebug(), "%s: No MDP layers after optimizing for fbBatch",
1040 __FUNCTION__);
Saurabh Shahb772ae32013-11-18 15:40:02 -08001041 return false;
1042 }
1043
Saurabh Shahbe7bd322014-02-20 16:18:45 -08001044 mCurrentFrame.reset(numAppLayers);
1045
1046 //Try with successively smaller mdp batch sizes until we succeed or reach 1
1047 while(mdpBatchSize > 0) {
1048 //Mark layers for MDP comp
1049 int mdpBatchLeft = mdpBatchSize;
1050 for(int i = 0; i < lastMDPSupportedIndex and mdpBatchLeft; i++) {
1051 if(mCurrentFrame.drop[i]) {
1052 continue;
1053 }
1054 mCurrentFrame.isFBComposed[i] = false;
1055 --mdpBatchLeft;
1056 }
1057
1058 mCurrentFrame.fbZ = mdpBatchSize;
1059 mCurrentFrame.fbCount = fbBatchSize;
1060 mCurrentFrame.mdpCount = mdpBatchSize;
1061
1062 ALOGD_IF(isDebug(), "%s:Trying with: mdpbatch %d fbbatch %d dropped %d",
1063 __FUNCTION__, mdpBatchSize, fbBatchSize,
1064 mCurrentFrame.dropCount);
1065
1066 if(postHeuristicsHandling(ctx, list)) {
1067 ALOGD_IF(isDebug(), "%s: Postheuristics handling succeeded",
Jeykumar Sankaran0ad97c42014-03-09 23:00:53 -07001068 __FUNCTION__);
1069 ALOGD_IF(sSimulationFlags,"%s: LOAD_MDP_COMP SUCCEEDED",
1070 __FUNCTION__);
Saurabh Shahbe7bd322014-02-20 16:18:45 -08001071 return true;
1072 }
1073
1074 reset(ctx);
1075 --mdpBatchSize;
1076 ++fbBatchSize;
1077 }
1078
1079 return false;
Saurabh Shahb772ae32013-11-18 15:40:02 -08001080}
1081
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001082bool MDPComp::isLoadBasedCompDoable(hwc_context_t *ctx) {
Prabhanjan Kandula3dbbd882013-12-11 14:43:46 +05301083 if(mDpy or isSecurePresent(ctx, mDpy) or
1084 isYuvPresent(ctx, mDpy)) {
Saurabh Shah8028e3b2013-10-15 12:27:59 -07001085 return false;
1086 }
1087 return true;
1088}
1089
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001090bool MDPComp::canPartialUpdate(hwc_context_t *ctx,
1091 hwc_display_contents_1_t* list){
1092 if(!qdutils::MDPVersion::getInstance().isPartialUpdateEnabled() ||
1093 isSkipPresent(ctx, mDpy) || (list->flags & HWC_GEOMETRY_CHANGED) ||
1094 mDpy ) {
1095 return false;
1096 }
1097 return true;
1098}
1099
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001100bool MDPComp::tryVideoOnly(hwc_context_t *ctx,
1101 hwc_display_contents_1_t* list) {
1102 const bool secureOnly = true;
1103 return videoOnlyComp(ctx, list, not secureOnly) or
1104 videoOnlyComp(ctx, list, secureOnly);
1105}
1106
1107bool MDPComp::videoOnlyComp(hwc_context_t *ctx,
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001108 hwc_display_contents_1_t* list, bool secureOnly) {
Jeykumar Sankaran0ad97c42014-03-09 23:00:53 -07001109 if(sSimulationFlags & MDPCOMP_AVOID_VIDEO_ONLY)
1110 return false;
Saurabh Shahaa236822013-04-24 18:07:26 -07001111 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001112
Saurabh Shahaa236822013-04-24 18:07:26 -07001113 mCurrentFrame.reset(numAppLayers);
Jeykumar Sankaraneb3a5e22014-04-08 16:07:55 -07001114 mCurrentFrame.fbCount -= mCurrentFrame.dropCount;
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001115 updateYUV(ctx, list, secureOnly);
Saurabh Shah4fdde762013-04-30 18:47:33 -07001116 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001117
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001118 if(!isYuvPresent(ctx, mDpy) or (mdpCount == 0)) {
1119 reset(ctx);
Saurabh Shahaa236822013-04-24 18:07:26 -07001120 return false;
1121 }
1122
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -08001123 /* Bail out if we are processing only secured video layers
1124 * and we dont have any */
1125 if(!isSecurePresent(ctx, mDpy) && secureOnly){
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001126 reset(ctx);
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -08001127 return false;
1128 }
1129
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001130 if(mCurrentFrame.fbCount)
1131 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
Saurabh Shah4fdde762013-04-30 18:47:33 -07001132
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001133 if(sEnable4k2kYUVSplit){
1134 adjustForSourceSplit(ctx, list);
1135 }
1136
1137 if(!postHeuristicsHandling(ctx, list)) {
1138 ALOGD_IF(isDebug(), "post heuristic handling failed");
1139 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001140 return false;
1141 }
1142
Jeykumar Sankaran0ad97c42014-03-09 23:00:53 -07001143 ALOGD_IF(sSimulationFlags,"%s: VIDEO_ONLY_COMP SUCCEEDED",
1144 __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001145 return true;
1146}
1147
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001148/* Checks for conditions where YUV layers cannot be bypassed */
1149bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -07001150 if(isSkipLayer(layer)) {
Saurabh Shahe2474082013-05-15 16:32:13 -07001151 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001152 return false;
1153 }
1154
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -07001155 if(layer->transform & HWC_TRANSFORM_ROT_90 && !canUseRotator(ctx,mDpy)) {
1156 ALOGD_IF(isDebug(), "%s: no free DMA pipe",__FUNCTION__);
1157 return false;
1158 }
1159
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001160 if(isSecuring(ctx, layer)) {
1161 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
1162 return false;
1163 }
1164
Saurabh Shah4fdde762013-04-30 18:47:33 -07001165 if(!isValidDimension(ctx, layer)) {
1166 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
1167 __FUNCTION__);
1168 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001169 }
Saurabh Shah4fdde762013-04-30 18:47:33 -07001170
Naseer Ahmeddc61a972013-07-10 17:50:54 -04001171 if(layer->planeAlpha < 0xFF) {
1172 ALOGD_IF(isDebug(), "%s: Cannot handle YUV layer with plane alpha\
1173 in video only mode",
1174 __FUNCTION__);
1175 return false;
1176 }
1177
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001178 return true;
1179}
1180
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301181/* starts at fromIndex and check for each layer to find
1182 * if it it has overlapping with any Updating layer above it in zorder
1183 * till the end of the batch. returns true if it finds any intersection */
1184bool MDPComp::canPushBatchToTop(const hwc_display_contents_1_t* list,
1185 int fromIndex, int toIndex) {
1186 for(int i = fromIndex; i < toIndex; i++) {
1187 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
1188 if(intersectingUpdatingLayers(list, i+1, toIndex, i)) {
1189 return false;
1190 }
1191 }
1192 }
1193 return true;
1194}
1195
1196/* Checks if given layer at targetLayerIndex has any
1197 * intersection with all the updating layers in beween
1198 * fromIndex and toIndex. Returns true if it finds intersectiion */
1199bool MDPComp::intersectingUpdatingLayers(const hwc_display_contents_1_t* list,
1200 int fromIndex, int toIndex, int targetLayerIndex) {
1201 for(int i = fromIndex; i <= toIndex; i++) {
1202 if(!mCurrentFrame.isFBComposed[i]) {
1203 if(areLayersIntersecting(&list->hwLayers[i],
1204 &list->hwLayers[targetLayerIndex])) {
1205 return true;
1206 }
1207 }
1208 }
1209 return false;
1210}
1211
1212int MDPComp::getBatch(hwc_display_contents_1_t* list,
1213 int& maxBatchStart, int& maxBatchEnd,
1214 int& maxBatchCount) {
1215 int i = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301216 int fbZOrder =-1;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -08001217 int droppedLayerCt = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301218 while (i < mCurrentFrame.layerCount) {
1219 int batchCount = 0;
1220 int batchStart = i;
1221 int batchEnd = i;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -08001222 /* Adjust batch Z order with the dropped layers so far */
1223 int fbZ = batchStart - droppedLayerCt;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301224 int firstZReverseIndex = -1;
Prabhanjan Kandula0ed2cc92013-12-06 12:39:04 +05301225 int updatingLayersAbove = 0;//Updating layer count in middle of batch
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301226 while(i < mCurrentFrame.layerCount) {
1227 if(!mCurrentFrame.isFBComposed[i]) {
1228 if(!batchCount) {
1229 i++;
1230 break;
1231 }
1232 updatingLayersAbove++;
1233 i++;
1234 continue;
1235 } else {
1236 if(mCurrentFrame.drop[i]) {
1237 i++;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -08001238 droppedLayerCt++;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301239 continue;
1240 } else if(updatingLayersAbove <= 0) {
1241 batchCount++;
1242 batchEnd = i;
1243 i++;
1244 continue;
1245 } else { //Layer is FBComposed, not a drop & updatingLayer > 0
1246
1247 // We have a valid updating layer already. If layer-i not
1248 // have overlapping with all updating layers in between
1249 // batch-start and i, then we can add layer i to batch.
1250 if(!intersectingUpdatingLayers(list, batchStart, i-1, i)) {
1251 batchCount++;
1252 batchEnd = i;
1253 i++;
1254 continue;
1255 } else if(canPushBatchToTop(list, batchStart, i)) {
1256 //If All the non-updating layers with in this batch
1257 //does not have intersection with the updating layers
1258 //above in z-order, then we can safely move the batch to
1259 //higher z-order. Increment fbZ as it is moving up.
1260 if( firstZReverseIndex < 0) {
1261 firstZReverseIndex = i;
1262 }
1263 batchCount++;
1264 batchEnd = i;
1265 fbZ += updatingLayersAbove;
1266 i++;
1267 updatingLayersAbove = 0;
1268 continue;
1269 } else {
1270 //both failed.start the loop again from here.
1271 if(firstZReverseIndex >= 0) {
1272 i = firstZReverseIndex;
1273 }
1274 break;
1275 }
1276 }
1277 }
1278 }
1279 if(batchCount > maxBatchCount) {
1280 maxBatchCount = batchCount;
1281 maxBatchStart = batchStart;
1282 maxBatchEnd = batchEnd;
1283 fbZOrder = fbZ;
1284 }
1285 }
1286 return fbZOrder;
1287}
1288
1289bool MDPComp::markLayersForCaching(hwc_context_t* ctx,
1290 hwc_display_contents_1_t* list) {
1291 /* Idea is to keep as many non-updating(cached) layers in FB and
1292 * send rest of them through MDP. This is done in 2 steps.
1293 * 1. Find the maximum contiguous batch of non-updating layers.
1294 * 2. See if we can improve this batch size for caching by adding
1295 * opaque layers around the batch, if they don't have
1296 * any overlapping with the updating layers in between.
1297 * NEVER mark an updating layer for caching.
1298 * But cached ones can be marked for MDP */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001299
1300 int maxBatchStart = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001301 int maxBatchEnd = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001302 int maxBatchCount = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301303 int fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001304
Saurabh Shahd53bc5f2014-02-05 10:17:43 -08001305 /* Nothing is cached. No batching needed */
1306 if(mCurrentFrame.fbCount == 0) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001307 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -07001308 }
Saurabh Shahd53bc5f2014-02-05 10:17:43 -08001309
1310 /* No MDP comp layers, try to use other comp modes */
1311 if(mCurrentFrame.mdpCount == 0) {
1312 return false;
Saurabh Shahaa236822013-04-24 18:07:26 -07001313 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001314
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301315 fbZ = getBatch(list, maxBatchStart, maxBatchEnd, maxBatchCount);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001316
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301317 /* reset rest of the layers lying inside ROI for MDP comp */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001318 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001319 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001320 if((i < maxBatchStart || i > maxBatchEnd) &&
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301321 mCurrentFrame.isFBComposed[i]){
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001322 if(!mCurrentFrame.drop[i]){
1323 //If an unsupported layer is being attempted to
1324 //be pulled out we should fail
1325 if(not isSupportedForMDPComp(ctx, layer)) {
1326 return false;
1327 }
1328 mCurrentFrame.isFBComposed[i] = false;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001329 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001330 }
1331 }
1332
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301333 // update the frame data
1334 mCurrentFrame.fbZ = fbZ;
1335 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001336 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001337 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001338
1339 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301340 mCurrentFrame.fbCount);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001341
1342 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001343}
Saurabh Shah85234ec2013-04-12 17:09:00 -07001344
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001345void MDPComp::updateLayerCache(hwc_context_t* ctx,
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001346 hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001347 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001348 int fbCount = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001349
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001350 for(int i = 0; i < numAppLayers; i++) {
1351 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001352 if(!mCurrentFrame.drop[i])
1353 fbCount++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001354 mCurrentFrame.isFBComposed[i] = true;
1355 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -07001356 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001357 }
1358 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001359
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001360 mCurrentFrame.fbCount = fbCount;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001361 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount
1362 - mCurrentFrame.dropCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001363
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001364 ALOGD_IF(isDebug(),"%s: MDP count: %d FB count %d drop count: %d"
1365 ,__FUNCTION__, mCurrentFrame.mdpCount, mCurrentFrame.fbCount,
1366 mCurrentFrame.dropCount);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001367}
1368
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001369void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list,
1370 bool secureOnly) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001371 int nYuvCount = ctx->listStats[mDpy].yuvCount;
1372 for(int index = 0;index < nYuvCount; index++){
1373 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
1374 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
1375
1376 if(!isYUVDoable(ctx, layer)) {
1377 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
1378 mCurrentFrame.isFBComposed[nYuvIndex] = true;
1379 mCurrentFrame.fbCount++;
1380 }
1381 } else {
1382 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001383 private_handle_t *hnd = (private_handle_t *)layer->handle;
1384 if(!secureOnly || isSecureBuffer(hnd)) {
1385 mCurrentFrame.isFBComposed[nYuvIndex] = false;
1386 mCurrentFrame.fbCount--;
1387 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001388 }
1389 }
1390 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001391
1392 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001393 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
1394 ALOGD_IF(isDebug(),"%s: fb count: %d",__FUNCTION__,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001395 mCurrentFrame.fbCount);
1396}
1397
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001398hwc_rect_t MDPComp::getUpdatingFBRect(hwc_context_t *ctx,
1399 hwc_display_contents_1_t* list){
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001400 hwc_rect_t fbRect = (struct hwc_rect){0, 0, 0, 0};
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001401
1402 /* Update only the region of FB needed for composition */
1403 for(int i = 0; i < mCurrentFrame.layerCount; i++ ) {
1404 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
1405 hwc_layer_1_t* layer = &list->hwLayers[i];
1406 hwc_rect_t dst = layer->displayFrame;
1407 fbRect = getUnion(fbRect, dst);
1408 }
1409 }
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001410 trimAgainstROI(ctx, fbRect);
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001411 return fbRect;
1412}
1413
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001414bool MDPComp::postHeuristicsHandling(hwc_context_t *ctx,
1415 hwc_display_contents_1_t* list) {
1416
1417 //Capability checks
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301418 if(!resourceCheck()) {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001419 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
1420 return false;
1421 }
1422
1423 //Limitations checks
1424 if(!hwLimitationsCheck(ctx, list)) {
1425 ALOGD_IF(isDebug(), "%s: HW limitations",__FUNCTION__);
1426 return false;
1427 }
1428
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001429 //Configure framebuffer first if applicable
1430 if(mCurrentFrame.fbZ >= 0) {
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001431 hwc_rect_t fbRect = getUpdatingFBRect(ctx, list);
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001432 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, fbRect, mCurrentFrame.fbZ))
1433 {
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001434 ALOGD_IF(isDebug(), "%s configure framebuffer failed",
1435 __FUNCTION__);
1436 return false;
1437 }
1438 }
1439
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001440 mCurrentFrame.map();
1441
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001442 if(!allocLayerPipes(ctx, list)) {
1443 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -07001444 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001445 }
1446
1447 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001448 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001449 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001450 int mdpIndex = mCurrentFrame.layerToMDP[index];
1451 hwc_layer_1_t* layer = &list->hwLayers[index];
1452
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301453 //Leave fbZ for framebuffer. CACHE/GLES layers go here.
1454 if(mdpNextZOrder == mCurrentFrame.fbZ) {
1455 mdpNextZOrder++;
1456 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001457 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1458 cur_pipe->zOrder = mdpNextZOrder++;
1459
radhakrishnac9a67412013-09-25 17:40:42 +05301460 private_handle_t *hnd = (private_handle_t *)layer->handle;
1461 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1462 if(configure4k2kYuv(ctx, layer,
1463 mCurrentFrame.mdpToLayer[mdpIndex])
1464 != 0 ){
1465 ALOGD_IF(isDebug(), "%s: Failed to configure split pipes \
1466 for layer %d",__FUNCTION__, index);
1467 return false;
1468 }
1469 else{
1470 mdpNextZOrder++;
1471 }
1472 continue;
1473 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001474 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
1475 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
radhakrishnac9a67412013-09-25 17:40:42 +05301476 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -07001477 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001478 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001479 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001480 }
1481
Saurabh Shaha36be922013-12-16 18:18:39 -08001482 if(!ctx->mOverlay->validateAndSet(mDpy, ctx->dpyAttr[mDpy].fd)) {
1483 ALOGD_IF(isDebug(), "%s: Failed to validate and set overlay for dpy %d"
1484 ,__FUNCTION__, mDpy);
1485 return false;
1486 }
1487
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001488 setRedraw(ctx, list);
Saurabh Shahaa236822013-04-24 18:07:26 -07001489 return true;
1490}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001491
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301492bool MDPComp::resourceCheck() {
Saurabh Shah173f4242013-11-20 09:50:12 -08001493 const bool fbUsed = mCurrentFrame.fbCount;
1494 if(mCurrentFrame.mdpCount > sMaxPipesPerMixer - fbUsed) {
1495 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
1496 return false;
1497 }
Saurabh Shah173f4242013-11-20 09:50:12 -08001498 return true;
1499}
1500
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301501bool MDPComp::hwLimitationsCheck(hwc_context_t* ctx,
1502 hwc_display_contents_1_t* list) {
1503
1504 //A-family hw limitation:
1505 //If a layer need alpha scaling, MDP can not support.
1506 if(ctx->mMDP.version < qdutils::MDSS_V5) {
1507 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1508 if(!mCurrentFrame.isFBComposed[i] &&
1509 isAlphaScaled( &list->hwLayers[i])) {
1510 ALOGD_IF(isDebug(), "%s:frame needs alphaScaling",__FUNCTION__);
1511 return false;
1512 }
1513 }
1514 }
1515
1516 // On 8x26 & 8974 hw, we have a limitation of downscaling+blending.
1517 //If multiple layers requires downscaling and also they are overlapping
1518 //fall back to GPU since MDSS can not handle it.
1519 if(qdutils::MDPVersion::getInstance().is8x74v2() ||
1520 qdutils::MDPVersion::getInstance().is8x26()) {
1521 for(int i = 0; i < mCurrentFrame.layerCount-1; ++i) {
1522 hwc_layer_1_t* botLayer = &list->hwLayers[i];
1523 if(!mCurrentFrame.isFBComposed[i] &&
1524 isDownscaleRequired(botLayer)) {
1525 //if layer-i is marked for MDP and needs downscaling
1526 //check if any MDP layer on top of i & overlaps with layer-i
1527 for(int j = i+1; j < mCurrentFrame.layerCount; ++j) {
1528 hwc_layer_1_t* topLayer = &list->hwLayers[j];
1529 if(!mCurrentFrame.isFBComposed[j] &&
1530 isDownscaleRequired(topLayer)) {
1531 hwc_rect_t r = getIntersection(botLayer->displayFrame,
1532 topLayer->displayFrame);
1533 if(isValidRect(r))
1534 return false;
1535 }
1536 }
1537 }
1538 }
1539 }
1540 return true;
1541}
1542
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001543int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001544 int ret = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -07001545 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran0ad97c42014-03-09 23:00:53 -07001546 char property[PROPERTY_VALUE_MAX];
1547
1548 if(property_get("debug.hwc.simulate", property, NULL) > 0) {
1549 int currentFlags = atoi(property);
1550 if(currentFlags != sSimulationFlags) {
1551 sSimulationFlags = currentFlags;
1552 ALOGE("%s: Simulation Flag read: 0x%x (%d)", __FUNCTION__,
1553 sSimulationFlags, sSimulationFlags);
1554 }
1555 }
Sushil Chauhandefd3522014-05-13 18:17:12 -07001556 mOverlapIndex = -1;
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -07001557
Raj Kamal9ed3d6b2014-02-07 16:15:17 +05301558 //Do not cache the information for next draw cycle.
1559 if(numLayers > MAX_NUM_APP_LAYERS or (!numLayers)) {
1560 ALOGI("%s: Unsupported layer count for mdp composition",
1561 __FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001562 mCachedFrame.reset();
1563 return -1;
1564 }
1565
Saurabh Shahb39f8152013-08-22 10:21:44 -07001566 //reset old data
1567 mCurrentFrame.reset(numLayers);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001568 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1569 mCurrentFrame.dropCount = 0;
Prabhanjan Kandula088bd892013-07-02 23:47:13 +05301570
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -07001571 // Detect the start of animation and fall back to GPU only once to cache
1572 // all the layers in FB and display FB content untill animation completes.
1573 if(ctx->listStats[mDpy].isDisplayAnimating) {
1574 mCurrentFrame.needsRedraw = false;
1575 if(ctx->mAnimationState[mDpy] == ANIMATION_STOPPED) {
1576 mCurrentFrame.needsRedraw = true;
1577 ctx->mAnimationState[mDpy] = ANIMATION_STARTED;
1578 }
1579 setMDPCompLayerFlags(ctx, list);
1580 mCachedFrame.updateCounts(mCurrentFrame);
1581 ret = -1;
1582 return ret;
1583 } else {
1584 ctx->mAnimationState[mDpy] = ANIMATION_STOPPED;
1585 }
1586
Saurabh Shahb39f8152013-08-22 10:21:44 -07001587 //Hard conditions, if not met, cannot do MDP comp
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001588 if(isFrameDoable(ctx)) {
1589 generateROI(ctx, list);
Saurabh Shahb39f8152013-08-22 10:21:44 -07001590
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001591 if(tryFullFrame(ctx, list) || tryVideoOnly(ctx, list)) {
1592 setMDPCompLayerFlags(ctx, list);
1593 } else {
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001594 resetROI(ctx, mDpy);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001595 reset(ctx);
1596 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1597 mCurrentFrame.dropCount = 0;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001598 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001599 }
1600 } else {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001601 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
1602 __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001603 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001604 }
Saurabh Shahb39f8152013-08-22 10:21:44 -07001605
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001606 if(isDebug()) {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001607 ALOGD("GEOMETRY change: %d",
1608 (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001609 android::String8 sDump("");
Jeykumar Sankaran6850ac62014-05-27 10:07:26 -07001610 dump(sDump, ctx);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001611 ALOGD("%s",sDump.string());
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001612 }
1613
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001614 mCachedFrame.cacheAll(list);
1615 mCachedFrame.updateCounts(mCurrentFrame);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001616 return ret;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001617}
1618
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001619bool MDPComp::allocSplitVGPipesfor4k2k(hwc_context_t *ctx, int index) {
radhakrishnac9a67412013-09-25 17:40:42 +05301620
1621 bool bRet = true;
radhakrishnac9a67412013-09-25 17:40:42 +05301622 int mdpIndex = mCurrentFrame.layerToMDP[index];
1623 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
1624 info.pipeInfo = new MdpYUVPipeInfo;
1625 info.rot = NULL;
1626 MdpYUVPipeInfo& pipe_info = *(MdpYUVPipeInfo*)info.pipeInfo;
radhakrishnac9a67412013-09-25 17:40:42 +05301627
1628 pipe_info.lIndex = ovutils::OV_INVALID;
1629 pipe_info.rIndex = ovutils::OV_INVALID;
1630
Saurabh Shahc62f3982014-03-05 14:28:26 -08001631 Overlay::PipeSpecs pipeSpecs;
1632 pipeSpecs.formatClass = Overlay::FORMAT_YUV;
1633 pipeSpecs.needsScaling = true;
1634 pipeSpecs.dpy = mDpy;
1635 pipeSpecs.fb = false;
1636
1637 pipe_info.lIndex = ctx->mOverlay->getPipe(pipeSpecs);
radhakrishnac9a67412013-09-25 17:40:42 +05301638 if(pipe_info.lIndex == ovutils::OV_INVALID){
1639 bRet = false;
1640 ALOGD_IF(isDebug(),"%s: allocating first VG pipe failed",
1641 __FUNCTION__);
1642 }
Saurabh Shahc62f3982014-03-05 14:28:26 -08001643 pipe_info.rIndex = ctx->mOverlay->getPipe(pipeSpecs);
radhakrishnac9a67412013-09-25 17:40:42 +05301644 if(pipe_info.rIndex == ovutils::OV_INVALID){
1645 bRet = false;
1646 ALOGD_IF(isDebug(),"%s: allocating second VG pipe failed",
1647 __FUNCTION__);
1648 }
1649 return bRet;
1650}
Sushil Chauhandefd3522014-05-13 18:17:12 -07001651
1652int MDPComp::drawOverlap(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
1653 int fd = -1;
1654 if (mOverlapIndex != -1) {
1655 fd = ctx->mCopyBit[mDpy]->drawOverlap(ctx, list, mOverlapIndex);
1656 if (fd < 0) {
1657 ALOGD_IF(isDebug(),"%s: failed", __FUNCTION__);
1658 mOverlapIndex = -1;
1659 }
1660 }
1661 return fd;
1662}
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001663//=============MDPCompNonSplit==================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001664
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001665void MDPCompNonSplit::adjustForSourceSplit(hwc_context_t *ctx,
Dileep Kumar Reddi190dc1c2014-05-22 22:24:53 +05301666 hwc_display_contents_1_t* list) {
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001667 //If 4k2k Yuv layer split is possible, and if
1668 //fbz is above 4k2k layer, increment fb zorder by 1
1669 //as we split 4k2k layer and increment zorder for right half
1670 //of the layer
1671 if(mCurrentFrame.fbZ >= 0) {
Dileep Kumar Reddi190dc1c2014-05-22 22:24:53 +05301672 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
1673 index++) {
1674 if(!mCurrentFrame.isFBComposed[index]) {
1675 if(mdpNextZOrder == mCurrentFrame.fbZ) {
1676 mdpNextZOrder++;
1677 }
1678 mdpNextZOrder++;
1679 hwc_layer_1_t* layer = &list->hwLayers[index];
1680 private_handle_t *hnd = (private_handle_t *)layer->handle;
1681 if(is4kx2kYuvBuffer(hnd)) {
1682 if(mdpNextZOrder <= mCurrentFrame.fbZ)
1683 mCurrentFrame.fbZ += 1;
1684 mdpNextZOrder++;
1685 //As we split 4kx2k yuv layer and program to 2 VG pipes
1686 //(if available) increase mdpcount by 1.
1687 mCurrentFrame.mdpCount++;
1688 }
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001689 }
1690 }
1691 }
radhakrishnac9a67412013-09-25 17:40:42 +05301692}
1693
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001694/*
1695 * Configures pipe(s) for MDP composition
1696 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001697int MDPCompNonSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001698 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001699 MdpPipeInfoNonSplit& mdp_info =
1700 *(static_cast<MdpPipeInfoNonSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001701 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
1702 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1703 eIsFg isFg = IS_FG_OFF;
1704 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001705
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001706 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
1707 __FUNCTION__, layer, zOrder, dest);
1708
Saurabh Shah88e4d272013-09-03 13:31:29 -07001709 return configureNonSplit(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001710 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001711}
1712
Saurabh Shah88e4d272013-09-03 13:31:29 -07001713bool MDPCompNonSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001714 hwc_display_contents_1_t* list) {
1715 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001716
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001717 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001718
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001719 hwc_layer_1_t* layer = &list->hwLayers[index];
1720 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301721 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001722 if(allocSplitVGPipesfor4k2k(ctx, index)){
radhakrishnac9a67412013-09-25 17:40:42 +05301723 continue;
1724 }
1725 }
1726
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001727 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001728 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001729 info.pipeInfo = new MdpPipeInfoNonSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08001730 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001731 MdpPipeInfoNonSplit& pipe_info = *(MdpPipeInfoNonSplit*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001732
Saurabh Shahc62f3982014-03-05 14:28:26 -08001733 Overlay::PipeSpecs pipeSpecs;
1734 pipeSpecs.formatClass = isYuvBuffer(hnd) ?
1735 Overlay::FORMAT_YUV : Overlay::FORMAT_RGB;
1736 pipeSpecs.needsScaling = qhwc::needsScaling(layer) or
1737 (qdutils::MDPVersion::getInstance().is8x26() and
1738 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres > 1024);
1739 pipeSpecs.dpy = mDpy;
1740 pipeSpecs.fb = false;
Xu Yang1e686f62014-04-08 13:56:47 +08001741 pipeSpecs.numActiveDisplays = ctx->numActiveDisplays;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001742
Saurabh Shahc62f3982014-03-05 14:28:26 -08001743 pipe_info.index = ctx->mOverlay->getPipe(pipeSpecs);
1744
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001745 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001746 ALOGD_IF(isDebug(), "%s: Unable to get pipe", __FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001747 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001748 }
1749 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001750 return true;
1751}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001752
radhakrishnac9a67412013-09-25 17:40:42 +05301753int MDPCompNonSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1754 PipeLayerPair& PipeLayerPair) {
1755 MdpYUVPipeInfo& mdp_info =
1756 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1757 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1758 eIsFg isFg = IS_FG_OFF;
1759 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1760 eDest lDest = mdp_info.lIndex;
1761 eDest rDest = mdp_info.rIndex;
1762
1763 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1764 lDest, rDest, &PipeLayerPair.rot);
1765}
1766
Saurabh Shah88e4d272013-09-03 13:31:29 -07001767bool MDPCompNonSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001768
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001769 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001770 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1771 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -08001772 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001773
1774 if(!ctx || !list) {
1775 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001776 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001777 }
1778
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301779 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1780 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1781 return true;
1782 }
1783
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -08001784 // Set the Handle timeout to true for MDP or MIXED composition.
1785 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount) {
1786 sHandleTimeout = true;
1787 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001788
1789 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001790 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001791
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001792 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1793 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001794 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001795 if(mCurrentFrame.isFBComposed[i]) continue;
1796
Naseer Ahmed5b6708a2012-08-02 13:46:08 -07001797 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001798 private_handle_t *hnd = (private_handle_t *)layer->handle;
1799 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001800 if (!(layer->flags & HWC_COLOR_FILL)) {
1801 ALOGE("%s handle null", __FUNCTION__);
1802 return false;
1803 }
1804 // No PLAY for Color layer
1805 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1806 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001807 }
1808
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001809 int mdpIndex = mCurrentFrame.layerToMDP[i];
1810
radhakrishnac9a67412013-09-25 17:40:42 +05301811 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1812 {
1813 MdpYUVPipeInfo& pipe_info =
1814 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1815 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1816 ovutils::eDest indexL = pipe_info.lIndex;
1817 ovutils::eDest indexR = pipe_info.rIndex;
1818 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301819 uint32_t offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05301820 if(rot) {
1821 rot->queueBuffer(fd, offset);
1822 fd = rot->getDstMemId();
1823 offset = rot->getDstOffset();
1824 }
1825 if(indexL != ovutils::OV_INVALID) {
1826 ovutils::eDest destL = (ovutils::eDest)indexL;
1827 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1828 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1829 if (!ov.queueBuffer(fd, offset, destL)) {
1830 ALOGE("%s: queueBuffer failed for display:%d",
1831 __FUNCTION__, mDpy);
1832 return false;
1833 }
1834 }
1835
1836 if(indexR != ovutils::OV_INVALID) {
1837 ovutils::eDest destR = (ovutils::eDest)indexR;
1838 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1839 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1840 if (!ov.queueBuffer(fd, offset, destR)) {
1841 ALOGE("%s: queueBuffer failed for display:%d",
1842 __FUNCTION__, mDpy);
1843 return false;
1844 }
1845 }
1846 }
1847 else{
1848 MdpPipeInfoNonSplit& pipe_info =
Saurabh Shah88e4d272013-09-03 13:31:29 -07001849 *(MdpPipeInfoNonSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
radhakrishnac9a67412013-09-25 17:40:42 +05301850 ovutils::eDest dest = pipe_info.index;
1851 if(dest == ovutils::OV_INVALID) {
1852 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001853 return false;
radhakrishnac9a67412013-09-25 17:40:42 +05301854 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001855
radhakrishnac9a67412013-09-25 17:40:42 +05301856 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1857 continue;
1858 }
1859
Sushil Chauhandefd3522014-05-13 18:17:12 -07001860 if (!mDpy && (i == mOverlapIndex)) {
1861 hnd = ctx->mCopyBit[mDpy]->getCurrentRenderBuffer();
1862 }
1863
radhakrishnac9a67412013-09-25 17:40:42 +05301864 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1865 using pipe: %d", __FUNCTION__, layer,
1866 hnd, dest );
1867
1868 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301869 uint32_t offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05301870
1871 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1872 if(rot) {
1873 if(!rot->queueBuffer(fd, offset))
1874 return false;
1875 fd = rot->getDstMemId();
1876 offset = rot->getDstOffset();
1877 }
1878
1879 if (!ov.queueBuffer(fd, offset, dest)) {
1880 ALOGE("%s: queueBuffer failed for display:%d ",
1881 __FUNCTION__, mDpy);
1882 return false;
1883 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001884 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001885
1886 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001887 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001888 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001889}
1890
Saurabh Shah88e4d272013-09-03 13:31:29 -07001891//=============MDPCompSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001892
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001893void MDPCompSplit::adjustForSourceSplit(hwc_context_t *ctx,
radhakrishnac9a67412013-09-25 17:40:42 +05301894 hwc_display_contents_1_t* list){
1895 //if 4kx2k yuv layer is totally present in either in left half
1896 //or right half then try splitting the yuv layer to avoid decimation
radhakrishnac9a67412013-09-25 17:40:42 +05301897 const int lSplit = getLeftSplit(ctx, mDpy);
Dileep Kumar Reddi190dc1c2014-05-22 22:24:53 +05301898 if(mCurrentFrame.fbZ >= 0) {
1899 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
1900 index++) {
1901 if(!mCurrentFrame.isFBComposed[index]) {
1902 if(mdpNextZOrder == mCurrentFrame.fbZ) {
1903 mdpNextZOrder++;
1904 }
1905 mdpNextZOrder++;
1906 hwc_layer_1_t* layer = &list->hwLayers[index];
1907 private_handle_t *hnd = (private_handle_t *)layer->handle;
1908 if(is4kx2kYuvBuffer(hnd)) {
1909 hwc_rect_t dst = layer->displayFrame;
1910 if((dst.left > lSplit) || (dst.right < lSplit)) {
1911 mCurrentFrame.mdpCount += 1;
1912 }
1913 if(mdpNextZOrder <= mCurrentFrame.fbZ)
1914 mCurrentFrame.fbZ += 1;
1915 mdpNextZOrder++;
1916 }
1917 }
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001918 }
radhakrishnac9a67412013-09-25 17:40:42 +05301919 }
1920}
1921
Saurabh Shah88e4d272013-09-03 13:31:29 -07001922bool MDPCompSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Saurabh Shahc62f3982014-03-05 14:28:26 -08001923 MdpPipeInfoSplit& pipe_info) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001924
Saurabh Shahc62f3982014-03-05 14:28:26 -08001925 const int lSplit = getLeftSplit(ctx, mDpy);
1926 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001927 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001928 pipe_info.lIndex = ovutils::OV_INVALID;
1929 pipe_info.rIndex = ovutils::OV_INVALID;
1930
Saurabh Shahc62f3982014-03-05 14:28:26 -08001931 Overlay::PipeSpecs pipeSpecs;
1932 pipeSpecs.formatClass = isYuvBuffer(hnd) ?
1933 Overlay::FORMAT_YUV : Overlay::FORMAT_RGB;
1934 pipeSpecs.needsScaling = qhwc::needsScalingWithSplit(ctx, layer, mDpy);
1935 pipeSpecs.dpy = mDpy;
1936 pipeSpecs.mixer = Overlay::MIXER_LEFT;
1937 pipeSpecs.fb = false;
1938
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001939 // Acquire pipe only for the updating half
1940 hwc_rect_t l_roi = ctx->listStats[mDpy].lRoi;
1941 hwc_rect_t r_roi = ctx->listStats[mDpy].rRoi;
1942
1943 if (dst.left < lSplit && isValidRect(getIntersection(dst, l_roi))) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001944 pipe_info.lIndex = ctx->mOverlay->getPipe(pipeSpecs);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001945 if(pipe_info.lIndex == ovutils::OV_INVALID)
1946 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001947 }
1948
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001949 if(dst.right > lSplit && isValidRect(getIntersection(dst, r_roi))) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001950 pipeSpecs.mixer = Overlay::MIXER_RIGHT;
1951 pipe_info.rIndex = ctx->mOverlay->getPipe(pipeSpecs);
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001952 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001953 return false;
1954 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001955
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001956 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001957}
1958
Saurabh Shah88e4d272013-09-03 13:31:29 -07001959bool MDPCompSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001960 hwc_display_contents_1_t* list) {
1961 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001962
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001963 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001964
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001965 hwc_layer_1_t* layer = &list->hwLayers[index];
1966 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301967 hwc_rect_t dst = layer->displayFrame;
1968 const int lSplit = getLeftSplit(ctx, mDpy);
1969 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1970 if((dst.left > lSplit)||(dst.right < lSplit)){
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001971 if(allocSplitVGPipesfor4k2k(ctx, index)){
radhakrishnac9a67412013-09-25 17:40:42 +05301972 continue;
1973 }
1974 }
1975 }
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001976 int mdpIndex = mCurrentFrame.layerToMDP[index];
1977 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001978 info.pipeInfo = new MdpPipeInfoSplit;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001979 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001980 MdpPipeInfoSplit& pipe_info = *(MdpPipeInfoSplit*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001981
Saurabh Shahc62f3982014-03-05 14:28:26 -08001982 if(!acquireMDPPipes(ctx, layer, pipe_info)) {
1983 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type",
1984 __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001985 return false;
1986 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001987 }
1988 return true;
1989}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001990
radhakrishnac9a67412013-09-25 17:40:42 +05301991int MDPCompSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1992 PipeLayerPair& PipeLayerPair) {
1993 const int lSplit = getLeftSplit(ctx, mDpy);
1994 hwc_rect_t dst = layer->displayFrame;
1995 if((dst.left > lSplit)||(dst.right < lSplit)){
1996 MdpYUVPipeInfo& mdp_info =
1997 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1998 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1999 eIsFg isFg = IS_FG_OFF;
2000 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
2001 eDest lDest = mdp_info.lIndex;
2002 eDest rDest = mdp_info.rIndex;
2003
2004 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
2005 lDest, rDest, &PipeLayerPair.rot);
2006 }
2007 else{
2008 return configure(ctx, layer, PipeLayerPair);
2009 }
2010}
2011
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002012/*
2013 * Configures pipe(s) for MDP composition
2014 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07002015int MDPCompSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07002016 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07002017 MdpPipeInfoSplit& mdp_info =
2018 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08002019 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
2020 eIsFg isFg = IS_FG_OFF;
2021 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
2022 eDest lDest = mdp_info.lIndex;
2023 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08002024
2025 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
2026 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
2027
Saurabh Shah88e4d272013-09-03 13:31:29 -07002028 return configureSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08002029 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002030}
2031
Saurabh Shah88e4d272013-09-03 13:31:29 -07002032bool MDPCompSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002033
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08002034 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002035 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
2036 return true;
2037 }
2038
2039 if(!ctx || !list) {
2040 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002041 return false;
2042 }
2043
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05302044 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
2045 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
2046 return true;
2047 }
2048
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -08002049 // Set the Handle timeout to true for MDP or MIXED composition.
2050 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount) {
2051 sHandleTimeout = true;
2052 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002053
Naseer Ahmed54821fe2012-11-28 18:44:38 -05002054 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08002055 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002056
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08002057 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
2058 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002059 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08002060 if(mCurrentFrame.isFBComposed[i]) continue;
2061
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002062 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08002063 private_handle_t *hnd = (private_handle_t *)layer->handle;
2064 if(!hnd) {
2065 ALOGE("%s handle null", __FUNCTION__);
2066 return false;
2067 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002068
2069 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
2070 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002071 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002072
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08002073 int mdpIndex = mCurrentFrame.layerToMDP[i];
2074
radhakrishnac9a67412013-09-25 17:40:42 +05302075 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
2076 {
2077 MdpYUVPipeInfo& pipe_info =
2078 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
2079 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
2080 ovutils::eDest indexL = pipe_info.lIndex;
2081 ovutils::eDest indexR = pipe_info.rIndex;
2082 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05302083 uint32_t offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05302084 if(rot) {
2085 rot->queueBuffer(fd, offset);
2086 fd = rot->getDstMemId();
2087 offset = rot->getDstOffset();
2088 }
2089 if(indexL != ovutils::OV_INVALID) {
2090 ovutils::eDest destL = (ovutils::eDest)indexL;
2091 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
2092 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
2093 if (!ov.queueBuffer(fd, offset, destL)) {
2094 ALOGE("%s: queueBuffer failed for display:%d",
2095 __FUNCTION__, mDpy);
2096 return false;
2097 }
2098 }
Saurabh Shahacf10202013-02-26 10:15:15 -08002099
radhakrishnac9a67412013-09-25 17:40:42 +05302100 if(indexR != ovutils::OV_INVALID) {
2101 ovutils::eDest destR = (ovutils::eDest)indexR;
2102 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
2103 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
2104 if (!ov.queueBuffer(fd, offset, destR)) {
2105 ALOGE("%s: queueBuffer failed for display:%d",
2106 __FUNCTION__, mDpy);
2107 return false;
2108 }
Saurabh Shaha9da08f2013-07-03 13:27:53 -07002109 }
2110 }
radhakrishnac9a67412013-09-25 17:40:42 +05302111 else{
2112 MdpPipeInfoSplit& pipe_info =
2113 *(MdpPipeInfoSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
2114 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07002115
radhakrishnac9a67412013-09-25 17:40:42 +05302116 ovutils::eDest indexL = pipe_info.lIndex;
2117 ovutils::eDest indexR = pipe_info.rIndex;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002118
Sushil Chauhandefd3522014-05-13 18:17:12 -07002119 if (!mDpy && (i == mOverlapIndex)) {
2120 hnd = ctx->mCopyBit[mDpy]->getCurrentRenderBuffer();
2121 }
2122
radhakrishnac9a67412013-09-25 17:40:42 +05302123 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05302124 int offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05302125
Tatenda Chipeperekwa88fe6352014-04-14 10:36:06 -07002126 if(ctx->mAD->draw(ctx, fd, offset)) {
2127 fd = ctx->mAD->getDstFd();
2128 offset = ctx->mAD->getDstOffset();
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002129 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002130
radhakrishnac9a67412013-09-25 17:40:42 +05302131 if(rot) {
2132 rot->queueBuffer(fd, offset);
2133 fd = rot->getDstMemId();
2134 offset = rot->getDstOffset();
2135 }
2136
2137 //************* play left mixer **********
2138 if(indexL != ovutils::OV_INVALID) {
2139 ovutils::eDest destL = (ovutils::eDest)indexL;
2140 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
2141 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
2142 if (!ov.queueBuffer(fd, offset, destL)) {
2143 ALOGE("%s: queueBuffer failed for left mixer",
2144 __FUNCTION__);
2145 return false;
2146 }
2147 }
2148
2149 //************* play right mixer **********
2150 if(indexR != ovutils::OV_INVALID) {
2151 ovutils::eDest destR = (ovutils::eDest)indexR;
2152 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
2153 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
2154 if (!ov.queueBuffer(fd, offset, destR)) {
2155 ALOGE("%s: queueBuffer failed for right mixer",
2156 __FUNCTION__);
2157 return false;
2158 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002159 }
2160 }
Saurabh Shahacf10202013-02-26 10:15:15 -08002161
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002162 layerProp[i].mFlags &= ~HWC_MDPCOMP;
2163 }
Saurabh Shahacf10202013-02-26 10:15:15 -08002164
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002165 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002166}
Saurabh Shahab47c692014-02-12 18:45:57 -08002167
2168//================MDPCompSrcSplit==============================================
2169bool MDPCompSrcSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Saurabh Shahc62f3982014-03-05 14:28:26 -08002170 MdpPipeInfoSplit& pipe_info) {
Saurabh Shahab47c692014-02-12 18:45:57 -08002171 private_handle_t *hnd = (private_handle_t *)layer->handle;
2172 hwc_rect_t dst = layer->displayFrame;
2173 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
2174 pipe_info.lIndex = ovutils::OV_INVALID;
2175 pipe_info.rIndex = ovutils::OV_INVALID;
2176
2177 //If 2 pipes are staged on a single stage of a mixer, then the left pipe
2178 //should have a higher priority than the right one. Pipe priorities are
2179 //starting with VG0, VG1 ... , RGB0 ..., DMA1
Saurabh Shahab47c692014-02-12 18:45:57 -08002180
Saurabh Shahc62f3982014-03-05 14:28:26 -08002181 Overlay::PipeSpecs pipeSpecs;
2182 pipeSpecs.formatClass = isYuvBuffer(hnd) ?
2183 Overlay::FORMAT_YUV : Overlay::FORMAT_RGB;
2184 pipeSpecs.needsScaling = qhwc::needsScaling(layer);
2185 pipeSpecs.dpy = mDpy;
2186 pipeSpecs.fb = false;
2187
Saurabh Shahab47c692014-02-12 18:45:57 -08002188 //1 pipe by default for a layer
Saurabh Shahc62f3982014-03-05 14:28:26 -08002189 pipe_info.lIndex = ctx->mOverlay->getPipe(pipeSpecs);
Saurabh Shahab47c692014-02-12 18:45:57 -08002190 if(pipe_info.lIndex == ovutils::OV_INVALID) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08002191 return false;
Saurabh Shahab47c692014-02-12 18:45:57 -08002192 }
2193
2194 //If layer's crop width or dest width > 2048, use 2 pipes
2195 if((dst.right - dst.left) > qdutils::MAX_DISPLAY_DIM or
2196 (crop.right - crop.left) > qdutils::MAX_DISPLAY_DIM) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08002197 pipe_info.rIndex = ctx->mOverlay->getPipe(pipeSpecs);
Saurabh Shahab47c692014-02-12 18:45:57 -08002198 if(pipe_info.rIndex == ovutils::OV_INVALID) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08002199 return false;
Saurabh Shahdd8237a2014-02-28 14:29:09 -08002200 }
2201
2202 // Return values
2203 // 1 Left pipe is higher priority, do nothing.
2204 // 0 Pipes of same priority.
2205 //-1 Right pipe is of higher priority, needs swap.
2206 if(ctx->mOverlay->comparePipePriority(pipe_info.lIndex,
2207 pipe_info.rIndex) == -1) {
2208 qhwc::swap(pipe_info.lIndex, pipe_info.rIndex);
Saurabh Shahab47c692014-02-12 18:45:57 -08002209 }
2210 }
2211
2212 return true;
2213}
2214
Saurabh Shahab47c692014-02-12 18:45:57 -08002215int MDPCompSrcSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
2216 PipeLayerPair& PipeLayerPair) {
2217 private_handle_t *hnd = (private_handle_t *)layer->handle;
2218 if(!hnd) {
2219 ALOGE("%s: layer handle is NULL", __FUNCTION__);
2220 return -1;
2221 }
2222 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
2223 MdpPipeInfoSplit& mdp_info =
2224 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
2225 Rotator **rot = &PipeLayerPair.rot;
2226 eZorder z = static_cast<eZorder>(mdp_info.zOrder);
2227 eIsFg isFg = IS_FG_OFF;
2228 eDest lDest = mdp_info.lIndex;
2229 eDest rDest = mdp_info.rIndex;
2230 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
2231 hwc_rect_t dst = layer->displayFrame;
2232 int transform = layer->transform;
2233 eTransform orient = static_cast<eTransform>(transform);
2234 const int downscale = 0;
2235 int rotFlags = ROT_FLAGS_NONE;
2236 uint32_t format = ovutils::getMdpFormat(hnd->format, isTileRendered(hnd));
2237 Whf whf(getWidth(hnd), getHeight(hnd), format, hnd->size);
2238
2239 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
2240 "dest_pipeR: %d",__FUNCTION__, layer, z, lDest, rDest);
2241
2242 // Handle R/B swap
2243 if (layer->flags & HWC_FORMAT_RB_SWAP) {
2244 if (hnd->format == HAL_PIXEL_FORMAT_RGBA_8888)
2245 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRA_8888);
2246 else if (hnd->format == HAL_PIXEL_FORMAT_RGBX_8888)
2247 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRX_8888);
2248 }
2249
Saurabh Shah97e2d802014-04-14 18:03:54 -07002250 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
2251 setMdpFlags(layer, mdpFlags, 0, transform);
Saurabh Shahab47c692014-02-12 18:45:57 -08002252
2253 if(lDest != OV_INVALID && rDest != OV_INVALID) {
2254 //Enable overfetch
Saurabh Shah97e2d802014-04-14 18:03:54 -07002255 setMdpFlags(mdpFlags, OV_MDSS_MDP_DUAL_PIPE);
Saurabh Shahab47c692014-02-12 18:45:57 -08002256 }
2257
2258 if(isYuvBuffer(hnd) && (transform & HWC_TRANSFORM_ROT_90)) {
2259 (*rot) = ctx->mRotMgr->getNext();
2260 if((*rot) == NULL) return -1;
Saurabh Shah39240c92014-03-31 10:31:42 -07002261 ctx->mLayerRotMap[mDpy]->add(layer, *rot);
Saurabh Shah1bd5b6f2014-05-19 12:23:13 -07002262 //If the video is using a single pipe, enable BWC
2263 if(rDest == OV_INVALID) {
2264 BwcPM::setBwc(crop, dst, transform, mdpFlags);
2265 }
Saurabh Shahab47c692014-02-12 18:45:57 -08002266 //Configure rotator for pre-rotation
Saurabh Shah97e2d802014-04-14 18:03:54 -07002267 if(configRotator(*rot, whf, crop, mdpFlags, orient, downscale) < 0) {
Saurabh Shahab47c692014-02-12 18:45:57 -08002268 ALOGE("%s: configRotator failed!", __FUNCTION__);
2269 return -1;
2270 }
Saurabh Shahab47c692014-02-12 18:45:57 -08002271 whf.format = (*rot)->getDstFormat();
2272 updateSource(orient, whf, crop);
2273 rotFlags |= ROT_PREROTATED;
2274 }
2275
2276 //If 2 pipes being used, divide layer into half, crop and dst
2277 hwc_rect_t cropL = crop;
2278 hwc_rect_t cropR = crop;
2279 hwc_rect_t dstL = dst;
2280 hwc_rect_t dstR = dst;
2281 if(lDest != OV_INVALID && rDest != OV_INVALID) {
2282 cropL.right = (crop.right + crop.left) / 2;
2283 cropR.left = cropL.right;
2284 sanitizeSourceCrop(cropL, cropR, hnd);
2285
2286 //Swap crops on H flip since 2 pipes are being used
2287 if((orient & OVERLAY_TRANSFORM_FLIP_H) && (*rot) == NULL) {
2288 hwc_rect_t tmp = cropL;
2289 cropL = cropR;
2290 cropR = tmp;
2291 }
2292
2293 dstL.right = (dst.right + dst.left) / 2;
2294 dstR.left = dstL.right;
2295 }
2296
2297 //For the mdp, since either we are pre-rotating or MDP does flips
2298 orient = OVERLAY_TRANSFORM_0;
2299 transform = 0;
2300
2301 //configure left pipe
2302 if(lDest != OV_INVALID) {
Saurabh Shah97e2d802014-04-14 18:03:54 -07002303 PipeArgs pargL(mdpFlags, whf, z, isFg,
Saurabh Shahab47c692014-02-12 18:45:57 -08002304 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2305 (ovutils::eBlending) getBlending(layer->blending));
2306
2307 if(configMdp(ctx->mOverlay, pargL, orient,
2308 cropL, dstL, metadata, lDest) < 0) {
2309 ALOGE("%s: commit failed for left mixer config", __FUNCTION__);
2310 return -1;
2311 }
2312 }
2313
2314 //configure right pipe
2315 if(rDest != OV_INVALID) {
Saurabh Shah97e2d802014-04-14 18:03:54 -07002316 PipeArgs pargR(mdpFlags, whf, z, isFg,
Saurabh Shahab47c692014-02-12 18:45:57 -08002317 static_cast<eRotFlags>(rotFlags),
2318 layer->planeAlpha,
2319 (ovutils::eBlending) getBlending(layer->blending));
2320 if(configMdp(ctx->mOverlay, pargR, orient,
2321 cropR, dstR, metadata, rDest) < 0) {
2322 ALOGE("%s: commit failed for right mixer config", __FUNCTION__);
2323 return -1;
2324 }
2325 }
2326
2327 return 0;
2328}
2329
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002330}; //namespace
2331