blob: 1a1bd9e0c341918b2d0b0190a0090e5cbc13e2a1 [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
163 if((property_get("debug.mdpcomp.4k2kSplit", property, "0") > 0) &&
164 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
165 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
166 sEnable4k2kYUVSplit = true;
167 }
Sushil Chauhandefd3522014-05-13 18:17:12 -0700168
169 if ((property_get("persist.hwc.ptor.enable", property, NULL) > 0) &&
170 ((!strncasecmp(property, "true", PROPERTY_VALUE_MAX )) ||
171 (!strncmp(property, "1", PROPERTY_VALUE_MAX )))) {
172 ctx->mCopyBit[HWC_DISPLAY_PRIMARY] = new CopyBit(ctx,
173 HWC_DISPLAY_PRIMARY);
174 }
175
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700176 return true;
177}
178
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800179void MDPComp::reset(hwc_context_t *ctx) {
180 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700181 mCurrentFrame.reset(numLayers);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800182 ctx->mOverlay->clear(mDpy);
183 ctx->mLayerRotMap[mDpy]->clear();
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700184}
185
Raj Kamal4393eaa2014-06-06 13:45:20 +0530186void MDPComp::reset() {
187 sHandleTimeout = false;
188 mModeOn = false;
189}
190
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700191void MDPComp::timeout_handler(void *udata) {
192 struct hwc_context_t* ctx = (struct hwc_context_t*)(udata);
193
194 if(!ctx) {
195 ALOGE("%s: received empty data in timer callback", __FUNCTION__);
196 return;
197 }
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -0800198 Locker::Autolock _l(ctx->mDrawLock);
199 // Handle timeout event only if the previous composition is MDP or MIXED.
200 if(!sHandleTimeout) {
201 ALOGD_IF(isDebug(), "%s:Do not handle this timeout", __FUNCTION__);
202 return;
203 }
Jesse Hall3be78d92012-08-21 15:12:23 -0700204 if(!ctx->proc) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700205 ALOGE("%s: HWC proc not registered", __FUNCTION__);
206 return;
207 }
208 sIdleFallBack = true;
209 /* Trigger SF to redraw the current frame */
Jesse Hall3be78d92012-08-21 15:12:23 -0700210 ctx->proc->invalidate(ctx->proc);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700211}
212
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800213void MDPComp::setMDPCompLayerFlags(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800214 hwc_display_contents_1_t* list) {
215 LayerProp *layerProp = ctx->layerProp[mDpy];
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800216
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800217 for(int index = 0; index < ctx->listStats[mDpy].numAppLayers; index++) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800218 hwc_layer_1_t* layer = &(list->hwLayers[index]);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800219 if(!mCurrentFrame.isFBComposed[index]) {
220 layerProp[index].mFlags |= HWC_MDPCOMP;
221 layer->compositionType = HWC_OVERLAY;
222 layer->hints |= HWC_HINT_CLEAR_FB;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800223 } else {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700224 /* Drop the layer when its already present in FB OR when it lies
225 * outside frame's ROI */
226 if(!mCurrentFrame.needsRedraw || mCurrentFrame.drop[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800227 layer->compositionType = HWC_OVERLAY;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700228 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800229 }
230 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700231}
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500232
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800233void MDPComp::setRedraw(hwc_context_t *ctx,
234 hwc_display_contents_1_t* list) {
235 mCurrentFrame.needsRedraw = false;
236 if(!mCachedFrame.isSameFrame(mCurrentFrame, list) ||
237 (list->flags & HWC_GEOMETRY_CHANGED) ||
238 isSkipPresent(ctx, mDpy)) {
239 mCurrentFrame.needsRedraw = true;
240 }
241}
242
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800243MDPComp::FrameInfo::FrameInfo() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700244 reset(0);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800245}
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800246
Saurabh Shahaa236822013-04-24 18:07:26 -0700247void MDPComp::FrameInfo::reset(const int& numLayers) {
248 for(int i = 0 ; i < MAX_PIPES_PER_MIXER && numLayers; i++ ) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800249 if(mdpToLayer[i].pipeInfo) {
250 delete mdpToLayer[i].pipeInfo;
251 mdpToLayer[i].pipeInfo = NULL;
252 //We dont own the rotator
253 mdpToLayer[i].rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800254 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800255 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800256
257 memset(&mdpToLayer, 0, sizeof(mdpToLayer));
258 memset(&layerToMDP, -1, sizeof(layerToMDP));
Saurabh Shahaa236822013-04-24 18:07:26 -0700259 memset(&isFBComposed, 1, sizeof(isFBComposed));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800260
Saurabh Shahaa236822013-04-24 18:07:26 -0700261 layerCount = numLayers;
262 fbCount = numLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800263 mdpCount = 0;
Saurabh Shah2f3895f2013-05-02 10:13:31 -0700264 needsRedraw = true;
Saurabh Shahd53bc5f2014-02-05 10:17:43 -0800265 fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800266}
267
Saurabh Shahaa236822013-04-24 18:07:26 -0700268void MDPComp::FrameInfo::map() {
269 // populate layer and MDP maps
270 int mdpIdx = 0;
271 for(int idx = 0; idx < layerCount; idx++) {
272 if(!isFBComposed[idx]) {
273 mdpToLayer[mdpIdx].listIndex = idx;
274 layerToMDP[idx] = mdpIdx++;
275 }
276 }
277}
278
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800279MDPComp::LayerCache::LayerCache() {
280 reset();
281}
282
283void MDPComp::LayerCache::reset() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700284 memset(&hnd, 0, sizeof(hnd));
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530285 memset(&isFBComposed, true, sizeof(isFBComposed));
286 memset(&drop, false, sizeof(drop));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800287 layerCount = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -0700288}
289
290void MDPComp::LayerCache::cacheAll(hwc_display_contents_1_t* list) {
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530291 const int numAppLayers = (int)list->numHwLayers - 1;
Saurabh Shahaa236822013-04-24 18:07:26 -0700292 for(int i = 0; i < numAppLayers; i++) {
293 hnd[i] = list->hwLayers[i].handle;
294 }
295}
296
297void MDPComp::LayerCache::updateCounts(const FrameInfo& curFrame) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700298 layerCount = curFrame.layerCount;
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530299 memcpy(&isFBComposed, &curFrame.isFBComposed, sizeof(isFBComposed));
300 memcpy(&drop, &curFrame.drop, sizeof(drop));
301}
302
Jeykumar Sankaran988d3682013-11-15 11:57:16 -0800303bool MDPComp::LayerCache::isSameFrame(const FrameInfo& curFrame,
304 hwc_display_contents_1_t* list) {
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530305 if(layerCount != curFrame.layerCount)
306 return false;
307 for(int i = 0; i < curFrame.layerCount; i++) {
308 if((curFrame.isFBComposed[i] != isFBComposed[i]) ||
309 (curFrame.drop[i] != drop[i])) {
310 return false;
311 }
Jeykumar Sankaran988d3682013-11-15 11:57:16 -0800312 if(curFrame.isFBComposed[i] &&
313 (hnd[i] != list->hwLayers[i].handle)){
314 return false;
315 }
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530316 }
317 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800318}
319
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700320bool MDPComp::isSupportedForMDPComp(hwc_context_t *ctx, hwc_layer_1_t* layer) {
321 private_handle_t *hnd = (private_handle_t *)layer->handle;
322 if((not isYuvBuffer(hnd) and has90Transform(layer)) or
323 (not isValidDimension(ctx,layer))
324 //More conditions here, SKIP, sRGB+Blend etc
325 ) {
326 return false;
327 }
328 return true;
329}
330
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530331bool MDPComp::isValidDimension(hwc_context_t *ctx, hwc_layer_1_t *layer) {
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800332 private_handle_t *hnd = (private_handle_t *)layer->handle;
333
334 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -0700335 if (layer->flags & HWC_COLOR_FILL) {
336 // Color layer
337 return true;
338 }
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800339 ALOGE("%s: layer handle is NULL", __FUNCTION__);
340 return false;
341 }
342
Naseer Ahmede850a802013-09-06 13:12:52 -0400343 //XXX: Investigate doing this with pixel phase on MDSS
Naseer Ahmede77f8082013-10-10 13:42:48 -0400344 if(!isSecureBuffer(hnd) && isNonIntegralSourceCrop(layer->sourceCropf))
Naseer Ahmede850a802013-09-06 13:12:52 -0400345 return false;
346
Saurabh Shah62e1d732013-09-17 10:44:05 -0700347 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700348 hwc_rect_t dst = layer->displayFrame;
Saurabh Shah4fdde762013-04-30 18:47:33 -0700349 int crop_w = crop.right - crop.left;
350 int crop_h = crop.bottom - crop.top;
351 int dst_w = dst.right - dst.left;
352 int dst_h = dst.bottom - dst.top;
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800353 float w_scale = ((float)crop_w / (float)dst_w);
354 float h_scale = ((float)crop_h / (float)dst_h);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700355
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800356 /* Workaround for MDP HW limitation in DSI command mode panels where
357 * FPS will not go beyond 30 if buffers on RGB pipes are of width or height
358 * less than 5 pixels
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530359 * There also is a HW limilation in MDP, minimum block size is 2x2
360 * Fallback to GPU if height is less than 2.
361 */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800362 if((crop_w < 5)||(crop_h < 5))
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800363 return false;
364
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800365 if((w_scale > 1.0f) || (h_scale > 1.0f)) {
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700366 const uint32_t maxMDPDownscale =
Saurabh Shah4fdde762013-04-30 18:47:33 -0700367 qdutils::MDPVersion::getInstance().getMaxMDPDownscale();
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800368 const float w_dscale = w_scale;
369 const float h_dscale = h_scale;
370
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800371 if(ctx->mMDP.version >= qdutils::MDSS_V5) {
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700372
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800373 if(!qdutils::MDPVersion::getInstance().supportsDecimation()) {
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700374 /* On targets that doesnt support Decimation (eg.,8x26)
375 * maximum downscale support is overlay pipe downscale.
376 */
377 if(crop_w > MAX_DISPLAY_DIM || w_dscale > maxMDPDownscale ||
378 h_dscale > maxMDPDownscale)
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800379 return false;
380 } else {
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700381 // Decimation on macrotile format layers is not supported.
382 if(isTileRendered(hnd)) {
383 /* MDP can read maximum MAX_DISPLAY_DIM width.
384 * Bail out if
385 * 1. Src crop > MAX_DISPLAY_DIM on nonsplit MDPComp
386 * 2. exceeds maximum downscale limit
387 */
388 if(((crop_w > MAX_DISPLAY_DIM) && !sSrcSplitEnabled) ||
389 w_dscale > maxMDPDownscale ||
390 h_dscale > maxMDPDownscale) {
391 return false;
392 }
393 } else if(w_dscale > 64 || h_dscale > 64)
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800394 return false;
395 }
396 } else { //A-family
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700397 if(w_dscale > maxMDPDownscale || h_dscale > maxMDPDownscale)
Saurabh Shah4fdde762013-04-30 18:47:33 -0700398 return false;
399 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700400 }
401
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800402 if((w_scale < 1.0f) || (h_scale < 1.0f)) {
403 const uint32_t upscale =
404 qdutils::MDPVersion::getInstance().getMaxMDPUpscale();
405 const float w_uscale = 1.0f / w_scale;
406 const float h_uscale = 1.0f / h_scale;
407
408 if(w_uscale > upscale || h_uscale > upscale)
409 return false;
410 }
411
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800412 return true;
413}
414
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800415bool MDPComp::isFrameDoable(hwc_context_t *ctx) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700416 bool ret = true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800417
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800418 if(!isEnabled()) {
419 ALOGD_IF(isDebug(),"%s: MDP Comp. not enabled.", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700420 ret = false;
Raj Kamal068f4572014-04-14 16:14:06 +0530421 } else if((qdutils::MDPVersion::getInstance().is8x26() ||
Prabhanjan Kandula958ffa92014-05-12 14:56:56 +0530422 qdutils::MDPVersion::getInstance().is8x16() ||
423 qdutils::MDPVersion::getInstance().is8x39()) &&
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -0800424 ctx->mVideoTransFlag &&
425 isSecondaryConnected(ctx)) {
Saurabh Shahd4e65852013-06-17 11:33:53 -0700426 //1 Padding round to shift pipes across mixers
427 ALOGD_IF(isDebug(),"%s: MDP Comp. video transition padding round",
428 __FUNCTION__);
429 ret = false;
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -0800430 } else if(isSecondaryConfiguring(ctx)) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800431 ALOGD_IF( isDebug(),"%s: External Display connection is pending",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800432 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700433 ret = false;
Saurabh Shahaa236822013-04-24 18:07:26 -0700434 } else if(ctx->isPaddingRound) {
Raj Kamal9ed3d6b2014-02-07 16:15:17 +0530435 ALOGD_IF(isDebug(), "%s: padding round invoked for dpy %d",
436 __FUNCTION__,mDpy);
Saurabh Shahaa236822013-04-24 18:07:26 -0700437 ret = false;
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700438 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700439 return ret;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800440}
441
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800442void MDPCompNonSplit::trimAgainstROI(hwc_context_t *ctx, hwc_rect_t& fbRect) {
443 hwc_rect_t roi = ctx->listStats[mDpy].lRoi;
444 fbRect = getIntersection(fbRect, roi);
445}
446
447/* 1) Identify layers that are not visible or lying outside the updating ROI and
448 * drop them from composition.
449 * 2) If we have a scaling layer which needs cropping against generated
450 * ROI, reset ROI to full resolution. */
451bool MDPCompNonSplit::validateAndApplyROI(hwc_context_t *ctx,
452 hwc_display_contents_1_t* list) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700453 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800454 hwc_rect_t visibleRect = ctx->listStats[mDpy].lRoi;
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800455
456 for(int i = numAppLayers - 1; i >= 0; i--){
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800457 if(!isValidRect(visibleRect)) {
458 mCurrentFrame.drop[i] = true;
459 mCurrentFrame.dropCount++;
Jeykumar Sankaran0b961452014-01-21 17:26:12 -0800460 continue;
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800461 }
462
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700463 const hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700464 hwc_rect_t dstRect = layer->displayFrame;
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800465 hwc_rect_t res = getIntersection(visibleRect, dstRect);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700466
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700467 if(!isValidRect(res)) {
468 mCurrentFrame.drop[i] = true;
469 mCurrentFrame.dropCount++;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800470 } else {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700471 /* Reset frame ROI when any layer which needs scaling also needs ROI
472 * cropping */
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800473 if(!isSameRect(res, dstRect) && needsScaling (layer)) {
Arpita Banerjeed8965982013-11-08 17:27:33 -0800474 ALOGI("%s: Resetting ROI due to scaling", __FUNCTION__);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700475 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
476 mCurrentFrame.dropCount = 0;
477 return false;
478 }
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800479
Jeykumar Sankaran0b961452014-01-21 17:26:12 -0800480 /* deduct any opaque region from visibleRect */
481 if (layer->blending == HWC_BLENDING_NONE)
482 visibleRect = deductRect(visibleRect, res);
483 }
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700484 }
485 return true;
486}
487
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800488/* Calculate ROI for the frame by accounting all the layer's dispalyFrame which
489 * are updating. If DirtyRegion is applicable, calculate it by accounting all
490 * the changing layer's dirtyRegion. */
491void MDPCompNonSplit::generateROI(hwc_context_t *ctx,
492 hwc_display_contents_1_t* list) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700493 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800494 if(!canPartialUpdate(ctx, list))
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700495 return;
496
497 struct hwc_rect roi = (struct hwc_rect){0, 0, 0, 0};
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800498 hwc_rect fullFrame = (struct hwc_rect) {0, 0,(int)ctx->dpyAttr[mDpy].xres,
499 (int)ctx->dpyAttr[mDpy].yres};
500
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700501 for(int index = 0; index < numAppLayers; index++ ) {
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800502 hwc_layer_1_t* layer = &list->hwLayers[index];
503 if ((mCachedFrame.hnd[index] != layer->handle) ||
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800504 isYuvBuffer((private_handle_t *)layer->handle)) {
Jeykumar Sankaran455678c2014-05-30 10:22:38 -0700505 hwc_rect_t dst = layer->displayFrame;
506 hwc_rect_t updatingRect = dst;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800507
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800508#ifdef QCOM_BSP
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800509 if(!needsScaling(layer) && !layer->transform)
Jeykumar Sankaran455678c2014-05-30 10:22:38 -0700510 {
511 hwc_rect_t src = integerizeSourceCrop(layer->sourceCropf);
512 int x_off = dst.left - src.left;
513 int y_off = dst.top - src.top;
514 updatingRect = moveRect(layer->dirtyRect, x_off, y_off);
515 }
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800516#endif
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800517
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800518 roi = getUnion(roi, updatingRect);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700519 }
520 }
521
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800522 /* No layer is updating. Still SF wants a refresh.*/
523 if(!isValidRect(roi))
524 return;
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800525
526 // Align ROI coordinates to panel restrictions
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800527 roi = getSanitizeROI(roi, fullFrame);
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800528
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800529 ctx->listStats[mDpy].lRoi = roi;
530 if(!validateAndApplyROI(ctx, list))
531 resetROI(ctx, mDpy);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700532
533 ALOGD_IF(isDebug(),"%s: generated ROI: [%d, %d, %d, %d]", __FUNCTION__,
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800534 ctx->listStats[mDpy].lRoi.left, ctx->listStats[mDpy].lRoi.top,
535 ctx->listStats[mDpy].lRoi.right, ctx->listStats[mDpy].lRoi.bottom);
536}
537
538void MDPCompSplit::trimAgainstROI(hwc_context_t *ctx, hwc_rect_t& fbRect) {
539 hwc_rect l_roi = ctx->listStats[mDpy].lRoi;
540 hwc_rect r_roi = ctx->listStats[mDpy].rRoi;
541
542 hwc_rect_t l_fbRect = getIntersection(fbRect, l_roi);
543 hwc_rect_t r_fbRect = getIntersection(fbRect, r_roi);
544 fbRect = getUnion(l_fbRect, r_fbRect);
545}
546/* 1) Identify layers that are not visible or lying outside BOTH the updating
547 * ROI's and drop them from composition. If a layer is spanning across both
548 * the halves of the screen but needed by only ROI, the non-contributing
549 * half will not be programmed for MDP.
550 * 2) If we have a scaling layer which needs cropping against generated
551 * ROI, reset ROI to full resolution. */
552bool MDPCompSplit::validateAndApplyROI(hwc_context_t *ctx,
553 hwc_display_contents_1_t* list) {
554
555 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
556
557 hwc_rect_t visibleRectL = ctx->listStats[mDpy].lRoi;
558 hwc_rect_t visibleRectR = ctx->listStats[mDpy].rRoi;
559
560 for(int i = numAppLayers - 1; i >= 0; i--){
561 if(!isValidRect(visibleRectL) && !isValidRect(visibleRectR))
562 {
563 mCurrentFrame.drop[i] = true;
564 mCurrentFrame.dropCount++;
565 continue;
566 }
567
568 const hwc_layer_1_t* layer = &list->hwLayers[i];
569 hwc_rect_t dstRect = layer->displayFrame;
570
571 hwc_rect_t l_res = getIntersection(visibleRectL, dstRect);
572 hwc_rect_t r_res = getIntersection(visibleRectR, dstRect);
573 hwc_rect_t res = getUnion(l_res, r_res);
574
575 if(!isValidRect(l_res) && !isValidRect(r_res)) {
576 mCurrentFrame.drop[i] = true;
577 mCurrentFrame.dropCount++;
578 } else {
579 /* Reset frame ROI when any layer which needs scaling also needs ROI
580 * cropping */
581 if(!isSameRect(res, dstRect) && needsScaling (layer)) {
582 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
583 mCurrentFrame.dropCount = 0;
584 return false;
585 }
586
587 if (layer->blending == HWC_BLENDING_NONE) {
588 visibleRectL = deductRect(visibleRectL, l_res);
589 visibleRectR = deductRect(visibleRectR, r_res);
590 }
591 }
592 }
593 return true;
594}
595/* Calculate ROI for the frame by accounting all the layer's dispalyFrame which
596 * are updating. If DirtyRegion is applicable, calculate it by accounting all
597 * the changing layer's dirtyRegion. */
598void MDPCompSplit::generateROI(hwc_context_t *ctx,
599 hwc_display_contents_1_t* list) {
600 if(!canPartialUpdate(ctx, list))
601 return;
602
603 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
604 int lSplit = getLeftSplit(ctx, mDpy);
605
606 int hw_h = (int)ctx->dpyAttr[mDpy].yres;
607 int hw_w = (int)ctx->dpyAttr[mDpy].xres;
608
609 struct hwc_rect l_frame = (struct hwc_rect){0, 0, lSplit, hw_h};
610 struct hwc_rect r_frame = (struct hwc_rect){lSplit, 0, hw_w, hw_h};
611
612 struct hwc_rect l_roi = (struct hwc_rect){0, 0, 0, 0};
613 struct hwc_rect r_roi = (struct hwc_rect){0, 0, 0, 0};
614
615 for(int index = 0; index < numAppLayers; index++ ) {
616 hwc_layer_1_t* layer = &list->hwLayers[index];
617 if ((mCachedFrame.hnd[index] != layer->handle) ||
618 isYuvBuffer((private_handle_t *)layer->handle)) {
Jeykumar Sankaran71e597c2014-05-07 16:23:14 -0700619 hwc_rect_t dst = layer->displayFrame;
620 hwc_rect_t updatingRect = dst;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800621
622#ifdef QCOM_BSP
623 if(!needsScaling(layer) && !layer->transform)
Jeykumar Sankaran71e597c2014-05-07 16:23:14 -0700624 {
625 hwc_rect_t src = integerizeSourceCrop(layer->sourceCropf);
626 int x_off = dst.left - src.left;
627 int y_off = dst.top - src.top;
628 updatingRect = moveRect(layer->dirtyRect, x_off, y_off);
629 }
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800630#endif
631
632 hwc_rect_t l_dst = getIntersection(l_frame, updatingRect);
633 if(isValidRect(l_dst))
634 l_roi = getUnion(l_roi, l_dst);
635
636 hwc_rect_t r_dst = getIntersection(r_frame, updatingRect);
637 if(isValidRect(r_dst))
638 r_roi = getUnion(r_roi, r_dst);
639 }
640 }
641
Jeykumar Sankarana40a9342014-04-25 09:37:10 -0700642 /* For panels that cannot accept commands in both the interfaces, we cannot
643 * send two ROI's (for each half). We merge them into single ROI and split
644 * them across lSplit for MDP mixer use. The ROI's will be merged again
645 * finally before udpating the panel in the driver. */
646 if(qdutils::MDPVersion::getInstance().needsROIMerge()) {
647 hwc_rect_t temp_roi = getUnion(l_roi, r_roi);
648 l_roi = getIntersection(temp_roi, l_frame);
649 r_roi = getIntersection(temp_roi, r_frame);
650 }
651
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800652 /* No layer is updating. Still SF wants a refresh. */
653 if(!isValidRect(l_roi) && !isValidRect(r_roi))
654 return;
655
656 l_roi = getSanitizeROI(l_roi, l_frame);
657 r_roi = getSanitizeROI(r_roi, r_frame);
658
659 ctx->listStats[mDpy].lRoi = l_roi;
660 ctx->listStats[mDpy].rRoi = r_roi;
661
662 if(!validateAndApplyROI(ctx, list))
663 resetROI(ctx, mDpy);
664
665 ALOGD_IF(isDebug(),"%s: generated L_ROI: [%d, %d, %d, %d]"
666 "R_ROI: [%d, %d, %d, %d]", __FUNCTION__,
667 ctx->listStats[mDpy].lRoi.left, ctx->listStats[mDpy].lRoi.top,
668 ctx->listStats[mDpy].lRoi.right, ctx->listStats[mDpy].lRoi.bottom,
669 ctx->listStats[mDpy].rRoi.left, ctx->listStats[mDpy].rRoi.top,
670 ctx->listStats[mDpy].rRoi.right, ctx->listStats[mDpy].rRoi.bottom);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700671}
672
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800673/* Checks for conditions where all the layers marked for MDP comp cannot be
674 * bypassed. On such conditions we try to bypass atleast YUV layers */
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800675bool MDPComp::tryFullFrame(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800676 hwc_display_contents_1_t* list){
677
Saurabh Shahaa236822013-04-24 18:07:26 -0700678 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Arun Kumar K.R2e2871c2014-01-10 12:47:06 -0800679 int priDispW = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800680
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -0700681 if(sIdleFallBack && !ctx->listStats[mDpy].secureUI) {
Saurabh Shah2d998a92013-05-14 17:55:58 -0700682 ALOGD_IF(isDebug(), "%s: Idle fallback dpy %d",__FUNCTION__, mDpy);
683 return false;
684 }
685
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800686 if(isSkipPresent(ctx, mDpy)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700687 ALOGD_IF(isDebug(),"%s: SKIP present: %d",
688 __FUNCTION__,
689 isSkipPresent(ctx, mDpy));
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800690 return false;
691 }
692
Arun Kumar K.R2e2871c2014-01-10 12:47:06 -0800693 if(mDpy > HWC_DISPLAY_PRIMARY && (priDispW > MAX_DISPLAY_DIM) &&
694 (ctx->dpyAttr[mDpy].xres < MAX_DISPLAY_DIM)) {
695 // Disable MDP comp on Secondary when the primary is highres panel and
696 // the secondary is a normal 1080p, because, MDP comp on secondary under
697 // in such usecase, decimation gets used for downscale and there will be
698 // a quality mismatch when there will be a fallback to GPU comp
699 ALOGD_IF(isDebug(), "%s: Disable MDP Compositon for Secondary Disp",
700 __FUNCTION__);
701 return false;
702 }
703
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800704 // check for action safe flag and downscale mode which requires scaling.
705 if(ctx->dpyAttr[mDpy].mActionSafePresent
706 || ctx->dpyAttr[mDpy].mDownScaleMode) {
707 ALOGD_IF(isDebug(), "%s: Scaling needed for this frame",__FUNCTION__);
708 return false;
709 }
710
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800711 for(int i = 0; i < numAppLayers; ++i) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800712 hwc_layer_1_t* layer = &list->hwLayers[i];
713 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800714
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700715 if(isYuvBuffer(hnd) && has90Transform(layer)) {
716 if(!canUseRotator(ctx, mDpy)) {
717 ALOGD_IF(isDebug(), "%s: Can't use rotator for dpy %d",
718 __FUNCTION__, mDpy);
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700719 return false;
720 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800721 }
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530722
723 //For 8x26 with panel width>1k, if RGB layer needs HFLIP fail mdp comp
724 // may not need it if Gfx pre-rotation can handle all flips & rotations
Sushil Chauhanfda00fc2014-03-20 11:08:41 -0700725 int transform = (layer->flags & HWC_COLOR_FILL) ? 0 : layer->transform;
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530726 if(qdutils::MDPVersion::getInstance().is8x26() &&
727 (ctx->dpyAttr[mDpy].xres > 1024) &&
Sushil Chauhanfda00fc2014-03-20 11:08:41 -0700728 (transform & HWC_TRANSFORM_FLIP_H) &&
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530729 (!isYuvBuffer(hnd)))
730 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800731 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700732
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700733 if(ctx->mAD->isDoable()) {
734 return false;
735 }
736
Saurabh Shahaa236822013-04-24 18:07:26 -0700737 //If all above hard conditions are met we can do full or partial MDP comp.
738 bool ret = false;
739 if(fullMDPComp(ctx, list)) {
740 ret = true;
Sushil Chauhandefd3522014-05-13 18:17:12 -0700741 } else if(fullMDPCompWithPTOR(ctx, list)) {
742 ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700743 } else if(partialMDPComp(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700744 ret = true;
745 }
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530746
Saurabh Shahaa236822013-04-24 18:07:26 -0700747 return ret;
748}
749
750bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaran0ad97c42014-03-09 23:00:53 -0700751
752 if(sSimulationFlags & MDPCOMP_AVOID_FULL_MDP)
753 return false;
754
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700755 //Will benefit presentation / secondary-only layer.
756 if((mDpy > HWC_DISPLAY_PRIMARY) &&
757 (list->numHwLayers - 1) > MAX_SEC_LAYERS) {
758 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
759 return false;
760 }
761
762 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
763 for(int i = 0; i < numAppLayers; i++) {
764 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran880da832014-04-18 10:22:35 -0700765 if(not mCurrentFrame.drop[i] and
766 not isSupportedForMDPComp(ctx, layer)) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700767 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",__FUNCTION__);
768 return false;
769 }
770 }
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800771
Saurabh Shahaa236822013-04-24 18:07:26 -0700772 mCurrentFrame.fbCount = 0;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700773 memcpy(&mCurrentFrame.isFBComposed, &mCurrentFrame.drop,
774 sizeof(mCurrentFrame.isFBComposed));
775 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount -
776 mCurrentFrame.dropCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700777
radhakrishnac9a67412013-09-25 17:40:42 +0530778 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800779 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530780 }
781
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800782 if(!postHeuristicsHandling(ctx, list)) {
783 ALOGD_IF(isDebug(), "post heuristic handling failed");
784 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700785 return false;
786 }
Jeykumar Sankaran0ad97c42014-03-09 23:00:53 -0700787 ALOGD_IF(sSimulationFlags,"%s: FULL_MDP_COMP SUCCEEDED",
788 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700789 return true;
790}
791
Sushil Chauhandefd3522014-05-13 18:17:12 -0700792/* Full MDP Composition with Peripheral Tiny Overlap Removal.
793 * MDP bandwidth limitations can be avoided, if the overlap region
794 * covered by the smallest layer at a higher z-order, gets composed
795 * by Copybit on a render buffer, which can be queued to MDP.
796 */
797bool MDPComp::fullMDPCompWithPTOR(hwc_context_t *ctx,
798 hwc_display_contents_1_t* list) {
799
800 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
801 const int stagesForMDP = min(sMaxPipesPerMixer,
802 ctx->mOverlay->availablePipes(mDpy, Overlay::MIXER_DEFAULT));
803
804 // Hard checks where we cannot use this mode
805 if (mDpy || !ctx->mCopyBit[mDpy] || isDisplaySplit(ctx, mDpy)) {
806 ALOGD_IF(isDebug(), "%s: Feature not supported!", __FUNCTION__);
807 return false;
808 }
809
810 // Frame level checks
811 if ((numAppLayers > stagesForMDP) || isSkipPresent(ctx, mDpy) ||
812 isYuvPresent(ctx, mDpy) || mCurrentFrame.dropCount ||
813 isSecurePresent(ctx, mDpy)) {
814 ALOGD_IF(isDebug(), "%s: Frame not supported!", __FUNCTION__);
815 return false;
816 }
817
818 // Find overlap index
819 int overlapIdx = numAppLayers - 1;
820 uint32_t layerPixelCount, minPixelCount = 0;
821 for (int i = numAppLayers - 1; i >= 0; i--) {
822 hwc_layer_1_t* layer = &list->hwLayers[i];
823 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
824 layerPixelCount = (crop.right - crop.left) * (crop.bottom - crop.top);
825 if (!minPixelCount || (layerPixelCount < minPixelCount)) {
826 minPixelCount = layerPixelCount;
827 overlapIdx = i;
828 }
829 }
830
831 // No overlap
832 if (!overlapIdx)
833 return false;
834
835 /* We cannot use this composition mode, if:
836 1. A below layer needs scaling.
837 2. Overlap is not peripheral to display.
838 3. Overlap or a below layer has 90 degree transform.
839 4. Intersection of Overlap layer with a below layer is not valid.
840 5. Overlap area > (1/3 * FrameBuffer) area, based on Perf inputs.
841 */
842
843 hwc_rect_t overlap = list->hwLayers[overlapIdx].displayFrame;
844 if (!isPeripheral(overlap, ctx->mViewFrame[mDpy]))
845 return false;
846
847 if ((3 * (overlap.right - overlap.left) * (overlap.bottom - overlap.top)) >
848 ((int)ctx->dpyAttr[mDpy].xres * (int)ctx->dpyAttr[mDpy].yres))
849 return false;
850
851 for (int i = overlapIdx; i >= 0; i--) {
852 hwc_layer_1_t* layer = &list->hwLayers[i];
853 hwc_rect_t dispFrame = layer->displayFrame;
854
855 if (has90Transform(layer))
856 return false;
857
858 if (i < overlapIdx) {
859 if (needsScaling(layer) ||
860 !isValidRect(getIntersection(dispFrame, overlap)))
861 return false;
862 }
863 }
864
865 mOverlapIndex = overlapIdx;
866 if (!ctx->mCopyBit[mDpy]->prepareOverlap(ctx, list, overlapIdx)) {
867 ALOGD_IF(isDebug(), "%s: Overlap prepare failed!",__FUNCTION__);
868 mOverlapIndex = -1;
869 return false;
870 }
871
872 hwc_rect_t sourceCrop[overlapIdx];
873 hwc_rect_t displayFrame[overlapIdx];
874
875 // Remove overlap from crop & displayFrame of below layers
876 for (int i = 0; i < overlapIdx; i++) {
877 hwc_layer_1_t* layer = &list->hwLayers[i];
878 displayFrame[i] = layer->displayFrame;
879 sourceCrop[i] = integerizeSourceCrop(layer->sourceCropf);
880
881 // Update layer attributes
882 hwc_rect_t srcCrop = integerizeSourceCrop(layer->sourceCropf);
883 hwc_rect_t destRect = deductRect(layer->displayFrame, overlap);
884 qhwc::calculate_crop_rects(srcCrop, layer->displayFrame, destRect,
885 layer->transform);
886
887 layer->sourceCropf.left = (float)srcCrop.left;
888 layer->sourceCropf.top = (float)srcCrop.top;
889 layer->sourceCropf.right = (float)srcCrop.right;
890 layer->sourceCropf.bottom = (float)srcCrop.bottom;
891 }
892
893 mCurrentFrame.mdpCount = numAppLayers;
894 mCurrentFrame.fbCount = 0;
895 mCurrentFrame.fbZ = -1;
896
897 for (int j = 0; j < numAppLayers; j++)
898 mCurrentFrame.isFBComposed[j] = false;
899
900 bool result = postHeuristicsHandling(ctx, list);
901
902 // Restore layer attributes
903 for (int i = 0; i < overlapIdx; i++) {
904 hwc_layer_1_t* layer = &list->hwLayers[i];
905 layer->displayFrame = displayFrame[i];
906 layer->sourceCropf.left = (float)sourceCrop[i].left;
907 layer->sourceCropf.top = (float)sourceCrop[i].top;
908 layer->sourceCropf.right = (float)sourceCrop[i].right;
909 layer->sourceCropf.bottom = (float)sourceCrop[i].bottom;
910 }
911
912 if (!result) {
913 mOverlapIndex = -1;
914 reset(ctx);
915 }
916
917 ALOGD_IF(isDebug(), "%s: Postheuristics %s!, Overlap index = %d",
918 __FUNCTION__, (result ? "successful" : "failed"), mOverlapIndex);
919 return result;
920}
921
Saurabh Shahaa236822013-04-24 18:07:26 -0700922bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
923{
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700924 if(!sEnableMixedMode) {
925 //Mixed mode is disabled. No need to even try caching.
926 return false;
927 }
928
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700929 bool ret = false;
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800930 if(list->flags & HWC_GEOMETRY_CHANGED) { //Try load based first
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800931 ret = loadBasedComp(ctx, list) or
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800932 cacheBasedComp(ctx, list);
933 } else {
934 ret = cacheBasedComp(ctx, list) or
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800935 loadBasedComp(ctx, list);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700936 }
937
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700938 return ret;
939}
940
941bool MDPComp::cacheBasedComp(hwc_context_t *ctx,
942 hwc_display_contents_1_t* list) {
Jeykumar Sankaran0ad97c42014-03-09 23:00:53 -0700943 if(sSimulationFlags & MDPCOMP_AVOID_CACHE_MDP)
944 return false;
945
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700946 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700947 mCurrentFrame.reset(numAppLayers);
948 updateLayerCache(ctx, list);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700949
950 //If an MDP marked layer is unsupported cannot do partial MDP Comp
951 for(int i = 0; i < numAppLayers; i++) {
952 if(!mCurrentFrame.isFBComposed[i]) {
953 hwc_layer_1_t* layer = &list->hwLayers[i];
954 if(not isSupportedForMDPComp(ctx, layer)) {
955 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",
956 __FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800957 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700958 return false;
959 }
960 }
961 }
962
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700963 updateYUV(ctx, list, false /*secure only*/);
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530964 bool ret = markLayersForCaching(ctx, list); //sets up fbZ also
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700965 if(!ret) {
966 ALOGD_IF(isDebug(),"%s: batching failed, dpy %d",__FUNCTION__, mDpy);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800967 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700968 return false;
969 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700970
971 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700972
radhakrishnac9a67412013-09-25 17:40:42 +0530973 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800974 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530975 }
976
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700977 //Will benefit cases where a video has non-updating background.
978 if((mDpy > HWC_DISPLAY_PRIMARY) and
979 (mdpCount > MAX_SEC_LAYERS)) {
980 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800981 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700982 return false;
983 }
984
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800985 if(!postHeuristicsHandling(ctx, list)) {
986 ALOGD_IF(isDebug(), "post heuristic handling failed");
987 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700988 return false;
989 }
Jeykumar Sankaran0ad97c42014-03-09 23:00:53 -0700990 ALOGD_IF(sSimulationFlags,"%s: CACHE_MDP_COMP SUCCEEDED",
991 __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700992
Saurabh Shahaa236822013-04-24 18:07:26 -0700993 return true;
994}
995
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800996bool MDPComp::loadBasedComp(hwc_context_t *ctx,
Saurabh Shahb772ae32013-11-18 15:40:02 -0800997 hwc_display_contents_1_t* list) {
Jeykumar Sankaran0ad97c42014-03-09 23:00:53 -0700998 if(sSimulationFlags & MDPCOMP_AVOID_LOAD_MDP)
999 return false;
1000
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001001 if(not isLoadBasedCompDoable(ctx)) {
Saurabh Shahf2de00f2013-12-11 17:52:53 -08001002 return false;
1003 }
1004
Saurabh Shahb772ae32013-11-18 15:40:02 -08001005 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahbe7bd322014-02-20 16:18:45 -08001006 const int numNonDroppedLayers = numAppLayers - mCurrentFrame.dropCount;
1007 const int stagesForMDP = min(sMaxPipesPerMixer,
1008 ctx->mOverlay->availablePipes(mDpy, Overlay::MIXER_DEFAULT));
Saurabh Shahf2de00f2013-12-11 17:52:53 -08001009
Saurabh Shahbe7bd322014-02-20 16:18:45 -08001010 int mdpBatchSize = stagesForMDP - 1; //1 stage for FB
1011 int fbBatchSize = numNonDroppedLayers - mdpBatchSize;
1012 int lastMDPSupportedIndex = numAppLayers;
1013 int dropCount = 0;
Saurabh Shahb772ae32013-11-18 15:40:02 -08001014
Saurabh Shahbe7bd322014-02-20 16:18:45 -08001015 //Find the minimum MDP batch size
1016 for(int i = 0; i < numAppLayers;i++) {
1017 if(mCurrentFrame.drop[i]) {
1018 dropCount++;
Jeykumar Sankaran846e2792014-01-23 21:59:58 -08001019 continue;
Saurabh Shahbe7bd322014-02-20 16:18:45 -08001020 }
1021 hwc_layer_1_t* layer = &list->hwLayers[i];
1022 if(not isSupportedForMDPComp(ctx, layer)) {
1023 lastMDPSupportedIndex = i;
1024 mdpBatchSize = min(i - dropCount, stagesForMDP - 1);
1025 fbBatchSize = numNonDroppedLayers - mdpBatchSize;
Jeykumar Sankaran846e2792014-01-23 21:59:58 -08001026 break;
Saurabh Shahb772ae32013-11-18 15:40:02 -08001027 }
Saurabh Shahb772ae32013-11-18 15:40:02 -08001028 }
1029
Saurabh Shahbe7bd322014-02-20 16:18:45 -08001030 ALOGD_IF(isDebug(), "%s:Before optimizing fbBatch, mdpbatch %d, fbbatch %d "
1031 "dropped %d", __FUNCTION__, mdpBatchSize, fbBatchSize,
1032 mCurrentFrame.dropCount);
1033
1034 //Start at a point where the fb batch should at least have 2 layers, for
1035 //this mode to be justified.
1036 while(fbBatchSize < 2) {
1037 ++fbBatchSize;
1038 --mdpBatchSize;
Jeykumar Sankaran846e2792014-01-23 21:59:58 -08001039 }
Saurabh Shahb772ae32013-11-18 15:40:02 -08001040
Saurabh Shahbe7bd322014-02-20 16:18:45 -08001041 //If there are no layers for MDP, this mode doesnt make sense.
1042 if(mdpBatchSize < 1) {
1043 ALOGD_IF(isDebug(), "%s: No MDP layers after optimizing for fbBatch",
1044 __FUNCTION__);
Saurabh Shahb772ae32013-11-18 15:40:02 -08001045 return false;
1046 }
1047
Saurabh Shahbe7bd322014-02-20 16:18:45 -08001048 mCurrentFrame.reset(numAppLayers);
1049
1050 //Try with successively smaller mdp batch sizes until we succeed or reach 1
1051 while(mdpBatchSize > 0) {
1052 //Mark layers for MDP comp
1053 int mdpBatchLeft = mdpBatchSize;
1054 for(int i = 0; i < lastMDPSupportedIndex and mdpBatchLeft; i++) {
1055 if(mCurrentFrame.drop[i]) {
1056 continue;
1057 }
1058 mCurrentFrame.isFBComposed[i] = false;
1059 --mdpBatchLeft;
1060 }
1061
1062 mCurrentFrame.fbZ = mdpBatchSize;
1063 mCurrentFrame.fbCount = fbBatchSize;
1064 mCurrentFrame.mdpCount = mdpBatchSize;
1065
1066 ALOGD_IF(isDebug(), "%s:Trying with: mdpbatch %d fbbatch %d dropped %d",
1067 __FUNCTION__, mdpBatchSize, fbBatchSize,
1068 mCurrentFrame.dropCount);
1069
1070 if(postHeuristicsHandling(ctx, list)) {
1071 ALOGD_IF(isDebug(), "%s: Postheuristics handling succeeded",
Jeykumar Sankaran0ad97c42014-03-09 23:00:53 -07001072 __FUNCTION__);
1073 ALOGD_IF(sSimulationFlags,"%s: LOAD_MDP_COMP SUCCEEDED",
1074 __FUNCTION__);
Saurabh Shahbe7bd322014-02-20 16:18:45 -08001075 return true;
1076 }
1077
1078 reset(ctx);
1079 --mdpBatchSize;
1080 ++fbBatchSize;
1081 }
1082
1083 return false;
Saurabh Shahb772ae32013-11-18 15:40:02 -08001084}
1085
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001086bool MDPComp::isLoadBasedCompDoable(hwc_context_t *ctx) {
Prabhanjan Kandula3dbbd882013-12-11 14:43:46 +05301087 if(mDpy or isSecurePresent(ctx, mDpy) or
1088 isYuvPresent(ctx, mDpy)) {
Saurabh Shah8028e3b2013-10-15 12:27:59 -07001089 return false;
1090 }
1091 return true;
1092}
1093
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001094bool MDPComp::canPartialUpdate(hwc_context_t *ctx,
1095 hwc_display_contents_1_t* list){
1096 if(!qdutils::MDPVersion::getInstance().isPartialUpdateEnabled() ||
1097 isSkipPresent(ctx, mDpy) || (list->flags & HWC_GEOMETRY_CHANGED) ||
1098 mDpy ) {
1099 return false;
1100 }
1101 return true;
1102}
1103
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001104bool MDPComp::tryVideoOnly(hwc_context_t *ctx,
1105 hwc_display_contents_1_t* list) {
1106 const bool secureOnly = true;
1107 return videoOnlyComp(ctx, list, not secureOnly) or
1108 videoOnlyComp(ctx, list, secureOnly);
1109}
1110
1111bool MDPComp::videoOnlyComp(hwc_context_t *ctx,
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001112 hwc_display_contents_1_t* list, bool secureOnly) {
Jeykumar Sankaran0ad97c42014-03-09 23:00:53 -07001113 if(sSimulationFlags & MDPCOMP_AVOID_VIDEO_ONLY)
1114 return false;
Saurabh Shahaa236822013-04-24 18:07:26 -07001115 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001116
Saurabh Shahaa236822013-04-24 18:07:26 -07001117 mCurrentFrame.reset(numAppLayers);
Jeykumar Sankaraneb3a5e22014-04-08 16:07:55 -07001118 mCurrentFrame.fbCount -= mCurrentFrame.dropCount;
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001119 updateYUV(ctx, list, secureOnly);
Saurabh Shah4fdde762013-04-30 18:47:33 -07001120 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001121
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001122 if(!isYuvPresent(ctx, mDpy) or (mdpCount == 0)) {
1123 reset(ctx);
Saurabh Shahaa236822013-04-24 18:07:26 -07001124 return false;
1125 }
1126
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -08001127 /* Bail out if we are processing only secured video layers
1128 * and we dont have any */
1129 if(!isSecurePresent(ctx, mDpy) && secureOnly){
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001130 reset(ctx);
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -08001131 return false;
1132 }
1133
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001134 if(mCurrentFrame.fbCount)
1135 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
Saurabh Shah4fdde762013-04-30 18:47:33 -07001136
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001137 if(sEnable4k2kYUVSplit){
1138 adjustForSourceSplit(ctx, list);
1139 }
1140
1141 if(!postHeuristicsHandling(ctx, list)) {
1142 ALOGD_IF(isDebug(), "post heuristic handling failed");
1143 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001144 return false;
1145 }
1146
Jeykumar Sankaran0ad97c42014-03-09 23:00:53 -07001147 ALOGD_IF(sSimulationFlags,"%s: VIDEO_ONLY_COMP SUCCEEDED",
1148 __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001149 return true;
1150}
1151
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001152/* Checks for conditions where YUV layers cannot be bypassed */
1153bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -07001154 if(isSkipLayer(layer)) {
Saurabh Shahe2474082013-05-15 16:32:13 -07001155 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001156 return false;
1157 }
1158
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -07001159 if(layer->transform & HWC_TRANSFORM_ROT_90 && !canUseRotator(ctx,mDpy)) {
1160 ALOGD_IF(isDebug(), "%s: no free DMA pipe",__FUNCTION__);
1161 return false;
1162 }
1163
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001164 if(isSecuring(ctx, layer)) {
1165 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
1166 return false;
1167 }
1168
Saurabh Shah4fdde762013-04-30 18:47:33 -07001169 if(!isValidDimension(ctx, layer)) {
1170 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
1171 __FUNCTION__);
1172 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001173 }
Saurabh Shah4fdde762013-04-30 18:47:33 -07001174
Naseer Ahmeddc61a972013-07-10 17:50:54 -04001175 if(layer->planeAlpha < 0xFF) {
1176 ALOGD_IF(isDebug(), "%s: Cannot handle YUV layer with plane alpha\
1177 in video only mode",
1178 __FUNCTION__);
1179 return false;
1180 }
1181
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001182 return true;
1183}
1184
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301185/* starts at fromIndex and check for each layer to find
1186 * if it it has overlapping with any Updating layer above it in zorder
1187 * till the end of the batch. returns true if it finds any intersection */
1188bool MDPComp::canPushBatchToTop(const hwc_display_contents_1_t* list,
1189 int fromIndex, int toIndex) {
1190 for(int i = fromIndex; i < toIndex; i++) {
1191 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
1192 if(intersectingUpdatingLayers(list, i+1, toIndex, i)) {
1193 return false;
1194 }
1195 }
1196 }
1197 return true;
1198}
1199
1200/* Checks if given layer at targetLayerIndex has any
1201 * intersection with all the updating layers in beween
1202 * fromIndex and toIndex. Returns true if it finds intersectiion */
1203bool MDPComp::intersectingUpdatingLayers(const hwc_display_contents_1_t* list,
1204 int fromIndex, int toIndex, int targetLayerIndex) {
1205 for(int i = fromIndex; i <= toIndex; i++) {
1206 if(!mCurrentFrame.isFBComposed[i]) {
1207 if(areLayersIntersecting(&list->hwLayers[i],
1208 &list->hwLayers[targetLayerIndex])) {
1209 return true;
1210 }
1211 }
1212 }
1213 return false;
1214}
1215
1216int MDPComp::getBatch(hwc_display_contents_1_t* list,
1217 int& maxBatchStart, int& maxBatchEnd,
1218 int& maxBatchCount) {
1219 int i = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301220 int fbZOrder =-1;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -08001221 int droppedLayerCt = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301222 while (i < mCurrentFrame.layerCount) {
1223 int batchCount = 0;
1224 int batchStart = i;
1225 int batchEnd = i;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -08001226 /* Adjust batch Z order with the dropped layers so far */
1227 int fbZ = batchStart - droppedLayerCt;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301228 int firstZReverseIndex = -1;
Prabhanjan Kandula0ed2cc92013-12-06 12:39:04 +05301229 int updatingLayersAbove = 0;//Updating layer count in middle of batch
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301230 while(i < mCurrentFrame.layerCount) {
1231 if(!mCurrentFrame.isFBComposed[i]) {
1232 if(!batchCount) {
1233 i++;
1234 break;
1235 }
1236 updatingLayersAbove++;
1237 i++;
1238 continue;
1239 } else {
1240 if(mCurrentFrame.drop[i]) {
1241 i++;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -08001242 droppedLayerCt++;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301243 continue;
1244 } else if(updatingLayersAbove <= 0) {
1245 batchCount++;
1246 batchEnd = i;
1247 i++;
1248 continue;
1249 } else { //Layer is FBComposed, not a drop & updatingLayer > 0
1250
1251 // We have a valid updating layer already. If layer-i not
1252 // have overlapping with all updating layers in between
1253 // batch-start and i, then we can add layer i to batch.
1254 if(!intersectingUpdatingLayers(list, batchStart, i-1, i)) {
1255 batchCount++;
1256 batchEnd = i;
1257 i++;
1258 continue;
1259 } else if(canPushBatchToTop(list, batchStart, i)) {
1260 //If All the non-updating layers with in this batch
1261 //does not have intersection with the updating layers
1262 //above in z-order, then we can safely move the batch to
1263 //higher z-order. Increment fbZ as it is moving up.
1264 if( firstZReverseIndex < 0) {
1265 firstZReverseIndex = i;
1266 }
1267 batchCount++;
1268 batchEnd = i;
1269 fbZ += updatingLayersAbove;
1270 i++;
1271 updatingLayersAbove = 0;
1272 continue;
1273 } else {
1274 //both failed.start the loop again from here.
1275 if(firstZReverseIndex >= 0) {
1276 i = firstZReverseIndex;
1277 }
1278 break;
1279 }
1280 }
1281 }
1282 }
1283 if(batchCount > maxBatchCount) {
1284 maxBatchCount = batchCount;
1285 maxBatchStart = batchStart;
1286 maxBatchEnd = batchEnd;
1287 fbZOrder = fbZ;
1288 }
1289 }
1290 return fbZOrder;
1291}
1292
1293bool MDPComp::markLayersForCaching(hwc_context_t* ctx,
1294 hwc_display_contents_1_t* list) {
1295 /* Idea is to keep as many non-updating(cached) layers in FB and
1296 * send rest of them through MDP. This is done in 2 steps.
1297 * 1. Find the maximum contiguous batch of non-updating layers.
1298 * 2. See if we can improve this batch size for caching by adding
1299 * opaque layers around the batch, if they don't have
1300 * any overlapping with the updating layers in between.
1301 * NEVER mark an updating layer for caching.
1302 * But cached ones can be marked for MDP */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001303
1304 int maxBatchStart = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001305 int maxBatchEnd = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001306 int maxBatchCount = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301307 int fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001308
Saurabh Shahd53bc5f2014-02-05 10:17:43 -08001309 /* Nothing is cached. No batching needed */
1310 if(mCurrentFrame.fbCount == 0) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001311 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -07001312 }
Saurabh Shahd53bc5f2014-02-05 10:17:43 -08001313
1314 /* No MDP comp layers, try to use other comp modes */
1315 if(mCurrentFrame.mdpCount == 0) {
1316 return false;
Saurabh Shahaa236822013-04-24 18:07:26 -07001317 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001318
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301319 fbZ = getBatch(list, maxBatchStart, maxBatchEnd, maxBatchCount);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001320
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301321 /* reset rest of the layers lying inside ROI for MDP comp */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001322 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001323 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001324 if((i < maxBatchStart || i > maxBatchEnd) &&
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301325 mCurrentFrame.isFBComposed[i]){
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001326 if(!mCurrentFrame.drop[i]){
1327 //If an unsupported layer is being attempted to
1328 //be pulled out we should fail
1329 if(not isSupportedForMDPComp(ctx, layer)) {
1330 return false;
1331 }
1332 mCurrentFrame.isFBComposed[i] = false;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001333 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001334 }
1335 }
1336
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301337 // update the frame data
1338 mCurrentFrame.fbZ = fbZ;
1339 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001340 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001341 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001342
1343 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301344 mCurrentFrame.fbCount);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001345
1346 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001347}
Saurabh Shah85234ec2013-04-12 17:09:00 -07001348
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001349void MDPComp::updateLayerCache(hwc_context_t* ctx,
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001350 hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001351 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001352 int fbCount = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001353
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001354 for(int i = 0; i < numAppLayers; i++) {
1355 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001356 if(!mCurrentFrame.drop[i])
1357 fbCount++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001358 mCurrentFrame.isFBComposed[i] = true;
1359 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -07001360 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001361 }
1362 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001363
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001364 mCurrentFrame.fbCount = fbCount;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001365 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount
1366 - mCurrentFrame.dropCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001367
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001368 ALOGD_IF(isDebug(),"%s: MDP count: %d FB count %d drop count: %d"
1369 ,__FUNCTION__, mCurrentFrame.mdpCount, mCurrentFrame.fbCount,
1370 mCurrentFrame.dropCount);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001371}
1372
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001373void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list,
1374 bool secureOnly) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001375 int nYuvCount = ctx->listStats[mDpy].yuvCount;
1376 for(int index = 0;index < nYuvCount; index++){
1377 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
1378 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
1379
1380 if(!isYUVDoable(ctx, layer)) {
1381 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
1382 mCurrentFrame.isFBComposed[nYuvIndex] = true;
1383 mCurrentFrame.fbCount++;
1384 }
1385 } else {
1386 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001387 private_handle_t *hnd = (private_handle_t *)layer->handle;
1388 if(!secureOnly || isSecureBuffer(hnd)) {
1389 mCurrentFrame.isFBComposed[nYuvIndex] = false;
1390 mCurrentFrame.fbCount--;
1391 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001392 }
1393 }
1394 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001395
1396 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001397 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
1398 ALOGD_IF(isDebug(),"%s: fb count: %d",__FUNCTION__,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001399 mCurrentFrame.fbCount);
1400}
1401
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001402hwc_rect_t MDPComp::getUpdatingFBRect(hwc_context_t *ctx,
1403 hwc_display_contents_1_t* list){
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001404 hwc_rect_t fbRect = (struct hwc_rect){0, 0, 0, 0};
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001405
1406 /* Update only the region of FB needed for composition */
1407 for(int i = 0; i < mCurrentFrame.layerCount; i++ ) {
1408 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
1409 hwc_layer_1_t* layer = &list->hwLayers[i];
1410 hwc_rect_t dst = layer->displayFrame;
1411 fbRect = getUnion(fbRect, dst);
1412 }
1413 }
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001414 trimAgainstROI(ctx, fbRect);
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001415 return fbRect;
1416}
1417
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001418bool MDPComp::postHeuristicsHandling(hwc_context_t *ctx,
1419 hwc_display_contents_1_t* list) {
1420
1421 //Capability checks
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301422 if(!resourceCheck()) {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001423 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
1424 return false;
1425 }
1426
1427 //Limitations checks
1428 if(!hwLimitationsCheck(ctx, list)) {
1429 ALOGD_IF(isDebug(), "%s: HW limitations",__FUNCTION__);
1430 return false;
1431 }
1432
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001433 //Configure framebuffer first if applicable
1434 if(mCurrentFrame.fbZ >= 0) {
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001435 hwc_rect_t fbRect = getUpdatingFBRect(ctx, list);
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001436 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, fbRect, mCurrentFrame.fbZ))
1437 {
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001438 ALOGD_IF(isDebug(), "%s configure framebuffer failed",
1439 __FUNCTION__);
1440 return false;
1441 }
1442 }
1443
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001444 mCurrentFrame.map();
1445
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001446 if(!allocLayerPipes(ctx, list)) {
1447 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -07001448 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001449 }
1450
1451 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001452 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001453 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001454 int mdpIndex = mCurrentFrame.layerToMDP[index];
1455 hwc_layer_1_t* layer = &list->hwLayers[index];
1456
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301457 //Leave fbZ for framebuffer. CACHE/GLES layers go here.
1458 if(mdpNextZOrder == mCurrentFrame.fbZ) {
1459 mdpNextZOrder++;
1460 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001461 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1462 cur_pipe->zOrder = mdpNextZOrder++;
1463
radhakrishnac9a67412013-09-25 17:40:42 +05301464 private_handle_t *hnd = (private_handle_t *)layer->handle;
1465 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1466 if(configure4k2kYuv(ctx, layer,
1467 mCurrentFrame.mdpToLayer[mdpIndex])
1468 != 0 ){
1469 ALOGD_IF(isDebug(), "%s: Failed to configure split pipes \
1470 for layer %d",__FUNCTION__, index);
1471 return false;
1472 }
1473 else{
1474 mdpNextZOrder++;
1475 }
1476 continue;
1477 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001478 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
1479 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
radhakrishnac9a67412013-09-25 17:40:42 +05301480 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -07001481 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001482 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001483 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001484 }
1485
Saurabh Shaha36be922013-12-16 18:18:39 -08001486 if(!ctx->mOverlay->validateAndSet(mDpy, ctx->dpyAttr[mDpy].fd)) {
1487 ALOGD_IF(isDebug(), "%s: Failed to validate and set overlay for dpy %d"
1488 ,__FUNCTION__, mDpy);
1489 return false;
1490 }
1491
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001492 setRedraw(ctx, list);
Saurabh Shahaa236822013-04-24 18:07:26 -07001493 return true;
1494}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001495
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301496bool MDPComp::resourceCheck() {
Saurabh Shah173f4242013-11-20 09:50:12 -08001497 const bool fbUsed = mCurrentFrame.fbCount;
1498 if(mCurrentFrame.mdpCount > sMaxPipesPerMixer - fbUsed) {
1499 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
1500 return false;
1501 }
Saurabh Shah173f4242013-11-20 09:50:12 -08001502 return true;
1503}
1504
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301505bool MDPComp::hwLimitationsCheck(hwc_context_t* ctx,
1506 hwc_display_contents_1_t* list) {
1507
1508 //A-family hw limitation:
1509 //If a layer need alpha scaling, MDP can not support.
1510 if(ctx->mMDP.version < qdutils::MDSS_V5) {
1511 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1512 if(!mCurrentFrame.isFBComposed[i] &&
1513 isAlphaScaled( &list->hwLayers[i])) {
1514 ALOGD_IF(isDebug(), "%s:frame needs alphaScaling",__FUNCTION__);
1515 return false;
1516 }
1517 }
1518 }
1519
1520 // On 8x26 & 8974 hw, we have a limitation of downscaling+blending.
1521 //If multiple layers requires downscaling and also they are overlapping
1522 //fall back to GPU since MDSS can not handle it.
1523 if(qdutils::MDPVersion::getInstance().is8x74v2() ||
1524 qdutils::MDPVersion::getInstance().is8x26()) {
1525 for(int i = 0; i < mCurrentFrame.layerCount-1; ++i) {
1526 hwc_layer_1_t* botLayer = &list->hwLayers[i];
1527 if(!mCurrentFrame.isFBComposed[i] &&
1528 isDownscaleRequired(botLayer)) {
1529 //if layer-i is marked for MDP and needs downscaling
1530 //check if any MDP layer on top of i & overlaps with layer-i
1531 for(int j = i+1; j < mCurrentFrame.layerCount; ++j) {
1532 hwc_layer_1_t* topLayer = &list->hwLayers[j];
1533 if(!mCurrentFrame.isFBComposed[j] &&
1534 isDownscaleRequired(topLayer)) {
1535 hwc_rect_t r = getIntersection(botLayer->displayFrame,
1536 topLayer->displayFrame);
1537 if(isValidRect(r))
1538 return false;
1539 }
1540 }
1541 }
1542 }
1543 }
1544 return true;
1545}
1546
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001547int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001548 int ret = 0;
Jeykumar Sankaran0ad97c42014-03-09 23:00:53 -07001549 char property[PROPERTY_VALUE_MAX];
1550
Raj Kamal4393eaa2014-06-06 13:45:20 +05301551 if(!ctx || !list) {
1552 ALOGE("%s: Invalid context or list",__FUNCTION__);
1553 mCachedFrame.reset();
1554 return -1;
1555 }
1556
1557 const int numLayers = ctx->listStats[mDpy].numAppLayers;
1558
Jeykumar Sankaran0ad97c42014-03-09 23:00:53 -07001559 if(property_get("debug.hwc.simulate", property, NULL) > 0) {
1560 int currentFlags = atoi(property);
1561 if(currentFlags != sSimulationFlags) {
1562 sSimulationFlags = currentFlags;
1563 ALOGE("%s: Simulation Flag read: 0x%x (%d)", __FUNCTION__,
1564 sSimulationFlags, sSimulationFlags);
1565 }
1566 }
Sushil Chauhandefd3522014-05-13 18:17:12 -07001567 mOverlapIndex = -1;
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -07001568
Raj Kamal9ed3d6b2014-02-07 16:15:17 +05301569 //Do not cache the information for next draw cycle.
1570 if(numLayers > MAX_NUM_APP_LAYERS or (!numLayers)) {
1571 ALOGI("%s: Unsupported layer count for mdp composition",
1572 __FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001573 mCachedFrame.reset();
1574 return -1;
1575 }
1576
Saurabh Shahb39f8152013-08-22 10:21:44 -07001577 //reset old data
1578 mCurrentFrame.reset(numLayers);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001579 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1580 mCurrentFrame.dropCount = 0;
Prabhanjan Kandula088bd892013-07-02 23:47:13 +05301581
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -07001582 // Detect the start of animation and fall back to GPU only once to cache
1583 // all the layers in FB and display FB content untill animation completes.
1584 if(ctx->listStats[mDpy].isDisplayAnimating) {
1585 mCurrentFrame.needsRedraw = false;
1586 if(ctx->mAnimationState[mDpy] == ANIMATION_STOPPED) {
1587 mCurrentFrame.needsRedraw = true;
1588 ctx->mAnimationState[mDpy] = ANIMATION_STARTED;
1589 }
1590 setMDPCompLayerFlags(ctx, list);
1591 mCachedFrame.updateCounts(mCurrentFrame);
1592 ret = -1;
1593 return ret;
1594 } else {
1595 ctx->mAnimationState[mDpy] = ANIMATION_STOPPED;
1596 }
1597
Saurabh Shahb39f8152013-08-22 10:21:44 -07001598 //Hard conditions, if not met, cannot do MDP comp
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001599 if(isFrameDoable(ctx)) {
1600 generateROI(ctx, list);
Saurabh Shahb39f8152013-08-22 10:21:44 -07001601
Raj Kamal4393eaa2014-06-06 13:45:20 +05301602 mModeOn = tryFullFrame(ctx, list) || tryVideoOnly(ctx, list);
1603 if(mModeOn) {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001604 setMDPCompLayerFlags(ctx, list);
1605 } else {
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001606 resetROI(ctx, mDpy);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001607 reset(ctx);
1608 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1609 mCurrentFrame.dropCount = 0;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001610 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001611 }
1612 } else {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001613 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
1614 __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001615 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001616 }
Saurabh Shahb39f8152013-08-22 10:21:44 -07001617
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001618 if(isDebug()) {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001619 ALOGD("GEOMETRY change: %d",
1620 (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001621 android::String8 sDump("");
Jeykumar Sankaran6850ac62014-05-27 10:07:26 -07001622 dump(sDump, ctx);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001623 ALOGD("%s",sDump.string());
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001624 }
1625
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001626 mCachedFrame.cacheAll(list);
1627 mCachedFrame.updateCounts(mCurrentFrame);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001628 return ret;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001629}
1630
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001631bool MDPComp::allocSplitVGPipesfor4k2k(hwc_context_t *ctx, int index) {
radhakrishnac9a67412013-09-25 17:40:42 +05301632
1633 bool bRet = true;
radhakrishnac9a67412013-09-25 17:40:42 +05301634 int mdpIndex = mCurrentFrame.layerToMDP[index];
1635 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
1636 info.pipeInfo = new MdpYUVPipeInfo;
1637 info.rot = NULL;
1638 MdpYUVPipeInfo& pipe_info = *(MdpYUVPipeInfo*)info.pipeInfo;
radhakrishnac9a67412013-09-25 17:40:42 +05301639
1640 pipe_info.lIndex = ovutils::OV_INVALID;
1641 pipe_info.rIndex = ovutils::OV_INVALID;
1642
Saurabh Shahc62f3982014-03-05 14:28:26 -08001643 Overlay::PipeSpecs pipeSpecs;
1644 pipeSpecs.formatClass = Overlay::FORMAT_YUV;
1645 pipeSpecs.needsScaling = true;
1646 pipeSpecs.dpy = mDpy;
1647 pipeSpecs.fb = false;
1648
1649 pipe_info.lIndex = ctx->mOverlay->getPipe(pipeSpecs);
radhakrishnac9a67412013-09-25 17:40:42 +05301650 if(pipe_info.lIndex == ovutils::OV_INVALID){
1651 bRet = false;
1652 ALOGD_IF(isDebug(),"%s: allocating first VG pipe failed",
1653 __FUNCTION__);
1654 }
Saurabh Shahc62f3982014-03-05 14:28:26 -08001655 pipe_info.rIndex = ctx->mOverlay->getPipe(pipeSpecs);
radhakrishnac9a67412013-09-25 17:40:42 +05301656 if(pipe_info.rIndex == ovutils::OV_INVALID){
1657 bRet = false;
1658 ALOGD_IF(isDebug(),"%s: allocating second VG pipe failed",
1659 __FUNCTION__);
1660 }
1661 return bRet;
1662}
Sushil Chauhandefd3522014-05-13 18:17:12 -07001663
1664int MDPComp::drawOverlap(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
1665 int fd = -1;
1666 if (mOverlapIndex != -1) {
1667 fd = ctx->mCopyBit[mDpy]->drawOverlap(ctx, list, mOverlapIndex);
1668 if (fd < 0) {
1669 ALOGD_IF(isDebug(),"%s: failed", __FUNCTION__);
1670 mOverlapIndex = -1;
1671 }
1672 }
1673 return fd;
1674}
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001675//=============MDPCompNonSplit==================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001676
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001677void MDPCompNonSplit::adjustForSourceSplit(hwc_context_t *ctx,
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001678 hwc_display_contents_1_t*) {
radhakrishnac9a67412013-09-25 17:40:42 +05301679 //As we split 4kx2k yuv layer and program to 2 VG pipes
1680 //(if available) increase mdpcount accordingly
1681 mCurrentFrame.mdpCount += ctx->listStats[mDpy].yuv4k2kCount;
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001682
1683 //If 4k2k Yuv layer split is possible, and if
1684 //fbz is above 4k2k layer, increment fb zorder by 1
1685 //as we split 4k2k layer and increment zorder for right half
1686 //of the layer
1687 if(mCurrentFrame.fbZ >= 0) {
1688 int n4k2kYuvCount = ctx->listStats[mDpy].yuv4k2kCount;
1689 for(int index = 0; index < n4k2kYuvCount; index++){
1690 int n4k2kYuvIndex =
1691 ctx->listStats[mDpy].yuv4k2kIndices[index];
Dileep Kumar Reddi4cff9282014-04-01 12:57:08 +05301692 if(mCurrentFrame.fbZ >= n4k2kYuvIndex){
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001693 mCurrentFrame.fbZ += 1;
1694 }
1695 }
1696 }
radhakrishnac9a67412013-09-25 17:40:42 +05301697}
1698
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001699/*
1700 * Configures pipe(s) for MDP composition
1701 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001702int MDPCompNonSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001703 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001704 MdpPipeInfoNonSplit& mdp_info =
1705 *(static_cast<MdpPipeInfoNonSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001706 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
1707 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1708 eIsFg isFg = IS_FG_OFF;
1709 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001710
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001711 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
1712 __FUNCTION__, layer, zOrder, dest);
1713
Saurabh Shah88e4d272013-09-03 13:31:29 -07001714 return configureNonSplit(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001715 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001716}
1717
Saurabh Shah88e4d272013-09-03 13:31:29 -07001718bool MDPCompNonSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001719 hwc_display_contents_1_t* list) {
1720 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001721
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001722 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001723
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001724 hwc_layer_1_t* layer = &list->hwLayers[index];
1725 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301726 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001727 if(allocSplitVGPipesfor4k2k(ctx, index)){
radhakrishnac9a67412013-09-25 17:40:42 +05301728 continue;
1729 }
1730 }
1731
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001732 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001733 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001734 info.pipeInfo = new MdpPipeInfoNonSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08001735 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001736 MdpPipeInfoNonSplit& pipe_info = *(MdpPipeInfoNonSplit*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001737
Saurabh Shahc62f3982014-03-05 14:28:26 -08001738 Overlay::PipeSpecs pipeSpecs;
1739 pipeSpecs.formatClass = isYuvBuffer(hnd) ?
1740 Overlay::FORMAT_YUV : Overlay::FORMAT_RGB;
1741 pipeSpecs.needsScaling = qhwc::needsScaling(layer) or
1742 (qdutils::MDPVersion::getInstance().is8x26() and
1743 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres > 1024);
1744 pipeSpecs.dpy = mDpy;
1745 pipeSpecs.fb = false;
Xu Yang1e686f62014-04-08 13:56:47 +08001746 pipeSpecs.numActiveDisplays = ctx->numActiveDisplays;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001747
Saurabh Shahc62f3982014-03-05 14:28:26 -08001748 pipe_info.index = ctx->mOverlay->getPipe(pipeSpecs);
1749
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001750 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001751 ALOGD_IF(isDebug(), "%s: Unable to get pipe", __FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001752 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001753 }
1754 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001755 return true;
1756}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001757
radhakrishnac9a67412013-09-25 17:40:42 +05301758int MDPCompNonSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1759 PipeLayerPair& PipeLayerPair) {
1760 MdpYUVPipeInfo& mdp_info =
1761 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1762 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1763 eIsFg isFg = IS_FG_OFF;
1764 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1765 eDest lDest = mdp_info.lIndex;
1766 eDest rDest = mdp_info.rIndex;
1767
1768 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1769 lDest, rDest, &PipeLayerPair.rot);
1770}
1771
Saurabh Shah88e4d272013-09-03 13:31:29 -07001772bool MDPCompNonSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001773
Raj Kamal4393eaa2014-06-06 13:45:20 +05301774 if(!isEnabled() or !mModeOn) {
1775 ALOGD_IF(isDebug(),"%s: MDP Comp not enabled/configured", __FUNCTION__);
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301776 return true;
1777 }
1778
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -08001779 // Set the Handle timeout to true for MDP or MIXED composition.
1780 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount) {
1781 sHandleTimeout = true;
1782 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001783
1784 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001785 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001786
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001787 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1788 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001789 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001790 if(mCurrentFrame.isFBComposed[i]) continue;
1791
Naseer Ahmed5b6708a2012-08-02 13:46:08 -07001792 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001793 private_handle_t *hnd = (private_handle_t *)layer->handle;
1794 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001795 if (!(layer->flags & HWC_COLOR_FILL)) {
1796 ALOGE("%s handle null", __FUNCTION__);
1797 return false;
1798 }
1799 // No PLAY for Color layer
1800 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1801 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001802 }
1803
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001804 int mdpIndex = mCurrentFrame.layerToMDP[i];
1805
radhakrishnac9a67412013-09-25 17:40:42 +05301806 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1807 {
1808 MdpYUVPipeInfo& pipe_info =
1809 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1810 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1811 ovutils::eDest indexL = pipe_info.lIndex;
1812 ovutils::eDest indexR = pipe_info.rIndex;
1813 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301814 uint32_t offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05301815 if(rot) {
1816 rot->queueBuffer(fd, offset);
1817 fd = rot->getDstMemId();
1818 offset = rot->getDstOffset();
1819 }
1820 if(indexL != ovutils::OV_INVALID) {
1821 ovutils::eDest destL = (ovutils::eDest)indexL;
1822 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1823 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1824 if (!ov.queueBuffer(fd, offset, destL)) {
1825 ALOGE("%s: queueBuffer failed for display:%d",
1826 __FUNCTION__, mDpy);
1827 return false;
1828 }
1829 }
1830
1831 if(indexR != ovutils::OV_INVALID) {
1832 ovutils::eDest destR = (ovutils::eDest)indexR;
1833 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1834 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1835 if (!ov.queueBuffer(fd, offset, destR)) {
1836 ALOGE("%s: queueBuffer failed for display:%d",
1837 __FUNCTION__, mDpy);
1838 return false;
1839 }
1840 }
1841 }
1842 else{
1843 MdpPipeInfoNonSplit& pipe_info =
Saurabh Shah88e4d272013-09-03 13:31:29 -07001844 *(MdpPipeInfoNonSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
radhakrishnac9a67412013-09-25 17:40:42 +05301845 ovutils::eDest dest = pipe_info.index;
1846 if(dest == ovutils::OV_INVALID) {
1847 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001848 return false;
radhakrishnac9a67412013-09-25 17:40:42 +05301849 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001850
radhakrishnac9a67412013-09-25 17:40:42 +05301851 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1852 continue;
1853 }
1854
Sushil Chauhandefd3522014-05-13 18:17:12 -07001855 if (!mDpy && (i == mOverlapIndex)) {
1856 hnd = ctx->mCopyBit[mDpy]->getCurrentRenderBuffer();
1857 }
1858
radhakrishnac9a67412013-09-25 17:40:42 +05301859 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1860 using pipe: %d", __FUNCTION__, layer,
1861 hnd, dest );
1862
1863 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301864 uint32_t offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05301865
1866 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1867 if(rot) {
1868 if(!rot->queueBuffer(fd, offset))
1869 return false;
1870 fd = rot->getDstMemId();
1871 offset = rot->getDstOffset();
1872 }
1873
1874 if (!ov.queueBuffer(fd, offset, dest)) {
1875 ALOGE("%s: queueBuffer failed for display:%d ",
1876 __FUNCTION__, mDpy);
1877 return false;
1878 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001879 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001880
1881 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001882 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001883 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001884}
1885
Saurabh Shah88e4d272013-09-03 13:31:29 -07001886//=============MDPCompSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001887
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001888void MDPCompSplit::adjustForSourceSplit(hwc_context_t *ctx,
radhakrishnac9a67412013-09-25 17:40:42 +05301889 hwc_display_contents_1_t* list){
1890 //if 4kx2k yuv layer is totally present in either in left half
1891 //or right half then try splitting the yuv layer to avoid decimation
1892 int n4k2kYuvCount = ctx->listStats[mDpy].yuv4k2kCount;
1893 const int lSplit = getLeftSplit(ctx, mDpy);
1894 for(int index = 0; index < n4k2kYuvCount; index++){
1895 int n4k2kYuvIndex = ctx->listStats[mDpy].yuv4k2kIndices[index];
1896 hwc_layer_1_t* layer = &list->hwLayers[n4k2kYuvIndex];
1897 hwc_rect_t dst = layer->displayFrame;
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001898 if((dst.left > lSplit) || (dst.right < lSplit)) {
radhakrishnac9a67412013-09-25 17:40:42 +05301899 mCurrentFrame.mdpCount += 1;
1900 }
Dileep Kumar Reddi4cff9282014-04-01 12:57:08 +05301901 if(mCurrentFrame.fbZ >= n4k2kYuvIndex){
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001902 mCurrentFrame.fbZ += 1;
1903 }
radhakrishnac9a67412013-09-25 17:40:42 +05301904 }
1905}
1906
Saurabh Shah88e4d272013-09-03 13:31:29 -07001907bool MDPCompSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Saurabh Shahc62f3982014-03-05 14:28:26 -08001908 MdpPipeInfoSplit& pipe_info) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001909
Saurabh Shahc62f3982014-03-05 14:28:26 -08001910 const int lSplit = getLeftSplit(ctx, mDpy);
1911 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001912 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001913 pipe_info.lIndex = ovutils::OV_INVALID;
1914 pipe_info.rIndex = ovutils::OV_INVALID;
1915
Saurabh Shahc62f3982014-03-05 14:28:26 -08001916 Overlay::PipeSpecs pipeSpecs;
1917 pipeSpecs.formatClass = isYuvBuffer(hnd) ?
1918 Overlay::FORMAT_YUV : Overlay::FORMAT_RGB;
1919 pipeSpecs.needsScaling = qhwc::needsScalingWithSplit(ctx, layer, mDpy);
1920 pipeSpecs.dpy = mDpy;
1921 pipeSpecs.mixer = Overlay::MIXER_LEFT;
1922 pipeSpecs.fb = false;
1923
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001924 // Acquire pipe only for the updating half
1925 hwc_rect_t l_roi = ctx->listStats[mDpy].lRoi;
1926 hwc_rect_t r_roi = ctx->listStats[mDpy].rRoi;
1927
1928 if (dst.left < lSplit && isValidRect(getIntersection(dst, l_roi))) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001929 pipe_info.lIndex = ctx->mOverlay->getPipe(pipeSpecs);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001930 if(pipe_info.lIndex == ovutils::OV_INVALID)
1931 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001932 }
1933
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001934 if(dst.right > lSplit && isValidRect(getIntersection(dst, r_roi))) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001935 pipeSpecs.mixer = Overlay::MIXER_RIGHT;
1936 pipe_info.rIndex = ctx->mOverlay->getPipe(pipeSpecs);
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001937 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001938 return false;
1939 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001940
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001941 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001942}
1943
Saurabh Shah88e4d272013-09-03 13:31:29 -07001944bool MDPCompSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001945 hwc_display_contents_1_t* list) {
1946 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001947
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001948 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001949
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001950 hwc_layer_1_t* layer = &list->hwLayers[index];
1951 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301952 hwc_rect_t dst = layer->displayFrame;
1953 const int lSplit = getLeftSplit(ctx, mDpy);
1954 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1955 if((dst.left > lSplit)||(dst.right < lSplit)){
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001956 if(allocSplitVGPipesfor4k2k(ctx, index)){
radhakrishnac9a67412013-09-25 17:40:42 +05301957 continue;
1958 }
1959 }
1960 }
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001961 int mdpIndex = mCurrentFrame.layerToMDP[index];
1962 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001963 info.pipeInfo = new MdpPipeInfoSplit;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001964 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001965 MdpPipeInfoSplit& pipe_info = *(MdpPipeInfoSplit*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001966
Saurabh Shahc62f3982014-03-05 14:28:26 -08001967 if(!acquireMDPPipes(ctx, layer, pipe_info)) {
1968 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type",
1969 __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001970 return false;
1971 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001972 }
1973 return true;
1974}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001975
radhakrishnac9a67412013-09-25 17:40:42 +05301976int MDPCompSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1977 PipeLayerPair& PipeLayerPair) {
1978 const int lSplit = getLeftSplit(ctx, mDpy);
1979 hwc_rect_t dst = layer->displayFrame;
1980 if((dst.left > lSplit)||(dst.right < lSplit)){
1981 MdpYUVPipeInfo& mdp_info =
1982 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1983 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1984 eIsFg isFg = IS_FG_OFF;
1985 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1986 eDest lDest = mdp_info.lIndex;
1987 eDest rDest = mdp_info.rIndex;
1988
1989 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1990 lDest, rDest, &PipeLayerPair.rot);
1991 }
1992 else{
1993 return configure(ctx, layer, PipeLayerPair);
1994 }
1995}
1996
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001997/*
1998 * Configures pipe(s) for MDP composition
1999 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07002000int MDPCompSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07002001 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07002002 MdpPipeInfoSplit& mdp_info =
2003 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08002004 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
2005 eIsFg isFg = IS_FG_OFF;
2006 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
2007 eDest lDest = mdp_info.lIndex;
2008 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08002009
2010 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
2011 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
2012
Saurabh Shah88e4d272013-09-03 13:31:29 -07002013 return configureSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08002014 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002015}
2016
Saurabh Shah88e4d272013-09-03 13:31:29 -07002017bool MDPCompSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002018
Raj Kamal4393eaa2014-06-06 13:45:20 +05302019 if(!isEnabled() or !mModeOn) {
2020 ALOGD_IF(isDebug(),"%s: MDP Comp not enabled/configured", __FUNCTION__);
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05302021 return true;
2022 }
2023
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -08002024 // Set the Handle timeout to true for MDP or MIXED composition.
2025 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount) {
2026 sHandleTimeout = true;
2027 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002028
Naseer Ahmed54821fe2012-11-28 18:44:38 -05002029 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08002030 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002031
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08002032 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
2033 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002034 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08002035 if(mCurrentFrame.isFBComposed[i]) continue;
2036
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002037 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08002038 private_handle_t *hnd = (private_handle_t *)layer->handle;
2039 if(!hnd) {
2040 ALOGE("%s handle null", __FUNCTION__);
2041 return false;
2042 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002043
2044 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
2045 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002046 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002047
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08002048 int mdpIndex = mCurrentFrame.layerToMDP[i];
2049
radhakrishnac9a67412013-09-25 17:40:42 +05302050 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
2051 {
2052 MdpYUVPipeInfo& pipe_info =
2053 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
2054 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
2055 ovutils::eDest indexL = pipe_info.lIndex;
2056 ovutils::eDest indexR = pipe_info.rIndex;
2057 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05302058 uint32_t offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05302059 if(rot) {
2060 rot->queueBuffer(fd, offset);
2061 fd = rot->getDstMemId();
2062 offset = rot->getDstOffset();
2063 }
2064 if(indexL != ovutils::OV_INVALID) {
2065 ovutils::eDest destL = (ovutils::eDest)indexL;
2066 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
2067 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
2068 if (!ov.queueBuffer(fd, offset, destL)) {
2069 ALOGE("%s: queueBuffer failed for display:%d",
2070 __FUNCTION__, mDpy);
2071 return false;
2072 }
2073 }
Saurabh Shahacf10202013-02-26 10:15:15 -08002074
radhakrishnac9a67412013-09-25 17:40:42 +05302075 if(indexR != ovutils::OV_INVALID) {
2076 ovutils::eDest destR = (ovutils::eDest)indexR;
2077 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
2078 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
2079 if (!ov.queueBuffer(fd, offset, destR)) {
2080 ALOGE("%s: queueBuffer failed for display:%d",
2081 __FUNCTION__, mDpy);
2082 return false;
2083 }
Saurabh Shaha9da08f2013-07-03 13:27:53 -07002084 }
2085 }
radhakrishnac9a67412013-09-25 17:40:42 +05302086 else{
2087 MdpPipeInfoSplit& pipe_info =
2088 *(MdpPipeInfoSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
2089 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07002090
radhakrishnac9a67412013-09-25 17:40:42 +05302091 ovutils::eDest indexL = pipe_info.lIndex;
2092 ovutils::eDest indexR = pipe_info.rIndex;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002093
Sushil Chauhandefd3522014-05-13 18:17:12 -07002094 if (!mDpy && (i == mOverlapIndex)) {
2095 hnd = ctx->mCopyBit[mDpy]->getCurrentRenderBuffer();
2096 }
2097
radhakrishnac9a67412013-09-25 17:40:42 +05302098 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05302099 int offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05302100
Tatenda Chipeperekwa88fe6352014-04-14 10:36:06 -07002101 if(ctx->mAD->draw(ctx, fd, offset)) {
2102 fd = ctx->mAD->getDstFd();
2103 offset = ctx->mAD->getDstOffset();
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002104 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002105
radhakrishnac9a67412013-09-25 17:40:42 +05302106 if(rot) {
2107 rot->queueBuffer(fd, offset);
2108 fd = rot->getDstMemId();
2109 offset = rot->getDstOffset();
2110 }
2111
2112 //************* play left mixer **********
2113 if(indexL != ovutils::OV_INVALID) {
2114 ovutils::eDest destL = (ovutils::eDest)indexL;
2115 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
2116 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
2117 if (!ov.queueBuffer(fd, offset, destL)) {
2118 ALOGE("%s: queueBuffer failed for left mixer",
2119 __FUNCTION__);
2120 return false;
2121 }
2122 }
2123
2124 //************* play right mixer **********
2125 if(indexR != ovutils::OV_INVALID) {
2126 ovutils::eDest destR = (ovutils::eDest)indexR;
2127 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
2128 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
2129 if (!ov.queueBuffer(fd, offset, destR)) {
2130 ALOGE("%s: queueBuffer failed for right mixer",
2131 __FUNCTION__);
2132 return false;
2133 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002134 }
2135 }
Saurabh Shahacf10202013-02-26 10:15:15 -08002136
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002137 layerProp[i].mFlags &= ~HWC_MDPCOMP;
2138 }
Saurabh Shahacf10202013-02-26 10:15:15 -08002139
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002140 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002141}
Saurabh Shahab47c692014-02-12 18:45:57 -08002142
2143//================MDPCompSrcSplit==============================================
2144bool MDPCompSrcSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Saurabh Shahc62f3982014-03-05 14:28:26 -08002145 MdpPipeInfoSplit& pipe_info) {
Saurabh Shahab47c692014-02-12 18:45:57 -08002146 private_handle_t *hnd = (private_handle_t *)layer->handle;
2147 hwc_rect_t dst = layer->displayFrame;
2148 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
2149 pipe_info.lIndex = ovutils::OV_INVALID;
2150 pipe_info.rIndex = ovutils::OV_INVALID;
2151
2152 //If 2 pipes are staged on a single stage of a mixer, then the left pipe
2153 //should have a higher priority than the right one. Pipe priorities are
2154 //starting with VG0, VG1 ... , RGB0 ..., DMA1
Saurabh Shahab47c692014-02-12 18:45:57 -08002155
Saurabh Shahc62f3982014-03-05 14:28:26 -08002156 Overlay::PipeSpecs pipeSpecs;
2157 pipeSpecs.formatClass = isYuvBuffer(hnd) ?
2158 Overlay::FORMAT_YUV : Overlay::FORMAT_RGB;
2159 pipeSpecs.needsScaling = qhwc::needsScaling(layer);
2160 pipeSpecs.dpy = mDpy;
2161 pipeSpecs.fb = false;
2162
Saurabh Shahab47c692014-02-12 18:45:57 -08002163 //1 pipe by default for a layer
Saurabh Shahc62f3982014-03-05 14:28:26 -08002164 pipe_info.lIndex = ctx->mOverlay->getPipe(pipeSpecs);
Saurabh Shahab47c692014-02-12 18:45:57 -08002165 if(pipe_info.lIndex == ovutils::OV_INVALID) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08002166 return false;
Saurabh Shahab47c692014-02-12 18:45:57 -08002167 }
2168
2169 //If layer's crop width or dest width > 2048, use 2 pipes
2170 if((dst.right - dst.left) > qdutils::MAX_DISPLAY_DIM or
2171 (crop.right - crop.left) > qdutils::MAX_DISPLAY_DIM) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08002172 pipe_info.rIndex = ctx->mOverlay->getPipe(pipeSpecs);
Saurabh Shahab47c692014-02-12 18:45:57 -08002173 if(pipe_info.rIndex == ovutils::OV_INVALID) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08002174 return false;
Saurabh Shahdd8237a2014-02-28 14:29:09 -08002175 }
2176
2177 // Return values
2178 // 1 Left pipe is higher priority, do nothing.
2179 // 0 Pipes of same priority.
2180 //-1 Right pipe is of higher priority, needs swap.
2181 if(ctx->mOverlay->comparePipePriority(pipe_info.lIndex,
2182 pipe_info.rIndex) == -1) {
2183 qhwc::swap(pipe_info.lIndex, pipe_info.rIndex);
Saurabh Shahab47c692014-02-12 18:45:57 -08002184 }
2185 }
2186
2187 return true;
2188}
2189
Saurabh Shahab47c692014-02-12 18:45:57 -08002190int MDPCompSrcSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
2191 PipeLayerPair& PipeLayerPair) {
2192 private_handle_t *hnd = (private_handle_t *)layer->handle;
2193 if(!hnd) {
2194 ALOGE("%s: layer handle is NULL", __FUNCTION__);
2195 return -1;
2196 }
2197 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
2198 MdpPipeInfoSplit& mdp_info =
2199 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
2200 Rotator **rot = &PipeLayerPair.rot;
2201 eZorder z = static_cast<eZorder>(mdp_info.zOrder);
2202 eIsFg isFg = IS_FG_OFF;
2203 eDest lDest = mdp_info.lIndex;
2204 eDest rDest = mdp_info.rIndex;
2205 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
2206 hwc_rect_t dst = layer->displayFrame;
2207 int transform = layer->transform;
2208 eTransform orient = static_cast<eTransform>(transform);
2209 const int downscale = 0;
2210 int rotFlags = ROT_FLAGS_NONE;
2211 uint32_t format = ovutils::getMdpFormat(hnd->format, isTileRendered(hnd));
2212 Whf whf(getWidth(hnd), getHeight(hnd), format, hnd->size);
2213
2214 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
2215 "dest_pipeR: %d",__FUNCTION__, layer, z, lDest, rDest);
2216
2217 // Handle R/B swap
2218 if (layer->flags & HWC_FORMAT_RB_SWAP) {
2219 if (hnd->format == HAL_PIXEL_FORMAT_RGBA_8888)
2220 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRA_8888);
2221 else if (hnd->format == HAL_PIXEL_FORMAT_RGBX_8888)
2222 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRX_8888);
2223 }
2224
Saurabh Shah97e2d802014-04-14 18:03:54 -07002225 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
2226 setMdpFlags(layer, mdpFlags, 0, transform);
Saurabh Shahab47c692014-02-12 18:45:57 -08002227
2228 if(lDest != OV_INVALID && rDest != OV_INVALID) {
2229 //Enable overfetch
Saurabh Shah97e2d802014-04-14 18:03:54 -07002230 setMdpFlags(mdpFlags, OV_MDSS_MDP_DUAL_PIPE);
Saurabh Shahab47c692014-02-12 18:45:57 -08002231 }
2232
2233 if(isYuvBuffer(hnd) && (transform & HWC_TRANSFORM_ROT_90)) {
2234 (*rot) = ctx->mRotMgr->getNext();
2235 if((*rot) == NULL) return -1;
Saurabh Shah39240c92014-03-31 10:31:42 -07002236 ctx->mLayerRotMap[mDpy]->add(layer, *rot);
Saurabh Shah1bd5b6f2014-05-19 12:23:13 -07002237 //If the video is using a single pipe, enable BWC
2238 if(rDest == OV_INVALID) {
2239 BwcPM::setBwc(crop, dst, transform, mdpFlags);
2240 }
Saurabh Shahab47c692014-02-12 18:45:57 -08002241 //Configure rotator for pre-rotation
Saurabh Shah97e2d802014-04-14 18:03:54 -07002242 if(configRotator(*rot, whf, crop, mdpFlags, orient, downscale) < 0) {
Saurabh Shahab47c692014-02-12 18:45:57 -08002243 ALOGE("%s: configRotator failed!", __FUNCTION__);
2244 return -1;
2245 }
Saurabh Shahab47c692014-02-12 18:45:57 -08002246 whf.format = (*rot)->getDstFormat();
2247 updateSource(orient, whf, crop);
2248 rotFlags |= ROT_PREROTATED;
2249 }
2250
2251 //If 2 pipes being used, divide layer into half, crop and dst
2252 hwc_rect_t cropL = crop;
2253 hwc_rect_t cropR = crop;
2254 hwc_rect_t dstL = dst;
2255 hwc_rect_t dstR = dst;
2256 if(lDest != OV_INVALID && rDest != OV_INVALID) {
2257 cropL.right = (crop.right + crop.left) / 2;
2258 cropR.left = cropL.right;
2259 sanitizeSourceCrop(cropL, cropR, hnd);
2260
2261 //Swap crops on H flip since 2 pipes are being used
2262 if((orient & OVERLAY_TRANSFORM_FLIP_H) && (*rot) == NULL) {
2263 hwc_rect_t tmp = cropL;
2264 cropL = cropR;
2265 cropR = tmp;
2266 }
2267
2268 dstL.right = (dst.right + dst.left) / 2;
2269 dstR.left = dstL.right;
2270 }
2271
2272 //For the mdp, since either we are pre-rotating or MDP does flips
2273 orient = OVERLAY_TRANSFORM_0;
2274 transform = 0;
2275
2276 //configure left pipe
2277 if(lDest != OV_INVALID) {
Saurabh Shah97e2d802014-04-14 18:03:54 -07002278 PipeArgs pargL(mdpFlags, whf, z, isFg,
Saurabh Shahab47c692014-02-12 18:45:57 -08002279 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2280 (ovutils::eBlending) getBlending(layer->blending));
2281
2282 if(configMdp(ctx->mOverlay, pargL, orient,
2283 cropL, dstL, metadata, lDest) < 0) {
2284 ALOGE("%s: commit failed for left mixer config", __FUNCTION__);
2285 return -1;
2286 }
2287 }
2288
2289 //configure right pipe
2290 if(rDest != OV_INVALID) {
Saurabh Shah97e2d802014-04-14 18:03:54 -07002291 PipeArgs pargR(mdpFlags, whf, z, isFg,
Saurabh Shahab47c692014-02-12 18:45:57 -08002292 static_cast<eRotFlags>(rotFlags),
2293 layer->planeAlpha,
2294 (ovutils::eBlending) getBlending(layer->blending));
2295 if(configMdp(ctx->mOverlay, pargR, orient,
2296 cropR, dstR, metadata, rDest) < 0) {
2297 ALOGE("%s: commit failed for right mixer config", __FUNCTION__);
2298 return -1;
2299 }
2300 }
2301
2302 return 0;
2303}
2304
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002305}; //namespace
2306