blob: 8b641934cee7189cc5b95eef397e68539672f056 [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
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700186void MDPComp::timeout_handler(void *udata) {
187 struct hwc_context_t* ctx = (struct hwc_context_t*)(udata);
188
189 if(!ctx) {
190 ALOGE("%s: received empty data in timer callback", __FUNCTION__);
191 return;
192 }
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -0800193 Locker::Autolock _l(ctx->mDrawLock);
194 // Handle timeout event only if the previous composition is MDP or MIXED.
195 if(!sHandleTimeout) {
196 ALOGD_IF(isDebug(), "%s:Do not handle this timeout", __FUNCTION__);
197 return;
198 }
Jesse Hall3be78d92012-08-21 15:12:23 -0700199 if(!ctx->proc) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700200 ALOGE("%s: HWC proc not registered", __FUNCTION__);
201 return;
202 }
203 sIdleFallBack = true;
204 /* Trigger SF to redraw the current frame */
Jesse Hall3be78d92012-08-21 15:12:23 -0700205 ctx->proc->invalidate(ctx->proc);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700206}
207
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800208void MDPComp::setMDPCompLayerFlags(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800209 hwc_display_contents_1_t* list) {
210 LayerProp *layerProp = ctx->layerProp[mDpy];
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800211
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800212 for(int index = 0; index < ctx->listStats[mDpy].numAppLayers; index++) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800213 hwc_layer_1_t* layer = &(list->hwLayers[index]);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800214 if(!mCurrentFrame.isFBComposed[index]) {
215 layerProp[index].mFlags |= HWC_MDPCOMP;
216 layer->compositionType = HWC_OVERLAY;
217 layer->hints |= HWC_HINT_CLEAR_FB;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800218 } else {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700219 /* Drop the layer when its already present in FB OR when it lies
220 * outside frame's ROI */
221 if(!mCurrentFrame.needsRedraw || mCurrentFrame.drop[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800222 layer->compositionType = HWC_OVERLAY;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700223 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800224 }
225 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700226}
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500227
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800228void MDPComp::setRedraw(hwc_context_t *ctx,
229 hwc_display_contents_1_t* list) {
230 mCurrentFrame.needsRedraw = false;
231 if(!mCachedFrame.isSameFrame(mCurrentFrame, list) ||
232 (list->flags & HWC_GEOMETRY_CHANGED) ||
233 isSkipPresent(ctx, mDpy)) {
234 mCurrentFrame.needsRedraw = true;
235 }
236}
237
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800238MDPComp::FrameInfo::FrameInfo() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700239 reset(0);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800240}
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800241
Saurabh Shahaa236822013-04-24 18:07:26 -0700242void MDPComp::FrameInfo::reset(const int& numLayers) {
243 for(int i = 0 ; i < MAX_PIPES_PER_MIXER && numLayers; i++ ) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800244 if(mdpToLayer[i].pipeInfo) {
245 delete mdpToLayer[i].pipeInfo;
246 mdpToLayer[i].pipeInfo = NULL;
247 //We dont own the rotator
248 mdpToLayer[i].rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800249 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800250 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800251
252 memset(&mdpToLayer, 0, sizeof(mdpToLayer));
253 memset(&layerToMDP, -1, sizeof(layerToMDP));
Saurabh Shahaa236822013-04-24 18:07:26 -0700254 memset(&isFBComposed, 1, sizeof(isFBComposed));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800255
Saurabh Shahaa236822013-04-24 18:07:26 -0700256 layerCount = numLayers;
257 fbCount = numLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800258 mdpCount = 0;
Saurabh Shah2f3895f2013-05-02 10:13:31 -0700259 needsRedraw = true;
Saurabh Shahd53bc5f2014-02-05 10:17:43 -0800260 fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800261}
262
Saurabh Shahaa236822013-04-24 18:07:26 -0700263void MDPComp::FrameInfo::map() {
264 // populate layer and MDP maps
265 int mdpIdx = 0;
266 for(int idx = 0; idx < layerCount; idx++) {
267 if(!isFBComposed[idx]) {
268 mdpToLayer[mdpIdx].listIndex = idx;
269 layerToMDP[idx] = mdpIdx++;
270 }
271 }
272}
273
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800274MDPComp::LayerCache::LayerCache() {
275 reset();
276}
277
278void MDPComp::LayerCache::reset() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700279 memset(&hnd, 0, sizeof(hnd));
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530280 memset(&isFBComposed, true, sizeof(isFBComposed));
281 memset(&drop, false, sizeof(drop));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800282 layerCount = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -0700283}
284
285void MDPComp::LayerCache::cacheAll(hwc_display_contents_1_t* list) {
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530286 const int numAppLayers = (int)list->numHwLayers - 1;
Saurabh Shahaa236822013-04-24 18:07:26 -0700287 for(int i = 0; i < numAppLayers; i++) {
288 hnd[i] = list->hwLayers[i].handle;
289 }
290}
291
292void MDPComp::LayerCache::updateCounts(const FrameInfo& curFrame) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700293 layerCount = curFrame.layerCount;
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530294 memcpy(&isFBComposed, &curFrame.isFBComposed, sizeof(isFBComposed));
295 memcpy(&drop, &curFrame.drop, sizeof(drop));
296}
297
Jeykumar Sankaran988d3682013-11-15 11:57:16 -0800298bool MDPComp::LayerCache::isSameFrame(const FrameInfo& curFrame,
299 hwc_display_contents_1_t* list) {
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530300 if(layerCount != curFrame.layerCount)
301 return false;
302 for(int i = 0; i < curFrame.layerCount; i++) {
303 if((curFrame.isFBComposed[i] != isFBComposed[i]) ||
304 (curFrame.drop[i] != drop[i])) {
305 return false;
306 }
Jeykumar Sankaran988d3682013-11-15 11:57:16 -0800307 if(curFrame.isFBComposed[i] &&
308 (hnd[i] != list->hwLayers[i].handle)){
309 return false;
310 }
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530311 }
312 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800313}
314
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700315bool MDPComp::isSupportedForMDPComp(hwc_context_t *ctx, hwc_layer_1_t* layer) {
316 private_handle_t *hnd = (private_handle_t *)layer->handle;
317 if((not isYuvBuffer(hnd) and has90Transform(layer)) or
318 (not isValidDimension(ctx,layer))
319 //More conditions here, SKIP, sRGB+Blend etc
320 ) {
321 return false;
322 }
323 return true;
324}
325
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530326bool MDPComp::isValidDimension(hwc_context_t *ctx, hwc_layer_1_t *layer) {
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800327 private_handle_t *hnd = (private_handle_t *)layer->handle;
328
329 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -0700330 if (layer->flags & HWC_COLOR_FILL) {
331 // Color layer
332 return true;
333 }
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800334 ALOGE("%s: layer handle is NULL", __FUNCTION__);
335 return false;
336 }
337
Naseer Ahmede850a802013-09-06 13:12:52 -0400338 //XXX: Investigate doing this with pixel phase on MDSS
Naseer Ahmede77f8082013-10-10 13:42:48 -0400339 if(!isSecureBuffer(hnd) && isNonIntegralSourceCrop(layer->sourceCropf))
Naseer Ahmede850a802013-09-06 13:12:52 -0400340 return false;
341
Saurabh Shah62e1d732013-09-17 10:44:05 -0700342 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700343 hwc_rect_t dst = layer->displayFrame;
Saurabh Shah4fdde762013-04-30 18:47:33 -0700344 int crop_w = crop.right - crop.left;
345 int crop_h = crop.bottom - crop.top;
346 int dst_w = dst.right - dst.left;
347 int dst_h = dst.bottom - dst.top;
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800348 float w_scale = ((float)crop_w / (float)dst_w);
349 float h_scale = ((float)crop_h / (float)dst_h);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700350
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800351 /* Workaround for MDP HW limitation in DSI command mode panels where
352 * FPS will not go beyond 30 if buffers on RGB pipes are of width or height
353 * less than 5 pixels
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530354 * There also is a HW limilation in MDP, minimum block size is 2x2
355 * Fallback to GPU if height is less than 2.
356 */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800357 if((crop_w < 5)||(crop_h < 5))
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800358 return false;
359
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800360 if((w_scale > 1.0f) || (h_scale > 1.0f)) {
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700361 const uint32_t maxMDPDownscale =
Saurabh Shah4fdde762013-04-30 18:47:33 -0700362 qdutils::MDPVersion::getInstance().getMaxMDPDownscale();
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800363 const float w_dscale = w_scale;
364 const float h_dscale = h_scale;
365
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800366 if(ctx->mMDP.version >= qdutils::MDSS_V5) {
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700367
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800368 if(!qdutils::MDPVersion::getInstance().supportsDecimation()) {
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700369 /* On targets that doesnt support Decimation (eg.,8x26)
370 * maximum downscale support is overlay pipe downscale.
371 */
372 if(crop_w > MAX_DISPLAY_DIM || w_dscale > maxMDPDownscale ||
373 h_dscale > maxMDPDownscale)
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800374 return false;
375 } else {
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700376 // Decimation on macrotile format layers is not supported.
377 if(isTileRendered(hnd)) {
378 /* MDP can read maximum MAX_DISPLAY_DIM width.
379 * Bail out if
380 * 1. Src crop > MAX_DISPLAY_DIM on nonsplit MDPComp
381 * 2. exceeds maximum downscale limit
382 */
383 if(((crop_w > MAX_DISPLAY_DIM) && !sSrcSplitEnabled) ||
384 w_dscale > maxMDPDownscale ||
385 h_dscale > maxMDPDownscale) {
386 return false;
387 }
388 } else if(w_dscale > 64 || h_dscale > 64)
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800389 return false;
390 }
391 } else { //A-family
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700392 if(w_dscale > maxMDPDownscale || h_dscale > maxMDPDownscale)
Saurabh Shah4fdde762013-04-30 18:47:33 -0700393 return false;
394 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700395 }
396
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800397 if((w_scale < 1.0f) || (h_scale < 1.0f)) {
398 const uint32_t upscale =
399 qdutils::MDPVersion::getInstance().getMaxMDPUpscale();
400 const float w_uscale = 1.0f / w_scale;
401 const float h_uscale = 1.0f / h_scale;
402
403 if(w_uscale > upscale || h_uscale > upscale)
404 return false;
405 }
406
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800407 return true;
408}
409
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800410bool MDPComp::isFrameDoable(hwc_context_t *ctx) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700411 bool ret = true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800412
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800413 if(!isEnabled()) {
414 ALOGD_IF(isDebug(),"%s: MDP Comp. not enabled.", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700415 ret = false;
Raj Kamal068f4572014-04-14 16:14:06 +0530416 } else if((qdutils::MDPVersion::getInstance().is8x26() ||
Prabhanjan Kandula958ffa92014-05-12 14:56:56 +0530417 qdutils::MDPVersion::getInstance().is8x16() ||
418 qdutils::MDPVersion::getInstance().is8x39()) &&
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -0800419 ctx->mVideoTransFlag &&
420 isSecondaryConnected(ctx)) {
Saurabh Shahd4e65852013-06-17 11:33:53 -0700421 //1 Padding round to shift pipes across mixers
422 ALOGD_IF(isDebug(),"%s: MDP Comp. video transition padding round",
423 __FUNCTION__);
424 ret = false;
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -0800425 } else if(isSecondaryConfiguring(ctx)) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800426 ALOGD_IF( isDebug(),"%s: External Display connection is pending",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800427 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700428 ret = false;
Saurabh Shahaa236822013-04-24 18:07:26 -0700429 } else if(ctx->isPaddingRound) {
Raj Kamal9ed3d6b2014-02-07 16:15:17 +0530430 ALOGD_IF(isDebug(), "%s: padding round invoked for dpy %d",
431 __FUNCTION__,mDpy);
Saurabh Shahaa236822013-04-24 18:07:26 -0700432 ret = false;
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700433 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700434 return ret;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800435}
436
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800437void MDPCompNonSplit::trimAgainstROI(hwc_context_t *ctx, hwc_rect_t& fbRect) {
438 hwc_rect_t roi = ctx->listStats[mDpy].lRoi;
439 fbRect = getIntersection(fbRect, roi);
440}
441
442/* 1) Identify layers that are not visible or lying outside the updating ROI and
443 * drop them from composition.
444 * 2) If we have a scaling layer which needs cropping against generated
445 * ROI, reset ROI to full resolution. */
446bool MDPCompNonSplit::validateAndApplyROI(hwc_context_t *ctx,
447 hwc_display_contents_1_t* list) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700448 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800449 hwc_rect_t visibleRect = ctx->listStats[mDpy].lRoi;
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800450
451 for(int i = numAppLayers - 1; i >= 0; i--){
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800452 if(!isValidRect(visibleRect)) {
453 mCurrentFrame.drop[i] = true;
454 mCurrentFrame.dropCount++;
Jeykumar Sankaran0b961452014-01-21 17:26:12 -0800455 continue;
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800456 }
457
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700458 const hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700459 hwc_rect_t dstRect = layer->displayFrame;
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800460 hwc_rect_t res = getIntersection(visibleRect, dstRect);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700461
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700462 if(!isValidRect(res)) {
463 mCurrentFrame.drop[i] = true;
464 mCurrentFrame.dropCount++;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800465 } else {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700466 /* Reset frame ROI when any layer which needs scaling also needs ROI
467 * cropping */
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800468 if(!isSameRect(res, dstRect) && needsScaling (layer)) {
Arpita Banerjeed8965982013-11-08 17:27:33 -0800469 ALOGI("%s: Resetting ROI due to scaling", __FUNCTION__);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700470 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
471 mCurrentFrame.dropCount = 0;
472 return false;
473 }
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800474
Jeykumar Sankaran0b961452014-01-21 17:26:12 -0800475 /* deduct any opaque region from visibleRect */
476 if (layer->blending == HWC_BLENDING_NONE)
477 visibleRect = deductRect(visibleRect, res);
478 }
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700479 }
480 return true;
481}
482
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800483/* Calculate ROI for the frame by accounting all the layer's dispalyFrame which
484 * are updating. If DirtyRegion is applicable, calculate it by accounting all
485 * the changing layer's dirtyRegion. */
486void MDPCompNonSplit::generateROI(hwc_context_t *ctx,
487 hwc_display_contents_1_t* list) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700488 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800489 if(!canPartialUpdate(ctx, list))
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700490 return;
491
492 struct hwc_rect roi = (struct hwc_rect){0, 0, 0, 0};
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800493 hwc_rect fullFrame = (struct hwc_rect) {0, 0,(int)ctx->dpyAttr[mDpy].xres,
494 (int)ctx->dpyAttr[mDpy].yres};
495
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700496 for(int index = 0; index < numAppLayers; index++ ) {
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800497 hwc_layer_1_t* layer = &list->hwLayers[index];
498 if ((mCachedFrame.hnd[index] != layer->handle) ||
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800499 isYuvBuffer((private_handle_t *)layer->handle)) {
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800500 hwc_rect_t updatingRect = layer->displayFrame;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800501
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800502#ifdef QCOM_BSP
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800503 if(!needsScaling(layer) && !layer->transform)
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800504 updatingRect = layer->dirtyRect;
505#endif
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800506
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800507 roi = getUnion(roi, updatingRect);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700508 }
509 }
510
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800511 /* No layer is updating. Still SF wants a refresh.*/
512 if(!isValidRect(roi))
513 return;
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800514
515 // Align ROI coordinates to panel restrictions
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800516 roi = getSanitizeROI(roi, fullFrame);
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800517
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800518 ctx->listStats[mDpy].lRoi = roi;
519 if(!validateAndApplyROI(ctx, list))
520 resetROI(ctx, mDpy);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700521
522 ALOGD_IF(isDebug(),"%s: generated ROI: [%d, %d, %d, %d]", __FUNCTION__,
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800523 ctx->listStats[mDpy].lRoi.left, ctx->listStats[mDpy].lRoi.top,
524 ctx->listStats[mDpy].lRoi.right, ctx->listStats[mDpy].lRoi.bottom);
525}
526
527void MDPCompSplit::trimAgainstROI(hwc_context_t *ctx, hwc_rect_t& fbRect) {
528 hwc_rect l_roi = ctx->listStats[mDpy].lRoi;
529 hwc_rect r_roi = ctx->listStats[mDpy].rRoi;
530
531 hwc_rect_t l_fbRect = getIntersection(fbRect, l_roi);
532 hwc_rect_t r_fbRect = getIntersection(fbRect, r_roi);
533 fbRect = getUnion(l_fbRect, r_fbRect);
534}
535/* 1) Identify layers that are not visible or lying outside BOTH the updating
536 * ROI's and drop them from composition. If a layer is spanning across both
537 * the halves of the screen but needed by only ROI, the non-contributing
538 * half will not be programmed for MDP.
539 * 2) If we have a scaling layer which needs cropping against generated
540 * ROI, reset ROI to full resolution. */
541bool MDPCompSplit::validateAndApplyROI(hwc_context_t *ctx,
542 hwc_display_contents_1_t* list) {
543
544 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
545
546 hwc_rect_t visibleRectL = ctx->listStats[mDpy].lRoi;
547 hwc_rect_t visibleRectR = ctx->listStats[mDpy].rRoi;
548
549 for(int i = numAppLayers - 1; i >= 0; i--){
550 if(!isValidRect(visibleRectL) && !isValidRect(visibleRectR))
551 {
552 mCurrentFrame.drop[i] = true;
553 mCurrentFrame.dropCount++;
554 continue;
555 }
556
557 const hwc_layer_1_t* layer = &list->hwLayers[i];
558 hwc_rect_t dstRect = layer->displayFrame;
559
560 hwc_rect_t l_res = getIntersection(visibleRectL, dstRect);
561 hwc_rect_t r_res = getIntersection(visibleRectR, dstRect);
562 hwc_rect_t res = getUnion(l_res, r_res);
563
564 if(!isValidRect(l_res) && !isValidRect(r_res)) {
565 mCurrentFrame.drop[i] = true;
566 mCurrentFrame.dropCount++;
567 } else {
568 /* Reset frame ROI when any layer which needs scaling also needs ROI
569 * cropping */
570 if(!isSameRect(res, dstRect) && needsScaling (layer)) {
571 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
572 mCurrentFrame.dropCount = 0;
573 return false;
574 }
575
576 if (layer->blending == HWC_BLENDING_NONE) {
577 visibleRectL = deductRect(visibleRectL, l_res);
578 visibleRectR = deductRect(visibleRectR, r_res);
579 }
580 }
581 }
582 return true;
583}
584/* Calculate ROI for the frame by accounting all the layer's dispalyFrame which
585 * are updating. If DirtyRegion is applicable, calculate it by accounting all
586 * the changing layer's dirtyRegion. */
587void MDPCompSplit::generateROI(hwc_context_t *ctx,
588 hwc_display_contents_1_t* list) {
589 if(!canPartialUpdate(ctx, list))
590 return;
591
592 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
593 int lSplit = getLeftSplit(ctx, mDpy);
594
595 int hw_h = (int)ctx->dpyAttr[mDpy].yres;
596 int hw_w = (int)ctx->dpyAttr[mDpy].xres;
597
598 struct hwc_rect l_frame = (struct hwc_rect){0, 0, lSplit, hw_h};
599 struct hwc_rect r_frame = (struct hwc_rect){lSplit, 0, hw_w, hw_h};
600
601 struct hwc_rect l_roi = (struct hwc_rect){0, 0, 0, 0};
602 struct hwc_rect r_roi = (struct hwc_rect){0, 0, 0, 0};
603
604 for(int index = 0; index < numAppLayers; index++ ) {
605 hwc_layer_1_t* layer = &list->hwLayers[index];
606 if ((mCachedFrame.hnd[index] != layer->handle) ||
607 isYuvBuffer((private_handle_t *)layer->handle)) {
Jeykumar Sankaran71e597c2014-05-07 16:23:14 -0700608 hwc_rect_t dst = layer->displayFrame;
609 hwc_rect_t updatingRect = dst;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800610
611#ifdef QCOM_BSP
612 if(!needsScaling(layer) && !layer->transform)
Jeykumar Sankaran71e597c2014-05-07 16:23:14 -0700613 {
614 hwc_rect_t src = integerizeSourceCrop(layer->sourceCropf);
615 int x_off = dst.left - src.left;
616 int y_off = dst.top - src.top;
617 updatingRect = moveRect(layer->dirtyRect, x_off, y_off);
618 }
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800619#endif
620
621 hwc_rect_t l_dst = getIntersection(l_frame, updatingRect);
622 if(isValidRect(l_dst))
623 l_roi = getUnion(l_roi, l_dst);
624
625 hwc_rect_t r_dst = getIntersection(r_frame, updatingRect);
626 if(isValidRect(r_dst))
627 r_roi = getUnion(r_roi, r_dst);
628 }
629 }
630
Jeykumar Sankarana40a9342014-04-25 09:37:10 -0700631 /* For panels that cannot accept commands in both the interfaces, we cannot
632 * send two ROI's (for each half). We merge them into single ROI and split
633 * them across lSplit for MDP mixer use. The ROI's will be merged again
634 * finally before udpating the panel in the driver. */
635 if(qdutils::MDPVersion::getInstance().needsROIMerge()) {
636 hwc_rect_t temp_roi = getUnion(l_roi, r_roi);
637 l_roi = getIntersection(temp_roi, l_frame);
638 r_roi = getIntersection(temp_roi, r_frame);
639 }
640
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800641 /* No layer is updating. Still SF wants a refresh. */
642 if(!isValidRect(l_roi) && !isValidRect(r_roi))
643 return;
644
645 l_roi = getSanitizeROI(l_roi, l_frame);
646 r_roi = getSanitizeROI(r_roi, r_frame);
647
648 ctx->listStats[mDpy].lRoi = l_roi;
649 ctx->listStats[mDpy].rRoi = r_roi;
650
651 if(!validateAndApplyROI(ctx, list))
652 resetROI(ctx, mDpy);
653
654 ALOGD_IF(isDebug(),"%s: generated L_ROI: [%d, %d, %d, %d]"
655 "R_ROI: [%d, %d, %d, %d]", __FUNCTION__,
656 ctx->listStats[mDpy].lRoi.left, ctx->listStats[mDpy].lRoi.top,
657 ctx->listStats[mDpy].lRoi.right, ctx->listStats[mDpy].lRoi.bottom,
658 ctx->listStats[mDpy].rRoi.left, ctx->listStats[mDpy].rRoi.top,
659 ctx->listStats[mDpy].rRoi.right, ctx->listStats[mDpy].rRoi.bottom);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700660}
661
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800662/* Checks for conditions where all the layers marked for MDP comp cannot be
663 * bypassed. On such conditions we try to bypass atleast YUV layers */
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800664bool MDPComp::tryFullFrame(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800665 hwc_display_contents_1_t* list){
666
Saurabh Shahaa236822013-04-24 18:07:26 -0700667 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Arun Kumar K.R2e2871c2014-01-10 12:47:06 -0800668 int priDispW = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800669
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -0700670 if(sIdleFallBack && !ctx->listStats[mDpy].secureUI) {
Saurabh Shah2d998a92013-05-14 17:55:58 -0700671 ALOGD_IF(isDebug(), "%s: Idle fallback dpy %d",__FUNCTION__, mDpy);
672 return false;
673 }
674
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800675 if(isSkipPresent(ctx, mDpy)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700676 ALOGD_IF(isDebug(),"%s: SKIP present: %d",
677 __FUNCTION__,
678 isSkipPresent(ctx, mDpy));
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800679 return false;
680 }
681
Arun Kumar K.R2e2871c2014-01-10 12:47:06 -0800682 if(mDpy > HWC_DISPLAY_PRIMARY && (priDispW > MAX_DISPLAY_DIM) &&
683 (ctx->dpyAttr[mDpy].xres < MAX_DISPLAY_DIM)) {
684 // Disable MDP comp on Secondary when the primary is highres panel and
685 // the secondary is a normal 1080p, because, MDP comp on secondary under
686 // in such usecase, decimation gets used for downscale and there will be
687 // a quality mismatch when there will be a fallback to GPU comp
688 ALOGD_IF(isDebug(), "%s: Disable MDP Compositon for Secondary Disp",
689 __FUNCTION__);
690 return false;
691 }
692
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800693 // check for action safe flag and downscale mode which requires scaling.
694 if(ctx->dpyAttr[mDpy].mActionSafePresent
695 || ctx->dpyAttr[mDpy].mDownScaleMode) {
696 ALOGD_IF(isDebug(), "%s: Scaling needed for this frame",__FUNCTION__);
697 return false;
698 }
699
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800700 for(int i = 0; i < numAppLayers; ++i) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800701 hwc_layer_1_t* layer = &list->hwLayers[i];
702 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800703
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700704 if(isYuvBuffer(hnd) && has90Transform(layer)) {
705 if(!canUseRotator(ctx, mDpy)) {
706 ALOGD_IF(isDebug(), "%s: Can't use rotator for dpy %d",
707 __FUNCTION__, mDpy);
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700708 return false;
709 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800710 }
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530711
712 //For 8x26 with panel width>1k, if RGB layer needs HFLIP fail mdp comp
713 // may not need it if Gfx pre-rotation can handle all flips & rotations
Sushil Chauhanfda00fc2014-03-20 11:08:41 -0700714 int transform = (layer->flags & HWC_COLOR_FILL) ? 0 : layer->transform;
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530715 if(qdutils::MDPVersion::getInstance().is8x26() &&
716 (ctx->dpyAttr[mDpy].xres > 1024) &&
Sushil Chauhanfda00fc2014-03-20 11:08:41 -0700717 (transform & HWC_TRANSFORM_FLIP_H) &&
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530718 (!isYuvBuffer(hnd)))
719 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800720 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700721
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700722 if(ctx->mAD->isDoable()) {
723 return false;
724 }
725
Saurabh Shahaa236822013-04-24 18:07:26 -0700726 //If all above hard conditions are met we can do full or partial MDP comp.
727 bool ret = false;
728 if(fullMDPComp(ctx, list)) {
729 ret = true;
Sushil Chauhandefd3522014-05-13 18:17:12 -0700730 } else if(fullMDPCompWithPTOR(ctx, list)) {
731 ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700732 } else if(partialMDPComp(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700733 ret = true;
734 }
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530735
Saurabh Shahaa236822013-04-24 18:07:26 -0700736 return ret;
737}
738
739bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaran0ad97c42014-03-09 23:00:53 -0700740
741 if(sSimulationFlags & MDPCOMP_AVOID_FULL_MDP)
742 return false;
743
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700744 //Will benefit presentation / secondary-only layer.
745 if((mDpy > HWC_DISPLAY_PRIMARY) &&
746 (list->numHwLayers - 1) > MAX_SEC_LAYERS) {
747 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
748 return false;
749 }
750
751 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
752 for(int i = 0; i < numAppLayers; i++) {
753 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran880da832014-04-18 10:22:35 -0700754 if(not mCurrentFrame.drop[i] and
755 not isSupportedForMDPComp(ctx, layer)) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700756 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",__FUNCTION__);
757 return false;
758 }
759 }
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800760
Saurabh Shahaa236822013-04-24 18:07:26 -0700761 mCurrentFrame.fbCount = 0;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700762 memcpy(&mCurrentFrame.isFBComposed, &mCurrentFrame.drop,
763 sizeof(mCurrentFrame.isFBComposed));
764 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount -
765 mCurrentFrame.dropCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700766
radhakrishnac9a67412013-09-25 17:40:42 +0530767 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800768 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530769 }
770
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800771 if(!postHeuristicsHandling(ctx, list)) {
772 ALOGD_IF(isDebug(), "post heuristic handling failed");
773 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700774 return false;
775 }
Jeykumar Sankaran0ad97c42014-03-09 23:00:53 -0700776 ALOGD_IF(sSimulationFlags,"%s: FULL_MDP_COMP SUCCEEDED",
777 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700778 return true;
779}
780
Sushil Chauhandefd3522014-05-13 18:17:12 -0700781/* Full MDP Composition with Peripheral Tiny Overlap Removal.
782 * MDP bandwidth limitations can be avoided, if the overlap region
783 * covered by the smallest layer at a higher z-order, gets composed
784 * by Copybit on a render buffer, which can be queued to MDP.
785 */
786bool MDPComp::fullMDPCompWithPTOR(hwc_context_t *ctx,
787 hwc_display_contents_1_t* list) {
788
789 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
790 const int stagesForMDP = min(sMaxPipesPerMixer,
791 ctx->mOverlay->availablePipes(mDpy, Overlay::MIXER_DEFAULT));
792
793 // Hard checks where we cannot use this mode
794 if (mDpy || !ctx->mCopyBit[mDpy] || isDisplaySplit(ctx, mDpy)) {
795 ALOGD_IF(isDebug(), "%s: Feature not supported!", __FUNCTION__);
796 return false;
797 }
798
799 // Frame level checks
800 if ((numAppLayers > stagesForMDP) || isSkipPresent(ctx, mDpy) ||
801 isYuvPresent(ctx, mDpy) || mCurrentFrame.dropCount ||
802 isSecurePresent(ctx, mDpy)) {
803 ALOGD_IF(isDebug(), "%s: Frame not supported!", __FUNCTION__);
804 return false;
805 }
806
807 // Find overlap index
808 int overlapIdx = numAppLayers - 1;
809 uint32_t layerPixelCount, minPixelCount = 0;
810 for (int i = numAppLayers - 1; i >= 0; i--) {
811 hwc_layer_1_t* layer = &list->hwLayers[i];
812 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
813 layerPixelCount = (crop.right - crop.left) * (crop.bottom - crop.top);
814 if (!minPixelCount || (layerPixelCount < minPixelCount)) {
815 minPixelCount = layerPixelCount;
816 overlapIdx = i;
817 }
818 }
819
820 // No overlap
821 if (!overlapIdx)
822 return false;
823
824 /* We cannot use this composition mode, if:
825 1. A below layer needs scaling.
826 2. Overlap is not peripheral to display.
827 3. Overlap or a below layer has 90 degree transform.
828 4. Intersection of Overlap layer with a below layer is not valid.
829 5. Overlap area > (1/3 * FrameBuffer) area, based on Perf inputs.
830 */
831
832 hwc_rect_t overlap = list->hwLayers[overlapIdx].displayFrame;
833 if (!isPeripheral(overlap, ctx->mViewFrame[mDpy]))
834 return false;
835
836 if ((3 * (overlap.right - overlap.left) * (overlap.bottom - overlap.top)) >
837 ((int)ctx->dpyAttr[mDpy].xres * (int)ctx->dpyAttr[mDpy].yres))
838 return false;
839
840 for (int i = overlapIdx; i >= 0; i--) {
841 hwc_layer_1_t* layer = &list->hwLayers[i];
842 hwc_rect_t dispFrame = layer->displayFrame;
843
844 if (has90Transform(layer))
845 return false;
846
847 if (i < overlapIdx) {
848 if (needsScaling(layer) ||
849 !isValidRect(getIntersection(dispFrame, overlap)))
850 return false;
851 }
852 }
853
854 mOverlapIndex = overlapIdx;
855 if (!ctx->mCopyBit[mDpy]->prepareOverlap(ctx, list, overlapIdx)) {
856 ALOGD_IF(isDebug(), "%s: Overlap prepare failed!",__FUNCTION__);
857 mOverlapIndex = -1;
858 return false;
859 }
860
861 hwc_rect_t sourceCrop[overlapIdx];
862 hwc_rect_t displayFrame[overlapIdx];
863
864 // Remove overlap from crop & displayFrame of below layers
865 for (int i = 0; i < overlapIdx; i++) {
866 hwc_layer_1_t* layer = &list->hwLayers[i];
867 displayFrame[i] = layer->displayFrame;
868 sourceCrop[i] = integerizeSourceCrop(layer->sourceCropf);
869
870 // Update layer attributes
871 hwc_rect_t srcCrop = integerizeSourceCrop(layer->sourceCropf);
872 hwc_rect_t destRect = deductRect(layer->displayFrame, overlap);
873 qhwc::calculate_crop_rects(srcCrop, layer->displayFrame, destRect,
874 layer->transform);
875
876 layer->sourceCropf.left = (float)srcCrop.left;
877 layer->sourceCropf.top = (float)srcCrop.top;
878 layer->sourceCropf.right = (float)srcCrop.right;
879 layer->sourceCropf.bottom = (float)srcCrop.bottom;
880 }
881
882 mCurrentFrame.mdpCount = numAppLayers;
883 mCurrentFrame.fbCount = 0;
884 mCurrentFrame.fbZ = -1;
885
886 for (int j = 0; j < numAppLayers; j++)
887 mCurrentFrame.isFBComposed[j] = false;
888
889 bool result = postHeuristicsHandling(ctx, list);
890
891 // Restore layer attributes
892 for (int i = 0; i < overlapIdx; i++) {
893 hwc_layer_1_t* layer = &list->hwLayers[i];
894 layer->displayFrame = displayFrame[i];
895 layer->sourceCropf.left = (float)sourceCrop[i].left;
896 layer->sourceCropf.top = (float)sourceCrop[i].top;
897 layer->sourceCropf.right = (float)sourceCrop[i].right;
898 layer->sourceCropf.bottom = (float)sourceCrop[i].bottom;
899 }
900
901 if (!result) {
902 mOverlapIndex = -1;
903 reset(ctx);
904 }
905
906 ALOGD_IF(isDebug(), "%s: Postheuristics %s!, Overlap index = %d",
907 __FUNCTION__, (result ? "successful" : "failed"), mOverlapIndex);
908 return result;
909}
910
Saurabh Shahaa236822013-04-24 18:07:26 -0700911bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
912{
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700913 if(!sEnableMixedMode) {
914 //Mixed mode is disabled. No need to even try caching.
915 return false;
916 }
917
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700918 bool ret = false;
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800919 if(list->flags & HWC_GEOMETRY_CHANGED) { //Try load based first
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800920 ret = loadBasedComp(ctx, list) or
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800921 cacheBasedComp(ctx, list);
922 } else {
923 ret = cacheBasedComp(ctx, list) or
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800924 loadBasedComp(ctx, list);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700925 }
926
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700927 return ret;
928}
929
930bool MDPComp::cacheBasedComp(hwc_context_t *ctx,
931 hwc_display_contents_1_t* list) {
Jeykumar Sankaran0ad97c42014-03-09 23:00:53 -0700932 if(sSimulationFlags & MDPCOMP_AVOID_CACHE_MDP)
933 return false;
934
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700935 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700936 mCurrentFrame.reset(numAppLayers);
937 updateLayerCache(ctx, list);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700938
939 //If an MDP marked layer is unsupported cannot do partial MDP Comp
940 for(int i = 0; i < numAppLayers; i++) {
941 if(!mCurrentFrame.isFBComposed[i]) {
942 hwc_layer_1_t* layer = &list->hwLayers[i];
943 if(not isSupportedForMDPComp(ctx, layer)) {
944 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",
945 __FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800946 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700947 return false;
948 }
949 }
950 }
951
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700952 updateYUV(ctx, list, false /*secure only*/);
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530953 bool ret = markLayersForCaching(ctx, list); //sets up fbZ also
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700954 if(!ret) {
955 ALOGD_IF(isDebug(),"%s: batching failed, dpy %d",__FUNCTION__, mDpy);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800956 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700957 return false;
958 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700959
960 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700961
radhakrishnac9a67412013-09-25 17:40:42 +0530962 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800963 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530964 }
965
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700966 //Will benefit cases where a video has non-updating background.
967 if((mDpy > HWC_DISPLAY_PRIMARY) and
968 (mdpCount > MAX_SEC_LAYERS)) {
969 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800970 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700971 return false;
972 }
973
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800974 if(!postHeuristicsHandling(ctx, list)) {
975 ALOGD_IF(isDebug(), "post heuristic handling failed");
976 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700977 return false;
978 }
Jeykumar Sankaran0ad97c42014-03-09 23:00:53 -0700979 ALOGD_IF(sSimulationFlags,"%s: CACHE_MDP_COMP SUCCEEDED",
980 __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700981
Saurabh Shahaa236822013-04-24 18:07:26 -0700982 return true;
983}
984
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800985bool MDPComp::loadBasedComp(hwc_context_t *ctx,
Saurabh Shahb772ae32013-11-18 15:40:02 -0800986 hwc_display_contents_1_t* list) {
Jeykumar Sankaran0ad97c42014-03-09 23:00:53 -0700987 if(sSimulationFlags & MDPCOMP_AVOID_LOAD_MDP)
988 return false;
989
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -0800990 if(not isLoadBasedCompDoable(ctx)) {
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800991 return false;
992 }
993
Saurabh Shahb772ae32013-11-18 15:40:02 -0800994 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800995 const int numNonDroppedLayers = numAppLayers - mCurrentFrame.dropCount;
996 const int stagesForMDP = min(sMaxPipesPerMixer,
997 ctx->mOverlay->availablePipes(mDpy, Overlay::MIXER_DEFAULT));
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800998
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800999 int mdpBatchSize = stagesForMDP - 1; //1 stage for FB
1000 int fbBatchSize = numNonDroppedLayers - mdpBatchSize;
1001 int lastMDPSupportedIndex = numAppLayers;
1002 int dropCount = 0;
Saurabh Shahb772ae32013-11-18 15:40:02 -08001003
Saurabh Shahbe7bd322014-02-20 16:18:45 -08001004 //Find the minimum MDP batch size
1005 for(int i = 0; i < numAppLayers;i++) {
1006 if(mCurrentFrame.drop[i]) {
1007 dropCount++;
Jeykumar Sankaran846e2792014-01-23 21:59:58 -08001008 continue;
Saurabh Shahbe7bd322014-02-20 16:18:45 -08001009 }
1010 hwc_layer_1_t* layer = &list->hwLayers[i];
1011 if(not isSupportedForMDPComp(ctx, layer)) {
1012 lastMDPSupportedIndex = i;
1013 mdpBatchSize = min(i - dropCount, stagesForMDP - 1);
1014 fbBatchSize = numNonDroppedLayers - mdpBatchSize;
Jeykumar Sankaran846e2792014-01-23 21:59:58 -08001015 break;
Saurabh Shahb772ae32013-11-18 15:40:02 -08001016 }
Saurabh Shahb772ae32013-11-18 15:40:02 -08001017 }
1018
Saurabh Shahbe7bd322014-02-20 16:18:45 -08001019 ALOGD_IF(isDebug(), "%s:Before optimizing fbBatch, mdpbatch %d, fbbatch %d "
1020 "dropped %d", __FUNCTION__, mdpBatchSize, fbBatchSize,
1021 mCurrentFrame.dropCount);
1022
1023 //Start at a point where the fb batch should at least have 2 layers, for
1024 //this mode to be justified.
1025 while(fbBatchSize < 2) {
1026 ++fbBatchSize;
1027 --mdpBatchSize;
Jeykumar Sankaran846e2792014-01-23 21:59:58 -08001028 }
Saurabh Shahb772ae32013-11-18 15:40:02 -08001029
Saurabh Shahbe7bd322014-02-20 16:18:45 -08001030 //If there are no layers for MDP, this mode doesnt make sense.
1031 if(mdpBatchSize < 1) {
1032 ALOGD_IF(isDebug(), "%s: No MDP layers after optimizing for fbBatch",
1033 __FUNCTION__);
Saurabh Shahb772ae32013-11-18 15:40:02 -08001034 return false;
1035 }
1036
Saurabh Shahbe7bd322014-02-20 16:18:45 -08001037 mCurrentFrame.reset(numAppLayers);
1038
1039 //Try with successively smaller mdp batch sizes until we succeed or reach 1
1040 while(mdpBatchSize > 0) {
1041 //Mark layers for MDP comp
1042 int mdpBatchLeft = mdpBatchSize;
1043 for(int i = 0; i < lastMDPSupportedIndex and mdpBatchLeft; i++) {
1044 if(mCurrentFrame.drop[i]) {
1045 continue;
1046 }
1047 mCurrentFrame.isFBComposed[i] = false;
1048 --mdpBatchLeft;
1049 }
1050
1051 mCurrentFrame.fbZ = mdpBatchSize;
1052 mCurrentFrame.fbCount = fbBatchSize;
1053 mCurrentFrame.mdpCount = mdpBatchSize;
1054
1055 ALOGD_IF(isDebug(), "%s:Trying with: mdpbatch %d fbbatch %d dropped %d",
1056 __FUNCTION__, mdpBatchSize, fbBatchSize,
1057 mCurrentFrame.dropCount);
1058
1059 if(postHeuristicsHandling(ctx, list)) {
1060 ALOGD_IF(isDebug(), "%s: Postheuristics handling succeeded",
Jeykumar Sankaran0ad97c42014-03-09 23:00:53 -07001061 __FUNCTION__);
1062 ALOGD_IF(sSimulationFlags,"%s: LOAD_MDP_COMP SUCCEEDED",
1063 __FUNCTION__);
Saurabh Shahbe7bd322014-02-20 16:18:45 -08001064 return true;
1065 }
1066
1067 reset(ctx);
1068 --mdpBatchSize;
1069 ++fbBatchSize;
1070 }
1071
1072 return false;
Saurabh Shahb772ae32013-11-18 15:40:02 -08001073}
1074
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001075bool MDPComp::isLoadBasedCompDoable(hwc_context_t *ctx) {
Prabhanjan Kandula3dbbd882013-12-11 14:43:46 +05301076 if(mDpy or isSecurePresent(ctx, mDpy) or
1077 isYuvPresent(ctx, mDpy)) {
Saurabh Shah8028e3b2013-10-15 12:27:59 -07001078 return false;
1079 }
1080 return true;
1081}
1082
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001083bool MDPComp::canPartialUpdate(hwc_context_t *ctx,
1084 hwc_display_contents_1_t* list){
1085 if(!qdutils::MDPVersion::getInstance().isPartialUpdateEnabled() ||
1086 isSkipPresent(ctx, mDpy) || (list->flags & HWC_GEOMETRY_CHANGED) ||
1087 mDpy ) {
1088 return false;
1089 }
1090 return true;
1091}
1092
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001093bool MDPComp::tryVideoOnly(hwc_context_t *ctx,
1094 hwc_display_contents_1_t* list) {
1095 const bool secureOnly = true;
1096 return videoOnlyComp(ctx, list, not secureOnly) or
1097 videoOnlyComp(ctx, list, secureOnly);
1098}
1099
1100bool MDPComp::videoOnlyComp(hwc_context_t *ctx,
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001101 hwc_display_contents_1_t* list, bool secureOnly) {
Jeykumar Sankaran0ad97c42014-03-09 23:00:53 -07001102 if(sSimulationFlags & MDPCOMP_AVOID_VIDEO_ONLY)
1103 return false;
Saurabh Shahaa236822013-04-24 18:07:26 -07001104 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001105
Saurabh Shahaa236822013-04-24 18:07:26 -07001106 mCurrentFrame.reset(numAppLayers);
Jeykumar Sankaraneb3a5e22014-04-08 16:07:55 -07001107 mCurrentFrame.fbCount -= mCurrentFrame.dropCount;
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001108 updateYUV(ctx, list, secureOnly);
Saurabh Shah4fdde762013-04-30 18:47:33 -07001109 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001110
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001111 if(!isYuvPresent(ctx, mDpy) or (mdpCount == 0)) {
1112 reset(ctx);
Saurabh Shahaa236822013-04-24 18:07:26 -07001113 return false;
1114 }
1115
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -08001116 /* Bail out if we are processing only secured video layers
1117 * and we dont have any */
1118 if(!isSecurePresent(ctx, mDpy) && secureOnly){
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001119 reset(ctx);
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -08001120 return false;
1121 }
1122
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001123 if(mCurrentFrame.fbCount)
1124 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
Saurabh Shah4fdde762013-04-30 18:47:33 -07001125
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001126 if(sEnable4k2kYUVSplit){
1127 adjustForSourceSplit(ctx, list);
1128 }
1129
1130 if(!postHeuristicsHandling(ctx, list)) {
1131 ALOGD_IF(isDebug(), "post heuristic handling failed");
1132 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001133 return false;
1134 }
1135
Jeykumar Sankaran0ad97c42014-03-09 23:00:53 -07001136 ALOGD_IF(sSimulationFlags,"%s: VIDEO_ONLY_COMP SUCCEEDED",
1137 __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001138 return true;
1139}
1140
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001141/* Checks for conditions where YUV layers cannot be bypassed */
1142bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -07001143 if(isSkipLayer(layer)) {
Saurabh Shahe2474082013-05-15 16:32:13 -07001144 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001145 return false;
1146 }
1147
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -07001148 if(layer->transform & HWC_TRANSFORM_ROT_90 && !canUseRotator(ctx,mDpy)) {
1149 ALOGD_IF(isDebug(), "%s: no free DMA pipe",__FUNCTION__);
1150 return false;
1151 }
1152
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001153 if(isSecuring(ctx, layer)) {
1154 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
1155 return false;
1156 }
1157
Saurabh Shah4fdde762013-04-30 18:47:33 -07001158 if(!isValidDimension(ctx, layer)) {
1159 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
1160 __FUNCTION__);
1161 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001162 }
Saurabh Shah4fdde762013-04-30 18:47:33 -07001163
Naseer Ahmeddc61a972013-07-10 17:50:54 -04001164 if(layer->planeAlpha < 0xFF) {
1165 ALOGD_IF(isDebug(), "%s: Cannot handle YUV layer with plane alpha\
1166 in video only mode",
1167 __FUNCTION__);
1168 return false;
1169 }
1170
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001171 return true;
1172}
1173
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301174/* starts at fromIndex and check for each layer to find
1175 * if it it has overlapping with any Updating layer above it in zorder
1176 * till the end of the batch. returns true if it finds any intersection */
1177bool MDPComp::canPushBatchToTop(const hwc_display_contents_1_t* list,
1178 int fromIndex, int toIndex) {
1179 for(int i = fromIndex; i < toIndex; i++) {
1180 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
1181 if(intersectingUpdatingLayers(list, i+1, toIndex, i)) {
1182 return false;
1183 }
1184 }
1185 }
1186 return true;
1187}
1188
1189/* Checks if given layer at targetLayerIndex has any
1190 * intersection with all the updating layers in beween
1191 * fromIndex and toIndex. Returns true if it finds intersectiion */
1192bool MDPComp::intersectingUpdatingLayers(const hwc_display_contents_1_t* list,
1193 int fromIndex, int toIndex, int targetLayerIndex) {
1194 for(int i = fromIndex; i <= toIndex; i++) {
1195 if(!mCurrentFrame.isFBComposed[i]) {
1196 if(areLayersIntersecting(&list->hwLayers[i],
1197 &list->hwLayers[targetLayerIndex])) {
1198 return true;
1199 }
1200 }
1201 }
1202 return false;
1203}
1204
1205int MDPComp::getBatch(hwc_display_contents_1_t* list,
1206 int& maxBatchStart, int& maxBatchEnd,
1207 int& maxBatchCount) {
1208 int i = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301209 int fbZOrder =-1;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -08001210 int droppedLayerCt = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301211 while (i < mCurrentFrame.layerCount) {
1212 int batchCount = 0;
1213 int batchStart = i;
1214 int batchEnd = i;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -08001215 /* Adjust batch Z order with the dropped layers so far */
1216 int fbZ = batchStart - droppedLayerCt;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301217 int firstZReverseIndex = -1;
Prabhanjan Kandula0ed2cc92013-12-06 12:39:04 +05301218 int updatingLayersAbove = 0;//Updating layer count in middle of batch
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301219 while(i < mCurrentFrame.layerCount) {
1220 if(!mCurrentFrame.isFBComposed[i]) {
1221 if(!batchCount) {
1222 i++;
1223 break;
1224 }
1225 updatingLayersAbove++;
1226 i++;
1227 continue;
1228 } else {
1229 if(mCurrentFrame.drop[i]) {
1230 i++;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -08001231 droppedLayerCt++;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301232 continue;
1233 } else if(updatingLayersAbove <= 0) {
1234 batchCount++;
1235 batchEnd = i;
1236 i++;
1237 continue;
1238 } else { //Layer is FBComposed, not a drop & updatingLayer > 0
1239
1240 // We have a valid updating layer already. If layer-i not
1241 // have overlapping with all updating layers in between
1242 // batch-start and i, then we can add layer i to batch.
1243 if(!intersectingUpdatingLayers(list, batchStart, i-1, i)) {
1244 batchCount++;
1245 batchEnd = i;
1246 i++;
1247 continue;
1248 } else if(canPushBatchToTop(list, batchStart, i)) {
1249 //If All the non-updating layers with in this batch
1250 //does not have intersection with the updating layers
1251 //above in z-order, then we can safely move the batch to
1252 //higher z-order. Increment fbZ as it is moving up.
1253 if( firstZReverseIndex < 0) {
1254 firstZReverseIndex = i;
1255 }
1256 batchCount++;
1257 batchEnd = i;
1258 fbZ += updatingLayersAbove;
1259 i++;
1260 updatingLayersAbove = 0;
1261 continue;
1262 } else {
1263 //both failed.start the loop again from here.
1264 if(firstZReverseIndex >= 0) {
1265 i = firstZReverseIndex;
1266 }
1267 break;
1268 }
1269 }
1270 }
1271 }
1272 if(batchCount > maxBatchCount) {
1273 maxBatchCount = batchCount;
1274 maxBatchStart = batchStart;
1275 maxBatchEnd = batchEnd;
1276 fbZOrder = fbZ;
1277 }
1278 }
1279 return fbZOrder;
1280}
1281
1282bool MDPComp::markLayersForCaching(hwc_context_t* ctx,
1283 hwc_display_contents_1_t* list) {
1284 /* Idea is to keep as many non-updating(cached) layers in FB and
1285 * send rest of them through MDP. This is done in 2 steps.
1286 * 1. Find the maximum contiguous batch of non-updating layers.
1287 * 2. See if we can improve this batch size for caching by adding
1288 * opaque layers around the batch, if they don't have
1289 * any overlapping with the updating layers in between.
1290 * NEVER mark an updating layer for caching.
1291 * But cached ones can be marked for MDP */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001292
1293 int maxBatchStart = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001294 int maxBatchEnd = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001295 int maxBatchCount = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301296 int fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001297
Saurabh Shahd53bc5f2014-02-05 10:17:43 -08001298 /* Nothing is cached. No batching needed */
1299 if(mCurrentFrame.fbCount == 0) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001300 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -07001301 }
Saurabh Shahd53bc5f2014-02-05 10:17:43 -08001302
1303 /* No MDP comp layers, try to use other comp modes */
1304 if(mCurrentFrame.mdpCount == 0) {
1305 return false;
Saurabh Shahaa236822013-04-24 18:07:26 -07001306 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001307
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301308 fbZ = getBatch(list, maxBatchStart, maxBatchEnd, maxBatchCount);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001309
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301310 /* reset rest of the layers lying inside ROI for MDP comp */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001311 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001312 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001313 if((i < maxBatchStart || i > maxBatchEnd) &&
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301314 mCurrentFrame.isFBComposed[i]){
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001315 if(!mCurrentFrame.drop[i]){
1316 //If an unsupported layer is being attempted to
1317 //be pulled out we should fail
1318 if(not isSupportedForMDPComp(ctx, layer)) {
1319 return false;
1320 }
1321 mCurrentFrame.isFBComposed[i] = false;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001322 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001323 }
1324 }
1325
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301326 // update the frame data
1327 mCurrentFrame.fbZ = fbZ;
1328 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001329 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001330 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001331
1332 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301333 mCurrentFrame.fbCount);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001334
1335 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001336}
Saurabh Shah85234ec2013-04-12 17:09:00 -07001337
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001338void MDPComp::updateLayerCache(hwc_context_t* ctx,
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001339 hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001340 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001341 int fbCount = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001342
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001343 for(int i = 0; i < numAppLayers; i++) {
1344 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001345 if(!mCurrentFrame.drop[i])
1346 fbCount++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001347 mCurrentFrame.isFBComposed[i] = true;
1348 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -07001349 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001350 }
1351 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001352
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001353 mCurrentFrame.fbCount = fbCount;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001354 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount
1355 - mCurrentFrame.dropCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001356
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001357 ALOGD_IF(isDebug(),"%s: MDP count: %d FB count %d drop count: %d"
1358 ,__FUNCTION__, mCurrentFrame.mdpCount, mCurrentFrame.fbCount,
1359 mCurrentFrame.dropCount);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001360}
1361
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001362void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list,
1363 bool secureOnly) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001364 int nYuvCount = ctx->listStats[mDpy].yuvCount;
1365 for(int index = 0;index < nYuvCount; index++){
1366 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
1367 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
1368
1369 if(!isYUVDoable(ctx, layer)) {
1370 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
1371 mCurrentFrame.isFBComposed[nYuvIndex] = true;
1372 mCurrentFrame.fbCount++;
1373 }
1374 } else {
1375 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001376 private_handle_t *hnd = (private_handle_t *)layer->handle;
1377 if(!secureOnly || isSecureBuffer(hnd)) {
1378 mCurrentFrame.isFBComposed[nYuvIndex] = false;
1379 mCurrentFrame.fbCount--;
1380 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001381 }
1382 }
1383 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001384
1385 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001386 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
1387 ALOGD_IF(isDebug(),"%s: fb count: %d",__FUNCTION__,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001388 mCurrentFrame.fbCount);
1389}
1390
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001391hwc_rect_t MDPComp::getUpdatingFBRect(hwc_context_t *ctx,
1392 hwc_display_contents_1_t* list){
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001393 hwc_rect_t fbRect = (struct hwc_rect){0, 0, 0, 0};
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001394
1395 /* Update only the region of FB needed for composition */
1396 for(int i = 0; i < mCurrentFrame.layerCount; i++ ) {
1397 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
1398 hwc_layer_1_t* layer = &list->hwLayers[i];
1399 hwc_rect_t dst = layer->displayFrame;
1400 fbRect = getUnion(fbRect, dst);
1401 }
1402 }
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001403 trimAgainstROI(ctx, fbRect);
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001404 return fbRect;
1405}
1406
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001407bool MDPComp::postHeuristicsHandling(hwc_context_t *ctx,
1408 hwc_display_contents_1_t* list) {
1409
1410 //Capability checks
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301411 if(!resourceCheck()) {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001412 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
1413 return false;
1414 }
1415
1416 //Limitations checks
1417 if(!hwLimitationsCheck(ctx, list)) {
1418 ALOGD_IF(isDebug(), "%s: HW limitations",__FUNCTION__);
1419 return false;
1420 }
1421
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001422 //Configure framebuffer first if applicable
1423 if(mCurrentFrame.fbZ >= 0) {
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001424 hwc_rect_t fbRect = getUpdatingFBRect(ctx, list);
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001425 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, fbRect, mCurrentFrame.fbZ))
1426 {
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001427 ALOGD_IF(isDebug(), "%s configure framebuffer failed",
1428 __FUNCTION__);
1429 return false;
1430 }
1431 }
1432
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001433 mCurrentFrame.map();
1434
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001435 if(!allocLayerPipes(ctx, list)) {
1436 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -07001437 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001438 }
1439
1440 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001441 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001442 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001443 int mdpIndex = mCurrentFrame.layerToMDP[index];
1444 hwc_layer_1_t* layer = &list->hwLayers[index];
1445
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301446 //Leave fbZ for framebuffer. CACHE/GLES layers go here.
1447 if(mdpNextZOrder == mCurrentFrame.fbZ) {
1448 mdpNextZOrder++;
1449 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001450 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1451 cur_pipe->zOrder = mdpNextZOrder++;
1452
radhakrishnac9a67412013-09-25 17:40:42 +05301453 private_handle_t *hnd = (private_handle_t *)layer->handle;
1454 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1455 if(configure4k2kYuv(ctx, layer,
1456 mCurrentFrame.mdpToLayer[mdpIndex])
1457 != 0 ){
1458 ALOGD_IF(isDebug(), "%s: Failed to configure split pipes \
1459 for layer %d",__FUNCTION__, index);
1460 return false;
1461 }
1462 else{
1463 mdpNextZOrder++;
1464 }
1465 continue;
1466 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001467 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
1468 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
radhakrishnac9a67412013-09-25 17:40:42 +05301469 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -07001470 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001471 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001472 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001473 }
1474
Saurabh Shaha36be922013-12-16 18:18:39 -08001475 if(!ctx->mOverlay->validateAndSet(mDpy, ctx->dpyAttr[mDpy].fd)) {
1476 ALOGD_IF(isDebug(), "%s: Failed to validate and set overlay for dpy %d"
1477 ,__FUNCTION__, mDpy);
1478 return false;
1479 }
1480
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001481 setRedraw(ctx, list);
Saurabh Shahaa236822013-04-24 18:07:26 -07001482 return true;
1483}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001484
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301485bool MDPComp::resourceCheck() {
Saurabh Shah173f4242013-11-20 09:50:12 -08001486 const bool fbUsed = mCurrentFrame.fbCount;
1487 if(mCurrentFrame.mdpCount > sMaxPipesPerMixer - fbUsed) {
1488 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
1489 return false;
1490 }
Saurabh Shah173f4242013-11-20 09:50:12 -08001491 return true;
1492}
1493
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301494bool MDPComp::hwLimitationsCheck(hwc_context_t* ctx,
1495 hwc_display_contents_1_t* list) {
1496
1497 //A-family hw limitation:
1498 //If a layer need alpha scaling, MDP can not support.
1499 if(ctx->mMDP.version < qdutils::MDSS_V5) {
1500 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1501 if(!mCurrentFrame.isFBComposed[i] &&
1502 isAlphaScaled( &list->hwLayers[i])) {
1503 ALOGD_IF(isDebug(), "%s:frame needs alphaScaling",__FUNCTION__);
1504 return false;
1505 }
1506 }
1507 }
1508
1509 // On 8x26 & 8974 hw, we have a limitation of downscaling+blending.
1510 //If multiple layers requires downscaling and also they are overlapping
1511 //fall back to GPU since MDSS can not handle it.
1512 if(qdutils::MDPVersion::getInstance().is8x74v2() ||
1513 qdutils::MDPVersion::getInstance().is8x26()) {
1514 for(int i = 0; i < mCurrentFrame.layerCount-1; ++i) {
1515 hwc_layer_1_t* botLayer = &list->hwLayers[i];
1516 if(!mCurrentFrame.isFBComposed[i] &&
1517 isDownscaleRequired(botLayer)) {
1518 //if layer-i is marked for MDP and needs downscaling
1519 //check if any MDP layer on top of i & overlaps with layer-i
1520 for(int j = i+1; j < mCurrentFrame.layerCount; ++j) {
1521 hwc_layer_1_t* topLayer = &list->hwLayers[j];
1522 if(!mCurrentFrame.isFBComposed[j] &&
1523 isDownscaleRequired(topLayer)) {
1524 hwc_rect_t r = getIntersection(botLayer->displayFrame,
1525 topLayer->displayFrame);
1526 if(isValidRect(r))
1527 return false;
1528 }
1529 }
1530 }
1531 }
1532 }
1533 return true;
1534}
1535
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001536int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001537 int ret = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -07001538 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran0ad97c42014-03-09 23:00:53 -07001539 char property[PROPERTY_VALUE_MAX];
1540
1541 if(property_get("debug.hwc.simulate", property, NULL) > 0) {
1542 int currentFlags = atoi(property);
1543 if(currentFlags != sSimulationFlags) {
1544 sSimulationFlags = currentFlags;
1545 ALOGE("%s: Simulation Flag read: 0x%x (%d)", __FUNCTION__,
1546 sSimulationFlags, sSimulationFlags);
1547 }
1548 }
Sushil Chauhandefd3522014-05-13 18:17:12 -07001549 mOverlapIndex = -1;
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -07001550
Raj Kamal9ed3d6b2014-02-07 16:15:17 +05301551 //Do not cache the information for next draw cycle.
1552 if(numLayers > MAX_NUM_APP_LAYERS or (!numLayers)) {
1553 ALOGI("%s: Unsupported layer count for mdp composition",
1554 __FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001555 mCachedFrame.reset();
1556 return -1;
1557 }
1558
Saurabh Shahb39f8152013-08-22 10:21:44 -07001559 //reset old data
1560 mCurrentFrame.reset(numLayers);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001561 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1562 mCurrentFrame.dropCount = 0;
Prabhanjan Kandula088bd892013-07-02 23:47:13 +05301563
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -07001564 // Detect the start of animation and fall back to GPU only once to cache
1565 // all the layers in FB and display FB content untill animation completes.
1566 if(ctx->listStats[mDpy].isDisplayAnimating) {
1567 mCurrentFrame.needsRedraw = false;
1568 if(ctx->mAnimationState[mDpy] == ANIMATION_STOPPED) {
1569 mCurrentFrame.needsRedraw = true;
1570 ctx->mAnimationState[mDpy] = ANIMATION_STARTED;
1571 }
1572 setMDPCompLayerFlags(ctx, list);
1573 mCachedFrame.updateCounts(mCurrentFrame);
1574 ret = -1;
1575 return ret;
1576 } else {
1577 ctx->mAnimationState[mDpy] = ANIMATION_STOPPED;
1578 }
1579
Saurabh Shahb39f8152013-08-22 10:21:44 -07001580 //Hard conditions, if not met, cannot do MDP comp
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001581 if(isFrameDoable(ctx)) {
1582 generateROI(ctx, list);
Saurabh Shahb39f8152013-08-22 10:21:44 -07001583
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001584 if(tryFullFrame(ctx, list) || tryVideoOnly(ctx, list)) {
1585 setMDPCompLayerFlags(ctx, list);
1586 } else {
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001587 resetROI(ctx, mDpy);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001588 reset(ctx);
1589 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1590 mCurrentFrame.dropCount = 0;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001591 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001592 }
1593 } else {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001594 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
1595 __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001596 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001597 }
Saurabh Shahb39f8152013-08-22 10:21:44 -07001598
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001599 if(isDebug()) {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001600 ALOGD("GEOMETRY change: %d",
1601 (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001602 android::String8 sDump("");
Jeykumar Sankaran6850ac62014-05-27 10:07:26 -07001603 dump(sDump, ctx);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001604 ALOGD("%s",sDump.string());
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001605 }
1606
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001607 mCachedFrame.cacheAll(list);
1608 mCachedFrame.updateCounts(mCurrentFrame);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001609 return ret;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001610}
1611
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001612bool MDPComp::allocSplitVGPipesfor4k2k(hwc_context_t *ctx, int index) {
radhakrishnac9a67412013-09-25 17:40:42 +05301613
1614 bool bRet = true;
radhakrishnac9a67412013-09-25 17:40:42 +05301615 int mdpIndex = mCurrentFrame.layerToMDP[index];
1616 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
1617 info.pipeInfo = new MdpYUVPipeInfo;
1618 info.rot = NULL;
1619 MdpYUVPipeInfo& pipe_info = *(MdpYUVPipeInfo*)info.pipeInfo;
radhakrishnac9a67412013-09-25 17:40:42 +05301620
1621 pipe_info.lIndex = ovutils::OV_INVALID;
1622 pipe_info.rIndex = ovutils::OV_INVALID;
1623
Saurabh Shahc62f3982014-03-05 14:28:26 -08001624 Overlay::PipeSpecs pipeSpecs;
1625 pipeSpecs.formatClass = Overlay::FORMAT_YUV;
1626 pipeSpecs.needsScaling = true;
1627 pipeSpecs.dpy = mDpy;
1628 pipeSpecs.fb = false;
1629
1630 pipe_info.lIndex = ctx->mOverlay->getPipe(pipeSpecs);
radhakrishnac9a67412013-09-25 17:40:42 +05301631 if(pipe_info.lIndex == ovutils::OV_INVALID){
1632 bRet = false;
1633 ALOGD_IF(isDebug(),"%s: allocating first VG pipe failed",
1634 __FUNCTION__);
1635 }
Saurabh Shahc62f3982014-03-05 14:28:26 -08001636 pipe_info.rIndex = ctx->mOverlay->getPipe(pipeSpecs);
radhakrishnac9a67412013-09-25 17:40:42 +05301637 if(pipe_info.rIndex == ovutils::OV_INVALID){
1638 bRet = false;
1639 ALOGD_IF(isDebug(),"%s: allocating second VG pipe failed",
1640 __FUNCTION__);
1641 }
1642 return bRet;
1643}
Sushil Chauhandefd3522014-05-13 18:17:12 -07001644
1645int MDPComp::drawOverlap(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
1646 int fd = -1;
1647 if (mOverlapIndex != -1) {
1648 fd = ctx->mCopyBit[mDpy]->drawOverlap(ctx, list, mOverlapIndex);
1649 if (fd < 0) {
1650 ALOGD_IF(isDebug(),"%s: failed", __FUNCTION__);
1651 mOverlapIndex = -1;
1652 }
1653 }
1654 return fd;
1655}
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001656//=============MDPCompNonSplit==================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001657
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001658void MDPCompNonSplit::adjustForSourceSplit(hwc_context_t *ctx,
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001659 hwc_display_contents_1_t*) {
radhakrishnac9a67412013-09-25 17:40:42 +05301660 //As we split 4kx2k yuv layer and program to 2 VG pipes
1661 //(if available) increase mdpcount accordingly
1662 mCurrentFrame.mdpCount += ctx->listStats[mDpy].yuv4k2kCount;
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001663
1664 //If 4k2k Yuv layer split is possible, and if
1665 //fbz is above 4k2k layer, increment fb zorder by 1
1666 //as we split 4k2k layer and increment zorder for right half
1667 //of the layer
1668 if(mCurrentFrame.fbZ >= 0) {
1669 int n4k2kYuvCount = ctx->listStats[mDpy].yuv4k2kCount;
1670 for(int index = 0; index < n4k2kYuvCount; index++){
1671 int n4k2kYuvIndex =
1672 ctx->listStats[mDpy].yuv4k2kIndices[index];
Dileep Kumar Reddi4cff9282014-04-01 12:57:08 +05301673 if(mCurrentFrame.fbZ >= n4k2kYuvIndex){
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001674 mCurrentFrame.fbZ += 1;
1675 }
1676 }
1677 }
radhakrishnac9a67412013-09-25 17:40:42 +05301678}
1679
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001680/*
1681 * Configures pipe(s) for MDP composition
1682 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001683int MDPCompNonSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001684 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001685 MdpPipeInfoNonSplit& mdp_info =
1686 *(static_cast<MdpPipeInfoNonSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001687 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
1688 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1689 eIsFg isFg = IS_FG_OFF;
1690 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001691
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001692 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
1693 __FUNCTION__, layer, zOrder, dest);
1694
Saurabh Shah88e4d272013-09-03 13:31:29 -07001695 return configureNonSplit(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001696 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001697}
1698
Saurabh Shah88e4d272013-09-03 13:31:29 -07001699bool MDPCompNonSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001700 hwc_display_contents_1_t* list) {
1701 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001702
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001703 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001704
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001705 hwc_layer_1_t* layer = &list->hwLayers[index];
1706 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301707 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001708 if(allocSplitVGPipesfor4k2k(ctx, index)){
radhakrishnac9a67412013-09-25 17:40:42 +05301709 continue;
1710 }
1711 }
1712
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001713 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001714 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001715 info.pipeInfo = new MdpPipeInfoNonSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08001716 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001717 MdpPipeInfoNonSplit& pipe_info = *(MdpPipeInfoNonSplit*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001718
Saurabh Shahc62f3982014-03-05 14:28:26 -08001719 Overlay::PipeSpecs pipeSpecs;
1720 pipeSpecs.formatClass = isYuvBuffer(hnd) ?
1721 Overlay::FORMAT_YUV : Overlay::FORMAT_RGB;
1722 pipeSpecs.needsScaling = qhwc::needsScaling(layer) or
1723 (qdutils::MDPVersion::getInstance().is8x26() and
1724 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres > 1024);
1725 pipeSpecs.dpy = mDpy;
1726 pipeSpecs.fb = false;
Xu Yang1e686f62014-04-08 13:56:47 +08001727 pipeSpecs.numActiveDisplays = ctx->numActiveDisplays;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001728
Saurabh Shahc62f3982014-03-05 14:28:26 -08001729 pipe_info.index = ctx->mOverlay->getPipe(pipeSpecs);
1730
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001731 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001732 ALOGD_IF(isDebug(), "%s: Unable to get pipe", __FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001733 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001734 }
1735 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001736 return true;
1737}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001738
radhakrishnac9a67412013-09-25 17:40:42 +05301739int MDPCompNonSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1740 PipeLayerPair& PipeLayerPair) {
1741 MdpYUVPipeInfo& mdp_info =
1742 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1743 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1744 eIsFg isFg = IS_FG_OFF;
1745 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1746 eDest lDest = mdp_info.lIndex;
1747 eDest rDest = mdp_info.rIndex;
1748
1749 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1750 lDest, rDest, &PipeLayerPair.rot);
1751}
1752
Saurabh Shah88e4d272013-09-03 13:31:29 -07001753bool MDPCompNonSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001754
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001755 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001756 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1757 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -08001758 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001759
1760 if(!ctx || !list) {
1761 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001762 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001763 }
1764
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301765 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1766 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1767 return true;
1768 }
1769
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -08001770 // Set the Handle timeout to true for MDP or MIXED composition.
1771 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount) {
1772 sHandleTimeout = true;
1773 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001774
1775 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001776 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001777
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001778 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1779 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001780 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001781 if(mCurrentFrame.isFBComposed[i]) continue;
1782
Naseer Ahmed5b6708a2012-08-02 13:46:08 -07001783 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001784 private_handle_t *hnd = (private_handle_t *)layer->handle;
1785 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001786 if (!(layer->flags & HWC_COLOR_FILL)) {
1787 ALOGE("%s handle null", __FUNCTION__);
1788 return false;
1789 }
1790 // No PLAY for Color layer
1791 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1792 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001793 }
1794
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001795 int mdpIndex = mCurrentFrame.layerToMDP[i];
1796
radhakrishnac9a67412013-09-25 17:40:42 +05301797 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1798 {
1799 MdpYUVPipeInfo& pipe_info =
1800 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1801 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1802 ovutils::eDest indexL = pipe_info.lIndex;
1803 ovutils::eDest indexR = pipe_info.rIndex;
1804 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301805 uint32_t offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05301806 if(rot) {
1807 rot->queueBuffer(fd, offset);
1808 fd = rot->getDstMemId();
1809 offset = rot->getDstOffset();
1810 }
1811 if(indexL != ovutils::OV_INVALID) {
1812 ovutils::eDest destL = (ovutils::eDest)indexL;
1813 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1814 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1815 if (!ov.queueBuffer(fd, offset, destL)) {
1816 ALOGE("%s: queueBuffer failed for display:%d",
1817 __FUNCTION__, mDpy);
1818 return false;
1819 }
1820 }
1821
1822 if(indexR != ovutils::OV_INVALID) {
1823 ovutils::eDest destR = (ovutils::eDest)indexR;
1824 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1825 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1826 if (!ov.queueBuffer(fd, offset, destR)) {
1827 ALOGE("%s: queueBuffer failed for display:%d",
1828 __FUNCTION__, mDpy);
1829 return false;
1830 }
1831 }
1832 }
1833 else{
1834 MdpPipeInfoNonSplit& pipe_info =
Saurabh Shah88e4d272013-09-03 13:31:29 -07001835 *(MdpPipeInfoNonSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
radhakrishnac9a67412013-09-25 17:40:42 +05301836 ovutils::eDest dest = pipe_info.index;
1837 if(dest == ovutils::OV_INVALID) {
1838 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001839 return false;
radhakrishnac9a67412013-09-25 17:40:42 +05301840 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001841
radhakrishnac9a67412013-09-25 17:40:42 +05301842 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1843 continue;
1844 }
1845
Sushil Chauhandefd3522014-05-13 18:17:12 -07001846 if (!mDpy && (i == mOverlapIndex)) {
1847 hnd = ctx->mCopyBit[mDpy]->getCurrentRenderBuffer();
1848 }
1849
radhakrishnac9a67412013-09-25 17:40:42 +05301850 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1851 using pipe: %d", __FUNCTION__, layer,
1852 hnd, dest );
1853
1854 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301855 uint32_t offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05301856
1857 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1858 if(rot) {
1859 if(!rot->queueBuffer(fd, offset))
1860 return false;
1861 fd = rot->getDstMemId();
1862 offset = rot->getDstOffset();
1863 }
1864
1865 if (!ov.queueBuffer(fd, offset, dest)) {
1866 ALOGE("%s: queueBuffer failed for display:%d ",
1867 __FUNCTION__, mDpy);
1868 return false;
1869 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001870 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001871
1872 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001873 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001874 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001875}
1876
Saurabh Shah88e4d272013-09-03 13:31:29 -07001877//=============MDPCompSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001878
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001879void MDPCompSplit::adjustForSourceSplit(hwc_context_t *ctx,
radhakrishnac9a67412013-09-25 17:40:42 +05301880 hwc_display_contents_1_t* list){
1881 //if 4kx2k yuv layer is totally present in either in left half
1882 //or right half then try splitting the yuv layer to avoid decimation
1883 int n4k2kYuvCount = ctx->listStats[mDpy].yuv4k2kCount;
1884 const int lSplit = getLeftSplit(ctx, mDpy);
1885 for(int index = 0; index < n4k2kYuvCount; index++){
1886 int n4k2kYuvIndex = ctx->listStats[mDpy].yuv4k2kIndices[index];
1887 hwc_layer_1_t* layer = &list->hwLayers[n4k2kYuvIndex];
1888 hwc_rect_t dst = layer->displayFrame;
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001889 if((dst.left > lSplit) || (dst.right < lSplit)) {
radhakrishnac9a67412013-09-25 17:40:42 +05301890 mCurrentFrame.mdpCount += 1;
1891 }
Dileep Kumar Reddi4cff9282014-04-01 12:57:08 +05301892 if(mCurrentFrame.fbZ >= n4k2kYuvIndex){
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001893 mCurrentFrame.fbZ += 1;
1894 }
radhakrishnac9a67412013-09-25 17:40:42 +05301895 }
1896}
1897
Saurabh Shah88e4d272013-09-03 13:31:29 -07001898bool MDPCompSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Saurabh Shahc62f3982014-03-05 14:28:26 -08001899 MdpPipeInfoSplit& pipe_info) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001900
Saurabh Shahc62f3982014-03-05 14:28:26 -08001901 const int lSplit = getLeftSplit(ctx, mDpy);
1902 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001903 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001904 pipe_info.lIndex = ovutils::OV_INVALID;
1905 pipe_info.rIndex = ovutils::OV_INVALID;
1906
Saurabh Shahc62f3982014-03-05 14:28:26 -08001907 Overlay::PipeSpecs pipeSpecs;
1908 pipeSpecs.formatClass = isYuvBuffer(hnd) ?
1909 Overlay::FORMAT_YUV : Overlay::FORMAT_RGB;
1910 pipeSpecs.needsScaling = qhwc::needsScalingWithSplit(ctx, layer, mDpy);
1911 pipeSpecs.dpy = mDpy;
1912 pipeSpecs.mixer = Overlay::MIXER_LEFT;
1913 pipeSpecs.fb = false;
1914
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001915 // Acquire pipe only for the updating half
1916 hwc_rect_t l_roi = ctx->listStats[mDpy].lRoi;
1917 hwc_rect_t r_roi = ctx->listStats[mDpy].rRoi;
1918
1919 if (dst.left < lSplit && isValidRect(getIntersection(dst, l_roi))) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001920 pipe_info.lIndex = ctx->mOverlay->getPipe(pipeSpecs);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001921 if(pipe_info.lIndex == ovutils::OV_INVALID)
1922 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001923 }
1924
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001925 if(dst.right > lSplit && isValidRect(getIntersection(dst, r_roi))) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001926 pipeSpecs.mixer = Overlay::MIXER_RIGHT;
1927 pipe_info.rIndex = ctx->mOverlay->getPipe(pipeSpecs);
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001928 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001929 return false;
1930 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001931
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001932 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001933}
1934
Saurabh Shah88e4d272013-09-03 13:31:29 -07001935bool MDPCompSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001936 hwc_display_contents_1_t* list) {
1937 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001938
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001939 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001940
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001941 hwc_layer_1_t* layer = &list->hwLayers[index];
1942 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301943 hwc_rect_t dst = layer->displayFrame;
1944 const int lSplit = getLeftSplit(ctx, mDpy);
1945 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1946 if((dst.left > lSplit)||(dst.right < lSplit)){
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001947 if(allocSplitVGPipesfor4k2k(ctx, index)){
radhakrishnac9a67412013-09-25 17:40:42 +05301948 continue;
1949 }
1950 }
1951 }
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001952 int mdpIndex = mCurrentFrame.layerToMDP[index];
1953 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001954 info.pipeInfo = new MdpPipeInfoSplit;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001955 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001956 MdpPipeInfoSplit& pipe_info = *(MdpPipeInfoSplit*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001957
Saurabh Shahc62f3982014-03-05 14:28:26 -08001958 if(!acquireMDPPipes(ctx, layer, pipe_info)) {
1959 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type",
1960 __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001961 return false;
1962 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001963 }
1964 return true;
1965}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001966
radhakrishnac9a67412013-09-25 17:40:42 +05301967int MDPCompSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1968 PipeLayerPair& PipeLayerPair) {
1969 const int lSplit = getLeftSplit(ctx, mDpy);
1970 hwc_rect_t dst = layer->displayFrame;
1971 if((dst.left > lSplit)||(dst.right < lSplit)){
1972 MdpYUVPipeInfo& mdp_info =
1973 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1974 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1975 eIsFg isFg = IS_FG_OFF;
1976 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1977 eDest lDest = mdp_info.lIndex;
1978 eDest rDest = mdp_info.rIndex;
1979
1980 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1981 lDest, rDest, &PipeLayerPair.rot);
1982 }
1983 else{
1984 return configure(ctx, layer, PipeLayerPair);
1985 }
1986}
1987
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001988/*
1989 * Configures pipe(s) for MDP composition
1990 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001991int MDPCompSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001992 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001993 MdpPipeInfoSplit& mdp_info =
1994 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001995 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1996 eIsFg isFg = IS_FG_OFF;
1997 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1998 eDest lDest = mdp_info.lIndex;
1999 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08002000
2001 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
2002 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
2003
Saurabh Shah88e4d272013-09-03 13:31:29 -07002004 return configureSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08002005 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002006}
2007
Saurabh Shah88e4d272013-09-03 13:31:29 -07002008bool MDPCompSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002009
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08002010 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002011 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
2012 return true;
2013 }
2014
2015 if(!ctx || !list) {
2016 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002017 return false;
2018 }
2019
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05302020 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
2021 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
2022 return true;
2023 }
2024
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -08002025 // Set the Handle timeout to true for MDP or MIXED composition.
2026 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount) {
2027 sHandleTimeout = true;
2028 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002029
Naseer Ahmed54821fe2012-11-28 18:44:38 -05002030 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08002031 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002032
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08002033 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
2034 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002035 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08002036 if(mCurrentFrame.isFBComposed[i]) continue;
2037
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002038 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08002039 private_handle_t *hnd = (private_handle_t *)layer->handle;
2040 if(!hnd) {
2041 ALOGE("%s handle null", __FUNCTION__);
2042 return false;
2043 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002044
2045 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
2046 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002047 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002048
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08002049 int mdpIndex = mCurrentFrame.layerToMDP[i];
2050
radhakrishnac9a67412013-09-25 17:40:42 +05302051 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
2052 {
2053 MdpYUVPipeInfo& pipe_info =
2054 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
2055 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
2056 ovutils::eDest indexL = pipe_info.lIndex;
2057 ovutils::eDest indexR = pipe_info.rIndex;
2058 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05302059 uint32_t offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05302060 if(rot) {
2061 rot->queueBuffer(fd, offset);
2062 fd = rot->getDstMemId();
2063 offset = rot->getDstOffset();
2064 }
2065 if(indexL != ovutils::OV_INVALID) {
2066 ovutils::eDest destL = (ovutils::eDest)indexL;
2067 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
2068 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
2069 if (!ov.queueBuffer(fd, offset, destL)) {
2070 ALOGE("%s: queueBuffer failed for display:%d",
2071 __FUNCTION__, mDpy);
2072 return false;
2073 }
2074 }
Saurabh Shahacf10202013-02-26 10:15:15 -08002075
radhakrishnac9a67412013-09-25 17:40:42 +05302076 if(indexR != ovutils::OV_INVALID) {
2077 ovutils::eDest destR = (ovutils::eDest)indexR;
2078 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
2079 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
2080 if (!ov.queueBuffer(fd, offset, destR)) {
2081 ALOGE("%s: queueBuffer failed for display:%d",
2082 __FUNCTION__, mDpy);
2083 return false;
2084 }
Saurabh Shaha9da08f2013-07-03 13:27:53 -07002085 }
2086 }
radhakrishnac9a67412013-09-25 17:40:42 +05302087 else{
2088 MdpPipeInfoSplit& pipe_info =
2089 *(MdpPipeInfoSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
2090 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07002091
radhakrishnac9a67412013-09-25 17:40:42 +05302092 ovutils::eDest indexL = pipe_info.lIndex;
2093 ovutils::eDest indexR = pipe_info.rIndex;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002094
Sushil Chauhandefd3522014-05-13 18:17:12 -07002095 if (!mDpy && (i == mOverlapIndex)) {
2096 hnd = ctx->mCopyBit[mDpy]->getCurrentRenderBuffer();
2097 }
2098
radhakrishnac9a67412013-09-25 17:40:42 +05302099 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05302100 int offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05302101
Tatenda Chipeperekwa88fe6352014-04-14 10:36:06 -07002102 if(ctx->mAD->draw(ctx, fd, offset)) {
2103 fd = ctx->mAD->getDstFd();
2104 offset = ctx->mAD->getDstOffset();
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002105 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002106
radhakrishnac9a67412013-09-25 17:40:42 +05302107 if(rot) {
2108 rot->queueBuffer(fd, offset);
2109 fd = rot->getDstMemId();
2110 offset = rot->getDstOffset();
2111 }
2112
2113 //************* play left mixer **********
2114 if(indexL != ovutils::OV_INVALID) {
2115 ovutils::eDest destL = (ovutils::eDest)indexL;
2116 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
2117 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
2118 if (!ov.queueBuffer(fd, offset, destL)) {
2119 ALOGE("%s: queueBuffer failed for left mixer",
2120 __FUNCTION__);
2121 return false;
2122 }
2123 }
2124
2125 //************* play right mixer **********
2126 if(indexR != ovutils::OV_INVALID) {
2127 ovutils::eDest destR = (ovutils::eDest)indexR;
2128 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
2129 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
2130 if (!ov.queueBuffer(fd, offset, destR)) {
2131 ALOGE("%s: queueBuffer failed for right mixer",
2132 __FUNCTION__);
2133 return false;
2134 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002135 }
2136 }
Saurabh Shahacf10202013-02-26 10:15:15 -08002137
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002138 layerProp[i].mFlags &= ~HWC_MDPCOMP;
2139 }
Saurabh Shahacf10202013-02-26 10:15:15 -08002140
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002141 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002142}
Saurabh Shahab47c692014-02-12 18:45:57 -08002143
2144//================MDPCompSrcSplit==============================================
2145bool MDPCompSrcSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Saurabh Shahc62f3982014-03-05 14:28:26 -08002146 MdpPipeInfoSplit& pipe_info) {
Saurabh Shahab47c692014-02-12 18:45:57 -08002147 private_handle_t *hnd = (private_handle_t *)layer->handle;
2148 hwc_rect_t dst = layer->displayFrame;
2149 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
2150 pipe_info.lIndex = ovutils::OV_INVALID;
2151 pipe_info.rIndex = ovutils::OV_INVALID;
2152
2153 //If 2 pipes are staged on a single stage of a mixer, then the left pipe
2154 //should have a higher priority than the right one. Pipe priorities are
2155 //starting with VG0, VG1 ... , RGB0 ..., DMA1
Saurabh Shahab47c692014-02-12 18:45:57 -08002156
Saurabh Shahc62f3982014-03-05 14:28:26 -08002157 Overlay::PipeSpecs pipeSpecs;
2158 pipeSpecs.formatClass = isYuvBuffer(hnd) ?
2159 Overlay::FORMAT_YUV : Overlay::FORMAT_RGB;
2160 pipeSpecs.needsScaling = qhwc::needsScaling(layer);
2161 pipeSpecs.dpy = mDpy;
2162 pipeSpecs.fb = false;
2163
Saurabh Shahab47c692014-02-12 18:45:57 -08002164 //1 pipe by default for a layer
Saurabh Shahc62f3982014-03-05 14:28:26 -08002165 pipe_info.lIndex = ctx->mOverlay->getPipe(pipeSpecs);
Saurabh Shahab47c692014-02-12 18:45:57 -08002166 if(pipe_info.lIndex == ovutils::OV_INVALID) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08002167 return false;
Saurabh Shahab47c692014-02-12 18:45:57 -08002168 }
2169
2170 //If layer's crop width or dest width > 2048, use 2 pipes
2171 if((dst.right - dst.left) > qdutils::MAX_DISPLAY_DIM or
2172 (crop.right - crop.left) > qdutils::MAX_DISPLAY_DIM) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08002173 pipe_info.rIndex = ctx->mOverlay->getPipe(pipeSpecs);
Saurabh Shahab47c692014-02-12 18:45:57 -08002174 if(pipe_info.rIndex == ovutils::OV_INVALID) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08002175 return false;
Saurabh Shahdd8237a2014-02-28 14:29:09 -08002176 }
2177
2178 // Return values
2179 // 1 Left pipe is higher priority, do nothing.
2180 // 0 Pipes of same priority.
2181 //-1 Right pipe is of higher priority, needs swap.
2182 if(ctx->mOverlay->comparePipePriority(pipe_info.lIndex,
2183 pipe_info.rIndex) == -1) {
2184 qhwc::swap(pipe_info.lIndex, pipe_info.rIndex);
Saurabh Shahab47c692014-02-12 18:45:57 -08002185 }
2186 }
2187
2188 return true;
2189}
2190
Saurabh Shahab47c692014-02-12 18:45:57 -08002191int MDPCompSrcSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
2192 PipeLayerPair& PipeLayerPair) {
2193 private_handle_t *hnd = (private_handle_t *)layer->handle;
2194 if(!hnd) {
2195 ALOGE("%s: layer handle is NULL", __FUNCTION__);
2196 return -1;
2197 }
2198 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
2199 MdpPipeInfoSplit& mdp_info =
2200 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
2201 Rotator **rot = &PipeLayerPair.rot;
2202 eZorder z = static_cast<eZorder>(mdp_info.zOrder);
2203 eIsFg isFg = IS_FG_OFF;
2204 eDest lDest = mdp_info.lIndex;
2205 eDest rDest = mdp_info.rIndex;
2206 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
2207 hwc_rect_t dst = layer->displayFrame;
2208 int transform = layer->transform;
2209 eTransform orient = static_cast<eTransform>(transform);
2210 const int downscale = 0;
2211 int rotFlags = ROT_FLAGS_NONE;
2212 uint32_t format = ovutils::getMdpFormat(hnd->format, isTileRendered(hnd));
2213 Whf whf(getWidth(hnd), getHeight(hnd), format, hnd->size);
2214
2215 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
2216 "dest_pipeR: %d",__FUNCTION__, layer, z, lDest, rDest);
2217
2218 // Handle R/B swap
2219 if (layer->flags & HWC_FORMAT_RB_SWAP) {
2220 if (hnd->format == HAL_PIXEL_FORMAT_RGBA_8888)
2221 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRA_8888);
2222 else if (hnd->format == HAL_PIXEL_FORMAT_RGBX_8888)
2223 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRX_8888);
2224 }
2225
Saurabh Shah97e2d802014-04-14 18:03:54 -07002226 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
2227 setMdpFlags(layer, mdpFlags, 0, transform);
Saurabh Shahab47c692014-02-12 18:45:57 -08002228
2229 if(lDest != OV_INVALID && rDest != OV_INVALID) {
2230 //Enable overfetch
Saurabh Shah97e2d802014-04-14 18:03:54 -07002231 setMdpFlags(mdpFlags, OV_MDSS_MDP_DUAL_PIPE);
Saurabh Shahab47c692014-02-12 18:45:57 -08002232 }
2233
2234 if(isYuvBuffer(hnd) && (transform & HWC_TRANSFORM_ROT_90)) {
2235 (*rot) = ctx->mRotMgr->getNext();
2236 if((*rot) == NULL) return -1;
Saurabh Shah39240c92014-03-31 10:31:42 -07002237 ctx->mLayerRotMap[mDpy]->add(layer, *rot);
Saurabh Shah1bd5b6f2014-05-19 12:23:13 -07002238 //If the video is using a single pipe, enable BWC
2239 if(rDest == OV_INVALID) {
2240 BwcPM::setBwc(crop, dst, transform, mdpFlags);
2241 }
Saurabh Shahab47c692014-02-12 18:45:57 -08002242 //Configure rotator for pre-rotation
Saurabh Shah97e2d802014-04-14 18:03:54 -07002243 if(configRotator(*rot, whf, crop, mdpFlags, orient, downscale) < 0) {
Saurabh Shahab47c692014-02-12 18:45:57 -08002244 ALOGE("%s: configRotator failed!", __FUNCTION__);
2245 return -1;
2246 }
Saurabh Shahab47c692014-02-12 18:45:57 -08002247 whf.format = (*rot)->getDstFormat();
2248 updateSource(orient, whf, crop);
2249 rotFlags |= ROT_PREROTATED;
2250 }
2251
2252 //If 2 pipes being used, divide layer into half, crop and dst
2253 hwc_rect_t cropL = crop;
2254 hwc_rect_t cropR = crop;
2255 hwc_rect_t dstL = dst;
2256 hwc_rect_t dstR = dst;
2257 if(lDest != OV_INVALID && rDest != OV_INVALID) {
2258 cropL.right = (crop.right + crop.left) / 2;
2259 cropR.left = cropL.right;
2260 sanitizeSourceCrop(cropL, cropR, hnd);
2261
2262 //Swap crops on H flip since 2 pipes are being used
2263 if((orient & OVERLAY_TRANSFORM_FLIP_H) && (*rot) == NULL) {
2264 hwc_rect_t tmp = cropL;
2265 cropL = cropR;
2266 cropR = tmp;
2267 }
2268
2269 dstL.right = (dst.right + dst.left) / 2;
2270 dstR.left = dstL.right;
2271 }
2272
2273 //For the mdp, since either we are pre-rotating or MDP does flips
2274 orient = OVERLAY_TRANSFORM_0;
2275 transform = 0;
2276
2277 //configure left pipe
2278 if(lDest != OV_INVALID) {
Saurabh Shah97e2d802014-04-14 18:03:54 -07002279 PipeArgs pargL(mdpFlags, whf, z, isFg,
Saurabh Shahab47c692014-02-12 18:45:57 -08002280 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2281 (ovutils::eBlending) getBlending(layer->blending));
2282
2283 if(configMdp(ctx->mOverlay, pargL, orient,
2284 cropL, dstL, metadata, lDest) < 0) {
2285 ALOGE("%s: commit failed for left mixer config", __FUNCTION__);
2286 return -1;
2287 }
2288 }
2289
2290 //configure right pipe
2291 if(rDest != OV_INVALID) {
Saurabh Shah97e2d802014-04-14 18:03:54 -07002292 PipeArgs pargR(mdpFlags, whf, z, isFg,
Saurabh Shahab47c692014-02-12 18:45:57 -08002293 static_cast<eRotFlags>(rotFlags),
2294 layer->planeAlpha,
2295 (ovutils::eBlending) getBlending(layer->blending));
2296 if(configMdp(ctx->mOverlay, pargR, orient,
2297 cropR, dstR, metadata, rDest) < 0) {
2298 ALOGE("%s: commit failed for right mixer config", __FUNCTION__);
2299 return -1;
2300 }
2301 }
2302
2303 return 0;
2304}
2305
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002306}; //namespace
2307