blob: 0287f7eb332254ba66fecfc21ee9db848ae0f78e [file] [log] [blame]
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001/*
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002 * Copyright (C) 2012-2013, The Linux Foundation. All rights reserved.
Naseer Ahmed7c958d42012-07-31 18:57:03 -07003 * Not a Contribution, Apache license notifications and license are retained
4 * for attribution purposes only.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
Saurabh Shah4fdde762013-04-30 18:47:33 -070019#include <math.h>
Naseer Ahmed7c958d42012-07-31 18:57:03 -070020#include "hwc_mdpcomp.h"
Naseer Ahmed54821fe2012-11-28 18:44:38 -050021#include <sys/ioctl.h>
Saurabh Shah56f610d2012-08-07 15:27:06 -070022#include "external.h"
Jeykumar Sankaran27dee262013-08-01 17:09:54 -070023#include "virtual.h"
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -080024#include "qdMetaData.h"
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -080025#include "mdp_version.h"
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -070026#include "hwc_fbupdate.h"
Saurabh Shaha9da08f2013-07-03 13:27:53 -070027#include "hwc_ad.h"
Saurabh Shahacf10202013-02-26 10:15:15 -080028#include <overlayRotator.h>
Sushil Chauhan4259d872014-05-13 18:17:12 -070029#include "hwc_copybit.h"
Saurabh Shahacf10202013-02-26 10:15:15 -080030
Saurabh Shah85234ec2013-04-12 17:09:00 -070031using namespace overlay;
Saurabh Shahbd2d0832013-04-04 14:33:08 -070032using namespace qdutils;
Saurabh Shahacf10202013-02-26 10:15:15 -080033using namespace overlay::utils;
34namespace ovutils = overlay::utils;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070035
Naseer Ahmed7c958d42012-07-31 18:57:03 -070036namespace qhwc {
37
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080038//==============MDPComp========================================================
39
Naseer Ahmed7c958d42012-07-31 18:57:03 -070040IdleInvalidator *MDPComp::idleInvalidator = NULL;
41bool MDPComp::sIdleFallBack = false;
Ramkumar Radhakrishnand8595ae2014-02-06 21:31:29 -080042bool MDPComp::sHandleTimeout = false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070043bool MDPComp::sDebugLogs = false;
Naseer Ahmed54821fe2012-11-28 18:44:38 -050044bool MDPComp::sEnabled = false;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -070045bool MDPComp::sEnableMixedMode = true;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -070046bool MDPComp::sEnablePartialFrameUpdate = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080047int MDPComp::sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
radhakrishnac9a67412013-09-25 17:40:42 +053048bool MDPComp::sEnable4k2kYUVSplit = false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070049
Saurabh Shah88e4d272013-09-03 13:31:29 -070050MDPComp* MDPComp::getObject(hwc_context_t *ctx, const int& dpy) {
51 if(isDisplaySplit(ctx, dpy)) {
52 return new MDPCompSplit(dpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080053 }
Saurabh Shah88e4d272013-09-03 13:31:29 -070054 return new MDPCompNonSplit(dpy);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080055}
56
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080057MDPComp::MDPComp(int dpy):mDpy(dpy){};
58
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080059void MDPComp::dump(android::String8& buf)
60{
Jeykumar Sankaran3c6bb042013-08-15 14:01:04 -070061 if(mCurrentFrame.layerCount > MAX_NUM_APP_LAYERS)
62 return;
63
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080064 dumpsys_log(buf,"HWC Map for Dpy: %s \n",
Jeykumar Sankaran27dee262013-08-01 17:09:54 -070065 (mDpy == 0) ? "\"PRIMARY\"" :
66 (mDpy == 1) ? "\"EXTERNAL\"" : "\"VIRTUAL\"");
Saurabh Shahe9bc60f2013-08-29 12:58:06 -070067 dumpsys_log(buf,"CURR_FRAME: layerCount:%2d mdpCount:%2d "
68 "fbCount:%2d \n", mCurrentFrame.layerCount,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080069 mCurrentFrame.mdpCount, mCurrentFrame.fbCount);
70 dumpsys_log(buf,"needsFBRedraw:%3s pipesUsed:%2d MaxPipesPerMixer: %d \n",
71 (mCurrentFrame.needsRedraw? "YES" : "NO"),
72 mCurrentFrame.mdpCount, sMaxPipesPerMixer);
73 dumpsys_log(buf," --------------------------------------------- \n");
74 dumpsys_log(buf," listIdx | cached? | mdpIndex | comptype | Z \n");
75 dumpsys_log(buf," --------------------------------------------- \n");
76 for(int index = 0; index < mCurrentFrame.layerCount; index++ )
77 dumpsys_log(buf," %7d | %7s | %8d | %9s | %2d \n",
78 index,
79 (mCurrentFrame.isFBComposed[index] ? "YES" : "NO"),
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -070080 mCurrentFrame.layerToMDP[index],
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080081 (mCurrentFrame.isFBComposed[index] ?
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -070082 (mCurrentFrame.drop[index] ? "DROP" :
83 (mCurrentFrame.needsRedraw ? "GLES" : "CACHE")) : "MDP"),
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080084 (mCurrentFrame.isFBComposed[index] ? mCurrentFrame.fbZ :
85 mCurrentFrame.mdpToLayer[mCurrentFrame.layerToMDP[index]].pipeInfo->zOrder));
86 dumpsys_log(buf,"\n");
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080087}
88
89bool MDPComp::init(hwc_context_t *ctx) {
90
91 if(!ctx) {
92 ALOGE("%s: Invalid hwc context!!",__FUNCTION__);
93 return false;
94 }
95
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080096 char property[PROPERTY_VALUE_MAX];
97
98 sEnabled = false;
99 if((property_get("persist.hwc.mdpcomp.enable", property, NULL) > 0) &&
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800100 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
101 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800102 sEnabled = true;
103 }
104
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700105 sEnableMixedMode = true;
106 if((property_get("debug.mdpcomp.mixedmode.disable", property, NULL) > 0) &&
107 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
108 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
109 sEnableMixedMode = false;
110 }
111
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800112 if(property_get("debug.mdpcomp.logs", property, NULL) > 0) {
113 if(atoi(property) != 0)
114 sDebugLogs = true;
115 }
116
Jeykumar Sankaran18469742014-02-19 12:40:57 -0800117 if(property_get("persist.hwc.partialupdate", property, NULL) > 0) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700118 if((atoi(property) != 0) && ctx->mMDP.panel == MIPI_CMD_PANEL &&
119 qdutils::MDPVersion::getInstance().is8x74v2())
120 sEnablePartialFrameUpdate = true;
121 }
122 ALOGE_IF(isDebug(), "%s: Partial Update applicable?: %d",__FUNCTION__,
123 sEnablePartialFrameUpdate);
124
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800125 sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
Saurabh Shah85234ec2013-04-12 17:09:00 -0700126 if(property_get("debug.mdpcomp.maxpermixer", property, "-1") > 0) {
127 int val = atoi(property);
128 if(val >= 0)
129 sMaxPipesPerMixer = min(val, MAX_PIPES_PER_MIXER);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800130 }
131
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400132 if(ctx->mMDP.panel != MIPI_CMD_PANEL) {
133 // Idle invalidation is not necessary on command mode panels
134 long idle_timeout = DEFAULT_IDLE_TIME;
135 if(property_get("debug.mdpcomp.idletime", property, NULL) > 0) {
136 if(atoi(property) != 0)
137 idle_timeout = atoi(property);
138 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800139
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400140 //create Idle Invalidator only when not disabled through property
141 if(idle_timeout != -1)
142 idleInvalidator = IdleInvalidator::getInstance();
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800143
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400144 if(idleInvalidator == NULL) {
145 ALOGE("%s: failed to instantiate idleInvalidator object",
146 __FUNCTION__);
147 } else {
148 idleInvalidator->init(timeout_handler, ctx, idle_timeout);
149 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800150 }
radhakrishnac9a67412013-09-25 17:40:42 +0530151
152 if((property_get("debug.mdpcomp.4k2kSplit", property, "0") > 0) &&
153 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
154 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
155 sEnable4k2kYUVSplit = true;
156 }
Sushil Chauhan4259d872014-05-13 18:17:12 -0700157
158 if ((property_get("persist.hwc.ptor.enable", property, NULL) > 0) &&
159 ((!strncasecmp(property, "true", PROPERTY_VALUE_MAX )) ||
160 (!strncmp(property, "1", PROPERTY_VALUE_MAX )))) {
161 ctx->mCopyBit[HWC_DISPLAY_PRIMARY] = new CopyBit(ctx,
162 HWC_DISPLAY_PRIMARY);
163 }
164
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700165 return true;
166}
167
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800168void MDPComp::reset(hwc_context_t *ctx) {
169 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700170 mCurrentFrame.reset(numLayers);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800171 ctx->mOverlay->clear(mDpy);
172 ctx->mLayerRotMap[mDpy]->clear();
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700173}
174
Raj Kamal5166b312014-06-06 13:45:20 +0530175void MDPComp::reset() {
176 sHandleTimeout = false;
177 mModeOn = false;
178}
179
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700180void MDPComp::timeout_handler(void *udata) {
181 struct hwc_context_t* ctx = (struct hwc_context_t*)(udata);
182
183 if(!ctx) {
184 ALOGE("%s: received empty data in timer callback", __FUNCTION__);
185 return;
186 }
Ramkumar Radhakrishnand8595ae2014-02-06 21:31:29 -0800187 Locker::Autolock _l(ctx->mDrawLock);
188 // Handle timeout event only if the previous composition is MDP or MIXED.
189 if(!sHandleTimeout) {
190 ALOGD_IF(isDebug(), "%s:Do not handle this timeout", __FUNCTION__);
191 return;
192 }
Jesse Hall3be78d92012-08-21 15:12:23 -0700193 if(!ctx->proc) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700194 ALOGE("%s: HWC proc not registered", __FUNCTION__);
195 return;
196 }
197 sIdleFallBack = true;
198 /* Trigger SF to redraw the current frame */
Jesse Hall3be78d92012-08-21 15:12:23 -0700199 ctx->proc->invalidate(ctx->proc);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700200}
201
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800202void MDPComp::setMDPCompLayerFlags(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800203 hwc_display_contents_1_t* list) {
204 LayerProp *layerProp = ctx->layerProp[mDpy];
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800205
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800206 for(int index = 0; index < ctx->listStats[mDpy].numAppLayers; index++) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800207 hwc_layer_1_t* layer = &(list->hwLayers[index]);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800208 if(!mCurrentFrame.isFBComposed[index]) {
209 layerProp[index].mFlags |= HWC_MDPCOMP;
210 layer->compositionType = HWC_OVERLAY;
211 layer->hints |= HWC_HINT_CLEAR_FB;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800212 } else {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700213 /* Drop the layer when its already present in FB OR when it lies
214 * outside frame's ROI */
215 if(!mCurrentFrame.needsRedraw || mCurrentFrame.drop[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800216 layer->compositionType = HWC_OVERLAY;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700217 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800218 }
219 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700220}
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500221
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800222void MDPComp::setRedraw(hwc_context_t *ctx,
223 hwc_display_contents_1_t* list) {
224 mCurrentFrame.needsRedraw = false;
225 if(!mCachedFrame.isSameFrame(mCurrentFrame, list) ||
226 (list->flags & HWC_GEOMETRY_CHANGED) ||
227 isSkipPresent(ctx, mDpy)) {
228 mCurrentFrame.needsRedraw = true;
229 }
230}
231
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800232MDPComp::FrameInfo::FrameInfo() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700233 reset(0);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800234}
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800235
Saurabh Shahaa236822013-04-24 18:07:26 -0700236void MDPComp::FrameInfo::reset(const int& numLayers) {
237 for(int i = 0 ; i < MAX_PIPES_PER_MIXER && numLayers; i++ ) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800238 if(mdpToLayer[i].pipeInfo) {
239 delete mdpToLayer[i].pipeInfo;
240 mdpToLayer[i].pipeInfo = NULL;
241 //We dont own the rotator
242 mdpToLayer[i].rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800243 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800244 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800245
246 memset(&mdpToLayer, 0, sizeof(mdpToLayer));
247 memset(&layerToMDP, -1, sizeof(layerToMDP));
Saurabh Shahaa236822013-04-24 18:07:26 -0700248 memset(&isFBComposed, 1, sizeof(isFBComposed));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800249
Saurabh Shahaa236822013-04-24 18:07:26 -0700250 layerCount = numLayers;
251 fbCount = numLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800252 mdpCount = 0;
Saurabh Shah2f3895f2013-05-02 10:13:31 -0700253 needsRedraw = true;
Saurabh Shahce188452014-02-05 10:17:43 -0800254 fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800255}
256
Saurabh Shahaa236822013-04-24 18:07:26 -0700257void MDPComp::FrameInfo::map() {
258 // populate layer and MDP maps
259 int mdpIdx = 0;
260 for(int idx = 0; idx < layerCount; idx++) {
261 if(!isFBComposed[idx]) {
262 mdpToLayer[mdpIdx].listIndex = idx;
263 layerToMDP[idx] = mdpIdx++;
264 }
265 }
266}
267
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800268MDPComp::LayerCache::LayerCache() {
269 reset();
270}
271
272void MDPComp::LayerCache::reset() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700273 memset(&hnd, 0, sizeof(hnd));
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530274 memset(&isFBComposed, true, sizeof(isFBComposed));
275 memset(&drop, false, sizeof(drop));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800276 layerCount = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -0700277}
278
279void MDPComp::LayerCache::cacheAll(hwc_display_contents_1_t* list) {
280 const int numAppLayers = list->numHwLayers - 1;
281 for(int i = 0; i < numAppLayers; i++) {
282 hnd[i] = list->hwLayers[i].handle;
283 }
284}
285
286void MDPComp::LayerCache::updateCounts(const FrameInfo& curFrame) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700287 layerCount = curFrame.layerCount;
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530288 memcpy(&isFBComposed, &curFrame.isFBComposed, sizeof(isFBComposed));
289 memcpy(&drop, &curFrame.drop, sizeof(drop));
290}
291
Jeykumar Sankaran988d3682013-11-15 11:57:16 -0800292bool MDPComp::LayerCache::isSameFrame(const FrameInfo& curFrame,
293 hwc_display_contents_1_t* list) {
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530294 if(layerCount != curFrame.layerCount)
295 return false;
296 for(int i = 0; i < curFrame.layerCount; i++) {
297 if((curFrame.isFBComposed[i] != isFBComposed[i]) ||
298 (curFrame.drop[i] != drop[i])) {
299 return false;
300 }
Jeykumar Sankaran988d3682013-11-15 11:57:16 -0800301 if(curFrame.isFBComposed[i] &&
302 (hnd[i] != list->hwLayers[i].handle)){
303 return false;
304 }
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530305 }
306 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800307}
308
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700309bool MDPComp::isSupportedForMDPComp(hwc_context_t *ctx, hwc_layer_1_t* layer) {
310 private_handle_t *hnd = (private_handle_t *)layer->handle;
311 if((not isYuvBuffer(hnd) and has90Transform(layer)) or
312 (not isValidDimension(ctx,layer))
313 //More conditions here, SKIP, sRGB+Blend etc
314 ) {
315 return false;
316 }
317 return true;
318}
319
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530320bool MDPComp::isValidDimension(hwc_context_t *ctx, hwc_layer_1_t *layer) {
Saurabh Shah4fdde762013-04-30 18:47:33 -0700321 const int dpy = HWC_DISPLAY_PRIMARY;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800322 private_handle_t *hnd = (private_handle_t *)layer->handle;
323
324 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -0700325 if (layer->flags & HWC_COLOR_FILL) {
326 // Color layer
327 return true;
328 }
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800329 ALOGE("%s: layer handle is NULL", __FUNCTION__);
330 return false;
331 }
332
Naseer Ahmede850a802013-09-06 13:12:52 -0400333 //XXX: Investigate doing this with pixel phase on MDSS
Naseer Ahmede77f8082013-10-10 13:42:48 -0400334 if(!isSecureBuffer(hnd) && isNonIntegralSourceCrop(layer->sourceCropf))
Naseer Ahmede850a802013-09-06 13:12:52 -0400335 return false;
336
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800337 int hw_w = ctx->dpyAttr[mDpy].xres;
338 int hw_h = ctx->dpyAttr[mDpy].yres;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800339
Saurabh Shah62e1d732013-09-17 10:44:05 -0700340 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700341 hwc_rect_t dst = layer->displayFrame;
Saurabh Shah4fdde762013-04-30 18:47:33 -0700342 int crop_w = crop.right - crop.left;
343 int crop_h = crop.bottom - crop.top;
344 int dst_w = dst.right - dst.left;
345 int dst_h = dst.bottom - dst.top;
346 float w_dscale = ceilf((float)crop_w / (float)dst_w);
347 float h_dscale = ceilf((float)crop_h / (float)dst_h);
348
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800349 /* Workaround for MDP HW limitation in DSI command mode panels where
350 * FPS will not go beyond 30 if buffers on RGB pipes are of width or height
351 * less than 5 pixels
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530352 * There also is a HW limilation in MDP, minimum block size is 2x2
353 * Fallback to GPU if height is less than 2.
354 */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800355 if((crop_w < 5)||(crop_h < 5))
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800356 return false;
357
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800358 if((w_dscale > 1.0f) || (h_dscale > 1.0f)) {
359 const uint32_t downscale =
Saurabh Shah4fdde762013-04-30 18:47:33 -0700360 qdutils::MDPVersion::getInstance().getMaxMDPDownscale();
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800361 if(ctx->mMDP.version >= qdutils::MDSS_V5) {
362 /* Workaround for downscales larger than 4x.
363 * Will be removed once decimator block is enabled for MDSS
364 */
365 if(!qdutils::MDPVersion::getInstance().supportsDecimation()) {
366 if(crop_w > MAX_DISPLAY_DIM || w_dscale > downscale ||
367 h_dscale > downscale)
368 return false;
369 } else {
370 if(w_dscale > 64 || h_dscale > 64)
371 return false;
372 }
373 } else { //A-family
374 if(w_dscale > downscale || h_dscale > downscale)
Saurabh Shah4fdde762013-04-30 18:47:33 -0700375 return false;
376 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700377 }
378
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800379 return true;
380}
381
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700382ovutils::eDest MDPComp::getMdpPipe(hwc_context_t *ctx, ePipeType type,
383 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800384 overlay::Overlay& ov = *ctx->mOverlay;
385 ovutils::eDest mdp_pipe = ovutils::OV_INVALID;
386
387 switch(type) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800388 case MDPCOMP_OV_DMA:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700389 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_DMA, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800390 if(mdp_pipe != ovutils::OV_INVALID) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800391 return mdp_pipe;
392 }
393 case MDPCOMP_OV_ANY:
394 case MDPCOMP_OV_RGB:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700395 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800396 if(mdp_pipe != ovutils::OV_INVALID) {
397 return mdp_pipe;
398 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800399
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800400 if(type == MDPCOMP_OV_RGB) {
401 //Requested only for RGB pipe
402 break;
403 }
404 case MDPCOMP_OV_VG:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700405 return ov.nextPipe(ovutils::OV_MDP_PIPE_VG, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800406 default:
407 ALOGE("%s: Invalid pipe type",__FUNCTION__);
408 return ovutils::OV_INVALID;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800409 };
410 return ovutils::OV_INVALID;
411}
412
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800413bool MDPComp::isFrameDoable(hwc_context_t *ctx) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700414 bool ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700415 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800416
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800417 if(!isEnabled()) {
418 ALOGD_IF(isDebug(),"%s: MDP Comp. not enabled.", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700419 ret = false;
Saurabh Shahd4e65852013-06-17 11:33:53 -0700420 } else if(qdutils::MDPVersion::getInstance().is8x26() &&
Tatenda Chipeperekwa75a41812014-04-01 12:54:13 -0700421 ctx->mVideoTransFlag &&
422 isSecondaryConnected(ctx)) {
Saurabh Shahd4e65852013-06-17 11:33:53 -0700423 //1 Padding round to shift pipes across mixers
424 ALOGD_IF(isDebug(),"%s: MDP Comp. video transition padding round",
425 __FUNCTION__);
426 ret = false;
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700427 } else if(ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isConfiguring ||
428 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isConfiguring) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800429 ALOGD_IF( isDebug(),"%s: External Display connection is pending",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800430 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700431 ret = false;
Saurabh Shahaa236822013-04-24 18:07:26 -0700432 } else if(ctx->isPaddingRound) {
Raj Kamalfc5b9222014-02-07 16:15:17 +0530433 ALOGD_IF(isDebug(), "%s: padding round invoked for dpy %d",
434 __FUNCTION__,mDpy);
Saurabh Shahaa236822013-04-24 18:07:26 -0700435 ret = false;
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700436 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700437 return ret;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800438}
439
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800440/*
441 * 1) Identify layers that are not visible in the updating ROI and drop them
442 * from composition.
443 * 2) If we have a scaling layers which needs cropping against generated ROI.
444 * Reset ROI to full resolution.
445 */
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700446bool MDPComp::validateAndApplyROI(hwc_context_t *ctx,
447 hwc_display_contents_1_t* list, hwc_rect_t roi) {
448 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
449
450 if(!isValidRect(roi))
451 return false;
452
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800453 hwc_rect_t visibleRect = roi;
454
455 for(int i = numAppLayers - 1; i >= 0; i--){
456
457 if(!isValidRect(visibleRect)) {
458 mCurrentFrame.drop[i] = true;
459 mCurrentFrame.dropCount++;
Jeykumar Sankaran65bc8022014-01-21 17:26:12 -0800460 continue;
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800461 }
462
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700463 const hwc_layer_1_t* layer = &list->hwLayers[i];
464
465 hwc_rect_t dstRect = layer->displayFrame;
Arun Kumar K.R91090c72013-10-28 19:40:18 -0700466 hwc_rect_t srcRect = integerizeSourceCrop(layer->sourceCropf);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700467 int transform = layer->transform;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700468
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800469 hwc_rect_t res = getIntersection(visibleRect, dstRect);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700470
471 int res_w = res.right - res.left;
472 int res_h = res.bottom - res.top;
473 int dst_w = dstRect.right - dstRect.left;
474 int dst_h = dstRect.bottom - dstRect.top;
475
476 if(!isValidRect(res)) {
477 mCurrentFrame.drop[i] = true;
478 mCurrentFrame.dropCount++;
479 }else {
480 /* Reset frame ROI when any layer which needs scaling also needs ROI
481 * cropping */
Jeykumar Sankaran65bc8022014-01-21 17:26:12 -0800482 if((res_w != dst_w || res_h != dst_h) && needsScaling (layer)) {
Arpita Banerjeed8965982013-11-08 17:27:33 -0800483 ALOGI("%s: Resetting ROI due to scaling", __FUNCTION__);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700484 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
485 mCurrentFrame.dropCount = 0;
486 return false;
487 }
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800488
Jeykumar Sankaran65bc8022014-01-21 17:26:12 -0800489 /* deduct any opaque region from visibleRect */
490 if (layer->blending == HWC_BLENDING_NONE)
491 visibleRect = deductRect(visibleRect, res);
492 }
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700493 }
494 return true;
495}
496
Jeykumar Sankaran4d76a382014-02-26 18:26:58 -0800497bool MDPComp::canDoPartialUpdate(hwc_context_t *ctx,
498 hwc_display_contents_1_t* list){
499 if(!qdutils::MDPVersion::getInstance().isPartialUpdateEnabled() || mDpy ||
500 isSkipPresent(ctx, mDpy) || (list->flags & HWC_GEOMETRY_CHANGED)||
501 isDisplaySplit(ctx, mDpy)) {
502 return false;
503 }
504 return true;
505}
506
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700507void MDPComp::generateROI(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
508 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
509
Jeykumar Sankaran4d76a382014-02-26 18:26:58 -0800510 if(!canDoPartialUpdate(ctx, list))
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700511 return;
512
513 struct hwc_rect roi = (struct hwc_rect){0, 0, 0, 0};
514 for(int index = 0; index < numAppLayers; index++ ) {
Jeykumar Sankaran4d76a382014-02-26 18:26:58 -0800515 hwc_layer_1_t* layer = &list->hwLayers[index];
516 if ((mCachedFrame.hnd[index] != layer->handle) ||
Jeykumar Sankaran78893422014-05-07 16:23:14 -0700517 isYuvBuffer((private_handle_t *)layer->handle)) {
518 hwc_rect_t dst = layer->displayFrame;
519 hwc_rect_t updatingRect = dst;
520
Jeykumar Sankaran4d76a382014-02-26 18:26:58 -0800521#ifdef QCOM_BSP
Jeykumar Sankaran78893422014-05-07 16:23:14 -0700522 if(!needsScaling(layer) && !layer->transform)
523 {
524 hwc_rect_t src = integerizeSourceCrop(layer->sourceCropf);
525 int x_off = dst.left - src.left;
526 int y_off = dst.top - src.top;
527 updatingRect = moveRect(layer->dirtyRect, x_off, y_off);
528 }
Jeykumar Sankaran4d76a382014-02-26 18:26:58 -0800529#endif
530 roi = getUnion(roi, updatingRect);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700531 }
532 }
533
Jeykumar Sankaran4d76a382014-02-26 18:26:58 -0800534 hwc_rect fullFrame = (struct hwc_rect) {0, 0,(int)ctx->dpyAttr[mDpy].xres,
535 (int)ctx->dpyAttr[mDpy].yres};
536
537 // Align ROI coordinates to panel restrictions
538 roi = sanitizeROI(roi, fullFrame);
539
540 if(!validateAndApplyROI(ctx, list, roi))
541 roi = fullFrame;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700542
543 ctx->listStats[mDpy].roi.x = roi.left;
544 ctx->listStats[mDpy].roi.y = roi.top;
545 ctx->listStats[mDpy].roi.w = roi.right - roi.left;
546 ctx->listStats[mDpy].roi.h = roi.bottom - roi.top;
547
548 ALOGD_IF(isDebug(),"%s: generated ROI: [%d, %d, %d, %d]", __FUNCTION__,
549 roi.left, roi.top, roi.right, roi.bottom);
550}
551
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800552/* Checks for conditions where all the layers marked for MDP comp cannot be
553 * bypassed. On such conditions we try to bypass atleast YUV layers */
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800554bool MDPComp::tryFullFrame(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800555 hwc_display_contents_1_t* list){
556
Saurabh Shahaa236822013-04-24 18:07:26 -0700557 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800558
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -0700559 if(sIdleFallBack && !ctx->listStats[mDpy].secureUI) {
Saurabh Shah2d998a92013-05-14 17:55:58 -0700560 ALOGD_IF(isDebug(), "%s: Idle fallback dpy %d",__FUNCTION__, mDpy);
561 return false;
562 }
563
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800564 if(isSkipPresent(ctx, mDpy)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700565 ALOGD_IF(isDebug(),"%s: SKIP present: %d",
566 __FUNCTION__,
567 isSkipPresent(ctx, mDpy));
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800568 return false;
569 }
570
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800571 // check for action safe flag and downscale mode which requires scaling.
572 if(ctx->dpyAttr[mDpy].mActionSafePresent
573 || ctx->dpyAttr[mDpy].mDownScaleMode) {
574 ALOGD_IF(isDebug(), "%s: Scaling needed for this frame",__FUNCTION__);
575 return false;
576 }
577
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800578 for(int i = 0; i < numAppLayers; ++i) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800579 hwc_layer_1_t* layer = &list->hwLayers[i];
580 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800581
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700582 if(isYuvBuffer(hnd) && has90Transform(layer)) {
583 if(!canUseRotator(ctx, mDpy)) {
584 ALOGD_IF(isDebug(), "%s: Can't use rotator for dpy %d",
585 __FUNCTION__, mDpy);
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700586 return false;
587 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800588 }
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530589
590 //For 8x26 with panel width>1k, if RGB layer needs HFLIP fail mdp comp
591 // may not need it if Gfx pre-rotation can handle all flips & rotations
Sushil Chauhand8ef93f2014-03-20 11:08:41 -0700592 int transform = (layer->flags & HWC_COLOR_FILL) ? 0 : layer->transform;
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530593 if(qdutils::MDPVersion::getInstance().is8x26() &&
594 (ctx->dpyAttr[mDpy].xres > 1024) &&
Sushil Chauhand8ef93f2014-03-20 11:08:41 -0700595 (transform & HWC_TRANSFORM_FLIP_H) &&
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530596 (!isYuvBuffer(hnd)))
597 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800598 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700599
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700600 if(ctx->mAD->isDoable()) {
601 return false;
602 }
603
Saurabh Shahaa236822013-04-24 18:07:26 -0700604 //If all above hard conditions are met we can do full or partial MDP comp.
605 bool ret = false;
606 if(fullMDPComp(ctx, list)) {
607 ret = true;
Sushil Chauhan4259d872014-05-13 18:17:12 -0700608 } else if(fullMDPCompWithPTOR(ctx, list)) {
609 ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700610 } else if(partialMDPComp(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700611 ret = true;
612 }
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530613
Saurabh Shahaa236822013-04-24 18:07:26 -0700614 return ret;
615}
616
617bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700618 //Will benefit presentation / secondary-only layer.
619 if((mDpy > HWC_DISPLAY_PRIMARY) &&
620 (list->numHwLayers - 1) > MAX_SEC_LAYERS) {
621 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
622 return false;
623 }
624
625 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
626 for(int i = 0; i < numAppLayers; i++) {
627 hwc_layer_1_t* layer = &list->hwLayers[i];
628 if(not isSupportedForMDPComp(ctx, layer)) {
629 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",__FUNCTION__);
630 return false;
631 }
632 }
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800633
Saurabh Shahaa236822013-04-24 18:07:26 -0700634 mCurrentFrame.fbCount = 0;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700635 memcpy(&mCurrentFrame.isFBComposed, &mCurrentFrame.drop,
636 sizeof(mCurrentFrame.isFBComposed));
637 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount -
638 mCurrentFrame.dropCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700639
radhakrishnac9a67412013-09-25 17:40:42 +0530640 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800641 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530642 }
643
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800644 if(!postHeuristicsHandling(ctx, list)) {
645 ALOGD_IF(isDebug(), "post heuristic handling failed");
646 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700647 return false;
648 }
649
Saurabh Shahaa236822013-04-24 18:07:26 -0700650 return true;
651}
652
Sushil Chauhan4259d872014-05-13 18:17:12 -0700653/* Full MDP Composition with Peripheral Tiny Overlap Removal.
654 * MDP bandwidth limitations can be avoided, if the overlap region
655 * covered by the smallest layer at a higher z-order, gets composed
656 * by Copybit on a render buffer, which can be queued to MDP.
657 */
658bool MDPComp::fullMDPCompWithPTOR(hwc_context_t *ctx,
659 hwc_display_contents_1_t* list) {
660
661 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
662 const int stagesForMDP = min(sMaxPipesPerMixer,
663 ctx->mOverlay->availablePipes(mDpy, Overlay::MIXER_DEFAULT));
664
665 // Hard checks where we cannot use this mode
666 if (mDpy || !ctx->mCopyBit[mDpy] || isDisplaySplit(ctx, mDpy)) {
667 ALOGD_IF(isDebug(), "%s: Feature not supported!", __FUNCTION__);
668 return false;
669 }
670
671 // Frame level checks
672 if ((numAppLayers > stagesForMDP) || isSkipPresent(ctx, mDpy) ||
673 isYuvPresent(ctx, mDpy) || mCurrentFrame.dropCount ||
674 isSecurePresent(ctx, mDpy)) {
675 ALOGD_IF(isDebug(), "%s: Frame not supported!", __FUNCTION__);
676 return false;
677 }
678
679 // Find overlap index
680 int overlapIdx = numAppLayers - 1;
681 uint32_t layerPixelCount, minPixelCount = 0;
682 for (int i = numAppLayers - 1; i >= 0; i--) {
683 hwc_layer_1_t* layer = &list->hwLayers[i];
684 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
685 layerPixelCount = (crop.right - crop.left) * (crop.bottom - crop.top);
686 if (!minPixelCount || (layerPixelCount < minPixelCount)) {
687 minPixelCount = layerPixelCount;
688 overlapIdx = i;
689 }
690 }
691
692 // No overlap
693 if (!overlapIdx)
694 return false;
695
696 /* We cannot use this composition mode, if:
697 1. A below layer needs scaling.
698 2. Overlap is not peripheral to display.
699 3. Overlap or a below layer has 90 degree transform.
700 4. Intersection of Overlap layer with a below layer is not valid.
701 5. Overlap area > (1/3 * FrameBuffer) area, based on Perf inputs.
702 */
703
704 hwc_rect_t overlap = list->hwLayers[overlapIdx].displayFrame;
705 if (!isPeripheral(overlap, ctx->mViewFrame[mDpy]))
706 return false;
707
708 if ((3 * (overlap.right - overlap.left) * (overlap.bottom - overlap.top)) >
709 ((int)ctx->dpyAttr[mDpy].xres * (int)ctx->dpyAttr[mDpy].yres))
710 return false;
711
712 for (int i = overlapIdx; i >= 0; i--) {
713 hwc_layer_1_t* layer = &list->hwLayers[i];
714 hwc_rect_t dispFrame = layer->displayFrame;
715
716 if (has90Transform(layer))
717 return false;
718
719 if (i < overlapIdx) {
720 if (needsScaling(layer) ||
721 !isValidRect(getIntersection(dispFrame, overlap)))
722 return false;
723 }
724 }
725
726 mOverlapIndex = overlapIdx;
727 if (!ctx->mCopyBit[mDpy]->prepareOverlap(ctx, list, overlapIdx)) {
728 ALOGD_IF(isDebug(), "%s: Overlap prepare failed!",__FUNCTION__);
729 mOverlapIndex = -1;
730 return false;
731 }
732
733 hwc_rect_t sourceCrop[overlapIdx];
734 hwc_rect_t displayFrame[overlapIdx];
735
736 // Remove overlap from crop & displayFrame of below layers
737 for (int i = 0; i < overlapIdx; i++) {
738 hwc_layer_1_t* layer = &list->hwLayers[i];
739 displayFrame[i] = layer->displayFrame;
740 sourceCrop[i] = integerizeSourceCrop(layer->sourceCropf);
741
742 // Update layer attributes
743 hwc_rect_t srcCrop = integerizeSourceCrop(layer->sourceCropf);
744 hwc_rect_t destRect = deductRect(layer->displayFrame, overlap);
745 qhwc::calculate_crop_rects(srcCrop, layer->displayFrame, destRect,
746 layer->transform);
747
748 layer->sourceCropf.left = (float)srcCrop.left;
749 layer->sourceCropf.top = (float)srcCrop.top;
750 layer->sourceCropf.right = (float)srcCrop.right;
751 layer->sourceCropf.bottom = (float)srcCrop.bottom;
752 }
753
754 mCurrentFrame.mdpCount = numAppLayers;
755 mCurrentFrame.fbCount = 0;
756 mCurrentFrame.fbZ = -1;
757
758 for (int j = 0; j < numAppLayers; j++)
759 mCurrentFrame.isFBComposed[j] = false;
760
761 bool result = postHeuristicsHandling(ctx, list);
762
763 // Restore layer attributes
764 for (int i = 0; i < overlapIdx; i++) {
765 hwc_layer_1_t* layer = &list->hwLayers[i];
766 layer->displayFrame = displayFrame[i];
767 layer->sourceCropf.left = (float)sourceCrop[i].left;
768 layer->sourceCropf.top = (float)sourceCrop[i].top;
769 layer->sourceCropf.right = (float)sourceCrop[i].right;
770 layer->sourceCropf.bottom = (float)sourceCrop[i].bottom;
771 }
772
773 if (!result) {
774 mOverlapIndex = -1;
775 reset(ctx);
776 }
777
778 ALOGD_IF(isDebug(), "%s: Postheuristics %s!, Overlap index = %d",
779 __FUNCTION__, (result ? "successful" : "failed"), mOverlapIndex);
780 return result;
781}
782
Saurabh Shahaa236822013-04-24 18:07:26 -0700783bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
784{
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700785 if(!sEnableMixedMode) {
786 //Mixed mode is disabled. No need to even try caching.
787 return false;
788 }
789
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700790 bool ret = false;
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800791 if(list->flags & HWC_GEOMETRY_CHANGED) { //Try load based first
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800792 ret = loadBasedComp(ctx, list) or
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800793 cacheBasedComp(ctx, list);
794 } else {
795 ret = cacheBasedComp(ctx, list) or
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800796 loadBasedComp(ctx, list);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700797 }
798
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700799 return ret;
800}
801
802bool MDPComp::cacheBasedComp(hwc_context_t *ctx,
803 hwc_display_contents_1_t* list) {
804 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700805 mCurrentFrame.reset(numAppLayers);
806 updateLayerCache(ctx, list);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700807
808 //If an MDP marked layer is unsupported cannot do partial MDP Comp
809 for(int i = 0; i < numAppLayers; i++) {
810 if(!mCurrentFrame.isFBComposed[i]) {
811 hwc_layer_1_t* layer = &list->hwLayers[i];
812 if(not isSupportedForMDPComp(ctx, layer)) {
813 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",
814 __FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800815 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700816 return false;
817 }
818 }
819 }
820
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700821 updateYUV(ctx, list, false /*secure only*/);
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530822 bool ret = markLayersForCaching(ctx, list); //sets up fbZ also
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700823 if(!ret) {
824 ALOGD_IF(isDebug(),"%s: batching failed, dpy %d",__FUNCTION__, mDpy);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800825 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700826 return false;
827 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700828
829 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700830
radhakrishnac9a67412013-09-25 17:40:42 +0530831 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800832 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530833 }
834
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700835 //Will benefit cases where a video has non-updating background.
836 if((mDpy > HWC_DISPLAY_PRIMARY) and
837 (mdpCount > MAX_SEC_LAYERS)) {
838 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800839 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700840 return false;
841 }
842
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800843 if(!postHeuristicsHandling(ctx, list)) {
844 ALOGD_IF(isDebug(), "post heuristic handling failed");
845 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700846 return false;
847 }
848
Saurabh Shahaa236822013-04-24 18:07:26 -0700849 return true;
850}
851
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800852bool MDPComp::loadBasedComp(hwc_context_t *ctx,
Saurabh Shahb772ae32013-11-18 15:40:02 -0800853 hwc_display_contents_1_t* list) {
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800854 if(not isLoadBasedCompDoable(ctx, list)) {
855 return false;
856 }
857
Saurabh Shahb772ae32013-11-18 15:40:02 -0800858 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800859 const int numNonDroppedLayers = numAppLayers - mCurrentFrame.dropCount;
860 const int stagesForMDP = min(sMaxPipesPerMixer,
861 ctx->mOverlay->availablePipes(mDpy, Overlay::MIXER_DEFAULT));
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800862
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800863 int mdpBatchSize = stagesForMDP - 1; //1 stage for FB
864 int fbBatchSize = numNonDroppedLayers - mdpBatchSize;
865 int lastMDPSupportedIndex = numAppLayers;
866 int dropCount = 0;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800867
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800868 //Find the minimum MDP batch size
869 for(int i = 0; i < numAppLayers;i++) {
870 if(mCurrentFrame.drop[i]) {
871 dropCount++;
Jeykumar Sankaran6279bc32014-01-23 21:59:58 -0800872 continue;
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800873 }
874 hwc_layer_1_t* layer = &list->hwLayers[i];
875 if(not isSupportedForMDPComp(ctx, layer)) {
876 lastMDPSupportedIndex = i;
877 mdpBatchSize = min(i - dropCount, stagesForMDP - 1);
878 fbBatchSize = numNonDroppedLayers - mdpBatchSize;
Jeykumar Sankaran6279bc32014-01-23 21:59:58 -0800879 break;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800880 }
Saurabh Shahb772ae32013-11-18 15:40:02 -0800881 }
882
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800883 ALOGD_IF(isDebug(), "%s:Before optimizing fbBatch, mdpbatch %d, fbbatch %d "
884 "dropped %d", __FUNCTION__, mdpBatchSize, fbBatchSize,
885 mCurrentFrame.dropCount);
886
887 //Start at a point where the fb batch should at least have 2 layers, for
888 //this mode to be justified.
889 while(fbBatchSize < 2) {
890 ++fbBatchSize;
891 --mdpBatchSize;
Jeykumar Sankaran6279bc32014-01-23 21:59:58 -0800892 }
Saurabh Shahb772ae32013-11-18 15:40:02 -0800893
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800894 //If there are no layers for MDP, this mode doesnt make sense.
895 if(mdpBatchSize < 1) {
896 ALOGD_IF(isDebug(), "%s: No MDP layers after optimizing for fbBatch",
897 __FUNCTION__);
Saurabh Shahb772ae32013-11-18 15:40:02 -0800898 return false;
899 }
900
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800901 mCurrentFrame.reset(numAppLayers);
902
903 //Try with successively smaller mdp batch sizes until we succeed or reach 1
904 while(mdpBatchSize > 0) {
905 //Mark layers for MDP comp
906 int mdpBatchLeft = mdpBatchSize;
907 for(int i = 0; i < lastMDPSupportedIndex and mdpBatchLeft; i++) {
908 if(mCurrentFrame.drop[i]) {
909 continue;
910 }
911 mCurrentFrame.isFBComposed[i] = false;
912 --mdpBatchLeft;
913 }
914
915 mCurrentFrame.fbZ = mdpBatchSize;
916 mCurrentFrame.fbCount = fbBatchSize;
917 mCurrentFrame.mdpCount = mdpBatchSize;
918
919 ALOGD_IF(isDebug(), "%s:Trying with: mdpbatch %d fbbatch %d dropped %d",
920 __FUNCTION__, mdpBatchSize, fbBatchSize,
921 mCurrentFrame.dropCount);
922
923 if(postHeuristicsHandling(ctx, list)) {
924 ALOGD_IF(isDebug(), "%s: Postheuristics handling succeeded",
925 __FUNCTION__);
926 return true;
927 }
928
929 reset(ctx);
930 --mdpBatchSize;
931 ++fbBatchSize;
932 }
933
934 return false;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800935}
936
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700937bool MDPComp::isLoadBasedCompDoable(hwc_context_t *ctx,
938 hwc_display_contents_1_t* list) {
Prabhanjan Kandula3dbbd882013-12-11 14:43:46 +0530939 if(mDpy or isSecurePresent(ctx, mDpy) or
940 isYuvPresent(ctx, mDpy)) {
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700941 return false;
942 }
943 return true;
944}
945
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800946bool MDPComp::tryVideoOnly(hwc_context_t *ctx,
947 hwc_display_contents_1_t* list) {
948 const bool secureOnly = true;
949 return videoOnlyComp(ctx, list, not secureOnly) or
950 videoOnlyComp(ctx, list, secureOnly);
951}
952
953bool MDPComp::videoOnlyComp(hwc_context_t *ctx,
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700954 hwc_display_contents_1_t* list, bool secureOnly) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700955 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700956
Saurabh Shahaa236822013-04-24 18:07:26 -0700957 mCurrentFrame.reset(numAppLayers);
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700958 updateYUV(ctx, list, secureOnly);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700959 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700960
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800961 if(!isYuvPresent(ctx, mDpy) or (mdpCount == 0)) {
962 reset(ctx);
Saurabh Shahaa236822013-04-24 18:07:26 -0700963 return false;
964 }
965
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -0800966 /* Bail out if we are processing only secured video layers
967 * and we dont have any */
968 if(!isSecurePresent(ctx, mDpy) && secureOnly){
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800969 reset(ctx);
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -0800970 return false;
971 }
972
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800973 if(mCurrentFrame.fbCount)
974 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
Saurabh Shah4fdde762013-04-30 18:47:33 -0700975
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800976 if(sEnable4k2kYUVSplit){
977 adjustForSourceSplit(ctx, list);
978 }
979
980 if(!postHeuristicsHandling(ctx, list)) {
981 ALOGD_IF(isDebug(), "post heuristic handling failed");
982 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700983 return false;
984 }
985
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800986 return true;
987}
988
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800989/* Checks for conditions where YUV layers cannot be bypassed */
990bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -0700991 if(isSkipLayer(layer)) {
Saurabh Shahe2474082013-05-15 16:32:13 -0700992 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800993 return false;
994 }
995
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700996 if(layer->transform & HWC_TRANSFORM_ROT_90 && !canUseRotator(ctx,mDpy)) {
997 ALOGD_IF(isDebug(), "%s: no free DMA pipe",__FUNCTION__);
998 return false;
999 }
1000
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001001 if(isSecuring(ctx, layer)) {
1002 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
1003 return false;
1004 }
1005
Saurabh Shah4fdde762013-04-30 18:47:33 -07001006 if(!isValidDimension(ctx, layer)) {
1007 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
1008 __FUNCTION__);
1009 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001010 }
Saurabh Shah4fdde762013-04-30 18:47:33 -07001011
Naseer Ahmeddc61a972013-07-10 17:50:54 -04001012 if(layer->planeAlpha < 0xFF) {
1013 ALOGD_IF(isDebug(), "%s: Cannot handle YUV layer with plane alpha\
1014 in video only mode",
1015 __FUNCTION__);
1016 return false;
1017 }
1018
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001019 return true;
1020}
1021
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301022/* starts at fromIndex and check for each layer to find
1023 * if it it has overlapping with any Updating layer above it in zorder
1024 * till the end of the batch. returns true if it finds any intersection */
1025bool MDPComp::canPushBatchToTop(const hwc_display_contents_1_t* list,
1026 int fromIndex, int toIndex) {
1027 for(int i = fromIndex; i < toIndex; i++) {
1028 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
1029 if(intersectingUpdatingLayers(list, i+1, toIndex, i)) {
1030 return false;
1031 }
1032 }
1033 }
1034 return true;
1035}
1036
1037/* Checks if given layer at targetLayerIndex has any
1038 * intersection with all the updating layers in beween
1039 * fromIndex and toIndex. Returns true if it finds intersectiion */
1040bool MDPComp::intersectingUpdatingLayers(const hwc_display_contents_1_t* list,
1041 int fromIndex, int toIndex, int targetLayerIndex) {
1042 for(int i = fromIndex; i <= toIndex; i++) {
1043 if(!mCurrentFrame.isFBComposed[i]) {
1044 if(areLayersIntersecting(&list->hwLayers[i],
1045 &list->hwLayers[targetLayerIndex])) {
1046 return true;
1047 }
1048 }
1049 }
1050 return false;
1051}
1052
1053int MDPComp::getBatch(hwc_display_contents_1_t* list,
1054 int& maxBatchStart, int& maxBatchEnd,
1055 int& maxBatchCount) {
1056 int i = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301057 int fbZOrder =-1;
Jeykumar Sankaran5a495da2014-01-20 12:25:32 -08001058 int droppedLayerCt = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301059 while (i < mCurrentFrame.layerCount) {
1060 int batchCount = 0;
1061 int batchStart = i;
1062 int batchEnd = i;
Jeykumar Sankaran5a495da2014-01-20 12:25:32 -08001063 /* Adjust batch Z order with the dropped layers so far */
1064 int fbZ = batchStart - droppedLayerCt;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301065 int firstZReverseIndex = -1;
Prabhanjan Kandula0ed2cc92013-12-06 12:39:04 +05301066 int updatingLayersAbove = 0;//Updating layer count in middle of batch
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301067 while(i < mCurrentFrame.layerCount) {
1068 if(!mCurrentFrame.isFBComposed[i]) {
1069 if(!batchCount) {
1070 i++;
1071 break;
1072 }
1073 updatingLayersAbove++;
1074 i++;
1075 continue;
1076 } else {
1077 if(mCurrentFrame.drop[i]) {
1078 i++;
Jeykumar Sankaran5a495da2014-01-20 12:25:32 -08001079 droppedLayerCt++;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301080 continue;
1081 } else if(updatingLayersAbove <= 0) {
1082 batchCount++;
1083 batchEnd = i;
1084 i++;
1085 continue;
1086 } else { //Layer is FBComposed, not a drop & updatingLayer > 0
1087
1088 // We have a valid updating layer already. If layer-i not
1089 // have overlapping with all updating layers in between
1090 // batch-start and i, then we can add layer i to batch.
1091 if(!intersectingUpdatingLayers(list, batchStart, i-1, i)) {
1092 batchCount++;
1093 batchEnd = i;
1094 i++;
1095 continue;
1096 } else if(canPushBatchToTop(list, batchStart, i)) {
1097 //If All the non-updating layers with in this batch
1098 //does not have intersection with the updating layers
1099 //above in z-order, then we can safely move the batch to
1100 //higher z-order. Increment fbZ as it is moving up.
1101 if( firstZReverseIndex < 0) {
1102 firstZReverseIndex = i;
1103 }
1104 batchCount++;
1105 batchEnd = i;
1106 fbZ += updatingLayersAbove;
1107 i++;
1108 updatingLayersAbove = 0;
1109 continue;
1110 } else {
1111 //both failed.start the loop again from here.
1112 if(firstZReverseIndex >= 0) {
1113 i = firstZReverseIndex;
1114 }
1115 break;
1116 }
1117 }
1118 }
1119 }
1120 if(batchCount > maxBatchCount) {
1121 maxBatchCount = batchCount;
1122 maxBatchStart = batchStart;
1123 maxBatchEnd = batchEnd;
1124 fbZOrder = fbZ;
1125 }
1126 }
1127 return fbZOrder;
1128}
1129
1130bool MDPComp::markLayersForCaching(hwc_context_t* ctx,
1131 hwc_display_contents_1_t* list) {
1132 /* Idea is to keep as many non-updating(cached) layers in FB and
1133 * send rest of them through MDP. This is done in 2 steps.
1134 * 1. Find the maximum contiguous batch of non-updating layers.
1135 * 2. See if we can improve this batch size for caching by adding
1136 * opaque layers around the batch, if they don't have
1137 * any overlapping with the updating layers in between.
1138 * NEVER mark an updating layer for caching.
1139 * But cached ones can be marked for MDP */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001140
1141 int maxBatchStart = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001142 int maxBatchEnd = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001143 int maxBatchCount = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301144 int fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001145
Saurabh Shahce188452014-02-05 10:17:43 -08001146 /* Nothing is cached. No batching needed */
1147 if(mCurrentFrame.fbCount == 0) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001148 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -07001149 }
Saurabh Shahce188452014-02-05 10:17:43 -08001150
1151 /* No MDP comp layers, try to use other comp modes */
1152 if(mCurrentFrame.mdpCount == 0) {
1153 return false;
Saurabh Shahaa236822013-04-24 18:07:26 -07001154 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001155
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301156 fbZ = getBatch(list, maxBatchStart, maxBatchEnd, maxBatchCount);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001157
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301158 /* reset rest of the layers lying inside ROI for MDP comp */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001159 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001160 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001161 if((i < maxBatchStart || i > maxBatchEnd) &&
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301162 mCurrentFrame.isFBComposed[i]){
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001163 if(!mCurrentFrame.drop[i]){
1164 //If an unsupported layer is being attempted to
1165 //be pulled out we should fail
1166 if(not isSupportedForMDPComp(ctx, layer)) {
1167 return false;
1168 }
1169 mCurrentFrame.isFBComposed[i] = false;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001170 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001171 }
1172 }
1173
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301174 // update the frame data
1175 mCurrentFrame.fbZ = fbZ;
1176 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001177 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001178 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001179
1180 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301181 mCurrentFrame.fbCount);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001182
1183 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001184}
Saurabh Shah85234ec2013-04-12 17:09:00 -07001185
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001186void MDPComp::updateLayerCache(hwc_context_t* ctx,
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001187 hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001188 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001189 int fbCount = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001190
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001191 for(int i = 0; i < numAppLayers; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001192 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001193 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001194 if(!mCurrentFrame.drop[i])
1195 fbCount++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001196 mCurrentFrame.isFBComposed[i] = true;
1197 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -07001198 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001199 }
1200 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001201
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001202 mCurrentFrame.fbCount = fbCount;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001203 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount
1204 - mCurrentFrame.dropCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001205
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001206 ALOGD_IF(isDebug(),"%s: MDP count: %d FB count %d drop count: %d"
1207 ,__FUNCTION__, mCurrentFrame.mdpCount, mCurrentFrame.fbCount,
1208 mCurrentFrame.dropCount);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001209}
1210
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001211void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list,
1212 bool secureOnly) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001213 int nYuvCount = ctx->listStats[mDpy].yuvCount;
1214 for(int index = 0;index < nYuvCount; index++){
1215 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
1216 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
1217
1218 if(!isYUVDoable(ctx, layer)) {
1219 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
1220 mCurrentFrame.isFBComposed[nYuvIndex] = true;
1221 mCurrentFrame.fbCount++;
1222 }
1223 } else {
1224 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001225 private_handle_t *hnd = (private_handle_t *)layer->handle;
1226 if(!secureOnly || isSecureBuffer(hnd)) {
1227 mCurrentFrame.isFBComposed[nYuvIndex] = false;
1228 mCurrentFrame.fbCount--;
1229 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001230 }
1231 }
1232 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001233
1234 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001235 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
1236 ALOGD_IF(isDebug(),"%s: fb count: %d",__FUNCTION__,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001237 mCurrentFrame.fbCount);
1238}
1239
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001240bool MDPComp::postHeuristicsHandling(hwc_context_t *ctx,
1241 hwc_display_contents_1_t* list) {
1242
1243 //Capability checks
1244 if(!resourceCheck(ctx, list)) {
1245 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
1246 return false;
1247 }
1248
1249 //Limitations checks
1250 if(!hwLimitationsCheck(ctx, list)) {
1251 ALOGD_IF(isDebug(), "%s: HW limitations",__FUNCTION__);
1252 return false;
1253 }
1254
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001255 //Configure framebuffer first if applicable
1256 if(mCurrentFrame.fbZ >= 0) {
1257 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, mCurrentFrame.fbZ)) {
1258 ALOGD_IF(isDebug(), "%s configure framebuffer failed",
1259 __FUNCTION__);
1260 return false;
1261 }
1262 }
1263
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001264 mCurrentFrame.map();
1265
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001266 if(!allocLayerPipes(ctx, list)) {
1267 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -07001268 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001269 }
1270
1271 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001272 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001273 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001274 int mdpIndex = mCurrentFrame.layerToMDP[index];
1275 hwc_layer_1_t* layer = &list->hwLayers[index];
1276
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301277 //Leave fbZ for framebuffer. CACHE/GLES layers go here.
1278 if(mdpNextZOrder == mCurrentFrame.fbZ) {
1279 mdpNextZOrder++;
1280 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001281 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1282 cur_pipe->zOrder = mdpNextZOrder++;
1283
radhakrishnac9a67412013-09-25 17:40:42 +05301284 private_handle_t *hnd = (private_handle_t *)layer->handle;
1285 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1286 if(configure4k2kYuv(ctx, layer,
1287 mCurrentFrame.mdpToLayer[mdpIndex])
1288 != 0 ){
1289 ALOGD_IF(isDebug(), "%s: Failed to configure split pipes \
1290 for layer %d",__FUNCTION__, index);
1291 return false;
1292 }
1293 else{
1294 mdpNextZOrder++;
1295 }
1296 continue;
1297 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001298 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
1299 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
radhakrishnac9a67412013-09-25 17:40:42 +05301300 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -07001301 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001302 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001303 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001304 }
1305
Saurabh Shah450ac972013-12-16 18:18:39 -08001306 if(!ctx->mOverlay->validateAndSet(mDpy, ctx->dpyAttr[mDpy].fd)) {
1307 ALOGD_IF(isDebug(), "%s: Failed to validate and set overlay for dpy %d"
1308 ,__FUNCTION__, mDpy);
1309 return false;
1310 }
1311
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001312 setRedraw(ctx, list);
Saurabh Shahaa236822013-04-24 18:07:26 -07001313 return true;
1314}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001315
Saurabh Shah173f4242013-11-20 09:50:12 -08001316bool MDPComp::resourceCheck(hwc_context_t *ctx,
1317 hwc_display_contents_1_t *list) {
1318 const bool fbUsed = mCurrentFrame.fbCount;
1319 if(mCurrentFrame.mdpCount > sMaxPipesPerMixer - fbUsed) {
1320 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
1321 return false;
1322 }
Saurabh Shah173f4242013-11-20 09:50:12 -08001323 return true;
1324}
1325
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301326bool MDPComp::hwLimitationsCheck(hwc_context_t* ctx,
1327 hwc_display_contents_1_t* list) {
1328
1329 //A-family hw limitation:
1330 //If a layer need alpha scaling, MDP can not support.
1331 if(ctx->mMDP.version < qdutils::MDSS_V5) {
1332 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1333 if(!mCurrentFrame.isFBComposed[i] &&
1334 isAlphaScaled( &list->hwLayers[i])) {
1335 ALOGD_IF(isDebug(), "%s:frame needs alphaScaling",__FUNCTION__);
1336 return false;
1337 }
1338 }
1339 }
1340
1341 // On 8x26 & 8974 hw, we have a limitation of downscaling+blending.
1342 //If multiple layers requires downscaling and also they are overlapping
1343 //fall back to GPU since MDSS can not handle it.
1344 if(qdutils::MDPVersion::getInstance().is8x74v2() ||
1345 qdutils::MDPVersion::getInstance().is8x26()) {
1346 for(int i = 0; i < mCurrentFrame.layerCount-1; ++i) {
1347 hwc_layer_1_t* botLayer = &list->hwLayers[i];
1348 if(!mCurrentFrame.isFBComposed[i] &&
1349 isDownscaleRequired(botLayer)) {
1350 //if layer-i is marked for MDP and needs downscaling
1351 //check if any MDP layer on top of i & overlaps with layer-i
1352 for(int j = i+1; j < mCurrentFrame.layerCount; ++j) {
1353 hwc_layer_1_t* topLayer = &list->hwLayers[j];
1354 if(!mCurrentFrame.isFBComposed[j] &&
1355 isDownscaleRequired(topLayer)) {
1356 hwc_rect_t r = getIntersection(botLayer->displayFrame,
1357 topLayer->displayFrame);
1358 if(isValidRect(r))
1359 return false;
1360 }
1361 }
1362 }
1363 }
1364 }
1365 return true;
1366}
1367
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001368int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001369 int ret = 0;
Raj Kamal5166b312014-06-06 13:45:20 +05301370
1371 if(!ctx || !list) {
1372 ALOGE("%s: Invalid context or list",__FUNCTION__);
1373 mCachedFrame.reset();
1374 return -1;
1375 }
1376
Saurabh Shahaa236822013-04-24 18:07:26 -07001377 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001378 MDPVersion& mdpVersion = qdutils::MDPVersion::getInstance();
Sushil Chauhan4259d872014-05-13 18:17:12 -07001379 mOverlapIndex = -1;
Raj Kamalfc5b9222014-02-07 16:15:17 +05301380 //Do not cache the information for next draw cycle.
1381 if(numLayers > MAX_NUM_APP_LAYERS or (!numLayers)) {
1382 ALOGI("%s: Unsupported layer count for mdp composition",
1383 __FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001384 mCachedFrame.reset();
1385 return -1;
1386 }
1387
Saurabh Shahb39f8152013-08-22 10:21:44 -07001388 //reset old data
1389 mCurrentFrame.reset(numLayers);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001390 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1391 mCurrentFrame.dropCount = 0;
Prabhanjan Kandula088bd892013-07-02 23:47:13 +05301392
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -07001393 // Detect the start of animation and fall back to GPU only once to cache
1394 // all the layers in FB and display FB content untill animation completes.
1395 if(ctx->listStats[mDpy].isDisplayAnimating) {
1396 mCurrentFrame.needsRedraw = false;
1397 if(ctx->mAnimationState[mDpy] == ANIMATION_STOPPED) {
1398 mCurrentFrame.needsRedraw = true;
1399 ctx->mAnimationState[mDpy] = ANIMATION_STARTED;
1400 }
1401 setMDPCompLayerFlags(ctx, list);
1402 mCachedFrame.updateCounts(mCurrentFrame);
1403 ret = -1;
1404 return ret;
1405 } else {
1406 ctx->mAnimationState[mDpy] = ANIMATION_STOPPED;
1407 }
1408
Saurabh Shahb39f8152013-08-22 10:21:44 -07001409 //Hard conditions, if not met, cannot do MDP comp
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001410 if(isFrameDoable(ctx)) {
1411 generateROI(ctx, list);
Saurabh Shahb39f8152013-08-22 10:21:44 -07001412
Raj Kamal5166b312014-06-06 13:45:20 +05301413 mModeOn = tryFullFrame(ctx, list) || tryVideoOnly(ctx, list);
1414 if(mModeOn) {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001415 setMDPCompLayerFlags(ctx, list);
1416 } else {
1417 reset(ctx);
1418 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1419 mCurrentFrame.dropCount = 0;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001420 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001421 }
1422 } else {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001423 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
1424 __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001425 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001426 }
Saurabh Shahb39f8152013-08-22 10:21:44 -07001427
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001428 if(isDebug()) {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001429 ALOGD("GEOMETRY change: %d",
1430 (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001431 android::String8 sDump("");
1432 dump(sDump);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001433 ALOGD("%s",sDump.string());
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001434 }
1435
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001436 mCachedFrame.cacheAll(list);
1437 mCachedFrame.updateCounts(mCurrentFrame);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001438 return ret;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001439}
1440
radhakrishnac9a67412013-09-25 17:40:42 +05301441bool MDPComp::allocSplitVGPipesfor4k2k(hwc_context_t *ctx,
1442 hwc_display_contents_1_t* list, int index) {
1443
1444 bool bRet = true;
1445 hwc_layer_1_t* layer = &list->hwLayers[index];
1446 private_handle_t *hnd = (private_handle_t *)layer->handle;
1447 int mdpIndex = mCurrentFrame.layerToMDP[index];
1448 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
1449 info.pipeInfo = new MdpYUVPipeInfo;
1450 info.rot = NULL;
1451 MdpYUVPipeInfo& pipe_info = *(MdpYUVPipeInfo*)info.pipeInfo;
1452 ePipeType type = MDPCOMP_OV_VG;
1453
1454 pipe_info.lIndex = ovutils::OV_INVALID;
1455 pipe_info.rIndex = ovutils::OV_INVALID;
1456
1457 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
1458 if(pipe_info.lIndex == ovutils::OV_INVALID){
1459 bRet = false;
1460 ALOGD_IF(isDebug(),"%s: allocating first VG pipe failed",
1461 __FUNCTION__);
1462 }
1463 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
1464 if(pipe_info.rIndex == ovutils::OV_INVALID){
1465 bRet = false;
1466 ALOGD_IF(isDebug(),"%s: allocating second VG pipe failed",
1467 __FUNCTION__);
1468 }
1469 return bRet;
1470}
Sushil Chauhan4259d872014-05-13 18:17:12 -07001471
1472int MDPComp::drawOverlap(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
1473 int fd = -1;
1474 if (mOverlapIndex != -1) {
1475 fd = ctx->mCopyBit[mDpy]->drawOverlap(ctx, list, mOverlapIndex);
1476 if (fd < 0) {
1477 ALOGD_IF(isDebug(),"%s: failed", __FUNCTION__);
1478 mOverlapIndex = -1;
1479 }
1480 }
1481 return fd;
1482}
1483
Saurabh Shah88e4d272013-09-03 13:31:29 -07001484//=============MDPCompNonSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001485
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001486void MDPCompNonSplit::adjustForSourceSplit(hwc_context_t *ctx,
radhakrishnac9a67412013-09-25 17:40:42 +05301487 hwc_display_contents_1_t* list){
1488 //As we split 4kx2k yuv layer and program to 2 VG pipes
1489 //(if available) increase mdpcount accordingly
1490 mCurrentFrame.mdpCount += ctx->listStats[mDpy].yuv4k2kCount;
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001491
1492 //If 4k2k Yuv layer split is possible, and if
1493 //fbz is above 4k2k layer, increment fb zorder by 1
1494 //as we split 4k2k layer and increment zorder for right half
1495 //of the layer
1496 if(mCurrentFrame.fbZ >= 0) {
Dileep Kumar Reddi2268dd72014-05-22 22:24:53 +05301497 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
1498 index++) {
1499 if(!mCurrentFrame.isFBComposed[index]) {
1500 if(mdpNextZOrder == mCurrentFrame.fbZ) {
1501 mdpNextZOrder++;
1502 }
1503 mdpNextZOrder++;
1504 hwc_layer_1_t* layer = &list->hwLayers[index];
1505 private_handle_t *hnd = (private_handle_t *)layer->handle;
1506 if(is4kx2kYuvBuffer(hnd)) {
1507 if(mdpNextZOrder <= mCurrentFrame.fbZ)
1508 mCurrentFrame.fbZ += 1;
1509 mdpNextZOrder++;
1510 //As we split 4kx2k yuv layer and program to 2 VG pipes
1511 //(if available) increase mdpcount by 1.
1512 mCurrentFrame.mdpCount++;
1513 }
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001514 }
1515 }
1516 }
radhakrishnac9a67412013-09-25 17:40:42 +05301517}
1518
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001519/*
1520 * Configures pipe(s) for MDP composition
1521 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001522int MDPCompNonSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001523 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001524 MdpPipeInfoNonSplit& mdp_info =
1525 *(static_cast<MdpPipeInfoNonSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001526 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
1527 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1528 eIsFg isFg = IS_FG_OFF;
1529 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001530
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001531 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
1532 __FUNCTION__, layer, zOrder, dest);
1533
Saurabh Shah88e4d272013-09-03 13:31:29 -07001534 return configureNonSplit(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001535 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001536}
1537
Saurabh Shah88e4d272013-09-03 13:31:29 -07001538bool MDPCompNonSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001539 hwc_display_contents_1_t* list) {
1540 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001541
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001542 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001543
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001544 hwc_layer_1_t* layer = &list->hwLayers[index];
1545 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301546 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1547 if(allocSplitVGPipesfor4k2k(ctx, list, index)){
1548 continue;
1549 }
1550 }
1551
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001552 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001553 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001554 info.pipeInfo = new MdpPipeInfoNonSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08001555 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001556 MdpPipeInfoNonSplit& pipe_info = *(MdpPipeInfoNonSplit*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001557 ePipeType type = MDPCOMP_OV_ANY;
1558
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001559 if(isYuvBuffer(hnd)) {
1560 type = MDPCOMP_OV_VG;
Prabhanjan Kandula5b8913e2014-01-22 23:01:45 +05301561 } else if(qdutils::MDPVersion::getInstance().is8x26() &&
1562 (ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres > 1024)) {
1563 if(qhwc::needsScaling(layer))
1564 type = MDPCOMP_OV_RGB;
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301565 } else if(!qhwc::needsScaling(layer)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001566 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
1567 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001568 type = MDPCOMP_OV_DMA;
1569 }
1570
Xu Yang5c2b3af2014-04-08 13:56:47 +08001571 // for 8x26, never allow primary display occupy DMA pipe
1572 // when external display is connected
1573 if(qdutils::MDPVersion::getInstance().is8x26()
1574 && ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isActive
1575 && ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected
1576 && !ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isPause
1577 && mDpy == HWC_DISPLAY_PRIMARY
1578 && type == MDPCOMP_OV_DMA) {
1579 type = MDPCOMP_OV_RGB;
1580 }
1581
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001582 pipe_info.index = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001583 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001584 ALOGD_IF(isDebug(), "%s: Unable to get pipe type = %d",
1585 __FUNCTION__, (int) type);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001586 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001587 }
1588 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001589 return true;
1590}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001591
radhakrishnac9a67412013-09-25 17:40:42 +05301592int MDPCompNonSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1593 PipeLayerPair& PipeLayerPair) {
1594 MdpYUVPipeInfo& mdp_info =
1595 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1596 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1597 eIsFg isFg = IS_FG_OFF;
1598 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1599 eDest lDest = mdp_info.lIndex;
1600 eDest rDest = mdp_info.rIndex;
1601
1602 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1603 lDest, rDest, &PipeLayerPair.rot);
1604}
1605
Saurabh Shah88e4d272013-09-03 13:31:29 -07001606bool MDPCompNonSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001607
Raj Kamal5166b312014-06-06 13:45:20 +05301608 if(!isEnabled() or !mModeOn) {
1609 ALOGD_IF(isDebug(),"%s: MDP Comp not enabled/configured", __FUNCTION__);
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301610 return true;
1611 }
1612
Ramkumar Radhakrishnand8595ae2014-02-06 21:31:29 -08001613 // Set the Handle timeout to true for MDP or MIXED composition.
1614 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount) {
1615 sHandleTimeout = true;
1616 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001617
1618 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001619 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001620
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001621 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1622 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001623 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001624 if(mCurrentFrame.isFBComposed[i]) continue;
1625
Naseer Ahmed5b6708a2012-08-02 13:46:08 -07001626 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001627 private_handle_t *hnd = (private_handle_t *)layer->handle;
1628 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001629 if (!(layer->flags & HWC_COLOR_FILL)) {
1630 ALOGE("%s handle null", __FUNCTION__);
1631 return false;
1632 }
1633 // No PLAY for Color layer
1634 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1635 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001636 }
1637
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001638 int mdpIndex = mCurrentFrame.layerToMDP[i];
1639
radhakrishnac9a67412013-09-25 17:40:42 +05301640 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1641 {
1642 MdpYUVPipeInfo& pipe_info =
1643 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1644 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1645 ovutils::eDest indexL = pipe_info.lIndex;
1646 ovutils::eDest indexR = pipe_info.rIndex;
1647 int fd = hnd->fd;
1648 uint32_t offset = hnd->offset;
1649 if(rot) {
1650 rot->queueBuffer(fd, offset);
1651 fd = rot->getDstMemId();
1652 offset = rot->getDstOffset();
1653 }
1654 if(indexL != ovutils::OV_INVALID) {
1655 ovutils::eDest destL = (ovutils::eDest)indexL;
1656 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1657 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1658 if (!ov.queueBuffer(fd, offset, destL)) {
1659 ALOGE("%s: queueBuffer failed for display:%d",
1660 __FUNCTION__, mDpy);
1661 return false;
1662 }
1663 }
1664
1665 if(indexR != ovutils::OV_INVALID) {
1666 ovutils::eDest destR = (ovutils::eDest)indexR;
1667 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1668 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1669 if (!ov.queueBuffer(fd, offset, destR)) {
1670 ALOGE("%s: queueBuffer failed for display:%d",
1671 __FUNCTION__, mDpy);
1672 return false;
1673 }
1674 }
1675 }
1676 else{
1677 MdpPipeInfoNonSplit& pipe_info =
Saurabh Shah88e4d272013-09-03 13:31:29 -07001678 *(MdpPipeInfoNonSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
radhakrishnac9a67412013-09-25 17:40:42 +05301679 ovutils::eDest dest = pipe_info.index;
1680 if(dest == ovutils::OV_INVALID) {
1681 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001682 return false;
radhakrishnac9a67412013-09-25 17:40:42 +05301683 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001684
radhakrishnac9a67412013-09-25 17:40:42 +05301685 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1686 continue;
1687 }
1688
Sushil Chauhan4259d872014-05-13 18:17:12 -07001689 if (!mDpy && (i == mOverlapIndex)) {
1690 hnd = ctx->mCopyBit[mDpy]->getCurrentRenderBuffer();
1691 }
1692
radhakrishnac9a67412013-09-25 17:40:42 +05301693 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1694 using pipe: %d", __FUNCTION__, layer,
1695 hnd, dest );
1696
1697 int fd = hnd->fd;
1698 uint32_t offset = hnd->offset;
1699
1700 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1701 if(rot) {
1702 if(!rot->queueBuffer(fd, offset))
1703 return false;
1704 fd = rot->getDstMemId();
1705 offset = rot->getDstOffset();
1706 }
1707
1708 if (!ov.queueBuffer(fd, offset, dest)) {
1709 ALOGE("%s: queueBuffer failed for display:%d ",
1710 __FUNCTION__, mDpy);
1711 return false;
1712 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001713 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001714
1715 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001716 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001717 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001718}
1719
Saurabh Shah88e4d272013-09-03 13:31:29 -07001720//=============MDPCompSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001721
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001722void MDPCompSplit::adjustForSourceSplit(hwc_context_t *ctx,
radhakrishnac9a67412013-09-25 17:40:42 +05301723 hwc_display_contents_1_t* list){
1724 //if 4kx2k yuv layer is totally present in either in left half
1725 //or right half then try splitting the yuv layer to avoid decimation
radhakrishnac9a67412013-09-25 17:40:42 +05301726 const int lSplit = getLeftSplit(ctx, mDpy);
Dileep Kumar Reddi2268dd72014-05-22 22:24:53 +05301727 if(mCurrentFrame.fbZ >= 0) {
1728 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
1729 index++) {
1730 if(!mCurrentFrame.isFBComposed[index]) {
1731 if(mdpNextZOrder == mCurrentFrame.fbZ) {
1732 mdpNextZOrder++;
1733 }
1734 mdpNextZOrder++;
1735 hwc_layer_1_t* layer = &list->hwLayers[index];
1736 private_handle_t *hnd = (private_handle_t *)layer->handle;
1737 if(is4kx2kYuvBuffer(hnd)) {
1738 hwc_rect_t dst = layer->displayFrame;
1739 if((dst.left > lSplit) || (dst.right < lSplit)) {
1740 mCurrentFrame.mdpCount += 1;
1741 }
1742 if(mdpNextZOrder <= mCurrentFrame.fbZ)
1743 mCurrentFrame.fbZ += 1;
1744 mdpNextZOrder++;
1745 }
1746 }
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001747 }
radhakrishnac9a67412013-09-25 17:40:42 +05301748 }
1749}
1750
Saurabh Shah88e4d272013-09-03 13:31:29 -07001751bool MDPCompSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
1752 MdpPipeInfoSplit& pipe_info,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001753 ePipeType type) {
1754 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001755 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001756
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001757 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001758 pipe_info.lIndex = ovutils::OV_INVALID;
1759 pipe_info.rIndex = ovutils::OV_INVALID;
1760
1761 if (dst.left < lSplit) {
1762 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_LEFT);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001763 if(pipe_info.lIndex == ovutils::OV_INVALID)
1764 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001765 }
1766
1767 if(dst.right > lSplit) {
1768 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_RIGHT);
1769 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001770 return false;
1771 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001772
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001773 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001774}
1775
Saurabh Shah88e4d272013-09-03 13:31:29 -07001776bool MDPCompSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001777 hwc_display_contents_1_t* list) {
1778 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001779
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001780 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001781
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001782 hwc_layer_1_t* layer = &list->hwLayers[index];
1783 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301784 hwc_rect_t dst = layer->displayFrame;
1785 const int lSplit = getLeftSplit(ctx, mDpy);
1786 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1787 if((dst.left > lSplit)||(dst.right < lSplit)){
1788 if(allocSplitVGPipesfor4k2k(ctx, list, index)){
1789 continue;
1790 }
1791 }
1792 }
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001793 int mdpIndex = mCurrentFrame.layerToMDP[index];
1794 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001795 info.pipeInfo = new MdpPipeInfoSplit;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001796 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001797 MdpPipeInfoSplit& pipe_info = *(MdpPipeInfoSplit*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001798 ePipeType type = MDPCOMP_OV_ANY;
1799
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001800 if(isYuvBuffer(hnd)) {
1801 type = MDPCOMP_OV_VG;
Sushil Chauhan15a2ea62013-09-04 18:28:36 -07001802 } else if(!qhwc::needsScalingWithSplit(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001803 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001804 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001805 type = MDPCOMP_OV_DMA;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001806 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001807
1808 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001809 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type = %d",
1810 __FUNCTION__, (int) type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001811 return false;
1812 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001813 }
1814 return true;
1815}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001816
radhakrishnac9a67412013-09-25 17:40:42 +05301817int MDPCompSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1818 PipeLayerPair& PipeLayerPair) {
1819 const int lSplit = getLeftSplit(ctx, mDpy);
1820 hwc_rect_t dst = layer->displayFrame;
1821 if((dst.left > lSplit)||(dst.right < lSplit)){
1822 MdpYUVPipeInfo& mdp_info =
1823 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1824 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1825 eIsFg isFg = IS_FG_OFF;
1826 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1827 eDest lDest = mdp_info.lIndex;
1828 eDest rDest = mdp_info.rIndex;
1829
1830 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1831 lDest, rDest, &PipeLayerPair.rot);
1832 }
1833 else{
1834 return configure(ctx, layer, PipeLayerPair);
1835 }
1836}
1837
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001838/*
1839 * Configures pipe(s) for MDP composition
1840 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001841int MDPCompSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001842 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001843 MdpPipeInfoSplit& mdp_info =
1844 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001845 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1846 eIsFg isFg = IS_FG_OFF;
1847 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1848 eDest lDest = mdp_info.lIndex;
1849 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001850
1851 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1852 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1853
Saurabh Shah88e4d272013-09-03 13:31:29 -07001854 return configureSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001855 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001856}
1857
Saurabh Shah88e4d272013-09-03 13:31:29 -07001858bool MDPCompSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001859
Raj Kamal5166b312014-06-06 13:45:20 +05301860 if(!isEnabled() or !mModeOn) {
1861 ALOGD_IF(isDebug(),"%s: MDP Comp not enabled/configured", __FUNCTION__);
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301862 return true;
1863 }
1864
Ramkumar Radhakrishnand8595ae2014-02-06 21:31:29 -08001865 // Set the Handle timeout to true for MDP or MIXED composition.
1866 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount) {
1867 sHandleTimeout = true;
1868 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001869
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001870 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001871 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001872
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001873 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1874 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001875 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001876 if(mCurrentFrame.isFBComposed[i]) continue;
1877
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001878 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001879 private_handle_t *hnd = (private_handle_t *)layer->handle;
1880 if(!hnd) {
1881 ALOGE("%s handle null", __FUNCTION__);
1882 return false;
1883 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001884
1885 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1886 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001887 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001888
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001889 int mdpIndex = mCurrentFrame.layerToMDP[i];
1890
radhakrishnac9a67412013-09-25 17:40:42 +05301891 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1892 {
1893 MdpYUVPipeInfo& pipe_info =
1894 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1895 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1896 ovutils::eDest indexL = pipe_info.lIndex;
1897 ovutils::eDest indexR = pipe_info.rIndex;
1898 int fd = hnd->fd;
1899 uint32_t offset = hnd->offset;
1900 if(rot) {
1901 rot->queueBuffer(fd, offset);
1902 fd = rot->getDstMemId();
1903 offset = rot->getDstOffset();
1904 }
1905 if(indexL != ovutils::OV_INVALID) {
1906 ovutils::eDest destL = (ovutils::eDest)indexL;
1907 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1908 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1909 if (!ov.queueBuffer(fd, offset, destL)) {
1910 ALOGE("%s: queueBuffer failed for display:%d",
1911 __FUNCTION__, mDpy);
1912 return false;
1913 }
1914 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001915
radhakrishnac9a67412013-09-25 17:40:42 +05301916 if(indexR != ovutils::OV_INVALID) {
1917 ovutils::eDest destR = (ovutils::eDest)indexR;
1918 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1919 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1920 if (!ov.queueBuffer(fd, offset, destR)) {
1921 ALOGE("%s: queueBuffer failed for display:%d",
1922 __FUNCTION__, mDpy);
1923 return false;
1924 }
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001925 }
1926 }
radhakrishnac9a67412013-09-25 17:40:42 +05301927 else{
1928 MdpPipeInfoSplit& pipe_info =
1929 *(MdpPipeInfoSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1930 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001931
radhakrishnac9a67412013-09-25 17:40:42 +05301932 ovutils::eDest indexL = pipe_info.lIndex;
1933 ovutils::eDest indexR = pipe_info.rIndex;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001934
Sushil Chauhan4259d872014-05-13 18:17:12 -07001935 if (!mDpy && (i == mOverlapIndex)) {
1936 hnd = ctx->mCopyBit[mDpy]->getCurrentRenderBuffer();
1937 }
1938
radhakrishnac9a67412013-09-25 17:40:42 +05301939 int fd = hnd->fd;
1940 int offset = hnd->offset;
1941
Tatenda Chipeperekwa2f8cd2b2014-04-14 10:36:06 -07001942 if(ctx->mAD->draw(ctx, fd, offset)) {
1943 fd = ctx->mAD->getDstFd(ctx);
1944 offset = ctx->mAD->getDstOffset(ctx);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001945 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001946
radhakrishnac9a67412013-09-25 17:40:42 +05301947 if(rot) {
1948 rot->queueBuffer(fd, offset);
1949 fd = rot->getDstMemId();
1950 offset = rot->getDstOffset();
1951 }
1952
1953 //************* play left mixer **********
1954 if(indexL != ovutils::OV_INVALID) {
1955 ovutils::eDest destL = (ovutils::eDest)indexL;
1956 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1957 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1958 if (!ov.queueBuffer(fd, offset, destL)) {
1959 ALOGE("%s: queueBuffer failed for left mixer",
1960 __FUNCTION__);
1961 return false;
1962 }
1963 }
1964
1965 //************* play right mixer **********
1966 if(indexR != ovutils::OV_INVALID) {
1967 ovutils::eDest destR = (ovutils::eDest)indexR;
1968 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1969 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1970 if (!ov.queueBuffer(fd, offset, destR)) {
1971 ALOGE("%s: queueBuffer failed for right mixer",
1972 __FUNCTION__);
1973 return false;
1974 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001975 }
1976 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001977
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001978 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1979 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001980
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001981 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001982}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001983}; //namespace
1984