blob: 8048d71a0cc4b585026ed8953e83e4393264fd53 [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) {
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800839 if(mDpy or isSecurePresent(ctx, mDpy)) {
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700840 return false;
841 }
842 return true;
843}
844
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800845bool MDPComp::tryVideoOnly(hwc_context_t *ctx,
846 hwc_display_contents_1_t* list) {
847 const bool secureOnly = true;
848 return videoOnlyComp(ctx, list, not secureOnly) or
849 videoOnlyComp(ctx, list, secureOnly);
850}
851
852bool MDPComp::videoOnlyComp(hwc_context_t *ctx,
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700853 hwc_display_contents_1_t* list, bool secureOnly) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700854 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700855
Saurabh Shahaa236822013-04-24 18:07:26 -0700856 mCurrentFrame.reset(numAppLayers);
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700857 updateYUV(ctx, list, secureOnly);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700858 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700859
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800860 if(!isYuvPresent(ctx, mDpy) or (mdpCount == 0)) {
861 reset(ctx);
Saurabh Shahaa236822013-04-24 18:07:26 -0700862 return false;
863 }
864
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -0800865 /* Bail out if we are processing only secured video layers
866 * and we dont have any */
867 if(!isSecurePresent(ctx, mDpy) && secureOnly){
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800868 reset(ctx);
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -0800869 return false;
870 }
871
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800872 if(mCurrentFrame.fbCount)
873 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
Saurabh Shah4fdde762013-04-30 18:47:33 -0700874
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800875 if(sEnable4k2kYUVSplit){
876 adjustForSourceSplit(ctx, list);
877 }
878
879 if(!postHeuristicsHandling(ctx, list)) {
880 ALOGD_IF(isDebug(), "post heuristic handling failed");
881 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700882 return false;
883 }
884
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800885 return true;
886}
887
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800888/* Checks for conditions where YUV layers cannot be bypassed */
889bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -0700890 if(isSkipLayer(layer)) {
Saurabh Shahe2474082013-05-15 16:32:13 -0700891 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800892 return false;
893 }
894
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700895 if(layer->transform & HWC_TRANSFORM_ROT_90 && !canUseRotator(ctx,mDpy)) {
896 ALOGD_IF(isDebug(), "%s: no free DMA pipe",__FUNCTION__);
897 return false;
898 }
899
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800900 if(isSecuring(ctx, layer)) {
901 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
902 return false;
903 }
904
Saurabh Shah4fdde762013-04-30 18:47:33 -0700905 if(!isValidDimension(ctx, layer)) {
906 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
907 __FUNCTION__);
908 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800909 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700910
Naseer Ahmeddc61a972013-07-10 17:50:54 -0400911 if(layer->planeAlpha < 0xFF) {
912 ALOGD_IF(isDebug(), "%s: Cannot handle YUV layer with plane alpha\
913 in video only mode",
914 __FUNCTION__);
915 return false;
916 }
917
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800918 return true;
919}
920
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530921/* starts at fromIndex and check for each layer to find
922 * if it it has overlapping with any Updating layer above it in zorder
923 * till the end of the batch. returns true if it finds any intersection */
924bool MDPComp::canPushBatchToTop(const hwc_display_contents_1_t* list,
925 int fromIndex, int toIndex) {
926 for(int i = fromIndex; i < toIndex; i++) {
927 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
928 if(intersectingUpdatingLayers(list, i+1, toIndex, i)) {
929 return false;
930 }
931 }
932 }
933 return true;
934}
935
936/* Checks if given layer at targetLayerIndex has any
937 * intersection with all the updating layers in beween
938 * fromIndex and toIndex. Returns true if it finds intersectiion */
939bool MDPComp::intersectingUpdatingLayers(const hwc_display_contents_1_t* list,
940 int fromIndex, int toIndex, int targetLayerIndex) {
941 for(int i = fromIndex; i <= toIndex; i++) {
942 if(!mCurrentFrame.isFBComposed[i]) {
943 if(areLayersIntersecting(&list->hwLayers[i],
944 &list->hwLayers[targetLayerIndex])) {
945 return true;
946 }
947 }
948 }
949 return false;
950}
951
952int MDPComp::getBatch(hwc_display_contents_1_t* list,
953 int& maxBatchStart, int& maxBatchEnd,
954 int& maxBatchCount) {
955 int i = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530956 int fbZOrder =-1;
957 while (i < mCurrentFrame.layerCount) {
958 int batchCount = 0;
959 int batchStart = i;
960 int batchEnd = i;
961 int fbZ = batchStart;
962 int firstZReverseIndex = -1;
Prabhanjan Kandula0ed2cc92013-12-06 12:39:04 +0530963 int updatingLayersAbove = 0;//Updating layer count in middle of batch
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530964 while(i < mCurrentFrame.layerCount) {
965 if(!mCurrentFrame.isFBComposed[i]) {
966 if(!batchCount) {
967 i++;
968 break;
969 }
970 updatingLayersAbove++;
971 i++;
972 continue;
973 } else {
974 if(mCurrentFrame.drop[i]) {
975 i++;
976 continue;
977 } else if(updatingLayersAbove <= 0) {
978 batchCount++;
979 batchEnd = i;
980 i++;
981 continue;
982 } else { //Layer is FBComposed, not a drop & updatingLayer > 0
983
984 // We have a valid updating layer already. If layer-i not
985 // have overlapping with all updating layers in between
986 // batch-start and i, then we can add layer i to batch.
987 if(!intersectingUpdatingLayers(list, batchStart, i-1, i)) {
988 batchCount++;
989 batchEnd = i;
990 i++;
991 continue;
992 } else if(canPushBatchToTop(list, batchStart, i)) {
993 //If All the non-updating layers with in this batch
994 //does not have intersection with the updating layers
995 //above in z-order, then we can safely move the batch to
996 //higher z-order. Increment fbZ as it is moving up.
997 if( firstZReverseIndex < 0) {
998 firstZReverseIndex = i;
999 }
1000 batchCount++;
1001 batchEnd = i;
1002 fbZ += updatingLayersAbove;
1003 i++;
1004 updatingLayersAbove = 0;
1005 continue;
1006 } else {
1007 //both failed.start the loop again from here.
1008 if(firstZReverseIndex >= 0) {
1009 i = firstZReverseIndex;
1010 }
1011 break;
1012 }
1013 }
1014 }
1015 }
1016 if(batchCount > maxBatchCount) {
1017 maxBatchCount = batchCount;
1018 maxBatchStart = batchStart;
1019 maxBatchEnd = batchEnd;
1020 fbZOrder = fbZ;
1021 }
1022 }
1023 return fbZOrder;
1024}
1025
1026bool MDPComp::markLayersForCaching(hwc_context_t* ctx,
1027 hwc_display_contents_1_t* list) {
1028 /* Idea is to keep as many non-updating(cached) layers in FB and
1029 * send rest of them through MDP. This is done in 2 steps.
1030 * 1. Find the maximum contiguous batch of non-updating layers.
1031 * 2. See if we can improve this batch size for caching by adding
1032 * opaque layers around the batch, if they don't have
1033 * any overlapping with the updating layers in between.
1034 * NEVER mark an updating layer for caching.
1035 * But cached ones can be marked for MDP */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001036
1037 int maxBatchStart = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001038 int maxBatchEnd = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001039 int maxBatchCount = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301040 int fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001041
1042 /* All or Nothing is cached. No batching needed */
Saurabh Shahaa236822013-04-24 18:07:26 -07001043 if(!mCurrentFrame.fbCount) {
1044 mCurrentFrame.fbZ = -1;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001045 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -07001046 }
1047 if(!mCurrentFrame.mdpCount) {
1048 mCurrentFrame.fbZ = 0;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001049 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -07001050 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001051
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301052 fbZ = getBatch(list, maxBatchStart, maxBatchEnd, maxBatchCount);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001053
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301054 /* reset rest of the layers lying inside ROI for MDP comp */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001055 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001056 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001057 if((i < maxBatchStart || i > maxBatchEnd) &&
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301058 mCurrentFrame.isFBComposed[i]){
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001059 if(!mCurrentFrame.drop[i]){
1060 //If an unsupported layer is being attempted to
1061 //be pulled out we should fail
1062 if(not isSupportedForMDPComp(ctx, layer)) {
1063 return false;
1064 }
1065 mCurrentFrame.isFBComposed[i] = false;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001066 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001067 }
1068 }
1069
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301070 // update the frame data
1071 mCurrentFrame.fbZ = fbZ;
1072 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001073 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001074 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001075
1076 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301077 mCurrentFrame.fbCount);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001078
1079 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001080}
Saurabh Shah85234ec2013-04-12 17:09:00 -07001081
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001082void MDPComp::updateLayerCache(hwc_context_t* ctx,
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001083 hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001084 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001085 int fbCount = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001086
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001087 for(int i = 0; i < numAppLayers; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001088 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001089 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001090 if(!mCurrentFrame.drop[i])
1091 fbCount++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001092 mCurrentFrame.isFBComposed[i] = true;
1093 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -07001094 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001095 }
1096 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001097
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001098 mCurrentFrame.fbCount = fbCount;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001099 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount
1100 - mCurrentFrame.dropCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001101
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001102 ALOGD_IF(isDebug(),"%s: MDP count: %d FB count %d drop count: %d"
1103 ,__FUNCTION__, mCurrentFrame.mdpCount, mCurrentFrame.fbCount,
1104 mCurrentFrame.dropCount);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001105}
1106
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001107void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list,
1108 bool secureOnly) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001109 int nYuvCount = ctx->listStats[mDpy].yuvCount;
1110 for(int index = 0;index < nYuvCount; index++){
1111 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
1112 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
1113
1114 if(!isYUVDoable(ctx, layer)) {
1115 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
1116 mCurrentFrame.isFBComposed[nYuvIndex] = true;
1117 mCurrentFrame.fbCount++;
1118 }
1119 } else {
1120 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001121 private_handle_t *hnd = (private_handle_t *)layer->handle;
1122 if(!secureOnly || isSecureBuffer(hnd)) {
1123 mCurrentFrame.isFBComposed[nYuvIndex] = false;
1124 mCurrentFrame.fbCount--;
1125 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001126 }
1127 }
1128 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001129
1130 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001131 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
1132 ALOGD_IF(isDebug(),"%s: fb count: %d",__FUNCTION__,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001133 mCurrentFrame.fbCount);
1134}
1135
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001136bool MDPComp::postHeuristicsHandling(hwc_context_t *ctx,
1137 hwc_display_contents_1_t* list) {
1138
1139 //Capability checks
1140 if(!resourceCheck(ctx, list)) {
1141 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
1142 return false;
1143 }
1144
1145 //Limitations checks
1146 if(!hwLimitationsCheck(ctx, list)) {
1147 ALOGD_IF(isDebug(), "%s: HW limitations",__FUNCTION__);
1148 return false;
1149 }
1150
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001151 //Configure framebuffer first if applicable
1152 if(mCurrentFrame.fbZ >= 0) {
1153 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, mCurrentFrame.fbZ)) {
1154 ALOGD_IF(isDebug(), "%s configure framebuffer failed",
1155 __FUNCTION__);
1156 return false;
1157 }
1158 }
1159
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001160 mCurrentFrame.map();
1161
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001162 if(!allocLayerPipes(ctx, list)) {
1163 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -07001164 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001165 }
1166
1167 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001168 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001169 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001170 int mdpIndex = mCurrentFrame.layerToMDP[index];
1171 hwc_layer_1_t* layer = &list->hwLayers[index];
1172
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301173 //Leave fbZ for framebuffer. CACHE/GLES layers go here.
1174 if(mdpNextZOrder == mCurrentFrame.fbZ) {
1175 mdpNextZOrder++;
1176 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001177 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1178 cur_pipe->zOrder = mdpNextZOrder++;
1179
radhakrishnac9a67412013-09-25 17:40:42 +05301180 private_handle_t *hnd = (private_handle_t *)layer->handle;
1181 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1182 if(configure4k2kYuv(ctx, layer,
1183 mCurrentFrame.mdpToLayer[mdpIndex])
1184 != 0 ){
1185 ALOGD_IF(isDebug(), "%s: Failed to configure split pipes \
1186 for layer %d",__FUNCTION__, index);
1187 return false;
1188 }
1189 else{
1190 mdpNextZOrder++;
1191 }
1192 continue;
1193 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001194 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
1195 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
radhakrishnac9a67412013-09-25 17:40:42 +05301196 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -07001197 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001198 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001199 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001200 }
1201
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001202 setRedraw(ctx, list);
Saurabh Shahaa236822013-04-24 18:07:26 -07001203 return true;
1204}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001205
Saurabh Shah173f4242013-11-20 09:50:12 -08001206bool MDPComp::resourceCheck(hwc_context_t *ctx,
1207 hwc_display_contents_1_t *list) {
1208 const bool fbUsed = mCurrentFrame.fbCount;
1209 if(mCurrentFrame.mdpCount > sMaxPipesPerMixer - fbUsed) {
1210 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
1211 return false;
1212 }
1213
1214 if(!arePipesAvailable(ctx, list)) {
1215 return false;
1216 }
1217
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001218 double size = calcMDPBytesRead(ctx, list);
Saurabh Shah173f4242013-11-20 09:50:12 -08001219 if(!bandwidthCheck(ctx, size)) {
1220 ALOGD_IF(isDebug(), "%s: Exceeds bandwidth",__FUNCTION__);
1221 return false;
1222 }
1223
1224 return true;
1225}
1226
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001227double MDPComp::calcMDPBytesRead(hwc_context_t *ctx,
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001228 hwc_display_contents_1_t* list) {
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001229 double size = 0;
1230 const double GIG = 1000000000.0;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001231
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001232 //Skip for targets where no device tree value for bw is supplied
1233 if(sMaxBw <= 0.0) {
1234 return 0.0;
1235 }
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001236
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001237 for (uint32_t i = 0; i < list->numHwLayers - 1; i++) {
1238 if(!mCurrentFrame.isFBComposed[i]) {
1239 hwc_layer_1_t* layer = &list->hwLayers[i];
1240 private_handle_t *hnd = (private_handle_t *)layer->handle;
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001241 if (hnd) {
Saurabh Shah62e1d732013-09-17 10:44:05 -07001242 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah90789162013-09-16 10:29:20 -07001243 hwc_rect_t dst = layer->displayFrame;
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001244 float bpp = ((float)hnd->size) / (hnd->width * hnd->height);
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001245 size += (bpp * (crop.right - crop.left) *
1246 (crop.bottom - crop.top) *
1247 ctx->dpyAttr[mDpy].yres / (dst.bottom - dst.top)) /
1248 GIG;
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001249 }
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001250 }
1251 }
1252
1253 if(mCurrentFrame.fbCount) {
1254 hwc_layer_1_t* layer = &list->hwLayers[list->numHwLayers - 1];
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001255 int tempw, temph;
1256 size += (getBufferSizeAndDimensions(
1257 layer->displayFrame.right - layer->displayFrame.left,
1258 layer->displayFrame.bottom - layer->displayFrame.top,
1259 HAL_PIXEL_FORMAT_RGBA_8888,
1260 tempw, temph)) / GIG;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001261 }
1262
1263 return size;
1264}
1265
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001266bool MDPComp::bandwidthCheck(hwc_context_t *ctx, const double& size) {
1267 //Skip for targets where no device tree value for bw is supplied
1268 if(sMaxBw <= 0.0) {
1269 return true;
1270 }
1271
1272 double panelRefRate =
1273 1000000000.0 / ctx->dpyAttr[mDpy].vsync_period;
1274 if((size * panelRefRate) > (sMaxBw - sBwClaimed)) {
1275 return false;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001276 }
1277 return true;
1278}
1279
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301280bool MDPComp::hwLimitationsCheck(hwc_context_t* ctx,
1281 hwc_display_contents_1_t* list) {
1282
1283 //A-family hw limitation:
1284 //If a layer need alpha scaling, MDP can not support.
1285 if(ctx->mMDP.version < qdutils::MDSS_V5) {
1286 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1287 if(!mCurrentFrame.isFBComposed[i] &&
1288 isAlphaScaled( &list->hwLayers[i])) {
1289 ALOGD_IF(isDebug(), "%s:frame needs alphaScaling",__FUNCTION__);
1290 return false;
1291 }
1292 }
1293 }
1294
1295 // On 8x26 & 8974 hw, we have a limitation of downscaling+blending.
1296 //If multiple layers requires downscaling and also they are overlapping
1297 //fall back to GPU since MDSS can not handle it.
1298 if(qdutils::MDPVersion::getInstance().is8x74v2() ||
1299 qdutils::MDPVersion::getInstance().is8x26()) {
1300 for(int i = 0; i < mCurrentFrame.layerCount-1; ++i) {
1301 hwc_layer_1_t* botLayer = &list->hwLayers[i];
1302 if(!mCurrentFrame.isFBComposed[i] &&
1303 isDownscaleRequired(botLayer)) {
1304 //if layer-i is marked for MDP and needs downscaling
1305 //check if any MDP layer on top of i & overlaps with layer-i
1306 for(int j = i+1; j < mCurrentFrame.layerCount; ++j) {
1307 hwc_layer_1_t* topLayer = &list->hwLayers[j];
1308 if(!mCurrentFrame.isFBComposed[j] &&
1309 isDownscaleRequired(topLayer)) {
1310 hwc_rect_t r = getIntersection(botLayer->displayFrame,
1311 topLayer->displayFrame);
1312 if(isValidRect(r))
1313 return false;
1314 }
1315 }
1316 }
1317 }
1318 }
1319 return true;
1320}
1321
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001322int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001323 int ret = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -07001324 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001325 MDPVersion& mdpVersion = qdutils::MDPVersion::getInstance();
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -07001326
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001327 //number of app layers exceeds MAX_NUM_APP_LAYERS fall back to GPU
1328 //do not cache the information for next draw cycle.
1329 if(numLayers > MAX_NUM_APP_LAYERS) {
1330 ALOGI("%s: Number of App layers exceeded the limit ",
1331 __FUNCTION__);
1332 mCachedFrame.reset();
1333 return -1;
1334 }
1335
Saurabh Shahb39f8152013-08-22 10:21:44 -07001336 //reset old data
1337 mCurrentFrame.reset(numLayers);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001338 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1339 mCurrentFrame.dropCount = 0;
Prabhanjan Kandula088bd892013-07-02 23:47:13 +05301340
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -07001341 // Detect the start of animation and fall back to GPU only once to cache
1342 // all the layers in FB and display FB content untill animation completes.
1343 if(ctx->listStats[mDpy].isDisplayAnimating) {
1344 mCurrentFrame.needsRedraw = false;
1345 if(ctx->mAnimationState[mDpy] == ANIMATION_STOPPED) {
1346 mCurrentFrame.needsRedraw = true;
1347 ctx->mAnimationState[mDpy] = ANIMATION_STARTED;
1348 }
1349 setMDPCompLayerFlags(ctx, list);
1350 mCachedFrame.updateCounts(mCurrentFrame);
1351 ret = -1;
1352 return ret;
1353 } else {
1354 ctx->mAnimationState[mDpy] = ANIMATION_STOPPED;
1355 }
1356
Saurabh Shahb39f8152013-08-22 10:21:44 -07001357 //Hard conditions, if not met, cannot do MDP comp
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001358 if(isFrameDoable(ctx)) {
1359 generateROI(ctx, list);
Saurabh Shahb39f8152013-08-22 10:21:44 -07001360
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001361 //Convert from kbps to gbps
1362 sMaxBw = mdpVersion.getHighBw() / 1000000.0;
1363 if (ctx->mExtDisplay->isConnected() ||
1364 ctx->mMDP.panel != MIPI_CMD_PANEL) {
1365 sMaxBw = mdpVersion.getLowBw() / 1000000.0;
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001366 }
1367
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001368 if(tryFullFrame(ctx, list) || tryVideoOnly(ctx, list)) {
1369 setMDPCompLayerFlags(ctx, list);
1370 } else {
1371 reset(ctx);
1372 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1373 mCurrentFrame.dropCount = 0;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001374 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001375 }
1376 } else {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001377 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
1378 __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001379 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001380 }
Saurabh Shahb39f8152013-08-22 10:21:44 -07001381
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001382 if(isDebug()) {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001383 ALOGD("GEOMETRY change: %d",
1384 (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001385 android::String8 sDump("");
1386 dump(sDump);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001387 ALOGD("%s",sDump.string());
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001388 }
1389
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001390 mCachedFrame.cacheAll(list);
1391 mCachedFrame.updateCounts(mCurrentFrame);
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001392 double panelRefRate =
1393 1000000000.0 / ctx->dpyAttr[mDpy].vsync_period;
1394 sBwClaimed += calcMDPBytesRead(ctx, list) * panelRefRate;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001395 return ret;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001396}
1397
radhakrishnac9a67412013-09-25 17:40:42 +05301398bool MDPComp::allocSplitVGPipesfor4k2k(hwc_context_t *ctx,
1399 hwc_display_contents_1_t* list, int index) {
1400
1401 bool bRet = true;
1402 hwc_layer_1_t* layer = &list->hwLayers[index];
1403 private_handle_t *hnd = (private_handle_t *)layer->handle;
1404 int mdpIndex = mCurrentFrame.layerToMDP[index];
1405 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
1406 info.pipeInfo = new MdpYUVPipeInfo;
1407 info.rot = NULL;
1408 MdpYUVPipeInfo& pipe_info = *(MdpYUVPipeInfo*)info.pipeInfo;
1409 ePipeType type = MDPCOMP_OV_VG;
1410
1411 pipe_info.lIndex = ovutils::OV_INVALID;
1412 pipe_info.rIndex = ovutils::OV_INVALID;
1413
1414 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
1415 if(pipe_info.lIndex == ovutils::OV_INVALID){
1416 bRet = false;
1417 ALOGD_IF(isDebug(),"%s: allocating first VG pipe failed",
1418 __FUNCTION__);
1419 }
1420 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
1421 if(pipe_info.rIndex == ovutils::OV_INVALID){
1422 bRet = false;
1423 ALOGD_IF(isDebug(),"%s: allocating second VG pipe failed",
1424 __FUNCTION__);
1425 }
1426 return bRet;
1427}
Saurabh Shah88e4d272013-09-03 13:31:29 -07001428//=============MDPCompNonSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001429
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001430void MDPCompNonSplit::adjustForSourceSplit(hwc_context_t *ctx,
radhakrishnac9a67412013-09-25 17:40:42 +05301431 hwc_display_contents_1_t* list){
1432 //As we split 4kx2k yuv layer and program to 2 VG pipes
1433 //(if available) increase mdpcount accordingly
1434 mCurrentFrame.mdpCount += ctx->listStats[mDpy].yuv4k2kCount;
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001435
1436 //If 4k2k Yuv layer split is possible, and if
1437 //fbz is above 4k2k layer, increment fb zorder by 1
1438 //as we split 4k2k layer and increment zorder for right half
1439 //of the layer
1440 if(mCurrentFrame.fbZ >= 0) {
1441 int n4k2kYuvCount = ctx->listStats[mDpy].yuv4k2kCount;
1442 for(int index = 0; index < n4k2kYuvCount; index++){
1443 int n4k2kYuvIndex =
1444 ctx->listStats[mDpy].yuv4k2kIndices[index];
1445 if(mCurrentFrame.fbZ > n4k2kYuvIndex){
1446 mCurrentFrame.fbZ += 1;
1447 }
1448 }
1449 }
radhakrishnac9a67412013-09-25 17:40:42 +05301450}
1451
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001452/*
1453 * Configures pipe(s) for MDP composition
1454 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001455int MDPCompNonSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001456 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001457 MdpPipeInfoNonSplit& mdp_info =
1458 *(static_cast<MdpPipeInfoNonSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001459 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
1460 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1461 eIsFg isFg = IS_FG_OFF;
1462 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001463
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001464 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
1465 __FUNCTION__, layer, zOrder, dest);
1466
Saurabh Shah88e4d272013-09-03 13:31:29 -07001467 return configureNonSplit(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001468 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001469}
1470
Saurabh Shah88e4d272013-09-03 13:31:29 -07001471bool MDPCompNonSplit::arePipesAvailable(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001472 hwc_display_contents_1_t* list) {
1473 overlay::Overlay& ov = *ctx->mOverlay;
1474 int numPipesNeeded = mCurrentFrame.mdpCount;
1475 int availPipes = ov.availablePipes(mDpy, Overlay::MIXER_DEFAULT);
1476
1477 //Reserve pipe for FB
1478 if(mCurrentFrame.fbCount)
1479 availPipes -= 1;
1480
1481 if(numPipesNeeded > availPipes) {
1482 ALOGD_IF(isDebug(), "%s: Insufficient pipes, dpy %d needed %d, avail %d",
1483 __FUNCTION__, mDpy, numPipesNeeded, availPipes);
1484 return false;
1485 }
1486
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001487 if(not areVGPipesAvailable(ctx, list)) {
1488 return false;
1489 }
1490
1491 return true;
1492}
1493
1494bool MDPCompNonSplit::areVGPipesAvailable(hwc_context_t *ctx,
1495 hwc_display_contents_1_t* list) {
1496 overlay::Overlay& ov = *ctx->mOverlay;
1497 int pipesNeeded = 0;
1498 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1499 if(!mCurrentFrame.isFBComposed[i]) {
1500 hwc_layer_1_t* layer = &list->hwLayers[i];
1501 hwc_rect_t dst = layer->displayFrame;
1502 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301503 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1504 pipesNeeded = pipesNeeded + 2;
1505 }
1506 else if(isYuvBuffer(hnd)) {
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001507 pipesNeeded++;
1508 }
1509 }
1510 }
1511
1512 int availableVGPipes = ov.availablePipes(mDpy, ovutils::OV_MDP_PIPE_VG);
1513 if(pipesNeeded > availableVGPipes) {
1514 ALOGD_IF(isDebug(), "%s: Insufficient VG pipes for video layers"
1515 "dpy %d needed %d, avail %d",
1516 __FUNCTION__, mDpy, pipesNeeded, availableVGPipes);
1517 return false;
1518 }
1519
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001520 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001521}
1522
Saurabh Shah88e4d272013-09-03 13:31:29 -07001523bool MDPCompNonSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001524 hwc_display_contents_1_t* list) {
1525 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001526
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001527 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001528
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001529 hwc_layer_1_t* layer = &list->hwLayers[index];
1530 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301531 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1532 if(allocSplitVGPipesfor4k2k(ctx, list, index)){
1533 continue;
1534 }
1535 }
1536
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001537 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001538 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001539 info.pipeInfo = new MdpPipeInfoNonSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08001540 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001541 MdpPipeInfoNonSplit& pipe_info = *(MdpPipeInfoNonSplit*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001542 ePipeType type = MDPCOMP_OV_ANY;
1543
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001544 if(isYuvBuffer(hnd)) {
1545 type = MDPCOMP_OV_VG;
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301546 } else if(!qhwc::needsScaling(layer)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001547 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
1548 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001549 type = MDPCOMP_OV_DMA;
1550 }
1551
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001552 pipe_info.index = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001553 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001554 ALOGD_IF(isDebug(), "%s: Unable to get pipe type = %d",
1555 __FUNCTION__, (int) type);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001556 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001557 }
1558 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001559 return true;
1560}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001561
radhakrishnac9a67412013-09-25 17:40:42 +05301562int MDPCompNonSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1563 PipeLayerPair& PipeLayerPair) {
1564 MdpYUVPipeInfo& mdp_info =
1565 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1566 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1567 eIsFg isFg = IS_FG_OFF;
1568 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1569 eDest lDest = mdp_info.lIndex;
1570 eDest rDest = mdp_info.rIndex;
1571
1572 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1573 lDest, rDest, &PipeLayerPair.rot);
1574}
1575
Saurabh Shah88e4d272013-09-03 13:31:29 -07001576bool MDPCompNonSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001577
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001578 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001579 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1580 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -08001581 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001582
1583 if(!ctx || !list) {
1584 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001585 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001586 }
1587
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301588 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1589 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1590 return true;
1591 }
1592
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001593 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001594 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001595 idleInvalidator->markForSleep();
1596
1597 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001598 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001599
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001600 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1601 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001602 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001603 if(mCurrentFrame.isFBComposed[i]) continue;
1604
Naseer Ahmed5b6708a2012-08-02 13:46:08 -07001605 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001606 private_handle_t *hnd = (private_handle_t *)layer->handle;
1607 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001608 if (!(layer->flags & HWC_COLOR_FILL)) {
1609 ALOGE("%s handle null", __FUNCTION__);
1610 return false;
1611 }
1612 // No PLAY for Color layer
1613 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1614 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001615 }
1616
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001617 int mdpIndex = mCurrentFrame.layerToMDP[i];
1618
radhakrishnac9a67412013-09-25 17:40:42 +05301619 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1620 {
1621 MdpYUVPipeInfo& pipe_info =
1622 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1623 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1624 ovutils::eDest indexL = pipe_info.lIndex;
1625 ovutils::eDest indexR = pipe_info.rIndex;
1626 int fd = hnd->fd;
1627 uint32_t offset = hnd->offset;
1628 if(rot) {
1629 rot->queueBuffer(fd, offset);
1630 fd = rot->getDstMemId();
1631 offset = rot->getDstOffset();
1632 }
1633 if(indexL != ovutils::OV_INVALID) {
1634 ovutils::eDest destL = (ovutils::eDest)indexL;
1635 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1636 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1637 if (!ov.queueBuffer(fd, offset, destL)) {
1638 ALOGE("%s: queueBuffer failed for display:%d",
1639 __FUNCTION__, mDpy);
1640 return false;
1641 }
1642 }
1643
1644 if(indexR != ovutils::OV_INVALID) {
1645 ovutils::eDest destR = (ovutils::eDest)indexR;
1646 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1647 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1648 if (!ov.queueBuffer(fd, offset, destR)) {
1649 ALOGE("%s: queueBuffer failed for display:%d",
1650 __FUNCTION__, mDpy);
1651 return false;
1652 }
1653 }
1654 }
1655 else{
1656 MdpPipeInfoNonSplit& pipe_info =
Saurabh Shah88e4d272013-09-03 13:31:29 -07001657 *(MdpPipeInfoNonSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
radhakrishnac9a67412013-09-25 17:40:42 +05301658 ovutils::eDest dest = pipe_info.index;
1659 if(dest == ovutils::OV_INVALID) {
1660 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001661 return false;
radhakrishnac9a67412013-09-25 17:40:42 +05301662 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001663
radhakrishnac9a67412013-09-25 17:40:42 +05301664 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1665 continue;
1666 }
1667
1668 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1669 using pipe: %d", __FUNCTION__, layer,
1670 hnd, dest );
1671
1672 int fd = hnd->fd;
1673 uint32_t offset = hnd->offset;
1674
1675 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1676 if(rot) {
1677 if(!rot->queueBuffer(fd, offset))
1678 return false;
1679 fd = rot->getDstMemId();
1680 offset = rot->getDstOffset();
1681 }
1682
1683 if (!ov.queueBuffer(fd, offset, dest)) {
1684 ALOGE("%s: queueBuffer failed for display:%d ",
1685 __FUNCTION__, mDpy);
1686 return false;
1687 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001688 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001689
1690 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001691 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001692 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001693}
1694
Saurabh Shah88e4d272013-09-03 13:31:29 -07001695//=============MDPCompSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001696
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001697void MDPCompSplit::adjustForSourceSplit(hwc_context_t *ctx,
radhakrishnac9a67412013-09-25 17:40:42 +05301698 hwc_display_contents_1_t* list){
1699 //if 4kx2k yuv layer is totally present in either in left half
1700 //or right half then try splitting the yuv layer to avoid decimation
1701 int n4k2kYuvCount = ctx->listStats[mDpy].yuv4k2kCount;
1702 const int lSplit = getLeftSplit(ctx, mDpy);
1703 for(int index = 0; index < n4k2kYuvCount; index++){
1704 int n4k2kYuvIndex = ctx->listStats[mDpy].yuv4k2kIndices[index];
1705 hwc_layer_1_t* layer = &list->hwLayers[n4k2kYuvIndex];
1706 hwc_rect_t dst = layer->displayFrame;
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001707 if((dst.left > lSplit) || (dst.right < lSplit)) {
radhakrishnac9a67412013-09-25 17:40:42 +05301708 mCurrentFrame.mdpCount += 1;
1709 }
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001710 if(mCurrentFrame.fbZ > n4k2kYuvIndex){
1711 mCurrentFrame.fbZ += 1;
1712 }
radhakrishnac9a67412013-09-25 17:40:42 +05301713 }
1714}
1715
Saurabh Shah88e4d272013-09-03 13:31:29 -07001716int MDPCompSplit::pipesNeeded(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001717 hwc_display_contents_1_t* list,
1718 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001719 int pipesNeeded = 0;
Saurabh Shah67a38c32013-06-10 16:23:15 -07001720 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001721
1722 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001723
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001724 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1725 if(!mCurrentFrame.isFBComposed[i]) {
1726 hwc_layer_1_t* layer = &list->hwLayers[i];
1727 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001728 if(mixer == Overlay::MIXER_LEFT && dst.left < lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001729 pipesNeeded++;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001730 } else if(mixer == Overlay::MIXER_RIGHT && dst.right > lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001731 pipesNeeded++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001732 }
1733 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001734 }
1735 return pipesNeeded;
1736}
1737
Saurabh Shah88e4d272013-09-03 13:31:29 -07001738bool MDPCompSplit::arePipesAvailable(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001739 hwc_display_contents_1_t* list) {
1740 overlay::Overlay& ov = *ctx->mOverlay;
Saurabh Shah082468e2013-09-12 10:05:32 -07001741 int totalPipesNeeded = 0;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001742
1743 for(int i = 0; i < Overlay::MIXER_MAX; i++) {
1744 int numPipesNeeded = pipesNeeded(ctx, list, i);
1745 int availPipes = ov.availablePipes(mDpy, i);
1746
1747 //Reserve pipe(s)for FB
1748 if(mCurrentFrame.fbCount)
Saurabh Shah082468e2013-09-12 10:05:32 -07001749 numPipesNeeded += 1;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001750
Saurabh Shah082468e2013-09-12 10:05:32 -07001751 totalPipesNeeded += numPipesNeeded;
1752
1753 //Per mixer check.
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001754 if(numPipesNeeded > availPipes) {
1755 ALOGD_IF(isDebug(), "%s: Insufficient pipes for "
1756 "dpy %d mixer %d needed %d, avail %d",
1757 __FUNCTION__, mDpy, i, numPipesNeeded, availPipes);
1758 return false;
1759 }
1760 }
Saurabh Shah082468e2013-09-12 10:05:32 -07001761
1762 //Per display check, since unused pipes can get counted twice.
1763 int totalPipesAvailable = ov.availablePipes(mDpy);
1764 if(totalPipesNeeded > totalPipesAvailable) {
1765 ALOGD_IF(isDebug(), "%s: Insufficient pipes for "
1766 "dpy %d needed %d, avail %d",
1767 __FUNCTION__, mDpy, totalPipesNeeded, totalPipesAvailable);
1768 return false;
1769 }
1770
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001771 if(not areVGPipesAvailable(ctx, list)) {
1772 return false;
1773 }
1774
1775 return true;
1776}
1777
1778bool MDPCompSplit::areVGPipesAvailable(hwc_context_t *ctx,
1779 hwc_display_contents_1_t* list) {
1780 overlay::Overlay& ov = *ctx->mOverlay;
1781 int pipesNeeded = 0;
1782 const int lSplit = getLeftSplit(ctx, mDpy);
1783 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1784 if(!mCurrentFrame.isFBComposed[i]) {
1785 hwc_layer_1_t* layer = &list->hwLayers[i];
1786 hwc_rect_t dst = layer->displayFrame;
1787 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301788 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1789 if((dst.left > lSplit)||(dst.right < lSplit)){
1790 pipesNeeded = pipesNeeded + 2;
1791 continue;
1792 }
1793 }
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001794 if(isYuvBuffer(hnd)) {
1795 if(dst.left < lSplit) {
1796 pipesNeeded++;
1797 }
1798 if(dst.right > lSplit) {
1799 pipesNeeded++;
1800 }
1801 }
1802 }
1803 }
1804
1805 int availableVGPipes = ov.availablePipes(mDpy, ovutils::OV_MDP_PIPE_VG);
1806 if(pipesNeeded > availableVGPipes) {
1807 ALOGD_IF(isDebug(), "%s: Insufficient VG pipes for video layers"
1808 "dpy %d needed %d, avail %d",
1809 __FUNCTION__, mDpy, pipesNeeded, availableVGPipes);
1810 return false;
1811 }
1812
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001813 return true;
1814}
1815
Saurabh Shah88e4d272013-09-03 13:31:29 -07001816bool MDPCompSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
1817 MdpPipeInfoSplit& pipe_info,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001818 ePipeType type) {
1819 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001820 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001821
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001822 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001823 pipe_info.lIndex = ovutils::OV_INVALID;
1824 pipe_info.rIndex = ovutils::OV_INVALID;
1825
1826 if (dst.left < lSplit) {
1827 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_LEFT);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001828 if(pipe_info.lIndex == ovutils::OV_INVALID)
1829 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001830 }
1831
1832 if(dst.right > lSplit) {
1833 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_RIGHT);
1834 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001835 return false;
1836 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001837
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001838 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001839}
1840
Saurabh Shah88e4d272013-09-03 13:31:29 -07001841bool MDPCompSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001842 hwc_display_contents_1_t* list) {
1843 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001844
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001845 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001846
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001847 hwc_layer_1_t* layer = &list->hwLayers[index];
1848 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301849 hwc_rect_t dst = layer->displayFrame;
1850 const int lSplit = getLeftSplit(ctx, mDpy);
1851 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1852 if((dst.left > lSplit)||(dst.right < lSplit)){
1853 if(allocSplitVGPipesfor4k2k(ctx, list, index)){
1854 continue;
1855 }
1856 }
1857 }
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001858 int mdpIndex = mCurrentFrame.layerToMDP[index];
1859 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001860 info.pipeInfo = new MdpPipeInfoSplit;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001861 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001862 MdpPipeInfoSplit& pipe_info = *(MdpPipeInfoSplit*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001863 ePipeType type = MDPCOMP_OV_ANY;
1864
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001865 if(isYuvBuffer(hnd)) {
1866 type = MDPCOMP_OV_VG;
Sushil Chauhan15a2ea62013-09-04 18:28:36 -07001867 } else if(!qhwc::needsScalingWithSplit(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001868 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001869 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001870 type = MDPCOMP_OV_DMA;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001871 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001872
1873 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001874 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type = %d",
1875 __FUNCTION__, (int) type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001876 return false;
1877 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001878 }
1879 return true;
1880}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001881
radhakrishnac9a67412013-09-25 17:40:42 +05301882int MDPCompSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1883 PipeLayerPair& PipeLayerPair) {
1884 const int lSplit = getLeftSplit(ctx, mDpy);
1885 hwc_rect_t dst = layer->displayFrame;
1886 if((dst.left > lSplit)||(dst.right < lSplit)){
1887 MdpYUVPipeInfo& mdp_info =
1888 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1889 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1890 eIsFg isFg = IS_FG_OFF;
1891 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1892 eDest lDest = mdp_info.lIndex;
1893 eDest rDest = mdp_info.rIndex;
1894
1895 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1896 lDest, rDest, &PipeLayerPair.rot);
1897 }
1898 else{
1899 return configure(ctx, layer, PipeLayerPair);
1900 }
1901}
1902
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001903/*
1904 * Configures pipe(s) for MDP composition
1905 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001906int MDPCompSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001907 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001908 MdpPipeInfoSplit& mdp_info =
1909 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001910 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1911 eIsFg isFg = IS_FG_OFF;
1912 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1913 eDest lDest = mdp_info.lIndex;
1914 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001915
1916 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1917 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1918
Saurabh Shah88e4d272013-09-03 13:31:29 -07001919 return configureSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001920 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001921}
1922
Saurabh Shah88e4d272013-09-03 13:31:29 -07001923bool MDPCompSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001924
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001925 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001926 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1927 return true;
1928 }
1929
1930 if(!ctx || !list) {
1931 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001932 return false;
1933 }
1934
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301935 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1936 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1937 return true;
1938 }
1939
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001940 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001941 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001942 idleInvalidator->markForSleep();
1943
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001944 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001945 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001946
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001947 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1948 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001949 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001950 if(mCurrentFrame.isFBComposed[i]) continue;
1951
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001952 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001953 private_handle_t *hnd = (private_handle_t *)layer->handle;
1954 if(!hnd) {
1955 ALOGE("%s handle null", __FUNCTION__);
1956 return false;
1957 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001958
1959 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1960 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001961 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001962
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001963 int mdpIndex = mCurrentFrame.layerToMDP[i];
1964
radhakrishnac9a67412013-09-25 17:40:42 +05301965 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1966 {
1967 MdpYUVPipeInfo& pipe_info =
1968 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1969 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1970 ovutils::eDest indexL = pipe_info.lIndex;
1971 ovutils::eDest indexR = pipe_info.rIndex;
1972 int fd = hnd->fd;
1973 uint32_t offset = hnd->offset;
1974 if(rot) {
1975 rot->queueBuffer(fd, offset);
1976 fd = rot->getDstMemId();
1977 offset = rot->getDstOffset();
1978 }
1979 if(indexL != ovutils::OV_INVALID) {
1980 ovutils::eDest destL = (ovutils::eDest)indexL;
1981 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1982 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1983 if (!ov.queueBuffer(fd, offset, destL)) {
1984 ALOGE("%s: queueBuffer failed for display:%d",
1985 __FUNCTION__, mDpy);
1986 return false;
1987 }
1988 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001989
radhakrishnac9a67412013-09-25 17:40:42 +05301990 if(indexR != ovutils::OV_INVALID) {
1991 ovutils::eDest destR = (ovutils::eDest)indexR;
1992 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1993 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1994 if (!ov.queueBuffer(fd, offset, destR)) {
1995 ALOGE("%s: queueBuffer failed for display:%d",
1996 __FUNCTION__, mDpy);
1997 return false;
1998 }
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001999 }
2000 }
radhakrishnac9a67412013-09-25 17:40:42 +05302001 else{
2002 MdpPipeInfoSplit& pipe_info =
2003 *(MdpPipeInfoSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
2004 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07002005
radhakrishnac9a67412013-09-25 17:40:42 +05302006 ovutils::eDest indexL = pipe_info.lIndex;
2007 ovutils::eDest indexR = pipe_info.rIndex;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002008
radhakrishnac9a67412013-09-25 17:40:42 +05302009 int fd = hnd->fd;
2010 int offset = hnd->offset;
2011
2012 if(ctx->mAD->isModeOn()) {
2013 if(ctx->mAD->draw(ctx, fd, offset)) {
2014 fd = ctx->mAD->getDstFd(ctx);
2015 offset = ctx->mAD->getDstOffset(ctx);
2016 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002017 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002018
radhakrishnac9a67412013-09-25 17:40:42 +05302019 if(rot) {
2020 rot->queueBuffer(fd, offset);
2021 fd = rot->getDstMemId();
2022 offset = rot->getDstOffset();
2023 }
2024
2025 //************* play left mixer **********
2026 if(indexL != ovutils::OV_INVALID) {
2027 ovutils::eDest destL = (ovutils::eDest)indexL;
2028 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
2029 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
2030 if (!ov.queueBuffer(fd, offset, destL)) {
2031 ALOGE("%s: queueBuffer failed for left mixer",
2032 __FUNCTION__);
2033 return false;
2034 }
2035 }
2036
2037 //************* play right mixer **********
2038 if(indexR != ovutils::OV_INVALID) {
2039 ovutils::eDest destR = (ovutils::eDest)indexR;
2040 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
2041 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
2042 if (!ov.queueBuffer(fd, offset, destR)) {
2043 ALOGE("%s: queueBuffer failed for right mixer",
2044 __FUNCTION__);
2045 return false;
2046 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002047 }
2048 }
Saurabh Shahacf10202013-02-26 10:15:15 -08002049
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002050 layerProp[i].mFlags &= ~HWC_MDPCOMP;
2051 }
Saurabh Shahacf10202013-02-26 10:15:15 -08002052
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002053 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002054}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002055}; //namespace
2056