blob: 8a717c041f4fbfdd7b7647dfd03b93b1c045334e [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>
29
Saurabh Shah85234ec2013-04-12 17:09:00 -070030using namespace overlay;
Saurabh Shahbd2d0832013-04-04 14:33:08 -070031using namespace qdutils;
Saurabh Shahacf10202013-02-26 10:15:15 -080032using namespace overlay::utils;
33namespace ovutils = overlay::utils;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070034
Naseer Ahmed7c958d42012-07-31 18:57:03 -070035namespace qhwc {
36
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080037//==============MDPComp========================================================
38
Naseer Ahmed7c958d42012-07-31 18:57:03 -070039IdleInvalidator *MDPComp::idleInvalidator = NULL;
40bool MDPComp::sIdleFallBack = false;
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -080041bool MDPComp::sHandleTimeout = false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070042bool MDPComp::sDebugLogs = false;
Naseer Ahmed54821fe2012-11-28 18:44:38 -050043bool MDPComp::sEnabled = false;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -070044bool MDPComp::sEnableMixedMode = true;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -070045bool MDPComp::sEnablePartialFrameUpdate = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080046int MDPComp::sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
radhakrishnac9a67412013-09-25 17:40:42 +053047bool MDPComp::sEnable4k2kYUVSplit = false;
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -070048bool MDPComp::sSrcSplitEnabled = false;
Saurabh Shah88e4d272013-09-03 13:31:29 -070049MDPComp* MDPComp::getObject(hwc_context_t *ctx, const int& dpy) {
Saurabh Shah60e8bde2014-04-30 14:46:03 -070050 if(qdutils::MDPVersion::getInstance().isSrcSplit()) {
51 sSrcSplitEnabled = true;
52 return new MDPCompSrcSplit(dpy);
53 } else if(isDisplaySplit(ctx, dpy)) {
Saurabh Shah88e4d272013-09-03 13:31:29 -070054 return new MDPCompSplit(dpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080055 }
Saurabh Shah88e4d272013-09-03 13:31:29 -070056 return new MDPCompNonSplit(dpy);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080057}
58
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080059MDPComp::MDPComp(int dpy):mDpy(dpy){};
60
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080061void MDPComp::dump(android::String8& buf)
62{
Jeykumar Sankaran3c6bb042013-08-15 14:01:04 -070063 if(mCurrentFrame.layerCount > MAX_NUM_APP_LAYERS)
64 return;
65
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080066 dumpsys_log(buf,"HWC Map for Dpy: %s \n",
Jeykumar Sankaran27dee262013-08-01 17:09:54 -070067 (mDpy == 0) ? "\"PRIMARY\"" :
68 (mDpy == 1) ? "\"EXTERNAL\"" : "\"VIRTUAL\"");
Saurabh Shahe9bc60f2013-08-29 12:58:06 -070069 dumpsys_log(buf,"CURR_FRAME: layerCount:%2d mdpCount:%2d "
70 "fbCount:%2d \n", mCurrentFrame.layerCount,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080071 mCurrentFrame.mdpCount, mCurrentFrame.fbCount);
72 dumpsys_log(buf,"needsFBRedraw:%3s pipesUsed:%2d MaxPipesPerMixer: %d \n",
73 (mCurrentFrame.needsRedraw? "YES" : "NO"),
74 mCurrentFrame.mdpCount, sMaxPipesPerMixer);
75 dumpsys_log(buf," --------------------------------------------- \n");
76 dumpsys_log(buf," listIdx | cached? | mdpIndex | comptype | Z \n");
77 dumpsys_log(buf," --------------------------------------------- \n");
78 for(int index = 0; index < mCurrentFrame.layerCount; index++ )
79 dumpsys_log(buf," %7d | %7s | %8d | %9s | %2d \n",
80 index,
81 (mCurrentFrame.isFBComposed[index] ? "YES" : "NO"),
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -070082 mCurrentFrame.layerToMDP[index],
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080083 (mCurrentFrame.isFBComposed[index] ?
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -070084 (mCurrentFrame.drop[index] ? "DROP" :
85 (mCurrentFrame.needsRedraw ? "GLES" : "CACHE")) : "MDP"),
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080086 (mCurrentFrame.isFBComposed[index] ? mCurrentFrame.fbZ :
87 mCurrentFrame.mdpToLayer[mCurrentFrame.layerToMDP[index]].pipeInfo->zOrder));
88 dumpsys_log(buf,"\n");
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080089}
90
91bool MDPComp::init(hwc_context_t *ctx) {
92
93 if(!ctx) {
94 ALOGE("%s: Invalid hwc context!!",__FUNCTION__);
95 return false;
96 }
97
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080098 char property[PROPERTY_VALUE_MAX];
99
100 sEnabled = false;
101 if((property_get("persist.hwc.mdpcomp.enable", property, NULL) > 0) &&
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800102 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
103 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800104 sEnabled = true;
105 }
106
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700107 sEnableMixedMode = true;
108 if((property_get("debug.mdpcomp.mixedmode.disable", property, NULL) > 0) &&
109 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
110 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
111 sEnableMixedMode = false;
112 }
113
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800114 if(property_get("debug.mdpcomp.logs", property, NULL) > 0) {
115 if(atoi(property) != 0)
116 sDebugLogs = true;
117 }
118
Prabhanjan Kandula8e6f9142014-04-21 12:12:38 +0530119 // We read from drivers if panel supports partial updating
120 // and we enable partial update computations if supported.
121 // Keeping this property to disable partial update for
122 // debugging by setting below property to 0 & only 0.
123 property_get("persist.hwc.partialupdate", property, "-1");
124 if((atoi(property) != 0) &&
125 qdutils::MDPVersion::getInstance().isPartialUpdateEnabled()) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700126 sEnablePartialFrameUpdate = true;
127 }
128 ALOGE_IF(isDebug(), "%s: Partial Update applicable?: %d",__FUNCTION__,
129 sEnablePartialFrameUpdate);
130
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800131 sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
Saurabh Shah85234ec2013-04-12 17:09:00 -0700132 if(property_get("debug.mdpcomp.maxpermixer", property, "-1") > 0) {
133 int val = atoi(property);
134 if(val >= 0)
135 sMaxPipesPerMixer = min(val, MAX_PIPES_PER_MIXER);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800136 }
137
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400138 if(ctx->mMDP.panel != MIPI_CMD_PANEL) {
139 // Idle invalidation is not necessary on command mode panels
140 long idle_timeout = DEFAULT_IDLE_TIME;
141 if(property_get("debug.mdpcomp.idletime", property, NULL) > 0) {
142 if(atoi(property) != 0)
143 idle_timeout = atoi(property);
144 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800145
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400146 //create Idle Invalidator only when not disabled through property
147 if(idle_timeout != -1)
148 idleInvalidator = IdleInvalidator::getInstance();
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800149
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400150 if(idleInvalidator == NULL) {
151 ALOGE("%s: failed to instantiate idleInvalidator object",
152 __FUNCTION__);
153 } else {
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530154 idleInvalidator->init(timeout_handler, ctx,
155 (unsigned int)idle_timeout);
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400156 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800157 }
radhakrishnac9a67412013-09-25 17:40:42 +0530158
159 if((property_get("debug.mdpcomp.4k2kSplit", property, "0") > 0) &&
160 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
161 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
162 sEnable4k2kYUVSplit = true;
163 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700164 return true;
165}
166
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800167void MDPComp::reset(hwc_context_t *ctx) {
168 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700169 mCurrentFrame.reset(numLayers);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800170 ctx->mOverlay->clear(mDpy);
171 ctx->mLayerRotMap[mDpy]->clear();
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700172}
173
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700174void MDPComp::timeout_handler(void *udata) {
175 struct hwc_context_t* ctx = (struct hwc_context_t*)(udata);
176
177 if(!ctx) {
178 ALOGE("%s: received empty data in timer callback", __FUNCTION__);
179 return;
180 }
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -0800181 Locker::Autolock _l(ctx->mDrawLock);
182 // Handle timeout event only if the previous composition is MDP or MIXED.
183 if(!sHandleTimeout) {
184 ALOGD_IF(isDebug(), "%s:Do not handle this timeout", __FUNCTION__);
185 return;
186 }
Jesse Hall3be78d92012-08-21 15:12:23 -0700187 if(!ctx->proc) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700188 ALOGE("%s: HWC proc not registered", __FUNCTION__);
189 return;
190 }
191 sIdleFallBack = true;
192 /* Trigger SF to redraw the current frame */
Jesse Hall3be78d92012-08-21 15:12:23 -0700193 ctx->proc->invalidate(ctx->proc);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700194}
195
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800196void MDPComp::setMDPCompLayerFlags(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800197 hwc_display_contents_1_t* list) {
198 LayerProp *layerProp = ctx->layerProp[mDpy];
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800199
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800200 for(int index = 0; index < ctx->listStats[mDpy].numAppLayers; index++) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800201 hwc_layer_1_t* layer = &(list->hwLayers[index]);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800202 if(!mCurrentFrame.isFBComposed[index]) {
203 layerProp[index].mFlags |= HWC_MDPCOMP;
204 layer->compositionType = HWC_OVERLAY;
205 layer->hints |= HWC_HINT_CLEAR_FB;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800206 } else {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700207 /* Drop the layer when its already present in FB OR when it lies
208 * outside frame's ROI */
209 if(!mCurrentFrame.needsRedraw || mCurrentFrame.drop[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800210 layer->compositionType = HWC_OVERLAY;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700211 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800212 }
213 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700214}
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500215
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800216void MDPComp::setRedraw(hwc_context_t *ctx,
217 hwc_display_contents_1_t* list) {
218 mCurrentFrame.needsRedraw = false;
219 if(!mCachedFrame.isSameFrame(mCurrentFrame, list) ||
220 (list->flags & HWC_GEOMETRY_CHANGED) ||
221 isSkipPresent(ctx, mDpy)) {
222 mCurrentFrame.needsRedraw = true;
223 }
224}
225
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800226MDPComp::FrameInfo::FrameInfo() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700227 reset(0);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800228}
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800229
Saurabh Shahaa236822013-04-24 18:07:26 -0700230void MDPComp::FrameInfo::reset(const int& numLayers) {
231 for(int i = 0 ; i < MAX_PIPES_PER_MIXER && numLayers; i++ ) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800232 if(mdpToLayer[i].pipeInfo) {
233 delete mdpToLayer[i].pipeInfo;
234 mdpToLayer[i].pipeInfo = NULL;
235 //We dont own the rotator
236 mdpToLayer[i].rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800237 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800238 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800239
240 memset(&mdpToLayer, 0, sizeof(mdpToLayer));
241 memset(&layerToMDP, -1, sizeof(layerToMDP));
Saurabh Shahaa236822013-04-24 18:07:26 -0700242 memset(&isFBComposed, 1, sizeof(isFBComposed));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800243
Saurabh Shahaa236822013-04-24 18:07:26 -0700244 layerCount = numLayers;
245 fbCount = numLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800246 mdpCount = 0;
Saurabh Shah2f3895f2013-05-02 10:13:31 -0700247 needsRedraw = true;
Saurabh Shahd53bc5f2014-02-05 10:17:43 -0800248 fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800249}
250
Saurabh Shahaa236822013-04-24 18:07:26 -0700251void MDPComp::FrameInfo::map() {
252 // populate layer and MDP maps
253 int mdpIdx = 0;
254 for(int idx = 0; idx < layerCount; idx++) {
255 if(!isFBComposed[idx]) {
256 mdpToLayer[mdpIdx].listIndex = idx;
257 layerToMDP[idx] = mdpIdx++;
258 }
259 }
260}
261
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800262MDPComp::LayerCache::LayerCache() {
263 reset();
264}
265
266void MDPComp::LayerCache::reset() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700267 memset(&hnd, 0, sizeof(hnd));
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530268 memset(&isFBComposed, true, sizeof(isFBComposed));
269 memset(&drop, false, sizeof(drop));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800270 layerCount = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -0700271}
272
273void MDPComp::LayerCache::cacheAll(hwc_display_contents_1_t* list) {
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530274 const int numAppLayers = (int)list->numHwLayers - 1;
Saurabh Shahaa236822013-04-24 18:07:26 -0700275 for(int i = 0; i < numAppLayers; i++) {
276 hnd[i] = list->hwLayers[i].handle;
277 }
278}
279
280void MDPComp::LayerCache::updateCounts(const FrameInfo& curFrame) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700281 layerCount = curFrame.layerCount;
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530282 memcpy(&isFBComposed, &curFrame.isFBComposed, sizeof(isFBComposed));
283 memcpy(&drop, &curFrame.drop, sizeof(drop));
284}
285
Jeykumar Sankaran988d3682013-11-15 11:57:16 -0800286bool MDPComp::LayerCache::isSameFrame(const FrameInfo& curFrame,
287 hwc_display_contents_1_t* list) {
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530288 if(layerCount != curFrame.layerCount)
289 return false;
290 for(int i = 0; i < curFrame.layerCount; i++) {
291 if((curFrame.isFBComposed[i] != isFBComposed[i]) ||
292 (curFrame.drop[i] != drop[i])) {
293 return false;
294 }
Jeykumar Sankaran988d3682013-11-15 11:57:16 -0800295 if(curFrame.isFBComposed[i] &&
296 (hnd[i] != list->hwLayers[i].handle)){
297 return false;
298 }
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530299 }
300 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800301}
302
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700303bool MDPComp::isSupportedForMDPComp(hwc_context_t *ctx, hwc_layer_1_t* layer) {
304 private_handle_t *hnd = (private_handle_t *)layer->handle;
305 if((not isYuvBuffer(hnd) and has90Transform(layer)) or
306 (not isValidDimension(ctx,layer))
307 //More conditions here, SKIP, sRGB+Blend etc
308 ) {
309 return false;
310 }
311 return true;
312}
313
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530314bool MDPComp::isValidDimension(hwc_context_t *ctx, hwc_layer_1_t *layer) {
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800315 private_handle_t *hnd = (private_handle_t *)layer->handle;
316
317 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -0700318 if (layer->flags & HWC_COLOR_FILL) {
319 // Color layer
320 return true;
321 }
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800322 ALOGE("%s: layer handle is NULL", __FUNCTION__);
323 return false;
324 }
325
Naseer Ahmede850a802013-09-06 13:12:52 -0400326 //XXX: Investigate doing this with pixel phase on MDSS
Naseer Ahmede77f8082013-10-10 13:42:48 -0400327 if(!isSecureBuffer(hnd) && isNonIntegralSourceCrop(layer->sourceCropf))
Naseer Ahmede850a802013-09-06 13:12:52 -0400328 return false;
329
Saurabh Shah62e1d732013-09-17 10:44:05 -0700330 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700331 hwc_rect_t dst = layer->displayFrame;
Saurabh Shah4fdde762013-04-30 18:47:33 -0700332 int crop_w = crop.right - crop.left;
333 int crop_h = crop.bottom - crop.top;
334 int dst_w = dst.right - dst.left;
335 int dst_h = dst.bottom - dst.top;
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800336 float w_scale = ((float)crop_w / (float)dst_w);
337 float h_scale = ((float)crop_h / (float)dst_h);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700338
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800339 /* Workaround for MDP HW limitation in DSI command mode panels where
340 * FPS will not go beyond 30 if buffers on RGB pipes are of width or height
341 * less than 5 pixels
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530342 * There also is a HW limilation in MDP, minimum block size is 2x2
343 * Fallback to GPU if height is less than 2.
344 */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800345 if((crop_w < 5)||(crop_h < 5))
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800346 return false;
347
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800348 if((w_scale > 1.0f) || (h_scale > 1.0f)) {
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700349 const uint32_t maxMDPDownscale =
Saurabh Shah4fdde762013-04-30 18:47:33 -0700350 qdutils::MDPVersion::getInstance().getMaxMDPDownscale();
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800351 const float w_dscale = w_scale;
352 const float h_dscale = h_scale;
353
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800354 if(ctx->mMDP.version >= qdutils::MDSS_V5) {
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700355
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800356 if(!qdutils::MDPVersion::getInstance().supportsDecimation()) {
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700357 /* On targets that doesnt support Decimation (eg.,8x26)
358 * maximum downscale support is overlay pipe downscale.
359 */
360 if(crop_w > MAX_DISPLAY_DIM || w_dscale > maxMDPDownscale ||
361 h_dscale > maxMDPDownscale)
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800362 return false;
363 } else {
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700364 // Decimation on macrotile format layers is not supported.
365 if(isTileRendered(hnd)) {
366 /* MDP can read maximum MAX_DISPLAY_DIM width.
367 * Bail out if
368 * 1. Src crop > MAX_DISPLAY_DIM on nonsplit MDPComp
369 * 2. exceeds maximum downscale limit
370 */
371 if(((crop_w > MAX_DISPLAY_DIM) && !sSrcSplitEnabled) ||
372 w_dscale > maxMDPDownscale ||
373 h_dscale > maxMDPDownscale) {
374 return false;
375 }
376 } else if(w_dscale > 64 || h_dscale > 64)
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800377 return false;
378 }
379 } else { //A-family
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700380 if(w_dscale > maxMDPDownscale || h_dscale > maxMDPDownscale)
Saurabh Shah4fdde762013-04-30 18:47:33 -0700381 return false;
382 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700383 }
384
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800385 if((w_scale < 1.0f) || (h_scale < 1.0f)) {
386 const uint32_t upscale =
387 qdutils::MDPVersion::getInstance().getMaxMDPUpscale();
388 const float w_uscale = 1.0f / w_scale;
389 const float h_uscale = 1.0f / h_scale;
390
391 if(w_uscale > upscale || h_uscale > upscale)
392 return false;
393 }
394
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800395 return true;
396}
397
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800398bool MDPComp::isFrameDoable(hwc_context_t *ctx) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700399 bool ret = true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800400
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800401 if(!isEnabled()) {
402 ALOGD_IF(isDebug(),"%s: MDP Comp. not enabled.", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700403 ret = false;
Raj Kamal068f4572014-04-14 16:14:06 +0530404 } else if((qdutils::MDPVersion::getInstance().is8x26() ||
405 qdutils::MDPVersion::getInstance().is8x16()) &&
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -0800406 ctx->mVideoTransFlag &&
407 isSecondaryConnected(ctx)) {
Saurabh Shahd4e65852013-06-17 11:33:53 -0700408 //1 Padding round to shift pipes across mixers
409 ALOGD_IF(isDebug(),"%s: MDP Comp. video transition padding round",
410 __FUNCTION__);
411 ret = false;
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -0800412 } else if(isSecondaryConfiguring(ctx)) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800413 ALOGD_IF( isDebug(),"%s: External Display connection is pending",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800414 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700415 ret = false;
Saurabh Shahaa236822013-04-24 18:07:26 -0700416 } else if(ctx->isPaddingRound) {
Raj Kamal9ed3d6b2014-02-07 16:15:17 +0530417 ALOGD_IF(isDebug(), "%s: padding round invoked for dpy %d",
418 __FUNCTION__,mDpy);
Saurabh Shahaa236822013-04-24 18:07:26 -0700419 ret = false;
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700420 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700421 return ret;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800422}
423
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800424/*
425 * 1) Identify layers that are not visible in the updating ROI and drop them
426 * from composition.
427 * 2) If we have a scaling layers which needs cropping against generated ROI.
428 * Reset ROI to full resolution.
429 */
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700430bool MDPComp::validateAndApplyROI(hwc_context_t *ctx,
431 hwc_display_contents_1_t* list, hwc_rect_t roi) {
432 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
433
434 if(!isValidRect(roi))
435 return false;
436
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800437 hwc_rect_t visibleRect = roi;
438
439 for(int i = numAppLayers - 1; i >= 0; i--){
440
441 if(!isValidRect(visibleRect)) {
442 mCurrentFrame.drop[i] = true;
443 mCurrentFrame.dropCount++;
Jeykumar Sankaran0b961452014-01-21 17:26:12 -0800444 continue;
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800445 }
446
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700447 const hwc_layer_1_t* layer = &list->hwLayers[i];
448
449 hwc_rect_t dstRect = layer->displayFrame;
Arun Kumar K.R91090c72013-10-28 19:40:18 -0700450 hwc_rect_t srcRect = integerizeSourceCrop(layer->sourceCropf);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700451
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800452 hwc_rect_t res = getIntersection(visibleRect, dstRect);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700453
454 int res_w = res.right - res.left;
455 int res_h = res.bottom - res.top;
456 int dst_w = dstRect.right - dstRect.left;
457 int dst_h = dstRect.bottom - dstRect.top;
458
459 if(!isValidRect(res)) {
460 mCurrentFrame.drop[i] = true;
461 mCurrentFrame.dropCount++;
462 }else {
463 /* Reset frame ROI when any layer which needs scaling also needs ROI
464 * cropping */
Jeykumar Sankaran0b961452014-01-21 17:26:12 -0800465 if((res_w != dst_w || res_h != dst_h) && needsScaling (layer)) {
Arpita Banerjeed8965982013-11-08 17:27:33 -0800466 ALOGI("%s: Resetting ROI due to scaling", __FUNCTION__);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700467 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
468 mCurrentFrame.dropCount = 0;
469 return false;
470 }
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800471
Jeykumar Sankaran0b961452014-01-21 17:26:12 -0800472 /* deduct any opaque region from visibleRect */
473 if (layer->blending == HWC_BLENDING_NONE)
474 visibleRect = deductRect(visibleRect, res);
475 }
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700476 }
477 return true;
478}
479
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800480bool MDPComp::canDoPartialUpdate(hwc_context_t *ctx,
481 hwc_display_contents_1_t* list){
482 if(!qdutils::MDPVersion::getInstance().isPartialUpdateEnabled() || mDpy ||
483 isSkipPresent(ctx, mDpy) || (list->flags & HWC_GEOMETRY_CHANGED)||
484 isDisplaySplit(ctx, mDpy)) {
485 return false;
486 }
487 return true;
488}
489
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700490void MDPComp::generateROI(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
491 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
492
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800493 if(!canDoPartialUpdate(ctx, list))
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700494 return;
495
496 struct hwc_rect roi = (struct hwc_rect){0, 0, 0, 0};
497 for(int index = 0; index < numAppLayers; index++ ) {
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800498 hwc_layer_1_t* layer = &list->hwLayers[index];
499 if ((mCachedFrame.hnd[index] != layer->handle) ||
500 isYuvBuffer((private_handle_t *)layer->handle)) {
501 hwc_rect_t updatingRect = layer->displayFrame;
502#ifdef QCOM_BSP
503 if(!needsScaling(layer))
504 updatingRect = layer->dirtyRect;
505#endif
506 roi = getUnion(roi, updatingRect);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700507 }
508 }
509
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800510 hwc_rect fullFrame = (struct hwc_rect) {0, 0,(int)ctx->dpyAttr[mDpy].xres,
511 (int)ctx->dpyAttr[mDpy].yres};
512
513 // Align ROI coordinates to panel restrictions
514 roi = sanitizeROI(roi, fullFrame);
515
516 if(!validateAndApplyROI(ctx, list, roi))
517 roi = fullFrame;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700518
519 ctx->listStats[mDpy].roi.x = roi.left;
520 ctx->listStats[mDpy].roi.y = roi.top;
521 ctx->listStats[mDpy].roi.w = roi.right - roi.left;
522 ctx->listStats[mDpy].roi.h = roi.bottom - roi.top;
523
524 ALOGD_IF(isDebug(),"%s: generated ROI: [%d, %d, %d, %d]", __FUNCTION__,
525 roi.left, roi.top, roi.right, roi.bottom);
526}
527
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800528/* Checks for conditions where all the layers marked for MDP comp cannot be
529 * bypassed. On such conditions we try to bypass atleast YUV layers */
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800530bool MDPComp::tryFullFrame(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800531 hwc_display_contents_1_t* list){
532
Saurabh Shahaa236822013-04-24 18:07:26 -0700533 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Arun Kumar K.R2e2871c2014-01-10 12:47:06 -0800534 int priDispW = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800535
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -0700536 if(sIdleFallBack && !ctx->listStats[mDpy].secureUI) {
Saurabh Shah2d998a92013-05-14 17:55:58 -0700537 ALOGD_IF(isDebug(), "%s: Idle fallback dpy %d",__FUNCTION__, mDpy);
538 return false;
539 }
540
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800541 if(isSkipPresent(ctx, mDpy)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700542 ALOGD_IF(isDebug(),"%s: SKIP present: %d",
543 __FUNCTION__,
544 isSkipPresent(ctx, mDpy));
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800545 return false;
546 }
547
Arun Kumar K.R2e2871c2014-01-10 12:47:06 -0800548 if(mDpy > HWC_DISPLAY_PRIMARY && (priDispW > MAX_DISPLAY_DIM) &&
549 (ctx->dpyAttr[mDpy].xres < MAX_DISPLAY_DIM)) {
550 // Disable MDP comp on Secondary when the primary is highres panel and
551 // the secondary is a normal 1080p, because, MDP comp on secondary under
552 // in such usecase, decimation gets used for downscale and there will be
553 // a quality mismatch when there will be a fallback to GPU comp
554 ALOGD_IF(isDebug(), "%s: Disable MDP Compositon for Secondary Disp",
555 __FUNCTION__);
556 return false;
557 }
558
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800559 // check for action safe flag and downscale mode which requires scaling.
560 if(ctx->dpyAttr[mDpy].mActionSafePresent
561 || ctx->dpyAttr[mDpy].mDownScaleMode) {
562 ALOGD_IF(isDebug(), "%s: Scaling needed for this frame",__FUNCTION__);
563 return false;
564 }
565
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800566 for(int i = 0; i < numAppLayers; ++i) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800567 hwc_layer_1_t* layer = &list->hwLayers[i];
568 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800569
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700570 if(isYuvBuffer(hnd) && has90Transform(layer)) {
571 if(!canUseRotator(ctx, mDpy)) {
572 ALOGD_IF(isDebug(), "%s: Can't use rotator for dpy %d",
573 __FUNCTION__, mDpy);
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700574 return false;
575 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800576 }
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530577
578 //For 8x26 with panel width>1k, if RGB layer needs HFLIP fail mdp comp
579 // may not need it if Gfx pre-rotation can handle all flips & rotations
Sushil Chauhanfda00fc2014-03-20 11:08:41 -0700580 int transform = (layer->flags & HWC_COLOR_FILL) ? 0 : layer->transform;
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530581 if(qdutils::MDPVersion::getInstance().is8x26() &&
582 (ctx->dpyAttr[mDpy].xres > 1024) &&
Sushil Chauhanfda00fc2014-03-20 11:08:41 -0700583 (transform & HWC_TRANSFORM_FLIP_H) &&
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530584 (!isYuvBuffer(hnd)))
585 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800586 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700587
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700588 if(ctx->mAD->isDoable()) {
589 return false;
590 }
591
Saurabh Shahaa236822013-04-24 18:07:26 -0700592 //If all above hard conditions are met we can do full or partial MDP comp.
593 bool ret = false;
594 if(fullMDPComp(ctx, list)) {
595 ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700596 } else if(partialMDPComp(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700597 ret = true;
598 }
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530599
Saurabh Shahaa236822013-04-24 18:07:26 -0700600 return ret;
601}
602
603bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700604 //Will benefit presentation / secondary-only layer.
605 if((mDpy > HWC_DISPLAY_PRIMARY) &&
606 (list->numHwLayers - 1) > MAX_SEC_LAYERS) {
607 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
608 return false;
609 }
610
611 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
612 for(int i = 0; i < numAppLayers; i++) {
613 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran880da832014-04-18 10:22:35 -0700614 if(not mCurrentFrame.drop[i] and
615 not isSupportedForMDPComp(ctx, layer)) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700616 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",__FUNCTION__);
617 return false;
618 }
619 }
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800620
Saurabh Shahaa236822013-04-24 18:07:26 -0700621 mCurrentFrame.fbCount = 0;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700622 memcpy(&mCurrentFrame.isFBComposed, &mCurrentFrame.drop,
623 sizeof(mCurrentFrame.isFBComposed));
624 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount -
625 mCurrentFrame.dropCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700626
radhakrishnac9a67412013-09-25 17:40:42 +0530627 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800628 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530629 }
630
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800631 if(!postHeuristicsHandling(ctx, list)) {
632 ALOGD_IF(isDebug(), "post heuristic handling failed");
633 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700634 return false;
635 }
636
Saurabh Shahaa236822013-04-24 18:07:26 -0700637 return true;
638}
639
640bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
641{
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700642 if(!sEnableMixedMode) {
643 //Mixed mode is disabled. No need to even try caching.
644 return false;
645 }
646
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700647 bool ret = false;
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800648 if(list->flags & HWC_GEOMETRY_CHANGED) { //Try load based first
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800649 ret = loadBasedComp(ctx, list) or
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800650 cacheBasedComp(ctx, list);
651 } else {
652 ret = cacheBasedComp(ctx, list) or
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800653 loadBasedComp(ctx, list);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700654 }
655
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700656 return ret;
657}
658
659bool MDPComp::cacheBasedComp(hwc_context_t *ctx,
660 hwc_display_contents_1_t* list) {
661 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700662 mCurrentFrame.reset(numAppLayers);
663 updateLayerCache(ctx, list);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700664
665 //If an MDP marked layer is unsupported cannot do partial MDP Comp
666 for(int i = 0; i < numAppLayers; i++) {
667 if(!mCurrentFrame.isFBComposed[i]) {
668 hwc_layer_1_t* layer = &list->hwLayers[i];
669 if(not isSupportedForMDPComp(ctx, layer)) {
670 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",
671 __FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800672 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700673 return false;
674 }
675 }
676 }
677
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700678 updateYUV(ctx, list, false /*secure only*/);
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530679 bool ret = markLayersForCaching(ctx, list); //sets up fbZ also
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700680 if(!ret) {
681 ALOGD_IF(isDebug(),"%s: batching failed, dpy %d",__FUNCTION__, mDpy);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800682 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700683 return false;
684 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700685
686 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700687
radhakrishnac9a67412013-09-25 17:40:42 +0530688 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800689 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530690 }
691
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700692 //Will benefit cases where a video has non-updating background.
693 if((mDpy > HWC_DISPLAY_PRIMARY) and
694 (mdpCount > MAX_SEC_LAYERS)) {
695 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800696 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700697 return false;
698 }
699
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800700 if(!postHeuristicsHandling(ctx, list)) {
701 ALOGD_IF(isDebug(), "post heuristic handling failed");
702 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700703 return false;
704 }
705
Saurabh Shahaa236822013-04-24 18:07:26 -0700706 return true;
707}
708
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800709bool MDPComp::loadBasedComp(hwc_context_t *ctx,
Saurabh Shahb772ae32013-11-18 15:40:02 -0800710 hwc_display_contents_1_t* list) {
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -0800711 if(not isLoadBasedCompDoable(ctx)) {
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800712 return false;
713 }
714
Saurabh Shahb772ae32013-11-18 15:40:02 -0800715 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800716 const int numNonDroppedLayers = numAppLayers - mCurrentFrame.dropCount;
717 const int stagesForMDP = min(sMaxPipesPerMixer,
718 ctx->mOverlay->availablePipes(mDpy, Overlay::MIXER_DEFAULT));
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800719
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800720 int mdpBatchSize = stagesForMDP - 1; //1 stage for FB
721 int fbBatchSize = numNonDroppedLayers - mdpBatchSize;
722 int lastMDPSupportedIndex = numAppLayers;
723 int dropCount = 0;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800724
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800725 //Find the minimum MDP batch size
726 for(int i = 0; i < numAppLayers;i++) {
727 if(mCurrentFrame.drop[i]) {
728 dropCount++;
Jeykumar Sankaran846e2792014-01-23 21:59:58 -0800729 continue;
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800730 }
731 hwc_layer_1_t* layer = &list->hwLayers[i];
732 if(not isSupportedForMDPComp(ctx, layer)) {
733 lastMDPSupportedIndex = i;
734 mdpBatchSize = min(i - dropCount, stagesForMDP - 1);
735 fbBatchSize = numNonDroppedLayers - mdpBatchSize;
Jeykumar Sankaran846e2792014-01-23 21:59:58 -0800736 break;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800737 }
Saurabh Shahb772ae32013-11-18 15:40:02 -0800738 }
739
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800740 ALOGD_IF(isDebug(), "%s:Before optimizing fbBatch, mdpbatch %d, fbbatch %d "
741 "dropped %d", __FUNCTION__, mdpBatchSize, fbBatchSize,
742 mCurrentFrame.dropCount);
743
744 //Start at a point where the fb batch should at least have 2 layers, for
745 //this mode to be justified.
746 while(fbBatchSize < 2) {
747 ++fbBatchSize;
748 --mdpBatchSize;
Jeykumar Sankaran846e2792014-01-23 21:59:58 -0800749 }
Saurabh Shahb772ae32013-11-18 15:40:02 -0800750
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800751 //If there are no layers for MDP, this mode doesnt make sense.
752 if(mdpBatchSize < 1) {
753 ALOGD_IF(isDebug(), "%s: No MDP layers after optimizing for fbBatch",
754 __FUNCTION__);
Saurabh Shahb772ae32013-11-18 15:40:02 -0800755 return false;
756 }
757
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800758 mCurrentFrame.reset(numAppLayers);
759
760 //Try with successively smaller mdp batch sizes until we succeed or reach 1
761 while(mdpBatchSize > 0) {
762 //Mark layers for MDP comp
763 int mdpBatchLeft = mdpBatchSize;
764 for(int i = 0; i < lastMDPSupportedIndex and mdpBatchLeft; i++) {
765 if(mCurrentFrame.drop[i]) {
766 continue;
767 }
768 mCurrentFrame.isFBComposed[i] = false;
769 --mdpBatchLeft;
770 }
771
772 mCurrentFrame.fbZ = mdpBatchSize;
773 mCurrentFrame.fbCount = fbBatchSize;
774 mCurrentFrame.mdpCount = mdpBatchSize;
775
776 ALOGD_IF(isDebug(), "%s:Trying with: mdpbatch %d fbbatch %d dropped %d",
777 __FUNCTION__, mdpBatchSize, fbBatchSize,
778 mCurrentFrame.dropCount);
779
780 if(postHeuristicsHandling(ctx, list)) {
781 ALOGD_IF(isDebug(), "%s: Postheuristics handling succeeded",
782 __FUNCTION__);
783 return true;
784 }
785
786 reset(ctx);
787 --mdpBatchSize;
788 ++fbBatchSize;
789 }
790
791 return false;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800792}
793
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -0800794bool MDPComp::isLoadBasedCompDoable(hwc_context_t *ctx) {
Prabhanjan Kandula3dbbd882013-12-11 14:43:46 +0530795 if(mDpy or isSecurePresent(ctx, mDpy) or
796 isYuvPresent(ctx, mDpy)) {
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700797 return false;
798 }
799 return true;
800}
801
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800802bool MDPComp::tryVideoOnly(hwc_context_t *ctx,
803 hwc_display_contents_1_t* list) {
804 const bool secureOnly = true;
805 return videoOnlyComp(ctx, list, not secureOnly) or
806 videoOnlyComp(ctx, list, secureOnly);
807}
808
809bool MDPComp::videoOnlyComp(hwc_context_t *ctx,
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700810 hwc_display_contents_1_t* list, bool secureOnly) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700811 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700812
Saurabh Shahaa236822013-04-24 18:07:26 -0700813 mCurrentFrame.reset(numAppLayers);
Jeykumar Sankaraneb3a5e22014-04-08 16:07:55 -0700814 mCurrentFrame.fbCount -= mCurrentFrame.dropCount;
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700815 updateYUV(ctx, list, secureOnly);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700816 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700817
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800818 if(!isYuvPresent(ctx, mDpy) or (mdpCount == 0)) {
819 reset(ctx);
Saurabh Shahaa236822013-04-24 18:07:26 -0700820 return false;
821 }
822
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -0800823 /* Bail out if we are processing only secured video layers
824 * and we dont have any */
825 if(!isSecurePresent(ctx, mDpy) && secureOnly){
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800826 reset(ctx);
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -0800827 return false;
828 }
829
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800830 if(mCurrentFrame.fbCount)
831 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
Saurabh Shah4fdde762013-04-30 18:47:33 -0700832
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800833 if(sEnable4k2kYUVSplit){
834 adjustForSourceSplit(ctx, list);
835 }
836
837 if(!postHeuristicsHandling(ctx, list)) {
838 ALOGD_IF(isDebug(), "post heuristic handling failed");
839 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700840 return false;
841 }
842
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800843 return true;
844}
845
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800846/* Checks for conditions where YUV layers cannot be bypassed */
847bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -0700848 if(isSkipLayer(layer)) {
Saurabh Shahe2474082013-05-15 16:32:13 -0700849 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800850 return false;
851 }
852
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700853 if(layer->transform & HWC_TRANSFORM_ROT_90 && !canUseRotator(ctx,mDpy)) {
854 ALOGD_IF(isDebug(), "%s: no free DMA pipe",__FUNCTION__);
855 return false;
856 }
857
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800858 if(isSecuring(ctx, layer)) {
859 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
860 return false;
861 }
862
Saurabh Shah4fdde762013-04-30 18:47:33 -0700863 if(!isValidDimension(ctx, layer)) {
864 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
865 __FUNCTION__);
866 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800867 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700868
Naseer Ahmeddc61a972013-07-10 17:50:54 -0400869 if(layer->planeAlpha < 0xFF) {
870 ALOGD_IF(isDebug(), "%s: Cannot handle YUV layer with plane alpha\
871 in video only mode",
872 __FUNCTION__);
873 return false;
874 }
875
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800876 return true;
877}
878
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530879/* starts at fromIndex and check for each layer to find
880 * if it it has overlapping with any Updating layer above it in zorder
881 * till the end of the batch. returns true if it finds any intersection */
882bool MDPComp::canPushBatchToTop(const hwc_display_contents_1_t* list,
883 int fromIndex, int toIndex) {
884 for(int i = fromIndex; i < toIndex; i++) {
885 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
886 if(intersectingUpdatingLayers(list, i+1, toIndex, i)) {
887 return false;
888 }
889 }
890 }
891 return true;
892}
893
894/* Checks if given layer at targetLayerIndex has any
895 * intersection with all the updating layers in beween
896 * fromIndex and toIndex. Returns true if it finds intersectiion */
897bool MDPComp::intersectingUpdatingLayers(const hwc_display_contents_1_t* list,
898 int fromIndex, int toIndex, int targetLayerIndex) {
899 for(int i = fromIndex; i <= toIndex; i++) {
900 if(!mCurrentFrame.isFBComposed[i]) {
901 if(areLayersIntersecting(&list->hwLayers[i],
902 &list->hwLayers[targetLayerIndex])) {
903 return true;
904 }
905 }
906 }
907 return false;
908}
909
910int MDPComp::getBatch(hwc_display_contents_1_t* list,
911 int& maxBatchStart, int& maxBatchEnd,
912 int& maxBatchCount) {
913 int i = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530914 int fbZOrder =-1;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -0800915 int droppedLayerCt = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530916 while (i < mCurrentFrame.layerCount) {
917 int batchCount = 0;
918 int batchStart = i;
919 int batchEnd = i;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -0800920 /* Adjust batch Z order with the dropped layers so far */
921 int fbZ = batchStart - droppedLayerCt;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530922 int firstZReverseIndex = -1;
Prabhanjan Kandula0ed2cc92013-12-06 12:39:04 +0530923 int updatingLayersAbove = 0;//Updating layer count in middle of batch
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530924 while(i < mCurrentFrame.layerCount) {
925 if(!mCurrentFrame.isFBComposed[i]) {
926 if(!batchCount) {
927 i++;
928 break;
929 }
930 updatingLayersAbove++;
931 i++;
932 continue;
933 } else {
934 if(mCurrentFrame.drop[i]) {
935 i++;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -0800936 droppedLayerCt++;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530937 continue;
938 } else if(updatingLayersAbove <= 0) {
939 batchCount++;
940 batchEnd = i;
941 i++;
942 continue;
943 } else { //Layer is FBComposed, not a drop & updatingLayer > 0
944
945 // We have a valid updating layer already. If layer-i not
946 // have overlapping with all updating layers in between
947 // batch-start and i, then we can add layer i to batch.
948 if(!intersectingUpdatingLayers(list, batchStart, i-1, i)) {
949 batchCount++;
950 batchEnd = i;
951 i++;
952 continue;
953 } else if(canPushBatchToTop(list, batchStart, i)) {
954 //If All the non-updating layers with in this batch
955 //does not have intersection with the updating layers
956 //above in z-order, then we can safely move the batch to
957 //higher z-order. Increment fbZ as it is moving up.
958 if( firstZReverseIndex < 0) {
959 firstZReverseIndex = i;
960 }
961 batchCount++;
962 batchEnd = i;
963 fbZ += updatingLayersAbove;
964 i++;
965 updatingLayersAbove = 0;
966 continue;
967 } else {
968 //both failed.start the loop again from here.
969 if(firstZReverseIndex >= 0) {
970 i = firstZReverseIndex;
971 }
972 break;
973 }
974 }
975 }
976 }
977 if(batchCount > maxBatchCount) {
978 maxBatchCount = batchCount;
979 maxBatchStart = batchStart;
980 maxBatchEnd = batchEnd;
981 fbZOrder = fbZ;
982 }
983 }
984 return fbZOrder;
985}
986
987bool MDPComp::markLayersForCaching(hwc_context_t* ctx,
988 hwc_display_contents_1_t* list) {
989 /* Idea is to keep as many non-updating(cached) layers in FB and
990 * send rest of them through MDP. This is done in 2 steps.
991 * 1. Find the maximum contiguous batch of non-updating layers.
992 * 2. See if we can improve this batch size for caching by adding
993 * opaque layers around the batch, if they don't have
994 * any overlapping with the updating layers in between.
995 * NEVER mark an updating layer for caching.
996 * But cached ones can be marked for MDP */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800997
998 int maxBatchStart = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700999 int maxBatchEnd = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001000 int maxBatchCount = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301001 int fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001002
Saurabh Shahd53bc5f2014-02-05 10:17:43 -08001003 /* Nothing is cached. No batching needed */
1004 if(mCurrentFrame.fbCount == 0) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001005 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -07001006 }
Saurabh Shahd53bc5f2014-02-05 10:17:43 -08001007
1008 /* No MDP comp layers, try to use other comp modes */
1009 if(mCurrentFrame.mdpCount == 0) {
1010 return false;
Saurabh Shahaa236822013-04-24 18:07:26 -07001011 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001012
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301013 fbZ = getBatch(list, maxBatchStart, maxBatchEnd, maxBatchCount);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001014
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301015 /* reset rest of the layers lying inside ROI for MDP comp */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001016 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001017 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001018 if((i < maxBatchStart || i > maxBatchEnd) &&
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301019 mCurrentFrame.isFBComposed[i]){
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001020 if(!mCurrentFrame.drop[i]){
1021 //If an unsupported layer is being attempted to
1022 //be pulled out we should fail
1023 if(not isSupportedForMDPComp(ctx, layer)) {
1024 return false;
1025 }
1026 mCurrentFrame.isFBComposed[i] = false;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001027 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001028 }
1029 }
1030
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301031 // update the frame data
1032 mCurrentFrame.fbZ = fbZ;
1033 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001034 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001035 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001036
1037 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301038 mCurrentFrame.fbCount);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001039
1040 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001041}
Saurabh Shah85234ec2013-04-12 17:09:00 -07001042
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001043void MDPComp::updateLayerCache(hwc_context_t* ctx,
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001044 hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001045 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001046 int fbCount = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001047
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001048 for(int i = 0; i < numAppLayers; i++) {
1049 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001050 if(!mCurrentFrame.drop[i])
1051 fbCount++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001052 mCurrentFrame.isFBComposed[i] = true;
1053 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -07001054 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001055 }
1056 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001057
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001058 mCurrentFrame.fbCount = fbCount;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001059 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount
1060 - mCurrentFrame.dropCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001061
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001062 ALOGD_IF(isDebug(),"%s: MDP count: %d FB count %d drop count: %d"
1063 ,__FUNCTION__, mCurrentFrame.mdpCount, mCurrentFrame.fbCount,
1064 mCurrentFrame.dropCount);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001065}
1066
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001067void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list,
1068 bool secureOnly) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001069 int nYuvCount = ctx->listStats[mDpy].yuvCount;
1070 for(int index = 0;index < nYuvCount; index++){
1071 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
1072 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
1073
1074 if(!isYUVDoable(ctx, layer)) {
1075 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
1076 mCurrentFrame.isFBComposed[nYuvIndex] = true;
1077 mCurrentFrame.fbCount++;
1078 }
1079 } else {
1080 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001081 private_handle_t *hnd = (private_handle_t *)layer->handle;
1082 if(!secureOnly || isSecureBuffer(hnd)) {
1083 mCurrentFrame.isFBComposed[nYuvIndex] = false;
1084 mCurrentFrame.fbCount--;
1085 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001086 }
1087 }
1088 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001089
1090 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001091 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
1092 ALOGD_IF(isDebug(),"%s: fb count: %d",__FUNCTION__,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001093 mCurrentFrame.fbCount);
1094}
1095
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301096hwc_rect_t MDPComp::getUpdatingFBRect(hwc_display_contents_1_t* list){
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001097 hwc_rect_t fbRect = (struct hwc_rect){0, 0, 0, 0};
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001098
1099 /* Update only the region of FB needed for composition */
1100 for(int i = 0; i < mCurrentFrame.layerCount; i++ ) {
1101 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
1102 hwc_layer_1_t* layer = &list->hwLayers[i];
1103 hwc_rect_t dst = layer->displayFrame;
1104 fbRect = getUnion(fbRect, dst);
1105 }
1106 }
1107 return fbRect;
1108}
1109
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001110bool MDPComp::postHeuristicsHandling(hwc_context_t *ctx,
1111 hwc_display_contents_1_t* list) {
1112
1113 //Capability checks
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301114 if(!resourceCheck()) {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001115 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
1116 return false;
1117 }
1118
1119 //Limitations checks
1120 if(!hwLimitationsCheck(ctx, list)) {
1121 ALOGD_IF(isDebug(), "%s: HW limitations",__FUNCTION__);
1122 return false;
1123 }
1124
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001125 //Configure framebuffer first if applicable
1126 if(mCurrentFrame.fbZ >= 0) {
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301127 hwc_rect_t fbRect = getUpdatingFBRect(list);
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001128 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, fbRect, mCurrentFrame.fbZ))
1129 {
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001130 ALOGD_IF(isDebug(), "%s configure framebuffer failed",
1131 __FUNCTION__);
1132 return false;
1133 }
1134 }
1135
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001136 mCurrentFrame.map();
1137
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001138 if(!allocLayerPipes(ctx, list)) {
1139 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -07001140 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001141 }
1142
1143 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001144 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001145 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001146 int mdpIndex = mCurrentFrame.layerToMDP[index];
1147 hwc_layer_1_t* layer = &list->hwLayers[index];
1148
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301149 //Leave fbZ for framebuffer. CACHE/GLES layers go here.
1150 if(mdpNextZOrder == mCurrentFrame.fbZ) {
1151 mdpNextZOrder++;
1152 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001153 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1154 cur_pipe->zOrder = mdpNextZOrder++;
1155
radhakrishnac9a67412013-09-25 17:40:42 +05301156 private_handle_t *hnd = (private_handle_t *)layer->handle;
1157 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1158 if(configure4k2kYuv(ctx, layer,
1159 mCurrentFrame.mdpToLayer[mdpIndex])
1160 != 0 ){
1161 ALOGD_IF(isDebug(), "%s: Failed to configure split pipes \
1162 for layer %d",__FUNCTION__, index);
1163 return false;
1164 }
1165 else{
1166 mdpNextZOrder++;
1167 }
1168 continue;
1169 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001170 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
1171 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
radhakrishnac9a67412013-09-25 17:40:42 +05301172 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -07001173 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001174 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001175 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001176 }
1177
Saurabh Shaha36be922013-12-16 18:18:39 -08001178 if(!ctx->mOverlay->validateAndSet(mDpy, ctx->dpyAttr[mDpy].fd)) {
1179 ALOGD_IF(isDebug(), "%s: Failed to validate and set overlay for dpy %d"
1180 ,__FUNCTION__, mDpy);
1181 return false;
1182 }
1183
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001184 setRedraw(ctx, list);
Saurabh Shahaa236822013-04-24 18:07:26 -07001185 return true;
1186}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001187
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301188bool MDPComp::resourceCheck() {
Saurabh Shah173f4242013-11-20 09:50:12 -08001189 const bool fbUsed = mCurrentFrame.fbCount;
1190 if(mCurrentFrame.mdpCount > sMaxPipesPerMixer - fbUsed) {
1191 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
1192 return false;
1193 }
Saurabh Shah173f4242013-11-20 09:50:12 -08001194 return true;
1195}
1196
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301197bool MDPComp::hwLimitationsCheck(hwc_context_t* ctx,
1198 hwc_display_contents_1_t* list) {
1199
1200 //A-family hw limitation:
1201 //If a layer need alpha scaling, MDP can not support.
1202 if(ctx->mMDP.version < qdutils::MDSS_V5) {
1203 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1204 if(!mCurrentFrame.isFBComposed[i] &&
1205 isAlphaScaled( &list->hwLayers[i])) {
1206 ALOGD_IF(isDebug(), "%s:frame needs alphaScaling",__FUNCTION__);
1207 return false;
1208 }
1209 }
1210 }
1211
1212 // On 8x26 & 8974 hw, we have a limitation of downscaling+blending.
1213 //If multiple layers requires downscaling and also they are overlapping
1214 //fall back to GPU since MDSS can not handle it.
1215 if(qdutils::MDPVersion::getInstance().is8x74v2() ||
1216 qdutils::MDPVersion::getInstance().is8x26()) {
1217 for(int i = 0; i < mCurrentFrame.layerCount-1; ++i) {
1218 hwc_layer_1_t* botLayer = &list->hwLayers[i];
1219 if(!mCurrentFrame.isFBComposed[i] &&
1220 isDownscaleRequired(botLayer)) {
1221 //if layer-i is marked for MDP and needs downscaling
1222 //check if any MDP layer on top of i & overlaps with layer-i
1223 for(int j = i+1; j < mCurrentFrame.layerCount; ++j) {
1224 hwc_layer_1_t* topLayer = &list->hwLayers[j];
1225 if(!mCurrentFrame.isFBComposed[j] &&
1226 isDownscaleRequired(topLayer)) {
1227 hwc_rect_t r = getIntersection(botLayer->displayFrame,
1228 topLayer->displayFrame);
1229 if(isValidRect(r))
1230 return false;
1231 }
1232 }
1233 }
1234 }
1235 }
1236 return true;
1237}
1238
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001239int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001240 int ret = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -07001241 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -07001242
Raj Kamal9ed3d6b2014-02-07 16:15:17 +05301243 //Do not cache the information for next draw cycle.
1244 if(numLayers > MAX_NUM_APP_LAYERS or (!numLayers)) {
1245 ALOGI("%s: Unsupported layer count for mdp composition",
1246 __FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001247 mCachedFrame.reset();
1248 return -1;
1249 }
1250
Saurabh Shahb39f8152013-08-22 10:21:44 -07001251 //reset old data
1252 mCurrentFrame.reset(numLayers);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001253 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1254 mCurrentFrame.dropCount = 0;
Prabhanjan Kandula088bd892013-07-02 23:47:13 +05301255
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -07001256 // Detect the start of animation and fall back to GPU only once to cache
1257 // all the layers in FB and display FB content untill animation completes.
1258 if(ctx->listStats[mDpy].isDisplayAnimating) {
1259 mCurrentFrame.needsRedraw = false;
1260 if(ctx->mAnimationState[mDpy] == ANIMATION_STOPPED) {
1261 mCurrentFrame.needsRedraw = true;
1262 ctx->mAnimationState[mDpy] = ANIMATION_STARTED;
1263 }
1264 setMDPCompLayerFlags(ctx, list);
1265 mCachedFrame.updateCounts(mCurrentFrame);
1266 ret = -1;
1267 return ret;
1268 } else {
1269 ctx->mAnimationState[mDpy] = ANIMATION_STOPPED;
1270 }
1271
Saurabh Shahb39f8152013-08-22 10:21:44 -07001272 //Hard conditions, if not met, cannot do MDP comp
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001273 if(isFrameDoable(ctx)) {
1274 generateROI(ctx, list);
Saurabh Shahb39f8152013-08-22 10:21:44 -07001275
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001276 if(tryFullFrame(ctx, list) || tryVideoOnly(ctx, list)) {
1277 setMDPCompLayerFlags(ctx, list);
1278 } else {
1279 reset(ctx);
1280 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1281 mCurrentFrame.dropCount = 0;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001282 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001283 }
1284 } else {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001285 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
1286 __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001287 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001288 }
Saurabh Shahb39f8152013-08-22 10:21:44 -07001289
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001290 if(isDebug()) {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001291 ALOGD("GEOMETRY change: %d",
1292 (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001293 android::String8 sDump("");
1294 dump(sDump);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001295 ALOGD("%s",sDump.string());
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001296 }
1297
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001298 mCachedFrame.cacheAll(list);
1299 mCachedFrame.updateCounts(mCurrentFrame);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001300 return ret;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001301}
1302
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001303bool MDPComp::allocSplitVGPipesfor4k2k(hwc_context_t *ctx, int index) {
radhakrishnac9a67412013-09-25 17:40:42 +05301304
1305 bool bRet = true;
radhakrishnac9a67412013-09-25 17:40:42 +05301306 int mdpIndex = mCurrentFrame.layerToMDP[index];
1307 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
1308 info.pipeInfo = new MdpYUVPipeInfo;
1309 info.rot = NULL;
1310 MdpYUVPipeInfo& pipe_info = *(MdpYUVPipeInfo*)info.pipeInfo;
radhakrishnac9a67412013-09-25 17:40:42 +05301311
1312 pipe_info.lIndex = ovutils::OV_INVALID;
1313 pipe_info.rIndex = ovutils::OV_INVALID;
1314
Saurabh Shahc62f3982014-03-05 14:28:26 -08001315 Overlay::PipeSpecs pipeSpecs;
1316 pipeSpecs.formatClass = Overlay::FORMAT_YUV;
1317 pipeSpecs.needsScaling = true;
1318 pipeSpecs.dpy = mDpy;
1319 pipeSpecs.fb = false;
1320
1321 pipe_info.lIndex = ctx->mOverlay->getPipe(pipeSpecs);
radhakrishnac9a67412013-09-25 17:40:42 +05301322 if(pipe_info.lIndex == ovutils::OV_INVALID){
1323 bRet = false;
1324 ALOGD_IF(isDebug(),"%s: allocating first VG pipe failed",
1325 __FUNCTION__);
1326 }
Saurabh Shahc62f3982014-03-05 14:28:26 -08001327 pipe_info.rIndex = ctx->mOverlay->getPipe(pipeSpecs);
radhakrishnac9a67412013-09-25 17:40:42 +05301328 if(pipe_info.rIndex == ovutils::OV_INVALID){
1329 bRet = false;
1330 ALOGD_IF(isDebug(),"%s: allocating second VG pipe failed",
1331 __FUNCTION__);
1332 }
1333 return bRet;
1334}
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001335//=============MDPCompNonSplit==================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001336
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001337void MDPCompNonSplit::adjustForSourceSplit(hwc_context_t *ctx,
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001338 hwc_display_contents_1_t*) {
radhakrishnac9a67412013-09-25 17:40:42 +05301339 //As we split 4kx2k yuv layer and program to 2 VG pipes
1340 //(if available) increase mdpcount accordingly
1341 mCurrentFrame.mdpCount += ctx->listStats[mDpy].yuv4k2kCount;
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001342
1343 //If 4k2k Yuv layer split is possible, and if
1344 //fbz is above 4k2k layer, increment fb zorder by 1
1345 //as we split 4k2k layer and increment zorder for right half
1346 //of the layer
1347 if(mCurrentFrame.fbZ >= 0) {
1348 int n4k2kYuvCount = ctx->listStats[mDpy].yuv4k2kCount;
1349 for(int index = 0; index < n4k2kYuvCount; index++){
1350 int n4k2kYuvIndex =
1351 ctx->listStats[mDpy].yuv4k2kIndices[index];
Dileep Kumar Reddi4cff9282014-04-01 12:57:08 +05301352 if(mCurrentFrame.fbZ >= n4k2kYuvIndex){
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001353 mCurrentFrame.fbZ += 1;
1354 }
1355 }
1356 }
radhakrishnac9a67412013-09-25 17:40:42 +05301357}
1358
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001359/*
1360 * Configures pipe(s) for MDP composition
1361 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001362int MDPCompNonSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001363 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001364 MdpPipeInfoNonSplit& mdp_info =
1365 *(static_cast<MdpPipeInfoNonSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001366 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
1367 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1368 eIsFg isFg = IS_FG_OFF;
1369 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001370
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001371 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
1372 __FUNCTION__, layer, zOrder, dest);
1373
Saurabh Shah88e4d272013-09-03 13:31:29 -07001374 return configureNonSplit(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001375 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001376}
1377
Saurabh Shah88e4d272013-09-03 13:31:29 -07001378bool MDPCompNonSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001379 hwc_display_contents_1_t* list) {
1380 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001381
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001382 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001383
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001384 hwc_layer_1_t* layer = &list->hwLayers[index];
1385 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301386 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001387 if(allocSplitVGPipesfor4k2k(ctx, index)){
radhakrishnac9a67412013-09-25 17:40:42 +05301388 continue;
1389 }
1390 }
1391
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001392 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001393 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001394 info.pipeInfo = new MdpPipeInfoNonSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08001395 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001396 MdpPipeInfoNonSplit& pipe_info = *(MdpPipeInfoNonSplit*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001397
Saurabh Shahc62f3982014-03-05 14:28:26 -08001398 Overlay::PipeSpecs pipeSpecs;
1399 pipeSpecs.formatClass = isYuvBuffer(hnd) ?
1400 Overlay::FORMAT_YUV : Overlay::FORMAT_RGB;
1401 pipeSpecs.needsScaling = qhwc::needsScaling(layer) or
1402 (qdutils::MDPVersion::getInstance().is8x26() and
1403 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres > 1024);
1404 pipeSpecs.dpy = mDpy;
1405 pipeSpecs.fb = false;
Xu Yang1e686f62014-04-08 13:56:47 +08001406 pipeSpecs.numActiveDisplays = ctx->numActiveDisplays;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001407
Saurabh Shahc62f3982014-03-05 14:28:26 -08001408 pipe_info.index = ctx->mOverlay->getPipe(pipeSpecs);
1409
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001410 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001411 ALOGD_IF(isDebug(), "%s: Unable to get pipe", __FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001412 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001413 }
1414 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001415 return true;
1416}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001417
radhakrishnac9a67412013-09-25 17:40:42 +05301418int MDPCompNonSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1419 PipeLayerPair& PipeLayerPair) {
1420 MdpYUVPipeInfo& mdp_info =
1421 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1422 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1423 eIsFg isFg = IS_FG_OFF;
1424 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1425 eDest lDest = mdp_info.lIndex;
1426 eDest rDest = mdp_info.rIndex;
1427
1428 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1429 lDest, rDest, &PipeLayerPair.rot);
1430}
1431
Saurabh Shah88e4d272013-09-03 13:31:29 -07001432bool MDPCompNonSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001433
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001434 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001435 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1436 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -08001437 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001438
1439 if(!ctx || !list) {
1440 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001441 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001442 }
1443
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301444 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1445 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1446 return true;
1447 }
1448
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -08001449 // Set the Handle timeout to true for MDP or MIXED composition.
1450 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount) {
1451 sHandleTimeout = true;
1452 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001453
1454 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001455 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001456
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001457 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1458 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001459 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001460 if(mCurrentFrame.isFBComposed[i]) continue;
1461
Naseer Ahmed5b6708a2012-08-02 13:46:08 -07001462 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001463 private_handle_t *hnd = (private_handle_t *)layer->handle;
1464 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001465 if (!(layer->flags & HWC_COLOR_FILL)) {
1466 ALOGE("%s handle null", __FUNCTION__);
1467 return false;
1468 }
1469 // No PLAY for Color layer
1470 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1471 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001472 }
1473
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001474 int mdpIndex = mCurrentFrame.layerToMDP[i];
1475
radhakrishnac9a67412013-09-25 17:40:42 +05301476 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1477 {
1478 MdpYUVPipeInfo& pipe_info =
1479 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1480 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1481 ovutils::eDest indexL = pipe_info.lIndex;
1482 ovutils::eDest indexR = pipe_info.rIndex;
1483 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301484 uint32_t offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05301485 if(rot) {
1486 rot->queueBuffer(fd, offset);
1487 fd = rot->getDstMemId();
1488 offset = rot->getDstOffset();
1489 }
1490 if(indexL != ovutils::OV_INVALID) {
1491 ovutils::eDest destL = (ovutils::eDest)indexL;
1492 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1493 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1494 if (!ov.queueBuffer(fd, offset, destL)) {
1495 ALOGE("%s: queueBuffer failed for display:%d",
1496 __FUNCTION__, mDpy);
1497 return false;
1498 }
1499 }
1500
1501 if(indexR != ovutils::OV_INVALID) {
1502 ovutils::eDest destR = (ovutils::eDest)indexR;
1503 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1504 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1505 if (!ov.queueBuffer(fd, offset, destR)) {
1506 ALOGE("%s: queueBuffer failed for display:%d",
1507 __FUNCTION__, mDpy);
1508 return false;
1509 }
1510 }
1511 }
1512 else{
1513 MdpPipeInfoNonSplit& pipe_info =
Saurabh Shah88e4d272013-09-03 13:31:29 -07001514 *(MdpPipeInfoNonSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
radhakrishnac9a67412013-09-25 17:40:42 +05301515 ovutils::eDest dest = pipe_info.index;
1516 if(dest == ovutils::OV_INVALID) {
1517 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001518 return false;
radhakrishnac9a67412013-09-25 17:40:42 +05301519 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001520
radhakrishnac9a67412013-09-25 17:40:42 +05301521 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1522 continue;
1523 }
1524
1525 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1526 using pipe: %d", __FUNCTION__, layer,
1527 hnd, dest );
1528
1529 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301530 uint32_t offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05301531
1532 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1533 if(rot) {
1534 if(!rot->queueBuffer(fd, offset))
1535 return false;
1536 fd = rot->getDstMemId();
1537 offset = rot->getDstOffset();
1538 }
1539
1540 if (!ov.queueBuffer(fd, offset, dest)) {
1541 ALOGE("%s: queueBuffer failed for display:%d ",
1542 __FUNCTION__, mDpy);
1543 return false;
1544 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001545 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001546
1547 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001548 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001549 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001550}
1551
Saurabh Shah88e4d272013-09-03 13:31:29 -07001552//=============MDPCompSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001553
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001554void MDPCompSplit::adjustForSourceSplit(hwc_context_t *ctx,
radhakrishnac9a67412013-09-25 17:40:42 +05301555 hwc_display_contents_1_t* list){
1556 //if 4kx2k yuv layer is totally present in either in left half
1557 //or right half then try splitting the yuv layer to avoid decimation
1558 int n4k2kYuvCount = ctx->listStats[mDpy].yuv4k2kCount;
1559 const int lSplit = getLeftSplit(ctx, mDpy);
1560 for(int index = 0; index < n4k2kYuvCount; index++){
1561 int n4k2kYuvIndex = ctx->listStats[mDpy].yuv4k2kIndices[index];
1562 hwc_layer_1_t* layer = &list->hwLayers[n4k2kYuvIndex];
1563 hwc_rect_t dst = layer->displayFrame;
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001564 if((dst.left > lSplit) || (dst.right < lSplit)) {
radhakrishnac9a67412013-09-25 17:40:42 +05301565 mCurrentFrame.mdpCount += 1;
1566 }
Dileep Kumar Reddi4cff9282014-04-01 12:57:08 +05301567 if(mCurrentFrame.fbZ >= n4k2kYuvIndex){
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001568 mCurrentFrame.fbZ += 1;
1569 }
radhakrishnac9a67412013-09-25 17:40:42 +05301570 }
1571}
1572
Saurabh Shah88e4d272013-09-03 13:31:29 -07001573bool MDPCompSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Saurabh Shahc62f3982014-03-05 14:28:26 -08001574 MdpPipeInfoSplit& pipe_info) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001575
Saurabh Shahc62f3982014-03-05 14:28:26 -08001576 const int lSplit = getLeftSplit(ctx, mDpy);
1577 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001578 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001579 pipe_info.lIndex = ovutils::OV_INVALID;
1580 pipe_info.rIndex = ovutils::OV_INVALID;
1581
Saurabh Shahc62f3982014-03-05 14:28:26 -08001582 Overlay::PipeSpecs pipeSpecs;
1583 pipeSpecs.formatClass = isYuvBuffer(hnd) ?
1584 Overlay::FORMAT_YUV : Overlay::FORMAT_RGB;
1585 pipeSpecs.needsScaling = qhwc::needsScalingWithSplit(ctx, layer, mDpy);
1586 pipeSpecs.dpy = mDpy;
1587 pipeSpecs.mixer = Overlay::MIXER_LEFT;
1588 pipeSpecs.fb = false;
1589
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001590 if (dst.left < lSplit) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001591 pipe_info.lIndex = ctx->mOverlay->getPipe(pipeSpecs);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001592 if(pipe_info.lIndex == ovutils::OV_INVALID)
1593 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001594 }
1595
1596 if(dst.right > lSplit) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001597 pipeSpecs.mixer = Overlay::MIXER_RIGHT;
1598 pipe_info.rIndex = ctx->mOverlay->getPipe(pipeSpecs);
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001599 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001600 return false;
1601 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001602
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001603 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001604}
1605
Saurabh Shah88e4d272013-09-03 13:31:29 -07001606bool MDPCompSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001607 hwc_display_contents_1_t* list) {
1608 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001609
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001610 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001611
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001612 hwc_layer_1_t* layer = &list->hwLayers[index];
1613 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301614 hwc_rect_t dst = layer->displayFrame;
1615 const int lSplit = getLeftSplit(ctx, mDpy);
1616 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1617 if((dst.left > lSplit)||(dst.right < lSplit)){
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001618 if(allocSplitVGPipesfor4k2k(ctx, index)){
radhakrishnac9a67412013-09-25 17:40:42 +05301619 continue;
1620 }
1621 }
1622 }
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001623 int mdpIndex = mCurrentFrame.layerToMDP[index];
1624 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001625 info.pipeInfo = new MdpPipeInfoSplit;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001626 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001627 MdpPipeInfoSplit& pipe_info = *(MdpPipeInfoSplit*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001628
Saurabh Shahc62f3982014-03-05 14:28:26 -08001629 if(!acquireMDPPipes(ctx, layer, pipe_info)) {
1630 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type",
1631 __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001632 return false;
1633 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001634 }
1635 return true;
1636}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001637
radhakrishnac9a67412013-09-25 17:40:42 +05301638int MDPCompSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1639 PipeLayerPair& PipeLayerPair) {
1640 const int lSplit = getLeftSplit(ctx, mDpy);
1641 hwc_rect_t dst = layer->displayFrame;
1642 if((dst.left > lSplit)||(dst.right < lSplit)){
1643 MdpYUVPipeInfo& mdp_info =
1644 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1645 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1646 eIsFg isFg = IS_FG_OFF;
1647 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1648 eDest lDest = mdp_info.lIndex;
1649 eDest rDest = mdp_info.rIndex;
1650
1651 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1652 lDest, rDest, &PipeLayerPair.rot);
1653 }
1654 else{
1655 return configure(ctx, layer, PipeLayerPair);
1656 }
1657}
1658
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001659/*
1660 * Configures pipe(s) for MDP composition
1661 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001662int MDPCompSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001663 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001664 MdpPipeInfoSplit& mdp_info =
1665 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001666 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1667 eIsFg isFg = IS_FG_OFF;
1668 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1669 eDest lDest = mdp_info.lIndex;
1670 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001671
1672 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1673 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1674
Saurabh Shah88e4d272013-09-03 13:31:29 -07001675 return configureSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001676 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001677}
1678
Saurabh Shah88e4d272013-09-03 13:31:29 -07001679bool MDPCompSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001680
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001681 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001682 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1683 return true;
1684 }
1685
1686 if(!ctx || !list) {
1687 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001688 return false;
1689 }
1690
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301691 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1692 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1693 return true;
1694 }
1695
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -08001696 // Set the Handle timeout to true for MDP or MIXED composition.
1697 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount) {
1698 sHandleTimeout = true;
1699 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001700
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001701 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001702 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001703
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001704 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1705 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001706 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001707 if(mCurrentFrame.isFBComposed[i]) continue;
1708
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001709 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001710 private_handle_t *hnd = (private_handle_t *)layer->handle;
1711 if(!hnd) {
1712 ALOGE("%s handle null", __FUNCTION__);
1713 return false;
1714 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001715
1716 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1717 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001718 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001719
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001720 int mdpIndex = mCurrentFrame.layerToMDP[i];
1721
radhakrishnac9a67412013-09-25 17:40:42 +05301722 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1723 {
1724 MdpYUVPipeInfo& pipe_info =
1725 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1726 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1727 ovutils::eDest indexL = pipe_info.lIndex;
1728 ovutils::eDest indexR = pipe_info.rIndex;
1729 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301730 uint32_t offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05301731 if(rot) {
1732 rot->queueBuffer(fd, offset);
1733 fd = rot->getDstMemId();
1734 offset = rot->getDstOffset();
1735 }
1736 if(indexL != ovutils::OV_INVALID) {
1737 ovutils::eDest destL = (ovutils::eDest)indexL;
1738 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1739 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1740 if (!ov.queueBuffer(fd, offset, destL)) {
1741 ALOGE("%s: queueBuffer failed for display:%d",
1742 __FUNCTION__, mDpy);
1743 return false;
1744 }
1745 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001746
radhakrishnac9a67412013-09-25 17:40:42 +05301747 if(indexR != ovutils::OV_INVALID) {
1748 ovutils::eDest destR = (ovutils::eDest)indexR;
1749 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1750 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1751 if (!ov.queueBuffer(fd, offset, destR)) {
1752 ALOGE("%s: queueBuffer failed for display:%d",
1753 __FUNCTION__, mDpy);
1754 return false;
1755 }
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001756 }
1757 }
radhakrishnac9a67412013-09-25 17:40:42 +05301758 else{
1759 MdpPipeInfoSplit& pipe_info =
1760 *(MdpPipeInfoSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1761 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001762
radhakrishnac9a67412013-09-25 17:40:42 +05301763 ovutils::eDest indexL = pipe_info.lIndex;
1764 ovutils::eDest indexR = pipe_info.rIndex;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001765
radhakrishnac9a67412013-09-25 17:40:42 +05301766 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301767 int offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05301768
1769 if(ctx->mAD->isModeOn()) {
1770 if(ctx->mAD->draw(ctx, fd, offset)) {
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001771 fd = ctx->mAD->getDstFd();
1772 offset = ctx->mAD->getDstOffset();
radhakrishnac9a67412013-09-25 17:40:42 +05301773 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001774 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001775
radhakrishnac9a67412013-09-25 17:40:42 +05301776 if(rot) {
1777 rot->queueBuffer(fd, offset);
1778 fd = rot->getDstMemId();
1779 offset = rot->getDstOffset();
1780 }
1781
1782 //************* play left mixer **********
1783 if(indexL != ovutils::OV_INVALID) {
1784 ovutils::eDest destL = (ovutils::eDest)indexL;
1785 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1786 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1787 if (!ov.queueBuffer(fd, offset, destL)) {
1788 ALOGE("%s: queueBuffer failed for left mixer",
1789 __FUNCTION__);
1790 return false;
1791 }
1792 }
1793
1794 //************* play right mixer **********
1795 if(indexR != ovutils::OV_INVALID) {
1796 ovutils::eDest destR = (ovutils::eDest)indexR;
1797 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1798 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1799 if (!ov.queueBuffer(fd, offset, destR)) {
1800 ALOGE("%s: queueBuffer failed for right mixer",
1801 __FUNCTION__);
1802 return false;
1803 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001804 }
1805 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001806
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001807 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1808 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001809
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001810 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001811}
Saurabh Shahab47c692014-02-12 18:45:57 -08001812
1813//================MDPCompSrcSplit==============================================
1814bool MDPCompSrcSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Saurabh Shahc62f3982014-03-05 14:28:26 -08001815 MdpPipeInfoSplit& pipe_info) {
Saurabh Shahab47c692014-02-12 18:45:57 -08001816 private_handle_t *hnd = (private_handle_t *)layer->handle;
1817 hwc_rect_t dst = layer->displayFrame;
1818 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
1819 pipe_info.lIndex = ovutils::OV_INVALID;
1820 pipe_info.rIndex = ovutils::OV_INVALID;
1821
1822 //If 2 pipes are staged on a single stage of a mixer, then the left pipe
1823 //should have a higher priority than the right one. Pipe priorities are
1824 //starting with VG0, VG1 ... , RGB0 ..., DMA1
Saurabh Shahab47c692014-02-12 18:45:57 -08001825
Saurabh Shahc62f3982014-03-05 14:28:26 -08001826 Overlay::PipeSpecs pipeSpecs;
1827 pipeSpecs.formatClass = isYuvBuffer(hnd) ?
1828 Overlay::FORMAT_YUV : Overlay::FORMAT_RGB;
1829 pipeSpecs.needsScaling = qhwc::needsScaling(layer);
1830 pipeSpecs.dpy = mDpy;
1831 pipeSpecs.fb = false;
1832
Saurabh Shahab47c692014-02-12 18:45:57 -08001833 //1 pipe by default for a layer
Saurabh Shahc62f3982014-03-05 14:28:26 -08001834 pipe_info.lIndex = ctx->mOverlay->getPipe(pipeSpecs);
Saurabh Shahab47c692014-02-12 18:45:57 -08001835 if(pipe_info.lIndex == ovutils::OV_INVALID) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001836 return false;
Saurabh Shahab47c692014-02-12 18:45:57 -08001837 }
1838
1839 //If layer's crop width or dest width > 2048, use 2 pipes
1840 if((dst.right - dst.left) > qdutils::MAX_DISPLAY_DIM or
1841 (crop.right - crop.left) > qdutils::MAX_DISPLAY_DIM) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001842 pipe_info.rIndex = ctx->mOverlay->getPipe(pipeSpecs);
Saurabh Shahab47c692014-02-12 18:45:57 -08001843 if(pipe_info.rIndex == ovutils::OV_INVALID) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001844 return false;
Saurabh Shahdd8237a2014-02-28 14:29:09 -08001845 }
1846
1847 // Return values
1848 // 1 Left pipe is higher priority, do nothing.
1849 // 0 Pipes of same priority.
1850 //-1 Right pipe is of higher priority, needs swap.
1851 if(ctx->mOverlay->comparePipePriority(pipe_info.lIndex,
1852 pipe_info.rIndex) == -1) {
1853 qhwc::swap(pipe_info.lIndex, pipe_info.rIndex);
Saurabh Shahab47c692014-02-12 18:45:57 -08001854 }
1855 }
1856
1857 return true;
1858}
1859
Saurabh Shahab47c692014-02-12 18:45:57 -08001860int MDPCompSrcSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
1861 PipeLayerPair& PipeLayerPair) {
1862 private_handle_t *hnd = (private_handle_t *)layer->handle;
1863 if(!hnd) {
1864 ALOGE("%s: layer handle is NULL", __FUNCTION__);
1865 return -1;
1866 }
1867 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
1868 MdpPipeInfoSplit& mdp_info =
1869 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
1870 Rotator **rot = &PipeLayerPair.rot;
1871 eZorder z = static_cast<eZorder>(mdp_info.zOrder);
1872 eIsFg isFg = IS_FG_OFF;
1873 eDest lDest = mdp_info.lIndex;
1874 eDest rDest = mdp_info.rIndex;
1875 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
1876 hwc_rect_t dst = layer->displayFrame;
1877 int transform = layer->transform;
1878 eTransform orient = static_cast<eTransform>(transform);
1879 const int downscale = 0;
1880 int rotFlags = ROT_FLAGS_NONE;
1881 uint32_t format = ovutils::getMdpFormat(hnd->format, isTileRendered(hnd));
1882 Whf whf(getWidth(hnd), getHeight(hnd), format, hnd->size);
1883
1884 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1885 "dest_pipeR: %d",__FUNCTION__, layer, z, lDest, rDest);
1886
1887 // Handle R/B swap
1888 if (layer->flags & HWC_FORMAT_RB_SWAP) {
1889 if (hnd->format == HAL_PIXEL_FORMAT_RGBA_8888)
1890 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRA_8888);
1891 else if (hnd->format == HAL_PIXEL_FORMAT_RGBX_8888)
1892 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRX_8888);
1893 }
1894
Saurabh Shah97e2d802014-04-14 18:03:54 -07001895 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
1896 setMdpFlags(layer, mdpFlags, 0, transform);
Saurabh Shahab47c692014-02-12 18:45:57 -08001897
1898 if(lDest != OV_INVALID && rDest != OV_INVALID) {
1899 //Enable overfetch
Saurabh Shah97e2d802014-04-14 18:03:54 -07001900 setMdpFlags(mdpFlags, OV_MDSS_MDP_DUAL_PIPE);
Saurabh Shahab47c692014-02-12 18:45:57 -08001901 }
1902
1903 if(isYuvBuffer(hnd) && (transform & HWC_TRANSFORM_ROT_90)) {
1904 (*rot) = ctx->mRotMgr->getNext();
1905 if((*rot) == NULL) return -1;
Saurabh Shah39240c92014-03-31 10:31:42 -07001906 ctx->mLayerRotMap[mDpy]->add(layer, *rot);
Saurabh Shahab47c692014-02-12 18:45:57 -08001907 //Configure rotator for pre-rotation
Saurabh Shah97e2d802014-04-14 18:03:54 -07001908 if(configRotator(*rot, whf, crop, mdpFlags, orient, downscale) < 0) {
Saurabh Shahab47c692014-02-12 18:45:57 -08001909 ALOGE("%s: configRotator failed!", __FUNCTION__);
1910 return -1;
1911 }
Saurabh Shahab47c692014-02-12 18:45:57 -08001912 whf.format = (*rot)->getDstFormat();
1913 updateSource(orient, whf, crop);
1914 rotFlags |= ROT_PREROTATED;
1915 }
1916
1917 //If 2 pipes being used, divide layer into half, crop and dst
1918 hwc_rect_t cropL = crop;
1919 hwc_rect_t cropR = crop;
1920 hwc_rect_t dstL = dst;
1921 hwc_rect_t dstR = dst;
1922 if(lDest != OV_INVALID && rDest != OV_INVALID) {
1923 cropL.right = (crop.right + crop.left) / 2;
1924 cropR.left = cropL.right;
1925 sanitizeSourceCrop(cropL, cropR, hnd);
1926
1927 //Swap crops on H flip since 2 pipes are being used
1928 if((orient & OVERLAY_TRANSFORM_FLIP_H) && (*rot) == NULL) {
1929 hwc_rect_t tmp = cropL;
1930 cropL = cropR;
1931 cropR = tmp;
1932 }
1933
1934 dstL.right = (dst.right + dst.left) / 2;
1935 dstR.left = dstL.right;
1936 }
1937
1938 //For the mdp, since either we are pre-rotating or MDP does flips
1939 orient = OVERLAY_TRANSFORM_0;
1940 transform = 0;
1941
1942 //configure left pipe
1943 if(lDest != OV_INVALID) {
Saurabh Shah97e2d802014-04-14 18:03:54 -07001944 PipeArgs pargL(mdpFlags, whf, z, isFg,
Saurabh Shahab47c692014-02-12 18:45:57 -08001945 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
1946 (ovutils::eBlending) getBlending(layer->blending));
1947
1948 if(configMdp(ctx->mOverlay, pargL, orient,
1949 cropL, dstL, metadata, lDest) < 0) {
1950 ALOGE("%s: commit failed for left mixer config", __FUNCTION__);
1951 return -1;
1952 }
1953 }
1954
1955 //configure right pipe
1956 if(rDest != OV_INVALID) {
Saurabh Shah97e2d802014-04-14 18:03:54 -07001957 PipeArgs pargR(mdpFlags, whf, z, isFg,
Saurabh Shahab47c692014-02-12 18:45:57 -08001958 static_cast<eRotFlags>(rotFlags),
1959 layer->planeAlpha,
1960 (ovutils::eBlending) getBlending(layer->blending));
1961 if(configMdp(ctx->mOverlay, pargR, orient,
1962 cropR, dstR, metadata, rDest) < 0) {
1963 ALOGE("%s: commit failed for right mixer config", __FUNCTION__);
1964 return -1;
1965 }
1966 }
1967
1968 return 0;
1969}
1970
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001971}; //namespace
1972