blob: 00b20dcc1d18a1e9ef692931442f1147e20fab09 [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
Justin Philipb1906f72014-10-30 14:14:19 +0530666 if (mDpy || !ctx->mCopyBit[mDpy] || !ctx->mIsPTOREnabled) {
Sushil Chauhan4259d872014-05-13 18:17:12 -0700667 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 }
Arun Kumar K.Rbad65ab2014-06-03 11:54:10 -0700678 // MDP comp checks
679 for(int i = 0; i < numAppLayers; i++) {
Sushil Chauhan4259d872014-05-13 18:17:12 -0700680 hwc_layer_1_t* layer = &list->hwLayers[i];
Arun Kumar K.Rbad65ab2014-06-03 11:54:10 -0700681 if(not isSupportedForMDPComp(ctx, layer)) {
682 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",__FUNCTION__);
683 return false;
Sushil Chauhan4259d872014-05-13 18:17:12 -0700684 }
685 }
686
Sushil Chauhan4259d872014-05-13 18:17:12 -0700687 /* We cannot use this composition mode, if:
688 1. A below layer needs scaling.
689 2. Overlap is not peripheral to display.
690 3. Overlap or a below layer has 90 degree transform.
Arun Kumar K.Rbad65ab2014-06-03 11:54:10 -0700691 4. Overlap area > (1/3 * FrameBuffer) area, based on Perf inputs.
Sushil Chauhan4259d872014-05-13 18:17:12 -0700692 */
693
Arun Kumar K.Rbad65ab2014-06-03 11:54:10 -0700694 int minLayerIndex[MAX_PTOR_LAYERS] = { -1, -1};
695 hwc_rect_t overlapRect[MAX_PTOR_LAYERS];
696 memset(overlapRect, 0, sizeof(overlapRect));
697 int layerPixelCount, minPixelCount = 0;
698 int numPTORLayersFound = 0;
699 for (int i = numAppLayers-1; (i >= 0 &&
700 numPTORLayersFound < MAX_PTOR_LAYERS); i--) {
Sushil Chauhan4259d872014-05-13 18:17:12 -0700701 hwc_layer_1_t* layer = &list->hwLayers[i];
Arun Kumar K.Rbad65ab2014-06-03 11:54:10 -0700702 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Sushil Chauhan4259d872014-05-13 18:17:12 -0700703 hwc_rect_t dispFrame = layer->displayFrame;
Arun Kumar K.Rbad65ab2014-06-03 11:54:10 -0700704 layerPixelCount = (crop.right - crop.left) * (crop.bottom - crop.top);
705 // PTOR layer should be peripheral and cannot have transform
706 if (!isPeripheral(dispFrame, ctx->mViewFrame[mDpy]) ||
707 has90Transform(layer)) {
708 continue;
709 }
710 if((3 * (layerPixelCount + minPixelCount)) >
711 ((int)ctx->dpyAttr[mDpy].xres * (int)ctx->dpyAttr[mDpy].yres)) {
712 // Overlap area > (1/3 * FrameBuffer) area, based on Perf inputs.
713 continue;
714 }
Sushil Chauhane1474bf2014-07-25 12:20:23 -0700715 bool found = false;
Arun Kumar K.Rbad65ab2014-06-03 11:54:10 -0700716 for (int j = i-1; j >= 0; j--) {
717 // Check if the layers below this layer qualifies for PTOR comp
718 hwc_layer_1_t* layer = &list->hwLayers[j];
719 hwc_rect_t disFrame = layer->displayFrame;
Sushil Chauhane1474bf2014-07-25 12:20:23 -0700720 // Layer below PTOR is intersecting and has 90 degree transform or
Arun Kumar K.Rbad65ab2014-06-03 11:54:10 -0700721 // needs scaling cannot be supported.
Sushil Chauhane1474bf2014-07-25 12:20:23 -0700722 if (isValidRect(getIntersection(dispFrame, disFrame))) {
723 if (has90Transform(layer) || needsScaling(layer)) {
724 found = false;
725 break;
726 }
727 found = true;
Arun Kumar K.Rbad65ab2014-06-03 11:54:10 -0700728 }
729 }
730 // Store the minLayer Index
731 if(found) {
732 minLayerIndex[numPTORLayersFound] = i;
733 overlapRect[numPTORLayersFound] = list->hwLayers[i].displayFrame;
734 minPixelCount += layerPixelCount;
735 numPTORLayersFound++;
Sushil Chauhan4259d872014-05-13 18:17:12 -0700736 }
737 }
738
Arun Kumar K.Rbad65ab2014-06-03 11:54:10 -0700739 // No overlap layers
740 if (!numPTORLayersFound)
741 return false;
Sushil Chauhan4259d872014-05-13 18:17:12 -0700742
Arun Kumar K.Rbad65ab2014-06-03 11:54:10 -0700743 // Store the displayFrame and the sourceCrops of the layers
744 hwc_rect_t displayFrame[numAppLayers];
745 hwc_rect_t sourceCrop[numAppLayers];
746 for(int i = 0; i < numAppLayers; i++) {
Sushil Chauhan4259d872014-05-13 18:17:12 -0700747 hwc_layer_1_t* layer = &list->hwLayers[i];
748 displayFrame[i] = layer->displayFrame;
749 sourceCrop[i] = integerizeSourceCrop(layer->sourceCropf);
Arun Kumar K.Rbad65ab2014-06-03 11:54:10 -0700750 }
Sushil Chauhan4259d872014-05-13 18:17:12 -0700751
Prabhanjan Kandulabb1f6be2014-09-04 21:50:35 +0530752 /**
753 * It's possible that 2 PTOR layers might have overlapping.
754 * In such case, remove the intersection(again if peripheral)
755 * from the lower PTOR layer to avoid overlapping.
756 * If intersection is not on peripheral then compromise
757 * by reducing number of PTOR layers.
758 **/
759 hwc_rect_t commonRect = getIntersection(overlapRect[0], overlapRect[1]);
760 if(isValidRect(commonRect)) {
761 overlapRect[1] = deductRect(overlapRect[1], commonRect);
762 list->hwLayers[minLayerIndex[1]].displayFrame = overlapRect[1];
763 }
764
765 ctx->mPtorInfo.count = numPTORLayersFound;
766 for(int i = 0; i < MAX_PTOR_LAYERS; i++) {
767 ctx->mPtorInfo.layerIndex[i] = minLayerIndex[i];
768 }
769
770 if (!ctx->mCopyBit[mDpy]->prepareOverlap(ctx, list)) {
771 // reset PTOR
772 ctx->mPtorInfo.count = 0;
773 if(isValidRect(commonRect)) {
774 // If PTORs are intersecting restore displayframe of PTOR[1]
775 // before returning, as we have modified it above.
776 list->hwLayers[minLayerIndex[1]].displayFrame =
777 displayFrame[minLayerIndex[1]];
778 }
779 return false;
780 }
Sushil Chauhane1474bf2014-07-25 12:20:23 -0700781 private_handle_t *renderBuf = ctx->mCopyBit[mDpy]->getCurrentRenderBuffer();
782 Whf layerWhf[numPTORLayersFound]; // To store w,h,f of PTOR layers
783
Xu Yang645cb1f2014-07-30 21:57:21 +0800784 // Store the blending mode, planeAlpha, and transform of PTOR layers
785 int32_t blending[numPTORLayersFound];
786 uint8_t planeAlpha[numPTORLayersFound];
787 uint32_t transform[numPTORLayersFound];
788
Arun Kumar K.Rbad65ab2014-06-03 11:54:10 -0700789 for(int j = 0; j < numPTORLayersFound; j++) {
790 int index = ctx->mPtorInfo.layerIndex[j];
Sushil Chauhane1474bf2014-07-25 12:20:23 -0700791
792 // Update src crop of PTOR layer
793 hwc_layer_1_t* layer = &list->hwLayers[index];
794 layer->sourceCropf.left = (float)ctx->mPtorInfo.displayFrame[j].left;
795 layer->sourceCropf.top = (float)ctx->mPtorInfo.displayFrame[j].top;
796 layer->sourceCropf.right = (float)ctx->mPtorInfo.displayFrame[j].right;
797 layer->sourceCropf.bottom =(float)ctx->mPtorInfo.displayFrame[j].bottom;
798
799 // Store & update w, h, format of PTOR layer
800 private_handle_t *hnd = (private_handle_t *)layer->handle;
801 Whf whf(hnd->width, hnd->height, hnd->format, hnd->size);
802 layerWhf[j] = whf;
803 hnd->width = renderBuf->width;
804 hnd->height = renderBuf->height;
805 hnd->format = renderBuf->format;
806
Xu Yang645cb1f2014-07-30 21:57:21 +0800807 // Store & update blending mode, planeAlpha and transform of PTOR layer
808 blending[j] = layer->blending;
809 planeAlpha[j] = layer->planeAlpha;
810 transform[j] = layer->transform;
811 layer->blending = HWC_BLENDING_NONE;
812 layer->planeAlpha = 0xFF;
813 layer->transform = 0;
814
Arun Kumar K.Rbad65ab2014-06-03 11:54:10 -0700815 // Remove overlap from crop & displayFrame of below layers
816 for (int i = 0; i < index && index !=-1; i++) {
Sushil Chauhane1474bf2014-07-25 12:20:23 -0700817 layer = &list->hwLayers[i];
Arun Kumar K.Rbad65ab2014-06-03 11:54:10 -0700818 if(!isValidRect(getIntersection(layer->displayFrame,
819 overlapRect[j]))) {
820 continue;
821 }
822 // Update layer attributes
823 hwc_rect_t srcCrop = integerizeSourceCrop(layer->sourceCropf);
824 hwc_rect_t destRect = deductRect(layer->displayFrame,
825 overlapRect[j]);
826 qhwc::calculate_crop_rects(srcCrop, layer->displayFrame, destRect,
827 layer->transform);
828 layer->sourceCropf.left = (float)srcCrop.left;
829 layer->sourceCropf.top = (float)srcCrop.top;
830 layer->sourceCropf.right = (float)srcCrop.right;
831 layer->sourceCropf.bottom = (float)srcCrop.bottom;
832 }
Sushil Chauhan4259d872014-05-13 18:17:12 -0700833 }
834
835 mCurrentFrame.mdpCount = numAppLayers;
836 mCurrentFrame.fbCount = 0;
837 mCurrentFrame.fbZ = -1;
838
839 for (int j = 0; j < numAppLayers; j++)
840 mCurrentFrame.isFBComposed[j] = false;
841
842 bool result = postHeuristicsHandling(ctx, list);
843
844 // Restore layer attributes
Arun Kumar K.Rbad65ab2014-06-03 11:54:10 -0700845 for(int i = 0; i < numAppLayers; i++) {
Sushil Chauhan4259d872014-05-13 18:17:12 -0700846 hwc_layer_1_t* layer = &list->hwLayers[i];
847 layer->displayFrame = displayFrame[i];
848 layer->sourceCropf.left = (float)sourceCrop[i].left;
849 layer->sourceCropf.top = (float)sourceCrop[i].top;
850 layer->sourceCropf.right = (float)sourceCrop[i].right;
851 layer->sourceCropf.bottom = (float)sourceCrop[i].bottom;
852 }
853
Xu Yang645cb1f2014-07-30 21:57:21 +0800854 // Restore w,h,f, blending attributes, and transform of PTOR layers
Sushil Chauhane1474bf2014-07-25 12:20:23 -0700855 for (int i = 0; i < numPTORLayersFound; i++) {
856 int idx = ctx->mPtorInfo.layerIndex[i];
Xu Yang645cb1f2014-07-30 21:57:21 +0800857 hwc_layer_1_t* layer = &list->hwLayers[idx];
Sushil Chauhane1474bf2014-07-25 12:20:23 -0700858 private_handle_t *hnd = (private_handle_t *)list->hwLayers[idx].handle;
859 hnd->width = layerWhf[i].w;
860 hnd->height = layerWhf[i].h;
861 hnd->format = layerWhf[i].format;
Xu Yang645cb1f2014-07-30 21:57:21 +0800862 layer->blending = blending[i];
863 layer->planeAlpha = planeAlpha[i];
864 layer->transform = transform[i];
Sushil Chauhane1474bf2014-07-25 12:20:23 -0700865 }
866
Sushil Chauhan4259d872014-05-13 18:17:12 -0700867 if (!result) {
Arun Kumar K.Rbad65ab2014-06-03 11:54:10 -0700868 // reset PTOR
869 ctx->mPtorInfo.count = 0;
Sushil Chauhan4259d872014-05-13 18:17:12 -0700870 reset(ctx);
Arun Kumar K.Rbad65ab2014-06-03 11:54:10 -0700871 } else {
872 ALOGD_IF(isDebug(), "%s: PTOR Indexes: %d and %d", __FUNCTION__,
873 ctx->mPtorInfo.layerIndex[0], ctx->mPtorInfo.layerIndex[1]);
Sushil Chauhan4259d872014-05-13 18:17:12 -0700874 }
875
Arun Kumar K.Rbad65ab2014-06-03 11:54:10 -0700876 ALOGD_IF(isDebug(), "%s: Postheuristics %s!", __FUNCTION__,
877 (result ? "successful" : "failed"));
Sushil Chauhan4259d872014-05-13 18:17:12 -0700878 return result;
879}
880
Saurabh Shahaa236822013-04-24 18:07:26 -0700881bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
882{
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700883 if(!sEnableMixedMode) {
884 //Mixed mode is disabled. No need to even try caching.
885 return false;
886 }
887
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700888 bool ret = false;
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800889 if(list->flags & HWC_GEOMETRY_CHANGED) { //Try load based first
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800890 ret = loadBasedComp(ctx, list) or
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800891 cacheBasedComp(ctx, list);
892 } else {
893 ret = cacheBasedComp(ctx, list) or
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800894 loadBasedComp(ctx, list);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700895 }
896
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700897 return ret;
898}
899
900bool MDPComp::cacheBasedComp(hwc_context_t *ctx,
901 hwc_display_contents_1_t* list) {
902 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700903 mCurrentFrame.reset(numAppLayers);
904 updateLayerCache(ctx, list);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700905
906 //If an MDP marked layer is unsupported cannot do partial MDP Comp
907 for(int i = 0; i < numAppLayers; i++) {
908 if(!mCurrentFrame.isFBComposed[i]) {
909 hwc_layer_1_t* layer = &list->hwLayers[i];
910 if(not isSupportedForMDPComp(ctx, layer)) {
911 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",
912 __FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800913 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700914 return false;
915 }
916 }
917 }
918
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700919 updateYUV(ctx, list, false /*secure only*/);
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530920 bool ret = markLayersForCaching(ctx, list); //sets up fbZ also
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700921 if(!ret) {
922 ALOGD_IF(isDebug(),"%s: batching failed, dpy %d",__FUNCTION__, mDpy);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800923 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700924 return false;
925 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700926
927 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700928
radhakrishnac9a67412013-09-25 17:40:42 +0530929 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800930 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530931 }
932
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700933 //Will benefit cases where a video has non-updating background.
934 if((mDpy > HWC_DISPLAY_PRIMARY) and
935 (mdpCount > MAX_SEC_LAYERS)) {
936 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800937 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700938 return false;
939 }
940
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800941 if(!postHeuristicsHandling(ctx, list)) {
942 ALOGD_IF(isDebug(), "post heuristic handling failed");
943 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700944 return false;
945 }
946
Saurabh Shahaa236822013-04-24 18:07:26 -0700947 return true;
948}
949
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800950bool MDPComp::loadBasedComp(hwc_context_t *ctx,
Saurabh Shahb772ae32013-11-18 15:40:02 -0800951 hwc_display_contents_1_t* list) {
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800952 if(not isLoadBasedCompDoable(ctx, list)) {
953 return false;
954 }
955
Saurabh Shahb772ae32013-11-18 15:40:02 -0800956 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800957 const int numNonDroppedLayers = numAppLayers - mCurrentFrame.dropCount;
958 const int stagesForMDP = min(sMaxPipesPerMixer,
959 ctx->mOverlay->availablePipes(mDpy, Overlay::MIXER_DEFAULT));
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800960
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800961 int mdpBatchSize = stagesForMDP - 1; //1 stage for FB
962 int fbBatchSize = numNonDroppedLayers - mdpBatchSize;
963 int lastMDPSupportedIndex = numAppLayers;
964 int dropCount = 0;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800965
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800966 //Find the minimum MDP batch size
967 for(int i = 0; i < numAppLayers;i++) {
968 if(mCurrentFrame.drop[i]) {
969 dropCount++;
Jeykumar Sankaran6279bc32014-01-23 21:59:58 -0800970 continue;
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800971 }
972 hwc_layer_1_t* layer = &list->hwLayers[i];
973 if(not isSupportedForMDPComp(ctx, layer)) {
974 lastMDPSupportedIndex = i;
975 mdpBatchSize = min(i - dropCount, stagesForMDP - 1);
976 fbBatchSize = numNonDroppedLayers - mdpBatchSize;
Jeykumar Sankaran6279bc32014-01-23 21:59:58 -0800977 break;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800978 }
Saurabh Shahb772ae32013-11-18 15:40:02 -0800979 }
980
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800981 ALOGD_IF(isDebug(), "%s:Before optimizing fbBatch, mdpbatch %d, fbbatch %d "
982 "dropped %d", __FUNCTION__, mdpBatchSize, fbBatchSize,
983 mCurrentFrame.dropCount);
984
985 //Start at a point where the fb batch should at least have 2 layers, for
986 //this mode to be justified.
987 while(fbBatchSize < 2) {
988 ++fbBatchSize;
989 --mdpBatchSize;
Jeykumar Sankaran6279bc32014-01-23 21:59:58 -0800990 }
Saurabh Shahb772ae32013-11-18 15:40:02 -0800991
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800992 //If there are no layers for MDP, this mode doesnt make sense.
993 if(mdpBatchSize < 1) {
994 ALOGD_IF(isDebug(), "%s: No MDP layers after optimizing for fbBatch",
995 __FUNCTION__);
Saurabh Shahb772ae32013-11-18 15:40:02 -0800996 return false;
997 }
998
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800999 mCurrentFrame.reset(numAppLayers);
1000
1001 //Try with successively smaller mdp batch sizes until we succeed or reach 1
1002 while(mdpBatchSize > 0) {
1003 //Mark layers for MDP comp
1004 int mdpBatchLeft = mdpBatchSize;
1005 for(int i = 0; i < lastMDPSupportedIndex and mdpBatchLeft; i++) {
1006 if(mCurrentFrame.drop[i]) {
1007 continue;
1008 }
1009 mCurrentFrame.isFBComposed[i] = false;
1010 --mdpBatchLeft;
1011 }
1012
1013 mCurrentFrame.fbZ = mdpBatchSize;
1014 mCurrentFrame.fbCount = fbBatchSize;
1015 mCurrentFrame.mdpCount = mdpBatchSize;
1016
1017 ALOGD_IF(isDebug(), "%s:Trying with: mdpbatch %d fbbatch %d dropped %d",
1018 __FUNCTION__, mdpBatchSize, fbBatchSize,
1019 mCurrentFrame.dropCount);
1020
1021 if(postHeuristicsHandling(ctx, list)) {
1022 ALOGD_IF(isDebug(), "%s: Postheuristics handling succeeded",
1023 __FUNCTION__);
1024 return true;
1025 }
1026
1027 reset(ctx);
1028 --mdpBatchSize;
1029 ++fbBatchSize;
1030 }
1031
1032 return false;
Saurabh Shahb772ae32013-11-18 15:40:02 -08001033}
1034
Saurabh Shah8028e3b2013-10-15 12:27:59 -07001035bool MDPComp::isLoadBasedCompDoable(hwc_context_t *ctx,
1036 hwc_display_contents_1_t* list) {
Prabhanjan Kandula3dbbd882013-12-11 14:43:46 +05301037 if(mDpy or isSecurePresent(ctx, mDpy) or
1038 isYuvPresent(ctx, mDpy)) {
Saurabh Shah8028e3b2013-10-15 12:27:59 -07001039 return false;
1040 }
1041 return true;
1042}
1043
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001044bool MDPComp::tryVideoOnly(hwc_context_t *ctx,
1045 hwc_display_contents_1_t* list) {
1046 const bool secureOnly = true;
1047 return videoOnlyComp(ctx, list, not secureOnly) or
1048 videoOnlyComp(ctx, list, secureOnly);
1049}
1050
1051bool MDPComp::videoOnlyComp(hwc_context_t *ctx,
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001052 hwc_display_contents_1_t* list, bool secureOnly) {
Saurabh Shahaa236822013-04-24 18:07:26 -07001053 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001054
Saurabh Shahaa236822013-04-24 18:07:26 -07001055 mCurrentFrame.reset(numAppLayers);
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001056 updateYUV(ctx, list, secureOnly);
Saurabh Shah4fdde762013-04-30 18:47:33 -07001057 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001058
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001059 if(!isYuvPresent(ctx, mDpy) or (mdpCount == 0)) {
1060 reset(ctx);
Saurabh Shahaa236822013-04-24 18:07:26 -07001061 return false;
1062 }
1063
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -08001064 /* Bail out if we are processing only secured video layers
1065 * and we dont have any */
1066 if(!isSecurePresent(ctx, mDpy) && secureOnly){
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001067 reset(ctx);
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -08001068 return false;
1069 }
1070
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001071 if(mCurrentFrame.fbCount)
1072 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
Saurabh Shah4fdde762013-04-30 18:47:33 -07001073
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001074 if(sEnable4k2kYUVSplit){
1075 adjustForSourceSplit(ctx, list);
1076 }
1077
1078 if(!postHeuristicsHandling(ctx, list)) {
1079 ALOGD_IF(isDebug(), "post heuristic handling failed");
1080 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001081 return false;
1082 }
1083
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001084 return true;
1085}
1086
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001087/* Checks for conditions where YUV layers cannot be bypassed */
1088bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -07001089 if(isSkipLayer(layer)) {
Saurabh Shahe2474082013-05-15 16:32:13 -07001090 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001091 return false;
1092 }
1093
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -07001094 if(layer->transform & HWC_TRANSFORM_ROT_90 && !canUseRotator(ctx,mDpy)) {
1095 ALOGD_IF(isDebug(), "%s: no free DMA pipe",__FUNCTION__);
1096 return false;
1097 }
1098
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001099 if(isSecuring(ctx, layer)) {
1100 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
1101 return false;
1102 }
1103
Saurabh Shah4fdde762013-04-30 18:47:33 -07001104 if(!isValidDimension(ctx, layer)) {
1105 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
1106 __FUNCTION__);
1107 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001108 }
Saurabh Shah4fdde762013-04-30 18:47:33 -07001109
Naseer Ahmeddc61a972013-07-10 17:50:54 -04001110 if(layer->planeAlpha < 0xFF) {
1111 ALOGD_IF(isDebug(), "%s: Cannot handle YUV layer with plane alpha\
1112 in video only mode",
1113 __FUNCTION__);
1114 return false;
1115 }
1116
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001117 return true;
1118}
1119
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301120/* starts at fromIndex and check for each layer to find
1121 * if it it has overlapping with any Updating layer above it in zorder
1122 * till the end of the batch. returns true if it finds any intersection */
1123bool MDPComp::canPushBatchToTop(const hwc_display_contents_1_t* list,
1124 int fromIndex, int toIndex) {
1125 for(int i = fromIndex; i < toIndex; i++) {
1126 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
1127 if(intersectingUpdatingLayers(list, i+1, toIndex, i)) {
1128 return false;
1129 }
1130 }
1131 }
1132 return true;
1133}
1134
1135/* Checks if given layer at targetLayerIndex has any
1136 * intersection with all the updating layers in beween
1137 * fromIndex and toIndex. Returns true if it finds intersectiion */
1138bool MDPComp::intersectingUpdatingLayers(const hwc_display_contents_1_t* list,
1139 int fromIndex, int toIndex, int targetLayerIndex) {
1140 for(int i = fromIndex; i <= toIndex; i++) {
1141 if(!mCurrentFrame.isFBComposed[i]) {
1142 if(areLayersIntersecting(&list->hwLayers[i],
1143 &list->hwLayers[targetLayerIndex])) {
1144 return true;
1145 }
1146 }
1147 }
1148 return false;
1149}
1150
1151int MDPComp::getBatch(hwc_display_contents_1_t* list,
1152 int& maxBatchStart, int& maxBatchEnd,
1153 int& maxBatchCount) {
1154 int i = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301155 int fbZOrder =-1;
Jeykumar Sankaran5a495da2014-01-20 12:25:32 -08001156 int droppedLayerCt = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301157 while (i < mCurrentFrame.layerCount) {
1158 int batchCount = 0;
1159 int batchStart = i;
1160 int batchEnd = i;
Jeykumar Sankaran5a495da2014-01-20 12:25:32 -08001161 /* Adjust batch Z order with the dropped layers so far */
1162 int fbZ = batchStart - droppedLayerCt;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301163 int firstZReverseIndex = -1;
Prabhanjan Kandula0ed2cc92013-12-06 12:39:04 +05301164 int updatingLayersAbove = 0;//Updating layer count in middle of batch
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301165 while(i < mCurrentFrame.layerCount) {
1166 if(!mCurrentFrame.isFBComposed[i]) {
1167 if(!batchCount) {
1168 i++;
1169 break;
1170 }
1171 updatingLayersAbove++;
1172 i++;
1173 continue;
1174 } else {
1175 if(mCurrentFrame.drop[i]) {
1176 i++;
Jeykumar Sankaran5a495da2014-01-20 12:25:32 -08001177 droppedLayerCt++;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301178 continue;
1179 } else if(updatingLayersAbove <= 0) {
1180 batchCount++;
1181 batchEnd = i;
1182 i++;
1183 continue;
1184 } else { //Layer is FBComposed, not a drop & updatingLayer > 0
1185
1186 // We have a valid updating layer already. If layer-i not
1187 // have overlapping with all updating layers in between
1188 // batch-start and i, then we can add layer i to batch.
1189 if(!intersectingUpdatingLayers(list, batchStart, i-1, i)) {
1190 batchCount++;
1191 batchEnd = i;
1192 i++;
1193 continue;
1194 } else if(canPushBatchToTop(list, batchStart, i)) {
1195 //If All the non-updating layers with in this batch
1196 //does not have intersection with the updating layers
1197 //above in z-order, then we can safely move the batch to
1198 //higher z-order. Increment fbZ as it is moving up.
1199 if( firstZReverseIndex < 0) {
1200 firstZReverseIndex = i;
1201 }
1202 batchCount++;
1203 batchEnd = i;
1204 fbZ += updatingLayersAbove;
1205 i++;
1206 updatingLayersAbove = 0;
1207 continue;
1208 } else {
1209 //both failed.start the loop again from here.
1210 if(firstZReverseIndex >= 0) {
1211 i = firstZReverseIndex;
1212 }
1213 break;
1214 }
1215 }
1216 }
1217 }
1218 if(batchCount > maxBatchCount) {
1219 maxBatchCount = batchCount;
1220 maxBatchStart = batchStart;
1221 maxBatchEnd = batchEnd;
1222 fbZOrder = fbZ;
1223 }
1224 }
1225 return fbZOrder;
1226}
1227
1228bool MDPComp::markLayersForCaching(hwc_context_t* ctx,
1229 hwc_display_contents_1_t* list) {
1230 /* Idea is to keep as many non-updating(cached) layers in FB and
1231 * send rest of them through MDP. This is done in 2 steps.
1232 * 1. Find the maximum contiguous batch of non-updating layers.
1233 * 2. See if we can improve this batch size for caching by adding
1234 * opaque layers around the batch, if they don't have
1235 * any overlapping with the updating layers in between.
1236 * NEVER mark an updating layer for caching.
1237 * But cached ones can be marked for MDP */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001238
1239 int maxBatchStart = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001240 int maxBatchEnd = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001241 int maxBatchCount = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301242 int fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001243
Saurabh Shahce188452014-02-05 10:17:43 -08001244 /* Nothing is cached. No batching needed */
1245 if(mCurrentFrame.fbCount == 0) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001246 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -07001247 }
Saurabh Shahce188452014-02-05 10:17:43 -08001248
1249 /* No MDP comp layers, try to use other comp modes */
1250 if(mCurrentFrame.mdpCount == 0) {
1251 return false;
Saurabh Shahaa236822013-04-24 18:07:26 -07001252 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001253
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301254 fbZ = getBatch(list, maxBatchStart, maxBatchEnd, maxBatchCount);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001255
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301256 /* reset rest of the layers lying inside ROI for MDP comp */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001257 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001258 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001259 if((i < maxBatchStart || i > maxBatchEnd) &&
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301260 mCurrentFrame.isFBComposed[i]){
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001261 if(!mCurrentFrame.drop[i]){
1262 //If an unsupported layer is being attempted to
1263 //be pulled out we should fail
1264 if(not isSupportedForMDPComp(ctx, layer)) {
1265 return false;
1266 }
1267 mCurrentFrame.isFBComposed[i] = false;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001268 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001269 }
1270 }
1271
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301272 // update the frame data
1273 mCurrentFrame.fbZ = fbZ;
1274 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001275 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001276 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001277
1278 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301279 mCurrentFrame.fbCount);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001280
1281 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001282}
Saurabh Shah85234ec2013-04-12 17:09:00 -07001283
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001284void MDPComp::updateLayerCache(hwc_context_t* ctx,
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001285 hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001286 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001287 int fbCount = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001288
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001289 for(int i = 0; i < numAppLayers; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001290 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001291 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001292 if(!mCurrentFrame.drop[i])
1293 fbCount++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001294 mCurrentFrame.isFBComposed[i] = true;
1295 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -07001296 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001297 }
1298 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001299
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001300 mCurrentFrame.fbCount = fbCount;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001301 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount
1302 - mCurrentFrame.dropCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001303
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001304 ALOGD_IF(isDebug(),"%s: MDP count: %d FB count %d drop count: %d"
1305 ,__FUNCTION__, mCurrentFrame.mdpCount, mCurrentFrame.fbCount,
1306 mCurrentFrame.dropCount);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001307}
1308
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001309void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list,
1310 bool secureOnly) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001311 int nYuvCount = ctx->listStats[mDpy].yuvCount;
1312 for(int index = 0;index < nYuvCount; index++){
1313 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
1314 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
1315
1316 if(!isYUVDoable(ctx, layer)) {
1317 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
1318 mCurrentFrame.isFBComposed[nYuvIndex] = true;
1319 mCurrentFrame.fbCount++;
1320 }
1321 } else {
1322 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001323 private_handle_t *hnd = (private_handle_t *)layer->handle;
1324 if(!secureOnly || isSecureBuffer(hnd)) {
1325 mCurrentFrame.isFBComposed[nYuvIndex] = false;
1326 mCurrentFrame.fbCount--;
1327 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001328 }
1329 }
1330 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001331
1332 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001333 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
1334 ALOGD_IF(isDebug(),"%s: fb count: %d",__FUNCTION__,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001335 mCurrentFrame.fbCount);
1336}
1337
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001338bool MDPComp::postHeuristicsHandling(hwc_context_t *ctx,
1339 hwc_display_contents_1_t* list) {
1340
1341 //Capability checks
1342 if(!resourceCheck(ctx, list)) {
1343 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
1344 return false;
1345 }
1346
1347 //Limitations checks
1348 if(!hwLimitationsCheck(ctx, list)) {
1349 ALOGD_IF(isDebug(), "%s: HW limitations",__FUNCTION__);
1350 return false;
1351 }
1352
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001353 //Configure framebuffer first if applicable
1354 if(mCurrentFrame.fbZ >= 0) {
1355 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, mCurrentFrame.fbZ)) {
1356 ALOGD_IF(isDebug(), "%s configure framebuffer failed",
1357 __FUNCTION__);
1358 return false;
1359 }
1360 }
1361
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001362 mCurrentFrame.map();
1363
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001364 if(!allocLayerPipes(ctx, list)) {
1365 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -07001366 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001367 }
1368
1369 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001370 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001371 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001372 int mdpIndex = mCurrentFrame.layerToMDP[index];
1373 hwc_layer_1_t* layer = &list->hwLayers[index];
1374
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301375 //Leave fbZ for framebuffer. CACHE/GLES layers go here.
1376 if(mdpNextZOrder == mCurrentFrame.fbZ) {
1377 mdpNextZOrder++;
1378 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001379 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1380 cur_pipe->zOrder = mdpNextZOrder++;
1381
radhakrishnac9a67412013-09-25 17:40:42 +05301382 private_handle_t *hnd = (private_handle_t *)layer->handle;
1383 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1384 if(configure4k2kYuv(ctx, layer,
1385 mCurrentFrame.mdpToLayer[mdpIndex])
1386 != 0 ){
1387 ALOGD_IF(isDebug(), "%s: Failed to configure split pipes \
1388 for layer %d",__FUNCTION__, index);
1389 return false;
1390 }
1391 else{
1392 mdpNextZOrder++;
1393 }
1394 continue;
1395 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001396 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
1397 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
radhakrishnac9a67412013-09-25 17:40:42 +05301398 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -07001399 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001400 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001401 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001402 }
1403
Saurabh Shah450ac972013-12-16 18:18:39 -08001404 if(!ctx->mOverlay->validateAndSet(mDpy, ctx->dpyAttr[mDpy].fd)) {
1405 ALOGD_IF(isDebug(), "%s: Failed to validate and set overlay for dpy %d"
1406 ,__FUNCTION__, mDpy);
1407 return false;
1408 }
1409
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001410 setRedraw(ctx, list);
Saurabh Shahaa236822013-04-24 18:07:26 -07001411 return true;
1412}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001413
Saurabh Shah173f4242013-11-20 09:50:12 -08001414bool MDPComp::resourceCheck(hwc_context_t *ctx,
1415 hwc_display_contents_1_t *list) {
1416 const bool fbUsed = mCurrentFrame.fbCount;
1417 if(mCurrentFrame.mdpCount > sMaxPipesPerMixer - fbUsed) {
1418 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
1419 return false;
1420 }
Saurabh Shah173f4242013-11-20 09:50:12 -08001421 return true;
1422}
1423
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301424bool MDPComp::hwLimitationsCheck(hwc_context_t* ctx,
1425 hwc_display_contents_1_t* list) {
1426
1427 //A-family hw limitation:
1428 //If a layer need alpha scaling, MDP can not support.
1429 if(ctx->mMDP.version < qdutils::MDSS_V5) {
1430 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1431 if(!mCurrentFrame.isFBComposed[i] &&
1432 isAlphaScaled( &list->hwLayers[i])) {
1433 ALOGD_IF(isDebug(), "%s:frame needs alphaScaling",__FUNCTION__);
1434 return false;
1435 }
1436 }
1437 }
1438
1439 // On 8x26 & 8974 hw, we have a limitation of downscaling+blending.
1440 //If multiple layers requires downscaling and also they are overlapping
1441 //fall back to GPU since MDSS can not handle it.
1442 if(qdutils::MDPVersion::getInstance().is8x74v2() ||
1443 qdutils::MDPVersion::getInstance().is8x26()) {
1444 for(int i = 0; i < mCurrentFrame.layerCount-1; ++i) {
1445 hwc_layer_1_t* botLayer = &list->hwLayers[i];
1446 if(!mCurrentFrame.isFBComposed[i] &&
1447 isDownscaleRequired(botLayer)) {
1448 //if layer-i is marked for MDP and needs downscaling
1449 //check if any MDP layer on top of i & overlaps with layer-i
1450 for(int j = i+1; j < mCurrentFrame.layerCount; ++j) {
1451 hwc_layer_1_t* topLayer = &list->hwLayers[j];
1452 if(!mCurrentFrame.isFBComposed[j] &&
1453 isDownscaleRequired(topLayer)) {
1454 hwc_rect_t r = getIntersection(botLayer->displayFrame,
1455 topLayer->displayFrame);
1456 if(isValidRect(r))
1457 return false;
1458 }
1459 }
1460 }
1461 }
1462 }
1463 return true;
1464}
1465
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001466int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001467 int ret = 0;
Raj Kamal5166b312014-06-06 13:45:20 +05301468
1469 if(!ctx || !list) {
1470 ALOGE("%s: Invalid context or list",__FUNCTION__);
1471 mCachedFrame.reset();
1472 return -1;
1473 }
1474
Saurabh Shahaa236822013-04-24 18:07:26 -07001475 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001476 MDPVersion& mdpVersion = qdutils::MDPVersion::getInstance();
Arun Kumar K.Rbad65ab2014-06-03 11:54:10 -07001477
1478 // reset PTOR
1479 if(!mDpy)
1480 memset(&(ctx->mPtorInfo), 0, sizeof(ctx->mPtorInfo));
Raj Kamalfc5b9222014-02-07 16:15:17 +05301481 //Do not cache the information for next draw cycle.
1482 if(numLayers > MAX_NUM_APP_LAYERS or (!numLayers)) {
1483 ALOGI("%s: Unsupported layer count for mdp composition",
1484 __FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001485 mCachedFrame.reset();
1486 return -1;
1487 }
1488
Saurabh Shahb39f8152013-08-22 10:21:44 -07001489 //reset old data
1490 mCurrentFrame.reset(numLayers);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001491 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1492 mCurrentFrame.dropCount = 0;
Prabhanjan Kandula088bd892013-07-02 23:47:13 +05301493
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -07001494 // Detect the start of animation and fall back to GPU only once to cache
1495 // all the layers in FB and display FB content untill animation completes.
1496 if(ctx->listStats[mDpy].isDisplayAnimating) {
1497 mCurrentFrame.needsRedraw = false;
1498 if(ctx->mAnimationState[mDpy] == ANIMATION_STOPPED) {
1499 mCurrentFrame.needsRedraw = true;
1500 ctx->mAnimationState[mDpy] = ANIMATION_STARTED;
1501 }
1502 setMDPCompLayerFlags(ctx, list);
1503 mCachedFrame.updateCounts(mCurrentFrame);
1504 ret = -1;
1505 return ret;
1506 } else {
1507 ctx->mAnimationState[mDpy] = ANIMATION_STOPPED;
1508 }
1509
Saurabh Shahb39f8152013-08-22 10:21:44 -07001510 //Hard conditions, if not met, cannot do MDP comp
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001511 if(isFrameDoable(ctx)) {
1512 generateROI(ctx, list);
Saurabh Shahb39f8152013-08-22 10:21:44 -07001513
Raj Kamal5166b312014-06-06 13:45:20 +05301514 mModeOn = tryFullFrame(ctx, list) || tryVideoOnly(ctx, list);
1515 if(mModeOn) {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001516 setMDPCompLayerFlags(ctx, list);
1517 } else {
1518 reset(ctx);
1519 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1520 mCurrentFrame.dropCount = 0;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001521 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001522 }
1523 } else {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001524 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
1525 __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001526 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001527 }
Saurabh Shahb39f8152013-08-22 10:21:44 -07001528
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001529 if(isDebug()) {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001530 ALOGD("GEOMETRY change: %d",
1531 (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001532 android::String8 sDump("");
1533 dump(sDump);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001534 ALOGD("%s",sDump.string());
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001535 }
1536
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001537 mCachedFrame.cacheAll(list);
1538 mCachedFrame.updateCounts(mCurrentFrame);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001539 return ret;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001540}
1541
radhakrishnac9a67412013-09-25 17:40:42 +05301542bool MDPComp::allocSplitVGPipesfor4k2k(hwc_context_t *ctx,
1543 hwc_display_contents_1_t* list, int index) {
1544
1545 bool bRet = true;
1546 hwc_layer_1_t* layer = &list->hwLayers[index];
1547 private_handle_t *hnd = (private_handle_t *)layer->handle;
1548 int mdpIndex = mCurrentFrame.layerToMDP[index];
1549 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
1550 info.pipeInfo = new MdpYUVPipeInfo;
1551 info.rot = NULL;
1552 MdpYUVPipeInfo& pipe_info = *(MdpYUVPipeInfo*)info.pipeInfo;
1553 ePipeType type = MDPCOMP_OV_VG;
1554
1555 pipe_info.lIndex = ovutils::OV_INVALID;
1556 pipe_info.rIndex = ovutils::OV_INVALID;
1557
1558 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
1559 if(pipe_info.lIndex == ovutils::OV_INVALID){
1560 bRet = false;
1561 ALOGD_IF(isDebug(),"%s: allocating first VG pipe failed",
1562 __FUNCTION__);
1563 }
1564 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
1565 if(pipe_info.rIndex == ovutils::OV_INVALID){
1566 bRet = false;
1567 ALOGD_IF(isDebug(),"%s: allocating second VG pipe failed",
1568 __FUNCTION__);
1569 }
1570 return bRet;
1571}
Sushil Chauhan4259d872014-05-13 18:17:12 -07001572
1573int MDPComp::drawOverlap(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
1574 int fd = -1;
Arun Kumar K.Rbad65ab2014-06-03 11:54:10 -07001575 if (ctx->mPtorInfo.isActive()) {
1576 fd = ctx->mCopyBit[mDpy]->drawOverlap(ctx, list);
Sushil Chauhan4259d872014-05-13 18:17:12 -07001577 if (fd < 0) {
1578 ALOGD_IF(isDebug(),"%s: failed", __FUNCTION__);
Sushil Chauhan4259d872014-05-13 18:17:12 -07001579 }
1580 }
1581 return fd;
1582}
1583
Saurabh Shah88e4d272013-09-03 13:31:29 -07001584//=============MDPCompNonSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001585
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001586void MDPCompNonSplit::adjustForSourceSplit(hwc_context_t *ctx,
radhakrishnac9a67412013-09-25 17:40:42 +05301587 hwc_display_contents_1_t* list){
1588 //As we split 4kx2k yuv layer and program to 2 VG pipes
1589 //(if available) increase mdpcount accordingly
1590 mCurrentFrame.mdpCount += ctx->listStats[mDpy].yuv4k2kCount;
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001591
1592 //If 4k2k Yuv layer split is possible, and if
1593 //fbz is above 4k2k layer, increment fb zorder by 1
1594 //as we split 4k2k layer and increment zorder for right half
1595 //of the layer
1596 if(mCurrentFrame.fbZ >= 0) {
Dileep Kumar Reddi2268dd72014-05-22 22:24:53 +05301597 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
1598 index++) {
1599 if(!mCurrentFrame.isFBComposed[index]) {
1600 if(mdpNextZOrder == mCurrentFrame.fbZ) {
1601 mdpNextZOrder++;
1602 }
1603 mdpNextZOrder++;
1604 hwc_layer_1_t* layer = &list->hwLayers[index];
1605 private_handle_t *hnd = (private_handle_t *)layer->handle;
1606 if(is4kx2kYuvBuffer(hnd)) {
1607 if(mdpNextZOrder <= mCurrentFrame.fbZ)
1608 mCurrentFrame.fbZ += 1;
1609 mdpNextZOrder++;
1610 //As we split 4kx2k yuv layer and program to 2 VG pipes
1611 //(if available) increase mdpcount by 1.
1612 mCurrentFrame.mdpCount++;
1613 }
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001614 }
1615 }
1616 }
radhakrishnac9a67412013-09-25 17:40:42 +05301617}
1618
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001619/*
1620 * Configures pipe(s) for MDP composition
1621 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001622int MDPCompNonSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001623 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001624 MdpPipeInfoNonSplit& mdp_info =
1625 *(static_cast<MdpPipeInfoNonSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001626 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
1627 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1628 eIsFg isFg = IS_FG_OFF;
1629 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001630
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001631 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
1632 __FUNCTION__, layer, zOrder, dest);
1633
Saurabh Shah88e4d272013-09-03 13:31:29 -07001634 return configureNonSplit(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001635 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001636}
1637
Saurabh Shah88e4d272013-09-03 13:31:29 -07001638bool MDPCompNonSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001639 hwc_display_contents_1_t* list) {
1640 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001641
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001642 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001643
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001644 hwc_layer_1_t* layer = &list->hwLayers[index];
1645 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301646 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1647 if(allocSplitVGPipesfor4k2k(ctx, list, index)){
1648 continue;
1649 }
1650 }
1651
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001652 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001653 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001654 info.pipeInfo = new MdpPipeInfoNonSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08001655 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001656 MdpPipeInfoNonSplit& pipe_info = *(MdpPipeInfoNonSplit*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001657 ePipeType type = MDPCOMP_OV_ANY;
1658
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001659 if(isYuvBuffer(hnd)) {
1660 type = MDPCOMP_OV_VG;
Prabhanjan Kandula5b8913e2014-01-22 23:01:45 +05301661 } else if(qdutils::MDPVersion::getInstance().is8x26() &&
1662 (ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres > 1024)) {
1663 if(qhwc::needsScaling(layer))
1664 type = MDPCOMP_OV_RGB;
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301665 } else if(!qhwc::needsScaling(layer)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001666 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
1667 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001668 type = MDPCOMP_OV_DMA;
1669 }
1670
Xu Yang5c2b3af2014-04-08 13:56:47 +08001671 // for 8x26, never allow primary display occupy DMA pipe
1672 // when external display is connected
1673 if(qdutils::MDPVersion::getInstance().is8x26()
1674 && ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isActive
1675 && ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected
1676 && !ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isPause
1677 && mDpy == HWC_DISPLAY_PRIMARY
1678 && type == MDPCOMP_OV_DMA) {
1679 type = MDPCOMP_OV_RGB;
1680 }
1681
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001682 pipe_info.index = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001683 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001684 ALOGD_IF(isDebug(), "%s: Unable to get pipe type = %d",
1685 __FUNCTION__, (int) type);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001686 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001687 }
1688 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001689 return true;
1690}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001691
radhakrishnac9a67412013-09-25 17:40:42 +05301692int MDPCompNonSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1693 PipeLayerPair& PipeLayerPair) {
1694 MdpYUVPipeInfo& mdp_info =
1695 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1696 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1697 eIsFg isFg = IS_FG_OFF;
1698 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1699 eDest lDest = mdp_info.lIndex;
1700 eDest rDest = mdp_info.rIndex;
1701
1702 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1703 lDest, rDest, &PipeLayerPair.rot);
1704}
1705
Saurabh Shah88e4d272013-09-03 13:31:29 -07001706bool MDPCompNonSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001707
Raj Kamal5166b312014-06-06 13:45:20 +05301708 if(!isEnabled() or !mModeOn) {
1709 ALOGD_IF(isDebug(),"%s: MDP Comp not enabled/configured", __FUNCTION__);
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301710 return true;
1711 }
1712
Ramkumar Radhakrishnand8595ae2014-02-06 21:31:29 -08001713 // Set the Handle timeout to true for MDP or MIXED composition.
1714 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount) {
1715 sHandleTimeout = true;
1716 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001717
1718 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001719 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001720
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001721 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1722 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001723 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001724 if(mCurrentFrame.isFBComposed[i]) continue;
1725
Naseer Ahmed5b6708a2012-08-02 13:46:08 -07001726 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001727 private_handle_t *hnd = (private_handle_t *)layer->handle;
1728 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001729 if (!(layer->flags & HWC_COLOR_FILL)) {
1730 ALOGE("%s handle null", __FUNCTION__);
1731 return false;
1732 }
1733 // No PLAY for Color layer
1734 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1735 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001736 }
1737
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001738 int mdpIndex = mCurrentFrame.layerToMDP[i];
1739
radhakrishnac9a67412013-09-25 17:40:42 +05301740 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1741 {
1742 MdpYUVPipeInfo& pipe_info =
1743 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1744 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1745 ovutils::eDest indexL = pipe_info.lIndex;
1746 ovutils::eDest indexR = pipe_info.rIndex;
1747 int fd = hnd->fd;
1748 uint32_t offset = hnd->offset;
1749 if(rot) {
1750 rot->queueBuffer(fd, offset);
1751 fd = rot->getDstMemId();
1752 offset = rot->getDstOffset();
1753 }
1754 if(indexL != ovutils::OV_INVALID) {
1755 ovutils::eDest destL = (ovutils::eDest)indexL;
1756 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1757 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1758 if (!ov.queueBuffer(fd, offset, destL)) {
1759 ALOGE("%s: queueBuffer failed for display:%d",
1760 __FUNCTION__, mDpy);
1761 return false;
1762 }
1763 }
1764
1765 if(indexR != ovutils::OV_INVALID) {
1766 ovutils::eDest destR = (ovutils::eDest)indexR;
1767 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1768 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1769 if (!ov.queueBuffer(fd, offset, destR)) {
1770 ALOGE("%s: queueBuffer failed for display:%d",
1771 __FUNCTION__, mDpy);
1772 return false;
1773 }
1774 }
1775 }
1776 else{
1777 MdpPipeInfoNonSplit& pipe_info =
Saurabh Shah88e4d272013-09-03 13:31:29 -07001778 *(MdpPipeInfoNonSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
radhakrishnac9a67412013-09-25 17:40:42 +05301779 ovutils::eDest dest = pipe_info.index;
1780 if(dest == ovutils::OV_INVALID) {
1781 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001782 return false;
radhakrishnac9a67412013-09-25 17:40:42 +05301783 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001784
radhakrishnac9a67412013-09-25 17:40:42 +05301785 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1786 continue;
1787 }
1788
Arun Kumar K.Rbad65ab2014-06-03 11:54:10 -07001789 int fd = hnd->fd;
1790 uint32_t offset = (uint32_t)hnd->offset;
1791 int index = ctx->mPtorInfo.getPTORArrayIndex(i);
1792 if (!mDpy && (index != -1)) {
Sushil Chauhan4259d872014-05-13 18:17:12 -07001793 hnd = ctx->mCopyBit[mDpy]->getCurrentRenderBuffer();
Arun Kumar K.Rbad65ab2014-06-03 11:54:10 -07001794 fd = hnd->fd;
Sushil Chauhane1474bf2014-07-25 12:20:23 -07001795 offset = 0;
Sushil Chauhan4259d872014-05-13 18:17:12 -07001796 }
1797
radhakrishnac9a67412013-09-25 17:40:42 +05301798 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1799 using pipe: %d", __FUNCTION__, layer,
1800 hnd, dest );
1801
radhakrishnac9a67412013-09-25 17:40:42 +05301802 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1803 if(rot) {
1804 if(!rot->queueBuffer(fd, offset))
1805 return false;
1806 fd = rot->getDstMemId();
1807 offset = rot->getDstOffset();
1808 }
1809
1810 if (!ov.queueBuffer(fd, offset, dest)) {
1811 ALOGE("%s: queueBuffer failed for display:%d ",
1812 __FUNCTION__, mDpy);
1813 return false;
1814 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001815 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001816
1817 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001818 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001819 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001820}
1821
Saurabh Shah88e4d272013-09-03 13:31:29 -07001822//=============MDPCompSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001823
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001824void MDPCompSplit::adjustForSourceSplit(hwc_context_t *ctx,
radhakrishnac9a67412013-09-25 17:40:42 +05301825 hwc_display_contents_1_t* list){
1826 //if 4kx2k yuv layer is totally present in either in left half
1827 //or right half then try splitting the yuv layer to avoid decimation
radhakrishnac9a67412013-09-25 17:40:42 +05301828 const int lSplit = getLeftSplit(ctx, mDpy);
Dileep Kumar Reddi2268dd72014-05-22 22:24:53 +05301829 if(mCurrentFrame.fbZ >= 0) {
1830 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
1831 index++) {
1832 if(!mCurrentFrame.isFBComposed[index]) {
1833 if(mdpNextZOrder == mCurrentFrame.fbZ) {
1834 mdpNextZOrder++;
1835 }
1836 mdpNextZOrder++;
1837 hwc_layer_1_t* layer = &list->hwLayers[index];
1838 private_handle_t *hnd = (private_handle_t *)layer->handle;
1839 if(is4kx2kYuvBuffer(hnd)) {
1840 hwc_rect_t dst = layer->displayFrame;
1841 if((dst.left > lSplit) || (dst.right < lSplit)) {
1842 mCurrentFrame.mdpCount += 1;
1843 }
1844 if(mdpNextZOrder <= mCurrentFrame.fbZ)
1845 mCurrentFrame.fbZ += 1;
1846 mdpNextZOrder++;
1847 }
1848 }
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001849 }
radhakrishnac9a67412013-09-25 17:40:42 +05301850 }
1851}
1852
Saurabh Shah88e4d272013-09-03 13:31:29 -07001853bool MDPCompSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
1854 MdpPipeInfoSplit& pipe_info,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001855 ePipeType type) {
1856 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001857 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001858
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001859 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001860 pipe_info.lIndex = ovutils::OV_INVALID;
1861 pipe_info.rIndex = ovutils::OV_INVALID;
1862
1863 if (dst.left < lSplit) {
1864 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_LEFT);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001865 if(pipe_info.lIndex == ovutils::OV_INVALID)
1866 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001867 }
1868
1869 if(dst.right > lSplit) {
1870 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_RIGHT);
1871 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001872 return false;
1873 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001874
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001875 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001876}
1877
Saurabh Shah88e4d272013-09-03 13:31:29 -07001878bool MDPCompSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001879 hwc_display_contents_1_t* list) {
1880 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001881
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001882 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001883
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001884 hwc_layer_1_t* layer = &list->hwLayers[index];
1885 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301886 hwc_rect_t dst = layer->displayFrame;
1887 const int lSplit = getLeftSplit(ctx, mDpy);
1888 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1889 if((dst.left > lSplit)||(dst.right < lSplit)){
1890 if(allocSplitVGPipesfor4k2k(ctx, list, index)){
1891 continue;
1892 }
1893 }
1894 }
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001895 int mdpIndex = mCurrentFrame.layerToMDP[index];
1896 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001897 info.pipeInfo = new MdpPipeInfoSplit;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001898 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001899 MdpPipeInfoSplit& pipe_info = *(MdpPipeInfoSplit*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001900 ePipeType type = MDPCOMP_OV_ANY;
1901
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001902 if(isYuvBuffer(hnd)) {
1903 type = MDPCOMP_OV_VG;
Sushil Chauhan15a2ea62013-09-04 18:28:36 -07001904 } else if(!qhwc::needsScalingWithSplit(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001905 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001906 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001907 type = MDPCOMP_OV_DMA;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001908 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001909
1910 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001911 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type = %d",
1912 __FUNCTION__, (int) type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001913 return false;
1914 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001915 }
1916 return true;
1917}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001918
radhakrishnac9a67412013-09-25 17:40:42 +05301919int MDPCompSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1920 PipeLayerPair& PipeLayerPair) {
1921 const int lSplit = getLeftSplit(ctx, mDpy);
1922 hwc_rect_t dst = layer->displayFrame;
1923 if((dst.left > lSplit)||(dst.right < lSplit)){
1924 MdpYUVPipeInfo& mdp_info =
1925 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1926 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1927 eIsFg isFg = IS_FG_OFF;
1928 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1929 eDest lDest = mdp_info.lIndex;
1930 eDest rDest = mdp_info.rIndex;
1931
1932 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1933 lDest, rDest, &PipeLayerPair.rot);
1934 }
1935 else{
1936 return configure(ctx, layer, PipeLayerPair);
1937 }
1938}
1939
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001940/*
1941 * Configures pipe(s) for MDP composition
1942 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001943int MDPCompSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001944 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001945 MdpPipeInfoSplit& mdp_info =
1946 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001947 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1948 eIsFg isFg = IS_FG_OFF;
1949 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1950 eDest lDest = mdp_info.lIndex;
1951 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001952
1953 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1954 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1955
Saurabh Shah88e4d272013-09-03 13:31:29 -07001956 return configureSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001957 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001958}
1959
Saurabh Shah88e4d272013-09-03 13:31:29 -07001960bool MDPCompSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001961
Raj Kamal5166b312014-06-06 13:45:20 +05301962 if(!isEnabled() or !mModeOn) {
1963 ALOGD_IF(isDebug(),"%s: MDP Comp not enabled/configured", __FUNCTION__);
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301964 return true;
1965 }
1966
Ramkumar Radhakrishnand8595ae2014-02-06 21:31:29 -08001967 // Set the Handle timeout to true for MDP or MIXED composition.
1968 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount) {
1969 sHandleTimeout = true;
1970 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001971
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001972 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001973 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001974
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001975 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1976 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001977 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001978 if(mCurrentFrame.isFBComposed[i]) continue;
1979
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001980 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001981 private_handle_t *hnd = (private_handle_t *)layer->handle;
1982 if(!hnd) {
1983 ALOGE("%s handle null", __FUNCTION__);
1984 return false;
1985 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001986
1987 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1988 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001989 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001990
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001991 int mdpIndex = mCurrentFrame.layerToMDP[i];
1992
radhakrishnac9a67412013-09-25 17:40:42 +05301993 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1994 {
1995 MdpYUVPipeInfo& pipe_info =
1996 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1997 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1998 ovutils::eDest indexL = pipe_info.lIndex;
1999 ovutils::eDest indexR = pipe_info.rIndex;
2000 int fd = hnd->fd;
2001 uint32_t offset = hnd->offset;
2002 if(rot) {
2003 rot->queueBuffer(fd, offset);
2004 fd = rot->getDstMemId();
2005 offset = rot->getDstOffset();
2006 }
2007 if(indexL != ovutils::OV_INVALID) {
2008 ovutils::eDest destL = (ovutils::eDest)indexL;
2009 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
2010 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
2011 if (!ov.queueBuffer(fd, offset, destL)) {
2012 ALOGE("%s: queueBuffer failed for display:%d",
2013 __FUNCTION__, mDpy);
2014 return false;
2015 }
2016 }
Saurabh Shahacf10202013-02-26 10:15:15 -08002017
radhakrishnac9a67412013-09-25 17:40:42 +05302018 if(indexR != ovutils::OV_INVALID) {
2019 ovutils::eDest destR = (ovutils::eDest)indexR;
2020 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
2021 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
2022 if (!ov.queueBuffer(fd, offset, destR)) {
2023 ALOGE("%s: queueBuffer failed for display:%d",
2024 __FUNCTION__, mDpy);
2025 return false;
2026 }
Saurabh Shaha9da08f2013-07-03 13:27:53 -07002027 }
2028 }
radhakrishnac9a67412013-09-25 17:40:42 +05302029 else{
2030 MdpPipeInfoSplit& pipe_info =
2031 *(MdpPipeInfoSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
2032 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07002033
radhakrishnac9a67412013-09-25 17:40:42 +05302034 ovutils::eDest indexL = pipe_info.lIndex;
2035 ovutils::eDest indexR = pipe_info.rIndex;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002036
radhakrishnac9a67412013-09-25 17:40:42 +05302037 int fd = hnd->fd;
Arun Kumar K.Rbad65ab2014-06-03 11:54:10 -07002038 uint32_t offset = (uint32_t)hnd->offset;
2039 int index = ctx->mPtorInfo.getPTORArrayIndex(i);
2040 if (!mDpy && (index != -1)) {
2041 hnd = ctx->mCopyBit[mDpy]->getCurrentRenderBuffer();
2042 fd = hnd->fd;
Sushil Chauhane1474bf2014-07-25 12:20:23 -07002043 offset = 0;
Arun Kumar K.Rbad65ab2014-06-03 11:54:10 -07002044 }
radhakrishnac9a67412013-09-25 17:40:42 +05302045
Tatenda Chipeperekwa2f8cd2b2014-04-14 10:36:06 -07002046 if(ctx->mAD->draw(ctx, fd, offset)) {
2047 fd = ctx->mAD->getDstFd(ctx);
2048 offset = ctx->mAD->getDstOffset(ctx);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002049 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002050
radhakrishnac9a67412013-09-25 17:40:42 +05302051 if(rot) {
2052 rot->queueBuffer(fd, offset);
2053 fd = rot->getDstMemId();
2054 offset = rot->getDstOffset();
2055 }
2056
2057 //************* play left mixer **********
2058 if(indexL != ovutils::OV_INVALID) {
2059 ovutils::eDest destL = (ovutils::eDest)indexL;
2060 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
2061 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
2062 if (!ov.queueBuffer(fd, offset, destL)) {
2063 ALOGE("%s: queueBuffer failed for left mixer",
2064 __FUNCTION__);
2065 return false;
2066 }
2067 }
2068
2069 //************* play right mixer **********
2070 if(indexR != ovutils::OV_INVALID) {
2071 ovutils::eDest destR = (ovutils::eDest)indexR;
2072 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
2073 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
2074 if (!ov.queueBuffer(fd, offset, destR)) {
2075 ALOGE("%s: queueBuffer failed for right mixer",
2076 __FUNCTION__);
2077 return false;
2078 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002079 }
2080 }
Saurabh Shahacf10202013-02-26 10:15:15 -08002081
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002082 layerProp[i].mFlags &= ~HWC_MDPCOMP;
2083 }
Saurabh Shahacf10202013-02-26 10:15:15 -08002084
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002085 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002086}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002087}; //namespace
2088