blob: 0b4cbe0a3d7d2f178dde831d14271e8ef7e698da [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>
29
Saurabh Shah85234ec2013-04-12 17:09:00 -070030using namespace overlay;
Saurabh Shahbd2d0832013-04-04 14:33:08 -070031using namespace qdutils;
Saurabh Shahacf10202013-02-26 10:15:15 -080032using namespace overlay::utils;
33namespace ovutils = overlay::utils;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070034
Naseer Ahmed7c958d42012-07-31 18:57:03 -070035namespace qhwc {
36
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080037//==============MDPComp========================================================
38
Naseer Ahmed7c958d42012-07-31 18:57:03 -070039IdleInvalidator *MDPComp::idleInvalidator = NULL;
40bool MDPComp::sIdleFallBack = false;
41bool MDPComp::sDebugLogs = false;
Naseer Ahmed54821fe2012-11-28 18:44:38 -050042bool MDPComp::sEnabled = false;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -070043bool MDPComp::sEnableMixedMode = true;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -070044bool MDPComp::sEnablePartialFrameUpdate = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080045int MDPComp::sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
Saurabh Shahf5f2b132013-11-25 12:08:35 -080046double MDPComp::sMaxBw = 0.0;
Saurabh Shah3c1a6b02013-11-22 11:10:20 -080047double MDPComp::sBwClaimed = 0.0;
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 Sankaran6a9bb9e2013-08-01 14:19:26 -0700117 if(property_get("persist.hwc.partialupdate.enable", property, NULL) > 0) {
118 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 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700157 return true;
158}
159
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800160void MDPComp::reset(hwc_context_t *ctx) {
161 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700162 mCurrentFrame.reset(numLayers);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800163 ctx->mOverlay->clear(mDpy);
164 ctx->mLayerRotMap[mDpy]->clear();
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700165}
166
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700167void MDPComp::timeout_handler(void *udata) {
168 struct hwc_context_t* ctx = (struct hwc_context_t*)(udata);
169
170 if(!ctx) {
171 ALOGE("%s: received empty data in timer callback", __FUNCTION__);
172 return;
173 }
174
Jesse Hall3be78d92012-08-21 15:12:23 -0700175 if(!ctx->proc) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700176 ALOGE("%s: HWC proc not registered", __FUNCTION__);
177 return;
178 }
179 sIdleFallBack = true;
180 /* Trigger SF to redraw the current frame */
Jesse Hall3be78d92012-08-21 15:12:23 -0700181 ctx->proc->invalidate(ctx->proc);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700182}
183
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800184void MDPComp::setMDPCompLayerFlags(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800185 hwc_display_contents_1_t* list) {
186 LayerProp *layerProp = ctx->layerProp[mDpy];
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800187
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800188 for(int index = 0; index < ctx->listStats[mDpy].numAppLayers; index++) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800189 hwc_layer_1_t* layer = &(list->hwLayers[index]);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800190 if(!mCurrentFrame.isFBComposed[index]) {
191 layerProp[index].mFlags |= HWC_MDPCOMP;
192 layer->compositionType = HWC_OVERLAY;
193 layer->hints |= HWC_HINT_CLEAR_FB;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800194 } else {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700195 /* Drop the layer when its already present in FB OR when it lies
196 * outside frame's ROI */
197 if(!mCurrentFrame.needsRedraw || mCurrentFrame.drop[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800198 layer->compositionType = HWC_OVERLAY;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700199 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800200 }
201 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700202}
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500203
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800204void MDPComp::setRedraw(hwc_context_t *ctx,
205 hwc_display_contents_1_t* list) {
206 mCurrentFrame.needsRedraw = false;
207 if(!mCachedFrame.isSameFrame(mCurrentFrame, list) ||
208 (list->flags & HWC_GEOMETRY_CHANGED) ||
209 isSkipPresent(ctx, mDpy)) {
210 mCurrentFrame.needsRedraw = true;
211 }
212}
213
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800214MDPComp::FrameInfo::FrameInfo() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700215 reset(0);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800216}
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800217
Saurabh Shahaa236822013-04-24 18:07:26 -0700218void MDPComp::FrameInfo::reset(const int& numLayers) {
219 for(int i = 0 ; i < MAX_PIPES_PER_MIXER && numLayers; i++ ) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800220 if(mdpToLayer[i].pipeInfo) {
221 delete mdpToLayer[i].pipeInfo;
222 mdpToLayer[i].pipeInfo = NULL;
223 //We dont own the rotator
224 mdpToLayer[i].rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800225 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800226 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800227
228 memset(&mdpToLayer, 0, sizeof(mdpToLayer));
229 memset(&layerToMDP, -1, sizeof(layerToMDP));
Saurabh Shahaa236822013-04-24 18:07:26 -0700230 memset(&isFBComposed, 1, sizeof(isFBComposed));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800231
Saurabh Shahaa236822013-04-24 18:07:26 -0700232 layerCount = numLayers;
233 fbCount = numLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800234 mdpCount = 0;
Saurabh Shah2f3895f2013-05-02 10:13:31 -0700235 needsRedraw = true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800236 fbZ = 0;
237}
238
Saurabh Shahaa236822013-04-24 18:07:26 -0700239void MDPComp::FrameInfo::map() {
240 // populate layer and MDP maps
241 int mdpIdx = 0;
242 for(int idx = 0; idx < layerCount; idx++) {
243 if(!isFBComposed[idx]) {
244 mdpToLayer[mdpIdx].listIndex = idx;
245 layerToMDP[idx] = mdpIdx++;
246 }
247 }
248}
249
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800250MDPComp::LayerCache::LayerCache() {
251 reset();
252}
253
254void MDPComp::LayerCache::reset() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700255 memset(&hnd, 0, sizeof(hnd));
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530256 memset(&isFBComposed, true, sizeof(isFBComposed));
257 memset(&drop, false, sizeof(drop));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800258 layerCount = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -0700259}
260
261void MDPComp::LayerCache::cacheAll(hwc_display_contents_1_t* list) {
262 const int numAppLayers = list->numHwLayers - 1;
263 for(int i = 0; i < numAppLayers; i++) {
264 hnd[i] = list->hwLayers[i].handle;
265 }
266}
267
268void MDPComp::LayerCache::updateCounts(const FrameInfo& curFrame) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700269 layerCount = curFrame.layerCount;
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530270 memcpy(&isFBComposed, &curFrame.isFBComposed, sizeof(isFBComposed));
271 memcpy(&drop, &curFrame.drop, sizeof(drop));
272}
273
Jeykumar Sankaran988d3682013-11-15 11:57:16 -0800274bool MDPComp::LayerCache::isSameFrame(const FrameInfo& curFrame,
275 hwc_display_contents_1_t* list) {
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530276 if(layerCount != curFrame.layerCount)
277 return false;
278 for(int i = 0; i < curFrame.layerCount; i++) {
279 if((curFrame.isFBComposed[i] != isFBComposed[i]) ||
280 (curFrame.drop[i] != drop[i])) {
281 return false;
282 }
Jeykumar Sankaran988d3682013-11-15 11:57:16 -0800283 if(curFrame.isFBComposed[i] &&
284 (hnd[i] != list->hwLayers[i].handle)){
285 return false;
286 }
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530287 }
288 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800289}
290
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700291bool MDPComp::isSupportedForMDPComp(hwc_context_t *ctx, hwc_layer_1_t* layer) {
292 private_handle_t *hnd = (private_handle_t *)layer->handle;
293 if((not isYuvBuffer(hnd) and has90Transform(layer)) or
294 (not isValidDimension(ctx,layer))
295 //More conditions here, SKIP, sRGB+Blend etc
296 ) {
297 return false;
298 }
299 return true;
300}
301
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530302bool MDPComp::isValidDimension(hwc_context_t *ctx, hwc_layer_1_t *layer) {
Saurabh Shah4fdde762013-04-30 18:47:33 -0700303 const int dpy = HWC_DISPLAY_PRIMARY;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800304 private_handle_t *hnd = (private_handle_t *)layer->handle;
305
306 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -0700307 if (layer->flags & HWC_COLOR_FILL) {
308 // Color layer
309 return true;
310 }
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800311 ALOGE("%s: layer handle is NULL", __FUNCTION__);
312 return false;
313 }
314
Naseer Ahmede850a802013-09-06 13:12:52 -0400315 //XXX: Investigate doing this with pixel phase on MDSS
Naseer Ahmede77f8082013-10-10 13:42:48 -0400316 if(!isSecureBuffer(hnd) && isNonIntegralSourceCrop(layer->sourceCropf))
Naseer Ahmede850a802013-09-06 13:12:52 -0400317 return false;
318
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800319 int hw_w = ctx->dpyAttr[mDpy].xres;
320 int hw_h = ctx->dpyAttr[mDpy].yres;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800321
Saurabh Shah62e1d732013-09-17 10:44:05 -0700322 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700323 hwc_rect_t dst = layer->displayFrame;
Saurabh Shah4fdde762013-04-30 18:47:33 -0700324 int crop_w = crop.right - crop.left;
325 int crop_h = crop.bottom - crop.top;
326 int dst_w = dst.right - dst.left;
327 int dst_h = dst.bottom - dst.top;
328 float w_dscale = ceilf((float)crop_w / (float)dst_w);
329 float h_dscale = ceilf((float)crop_h / (float)dst_h);
330
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800331 /* Workaround for MDP HW limitation in DSI command mode panels where
332 * FPS will not go beyond 30 if buffers on RGB pipes are of width or height
333 * less than 5 pixels
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530334 * There also is a HW limilation in MDP, minimum block size is 2x2
335 * Fallback to GPU if height is less than 2.
336 */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800337 if((crop_w < 5)||(crop_h < 5))
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800338 return false;
339
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800340 if((w_dscale > 1.0f) || (h_dscale > 1.0f)) {
341 const uint32_t downscale =
Saurabh Shah4fdde762013-04-30 18:47:33 -0700342 qdutils::MDPVersion::getInstance().getMaxMDPDownscale();
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800343 if(ctx->mMDP.version >= qdutils::MDSS_V5) {
344 /* Workaround for downscales larger than 4x.
345 * Will be removed once decimator block is enabled for MDSS
346 */
347 if(!qdutils::MDPVersion::getInstance().supportsDecimation()) {
348 if(crop_w > MAX_DISPLAY_DIM || w_dscale > downscale ||
349 h_dscale > downscale)
350 return false;
351 } else {
352 if(w_dscale > 64 || h_dscale > 64)
353 return false;
354 }
355 } else { //A-family
356 if(w_dscale > downscale || h_dscale > downscale)
Saurabh Shah4fdde762013-04-30 18:47:33 -0700357 return false;
358 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700359 }
360
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800361 return true;
362}
363
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700364ovutils::eDest MDPComp::getMdpPipe(hwc_context_t *ctx, ePipeType type,
365 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800366 overlay::Overlay& ov = *ctx->mOverlay;
367 ovutils::eDest mdp_pipe = ovutils::OV_INVALID;
368
369 switch(type) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800370 case MDPCOMP_OV_DMA:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700371 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_DMA, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800372 if(mdp_pipe != ovutils::OV_INVALID) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800373 return mdp_pipe;
374 }
375 case MDPCOMP_OV_ANY:
376 case MDPCOMP_OV_RGB:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700377 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800378 if(mdp_pipe != ovutils::OV_INVALID) {
379 return mdp_pipe;
380 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800381
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800382 if(type == MDPCOMP_OV_RGB) {
383 //Requested only for RGB pipe
384 break;
385 }
386 case MDPCOMP_OV_VG:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700387 return ov.nextPipe(ovutils::OV_MDP_PIPE_VG, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800388 default:
389 ALOGE("%s: Invalid pipe type",__FUNCTION__);
390 return ovutils::OV_INVALID;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800391 };
392 return ovutils::OV_INVALID;
393}
394
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800395bool MDPComp::isFrameDoable(hwc_context_t *ctx) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700396 bool ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700397 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800398
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800399 if(!isEnabled()) {
400 ALOGD_IF(isDebug(),"%s: MDP Comp. not enabled.", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700401 ret = false;
Saurabh Shahd4e65852013-06-17 11:33:53 -0700402 } else if(qdutils::MDPVersion::getInstance().is8x26() &&
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700403 ctx->mVideoTransFlag && ctx->mVirtualDisplay->isConnected()) {
Saurabh Shahd4e65852013-06-17 11:33:53 -0700404 //1 Padding round to shift pipes across mixers
405 ALOGD_IF(isDebug(),"%s: MDP Comp. video transition padding round",
406 __FUNCTION__);
407 ret = false;
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700408 } else if(ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isConfiguring ||
409 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isConfiguring) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800410 ALOGD_IF( isDebug(),"%s: External Display connection is pending",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800411 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700412 ret = false;
Saurabh Shahaa236822013-04-24 18:07:26 -0700413 } else if(ctx->isPaddingRound) {
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700414 ctx->isPaddingRound = false;
415 ALOGD_IF(isDebug(), "%s: padding round",__FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700416 ret = false;
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700417 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700418 return ret;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800419}
420
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800421/*
422 * 1) Identify layers that are not visible in the updating ROI and drop them
423 * from composition.
424 * 2) If we have a scaling layers which needs cropping against generated ROI.
425 * Reset ROI to full resolution.
426 */
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700427bool MDPComp::validateAndApplyROI(hwc_context_t *ctx,
428 hwc_display_contents_1_t* list, hwc_rect_t roi) {
429 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
430
431 if(!isValidRect(roi))
432 return false;
433
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800434 hwc_rect_t visibleRect = roi;
435
436 for(int i = numAppLayers - 1; i >= 0; i--){
437
438 if(!isValidRect(visibleRect)) {
439 mCurrentFrame.drop[i] = true;
440 mCurrentFrame.dropCount++;
441 }
442
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700443 const hwc_layer_1_t* layer = &list->hwLayers[i];
444
445 hwc_rect_t dstRect = layer->displayFrame;
Arun Kumar K.R91090c72013-10-28 19:40:18 -0700446 hwc_rect_t srcRect = integerizeSourceCrop(layer->sourceCropf);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700447 int transform = layer->transform;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700448
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800449 hwc_rect_t res = getIntersection(visibleRect, dstRect);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700450
451 int res_w = res.right - res.left;
452 int res_h = res.bottom - res.top;
453 int dst_w = dstRect.right - dstRect.left;
454 int dst_h = dstRect.bottom - dstRect.top;
455
456 if(!isValidRect(res)) {
457 mCurrentFrame.drop[i] = true;
458 mCurrentFrame.dropCount++;
459 }else {
460 /* Reset frame ROI when any layer which needs scaling also needs ROI
461 * cropping */
462 if((res_w != dst_w || res_h != dst_h) &&
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530463 needsScaling (layer)) {
Arpita Banerjeed8965982013-11-08 17:27:33 -0800464 ALOGI("%s: Resetting ROI due to scaling", __FUNCTION__);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700465 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
466 mCurrentFrame.dropCount = 0;
467 return false;
468 }
469 }
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800470
471 if (layer->blending == HWC_BLENDING_NONE)
472 visibleRect = deductRect(visibleRect, res);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700473 }
474 return true;
475}
476
477void MDPComp::generateROI(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
478 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
479
480 if(!sEnablePartialFrameUpdate) {
481 return;
482 }
483
484 if(mDpy || isDisplaySplit(ctx, mDpy)){
485 ALOGE_IF(isDebug(), "%s: ROI not supported for"
486 "the (1) external / virtual display's (2) dual DSI displays",
487 __FUNCTION__);
488 return;
489 }
490
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800491 if(isSkipPresent(ctx, mDpy))
492 return;
493
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700494 if(list->flags & HWC_GEOMETRY_CHANGED)
495 return;
496
497 struct hwc_rect roi = (struct hwc_rect){0, 0, 0, 0};
498 for(int index = 0; index < numAppLayers; index++ ) {
499 if ((mCachedFrame.hnd[index] != list->hwLayers[index].handle) ||
500 isYuvBuffer((private_handle_t *)list->hwLayers[index].handle)) {
501 hwc_rect_t dstRect = list->hwLayers[index].displayFrame;
Arun Kumar K.R91090c72013-10-28 19:40:18 -0700502 hwc_rect_t srcRect = integerizeSourceCrop(
503 list->hwLayers[index].sourceCropf);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700504 int transform = list->hwLayers[index].transform;
505
506 /* Intersect against display boundaries */
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700507 roi = getUnion(roi, dstRect);
508 }
509 }
510
511 if(!validateAndApplyROI(ctx, list, roi)){
512 roi = (struct hwc_rect) {0, 0,
513 (int)ctx->dpyAttr[mDpy].xres, (int)ctx->dpyAttr[mDpy].yres};
514 }
515
516 ctx->listStats[mDpy].roi.x = roi.left;
517 ctx->listStats[mDpy].roi.y = roi.top;
518 ctx->listStats[mDpy].roi.w = roi.right - roi.left;
519 ctx->listStats[mDpy].roi.h = roi.bottom - roi.top;
520
521 ALOGD_IF(isDebug(),"%s: generated ROI: [%d, %d, %d, %d]", __FUNCTION__,
522 roi.left, roi.top, roi.right, roi.bottom);
523}
524
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800525/* Checks for conditions where all the layers marked for MDP comp cannot be
526 * bypassed. On such conditions we try to bypass atleast YUV layers */
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800527bool MDPComp::tryFullFrame(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800528 hwc_display_contents_1_t* list){
529
Saurabh Shahaa236822013-04-24 18:07:26 -0700530 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800531
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -0700532 if(sIdleFallBack && !ctx->listStats[mDpy].secureUI) {
Saurabh Shah2d998a92013-05-14 17:55:58 -0700533 ALOGD_IF(isDebug(), "%s: Idle fallback dpy %d",__FUNCTION__, mDpy);
534 return false;
535 }
536
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800537 if(isSkipPresent(ctx, mDpy)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700538 ALOGD_IF(isDebug(),"%s: SKIP present: %d",
539 __FUNCTION__,
540 isSkipPresent(ctx, mDpy));
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800541 return false;
542 }
543
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800544 for(int i = 0; i < numAppLayers; ++i) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800545 hwc_layer_1_t* layer = &list->hwLayers[i];
546 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800547
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700548 if(isYuvBuffer(hnd) && has90Transform(layer)) {
549 if(!canUseRotator(ctx, mDpy)) {
550 ALOGD_IF(isDebug(), "%s: Can't use rotator for dpy %d",
551 __FUNCTION__, mDpy);
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700552 return false;
553 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800554 }
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530555
556 //For 8x26 with panel width>1k, if RGB layer needs HFLIP fail mdp comp
557 // may not need it if Gfx pre-rotation can handle all flips & rotations
558 if(qdutils::MDPVersion::getInstance().is8x26() &&
559 (ctx->dpyAttr[mDpy].xres > 1024) &&
560 (layer->transform & HWC_TRANSFORM_FLIP_H) &&
561 (!isYuvBuffer(hnd)))
562 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800563 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700564
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700565 if(ctx->mAD->isDoable()) {
566 return false;
567 }
568
Saurabh Shahaa236822013-04-24 18:07:26 -0700569 //If all above hard conditions are met we can do full or partial MDP comp.
570 bool ret = false;
571 if(fullMDPComp(ctx, list)) {
572 ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700573 } else if(partialMDPComp(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700574 ret = true;
575 }
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530576
Saurabh Shahaa236822013-04-24 18:07:26 -0700577 return ret;
578}
579
580bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700581 //Will benefit presentation / secondary-only layer.
582 if((mDpy > HWC_DISPLAY_PRIMARY) &&
583 (list->numHwLayers - 1) > MAX_SEC_LAYERS) {
584 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
585 return false;
586 }
587
588 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
589 for(int i = 0; i < numAppLayers; i++) {
590 hwc_layer_1_t* layer = &list->hwLayers[i];
591 if(not isSupportedForMDPComp(ctx, layer)) {
592 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",__FUNCTION__);
593 return false;
594 }
Yang Xu9c1eb2b2013-11-26 01:28:13 +0800595
596 //For 8x26, if there is only one layer which needs scale for secondary
597 //while no scale for primary display, DMA pipe is occupied by primary.
598 //If need to fall back to GLES composition, virtual display lacks DMA
599 //pipe and error is reported.
600 if(qdutils::MDPVersion::getInstance().is8x26() &&
601 mDpy >= HWC_DISPLAY_EXTERNAL &&
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530602 qhwc::needsScaling(layer))
Yang Xu9c1eb2b2013-11-26 01:28:13 +0800603 return false;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700604 }
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800605
Saurabh Shahaa236822013-04-24 18:07:26 -0700606 mCurrentFrame.fbCount = 0;
607 mCurrentFrame.fbZ = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700608 memcpy(&mCurrentFrame.isFBComposed, &mCurrentFrame.drop,
609 sizeof(mCurrentFrame.isFBComposed));
610 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount -
611 mCurrentFrame.dropCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700612
radhakrishnac9a67412013-09-25 17:40:42 +0530613 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800614 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530615 }
616
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800617 if(!postHeuristicsHandling(ctx, list)) {
618 ALOGD_IF(isDebug(), "post heuristic handling failed");
619 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700620 return false;
621 }
622
Saurabh Shahaa236822013-04-24 18:07:26 -0700623 return true;
624}
625
626bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
627{
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700628 if(!sEnableMixedMode) {
629 //Mixed mode is disabled. No need to even try caching.
630 return false;
631 }
632
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700633 bool ret = false;
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800634 if(list->flags & HWC_GEOMETRY_CHANGED) { //Try load based first
635 ret = loadBasedCompPreferGPU(ctx, list) or
636 loadBasedCompPreferMDP(ctx, list) or
637 cacheBasedComp(ctx, list);
638 } else {
639 ret = cacheBasedComp(ctx, list) or
640 loadBasedCompPreferGPU(ctx, list) or
Saurabh Shahb772ae32013-11-18 15:40:02 -0800641 loadBasedCompPreferMDP(ctx, list);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700642 }
643
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700644 return ret;
645}
646
647bool MDPComp::cacheBasedComp(hwc_context_t *ctx,
648 hwc_display_contents_1_t* list) {
649 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700650 mCurrentFrame.reset(numAppLayers);
651 updateLayerCache(ctx, list);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700652
653 //If an MDP marked layer is unsupported cannot do partial MDP Comp
654 for(int i = 0; i < numAppLayers; i++) {
655 if(!mCurrentFrame.isFBComposed[i]) {
656 hwc_layer_1_t* layer = &list->hwLayers[i];
657 if(not isSupportedForMDPComp(ctx, layer)) {
658 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",
659 __FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800660 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700661 return false;
662 }
663 }
664 }
665
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700666 updateYUV(ctx, list, false /*secure only*/);
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530667 bool ret = markLayersForCaching(ctx, list); //sets up fbZ also
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700668 if(!ret) {
669 ALOGD_IF(isDebug(),"%s: batching failed, dpy %d",__FUNCTION__, mDpy);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800670 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700671 return false;
672 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700673
674 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700675
radhakrishnac9a67412013-09-25 17:40:42 +0530676 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800677 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530678 }
679
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700680 //Will benefit cases where a video has non-updating background.
681 if((mDpy > HWC_DISPLAY_PRIMARY) and
682 (mdpCount > MAX_SEC_LAYERS)) {
683 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800684 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700685 return false;
686 }
687
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800688 if(!postHeuristicsHandling(ctx, list)) {
689 ALOGD_IF(isDebug(), "post heuristic handling failed");
690 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700691 return false;
692 }
693
Saurabh Shahaa236822013-04-24 18:07:26 -0700694 return true;
695}
696
Saurabh Shahb772ae32013-11-18 15:40:02 -0800697bool MDPComp::loadBasedCompPreferGPU(hwc_context_t *ctx,
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700698 hwc_display_contents_1_t* list) {
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800699 if(not isLoadBasedCompDoable(ctx, list)) {
700 return false;
701 }
702
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700703 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
704 mCurrentFrame.reset(numAppLayers);
705
Saurabh Shahb772ae32013-11-18 15:40:02 -0800706 int stagesForMDP = min(sMaxPipesPerMixer, ctx->mOverlay->availablePipes(
707 mDpy, Overlay::MIXER_DEFAULT));
708 //If MDP has X possible stages, it can take X layers.
709 const int batchSize = numAppLayers - (stagesForMDP - 1); //1 for FB
710
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700711 if(batchSize <= 0) {
712 ALOGD_IF(isDebug(), "%s: Not attempting", __FUNCTION__);
713 return false;
714 }
715
716 int minBatchStart = -1;
717 size_t minBatchPixelCount = SIZE_MAX;
718
719 for(int i = 0; i <= numAppLayers - batchSize; i++) {
720 uint32_t batchPixelCount = 0;
721 for(int j = i; j < i + batchSize; j++) {
722 hwc_layer_1_t* layer = &list->hwLayers[j];
Arun Kumar K.R91090c72013-10-28 19:40:18 -0700723 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700724 batchPixelCount += (crop.right - crop.left) *
725 (crop.bottom - crop.top);
726 }
727
728 if(batchPixelCount < minBatchPixelCount) {
729 minBatchPixelCount = batchPixelCount;
730 minBatchStart = i;
731 }
732 }
733
734 if(minBatchStart < 0) {
735 ALOGD_IF(isDebug(), "%s: No batch found batchSize %d numAppLayers %d",
736 __FUNCTION__, batchSize, numAppLayers);
737 return false;
738 }
739
740 for(int i = 0; i < numAppLayers; i++) {
741 if(i < minBatchStart || i >= minBatchStart + batchSize) {
742 hwc_layer_1_t* layer = &list->hwLayers[i];
743 if(not isSupportedForMDPComp(ctx, layer)) {
744 ALOGD_IF(isDebug(), "%s: MDP unsupported layer found at %d",
745 __FUNCTION__, i);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800746 reset(ctx);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700747 return false;
748 }
749 mCurrentFrame.isFBComposed[i] = false;
750 }
751 }
752
753 mCurrentFrame.fbZ = minBatchStart;
754 mCurrentFrame.fbCount = batchSize;
755 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - batchSize;
756
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800757 ALOGD_IF(isDebug(), "%s: fbZ %d batchSize %d",
758 __FUNCTION__, mCurrentFrame.fbZ, batchSize);
759
radhakrishnac9a67412013-09-25 17:40:42 +0530760 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800761 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530762 }
763
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800764 if(!postHeuristicsHandling(ctx, list)) {
765 ALOGD_IF(isDebug(), "post heuristic handling failed");
766 reset(ctx);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700767 return false;
768 }
769
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700770 return true;
771}
772
Saurabh Shahb772ae32013-11-18 15:40:02 -0800773bool MDPComp::loadBasedCompPreferMDP(hwc_context_t *ctx,
774 hwc_display_contents_1_t* list) {
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800775 if(not isLoadBasedCompDoable(ctx, list)) {
776 return false;
777 }
778
Saurabh Shahb772ae32013-11-18 15:40:02 -0800779 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800780 mCurrentFrame.reset(numAppLayers);
781
Saurabh Shahb772ae32013-11-18 15:40:02 -0800782 //Full screen is from ib perspective, not actual full screen
783 const int bpp = 4;
784 double panelRefRate =
785 1000000000.0 / ctx->dpyAttr[mDpy].vsync_period;
786
787 double bwLeft = sMaxBw - sBwClaimed;
788
789 const int fullScreenLayers = bwLeft * 1000000000 / (ctx->dpyAttr[mDpy].xres
790 * ctx->dpyAttr[mDpy].yres * bpp * panelRefRate);
791
792 const int fbBatchSize = numAppLayers - (fullScreenLayers - 1);
793 //If batch size is not at least 2, we aren't really preferring MDP, since
794 //only 1 layer going to GPU could actually translate into an entire FB
795 //needed to be fetched by MDP, thus needing more b/w rather than less.
796 if(fbBatchSize < 2 || fbBatchSize > numAppLayers) {
797 ALOGD_IF(isDebug(), "%s: Not attempting", __FUNCTION__);
798 return false;
799 }
800
801 //Top-most layers constitute FB batch
802 const int fbBatchStart = numAppLayers - fbBatchSize;
803
804 //Bottom-most layers constitute MDP batch
805 for(int i = 0; i < fbBatchStart; i++) {
806 hwc_layer_1_t* layer = &list->hwLayers[i];
807 if(not isSupportedForMDPComp(ctx, layer)) {
808 ALOGD_IF(isDebug(), "%s: MDP unsupported layer found at %d",
809 __FUNCTION__, i);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800810 reset(ctx);
Saurabh Shahb772ae32013-11-18 15:40:02 -0800811 return false;
812 }
813 mCurrentFrame.isFBComposed[i] = false;
814 }
815
816 mCurrentFrame.fbZ = fbBatchStart;
817 mCurrentFrame.fbCount = fbBatchSize;
818 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - fbBatchSize;
819
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800820 ALOGD_IF(isDebug(), "%s: FB Z %d, num app layers %d, MDP Batch Size %d",
821 __FUNCTION__, mCurrentFrame.fbZ, numAppLayers,
822 numAppLayers - fbBatchSize);
823
radhakrishnac9a67412013-09-25 17:40:42 +0530824 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800825 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530826 }
827
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800828 if(!postHeuristicsHandling(ctx, list)) {
829 ALOGD_IF(isDebug(), "post heuristic handling failed");
830 reset(ctx);
Saurabh Shahb772ae32013-11-18 15:40:02 -0800831 return false;
832 }
833
Saurabh Shahb772ae32013-11-18 15:40:02 -0800834 return true;
835}
836
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700837bool MDPComp::isLoadBasedCompDoable(hwc_context_t *ctx,
838 hwc_display_contents_1_t* list) {
Prabhanjan Kandula3dbbd882013-12-11 14:43:46 +0530839 if(mDpy or isSecurePresent(ctx, mDpy) or
840 isYuvPresent(ctx, mDpy)) {
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700841 return false;
842 }
843 return true;
844}
845
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800846bool MDPComp::tryVideoOnly(hwc_context_t *ctx,
847 hwc_display_contents_1_t* list) {
848 const bool secureOnly = true;
849 return videoOnlyComp(ctx, list, not secureOnly) or
850 videoOnlyComp(ctx, list, secureOnly);
851}
852
853bool MDPComp::videoOnlyComp(hwc_context_t *ctx,
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700854 hwc_display_contents_1_t* list, bool secureOnly) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700855 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700856
Saurabh Shahaa236822013-04-24 18:07:26 -0700857 mCurrentFrame.reset(numAppLayers);
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700858 updateYUV(ctx, list, secureOnly);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700859 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700860
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800861 if(!isYuvPresent(ctx, mDpy) or (mdpCount == 0)) {
862 reset(ctx);
Saurabh Shahaa236822013-04-24 18:07:26 -0700863 return false;
864 }
865
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -0800866 /* Bail out if we are processing only secured video layers
867 * and we dont have any */
868 if(!isSecurePresent(ctx, mDpy) && secureOnly){
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800869 reset(ctx);
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -0800870 return false;
871 }
872
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800873 if(mCurrentFrame.fbCount)
874 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
Saurabh Shah4fdde762013-04-30 18:47:33 -0700875
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800876 if(sEnable4k2kYUVSplit){
877 adjustForSourceSplit(ctx, list);
878 }
879
880 if(!postHeuristicsHandling(ctx, list)) {
881 ALOGD_IF(isDebug(), "post heuristic handling failed");
882 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700883 return false;
884 }
885
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800886 return true;
887}
888
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800889/* Checks for conditions where YUV layers cannot be bypassed */
890bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -0700891 if(isSkipLayer(layer)) {
Saurabh Shahe2474082013-05-15 16:32:13 -0700892 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800893 return false;
894 }
895
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700896 if(layer->transform & HWC_TRANSFORM_ROT_90 && !canUseRotator(ctx,mDpy)) {
897 ALOGD_IF(isDebug(), "%s: no free DMA pipe",__FUNCTION__);
898 return false;
899 }
900
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800901 if(isSecuring(ctx, layer)) {
902 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
903 return false;
904 }
905
Saurabh Shah4fdde762013-04-30 18:47:33 -0700906 if(!isValidDimension(ctx, layer)) {
907 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
908 __FUNCTION__);
909 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800910 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700911
Naseer Ahmeddc61a972013-07-10 17:50:54 -0400912 if(layer->planeAlpha < 0xFF) {
913 ALOGD_IF(isDebug(), "%s: Cannot handle YUV layer with plane alpha\
914 in video only mode",
915 __FUNCTION__);
916 return false;
917 }
918
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800919 return true;
920}
921
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530922/* starts at fromIndex and check for each layer to find
923 * if it it has overlapping with any Updating layer above it in zorder
924 * till the end of the batch. returns true if it finds any intersection */
925bool MDPComp::canPushBatchToTop(const hwc_display_contents_1_t* list,
926 int fromIndex, int toIndex) {
927 for(int i = fromIndex; i < toIndex; i++) {
928 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
929 if(intersectingUpdatingLayers(list, i+1, toIndex, i)) {
930 return false;
931 }
932 }
933 }
934 return true;
935}
936
937/* Checks if given layer at targetLayerIndex has any
938 * intersection with all the updating layers in beween
939 * fromIndex and toIndex. Returns true if it finds intersectiion */
940bool MDPComp::intersectingUpdatingLayers(const hwc_display_contents_1_t* list,
941 int fromIndex, int toIndex, int targetLayerIndex) {
942 for(int i = fromIndex; i <= toIndex; i++) {
943 if(!mCurrentFrame.isFBComposed[i]) {
944 if(areLayersIntersecting(&list->hwLayers[i],
945 &list->hwLayers[targetLayerIndex])) {
946 return true;
947 }
948 }
949 }
950 return false;
951}
952
953int MDPComp::getBatch(hwc_display_contents_1_t* list,
954 int& maxBatchStart, int& maxBatchEnd,
955 int& maxBatchCount) {
956 int i = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530957 int fbZOrder =-1;
958 while (i < mCurrentFrame.layerCount) {
959 int batchCount = 0;
960 int batchStart = i;
961 int batchEnd = i;
962 int fbZ = batchStart;
963 int firstZReverseIndex = -1;
Prabhanjan Kandula0ed2cc92013-12-06 12:39:04 +0530964 int updatingLayersAbove = 0;//Updating layer count in middle of batch
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530965 while(i < mCurrentFrame.layerCount) {
966 if(!mCurrentFrame.isFBComposed[i]) {
967 if(!batchCount) {
968 i++;
969 break;
970 }
971 updatingLayersAbove++;
972 i++;
973 continue;
974 } else {
975 if(mCurrentFrame.drop[i]) {
976 i++;
977 continue;
978 } else if(updatingLayersAbove <= 0) {
979 batchCount++;
980 batchEnd = i;
981 i++;
982 continue;
983 } else { //Layer is FBComposed, not a drop & updatingLayer > 0
984
985 // We have a valid updating layer already. If layer-i not
986 // have overlapping with all updating layers in between
987 // batch-start and i, then we can add layer i to batch.
988 if(!intersectingUpdatingLayers(list, batchStart, i-1, i)) {
989 batchCount++;
990 batchEnd = i;
991 i++;
992 continue;
993 } else if(canPushBatchToTop(list, batchStart, i)) {
994 //If All the non-updating layers with in this batch
995 //does not have intersection with the updating layers
996 //above in z-order, then we can safely move the batch to
997 //higher z-order. Increment fbZ as it is moving up.
998 if( firstZReverseIndex < 0) {
999 firstZReverseIndex = i;
1000 }
1001 batchCount++;
1002 batchEnd = i;
1003 fbZ += updatingLayersAbove;
1004 i++;
1005 updatingLayersAbove = 0;
1006 continue;
1007 } else {
1008 //both failed.start the loop again from here.
1009 if(firstZReverseIndex >= 0) {
1010 i = firstZReverseIndex;
1011 }
1012 break;
1013 }
1014 }
1015 }
1016 }
1017 if(batchCount > maxBatchCount) {
1018 maxBatchCount = batchCount;
1019 maxBatchStart = batchStart;
1020 maxBatchEnd = batchEnd;
1021 fbZOrder = fbZ;
1022 }
1023 }
1024 return fbZOrder;
1025}
1026
1027bool MDPComp::markLayersForCaching(hwc_context_t* ctx,
1028 hwc_display_contents_1_t* list) {
1029 /* Idea is to keep as many non-updating(cached) layers in FB and
1030 * send rest of them through MDP. This is done in 2 steps.
1031 * 1. Find the maximum contiguous batch of non-updating layers.
1032 * 2. See if we can improve this batch size for caching by adding
1033 * opaque layers around the batch, if they don't have
1034 * any overlapping with the updating layers in between.
1035 * NEVER mark an updating layer for caching.
1036 * But cached ones can be marked for MDP */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001037
1038 int maxBatchStart = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001039 int maxBatchEnd = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001040 int maxBatchCount = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301041 int fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001042
1043 /* All or Nothing is cached. No batching needed */
Saurabh Shahaa236822013-04-24 18:07:26 -07001044 if(!mCurrentFrame.fbCount) {
1045 mCurrentFrame.fbZ = -1;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001046 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -07001047 }
1048 if(!mCurrentFrame.mdpCount) {
1049 mCurrentFrame.fbZ = 0;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001050 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -07001051 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001052
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301053 fbZ = getBatch(list, maxBatchStart, maxBatchEnd, maxBatchCount);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001054
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301055 /* reset rest of the layers lying inside ROI for MDP comp */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001056 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001057 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001058 if((i < maxBatchStart || i > maxBatchEnd) &&
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301059 mCurrentFrame.isFBComposed[i]){
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001060 if(!mCurrentFrame.drop[i]){
1061 //If an unsupported layer is being attempted to
1062 //be pulled out we should fail
1063 if(not isSupportedForMDPComp(ctx, layer)) {
1064 return false;
1065 }
1066 mCurrentFrame.isFBComposed[i] = false;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001067 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001068 }
1069 }
1070
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301071 // update the frame data
1072 mCurrentFrame.fbZ = fbZ;
1073 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001074 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001075 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001076
1077 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301078 mCurrentFrame.fbCount);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001079
1080 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001081}
Saurabh Shah85234ec2013-04-12 17:09:00 -07001082
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001083void MDPComp::updateLayerCache(hwc_context_t* ctx,
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001084 hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001085 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001086 int fbCount = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001087
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001088 for(int i = 0; i < numAppLayers; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001089 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001090 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001091 if(!mCurrentFrame.drop[i])
1092 fbCount++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001093 mCurrentFrame.isFBComposed[i] = true;
1094 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -07001095 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001096 }
1097 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001098
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001099 mCurrentFrame.fbCount = fbCount;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001100 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount
1101 - mCurrentFrame.dropCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001102
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001103 ALOGD_IF(isDebug(),"%s: MDP count: %d FB count %d drop count: %d"
1104 ,__FUNCTION__, mCurrentFrame.mdpCount, mCurrentFrame.fbCount,
1105 mCurrentFrame.dropCount);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001106}
1107
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001108void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list,
1109 bool secureOnly) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001110 int nYuvCount = ctx->listStats[mDpy].yuvCount;
1111 for(int index = 0;index < nYuvCount; index++){
1112 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
1113 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
1114
1115 if(!isYUVDoable(ctx, layer)) {
1116 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
1117 mCurrentFrame.isFBComposed[nYuvIndex] = true;
1118 mCurrentFrame.fbCount++;
1119 }
1120 } else {
1121 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001122 private_handle_t *hnd = (private_handle_t *)layer->handle;
1123 if(!secureOnly || isSecureBuffer(hnd)) {
1124 mCurrentFrame.isFBComposed[nYuvIndex] = false;
1125 mCurrentFrame.fbCount--;
1126 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001127 }
1128 }
1129 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001130
1131 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001132 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
1133 ALOGD_IF(isDebug(),"%s: fb count: %d",__FUNCTION__,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001134 mCurrentFrame.fbCount);
1135}
1136
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001137bool MDPComp::postHeuristicsHandling(hwc_context_t *ctx,
1138 hwc_display_contents_1_t* list) {
1139
1140 //Capability checks
1141 if(!resourceCheck(ctx, list)) {
1142 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
1143 return false;
1144 }
1145
1146 //Limitations checks
1147 if(!hwLimitationsCheck(ctx, list)) {
1148 ALOGD_IF(isDebug(), "%s: HW limitations",__FUNCTION__);
1149 return false;
1150 }
1151
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001152 //Configure framebuffer first if applicable
1153 if(mCurrentFrame.fbZ >= 0) {
1154 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, mCurrentFrame.fbZ)) {
1155 ALOGD_IF(isDebug(), "%s configure framebuffer failed",
1156 __FUNCTION__);
1157 return false;
1158 }
1159 }
1160
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001161 mCurrentFrame.map();
1162
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001163 if(!allocLayerPipes(ctx, list)) {
1164 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -07001165 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001166 }
1167
1168 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001169 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001170 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001171 int mdpIndex = mCurrentFrame.layerToMDP[index];
1172 hwc_layer_1_t* layer = &list->hwLayers[index];
1173
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301174 //Leave fbZ for framebuffer. CACHE/GLES layers go here.
1175 if(mdpNextZOrder == mCurrentFrame.fbZ) {
1176 mdpNextZOrder++;
1177 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001178 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1179 cur_pipe->zOrder = mdpNextZOrder++;
1180
radhakrishnac9a67412013-09-25 17:40:42 +05301181 private_handle_t *hnd = (private_handle_t *)layer->handle;
1182 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1183 if(configure4k2kYuv(ctx, layer,
1184 mCurrentFrame.mdpToLayer[mdpIndex])
1185 != 0 ){
1186 ALOGD_IF(isDebug(), "%s: Failed to configure split pipes \
1187 for layer %d",__FUNCTION__, index);
1188 return false;
1189 }
1190 else{
1191 mdpNextZOrder++;
1192 }
1193 continue;
1194 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001195 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
1196 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
radhakrishnac9a67412013-09-25 17:40:42 +05301197 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -07001198 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001199 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001200 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001201 }
1202
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001203 setRedraw(ctx, list);
Saurabh Shahaa236822013-04-24 18:07:26 -07001204 return true;
1205}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001206
Saurabh Shah173f4242013-11-20 09:50:12 -08001207bool MDPComp::resourceCheck(hwc_context_t *ctx,
1208 hwc_display_contents_1_t *list) {
1209 const bool fbUsed = mCurrentFrame.fbCount;
1210 if(mCurrentFrame.mdpCount > sMaxPipesPerMixer - fbUsed) {
1211 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
1212 return false;
1213 }
1214
1215 if(!arePipesAvailable(ctx, list)) {
1216 return false;
1217 }
1218
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001219 double size = calcMDPBytesRead(ctx, list);
Saurabh Shah173f4242013-11-20 09:50:12 -08001220 if(!bandwidthCheck(ctx, size)) {
1221 ALOGD_IF(isDebug(), "%s: Exceeds bandwidth",__FUNCTION__);
1222 return false;
1223 }
1224
1225 return true;
1226}
1227
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001228double MDPComp::calcMDPBytesRead(hwc_context_t *ctx,
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001229 hwc_display_contents_1_t* list) {
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001230 double size = 0;
1231 const double GIG = 1000000000.0;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001232
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001233 //Skip for targets where no device tree value for bw is supplied
1234 if(sMaxBw <= 0.0) {
1235 return 0.0;
1236 }
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001237
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001238 for (uint32_t i = 0; i < list->numHwLayers - 1; i++) {
1239 if(!mCurrentFrame.isFBComposed[i]) {
1240 hwc_layer_1_t* layer = &list->hwLayers[i];
1241 private_handle_t *hnd = (private_handle_t *)layer->handle;
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001242 if (hnd) {
Saurabh Shah62e1d732013-09-17 10:44:05 -07001243 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah90789162013-09-16 10:29:20 -07001244 hwc_rect_t dst = layer->displayFrame;
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001245 float bpp = ((float)hnd->size) / (hnd->width * hnd->height);
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001246 size += (bpp * (crop.right - crop.left) *
1247 (crop.bottom - crop.top) *
1248 ctx->dpyAttr[mDpy].yres / (dst.bottom - dst.top)) /
1249 GIG;
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001250 }
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001251 }
1252 }
1253
1254 if(mCurrentFrame.fbCount) {
1255 hwc_layer_1_t* layer = &list->hwLayers[list->numHwLayers - 1];
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001256 int tempw, temph;
1257 size += (getBufferSizeAndDimensions(
1258 layer->displayFrame.right - layer->displayFrame.left,
1259 layer->displayFrame.bottom - layer->displayFrame.top,
1260 HAL_PIXEL_FORMAT_RGBA_8888,
1261 tempw, temph)) / GIG;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001262 }
1263
1264 return size;
1265}
1266
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001267bool MDPComp::bandwidthCheck(hwc_context_t *ctx, const double& size) {
1268 //Skip for targets where no device tree value for bw is supplied
1269 if(sMaxBw <= 0.0) {
1270 return true;
1271 }
1272
1273 double panelRefRate =
1274 1000000000.0 / ctx->dpyAttr[mDpy].vsync_period;
1275 if((size * panelRefRate) > (sMaxBw - sBwClaimed)) {
1276 return false;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001277 }
1278 return true;
1279}
1280
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301281bool MDPComp::hwLimitationsCheck(hwc_context_t* ctx,
1282 hwc_display_contents_1_t* list) {
1283
1284 //A-family hw limitation:
1285 //If a layer need alpha scaling, MDP can not support.
1286 if(ctx->mMDP.version < qdutils::MDSS_V5) {
1287 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1288 if(!mCurrentFrame.isFBComposed[i] &&
1289 isAlphaScaled( &list->hwLayers[i])) {
1290 ALOGD_IF(isDebug(), "%s:frame needs alphaScaling",__FUNCTION__);
1291 return false;
1292 }
1293 }
1294 }
1295
1296 // On 8x26 & 8974 hw, we have a limitation of downscaling+blending.
1297 //If multiple layers requires downscaling and also they are overlapping
1298 //fall back to GPU since MDSS can not handle it.
1299 if(qdutils::MDPVersion::getInstance().is8x74v2() ||
1300 qdutils::MDPVersion::getInstance().is8x26()) {
1301 for(int i = 0; i < mCurrentFrame.layerCount-1; ++i) {
1302 hwc_layer_1_t* botLayer = &list->hwLayers[i];
1303 if(!mCurrentFrame.isFBComposed[i] &&
1304 isDownscaleRequired(botLayer)) {
1305 //if layer-i is marked for MDP and needs downscaling
1306 //check if any MDP layer on top of i & overlaps with layer-i
1307 for(int j = i+1; j < mCurrentFrame.layerCount; ++j) {
1308 hwc_layer_1_t* topLayer = &list->hwLayers[j];
1309 if(!mCurrentFrame.isFBComposed[j] &&
1310 isDownscaleRequired(topLayer)) {
1311 hwc_rect_t r = getIntersection(botLayer->displayFrame,
1312 topLayer->displayFrame);
1313 if(isValidRect(r))
1314 return false;
1315 }
1316 }
1317 }
1318 }
1319 }
1320 return true;
1321}
1322
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001323int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001324 int ret = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -07001325 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001326 MDPVersion& mdpVersion = qdutils::MDPVersion::getInstance();
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -07001327
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001328 //number of app layers exceeds MAX_NUM_APP_LAYERS fall back to GPU
1329 //do not cache the information for next draw cycle.
1330 if(numLayers > MAX_NUM_APP_LAYERS) {
1331 ALOGI("%s: Number of App layers exceeded the limit ",
1332 __FUNCTION__);
1333 mCachedFrame.reset();
1334 return -1;
1335 }
1336
Saurabh Shahb39f8152013-08-22 10:21:44 -07001337 //reset old data
1338 mCurrentFrame.reset(numLayers);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001339 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1340 mCurrentFrame.dropCount = 0;
Prabhanjan Kandula088bd892013-07-02 23:47:13 +05301341
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -07001342 // Detect the start of animation and fall back to GPU only once to cache
1343 // all the layers in FB and display FB content untill animation completes.
1344 if(ctx->listStats[mDpy].isDisplayAnimating) {
1345 mCurrentFrame.needsRedraw = false;
1346 if(ctx->mAnimationState[mDpy] == ANIMATION_STOPPED) {
1347 mCurrentFrame.needsRedraw = true;
1348 ctx->mAnimationState[mDpy] = ANIMATION_STARTED;
1349 }
1350 setMDPCompLayerFlags(ctx, list);
1351 mCachedFrame.updateCounts(mCurrentFrame);
1352 ret = -1;
1353 return ret;
1354 } else {
1355 ctx->mAnimationState[mDpy] = ANIMATION_STOPPED;
1356 }
1357
Saurabh Shahb39f8152013-08-22 10:21:44 -07001358 //Hard conditions, if not met, cannot do MDP comp
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001359 if(isFrameDoable(ctx)) {
1360 generateROI(ctx, list);
Saurabh Shahb39f8152013-08-22 10:21:44 -07001361
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001362 //Convert from kbps to gbps
1363 sMaxBw = mdpVersion.getHighBw() / 1000000.0;
1364 if (ctx->mExtDisplay->isConnected() ||
1365 ctx->mMDP.panel != MIPI_CMD_PANEL) {
1366 sMaxBw = mdpVersion.getLowBw() / 1000000.0;
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001367 }
1368
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001369 if(tryFullFrame(ctx, list) || tryVideoOnly(ctx, list)) {
1370 setMDPCompLayerFlags(ctx, list);
1371 } else {
1372 reset(ctx);
1373 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1374 mCurrentFrame.dropCount = 0;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001375 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001376 }
1377 } else {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001378 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
1379 __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001380 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001381 }
Saurabh Shahb39f8152013-08-22 10:21:44 -07001382
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001383 if(isDebug()) {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001384 ALOGD("GEOMETRY change: %d",
1385 (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001386 android::String8 sDump("");
1387 dump(sDump);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001388 ALOGD("%s",sDump.string());
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001389 }
1390
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001391 mCachedFrame.cacheAll(list);
1392 mCachedFrame.updateCounts(mCurrentFrame);
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001393 double panelRefRate =
1394 1000000000.0 / ctx->dpyAttr[mDpy].vsync_period;
1395 sBwClaimed += calcMDPBytesRead(ctx, list) * panelRefRate;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001396 return ret;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001397}
1398
radhakrishnac9a67412013-09-25 17:40:42 +05301399bool MDPComp::allocSplitVGPipesfor4k2k(hwc_context_t *ctx,
1400 hwc_display_contents_1_t* list, int index) {
1401
1402 bool bRet = true;
1403 hwc_layer_1_t* layer = &list->hwLayers[index];
1404 private_handle_t *hnd = (private_handle_t *)layer->handle;
1405 int mdpIndex = mCurrentFrame.layerToMDP[index];
1406 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
1407 info.pipeInfo = new MdpYUVPipeInfo;
1408 info.rot = NULL;
1409 MdpYUVPipeInfo& pipe_info = *(MdpYUVPipeInfo*)info.pipeInfo;
1410 ePipeType type = MDPCOMP_OV_VG;
1411
1412 pipe_info.lIndex = ovutils::OV_INVALID;
1413 pipe_info.rIndex = ovutils::OV_INVALID;
1414
1415 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
1416 if(pipe_info.lIndex == ovutils::OV_INVALID){
1417 bRet = false;
1418 ALOGD_IF(isDebug(),"%s: allocating first VG pipe failed",
1419 __FUNCTION__);
1420 }
1421 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
1422 if(pipe_info.rIndex == ovutils::OV_INVALID){
1423 bRet = false;
1424 ALOGD_IF(isDebug(),"%s: allocating second VG pipe failed",
1425 __FUNCTION__);
1426 }
1427 return bRet;
1428}
Saurabh Shah88e4d272013-09-03 13:31:29 -07001429//=============MDPCompNonSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001430
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001431void MDPCompNonSplit::adjustForSourceSplit(hwc_context_t *ctx,
radhakrishnac9a67412013-09-25 17:40:42 +05301432 hwc_display_contents_1_t* list){
1433 //As we split 4kx2k yuv layer and program to 2 VG pipes
1434 //(if available) increase mdpcount accordingly
1435 mCurrentFrame.mdpCount += ctx->listStats[mDpy].yuv4k2kCount;
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001436
1437 //If 4k2k Yuv layer split is possible, and if
1438 //fbz is above 4k2k layer, increment fb zorder by 1
1439 //as we split 4k2k layer and increment zorder for right half
1440 //of the layer
1441 if(mCurrentFrame.fbZ >= 0) {
1442 int n4k2kYuvCount = ctx->listStats[mDpy].yuv4k2kCount;
1443 for(int index = 0; index < n4k2kYuvCount; index++){
1444 int n4k2kYuvIndex =
1445 ctx->listStats[mDpy].yuv4k2kIndices[index];
1446 if(mCurrentFrame.fbZ > n4k2kYuvIndex){
1447 mCurrentFrame.fbZ += 1;
1448 }
1449 }
1450 }
radhakrishnac9a67412013-09-25 17:40:42 +05301451}
1452
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001453/*
1454 * Configures pipe(s) for MDP composition
1455 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001456int MDPCompNonSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001457 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001458 MdpPipeInfoNonSplit& mdp_info =
1459 *(static_cast<MdpPipeInfoNonSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001460 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
1461 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1462 eIsFg isFg = IS_FG_OFF;
1463 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001464
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001465 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
1466 __FUNCTION__, layer, zOrder, dest);
1467
Saurabh Shah88e4d272013-09-03 13:31:29 -07001468 return configureNonSplit(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001469 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001470}
1471
Saurabh Shah88e4d272013-09-03 13:31:29 -07001472bool MDPCompNonSplit::arePipesAvailable(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001473 hwc_display_contents_1_t* list) {
1474 overlay::Overlay& ov = *ctx->mOverlay;
1475 int numPipesNeeded = mCurrentFrame.mdpCount;
1476 int availPipes = ov.availablePipes(mDpy, Overlay::MIXER_DEFAULT);
1477
1478 //Reserve pipe for FB
1479 if(mCurrentFrame.fbCount)
1480 availPipes -= 1;
1481
1482 if(numPipesNeeded > availPipes) {
1483 ALOGD_IF(isDebug(), "%s: Insufficient pipes, dpy %d needed %d, avail %d",
1484 __FUNCTION__, mDpy, numPipesNeeded, availPipes);
1485 return false;
1486 }
1487
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001488 if(not areVGPipesAvailable(ctx, list)) {
1489 return false;
1490 }
1491
1492 return true;
1493}
1494
1495bool MDPCompNonSplit::areVGPipesAvailable(hwc_context_t *ctx,
1496 hwc_display_contents_1_t* list) {
1497 overlay::Overlay& ov = *ctx->mOverlay;
1498 int pipesNeeded = 0;
1499 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1500 if(!mCurrentFrame.isFBComposed[i]) {
1501 hwc_layer_1_t* layer = &list->hwLayers[i];
1502 hwc_rect_t dst = layer->displayFrame;
1503 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301504 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1505 pipesNeeded = pipesNeeded + 2;
1506 }
1507 else if(isYuvBuffer(hnd)) {
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001508 pipesNeeded++;
1509 }
1510 }
1511 }
1512
1513 int availableVGPipes = ov.availablePipes(mDpy, ovutils::OV_MDP_PIPE_VG);
1514 if(pipesNeeded > availableVGPipes) {
1515 ALOGD_IF(isDebug(), "%s: Insufficient VG pipes for video layers"
1516 "dpy %d needed %d, avail %d",
1517 __FUNCTION__, mDpy, pipesNeeded, availableVGPipes);
1518 return false;
1519 }
1520
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001521 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001522}
1523
Saurabh Shah88e4d272013-09-03 13:31:29 -07001524bool MDPCompNonSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001525 hwc_display_contents_1_t* list) {
1526 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001527
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001528 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001529
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001530 hwc_layer_1_t* layer = &list->hwLayers[index];
1531 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301532 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1533 if(allocSplitVGPipesfor4k2k(ctx, list, index)){
1534 continue;
1535 }
1536 }
1537
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001538 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001539 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001540 info.pipeInfo = new MdpPipeInfoNonSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08001541 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001542 MdpPipeInfoNonSplit& pipe_info = *(MdpPipeInfoNonSplit*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001543 ePipeType type = MDPCOMP_OV_ANY;
1544
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001545 if(isYuvBuffer(hnd)) {
1546 type = MDPCOMP_OV_VG;
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301547 } else if(!qhwc::needsScaling(layer)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001548 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
1549 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001550 type = MDPCOMP_OV_DMA;
1551 }
1552
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001553 pipe_info.index = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001554 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001555 ALOGD_IF(isDebug(), "%s: Unable to get pipe type = %d",
1556 __FUNCTION__, (int) type);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001557 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001558 }
1559 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001560 return true;
1561}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001562
radhakrishnac9a67412013-09-25 17:40:42 +05301563int MDPCompNonSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1564 PipeLayerPair& PipeLayerPair) {
1565 MdpYUVPipeInfo& mdp_info =
1566 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1567 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1568 eIsFg isFg = IS_FG_OFF;
1569 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1570 eDest lDest = mdp_info.lIndex;
1571 eDest rDest = mdp_info.rIndex;
1572
1573 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1574 lDest, rDest, &PipeLayerPair.rot);
1575}
1576
Saurabh Shah88e4d272013-09-03 13:31:29 -07001577bool MDPCompNonSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001578
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001579 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001580 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1581 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -08001582 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001583
1584 if(!ctx || !list) {
1585 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001586 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001587 }
1588
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301589 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1590 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1591 return true;
1592 }
1593
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001594 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001595 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001596 idleInvalidator->markForSleep();
1597
1598 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001599 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001600
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001601 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1602 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001603 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001604 if(mCurrentFrame.isFBComposed[i]) continue;
1605
Naseer Ahmed5b6708a2012-08-02 13:46:08 -07001606 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001607 private_handle_t *hnd = (private_handle_t *)layer->handle;
1608 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001609 if (!(layer->flags & HWC_COLOR_FILL)) {
1610 ALOGE("%s handle null", __FUNCTION__);
1611 return false;
1612 }
1613 // No PLAY for Color layer
1614 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1615 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001616 }
1617
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001618 int mdpIndex = mCurrentFrame.layerToMDP[i];
1619
radhakrishnac9a67412013-09-25 17:40:42 +05301620 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1621 {
1622 MdpYUVPipeInfo& pipe_info =
1623 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1624 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1625 ovutils::eDest indexL = pipe_info.lIndex;
1626 ovutils::eDest indexR = pipe_info.rIndex;
1627 int fd = hnd->fd;
1628 uint32_t offset = hnd->offset;
1629 if(rot) {
1630 rot->queueBuffer(fd, offset);
1631 fd = rot->getDstMemId();
1632 offset = rot->getDstOffset();
1633 }
1634 if(indexL != ovutils::OV_INVALID) {
1635 ovutils::eDest destL = (ovutils::eDest)indexL;
1636 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1637 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1638 if (!ov.queueBuffer(fd, offset, destL)) {
1639 ALOGE("%s: queueBuffer failed for display:%d",
1640 __FUNCTION__, mDpy);
1641 return false;
1642 }
1643 }
1644
1645 if(indexR != ovutils::OV_INVALID) {
1646 ovutils::eDest destR = (ovutils::eDest)indexR;
1647 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1648 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1649 if (!ov.queueBuffer(fd, offset, destR)) {
1650 ALOGE("%s: queueBuffer failed for display:%d",
1651 __FUNCTION__, mDpy);
1652 return false;
1653 }
1654 }
1655 }
1656 else{
1657 MdpPipeInfoNonSplit& pipe_info =
Saurabh Shah88e4d272013-09-03 13:31:29 -07001658 *(MdpPipeInfoNonSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
radhakrishnac9a67412013-09-25 17:40:42 +05301659 ovutils::eDest dest = pipe_info.index;
1660 if(dest == ovutils::OV_INVALID) {
1661 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001662 return false;
radhakrishnac9a67412013-09-25 17:40:42 +05301663 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001664
radhakrishnac9a67412013-09-25 17:40:42 +05301665 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1666 continue;
1667 }
1668
1669 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1670 using pipe: %d", __FUNCTION__, layer,
1671 hnd, dest );
1672
1673 int fd = hnd->fd;
1674 uint32_t offset = hnd->offset;
1675
1676 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1677 if(rot) {
1678 if(!rot->queueBuffer(fd, offset))
1679 return false;
1680 fd = rot->getDstMemId();
1681 offset = rot->getDstOffset();
1682 }
1683
1684 if (!ov.queueBuffer(fd, offset, dest)) {
1685 ALOGE("%s: queueBuffer failed for display:%d ",
1686 __FUNCTION__, mDpy);
1687 return false;
1688 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001689 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001690
1691 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001692 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001693 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001694}
1695
Saurabh Shah88e4d272013-09-03 13:31:29 -07001696//=============MDPCompSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001697
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001698void MDPCompSplit::adjustForSourceSplit(hwc_context_t *ctx,
radhakrishnac9a67412013-09-25 17:40:42 +05301699 hwc_display_contents_1_t* list){
1700 //if 4kx2k yuv layer is totally present in either in left half
1701 //or right half then try splitting the yuv layer to avoid decimation
1702 int n4k2kYuvCount = ctx->listStats[mDpy].yuv4k2kCount;
1703 const int lSplit = getLeftSplit(ctx, mDpy);
1704 for(int index = 0; index < n4k2kYuvCount; index++){
1705 int n4k2kYuvIndex = ctx->listStats[mDpy].yuv4k2kIndices[index];
1706 hwc_layer_1_t* layer = &list->hwLayers[n4k2kYuvIndex];
1707 hwc_rect_t dst = layer->displayFrame;
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001708 if((dst.left > lSplit) || (dst.right < lSplit)) {
radhakrishnac9a67412013-09-25 17:40:42 +05301709 mCurrentFrame.mdpCount += 1;
1710 }
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001711 if(mCurrentFrame.fbZ > n4k2kYuvIndex){
1712 mCurrentFrame.fbZ += 1;
1713 }
radhakrishnac9a67412013-09-25 17:40:42 +05301714 }
1715}
1716
Saurabh Shah88e4d272013-09-03 13:31:29 -07001717int MDPCompSplit::pipesNeeded(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001718 hwc_display_contents_1_t* list,
1719 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001720 int pipesNeeded = 0;
Saurabh Shah67a38c32013-06-10 16:23:15 -07001721 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001722
1723 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001724
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001725 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1726 if(!mCurrentFrame.isFBComposed[i]) {
1727 hwc_layer_1_t* layer = &list->hwLayers[i];
1728 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001729 if(mixer == Overlay::MIXER_LEFT && dst.left < lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001730 pipesNeeded++;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001731 } else if(mixer == Overlay::MIXER_RIGHT && dst.right > lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001732 pipesNeeded++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001733 }
1734 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001735 }
1736 return pipesNeeded;
1737}
1738
Saurabh Shah88e4d272013-09-03 13:31:29 -07001739bool MDPCompSplit::arePipesAvailable(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001740 hwc_display_contents_1_t* list) {
1741 overlay::Overlay& ov = *ctx->mOverlay;
Saurabh Shah082468e2013-09-12 10:05:32 -07001742 int totalPipesNeeded = 0;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001743
1744 for(int i = 0; i < Overlay::MIXER_MAX; i++) {
1745 int numPipesNeeded = pipesNeeded(ctx, list, i);
1746 int availPipes = ov.availablePipes(mDpy, i);
1747
1748 //Reserve pipe(s)for FB
1749 if(mCurrentFrame.fbCount)
Saurabh Shah082468e2013-09-12 10:05:32 -07001750 numPipesNeeded += 1;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001751
Saurabh Shah082468e2013-09-12 10:05:32 -07001752 totalPipesNeeded += numPipesNeeded;
1753
1754 //Per mixer check.
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001755 if(numPipesNeeded > availPipes) {
1756 ALOGD_IF(isDebug(), "%s: Insufficient pipes for "
1757 "dpy %d mixer %d needed %d, avail %d",
1758 __FUNCTION__, mDpy, i, numPipesNeeded, availPipes);
1759 return false;
1760 }
1761 }
Saurabh Shah082468e2013-09-12 10:05:32 -07001762
1763 //Per display check, since unused pipes can get counted twice.
1764 int totalPipesAvailable = ov.availablePipes(mDpy);
1765 if(totalPipesNeeded > totalPipesAvailable) {
1766 ALOGD_IF(isDebug(), "%s: Insufficient pipes for "
1767 "dpy %d needed %d, avail %d",
1768 __FUNCTION__, mDpy, totalPipesNeeded, totalPipesAvailable);
1769 return false;
1770 }
1771
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001772 if(not areVGPipesAvailable(ctx, list)) {
1773 return false;
1774 }
1775
1776 return true;
1777}
1778
1779bool MDPCompSplit::areVGPipesAvailable(hwc_context_t *ctx,
1780 hwc_display_contents_1_t* list) {
1781 overlay::Overlay& ov = *ctx->mOverlay;
1782 int pipesNeeded = 0;
1783 const int lSplit = getLeftSplit(ctx, mDpy);
1784 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1785 if(!mCurrentFrame.isFBComposed[i]) {
1786 hwc_layer_1_t* layer = &list->hwLayers[i];
1787 hwc_rect_t dst = layer->displayFrame;
1788 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301789 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1790 if((dst.left > lSplit)||(dst.right < lSplit)){
1791 pipesNeeded = pipesNeeded + 2;
1792 continue;
1793 }
1794 }
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001795 if(isYuvBuffer(hnd)) {
1796 if(dst.left < lSplit) {
1797 pipesNeeded++;
1798 }
1799 if(dst.right > lSplit) {
1800 pipesNeeded++;
1801 }
1802 }
1803 }
1804 }
1805
1806 int availableVGPipes = ov.availablePipes(mDpy, ovutils::OV_MDP_PIPE_VG);
1807 if(pipesNeeded > availableVGPipes) {
1808 ALOGD_IF(isDebug(), "%s: Insufficient VG pipes for video layers"
1809 "dpy %d needed %d, avail %d",
1810 __FUNCTION__, mDpy, pipesNeeded, availableVGPipes);
1811 return false;
1812 }
1813
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001814 return true;
1815}
1816
Saurabh Shah88e4d272013-09-03 13:31:29 -07001817bool MDPCompSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
1818 MdpPipeInfoSplit& pipe_info,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001819 ePipeType type) {
1820 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001821 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001822
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001823 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001824 pipe_info.lIndex = ovutils::OV_INVALID;
1825 pipe_info.rIndex = ovutils::OV_INVALID;
1826
1827 if (dst.left < lSplit) {
1828 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_LEFT);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001829 if(pipe_info.lIndex == ovutils::OV_INVALID)
1830 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001831 }
1832
1833 if(dst.right > lSplit) {
1834 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_RIGHT);
1835 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001836 return false;
1837 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001838
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001839 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001840}
1841
Saurabh Shah88e4d272013-09-03 13:31:29 -07001842bool MDPCompSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001843 hwc_display_contents_1_t* list) {
1844 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001845
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001846 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001847
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001848 hwc_layer_1_t* layer = &list->hwLayers[index];
1849 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301850 hwc_rect_t dst = layer->displayFrame;
1851 const int lSplit = getLeftSplit(ctx, mDpy);
1852 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1853 if((dst.left > lSplit)||(dst.right < lSplit)){
1854 if(allocSplitVGPipesfor4k2k(ctx, list, index)){
1855 continue;
1856 }
1857 }
1858 }
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001859 int mdpIndex = mCurrentFrame.layerToMDP[index];
1860 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001861 info.pipeInfo = new MdpPipeInfoSplit;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001862 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001863 MdpPipeInfoSplit& pipe_info = *(MdpPipeInfoSplit*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001864 ePipeType type = MDPCOMP_OV_ANY;
1865
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001866 if(isYuvBuffer(hnd)) {
1867 type = MDPCOMP_OV_VG;
Sushil Chauhan15a2ea62013-09-04 18:28:36 -07001868 } else if(!qhwc::needsScalingWithSplit(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001869 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001870 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001871 type = MDPCOMP_OV_DMA;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001872 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001873
1874 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001875 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type = %d",
1876 __FUNCTION__, (int) type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001877 return false;
1878 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001879 }
1880 return true;
1881}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001882
radhakrishnac9a67412013-09-25 17:40:42 +05301883int MDPCompSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1884 PipeLayerPair& PipeLayerPair) {
1885 const int lSplit = getLeftSplit(ctx, mDpy);
1886 hwc_rect_t dst = layer->displayFrame;
1887 if((dst.left > lSplit)||(dst.right < lSplit)){
1888 MdpYUVPipeInfo& mdp_info =
1889 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1890 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1891 eIsFg isFg = IS_FG_OFF;
1892 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1893 eDest lDest = mdp_info.lIndex;
1894 eDest rDest = mdp_info.rIndex;
1895
1896 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1897 lDest, rDest, &PipeLayerPair.rot);
1898 }
1899 else{
1900 return configure(ctx, layer, PipeLayerPair);
1901 }
1902}
1903
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001904/*
1905 * Configures pipe(s) for MDP composition
1906 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001907int MDPCompSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001908 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001909 MdpPipeInfoSplit& mdp_info =
1910 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001911 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1912 eIsFg isFg = IS_FG_OFF;
1913 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1914 eDest lDest = mdp_info.lIndex;
1915 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001916
1917 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1918 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1919
Saurabh Shah88e4d272013-09-03 13:31:29 -07001920 return configureSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001921 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001922}
1923
Saurabh Shah88e4d272013-09-03 13:31:29 -07001924bool MDPCompSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001925
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001926 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001927 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1928 return true;
1929 }
1930
1931 if(!ctx || !list) {
1932 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001933 return false;
1934 }
1935
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301936 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1937 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1938 return true;
1939 }
1940
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001941 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001942 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001943 idleInvalidator->markForSleep();
1944
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001945 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001946 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001947
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001948 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1949 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001950 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001951 if(mCurrentFrame.isFBComposed[i]) continue;
1952
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001953 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001954 private_handle_t *hnd = (private_handle_t *)layer->handle;
1955 if(!hnd) {
1956 ALOGE("%s handle null", __FUNCTION__);
1957 return false;
1958 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001959
1960 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1961 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001962 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001963
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001964 int mdpIndex = mCurrentFrame.layerToMDP[i];
1965
radhakrishnac9a67412013-09-25 17:40:42 +05301966 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1967 {
1968 MdpYUVPipeInfo& pipe_info =
1969 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1970 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1971 ovutils::eDest indexL = pipe_info.lIndex;
1972 ovutils::eDest indexR = pipe_info.rIndex;
1973 int fd = hnd->fd;
1974 uint32_t offset = hnd->offset;
1975 if(rot) {
1976 rot->queueBuffer(fd, offset);
1977 fd = rot->getDstMemId();
1978 offset = rot->getDstOffset();
1979 }
1980 if(indexL != ovutils::OV_INVALID) {
1981 ovutils::eDest destL = (ovutils::eDest)indexL;
1982 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1983 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1984 if (!ov.queueBuffer(fd, offset, destL)) {
1985 ALOGE("%s: queueBuffer failed for display:%d",
1986 __FUNCTION__, mDpy);
1987 return false;
1988 }
1989 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001990
radhakrishnac9a67412013-09-25 17:40:42 +05301991 if(indexR != ovutils::OV_INVALID) {
1992 ovutils::eDest destR = (ovutils::eDest)indexR;
1993 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1994 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1995 if (!ov.queueBuffer(fd, offset, destR)) {
1996 ALOGE("%s: queueBuffer failed for display:%d",
1997 __FUNCTION__, mDpy);
1998 return false;
1999 }
Saurabh Shaha9da08f2013-07-03 13:27:53 -07002000 }
2001 }
radhakrishnac9a67412013-09-25 17:40:42 +05302002 else{
2003 MdpPipeInfoSplit& pipe_info =
2004 *(MdpPipeInfoSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
2005 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07002006
radhakrishnac9a67412013-09-25 17:40:42 +05302007 ovutils::eDest indexL = pipe_info.lIndex;
2008 ovutils::eDest indexR = pipe_info.rIndex;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002009
radhakrishnac9a67412013-09-25 17:40:42 +05302010 int fd = hnd->fd;
2011 int offset = hnd->offset;
2012
2013 if(ctx->mAD->isModeOn()) {
2014 if(ctx->mAD->draw(ctx, fd, offset)) {
2015 fd = ctx->mAD->getDstFd(ctx);
2016 offset = ctx->mAD->getDstOffset(ctx);
2017 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002018 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002019
radhakrishnac9a67412013-09-25 17:40:42 +05302020 if(rot) {
2021 rot->queueBuffer(fd, offset);
2022 fd = rot->getDstMemId();
2023 offset = rot->getDstOffset();
2024 }
2025
2026 //************* play left mixer **********
2027 if(indexL != ovutils::OV_INVALID) {
2028 ovutils::eDest destL = (ovutils::eDest)indexL;
2029 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
2030 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
2031 if (!ov.queueBuffer(fd, offset, destL)) {
2032 ALOGE("%s: queueBuffer failed for left mixer",
2033 __FUNCTION__);
2034 return false;
2035 }
2036 }
2037
2038 //************* play right mixer **********
2039 if(indexR != ovutils::OV_INVALID) {
2040 ovutils::eDest destR = (ovutils::eDest)indexR;
2041 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
2042 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
2043 if (!ov.queueBuffer(fd, offset, destR)) {
2044 ALOGE("%s: queueBuffer failed for right mixer",
2045 __FUNCTION__);
2046 return false;
2047 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002048 }
2049 }
Saurabh Shahacf10202013-02-26 10:15:15 -08002050
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002051 layerProp[i].mFlags &= ~HWC_MDPCOMP;
2052 }
Saurabh Shahacf10202013-02-26 10:15:15 -08002053
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002054 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002055}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002056}; //namespace
2057