blob: 204d275f061f6df301f784a971064a3c44798ae0 [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
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080062void MDPComp::dump(android::String8& buf)
63{
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);
76 dumpsys_log(buf," --------------------------------------------- \n");
77 dumpsys_log(buf," listIdx | cached? | mdpIndex | comptype | Z \n");
78 dumpsys_log(buf," --------------------------------------------- \n");
79 for(int index = 0; index < mCurrentFrame.layerCount; index++ )
80 dumpsys_log(buf," %7d | %7s | %8d | %9s | %2d \n",
81 index,
82 (mCurrentFrame.isFBComposed[index] ? "YES" : "NO"),
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -070083 mCurrentFrame.layerToMDP[index],
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080084 (mCurrentFrame.isFBComposed[index] ?
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -070085 (mCurrentFrame.drop[index] ? "DROP" :
86 (mCurrentFrame.needsRedraw ? "GLES" : "CACHE")) : "MDP"),
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080087 (mCurrentFrame.isFBComposed[index] ? mCurrentFrame.fbZ :
88 mCurrentFrame.mdpToLayer[mCurrentFrame.layerToMDP[index]].pipeInfo->zOrder));
89 dumpsys_log(buf,"\n");
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080090}
91
92bool MDPComp::init(hwc_context_t *ctx) {
93
94 if(!ctx) {
95 ALOGE("%s: Invalid hwc context!!",__FUNCTION__);
96 return false;
97 }
98
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080099 char property[PROPERTY_VALUE_MAX];
100
101 sEnabled = false;
102 if((property_get("persist.hwc.mdpcomp.enable", property, NULL) > 0) &&
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800103 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
104 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800105 sEnabled = true;
106 }
107
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700108 sEnableMixedMode = true;
109 if((property_get("debug.mdpcomp.mixedmode.disable", property, NULL) > 0) &&
110 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
111 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
112 sEnableMixedMode = false;
113 }
114
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800115 if(property_get("debug.mdpcomp.logs", property, NULL) > 0) {
116 if(atoi(property) != 0)
117 sDebugLogs = true;
118 }
119
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800120 sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
Saurabh Shah85234ec2013-04-12 17:09:00 -0700121 if(property_get("debug.mdpcomp.maxpermixer", property, "-1") > 0) {
122 int val = atoi(property);
123 if(val >= 0)
124 sMaxPipesPerMixer = min(val, MAX_PIPES_PER_MIXER);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800125 }
126
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400127 if(ctx->mMDP.panel != MIPI_CMD_PANEL) {
128 // Idle invalidation is not necessary on command mode panels
129 long idle_timeout = DEFAULT_IDLE_TIME;
130 if(property_get("debug.mdpcomp.idletime", property, NULL) > 0) {
131 if(atoi(property) != 0)
132 idle_timeout = atoi(property);
133 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800134
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400135 //create Idle Invalidator only when not disabled through property
136 if(idle_timeout != -1)
137 idleInvalidator = IdleInvalidator::getInstance();
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800138
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400139 if(idleInvalidator == NULL) {
140 ALOGE("%s: failed to instantiate idleInvalidator object",
141 __FUNCTION__);
142 } else {
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530143 idleInvalidator->init(timeout_handler, ctx,
144 (unsigned int)idle_timeout);
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400145 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800146 }
radhakrishnac9a67412013-09-25 17:40:42 +0530147
148 if((property_get("debug.mdpcomp.4k2kSplit", property, "0") > 0) &&
149 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
150 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
151 sEnable4k2kYUVSplit = true;
152 }
Sushil Chauhandefd3522014-05-13 18:17:12 -0700153
154 if ((property_get("persist.hwc.ptor.enable", property, NULL) > 0) &&
155 ((!strncasecmp(property, "true", PROPERTY_VALUE_MAX )) ||
156 (!strncmp(property, "1", PROPERTY_VALUE_MAX )))) {
157 ctx->mCopyBit[HWC_DISPLAY_PRIMARY] = new CopyBit(ctx,
158 HWC_DISPLAY_PRIMARY);
159 }
160
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700161 return true;
162}
163
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800164void MDPComp::reset(hwc_context_t *ctx) {
165 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700166 mCurrentFrame.reset(numLayers);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800167 ctx->mOverlay->clear(mDpy);
168 ctx->mLayerRotMap[mDpy]->clear();
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700169}
170
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700171void MDPComp::timeout_handler(void *udata) {
172 struct hwc_context_t* ctx = (struct hwc_context_t*)(udata);
173
174 if(!ctx) {
175 ALOGE("%s: received empty data in timer callback", __FUNCTION__);
176 return;
177 }
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -0800178 Locker::Autolock _l(ctx->mDrawLock);
179 // Handle timeout event only if the previous composition is MDP or MIXED.
180 if(!sHandleTimeout) {
181 ALOGD_IF(isDebug(), "%s:Do not handle this timeout", __FUNCTION__);
182 return;
183 }
Jesse Hall3be78d92012-08-21 15:12:23 -0700184 if(!ctx->proc) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700185 ALOGE("%s: HWC proc not registered", __FUNCTION__);
186 return;
187 }
188 sIdleFallBack = true;
189 /* Trigger SF to redraw the current frame */
Jesse Hall3be78d92012-08-21 15:12:23 -0700190 ctx->proc->invalidate(ctx->proc);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700191}
192
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800193void MDPComp::setMDPCompLayerFlags(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800194 hwc_display_contents_1_t* list) {
195 LayerProp *layerProp = ctx->layerProp[mDpy];
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800196
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800197 for(int index = 0; index < ctx->listStats[mDpy].numAppLayers; index++) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800198 hwc_layer_1_t* layer = &(list->hwLayers[index]);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800199 if(!mCurrentFrame.isFBComposed[index]) {
200 layerProp[index].mFlags |= HWC_MDPCOMP;
201 layer->compositionType = HWC_OVERLAY;
202 layer->hints |= HWC_HINT_CLEAR_FB;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800203 } else {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700204 /* Drop the layer when its already present in FB OR when it lies
205 * outside frame's ROI */
206 if(!mCurrentFrame.needsRedraw || mCurrentFrame.drop[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800207 layer->compositionType = HWC_OVERLAY;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700208 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800209 }
210 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700211}
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500212
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800213void MDPComp::setRedraw(hwc_context_t *ctx,
214 hwc_display_contents_1_t* list) {
215 mCurrentFrame.needsRedraw = false;
216 if(!mCachedFrame.isSameFrame(mCurrentFrame, list) ||
217 (list->flags & HWC_GEOMETRY_CHANGED) ||
218 isSkipPresent(ctx, mDpy)) {
219 mCurrentFrame.needsRedraw = true;
220 }
221}
222
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800223MDPComp::FrameInfo::FrameInfo() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700224 reset(0);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800225}
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800226
Saurabh Shahaa236822013-04-24 18:07:26 -0700227void MDPComp::FrameInfo::reset(const int& numLayers) {
228 for(int i = 0 ; i < MAX_PIPES_PER_MIXER && numLayers; i++ ) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800229 if(mdpToLayer[i].pipeInfo) {
230 delete mdpToLayer[i].pipeInfo;
231 mdpToLayer[i].pipeInfo = NULL;
232 //We dont own the rotator
233 mdpToLayer[i].rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800234 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800235 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800236
237 memset(&mdpToLayer, 0, sizeof(mdpToLayer));
238 memset(&layerToMDP, -1, sizeof(layerToMDP));
Saurabh Shahaa236822013-04-24 18:07:26 -0700239 memset(&isFBComposed, 1, sizeof(isFBComposed));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800240
Saurabh Shahaa236822013-04-24 18:07:26 -0700241 layerCount = numLayers;
242 fbCount = numLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800243 mdpCount = 0;
Saurabh Shah2f3895f2013-05-02 10:13:31 -0700244 needsRedraw = true;
Saurabh Shahd53bc5f2014-02-05 10:17:43 -0800245 fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800246}
247
Saurabh Shahaa236822013-04-24 18:07:26 -0700248void MDPComp::FrameInfo::map() {
249 // populate layer and MDP maps
250 int mdpIdx = 0;
251 for(int idx = 0; idx < layerCount; idx++) {
252 if(!isFBComposed[idx]) {
253 mdpToLayer[mdpIdx].listIndex = idx;
254 layerToMDP[idx] = mdpIdx++;
255 }
256 }
257}
258
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800259MDPComp::LayerCache::LayerCache() {
260 reset();
261}
262
263void MDPComp::LayerCache::reset() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700264 memset(&hnd, 0, sizeof(hnd));
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530265 memset(&isFBComposed, true, sizeof(isFBComposed));
266 memset(&drop, false, sizeof(drop));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800267 layerCount = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -0700268}
269
270void MDPComp::LayerCache::cacheAll(hwc_display_contents_1_t* list) {
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530271 const int numAppLayers = (int)list->numHwLayers - 1;
Saurabh Shahaa236822013-04-24 18:07:26 -0700272 for(int i = 0; i < numAppLayers; i++) {
273 hnd[i] = list->hwLayers[i].handle;
274 }
275}
276
277void MDPComp::LayerCache::updateCounts(const FrameInfo& curFrame) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700278 layerCount = curFrame.layerCount;
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530279 memcpy(&isFBComposed, &curFrame.isFBComposed, sizeof(isFBComposed));
280 memcpy(&drop, &curFrame.drop, sizeof(drop));
281}
282
Jeykumar Sankaran988d3682013-11-15 11:57:16 -0800283bool MDPComp::LayerCache::isSameFrame(const FrameInfo& curFrame,
284 hwc_display_contents_1_t* list) {
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530285 if(layerCount != curFrame.layerCount)
286 return false;
287 for(int i = 0; i < curFrame.layerCount; i++) {
288 if((curFrame.isFBComposed[i] != isFBComposed[i]) ||
289 (curFrame.drop[i] != drop[i])) {
290 return false;
291 }
Jeykumar Sankaran988d3682013-11-15 11:57:16 -0800292 if(curFrame.isFBComposed[i] &&
293 (hnd[i] != list->hwLayers[i].handle)){
294 return false;
295 }
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530296 }
297 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800298}
299
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700300bool MDPComp::isSupportedForMDPComp(hwc_context_t *ctx, hwc_layer_1_t* layer) {
301 private_handle_t *hnd = (private_handle_t *)layer->handle;
302 if((not isYuvBuffer(hnd) and has90Transform(layer)) or
303 (not isValidDimension(ctx,layer))
304 //More conditions here, SKIP, sRGB+Blend etc
305 ) {
306 return false;
307 }
308 return true;
309}
310
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530311bool MDPComp::isValidDimension(hwc_context_t *ctx, hwc_layer_1_t *layer) {
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800312 private_handle_t *hnd = (private_handle_t *)layer->handle;
313
314 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -0700315 if (layer->flags & HWC_COLOR_FILL) {
316 // Color layer
317 return true;
318 }
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800319 ALOGE("%s: layer handle is NULL", __FUNCTION__);
320 return false;
321 }
322
Naseer Ahmede850a802013-09-06 13:12:52 -0400323 //XXX: Investigate doing this with pixel phase on MDSS
Naseer Ahmede77f8082013-10-10 13:42:48 -0400324 if(!isSecureBuffer(hnd) && isNonIntegralSourceCrop(layer->sourceCropf))
Naseer Ahmede850a802013-09-06 13:12:52 -0400325 return false;
326
Saurabh Shah62e1d732013-09-17 10:44:05 -0700327 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700328 hwc_rect_t dst = layer->displayFrame;
Saurabh Shah4fdde762013-04-30 18:47:33 -0700329 int crop_w = crop.right - crop.left;
330 int crop_h = crop.bottom - crop.top;
331 int dst_w = dst.right - dst.left;
332 int dst_h = dst.bottom - dst.top;
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800333 float w_scale = ((float)crop_w / (float)dst_w);
334 float h_scale = ((float)crop_h / (float)dst_h);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700335
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800336 /* Workaround for MDP HW limitation in DSI command mode panels where
337 * FPS will not go beyond 30 if buffers on RGB pipes are of width or height
338 * less than 5 pixels
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530339 * There also is a HW limilation in MDP, minimum block size is 2x2
340 * Fallback to GPU if height is less than 2.
341 */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800342 if((crop_w < 5)||(crop_h < 5))
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800343 return false;
344
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800345 if((w_scale > 1.0f) || (h_scale > 1.0f)) {
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700346 const uint32_t maxMDPDownscale =
Saurabh Shah4fdde762013-04-30 18:47:33 -0700347 qdutils::MDPVersion::getInstance().getMaxMDPDownscale();
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800348 const float w_dscale = w_scale;
349 const float h_dscale = h_scale;
350
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800351 if(ctx->mMDP.version >= qdutils::MDSS_V5) {
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700352
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800353 if(!qdutils::MDPVersion::getInstance().supportsDecimation()) {
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700354 /* On targets that doesnt support Decimation (eg.,8x26)
355 * maximum downscale support is overlay pipe downscale.
356 */
357 if(crop_w > MAX_DISPLAY_DIM || w_dscale > maxMDPDownscale ||
358 h_dscale > maxMDPDownscale)
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800359 return false;
360 } else {
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700361 // Decimation on macrotile format layers is not supported.
362 if(isTileRendered(hnd)) {
363 /* MDP can read maximum MAX_DISPLAY_DIM width.
364 * Bail out if
365 * 1. Src crop > MAX_DISPLAY_DIM on nonsplit MDPComp
366 * 2. exceeds maximum downscale limit
367 */
368 if(((crop_w > MAX_DISPLAY_DIM) && !sSrcSplitEnabled) ||
369 w_dscale > maxMDPDownscale ||
370 h_dscale > maxMDPDownscale) {
371 return false;
372 }
373 } else if(w_dscale > 64 || h_dscale > 64)
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800374 return false;
375 }
376 } else { //A-family
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700377 if(w_dscale > maxMDPDownscale || h_dscale > maxMDPDownscale)
Saurabh Shah4fdde762013-04-30 18:47:33 -0700378 return false;
379 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700380 }
381
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800382 if((w_scale < 1.0f) || (h_scale < 1.0f)) {
383 const uint32_t upscale =
384 qdutils::MDPVersion::getInstance().getMaxMDPUpscale();
385 const float w_uscale = 1.0f / w_scale;
386 const float h_uscale = 1.0f / h_scale;
387
388 if(w_uscale > upscale || h_uscale > upscale)
389 return false;
390 }
391
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800392 return true;
393}
394
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800395bool MDPComp::isFrameDoable(hwc_context_t *ctx) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700396 bool ret = true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800397
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800398 if(!isEnabled()) {
399 ALOGD_IF(isDebug(),"%s: MDP Comp. not enabled.", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700400 ret = false;
Raj Kamal068f4572014-04-14 16:14:06 +0530401 } else if((qdutils::MDPVersion::getInstance().is8x26() ||
Prabhanjan Kandula958ffa92014-05-12 14:56:56 +0530402 qdutils::MDPVersion::getInstance().is8x16() ||
403 qdutils::MDPVersion::getInstance().is8x39()) &&
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -0800404 ctx->mVideoTransFlag &&
405 isSecondaryConnected(ctx)) {
Saurabh Shahd4e65852013-06-17 11:33:53 -0700406 //1 Padding round to shift pipes across mixers
407 ALOGD_IF(isDebug(),"%s: MDP Comp. video transition padding round",
408 __FUNCTION__);
409 ret = false;
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -0800410 } else if(isSecondaryConfiguring(ctx)) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800411 ALOGD_IF( isDebug(),"%s: External Display connection is pending",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800412 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700413 ret = false;
Saurabh Shahaa236822013-04-24 18:07:26 -0700414 } else if(ctx->isPaddingRound) {
Raj Kamal9ed3d6b2014-02-07 16:15:17 +0530415 ALOGD_IF(isDebug(), "%s: padding round invoked for dpy %d",
416 __FUNCTION__,mDpy);
Saurabh Shahaa236822013-04-24 18:07:26 -0700417 ret = false;
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700418 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700419 return ret;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800420}
421
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800422void MDPCompNonSplit::trimAgainstROI(hwc_context_t *ctx, hwc_rect_t& fbRect) {
423 hwc_rect_t roi = ctx->listStats[mDpy].lRoi;
424 fbRect = getIntersection(fbRect, roi);
425}
426
427/* 1) Identify layers that are not visible or lying outside the updating ROI and
428 * drop them from composition.
429 * 2) If we have a scaling layer which needs cropping against generated
430 * ROI, reset ROI to full resolution. */
431bool MDPCompNonSplit::validateAndApplyROI(hwc_context_t *ctx,
432 hwc_display_contents_1_t* list) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700433 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800434 hwc_rect_t visibleRect = ctx->listStats[mDpy].lRoi;
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800435
436 for(int i = numAppLayers - 1; i >= 0; i--){
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800437 if(!isValidRect(visibleRect)) {
438 mCurrentFrame.drop[i] = true;
439 mCurrentFrame.dropCount++;
Jeykumar Sankaran0b961452014-01-21 17:26:12 -0800440 continue;
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800441 }
442
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700443 const hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700444 hwc_rect_t dstRect = layer->displayFrame;
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800445 hwc_rect_t res = getIntersection(visibleRect, dstRect);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700446
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700447 if(!isValidRect(res)) {
448 mCurrentFrame.drop[i] = true;
449 mCurrentFrame.dropCount++;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800450 } else {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700451 /* Reset frame ROI when any layer which needs scaling also needs ROI
452 * cropping */
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800453 if(!isSameRect(res, dstRect) && needsScaling (layer)) {
Arpita Banerjeed8965982013-11-08 17:27:33 -0800454 ALOGI("%s: Resetting ROI due to scaling", __FUNCTION__);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700455 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
456 mCurrentFrame.dropCount = 0;
457 return false;
458 }
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800459
Jeykumar Sankaran0b961452014-01-21 17:26:12 -0800460 /* deduct any opaque region from visibleRect */
461 if (layer->blending == HWC_BLENDING_NONE)
462 visibleRect = deductRect(visibleRect, res);
463 }
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700464 }
465 return true;
466}
467
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800468/* Calculate ROI for the frame by accounting all the layer's dispalyFrame which
469 * are updating. If DirtyRegion is applicable, calculate it by accounting all
470 * the changing layer's dirtyRegion. */
471void MDPCompNonSplit::generateROI(hwc_context_t *ctx,
472 hwc_display_contents_1_t* list) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700473 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800474 if(!canPartialUpdate(ctx, list))
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700475 return;
476
477 struct hwc_rect roi = (struct hwc_rect){0, 0, 0, 0};
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800478 hwc_rect fullFrame = (struct hwc_rect) {0, 0,(int)ctx->dpyAttr[mDpy].xres,
479 (int)ctx->dpyAttr[mDpy].yres};
480
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700481 for(int index = 0; index < numAppLayers; index++ ) {
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800482 hwc_layer_1_t* layer = &list->hwLayers[index];
483 if ((mCachedFrame.hnd[index] != layer->handle) ||
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800484 isYuvBuffer((private_handle_t *)layer->handle)) {
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800485 hwc_rect_t updatingRect = layer->displayFrame;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800486
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800487#ifdef QCOM_BSP
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800488 if(!needsScaling(layer) && !layer->transform)
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800489 updatingRect = layer->dirtyRect;
490#endif
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800491
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800492 roi = getUnion(roi, updatingRect);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700493 }
494 }
495
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800496 /* No layer is updating. Still SF wants a refresh.*/
497 if(!isValidRect(roi))
498 return;
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800499
500 // Align ROI coordinates to panel restrictions
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800501 roi = getSanitizeROI(roi, fullFrame);
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800502
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800503 ctx->listStats[mDpy].lRoi = roi;
504 if(!validateAndApplyROI(ctx, list))
505 resetROI(ctx, mDpy);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700506
507 ALOGD_IF(isDebug(),"%s: generated ROI: [%d, %d, %d, %d]", __FUNCTION__,
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800508 ctx->listStats[mDpy].lRoi.left, ctx->listStats[mDpy].lRoi.top,
509 ctx->listStats[mDpy].lRoi.right, ctx->listStats[mDpy].lRoi.bottom);
510}
511
512void MDPCompSplit::trimAgainstROI(hwc_context_t *ctx, hwc_rect_t& fbRect) {
513 hwc_rect l_roi = ctx->listStats[mDpy].lRoi;
514 hwc_rect r_roi = ctx->listStats[mDpy].rRoi;
515
516 hwc_rect_t l_fbRect = getIntersection(fbRect, l_roi);
517 hwc_rect_t r_fbRect = getIntersection(fbRect, r_roi);
518 fbRect = getUnion(l_fbRect, r_fbRect);
519}
520/* 1) Identify layers that are not visible or lying outside BOTH the updating
521 * ROI's and drop them from composition. If a layer is spanning across both
522 * the halves of the screen but needed by only ROI, the non-contributing
523 * half will not be programmed for MDP.
524 * 2) If we have a scaling layer which needs cropping against generated
525 * ROI, reset ROI to full resolution. */
526bool MDPCompSplit::validateAndApplyROI(hwc_context_t *ctx,
527 hwc_display_contents_1_t* list) {
528
529 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
530
531 hwc_rect_t visibleRectL = ctx->listStats[mDpy].lRoi;
532 hwc_rect_t visibleRectR = ctx->listStats[mDpy].rRoi;
533
534 for(int i = numAppLayers - 1; i >= 0; i--){
535 if(!isValidRect(visibleRectL) && !isValidRect(visibleRectR))
536 {
537 mCurrentFrame.drop[i] = true;
538 mCurrentFrame.dropCount++;
539 continue;
540 }
541
542 const hwc_layer_1_t* layer = &list->hwLayers[i];
543 hwc_rect_t dstRect = layer->displayFrame;
544
545 hwc_rect_t l_res = getIntersection(visibleRectL, dstRect);
546 hwc_rect_t r_res = getIntersection(visibleRectR, dstRect);
547 hwc_rect_t res = getUnion(l_res, r_res);
548
549 if(!isValidRect(l_res) && !isValidRect(r_res)) {
550 mCurrentFrame.drop[i] = true;
551 mCurrentFrame.dropCount++;
552 } else {
553 /* Reset frame ROI when any layer which needs scaling also needs ROI
554 * cropping */
555 if(!isSameRect(res, dstRect) && needsScaling (layer)) {
556 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
557 mCurrentFrame.dropCount = 0;
558 return false;
559 }
560
561 if (layer->blending == HWC_BLENDING_NONE) {
562 visibleRectL = deductRect(visibleRectL, l_res);
563 visibleRectR = deductRect(visibleRectR, r_res);
564 }
565 }
566 }
567 return true;
568}
569/* Calculate ROI for the frame by accounting all the layer's dispalyFrame which
570 * are updating. If DirtyRegion is applicable, calculate it by accounting all
571 * the changing layer's dirtyRegion. */
572void MDPCompSplit::generateROI(hwc_context_t *ctx,
573 hwc_display_contents_1_t* list) {
574 if(!canPartialUpdate(ctx, list))
575 return;
576
577 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
578 int lSplit = getLeftSplit(ctx, mDpy);
579
580 int hw_h = (int)ctx->dpyAttr[mDpy].yres;
581 int hw_w = (int)ctx->dpyAttr[mDpy].xres;
582
583 struct hwc_rect l_frame = (struct hwc_rect){0, 0, lSplit, hw_h};
584 struct hwc_rect r_frame = (struct hwc_rect){lSplit, 0, hw_w, hw_h};
585
586 struct hwc_rect l_roi = (struct hwc_rect){0, 0, 0, 0};
587 struct hwc_rect r_roi = (struct hwc_rect){0, 0, 0, 0};
588
589 for(int index = 0; index < numAppLayers; index++ ) {
590 hwc_layer_1_t* layer = &list->hwLayers[index];
591 if ((mCachedFrame.hnd[index] != layer->handle) ||
592 isYuvBuffer((private_handle_t *)layer->handle)) {
Jeykumar Sankaran71e597c2014-05-07 16:23:14 -0700593 hwc_rect_t dst = layer->displayFrame;
594 hwc_rect_t updatingRect = dst;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800595
596#ifdef QCOM_BSP
597 if(!needsScaling(layer) && !layer->transform)
Jeykumar Sankaran71e597c2014-05-07 16:23:14 -0700598 {
599 hwc_rect_t src = integerizeSourceCrop(layer->sourceCropf);
600 int x_off = dst.left - src.left;
601 int y_off = dst.top - src.top;
602 updatingRect = moveRect(layer->dirtyRect, x_off, y_off);
603 }
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800604#endif
605
606 hwc_rect_t l_dst = getIntersection(l_frame, updatingRect);
607 if(isValidRect(l_dst))
608 l_roi = getUnion(l_roi, l_dst);
609
610 hwc_rect_t r_dst = getIntersection(r_frame, updatingRect);
611 if(isValidRect(r_dst))
612 r_roi = getUnion(r_roi, r_dst);
613 }
614 }
615
Jeykumar Sankarana40a9342014-04-25 09:37:10 -0700616 /* For panels that cannot accept commands in both the interfaces, we cannot
617 * send two ROI's (for each half). We merge them into single ROI and split
618 * them across lSplit for MDP mixer use. The ROI's will be merged again
619 * finally before udpating the panel in the driver. */
620 if(qdutils::MDPVersion::getInstance().needsROIMerge()) {
621 hwc_rect_t temp_roi = getUnion(l_roi, r_roi);
622 l_roi = getIntersection(temp_roi, l_frame);
623 r_roi = getIntersection(temp_roi, r_frame);
624 }
625
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800626 /* No layer is updating. Still SF wants a refresh. */
627 if(!isValidRect(l_roi) && !isValidRect(r_roi))
628 return;
629
630 l_roi = getSanitizeROI(l_roi, l_frame);
631 r_roi = getSanitizeROI(r_roi, r_frame);
632
633 ctx->listStats[mDpy].lRoi = l_roi;
634 ctx->listStats[mDpy].rRoi = r_roi;
635
636 if(!validateAndApplyROI(ctx, list))
637 resetROI(ctx, mDpy);
638
639 ALOGD_IF(isDebug(),"%s: generated L_ROI: [%d, %d, %d, %d]"
640 "R_ROI: [%d, %d, %d, %d]", __FUNCTION__,
641 ctx->listStats[mDpy].lRoi.left, ctx->listStats[mDpy].lRoi.top,
642 ctx->listStats[mDpy].lRoi.right, ctx->listStats[mDpy].lRoi.bottom,
643 ctx->listStats[mDpy].rRoi.left, ctx->listStats[mDpy].rRoi.top,
644 ctx->listStats[mDpy].rRoi.right, ctx->listStats[mDpy].rRoi.bottom);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700645}
646
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800647/* Checks for conditions where all the layers marked for MDP comp cannot be
648 * bypassed. On such conditions we try to bypass atleast YUV layers */
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800649bool MDPComp::tryFullFrame(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800650 hwc_display_contents_1_t* list){
651
Saurabh Shahaa236822013-04-24 18:07:26 -0700652 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Arun Kumar K.R2e2871c2014-01-10 12:47:06 -0800653 int priDispW = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800654
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -0700655 if(sIdleFallBack && !ctx->listStats[mDpy].secureUI) {
Saurabh Shah2d998a92013-05-14 17:55:58 -0700656 ALOGD_IF(isDebug(), "%s: Idle fallback dpy %d",__FUNCTION__, mDpy);
657 return false;
658 }
659
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800660 if(isSkipPresent(ctx, mDpy)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700661 ALOGD_IF(isDebug(),"%s: SKIP present: %d",
662 __FUNCTION__,
663 isSkipPresent(ctx, mDpy));
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800664 return false;
665 }
666
Arun Kumar K.R2e2871c2014-01-10 12:47:06 -0800667 if(mDpy > HWC_DISPLAY_PRIMARY && (priDispW > MAX_DISPLAY_DIM) &&
668 (ctx->dpyAttr[mDpy].xres < MAX_DISPLAY_DIM)) {
669 // Disable MDP comp on Secondary when the primary is highres panel and
670 // the secondary is a normal 1080p, because, MDP comp on secondary under
671 // in such usecase, decimation gets used for downscale and there will be
672 // a quality mismatch when there will be a fallback to GPU comp
673 ALOGD_IF(isDebug(), "%s: Disable MDP Compositon for Secondary Disp",
674 __FUNCTION__);
675 return false;
676 }
677
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800678 // check for action safe flag and downscale mode which requires scaling.
679 if(ctx->dpyAttr[mDpy].mActionSafePresent
680 || ctx->dpyAttr[mDpy].mDownScaleMode) {
681 ALOGD_IF(isDebug(), "%s: Scaling needed for this frame",__FUNCTION__);
682 return false;
683 }
684
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800685 for(int i = 0; i < numAppLayers; ++i) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800686 hwc_layer_1_t* layer = &list->hwLayers[i];
687 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800688
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700689 if(isYuvBuffer(hnd) && has90Transform(layer)) {
690 if(!canUseRotator(ctx, mDpy)) {
691 ALOGD_IF(isDebug(), "%s: Can't use rotator for dpy %d",
692 __FUNCTION__, mDpy);
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700693 return false;
694 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800695 }
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530696
697 //For 8x26 with panel width>1k, if RGB layer needs HFLIP fail mdp comp
698 // may not need it if Gfx pre-rotation can handle all flips & rotations
Sushil Chauhanfda00fc2014-03-20 11:08:41 -0700699 int transform = (layer->flags & HWC_COLOR_FILL) ? 0 : layer->transform;
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530700 if(qdutils::MDPVersion::getInstance().is8x26() &&
701 (ctx->dpyAttr[mDpy].xres > 1024) &&
Sushil Chauhanfda00fc2014-03-20 11:08:41 -0700702 (transform & HWC_TRANSFORM_FLIP_H) &&
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530703 (!isYuvBuffer(hnd)))
704 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800705 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700706
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700707 if(ctx->mAD->isDoable()) {
708 return false;
709 }
710
Saurabh Shahaa236822013-04-24 18:07:26 -0700711 //If all above hard conditions are met we can do full or partial MDP comp.
712 bool ret = false;
713 if(fullMDPComp(ctx, list)) {
714 ret = true;
Sushil Chauhandefd3522014-05-13 18:17:12 -0700715 } else if(fullMDPCompWithPTOR(ctx, list)) {
716 ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700717 } else if(partialMDPComp(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700718 ret = true;
719 }
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530720
Saurabh Shahaa236822013-04-24 18:07:26 -0700721 return ret;
722}
723
724bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaran0ad97c42014-03-09 23:00:53 -0700725
726 if(sSimulationFlags & MDPCOMP_AVOID_FULL_MDP)
727 return false;
728
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700729 //Will benefit presentation / secondary-only layer.
730 if((mDpy > HWC_DISPLAY_PRIMARY) &&
731 (list->numHwLayers - 1) > MAX_SEC_LAYERS) {
732 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
733 return false;
734 }
735
736 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
737 for(int i = 0; i < numAppLayers; i++) {
738 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran880da832014-04-18 10:22:35 -0700739 if(not mCurrentFrame.drop[i] and
740 not isSupportedForMDPComp(ctx, layer)) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700741 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",__FUNCTION__);
742 return false;
743 }
744 }
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800745
Saurabh Shahaa236822013-04-24 18:07:26 -0700746 mCurrentFrame.fbCount = 0;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700747 memcpy(&mCurrentFrame.isFBComposed, &mCurrentFrame.drop,
748 sizeof(mCurrentFrame.isFBComposed));
749 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount -
750 mCurrentFrame.dropCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700751
radhakrishnac9a67412013-09-25 17:40:42 +0530752 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800753 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530754 }
755
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800756 if(!postHeuristicsHandling(ctx, list)) {
757 ALOGD_IF(isDebug(), "post heuristic handling failed");
758 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700759 return false;
760 }
Jeykumar Sankaran0ad97c42014-03-09 23:00:53 -0700761 ALOGD_IF(sSimulationFlags,"%s: FULL_MDP_COMP SUCCEEDED",
762 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700763 return true;
764}
765
Sushil Chauhandefd3522014-05-13 18:17:12 -0700766/* Full MDP Composition with Peripheral Tiny Overlap Removal.
767 * MDP bandwidth limitations can be avoided, if the overlap region
768 * covered by the smallest layer at a higher z-order, gets composed
769 * by Copybit on a render buffer, which can be queued to MDP.
770 */
771bool MDPComp::fullMDPCompWithPTOR(hwc_context_t *ctx,
772 hwc_display_contents_1_t* list) {
773
774 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
775 const int stagesForMDP = min(sMaxPipesPerMixer,
776 ctx->mOverlay->availablePipes(mDpy, Overlay::MIXER_DEFAULT));
777
778 // Hard checks where we cannot use this mode
779 if (mDpy || !ctx->mCopyBit[mDpy] || isDisplaySplit(ctx, mDpy)) {
780 ALOGD_IF(isDebug(), "%s: Feature not supported!", __FUNCTION__);
781 return false;
782 }
783
784 // Frame level checks
785 if ((numAppLayers > stagesForMDP) || isSkipPresent(ctx, mDpy) ||
786 isYuvPresent(ctx, mDpy) || mCurrentFrame.dropCount ||
787 isSecurePresent(ctx, mDpy)) {
788 ALOGD_IF(isDebug(), "%s: Frame not supported!", __FUNCTION__);
789 return false;
790 }
791
792 // Find overlap index
793 int overlapIdx = numAppLayers - 1;
794 uint32_t layerPixelCount, minPixelCount = 0;
795 for (int i = numAppLayers - 1; i >= 0; i--) {
796 hwc_layer_1_t* layer = &list->hwLayers[i];
797 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
798 layerPixelCount = (crop.right - crop.left) * (crop.bottom - crop.top);
799 if (!minPixelCount || (layerPixelCount < minPixelCount)) {
800 minPixelCount = layerPixelCount;
801 overlapIdx = i;
802 }
803 }
804
805 // No overlap
806 if (!overlapIdx)
807 return false;
808
809 /* We cannot use this composition mode, if:
810 1. A below layer needs scaling.
811 2. Overlap is not peripheral to display.
812 3. Overlap or a below layer has 90 degree transform.
813 4. Intersection of Overlap layer with a below layer is not valid.
814 5. Overlap area > (1/3 * FrameBuffer) area, based on Perf inputs.
815 */
816
817 hwc_rect_t overlap = list->hwLayers[overlapIdx].displayFrame;
818 if (!isPeripheral(overlap, ctx->mViewFrame[mDpy]))
819 return false;
820
821 if ((3 * (overlap.right - overlap.left) * (overlap.bottom - overlap.top)) >
822 ((int)ctx->dpyAttr[mDpy].xres * (int)ctx->dpyAttr[mDpy].yres))
823 return false;
824
825 for (int i = overlapIdx; i >= 0; i--) {
826 hwc_layer_1_t* layer = &list->hwLayers[i];
827 hwc_rect_t dispFrame = layer->displayFrame;
828
829 if (has90Transform(layer))
830 return false;
831
832 if (i < overlapIdx) {
833 if (needsScaling(layer) ||
834 !isValidRect(getIntersection(dispFrame, overlap)))
835 return false;
836 }
837 }
838
839 mOverlapIndex = overlapIdx;
840 if (!ctx->mCopyBit[mDpy]->prepareOverlap(ctx, list, overlapIdx)) {
841 ALOGD_IF(isDebug(), "%s: Overlap prepare failed!",__FUNCTION__);
842 mOverlapIndex = -1;
843 return false;
844 }
845
846 hwc_rect_t sourceCrop[overlapIdx];
847 hwc_rect_t displayFrame[overlapIdx];
848
849 // Remove overlap from crop & displayFrame of below layers
850 for (int i = 0; i < overlapIdx; i++) {
851 hwc_layer_1_t* layer = &list->hwLayers[i];
852 displayFrame[i] = layer->displayFrame;
853 sourceCrop[i] = integerizeSourceCrop(layer->sourceCropf);
854
855 // Update layer attributes
856 hwc_rect_t srcCrop = integerizeSourceCrop(layer->sourceCropf);
857 hwc_rect_t destRect = deductRect(layer->displayFrame, overlap);
858 qhwc::calculate_crop_rects(srcCrop, layer->displayFrame, destRect,
859 layer->transform);
860
861 layer->sourceCropf.left = (float)srcCrop.left;
862 layer->sourceCropf.top = (float)srcCrop.top;
863 layer->sourceCropf.right = (float)srcCrop.right;
864 layer->sourceCropf.bottom = (float)srcCrop.bottom;
865 }
866
867 mCurrentFrame.mdpCount = numAppLayers;
868 mCurrentFrame.fbCount = 0;
869 mCurrentFrame.fbZ = -1;
870
871 for (int j = 0; j < numAppLayers; j++)
872 mCurrentFrame.isFBComposed[j] = false;
873
874 bool result = postHeuristicsHandling(ctx, list);
875
876 // Restore layer attributes
877 for (int i = 0; i < overlapIdx; i++) {
878 hwc_layer_1_t* layer = &list->hwLayers[i];
879 layer->displayFrame = displayFrame[i];
880 layer->sourceCropf.left = (float)sourceCrop[i].left;
881 layer->sourceCropf.top = (float)sourceCrop[i].top;
882 layer->sourceCropf.right = (float)sourceCrop[i].right;
883 layer->sourceCropf.bottom = (float)sourceCrop[i].bottom;
884 }
885
886 if (!result) {
887 mOverlapIndex = -1;
888 reset(ctx);
889 }
890
891 ALOGD_IF(isDebug(), "%s: Postheuristics %s!, Overlap index = %d",
892 __FUNCTION__, (result ? "successful" : "failed"), mOverlapIndex);
893 return result;
894}
895
Saurabh Shahaa236822013-04-24 18:07:26 -0700896bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
897{
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700898 if(!sEnableMixedMode) {
899 //Mixed mode is disabled. No need to even try caching.
900 return false;
901 }
902
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700903 bool ret = false;
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800904 if(list->flags & HWC_GEOMETRY_CHANGED) { //Try load based first
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800905 ret = loadBasedComp(ctx, list) or
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800906 cacheBasedComp(ctx, list);
907 } else {
908 ret = cacheBasedComp(ctx, list) or
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800909 loadBasedComp(ctx, list);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700910 }
911
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700912 return ret;
913}
914
915bool MDPComp::cacheBasedComp(hwc_context_t *ctx,
916 hwc_display_contents_1_t* list) {
Jeykumar Sankaran0ad97c42014-03-09 23:00:53 -0700917 if(sSimulationFlags & MDPCOMP_AVOID_CACHE_MDP)
918 return false;
919
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700920 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700921 mCurrentFrame.reset(numAppLayers);
922 updateLayerCache(ctx, list);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700923
924 //If an MDP marked layer is unsupported cannot do partial MDP Comp
925 for(int i = 0; i < numAppLayers; i++) {
926 if(!mCurrentFrame.isFBComposed[i]) {
927 hwc_layer_1_t* layer = &list->hwLayers[i];
928 if(not isSupportedForMDPComp(ctx, layer)) {
929 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",
930 __FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800931 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700932 return false;
933 }
934 }
935 }
936
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700937 updateYUV(ctx, list, false /*secure only*/);
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530938 bool ret = markLayersForCaching(ctx, list); //sets up fbZ also
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700939 if(!ret) {
940 ALOGD_IF(isDebug(),"%s: batching failed, dpy %d",__FUNCTION__, mDpy);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800941 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700942 return false;
943 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700944
945 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700946
radhakrishnac9a67412013-09-25 17:40:42 +0530947 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800948 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530949 }
950
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700951 //Will benefit cases where a video has non-updating background.
952 if((mDpy > HWC_DISPLAY_PRIMARY) and
953 (mdpCount > MAX_SEC_LAYERS)) {
954 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800955 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700956 return false;
957 }
958
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800959 if(!postHeuristicsHandling(ctx, list)) {
960 ALOGD_IF(isDebug(), "post heuristic handling failed");
961 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700962 return false;
963 }
Jeykumar Sankaran0ad97c42014-03-09 23:00:53 -0700964 ALOGD_IF(sSimulationFlags,"%s: CACHE_MDP_COMP SUCCEEDED",
965 __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700966
Saurabh Shahaa236822013-04-24 18:07:26 -0700967 return true;
968}
969
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800970bool MDPComp::loadBasedComp(hwc_context_t *ctx,
Saurabh Shahb772ae32013-11-18 15:40:02 -0800971 hwc_display_contents_1_t* list) {
Jeykumar Sankaran0ad97c42014-03-09 23:00:53 -0700972 if(sSimulationFlags & MDPCOMP_AVOID_LOAD_MDP)
973 return false;
974
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -0800975 if(not isLoadBasedCompDoable(ctx)) {
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800976 return false;
977 }
978
Saurabh Shahb772ae32013-11-18 15:40:02 -0800979 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800980 const int numNonDroppedLayers = numAppLayers - mCurrentFrame.dropCount;
981 const int stagesForMDP = min(sMaxPipesPerMixer,
982 ctx->mOverlay->availablePipes(mDpy, Overlay::MIXER_DEFAULT));
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800983
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800984 int mdpBatchSize = stagesForMDP - 1; //1 stage for FB
985 int fbBatchSize = numNonDroppedLayers - mdpBatchSize;
986 int lastMDPSupportedIndex = numAppLayers;
987 int dropCount = 0;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800988
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800989 //Find the minimum MDP batch size
990 for(int i = 0; i < numAppLayers;i++) {
991 if(mCurrentFrame.drop[i]) {
992 dropCount++;
Jeykumar Sankaran846e2792014-01-23 21:59:58 -0800993 continue;
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800994 }
995 hwc_layer_1_t* layer = &list->hwLayers[i];
996 if(not isSupportedForMDPComp(ctx, layer)) {
997 lastMDPSupportedIndex = i;
998 mdpBatchSize = min(i - dropCount, stagesForMDP - 1);
999 fbBatchSize = numNonDroppedLayers - mdpBatchSize;
Jeykumar Sankaran846e2792014-01-23 21:59:58 -08001000 break;
Saurabh Shahb772ae32013-11-18 15:40:02 -08001001 }
Saurabh Shahb772ae32013-11-18 15:40:02 -08001002 }
1003
Saurabh Shahbe7bd322014-02-20 16:18:45 -08001004 ALOGD_IF(isDebug(), "%s:Before optimizing fbBatch, mdpbatch %d, fbbatch %d "
1005 "dropped %d", __FUNCTION__, mdpBatchSize, fbBatchSize,
1006 mCurrentFrame.dropCount);
1007
1008 //Start at a point where the fb batch should at least have 2 layers, for
1009 //this mode to be justified.
1010 while(fbBatchSize < 2) {
1011 ++fbBatchSize;
1012 --mdpBatchSize;
Jeykumar Sankaran846e2792014-01-23 21:59:58 -08001013 }
Saurabh Shahb772ae32013-11-18 15:40:02 -08001014
Saurabh Shahbe7bd322014-02-20 16:18:45 -08001015 //If there are no layers for MDP, this mode doesnt make sense.
1016 if(mdpBatchSize < 1) {
1017 ALOGD_IF(isDebug(), "%s: No MDP layers after optimizing for fbBatch",
1018 __FUNCTION__);
Saurabh Shahb772ae32013-11-18 15:40:02 -08001019 return false;
1020 }
1021
Saurabh Shahbe7bd322014-02-20 16:18:45 -08001022 mCurrentFrame.reset(numAppLayers);
1023
1024 //Try with successively smaller mdp batch sizes until we succeed or reach 1
1025 while(mdpBatchSize > 0) {
1026 //Mark layers for MDP comp
1027 int mdpBatchLeft = mdpBatchSize;
1028 for(int i = 0; i < lastMDPSupportedIndex and mdpBatchLeft; i++) {
1029 if(mCurrentFrame.drop[i]) {
1030 continue;
1031 }
1032 mCurrentFrame.isFBComposed[i] = false;
1033 --mdpBatchLeft;
1034 }
1035
1036 mCurrentFrame.fbZ = mdpBatchSize;
1037 mCurrentFrame.fbCount = fbBatchSize;
1038 mCurrentFrame.mdpCount = mdpBatchSize;
1039
1040 ALOGD_IF(isDebug(), "%s:Trying with: mdpbatch %d fbbatch %d dropped %d",
1041 __FUNCTION__, mdpBatchSize, fbBatchSize,
1042 mCurrentFrame.dropCount);
1043
1044 if(postHeuristicsHandling(ctx, list)) {
1045 ALOGD_IF(isDebug(), "%s: Postheuristics handling succeeded",
Jeykumar Sankaran0ad97c42014-03-09 23:00:53 -07001046 __FUNCTION__);
1047 ALOGD_IF(sSimulationFlags,"%s: LOAD_MDP_COMP SUCCEEDED",
1048 __FUNCTION__);
Saurabh Shahbe7bd322014-02-20 16:18:45 -08001049 return true;
1050 }
1051
1052 reset(ctx);
1053 --mdpBatchSize;
1054 ++fbBatchSize;
1055 }
1056
1057 return false;
Saurabh Shahb772ae32013-11-18 15:40:02 -08001058}
1059
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001060bool MDPComp::isLoadBasedCompDoable(hwc_context_t *ctx) {
Prabhanjan Kandula3dbbd882013-12-11 14:43:46 +05301061 if(mDpy or isSecurePresent(ctx, mDpy) or
1062 isYuvPresent(ctx, mDpy)) {
Saurabh Shah8028e3b2013-10-15 12:27:59 -07001063 return false;
1064 }
1065 return true;
1066}
1067
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001068bool MDPComp::canPartialUpdate(hwc_context_t *ctx,
1069 hwc_display_contents_1_t* list){
1070 if(!qdutils::MDPVersion::getInstance().isPartialUpdateEnabled() ||
1071 isSkipPresent(ctx, mDpy) || (list->flags & HWC_GEOMETRY_CHANGED) ||
1072 mDpy ) {
1073 return false;
1074 }
1075 return true;
1076}
1077
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001078bool MDPComp::tryVideoOnly(hwc_context_t *ctx,
1079 hwc_display_contents_1_t* list) {
1080 const bool secureOnly = true;
1081 return videoOnlyComp(ctx, list, not secureOnly) or
1082 videoOnlyComp(ctx, list, secureOnly);
1083}
1084
1085bool MDPComp::videoOnlyComp(hwc_context_t *ctx,
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001086 hwc_display_contents_1_t* list, bool secureOnly) {
Jeykumar Sankaran0ad97c42014-03-09 23:00:53 -07001087 if(sSimulationFlags & MDPCOMP_AVOID_VIDEO_ONLY)
1088 return false;
Saurabh Shahaa236822013-04-24 18:07:26 -07001089 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001090
Saurabh Shahaa236822013-04-24 18:07:26 -07001091 mCurrentFrame.reset(numAppLayers);
Jeykumar Sankaraneb3a5e22014-04-08 16:07:55 -07001092 mCurrentFrame.fbCount -= mCurrentFrame.dropCount;
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001093 updateYUV(ctx, list, secureOnly);
Saurabh Shah4fdde762013-04-30 18:47:33 -07001094 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001095
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001096 if(!isYuvPresent(ctx, mDpy) or (mdpCount == 0)) {
1097 reset(ctx);
Saurabh Shahaa236822013-04-24 18:07:26 -07001098 return false;
1099 }
1100
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -08001101 /* Bail out if we are processing only secured video layers
1102 * and we dont have any */
1103 if(!isSecurePresent(ctx, mDpy) && secureOnly){
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001104 reset(ctx);
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -08001105 return false;
1106 }
1107
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001108 if(mCurrentFrame.fbCount)
1109 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
Saurabh Shah4fdde762013-04-30 18:47:33 -07001110
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001111 if(sEnable4k2kYUVSplit){
1112 adjustForSourceSplit(ctx, list);
1113 }
1114
1115 if(!postHeuristicsHandling(ctx, list)) {
1116 ALOGD_IF(isDebug(), "post heuristic handling failed");
1117 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001118 return false;
1119 }
1120
Jeykumar Sankaran0ad97c42014-03-09 23:00:53 -07001121 ALOGD_IF(sSimulationFlags,"%s: VIDEO_ONLY_COMP SUCCEEDED",
1122 __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001123 return true;
1124}
1125
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001126/* Checks for conditions where YUV layers cannot be bypassed */
1127bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -07001128 if(isSkipLayer(layer)) {
Saurabh Shahe2474082013-05-15 16:32:13 -07001129 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001130 return false;
1131 }
1132
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -07001133 if(layer->transform & HWC_TRANSFORM_ROT_90 && !canUseRotator(ctx,mDpy)) {
1134 ALOGD_IF(isDebug(), "%s: no free DMA pipe",__FUNCTION__);
1135 return false;
1136 }
1137
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001138 if(isSecuring(ctx, layer)) {
1139 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
1140 return false;
1141 }
1142
Saurabh Shah4fdde762013-04-30 18:47:33 -07001143 if(!isValidDimension(ctx, layer)) {
1144 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
1145 __FUNCTION__);
1146 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001147 }
Saurabh Shah4fdde762013-04-30 18:47:33 -07001148
Naseer Ahmeddc61a972013-07-10 17:50:54 -04001149 if(layer->planeAlpha < 0xFF) {
1150 ALOGD_IF(isDebug(), "%s: Cannot handle YUV layer with plane alpha\
1151 in video only mode",
1152 __FUNCTION__);
1153 return false;
1154 }
1155
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001156 return true;
1157}
1158
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301159/* starts at fromIndex and check for each layer to find
1160 * if it it has overlapping with any Updating layer above it in zorder
1161 * till the end of the batch. returns true if it finds any intersection */
1162bool MDPComp::canPushBatchToTop(const hwc_display_contents_1_t* list,
1163 int fromIndex, int toIndex) {
1164 for(int i = fromIndex; i < toIndex; i++) {
1165 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
1166 if(intersectingUpdatingLayers(list, i+1, toIndex, i)) {
1167 return false;
1168 }
1169 }
1170 }
1171 return true;
1172}
1173
1174/* Checks if given layer at targetLayerIndex has any
1175 * intersection with all the updating layers in beween
1176 * fromIndex and toIndex. Returns true if it finds intersectiion */
1177bool MDPComp::intersectingUpdatingLayers(const hwc_display_contents_1_t* list,
1178 int fromIndex, int toIndex, int targetLayerIndex) {
1179 for(int i = fromIndex; i <= toIndex; i++) {
1180 if(!mCurrentFrame.isFBComposed[i]) {
1181 if(areLayersIntersecting(&list->hwLayers[i],
1182 &list->hwLayers[targetLayerIndex])) {
1183 return true;
1184 }
1185 }
1186 }
1187 return false;
1188}
1189
1190int MDPComp::getBatch(hwc_display_contents_1_t* list,
1191 int& maxBatchStart, int& maxBatchEnd,
1192 int& maxBatchCount) {
1193 int i = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301194 int fbZOrder =-1;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -08001195 int droppedLayerCt = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301196 while (i < mCurrentFrame.layerCount) {
1197 int batchCount = 0;
1198 int batchStart = i;
1199 int batchEnd = i;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -08001200 /* Adjust batch Z order with the dropped layers so far */
1201 int fbZ = batchStart - droppedLayerCt;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301202 int firstZReverseIndex = -1;
Prabhanjan Kandula0ed2cc92013-12-06 12:39:04 +05301203 int updatingLayersAbove = 0;//Updating layer count in middle of batch
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301204 while(i < mCurrentFrame.layerCount) {
1205 if(!mCurrentFrame.isFBComposed[i]) {
1206 if(!batchCount) {
1207 i++;
1208 break;
1209 }
1210 updatingLayersAbove++;
1211 i++;
1212 continue;
1213 } else {
1214 if(mCurrentFrame.drop[i]) {
1215 i++;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -08001216 droppedLayerCt++;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301217 continue;
1218 } else if(updatingLayersAbove <= 0) {
1219 batchCount++;
1220 batchEnd = i;
1221 i++;
1222 continue;
1223 } else { //Layer is FBComposed, not a drop & updatingLayer > 0
1224
1225 // We have a valid updating layer already. If layer-i not
1226 // have overlapping with all updating layers in between
1227 // batch-start and i, then we can add layer i to batch.
1228 if(!intersectingUpdatingLayers(list, batchStart, i-1, i)) {
1229 batchCount++;
1230 batchEnd = i;
1231 i++;
1232 continue;
1233 } else if(canPushBatchToTop(list, batchStart, i)) {
1234 //If All the non-updating layers with in this batch
1235 //does not have intersection with the updating layers
1236 //above in z-order, then we can safely move the batch to
1237 //higher z-order. Increment fbZ as it is moving up.
1238 if( firstZReverseIndex < 0) {
1239 firstZReverseIndex = i;
1240 }
1241 batchCount++;
1242 batchEnd = i;
1243 fbZ += updatingLayersAbove;
1244 i++;
1245 updatingLayersAbove = 0;
1246 continue;
1247 } else {
1248 //both failed.start the loop again from here.
1249 if(firstZReverseIndex >= 0) {
1250 i = firstZReverseIndex;
1251 }
1252 break;
1253 }
1254 }
1255 }
1256 }
1257 if(batchCount > maxBatchCount) {
1258 maxBatchCount = batchCount;
1259 maxBatchStart = batchStart;
1260 maxBatchEnd = batchEnd;
1261 fbZOrder = fbZ;
1262 }
1263 }
1264 return fbZOrder;
1265}
1266
1267bool MDPComp::markLayersForCaching(hwc_context_t* ctx,
1268 hwc_display_contents_1_t* list) {
1269 /* Idea is to keep as many non-updating(cached) layers in FB and
1270 * send rest of them through MDP. This is done in 2 steps.
1271 * 1. Find the maximum contiguous batch of non-updating layers.
1272 * 2. See if we can improve this batch size for caching by adding
1273 * opaque layers around the batch, if they don't have
1274 * any overlapping with the updating layers in between.
1275 * NEVER mark an updating layer for caching.
1276 * But cached ones can be marked for MDP */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001277
1278 int maxBatchStart = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001279 int maxBatchEnd = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001280 int maxBatchCount = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301281 int fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001282
Saurabh Shahd53bc5f2014-02-05 10:17:43 -08001283 /* Nothing is cached. No batching needed */
1284 if(mCurrentFrame.fbCount == 0) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001285 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -07001286 }
Saurabh Shahd53bc5f2014-02-05 10:17:43 -08001287
1288 /* No MDP comp layers, try to use other comp modes */
1289 if(mCurrentFrame.mdpCount == 0) {
1290 return false;
Saurabh Shahaa236822013-04-24 18:07:26 -07001291 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001292
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301293 fbZ = getBatch(list, maxBatchStart, maxBatchEnd, maxBatchCount);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001294
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301295 /* reset rest of the layers lying inside ROI for MDP comp */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001296 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001297 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001298 if((i < maxBatchStart || i > maxBatchEnd) &&
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301299 mCurrentFrame.isFBComposed[i]){
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001300 if(!mCurrentFrame.drop[i]){
1301 //If an unsupported layer is being attempted to
1302 //be pulled out we should fail
1303 if(not isSupportedForMDPComp(ctx, layer)) {
1304 return false;
1305 }
1306 mCurrentFrame.isFBComposed[i] = false;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001307 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001308 }
1309 }
1310
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301311 // update the frame data
1312 mCurrentFrame.fbZ = fbZ;
1313 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001314 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001315 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001316
1317 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301318 mCurrentFrame.fbCount);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001319
1320 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001321}
Saurabh Shah85234ec2013-04-12 17:09:00 -07001322
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001323void MDPComp::updateLayerCache(hwc_context_t* ctx,
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001324 hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001325 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001326 int fbCount = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001327
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001328 for(int i = 0; i < numAppLayers; i++) {
1329 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001330 if(!mCurrentFrame.drop[i])
1331 fbCount++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001332 mCurrentFrame.isFBComposed[i] = true;
1333 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -07001334 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001335 }
1336 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001337
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001338 mCurrentFrame.fbCount = fbCount;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001339 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount
1340 - mCurrentFrame.dropCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001341
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001342 ALOGD_IF(isDebug(),"%s: MDP count: %d FB count %d drop count: %d"
1343 ,__FUNCTION__, mCurrentFrame.mdpCount, mCurrentFrame.fbCount,
1344 mCurrentFrame.dropCount);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001345}
1346
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001347void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list,
1348 bool secureOnly) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001349 int nYuvCount = ctx->listStats[mDpy].yuvCount;
1350 for(int index = 0;index < nYuvCount; index++){
1351 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
1352 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
1353
1354 if(!isYUVDoable(ctx, layer)) {
1355 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
1356 mCurrentFrame.isFBComposed[nYuvIndex] = true;
1357 mCurrentFrame.fbCount++;
1358 }
1359 } else {
1360 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001361 private_handle_t *hnd = (private_handle_t *)layer->handle;
1362 if(!secureOnly || isSecureBuffer(hnd)) {
1363 mCurrentFrame.isFBComposed[nYuvIndex] = false;
1364 mCurrentFrame.fbCount--;
1365 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001366 }
1367 }
1368 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001369
1370 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001371 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
1372 ALOGD_IF(isDebug(),"%s: fb count: %d",__FUNCTION__,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001373 mCurrentFrame.fbCount);
1374}
1375
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001376hwc_rect_t MDPComp::getUpdatingFBRect(hwc_context_t *ctx,
1377 hwc_display_contents_1_t* list){
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001378 hwc_rect_t fbRect = (struct hwc_rect){0, 0, 0, 0};
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001379
1380 /* Update only the region of FB needed for composition */
1381 for(int i = 0; i < mCurrentFrame.layerCount; i++ ) {
1382 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
1383 hwc_layer_1_t* layer = &list->hwLayers[i];
1384 hwc_rect_t dst = layer->displayFrame;
1385 fbRect = getUnion(fbRect, dst);
1386 }
1387 }
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001388 trimAgainstROI(ctx, fbRect);
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001389 return fbRect;
1390}
1391
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001392bool MDPComp::postHeuristicsHandling(hwc_context_t *ctx,
1393 hwc_display_contents_1_t* list) {
1394
1395 //Capability checks
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301396 if(!resourceCheck()) {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001397 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
1398 return false;
1399 }
1400
1401 //Limitations checks
1402 if(!hwLimitationsCheck(ctx, list)) {
1403 ALOGD_IF(isDebug(), "%s: HW limitations",__FUNCTION__);
1404 return false;
1405 }
1406
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001407 //Configure framebuffer first if applicable
1408 if(mCurrentFrame.fbZ >= 0) {
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001409 hwc_rect_t fbRect = getUpdatingFBRect(ctx, list);
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001410 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, fbRect, mCurrentFrame.fbZ))
1411 {
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001412 ALOGD_IF(isDebug(), "%s configure framebuffer failed",
1413 __FUNCTION__);
1414 return false;
1415 }
1416 }
1417
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001418 mCurrentFrame.map();
1419
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001420 if(!allocLayerPipes(ctx, list)) {
1421 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -07001422 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001423 }
1424
1425 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001426 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001427 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001428 int mdpIndex = mCurrentFrame.layerToMDP[index];
1429 hwc_layer_1_t* layer = &list->hwLayers[index];
1430
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301431 //Leave fbZ for framebuffer. CACHE/GLES layers go here.
1432 if(mdpNextZOrder == mCurrentFrame.fbZ) {
1433 mdpNextZOrder++;
1434 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001435 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1436 cur_pipe->zOrder = mdpNextZOrder++;
1437
radhakrishnac9a67412013-09-25 17:40:42 +05301438 private_handle_t *hnd = (private_handle_t *)layer->handle;
1439 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1440 if(configure4k2kYuv(ctx, layer,
1441 mCurrentFrame.mdpToLayer[mdpIndex])
1442 != 0 ){
1443 ALOGD_IF(isDebug(), "%s: Failed to configure split pipes \
1444 for layer %d",__FUNCTION__, index);
1445 return false;
1446 }
1447 else{
1448 mdpNextZOrder++;
1449 }
1450 continue;
1451 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001452 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
1453 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
radhakrishnac9a67412013-09-25 17:40:42 +05301454 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -07001455 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001456 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001457 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001458 }
1459
Saurabh Shaha36be922013-12-16 18:18:39 -08001460 if(!ctx->mOverlay->validateAndSet(mDpy, ctx->dpyAttr[mDpy].fd)) {
1461 ALOGD_IF(isDebug(), "%s: Failed to validate and set overlay for dpy %d"
1462 ,__FUNCTION__, mDpy);
1463 return false;
1464 }
1465
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001466 setRedraw(ctx, list);
Saurabh Shahaa236822013-04-24 18:07:26 -07001467 return true;
1468}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001469
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301470bool MDPComp::resourceCheck() {
Saurabh Shah173f4242013-11-20 09:50:12 -08001471 const bool fbUsed = mCurrentFrame.fbCount;
1472 if(mCurrentFrame.mdpCount > sMaxPipesPerMixer - fbUsed) {
1473 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
1474 return false;
1475 }
Saurabh Shah173f4242013-11-20 09:50:12 -08001476 return true;
1477}
1478
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301479bool MDPComp::hwLimitationsCheck(hwc_context_t* ctx,
1480 hwc_display_contents_1_t* list) {
1481
1482 //A-family hw limitation:
1483 //If a layer need alpha scaling, MDP can not support.
1484 if(ctx->mMDP.version < qdutils::MDSS_V5) {
1485 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1486 if(!mCurrentFrame.isFBComposed[i] &&
1487 isAlphaScaled( &list->hwLayers[i])) {
1488 ALOGD_IF(isDebug(), "%s:frame needs alphaScaling",__FUNCTION__);
1489 return false;
1490 }
1491 }
1492 }
1493
1494 // On 8x26 & 8974 hw, we have a limitation of downscaling+blending.
1495 //If multiple layers requires downscaling and also they are overlapping
1496 //fall back to GPU since MDSS can not handle it.
1497 if(qdutils::MDPVersion::getInstance().is8x74v2() ||
1498 qdutils::MDPVersion::getInstance().is8x26()) {
1499 for(int i = 0; i < mCurrentFrame.layerCount-1; ++i) {
1500 hwc_layer_1_t* botLayer = &list->hwLayers[i];
1501 if(!mCurrentFrame.isFBComposed[i] &&
1502 isDownscaleRequired(botLayer)) {
1503 //if layer-i is marked for MDP and needs downscaling
1504 //check if any MDP layer on top of i & overlaps with layer-i
1505 for(int j = i+1; j < mCurrentFrame.layerCount; ++j) {
1506 hwc_layer_1_t* topLayer = &list->hwLayers[j];
1507 if(!mCurrentFrame.isFBComposed[j] &&
1508 isDownscaleRequired(topLayer)) {
1509 hwc_rect_t r = getIntersection(botLayer->displayFrame,
1510 topLayer->displayFrame);
1511 if(isValidRect(r))
1512 return false;
1513 }
1514 }
1515 }
1516 }
1517 }
1518 return true;
1519}
1520
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001521int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001522 int ret = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -07001523 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran0ad97c42014-03-09 23:00:53 -07001524 char property[PROPERTY_VALUE_MAX];
1525
1526 if(property_get("debug.hwc.simulate", property, NULL) > 0) {
1527 int currentFlags = atoi(property);
1528 if(currentFlags != sSimulationFlags) {
1529 sSimulationFlags = currentFlags;
1530 ALOGE("%s: Simulation Flag read: 0x%x (%d)", __FUNCTION__,
1531 sSimulationFlags, sSimulationFlags);
1532 }
1533 }
Sushil Chauhandefd3522014-05-13 18:17:12 -07001534 mOverlapIndex = -1;
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -07001535
Raj Kamal9ed3d6b2014-02-07 16:15:17 +05301536 //Do not cache the information for next draw cycle.
1537 if(numLayers > MAX_NUM_APP_LAYERS or (!numLayers)) {
1538 ALOGI("%s: Unsupported layer count for mdp composition",
1539 __FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001540 mCachedFrame.reset();
1541 return -1;
1542 }
1543
Saurabh Shahb39f8152013-08-22 10:21:44 -07001544 //reset old data
1545 mCurrentFrame.reset(numLayers);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001546 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1547 mCurrentFrame.dropCount = 0;
Prabhanjan Kandula088bd892013-07-02 23:47:13 +05301548
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -07001549 // Detect the start of animation and fall back to GPU only once to cache
1550 // all the layers in FB and display FB content untill animation completes.
1551 if(ctx->listStats[mDpy].isDisplayAnimating) {
1552 mCurrentFrame.needsRedraw = false;
1553 if(ctx->mAnimationState[mDpy] == ANIMATION_STOPPED) {
1554 mCurrentFrame.needsRedraw = true;
1555 ctx->mAnimationState[mDpy] = ANIMATION_STARTED;
1556 }
1557 setMDPCompLayerFlags(ctx, list);
1558 mCachedFrame.updateCounts(mCurrentFrame);
1559 ret = -1;
1560 return ret;
1561 } else {
1562 ctx->mAnimationState[mDpy] = ANIMATION_STOPPED;
1563 }
1564
Saurabh Shahb39f8152013-08-22 10:21:44 -07001565 //Hard conditions, if not met, cannot do MDP comp
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001566 if(isFrameDoable(ctx)) {
1567 generateROI(ctx, list);
Saurabh Shahb39f8152013-08-22 10:21:44 -07001568
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001569 if(tryFullFrame(ctx, list) || tryVideoOnly(ctx, list)) {
1570 setMDPCompLayerFlags(ctx, list);
1571 } else {
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001572 resetROI(ctx, mDpy);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001573 reset(ctx);
1574 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1575 mCurrentFrame.dropCount = 0;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001576 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001577 }
1578 } else {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001579 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
1580 __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001581 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001582 }
Saurabh Shahb39f8152013-08-22 10:21:44 -07001583
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001584 if(isDebug()) {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001585 ALOGD("GEOMETRY change: %d",
1586 (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001587 android::String8 sDump("");
1588 dump(sDump);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001589 ALOGD("%s",sDump.string());
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001590 }
1591
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001592 mCachedFrame.cacheAll(list);
1593 mCachedFrame.updateCounts(mCurrentFrame);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001594 return ret;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001595}
1596
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001597bool MDPComp::allocSplitVGPipesfor4k2k(hwc_context_t *ctx, int index) {
radhakrishnac9a67412013-09-25 17:40:42 +05301598
1599 bool bRet = true;
radhakrishnac9a67412013-09-25 17:40:42 +05301600 int mdpIndex = mCurrentFrame.layerToMDP[index];
1601 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
1602 info.pipeInfo = new MdpYUVPipeInfo;
1603 info.rot = NULL;
1604 MdpYUVPipeInfo& pipe_info = *(MdpYUVPipeInfo*)info.pipeInfo;
radhakrishnac9a67412013-09-25 17:40:42 +05301605
1606 pipe_info.lIndex = ovutils::OV_INVALID;
1607 pipe_info.rIndex = ovutils::OV_INVALID;
1608
Saurabh Shahc62f3982014-03-05 14:28:26 -08001609 Overlay::PipeSpecs pipeSpecs;
1610 pipeSpecs.formatClass = Overlay::FORMAT_YUV;
1611 pipeSpecs.needsScaling = true;
1612 pipeSpecs.dpy = mDpy;
1613 pipeSpecs.fb = false;
1614
1615 pipe_info.lIndex = ctx->mOverlay->getPipe(pipeSpecs);
radhakrishnac9a67412013-09-25 17:40:42 +05301616 if(pipe_info.lIndex == ovutils::OV_INVALID){
1617 bRet = false;
1618 ALOGD_IF(isDebug(),"%s: allocating first VG pipe failed",
1619 __FUNCTION__);
1620 }
Saurabh Shahc62f3982014-03-05 14:28:26 -08001621 pipe_info.rIndex = ctx->mOverlay->getPipe(pipeSpecs);
radhakrishnac9a67412013-09-25 17:40:42 +05301622 if(pipe_info.rIndex == ovutils::OV_INVALID){
1623 bRet = false;
1624 ALOGD_IF(isDebug(),"%s: allocating second VG pipe failed",
1625 __FUNCTION__);
1626 }
1627 return bRet;
1628}
Sushil Chauhandefd3522014-05-13 18:17:12 -07001629
1630int MDPComp::drawOverlap(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
1631 int fd = -1;
1632 if (mOverlapIndex != -1) {
1633 fd = ctx->mCopyBit[mDpy]->drawOverlap(ctx, list, mOverlapIndex);
1634 if (fd < 0) {
1635 ALOGD_IF(isDebug(),"%s: failed", __FUNCTION__);
1636 mOverlapIndex = -1;
1637 }
1638 }
1639 return fd;
1640}
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001641//=============MDPCompNonSplit==================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001642
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001643void MDPCompNonSplit::adjustForSourceSplit(hwc_context_t *ctx,
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001644 hwc_display_contents_1_t*) {
radhakrishnac9a67412013-09-25 17:40:42 +05301645 //As we split 4kx2k yuv layer and program to 2 VG pipes
1646 //(if available) increase mdpcount accordingly
1647 mCurrentFrame.mdpCount += ctx->listStats[mDpy].yuv4k2kCount;
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001648
1649 //If 4k2k Yuv layer split is possible, and if
1650 //fbz is above 4k2k layer, increment fb zorder by 1
1651 //as we split 4k2k layer and increment zorder for right half
1652 //of the layer
1653 if(mCurrentFrame.fbZ >= 0) {
1654 int n4k2kYuvCount = ctx->listStats[mDpy].yuv4k2kCount;
1655 for(int index = 0; index < n4k2kYuvCount; index++){
1656 int n4k2kYuvIndex =
1657 ctx->listStats[mDpy].yuv4k2kIndices[index];
Dileep Kumar Reddi4cff9282014-04-01 12:57:08 +05301658 if(mCurrentFrame.fbZ >= n4k2kYuvIndex){
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001659 mCurrentFrame.fbZ += 1;
1660 }
1661 }
1662 }
radhakrishnac9a67412013-09-25 17:40:42 +05301663}
1664
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001665/*
1666 * Configures pipe(s) for MDP composition
1667 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001668int MDPCompNonSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001669 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001670 MdpPipeInfoNonSplit& mdp_info =
1671 *(static_cast<MdpPipeInfoNonSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001672 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
1673 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1674 eIsFg isFg = IS_FG_OFF;
1675 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001676
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001677 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
1678 __FUNCTION__, layer, zOrder, dest);
1679
Saurabh Shah88e4d272013-09-03 13:31:29 -07001680 return configureNonSplit(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001681 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001682}
1683
Saurabh Shah88e4d272013-09-03 13:31:29 -07001684bool MDPCompNonSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001685 hwc_display_contents_1_t* list) {
1686 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001687
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001688 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001689
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001690 hwc_layer_1_t* layer = &list->hwLayers[index];
1691 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301692 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001693 if(allocSplitVGPipesfor4k2k(ctx, index)){
radhakrishnac9a67412013-09-25 17:40:42 +05301694 continue;
1695 }
1696 }
1697
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001698 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001699 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001700 info.pipeInfo = new MdpPipeInfoNonSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08001701 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001702 MdpPipeInfoNonSplit& pipe_info = *(MdpPipeInfoNonSplit*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001703
Saurabh Shahc62f3982014-03-05 14:28:26 -08001704 Overlay::PipeSpecs pipeSpecs;
1705 pipeSpecs.formatClass = isYuvBuffer(hnd) ?
1706 Overlay::FORMAT_YUV : Overlay::FORMAT_RGB;
1707 pipeSpecs.needsScaling = qhwc::needsScaling(layer) or
1708 (qdutils::MDPVersion::getInstance().is8x26() and
1709 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres > 1024);
1710 pipeSpecs.dpy = mDpy;
1711 pipeSpecs.fb = false;
Xu Yang1e686f62014-04-08 13:56:47 +08001712 pipeSpecs.numActiveDisplays = ctx->numActiveDisplays;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001713
Saurabh Shahc62f3982014-03-05 14:28:26 -08001714 pipe_info.index = ctx->mOverlay->getPipe(pipeSpecs);
1715
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001716 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001717 ALOGD_IF(isDebug(), "%s: Unable to get pipe", __FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001718 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001719 }
1720 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001721 return true;
1722}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001723
radhakrishnac9a67412013-09-25 17:40:42 +05301724int MDPCompNonSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1725 PipeLayerPair& PipeLayerPair) {
1726 MdpYUVPipeInfo& mdp_info =
1727 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1728 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1729 eIsFg isFg = IS_FG_OFF;
1730 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1731 eDest lDest = mdp_info.lIndex;
1732 eDest rDest = mdp_info.rIndex;
1733
1734 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1735 lDest, rDest, &PipeLayerPair.rot);
1736}
1737
Saurabh Shah88e4d272013-09-03 13:31:29 -07001738bool MDPCompNonSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001739
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001740 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001741 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1742 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -08001743 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001744
1745 if(!ctx || !list) {
1746 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001747 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001748 }
1749
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301750 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1751 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1752 return true;
1753 }
1754
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -08001755 // Set the Handle timeout to true for MDP or MIXED composition.
1756 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount) {
1757 sHandleTimeout = true;
1758 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001759
1760 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001761 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001762
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001763 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1764 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001765 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001766 if(mCurrentFrame.isFBComposed[i]) continue;
1767
Naseer Ahmed5b6708a2012-08-02 13:46:08 -07001768 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001769 private_handle_t *hnd = (private_handle_t *)layer->handle;
1770 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001771 if (!(layer->flags & HWC_COLOR_FILL)) {
1772 ALOGE("%s handle null", __FUNCTION__);
1773 return false;
1774 }
1775 // No PLAY for Color layer
1776 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1777 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001778 }
1779
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001780 int mdpIndex = mCurrentFrame.layerToMDP[i];
1781
radhakrishnac9a67412013-09-25 17:40:42 +05301782 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1783 {
1784 MdpYUVPipeInfo& pipe_info =
1785 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1786 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1787 ovutils::eDest indexL = pipe_info.lIndex;
1788 ovutils::eDest indexR = pipe_info.rIndex;
1789 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301790 uint32_t offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05301791 if(rot) {
1792 rot->queueBuffer(fd, offset);
1793 fd = rot->getDstMemId();
1794 offset = rot->getDstOffset();
1795 }
1796 if(indexL != ovutils::OV_INVALID) {
1797 ovutils::eDest destL = (ovutils::eDest)indexL;
1798 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1799 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1800 if (!ov.queueBuffer(fd, offset, destL)) {
1801 ALOGE("%s: queueBuffer failed for display:%d",
1802 __FUNCTION__, mDpy);
1803 return false;
1804 }
1805 }
1806
1807 if(indexR != ovutils::OV_INVALID) {
1808 ovutils::eDest destR = (ovutils::eDest)indexR;
1809 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1810 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1811 if (!ov.queueBuffer(fd, offset, destR)) {
1812 ALOGE("%s: queueBuffer failed for display:%d",
1813 __FUNCTION__, mDpy);
1814 return false;
1815 }
1816 }
1817 }
1818 else{
1819 MdpPipeInfoNonSplit& pipe_info =
Saurabh Shah88e4d272013-09-03 13:31:29 -07001820 *(MdpPipeInfoNonSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
radhakrishnac9a67412013-09-25 17:40:42 +05301821 ovutils::eDest dest = pipe_info.index;
1822 if(dest == ovutils::OV_INVALID) {
1823 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001824 return false;
radhakrishnac9a67412013-09-25 17:40:42 +05301825 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001826
radhakrishnac9a67412013-09-25 17:40:42 +05301827 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1828 continue;
1829 }
1830
Sushil Chauhandefd3522014-05-13 18:17:12 -07001831 if (!mDpy && (i == mOverlapIndex)) {
1832 hnd = ctx->mCopyBit[mDpy]->getCurrentRenderBuffer();
1833 }
1834
radhakrishnac9a67412013-09-25 17:40:42 +05301835 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1836 using pipe: %d", __FUNCTION__, layer,
1837 hnd, dest );
1838
1839 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301840 uint32_t offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05301841
1842 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1843 if(rot) {
1844 if(!rot->queueBuffer(fd, offset))
1845 return false;
1846 fd = rot->getDstMemId();
1847 offset = rot->getDstOffset();
1848 }
1849
1850 if (!ov.queueBuffer(fd, offset, dest)) {
1851 ALOGE("%s: queueBuffer failed for display:%d ",
1852 __FUNCTION__, mDpy);
1853 return false;
1854 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001855 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001856
1857 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001858 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001859 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001860}
1861
Saurabh Shah88e4d272013-09-03 13:31:29 -07001862//=============MDPCompSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001863
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001864void MDPCompSplit::adjustForSourceSplit(hwc_context_t *ctx,
radhakrishnac9a67412013-09-25 17:40:42 +05301865 hwc_display_contents_1_t* list){
1866 //if 4kx2k yuv layer is totally present in either in left half
1867 //or right half then try splitting the yuv layer to avoid decimation
1868 int n4k2kYuvCount = ctx->listStats[mDpy].yuv4k2kCount;
1869 const int lSplit = getLeftSplit(ctx, mDpy);
1870 for(int index = 0; index < n4k2kYuvCount; index++){
1871 int n4k2kYuvIndex = ctx->listStats[mDpy].yuv4k2kIndices[index];
1872 hwc_layer_1_t* layer = &list->hwLayers[n4k2kYuvIndex];
1873 hwc_rect_t dst = layer->displayFrame;
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001874 if((dst.left > lSplit) || (dst.right < lSplit)) {
radhakrishnac9a67412013-09-25 17:40:42 +05301875 mCurrentFrame.mdpCount += 1;
1876 }
Dileep Kumar Reddi4cff9282014-04-01 12:57:08 +05301877 if(mCurrentFrame.fbZ >= n4k2kYuvIndex){
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001878 mCurrentFrame.fbZ += 1;
1879 }
radhakrishnac9a67412013-09-25 17:40:42 +05301880 }
1881}
1882
Saurabh Shah88e4d272013-09-03 13:31:29 -07001883bool MDPCompSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Saurabh Shahc62f3982014-03-05 14:28:26 -08001884 MdpPipeInfoSplit& pipe_info) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001885
Saurabh Shahc62f3982014-03-05 14:28:26 -08001886 const int lSplit = getLeftSplit(ctx, mDpy);
1887 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001888 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001889 pipe_info.lIndex = ovutils::OV_INVALID;
1890 pipe_info.rIndex = ovutils::OV_INVALID;
1891
Saurabh Shahc62f3982014-03-05 14:28:26 -08001892 Overlay::PipeSpecs pipeSpecs;
1893 pipeSpecs.formatClass = isYuvBuffer(hnd) ?
1894 Overlay::FORMAT_YUV : Overlay::FORMAT_RGB;
1895 pipeSpecs.needsScaling = qhwc::needsScalingWithSplit(ctx, layer, mDpy);
1896 pipeSpecs.dpy = mDpy;
1897 pipeSpecs.mixer = Overlay::MIXER_LEFT;
1898 pipeSpecs.fb = false;
1899
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001900 // Acquire pipe only for the updating half
1901 hwc_rect_t l_roi = ctx->listStats[mDpy].lRoi;
1902 hwc_rect_t r_roi = ctx->listStats[mDpy].rRoi;
1903
1904 if (dst.left < lSplit && isValidRect(getIntersection(dst, l_roi))) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001905 pipe_info.lIndex = ctx->mOverlay->getPipe(pipeSpecs);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001906 if(pipe_info.lIndex == ovutils::OV_INVALID)
1907 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001908 }
1909
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001910 if(dst.right > lSplit && isValidRect(getIntersection(dst, r_roi))) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001911 pipeSpecs.mixer = Overlay::MIXER_RIGHT;
1912 pipe_info.rIndex = ctx->mOverlay->getPipe(pipeSpecs);
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001913 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001914 return false;
1915 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001916
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001917 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001918}
1919
Saurabh Shah88e4d272013-09-03 13:31:29 -07001920bool MDPCompSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001921 hwc_display_contents_1_t* list) {
1922 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001923
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001924 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001925
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001926 hwc_layer_1_t* layer = &list->hwLayers[index];
1927 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301928 hwc_rect_t dst = layer->displayFrame;
1929 const int lSplit = getLeftSplit(ctx, mDpy);
1930 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1931 if((dst.left > lSplit)||(dst.right < lSplit)){
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001932 if(allocSplitVGPipesfor4k2k(ctx, index)){
radhakrishnac9a67412013-09-25 17:40:42 +05301933 continue;
1934 }
1935 }
1936 }
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001937 int mdpIndex = mCurrentFrame.layerToMDP[index];
1938 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001939 info.pipeInfo = new MdpPipeInfoSplit;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001940 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001941 MdpPipeInfoSplit& pipe_info = *(MdpPipeInfoSplit*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001942
Saurabh Shahc62f3982014-03-05 14:28:26 -08001943 if(!acquireMDPPipes(ctx, layer, pipe_info)) {
1944 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type",
1945 __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001946 return false;
1947 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001948 }
1949 return true;
1950}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001951
radhakrishnac9a67412013-09-25 17:40:42 +05301952int MDPCompSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1953 PipeLayerPair& PipeLayerPair) {
1954 const int lSplit = getLeftSplit(ctx, mDpy);
1955 hwc_rect_t dst = layer->displayFrame;
1956 if((dst.left > lSplit)||(dst.right < lSplit)){
1957 MdpYUVPipeInfo& mdp_info =
1958 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1959 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1960 eIsFg isFg = IS_FG_OFF;
1961 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1962 eDest lDest = mdp_info.lIndex;
1963 eDest rDest = mdp_info.rIndex;
1964
1965 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1966 lDest, rDest, &PipeLayerPair.rot);
1967 }
1968 else{
1969 return configure(ctx, layer, PipeLayerPair);
1970 }
1971}
1972
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001973/*
1974 * Configures pipe(s) for MDP composition
1975 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001976int MDPCompSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001977 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001978 MdpPipeInfoSplit& mdp_info =
1979 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001980 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1981 eIsFg isFg = IS_FG_OFF;
1982 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1983 eDest lDest = mdp_info.lIndex;
1984 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001985
1986 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1987 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1988
Saurabh Shah88e4d272013-09-03 13:31:29 -07001989 return configureSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001990 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001991}
1992
Saurabh Shah88e4d272013-09-03 13:31:29 -07001993bool MDPCompSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001994
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001995 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001996 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1997 return true;
1998 }
1999
2000 if(!ctx || !list) {
2001 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002002 return false;
2003 }
2004
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05302005 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
2006 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
2007 return true;
2008 }
2009
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -08002010 // Set the Handle timeout to true for MDP or MIXED composition.
2011 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount) {
2012 sHandleTimeout = true;
2013 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002014
Naseer Ahmed54821fe2012-11-28 18:44:38 -05002015 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08002016 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002017
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08002018 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
2019 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002020 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08002021 if(mCurrentFrame.isFBComposed[i]) continue;
2022
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002023 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08002024 private_handle_t *hnd = (private_handle_t *)layer->handle;
2025 if(!hnd) {
2026 ALOGE("%s handle null", __FUNCTION__);
2027 return false;
2028 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002029
2030 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
2031 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002032 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002033
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08002034 int mdpIndex = mCurrentFrame.layerToMDP[i];
2035
radhakrishnac9a67412013-09-25 17:40:42 +05302036 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
2037 {
2038 MdpYUVPipeInfo& pipe_info =
2039 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
2040 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
2041 ovutils::eDest indexL = pipe_info.lIndex;
2042 ovutils::eDest indexR = pipe_info.rIndex;
2043 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05302044 uint32_t offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05302045 if(rot) {
2046 rot->queueBuffer(fd, offset);
2047 fd = rot->getDstMemId();
2048 offset = rot->getDstOffset();
2049 }
2050 if(indexL != ovutils::OV_INVALID) {
2051 ovutils::eDest destL = (ovutils::eDest)indexL;
2052 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
2053 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
2054 if (!ov.queueBuffer(fd, offset, destL)) {
2055 ALOGE("%s: queueBuffer failed for display:%d",
2056 __FUNCTION__, mDpy);
2057 return false;
2058 }
2059 }
Saurabh Shahacf10202013-02-26 10:15:15 -08002060
radhakrishnac9a67412013-09-25 17:40:42 +05302061 if(indexR != ovutils::OV_INVALID) {
2062 ovutils::eDest destR = (ovutils::eDest)indexR;
2063 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
2064 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
2065 if (!ov.queueBuffer(fd, offset, destR)) {
2066 ALOGE("%s: queueBuffer failed for display:%d",
2067 __FUNCTION__, mDpy);
2068 return false;
2069 }
Saurabh Shaha9da08f2013-07-03 13:27:53 -07002070 }
2071 }
radhakrishnac9a67412013-09-25 17:40:42 +05302072 else{
2073 MdpPipeInfoSplit& pipe_info =
2074 *(MdpPipeInfoSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
2075 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07002076
radhakrishnac9a67412013-09-25 17:40:42 +05302077 ovutils::eDest indexL = pipe_info.lIndex;
2078 ovutils::eDest indexR = pipe_info.rIndex;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002079
Sushil Chauhandefd3522014-05-13 18:17:12 -07002080 if (!mDpy && (i == mOverlapIndex)) {
2081 hnd = ctx->mCopyBit[mDpy]->getCurrentRenderBuffer();
2082 }
2083
radhakrishnac9a67412013-09-25 17:40:42 +05302084 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05302085 int offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05302086
Tatenda Chipeperekwa88fe6352014-04-14 10:36:06 -07002087 if(ctx->mAD->draw(ctx, fd, offset)) {
2088 fd = ctx->mAD->getDstFd();
2089 offset = ctx->mAD->getDstOffset();
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002090 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002091
radhakrishnac9a67412013-09-25 17:40:42 +05302092 if(rot) {
2093 rot->queueBuffer(fd, offset);
2094 fd = rot->getDstMemId();
2095 offset = rot->getDstOffset();
2096 }
2097
2098 //************* play left mixer **********
2099 if(indexL != ovutils::OV_INVALID) {
2100 ovutils::eDest destL = (ovutils::eDest)indexL;
2101 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
2102 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
2103 if (!ov.queueBuffer(fd, offset, destL)) {
2104 ALOGE("%s: queueBuffer failed for left mixer",
2105 __FUNCTION__);
2106 return false;
2107 }
2108 }
2109
2110 //************* play right mixer **********
2111 if(indexR != ovutils::OV_INVALID) {
2112 ovutils::eDest destR = (ovutils::eDest)indexR;
2113 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
2114 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
2115 if (!ov.queueBuffer(fd, offset, destR)) {
2116 ALOGE("%s: queueBuffer failed for right mixer",
2117 __FUNCTION__);
2118 return false;
2119 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002120 }
2121 }
Saurabh Shahacf10202013-02-26 10:15:15 -08002122
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002123 layerProp[i].mFlags &= ~HWC_MDPCOMP;
2124 }
Saurabh Shahacf10202013-02-26 10:15:15 -08002125
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002126 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002127}
Saurabh Shahab47c692014-02-12 18:45:57 -08002128
2129//================MDPCompSrcSplit==============================================
2130bool MDPCompSrcSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Saurabh Shahc62f3982014-03-05 14:28:26 -08002131 MdpPipeInfoSplit& pipe_info) {
Saurabh Shahab47c692014-02-12 18:45:57 -08002132 private_handle_t *hnd = (private_handle_t *)layer->handle;
2133 hwc_rect_t dst = layer->displayFrame;
2134 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
2135 pipe_info.lIndex = ovutils::OV_INVALID;
2136 pipe_info.rIndex = ovutils::OV_INVALID;
2137
2138 //If 2 pipes are staged on a single stage of a mixer, then the left pipe
2139 //should have a higher priority than the right one. Pipe priorities are
2140 //starting with VG0, VG1 ... , RGB0 ..., DMA1
Saurabh Shahab47c692014-02-12 18:45:57 -08002141
Saurabh Shahc62f3982014-03-05 14:28:26 -08002142 Overlay::PipeSpecs pipeSpecs;
2143 pipeSpecs.formatClass = isYuvBuffer(hnd) ?
2144 Overlay::FORMAT_YUV : Overlay::FORMAT_RGB;
2145 pipeSpecs.needsScaling = qhwc::needsScaling(layer);
2146 pipeSpecs.dpy = mDpy;
2147 pipeSpecs.fb = false;
2148
Saurabh Shahab47c692014-02-12 18:45:57 -08002149 //1 pipe by default for a layer
Saurabh Shahc62f3982014-03-05 14:28:26 -08002150 pipe_info.lIndex = ctx->mOverlay->getPipe(pipeSpecs);
Saurabh Shahab47c692014-02-12 18:45:57 -08002151 if(pipe_info.lIndex == ovutils::OV_INVALID) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08002152 return false;
Saurabh Shahab47c692014-02-12 18:45:57 -08002153 }
2154
2155 //If layer's crop width or dest width > 2048, use 2 pipes
2156 if((dst.right - dst.left) > qdutils::MAX_DISPLAY_DIM or
2157 (crop.right - crop.left) > qdutils::MAX_DISPLAY_DIM) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08002158 pipe_info.rIndex = ctx->mOverlay->getPipe(pipeSpecs);
Saurabh Shahab47c692014-02-12 18:45:57 -08002159 if(pipe_info.rIndex == ovutils::OV_INVALID) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08002160 return false;
Saurabh Shahdd8237a2014-02-28 14:29:09 -08002161 }
2162
2163 // Return values
2164 // 1 Left pipe is higher priority, do nothing.
2165 // 0 Pipes of same priority.
2166 //-1 Right pipe is of higher priority, needs swap.
2167 if(ctx->mOverlay->comparePipePriority(pipe_info.lIndex,
2168 pipe_info.rIndex) == -1) {
2169 qhwc::swap(pipe_info.lIndex, pipe_info.rIndex);
Saurabh Shahab47c692014-02-12 18:45:57 -08002170 }
2171 }
2172
2173 return true;
2174}
2175
Saurabh Shahab47c692014-02-12 18:45:57 -08002176int MDPCompSrcSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
2177 PipeLayerPair& PipeLayerPair) {
2178 private_handle_t *hnd = (private_handle_t *)layer->handle;
2179 if(!hnd) {
2180 ALOGE("%s: layer handle is NULL", __FUNCTION__);
2181 return -1;
2182 }
2183 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
2184 MdpPipeInfoSplit& mdp_info =
2185 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
2186 Rotator **rot = &PipeLayerPair.rot;
2187 eZorder z = static_cast<eZorder>(mdp_info.zOrder);
2188 eIsFg isFg = IS_FG_OFF;
2189 eDest lDest = mdp_info.lIndex;
2190 eDest rDest = mdp_info.rIndex;
2191 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
2192 hwc_rect_t dst = layer->displayFrame;
2193 int transform = layer->transform;
2194 eTransform orient = static_cast<eTransform>(transform);
2195 const int downscale = 0;
2196 int rotFlags = ROT_FLAGS_NONE;
2197 uint32_t format = ovutils::getMdpFormat(hnd->format, isTileRendered(hnd));
2198 Whf whf(getWidth(hnd), getHeight(hnd), format, hnd->size);
2199
2200 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
2201 "dest_pipeR: %d",__FUNCTION__, layer, z, lDest, rDest);
2202
2203 // Handle R/B swap
2204 if (layer->flags & HWC_FORMAT_RB_SWAP) {
2205 if (hnd->format == HAL_PIXEL_FORMAT_RGBA_8888)
2206 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRA_8888);
2207 else if (hnd->format == HAL_PIXEL_FORMAT_RGBX_8888)
2208 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRX_8888);
2209 }
2210
Saurabh Shah97e2d802014-04-14 18:03:54 -07002211 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
2212 setMdpFlags(layer, mdpFlags, 0, transform);
Saurabh Shahab47c692014-02-12 18:45:57 -08002213
2214 if(lDest != OV_INVALID && rDest != OV_INVALID) {
2215 //Enable overfetch
Saurabh Shah97e2d802014-04-14 18:03:54 -07002216 setMdpFlags(mdpFlags, OV_MDSS_MDP_DUAL_PIPE);
Saurabh Shahab47c692014-02-12 18:45:57 -08002217 }
2218
2219 if(isYuvBuffer(hnd) && (transform & HWC_TRANSFORM_ROT_90)) {
2220 (*rot) = ctx->mRotMgr->getNext();
2221 if((*rot) == NULL) return -1;
Saurabh Shah39240c92014-03-31 10:31:42 -07002222 ctx->mLayerRotMap[mDpy]->add(layer, *rot);
Saurabh Shah1bd5b6f2014-05-19 12:23:13 -07002223 //If the video is using a single pipe, enable BWC
2224 if(rDest == OV_INVALID) {
2225 BwcPM::setBwc(crop, dst, transform, mdpFlags);
2226 }
Saurabh Shahab47c692014-02-12 18:45:57 -08002227 //Configure rotator for pre-rotation
Saurabh Shah97e2d802014-04-14 18:03:54 -07002228 if(configRotator(*rot, whf, crop, mdpFlags, orient, downscale) < 0) {
Saurabh Shahab47c692014-02-12 18:45:57 -08002229 ALOGE("%s: configRotator failed!", __FUNCTION__);
2230 return -1;
2231 }
Saurabh Shahab47c692014-02-12 18:45:57 -08002232 whf.format = (*rot)->getDstFormat();
2233 updateSource(orient, whf, crop);
2234 rotFlags |= ROT_PREROTATED;
2235 }
2236
2237 //If 2 pipes being used, divide layer into half, crop and dst
2238 hwc_rect_t cropL = crop;
2239 hwc_rect_t cropR = crop;
2240 hwc_rect_t dstL = dst;
2241 hwc_rect_t dstR = dst;
2242 if(lDest != OV_INVALID && rDest != OV_INVALID) {
2243 cropL.right = (crop.right + crop.left) / 2;
2244 cropR.left = cropL.right;
2245 sanitizeSourceCrop(cropL, cropR, hnd);
2246
2247 //Swap crops on H flip since 2 pipes are being used
2248 if((orient & OVERLAY_TRANSFORM_FLIP_H) && (*rot) == NULL) {
2249 hwc_rect_t tmp = cropL;
2250 cropL = cropR;
2251 cropR = tmp;
2252 }
2253
2254 dstL.right = (dst.right + dst.left) / 2;
2255 dstR.left = dstL.right;
2256 }
2257
2258 //For the mdp, since either we are pre-rotating or MDP does flips
2259 orient = OVERLAY_TRANSFORM_0;
2260 transform = 0;
2261
2262 //configure left pipe
2263 if(lDest != OV_INVALID) {
Saurabh Shah97e2d802014-04-14 18:03:54 -07002264 PipeArgs pargL(mdpFlags, whf, z, isFg,
Saurabh Shahab47c692014-02-12 18:45:57 -08002265 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2266 (ovutils::eBlending) getBlending(layer->blending));
2267
2268 if(configMdp(ctx->mOverlay, pargL, orient,
2269 cropL, dstL, metadata, lDest) < 0) {
2270 ALOGE("%s: commit failed for left mixer config", __FUNCTION__);
2271 return -1;
2272 }
2273 }
2274
2275 //configure right pipe
2276 if(rDest != OV_INVALID) {
Saurabh Shah97e2d802014-04-14 18:03:54 -07002277 PipeArgs pargR(mdpFlags, whf, z, isFg,
Saurabh Shahab47c692014-02-12 18:45:57 -08002278 static_cast<eRotFlags>(rotFlags),
2279 layer->planeAlpha,
2280 (ovutils::eBlending) getBlending(layer->blending));
2281 if(configMdp(ctx->mOverlay, pargR, orient,
2282 cropR, dstR, metadata, rDest) < 0) {
2283 ALOGE("%s: commit failed for right mixer config", __FUNCTION__);
2284 return -1;
2285 }
2286 }
2287
2288 return 0;
2289}
2290
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002291}; //namespace
2292