blob: 40222eeac3cfa24debbcdc2446cd874bc58109d4 [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 Shah2a4eb1b2013-07-22 16:33:23 -0700160void MDPComp::reset(const int& numLayers, hwc_display_contents_1_t* list) {
161 mCurrentFrame.reset(numLayers);
162 mCachedFrame.cacheAll(list);
163 mCachedFrame.updateCounts(mCurrentFrame);
164}
165
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700166void MDPComp::timeout_handler(void *udata) {
167 struct hwc_context_t* ctx = (struct hwc_context_t*)(udata);
168
169 if(!ctx) {
170 ALOGE("%s: received empty data in timer callback", __FUNCTION__);
171 return;
172 }
173
Jesse Hall3be78d92012-08-21 15:12:23 -0700174 if(!ctx->proc) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700175 ALOGE("%s: HWC proc not registered", __FUNCTION__);
176 return;
177 }
178 sIdleFallBack = true;
179 /* Trigger SF to redraw the current frame */
Jesse Hall3be78d92012-08-21 15:12:23 -0700180 ctx->proc->invalidate(ctx->proc);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700181}
182
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800183void MDPComp::setMDPCompLayerFlags(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800184 hwc_display_contents_1_t* list) {
185 LayerProp *layerProp = ctx->layerProp[mDpy];
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800186
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800187 for(int index = 0; index < ctx->listStats[mDpy].numAppLayers; index++) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800188 hwc_layer_1_t* layer = &(list->hwLayers[index]);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800189 if(!mCurrentFrame.isFBComposed[index]) {
190 layerProp[index].mFlags |= HWC_MDPCOMP;
191 layer->compositionType = HWC_OVERLAY;
192 layer->hints |= HWC_HINT_CLEAR_FB;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800193 } else {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700194 /* Drop the layer when its already present in FB OR when it lies
195 * outside frame's ROI */
196 if(!mCurrentFrame.needsRedraw || mCurrentFrame.drop[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800197 layer->compositionType = HWC_OVERLAY;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700198 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800199 }
200 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700201}
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500202
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800203MDPComp::FrameInfo::FrameInfo() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700204 reset(0);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800205}
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800206
Saurabh Shahaa236822013-04-24 18:07:26 -0700207void MDPComp::FrameInfo::reset(const int& numLayers) {
208 for(int i = 0 ; i < MAX_PIPES_PER_MIXER && numLayers; i++ ) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800209 if(mdpToLayer[i].pipeInfo) {
210 delete mdpToLayer[i].pipeInfo;
211 mdpToLayer[i].pipeInfo = NULL;
212 //We dont own the rotator
213 mdpToLayer[i].rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800214 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800215 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800216
217 memset(&mdpToLayer, 0, sizeof(mdpToLayer));
218 memset(&layerToMDP, -1, sizeof(layerToMDP));
Saurabh Shahaa236822013-04-24 18:07:26 -0700219 memset(&isFBComposed, 1, sizeof(isFBComposed));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800220
Saurabh Shahaa236822013-04-24 18:07:26 -0700221 layerCount = numLayers;
222 fbCount = numLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800223 mdpCount = 0;
Saurabh Shah2f3895f2013-05-02 10:13:31 -0700224 needsRedraw = true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800225 fbZ = 0;
226}
227
Saurabh Shahaa236822013-04-24 18:07:26 -0700228void MDPComp::FrameInfo::map() {
229 // populate layer and MDP maps
230 int mdpIdx = 0;
231 for(int idx = 0; idx < layerCount; idx++) {
232 if(!isFBComposed[idx]) {
233 mdpToLayer[mdpIdx].listIndex = idx;
234 layerToMDP[idx] = mdpIdx++;
235 }
236 }
237}
238
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800239MDPComp::LayerCache::LayerCache() {
240 reset();
241}
242
243void MDPComp::LayerCache::reset() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700244 memset(&hnd, 0, sizeof(hnd));
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530245 memset(&isFBComposed, true, sizeof(isFBComposed));
246 memset(&drop, false, sizeof(drop));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800247 layerCount = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -0700248}
249
250void MDPComp::LayerCache::cacheAll(hwc_display_contents_1_t* list) {
251 const int numAppLayers = list->numHwLayers - 1;
252 for(int i = 0; i < numAppLayers; i++) {
253 hnd[i] = list->hwLayers[i].handle;
254 }
255}
256
257void MDPComp::LayerCache::updateCounts(const FrameInfo& curFrame) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700258 layerCount = curFrame.layerCount;
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530259 memcpy(&isFBComposed, &curFrame.isFBComposed, sizeof(isFBComposed));
260 memcpy(&drop, &curFrame.drop, sizeof(drop));
261}
262
Jeykumar Sankaran988d3682013-11-15 11:57:16 -0800263bool MDPComp::LayerCache::isSameFrame(const FrameInfo& curFrame,
264 hwc_display_contents_1_t* list) {
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530265 if(layerCount != curFrame.layerCount)
266 return false;
267 for(int i = 0; i < curFrame.layerCount; i++) {
268 if((curFrame.isFBComposed[i] != isFBComposed[i]) ||
269 (curFrame.drop[i] != drop[i])) {
270 return false;
271 }
Jeykumar Sankaran988d3682013-11-15 11:57:16 -0800272 if(curFrame.isFBComposed[i] &&
273 (hnd[i] != list->hwLayers[i].handle)){
274 return false;
275 }
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530276 }
277 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800278}
279
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700280bool MDPComp::isSupportedForMDPComp(hwc_context_t *ctx, hwc_layer_1_t* layer) {
281 private_handle_t *hnd = (private_handle_t *)layer->handle;
282 if((not isYuvBuffer(hnd) and has90Transform(layer)) or
283 (not isValidDimension(ctx,layer))
284 //More conditions here, SKIP, sRGB+Blend etc
285 ) {
286 return false;
287 }
288 return true;
289}
290
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530291bool MDPComp::isValidDimension(hwc_context_t *ctx, hwc_layer_1_t *layer) {
Saurabh Shah4fdde762013-04-30 18:47:33 -0700292 const int dpy = HWC_DISPLAY_PRIMARY;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800293 private_handle_t *hnd = (private_handle_t *)layer->handle;
294
295 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -0700296 if (layer->flags & HWC_COLOR_FILL) {
297 // Color layer
298 return true;
299 }
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800300 ALOGE("%s: layer handle is NULL", __FUNCTION__);
301 return false;
302 }
303
Naseer Ahmede850a802013-09-06 13:12:52 -0400304 //XXX: Investigate doing this with pixel phase on MDSS
Naseer Ahmede77f8082013-10-10 13:42:48 -0400305 if(!isSecureBuffer(hnd) && isNonIntegralSourceCrop(layer->sourceCropf))
Naseer Ahmede850a802013-09-06 13:12:52 -0400306 return false;
307
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800308 int hw_w = ctx->dpyAttr[mDpy].xres;
309 int hw_h = ctx->dpyAttr[mDpy].yres;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800310
Saurabh Shah62e1d732013-09-17 10:44:05 -0700311 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700312 hwc_rect_t dst = layer->displayFrame;
Saurabh Shah4fdde762013-04-30 18:47:33 -0700313 int crop_w = crop.right - crop.left;
314 int crop_h = crop.bottom - crop.top;
315 int dst_w = dst.right - dst.left;
316 int dst_h = dst.bottom - dst.top;
317 float w_dscale = ceilf((float)crop_w / (float)dst_w);
318 float h_dscale = ceilf((float)crop_h / (float)dst_h);
319
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800320 /* Workaround for MDP HW limitation in DSI command mode panels where
321 * FPS will not go beyond 30 if buffers on RGB pipes are of width or height
322 * less than 5 pixels
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530323 * There also is a HW limilation in MDP, minimum block size is 2x2
324 * Fallback to GPU if height is less than 2.
325 */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800326 if((crop_w < 5)||(crop_h < 5))
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800327 return false;
328
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800329 if((w_dscale > 1.0f) || (h_dscale > 1.0f)) {
330 const uint32_t downscale =
Saurabh Shah4fdde762013-04-30 18:47:33 -0700331 qdutils::MDPVersion::getInstance().getMaxMDPDownscale();
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800332 if(ctx->mMDP.version >= qdutils::MDSS_V5) {
333 /* Workaround for downscales larger than 4x.
334 * Will be removed once decimator block is enabled for MDSS
335 */
336 if(!qdutils::MDPVersion::getInstance().supportsDecimation()) {
337 if(crop_w > MAX_DISPLAY_DIM || w_dscale > downscale ||
338 h_dscale > downscale)
339 return false;
340 } else {
341 if(w_dscale > 64 || h_dscale > 64)
342 return false;
343 }
344 } else { //A-family
345 if(w_dscale > downscale || h_dscale > downscale)
Saurabh Shah4fdde762013-04-30 18:47:33 -0700346 return false;
347 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700348 }
349
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800350 return true;
351}
352
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700353ovutils::eDest MDPComp::getMdpPipe(hwc_context_t *ctx, ePipeType type,
354 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800355 overlay::Overlay& ov = *ctx->mOverlay;
356 ovutils::eDest mdp_pipe = ovutils::OV_INVALID;
357
358 switch(type) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800359 case MDPCOMP_OV_DMA:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700360 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_DMA, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800361 if(mdp_pipe != ovutils::OV_INVALID) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800362 return mdp_pipe;
363 }
364 case MDPCOMP_OV_ANY:
365 case MDPCOMP_OV_RGB:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700366 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800367 if(mdp_pipe != ovutils::OV_INVALID) {
368 return mdp_pipe;
369 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800370
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800371 if(type == MDPCOMP_OV_RGB) {
372 //Requested only for RGB pipe
373 break;
374 }
375 case MDPCOMP_OV_VG:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700376 return ov.nextPipe(ovutils::OV_MDP_PIPE_VG, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800377 default:
378 ALOGE("%s: Invalid pipe type",__FUNCTION__);
379 return ovutils::OV_INVALID;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800380 };
381 return ovutils::OV_INVALID;
382}
383
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800384bool MDPComp::isFrameDoable(hwc_context_t *ctx) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700385 bool ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700386 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800387
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800388 if(!isEnabled()) {
389 ALOGD_IF(isDebug(),"%s: MDP Comp. not enabled.", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700390 ret = false;
Saurabh Shahd4e65852013-06-17 11:33:53 -0700391 } else if(qdutils::MDPVersion::getInstance().is8x26() &&
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700392 ctx->mVideoTransFlag && ctx->mVirtualDisplay->isConnected()) {
Saurabh Shahd4e65852013-06-17 11:33:53 -0700393 //1 Padding round to shift pipes across mixers
394 ALOGD_IF(isDebug(),"%s: MDP Comp. video transition padding round",
395 __FUNCTION__);
396 ret = false;
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700397 } else if(ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isConfiguring ||
398 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isConfiguring) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800399 ALOGD_IF( isDebug(),"%s: External Display connection is pending",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800400 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700401 ret = false;
Saurabh Shahaa236822013-04-24 18:07:26 -0700402 } else if(ctx->isPaddingRound) {
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700403 ctx->isPaddingRound = false;
404 ALOGD_IF(isDebug(), "%s: padding round",__FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700405 ret = false;
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700406 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700407 return ret;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800408}
409
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800410/*
411 * 1) Identify layers that are not visible in the updating ROI and drop them
412 * from composition.
413 * 2) If we have a scaling layers which needs cropping against generated ROI.
414 * Reset ROI to full resolution.
415 */
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700416bool MDPComp::validateAndApplyROI(hwc_context_t *ctx,
417 hwc_display_contents_1_t* list, hwc_rect_t roi) {
418 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
419
420 if(!isValidRect(roi))
421 return false;
422
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800423 hwc_rect_t visibleRect = roi;
424
425 for(int i = numAppLayers - 1; i >= 0; i--){
426
427 if(!isValidRect(visibleRect)) {
428 mCurrentFrame.drop[i] = true;
429 mCurrentFrame.dropCount++;
430 }
431
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700432 const hwc_layer_1_t* layer = &list->hwLayers[i];
433
434 hwc_rect_t dstRect = layer->displayFrame;
Arun Kumar K.R91090c72013-10-28 19:40:18 -0700435 hwc_rect_t srcRect = integerizeSourceCrop(layer->sourceCropf);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700436 int transform = layer->transform;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700437
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800438 hwc_rect_t res = getIntersection(visibleRect, dstRect);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700439
440 int res_w = res.right - res.left;
441 int res_h = res.bottom - res.top;
442 int dst_w = dstRect.right - dstRect.left;
443 int dst_h = dstRect.bottom - dstRect.top;
444
445 if(!isValidRect(res)) {
446 mCurrentFrame.drop[i] = true;
447 mCurrentFrame.dropCount++;
448 }else {
449 /* Reset frame ROI when any layer which needs scaling also needs ROI
450 * cropping */
451 if((res_w != dst_w || res_h != dst_h) &&
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530452 needsScaling (layer)) {
Arpita Banerjeed8965982013-11-08 17:27:33 -0800453 ALOGI("%s: Resetting ROI due to scaling", __FUNCTION__);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700454 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
455 mCurrentFrame.dropCount = 0;
456 return false;
457 }
458 }
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800459
460 if (layer->blending == HWC_BLENDING_NONE)
461 visibleRect = deductRect(visibleRect, res);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700462 }
463 return true;
464}
465
466void MDPComp::generateROI(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
467 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
468
469 if(!sEnablePartialFrameUpdate) {
470 return;
471 }
472
473 if(mDpy || isDisplaySplit(ctx, mDpy)){
474 ALOGE_IF(isDebug(), "%s: ROI not supported for"
475 "the (1) external / virtual display's (2) dual DSI displays",
476 __FUNCTION__);
477 return;
478 }
479
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800480 if(isSkipPresent(ctx, mDpy))
481 return;
482
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700483 if(list->flags & HWC_GEOMETRY_CHANGED)
484 return;
485
486 struct hwc_rect roi = (struct hwc_rect){0, 0, 0, 0};
487 for(int index = 0; index < numAppLayers; index++ ) {
488 if ((mCachedFrame.hnd[index] != list->hwLayers[index].handle) ||
489 isYuvBuffer((private_handle_t *)list->hwLayers[index].handle)) {
490 hwc_rect_t dstRect = list->hwLayers[index].displayFrame;
Arun Kumar K.R91090c72013-10-28 19:40:18 -0700491 hwc_rect_t srcRect = integerizeSourceCrop(
492 list->hwLayers[index].sourceCropf);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700493 int transform = list->hwLayers[index].transform;
494
495 /* Intersect against display boundaries */
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700496 roi = getUnion(roi, dstRect);
497 }
498 }
499
500 if(!validateAndApplyROI(ctx, list, roi)){
501 roi = (struct hwc_rect) {0, 0,
502 (int)ctx->dpyAttr[mDpy].xres, (int)ctx->dpyAttr[mDpy].yres};
503 }
504
505 ctx->listStats[mDpy].roi.x = roi.left;
506 ctx->listStats[mDpy].roi.y = roi.top;
507 ctx->listStats[mDpy].roi.w = roi.right - roi.left;
508 ctx->listStats[mDpy].roi.h = roi.bottom - roi.top;
509
510 ALOGD_IF(isDebug(),"%s: generated ROI: [%d, %d, %d, %d]", __FUNCTION__,
511 roi.left, roi.top, roi.right, roi.bottom);
512}
513
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800514/* Checks for conditions where all the layers marked for MDP comp cannot be
515 * bypassed. On such conditions we try to bypass atleast YUV layers */
516bool MDPComp::isFullFrameDoable(hwc_context_t *ctx,
517 hwc_display_contents_1_t* list){
518
Saurabh Shahaa236822013-04-24 18:07:26 -0700519 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800520
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -0700521 if(sIdleFallBack && !ctx->listStats[mDpy].secureUI) {
Saurabh Shah2d998a92013-05-14 17:55:58 -0700522 ALOGD_IF(isDebug(), "%s: Idle fallback dpy %d",__FUNCTION__, mDpy);
523 return false;
524 }
525
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800526 if(isSkipPresent(ctx, mDpy)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700527 ALOGD_IF(isDebug(),"%s: SKIP present: %d",
528 __FUNCTION__,
529 isSkipPresent(ctx, mDpy));
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800530 return false;
531 }
532
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800533 for(int i = 0; i < numAppLayers; ++i) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800534 hwc_layer_1_t* layer = &list->hwLayers[i];
535 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800536
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700537 if(isYuvBuffer(hnd) && has90Transform(layer)) {
538 if(!canUseRotator(ctx, mDpy)) {
539 ALOGD_IF(isDebug(), "%s: Can't use rotator for dpy %d",
540 __FUNCTION__, mDpy);
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700541 return false;
542 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800543 }
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530544
545 //For 8x26 with panel width>1k, if RGB layer needs HFLIP fail mdp comp
546 // may not need it if Gfx pre-rotation can handle all flips & rotations
547 if(qdutils::MDPVersion::getInstance().is8x26() &&
548 (ctx->dpyAttr[mDpy].xres > 1024) &&
549 (layer->transform & HWC_TRANSFORM_FLIP_H) &&
550 (!isYuvBuffer(hnd)))
551 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800552 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700553
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700554 if(ctx->mAD->isDoable()) {
555 return false;
556 }
557
Saurabh Shahaa236822013-04-24 18:07:26 -0700558 //If all above hard conditions are met we can do full or partial MDP comp.
559 bool ret = false;
560 if(fullMDPComp(ctx, list)) {
561 ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700562 } else if(partialMDPComp(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700563 ret = true;
564 }
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530565
566 if(!hwLimitationsCheck(ctx, list)) {
567 ALOGD_IF(isDebug(), "%s: HW limitations",__FUNCTION__);
568 return false;
569 }
570
Saurabh Shahaa236822013-04-24 18:07:26 -0700571 return ret;
572}
573
574bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700575 //Will benefit presentation / secondary-only layer.
576 if((mDpy > HWC_DISPLAY_PRIMARY) &&
577 (list->numHwLayers - 1) > MAX_SEC_LAYERS) {
578 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
579 return false;
580 }
581
582 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
583 for(int i = 0; i < numAppLayers; i++) {
584 hwc_layer_1_t* layer = &list->hwLayers[i];
585 if(not isSupportedForMDPComp(ctx, layer)) {
586 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",__FUNCTION__);
587 return false;
588 }
Yang Xu9c1eb2b2013-11-26 01:28:13 +0800589
590 //For 8x26, if there is only one layer which needs scale for secondary
591 //while no scale for primary display, DMA pipe is occupied by primary.
592 //If need to fall back to GLES composition, virtual display lacks DMA
593 //pipe and error is reported.
594 if(qdutils::MDPVersion::getInstance().is8x26() &&
595 mDpy >= HWC_DISPLAY_EXTERNAL &&
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530596 qhwc::needsScaling(layer))
Yang Xu9c1eb2b2013-11-26 01:28:13 +0800597 return false;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700598 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700599 mCurrentFrame.fbCount = 0;
600 mCurrentFrame.fbZ = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700601 memcpy(&mCurrentFrame.isFBComposed, &mCurrentFrame.drop,
602 sizeof(mCurrentFrame.isFBComposed));
603 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount -
604 mCurrentFrame.dropCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700605
radhakrishnac9a67412013-09-25 17:40:42 +0530606 if(sEnable4k2kYUVSplit){
607 modifymdpCountfor4k2k(ctx, list);
608 }
609
Saurabh Shah173f4242013-11-20 09:50:12 -0800610 if(!resourceCheck(ctx, list)) {
611 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700612 return false;
613 }
614
Saurabh Shahaa236822013-04-24 18:07:26 -0700615 return true;
616}
617
618bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
619{
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700620 if(!sEnableMixedMode) {
621 //Mixed mode is disabled. No need to even try caching.
622 return false;
623 }
624
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700625 bool ret = false;
626 if(isLoadBasedCompDoable(ctx, list)) {
Saurabh Shahb772ae32013-11-18 15:40:02 -0800627 ret = loadBasedCompPreferGPU(ctx, list) ||
628 loadBasedCompPreferMDP(ctx, list);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700629 }
630
631 if(!ret) {
632 ret = cacheBasedComp(ctx, list);
633 }
634
635 return ret;
636}
637
638bool MDPComp::cacheBasedComp(hwc_context_t *ctx,
639 hwc_display_contents_1_t* list) {
640 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700641 mCurrentFrame.reset(numAppLayers);
642 updateLayerCache(ctx, list);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700643
644 //If an MDP marked layer is unsupported cannot do partial MDP Comp
645 for(int i = 0; i < numAppLayers; i++) {
646 if(!mCurrentFrame.isFBComposed[i]) {
647 hwc_layer_1_t* layer = &list->hwLayers[i];
648 if(not isSupportedForMDPComp(ctx, layer)) {
649 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",
650 __FUNCTION__);
651 return false;
652 }
653 }
654 }
655
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700656 updateYUV(ctx, list, false /*secure only*/);
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530657 bool ret = markLayersForCaching(ctx, list); //sets up fbZ also
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700658 if(!ret) {
659 ALOGD_IF(isDebug(),"%s: batching failed, dpy %d",__FUNCTION__, mDpy);
660 return false;
661 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700662
663 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700664
radhakrishnac9a67412013-09-25 17:40:42 +0530665 if(sEnable4k2kYUVSplit){
666 modifymdpCountfor4k2k(ctx, list);
667 }
668
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700669 //Will benefit cases where a video has non-updating background.
670 if((mDpy > HWC_DISPLAY_PRIMARY) and
671 (mdpCount > MAX_SEC_LAYERS)) {
672 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
673 return false;
674 }
675
Saurabh Shah173f4242013-11-20 09:50:12 -0800676 if(!resourceCheck(ctx, list)) {
677 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700678 return false;
679 }
680
Saurabh Shahaa236822013-04-24 18:07:26 -0700681 return true;
682}
683
Saurabh Shahb772ae32013-11-18 15:40:02 -0800684bool MDPComp::loadBasedCompPreferGPU(hwc_context_t *ctx,
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700685 hwc_display_contents_1_t* list) {
686 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
687 mCurrentFrame.reset(numAppLayers);
688
Saurabh Shahb772ae32013-11-18 15:40:02 -0800689 int stagesForMDP = min(sMaxPipesPerMixer, ctx->mOverlay->availablePipes(
690 mDpy, Overlay::MIXER_DEFAULT));
691 //If MDP has X possible stages, it can take X layers.
692 const int batchSize = numAppLayers - (stagesForMDP - 1); //1 for FB
693
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700694 if(batchSize <= 0) {
695 ALOGD_IF(isDebug(), "%s: Not attempting", __FUNCTION__);
696 return false;
697 }
698
699 int minBatchStart = -1;
700 size_t minBatchPixelCount = SIZE_MAX;
701
702 for(int i = 0; i <= numAppLayers - batchSize; i++) {
703 uint32_t batchPixelCount = 0;
704 for(int j = i; j < i + batchSize; j++) {
705 hwc_layer_1_t* layer = &list->hwLayers[j];
Arun Kumar K.R91090c72013-10-28 19:40:18 -0700706 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700707 batchPixelCount += (crop.right - crop.left) *
708 (crop.bottom - crop.top);
709 }
710
711 if(batchPixelCount < minBatchPixelCount) {
712 minBatchPixelCount = batchPixelCount;
713 minBatchStart = i;
714 }
715 }
716
717 if(minBatchStart < 0) {
718 ALOGD_IF(isDebug(), "%s: No batch found batchSize %d numAppLayers %d",
719 __FUNCTION__, batchSize, numAppLayers);
720 return false;
721 }
722
723 for(int i = 0; i < numAppLayers; i++) {
724 if(i < minBatchStart || i >= minBatchStart + batchSize) {
725 hwc_layer_1_t* layer = &list->hwLayers[i];
726 if(not isSupportedForMDPComp(ctx, layer)) {
727 ALOGD_IF(isDebug(), "%s: MDP unsupported layer found at %d",
728 __FUNCTION__, i);
729 return false;
730 }
731 mCurrentFrame.isFBComposed[i] = false;
732 }
733 }
734
735 mCurrentFrame.fbZ = minBatchStart;
736 mCurrentFrame.fbCount = batchSize;
737 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - batchSize;
738
radhakrishnac9a67412013-09-25 17:40:42 +0530739 if(sEnable4k2kYUVSplit){
740 modifymdpCountfor4k2k(ctx, list);
741 }
742
Saurabh Shah173f4242013-11-20 09:50:12 -0800743 if(!resourceCheck(ctx, list)) {
744 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700745 return false;
746 }
747
748 ALOGD_IF(isDebug(), "%s: fbZ %d batchSize %d",
749 __FUNCTION__, mCurrentFrame.fbZ, batchSize);
750 return true;
751}
752
Saurabh Shahb772ae32013-11-18 15:40:02 -0800753bool MDPComp::loadBasedCompPreferMDP(hwc_context_t *ctx,
754 hwc_display_contents_1_t* list) {
755 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
756 //TODO get the ib from sysfs node.
757 //Full screen is from ib perspective, not actual full screen
758 const int bpp = 4;
759 double panelRefRate =
760 1000000000.0 / ctx->dpyAttr[mDpy].vsync_period;
761
762 double bwLeft = sMaxBw - sBwClaimed;
763
764 const int fullScreenLayers = bwLeft * 1000000000 / (ctx->dpyAttr[mDpy].xres
765 * ctx->dpyAttr[mDpy].yres * bpp * panelRefRate);
766
767 const int fbBatchSize = numAppLayers - (fullScreenLayers - 1);
768 //If batch size is not at least 2, we aren't really preferring MDP, since
769 //only 1 layer going to GPU could actually translate into an entire FB
770 //needed to be fetched by MDP, thus needing more b/w rather than less.
771 if(fbBatchSize < 2 || fbBatchSize > numAppLayers) {
772 ALOGD_IF(isDebug(), "%s: Not attempting", __FUNCTION__);
773 return false;
774 }
775
776 //Top-most layers constitute FB batch
777 const int fbBatchStart = numAppLayers - fbBatchSize;
778
779 //Bottom-most layers constitute MDP batch
780 for(int i = 0; i < fbBatchStart; i++) {
781 hwc_layer_1_t* layer = &list->hwLayers[i];
782 if(not isSupportedForMDPComp(ctx, layer)) {
783 ALOGD_IF(isDebug(), "%s: MDP unsupported layer found at %d",
784 __FUNCTION__, i);
785 return false;
786 }
787 mCurrentFrame.isFBComposed[i] = false;
788 }
789
790 mCurrentFrame.fbZ = fbBatchStart;
791 mCurrentFrame.fbCount = fbBatchSize;
792 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - fbBatchSize;
793
radhakrishnac9a67412013-09-25 17:40:42 +0530794 if(sEnable4k2kYUVSplit){
795 modifymdpCountfor4k2k(ctx, list);
796 }
797
Saurabh Shahb772ae32013-11-18 15:40:02 -0800798 if(!resourceCheck(ctx, list)) {
799 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
800 return false;
801 }
802
803 ALOGD_IF(isDebug(), "%s: FB Z %d, num app layers %d, MDP Batch Size %d",
804 __FUNCTION__, mCurrentFrame.fbZ, numAppLayers,
805 numAppLayers - fbBatchSize);
806
807 return true;
808}
809
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700810bool MDPComp::isLoadBasedCompDoable(hwc_context_t *ctx,
811 hwc_display_contents_1_t* list) {
812 if(mDpy or isSecurePresent(ctx, mDpy) or
813 not (list->flags & HWC_GEOMETRY_CHANGED)) {
814 return false;
815 }
816 return true;
817}
818
Saurabh Shahaa236822013-04-24 18:07:26 -0700819bool MDPComp::isOnlyVideoDoable(hwc_context_t *ctx,
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700820 hwc_display_contents_1_t* list, bool secureOnly) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700821 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700822
Saurabh Shahaa236822013-04-24 18:07:26 -0700823 mCurrentFrame.reset(numAppLayers);
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700824 updateYUV(ctx, list, secureOnly);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700825 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700826
827 if(!isYuvPresent(ctx, mDpy)) {
828 return false;
829 }
830
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -0800831 /* Bail out if we are processing only secured video layers
832 * and we dont have any */
833 if(!isSecurePresent(ctx, mDpy) && secureOnly){
834 return false;
835 }
836
Saurabh Shah4fdde762013-04-30 18:47:33 -0700837 if(!mdpCount)
838 return false;
839
Saurabh Shah173f4242013-11-20 09:50:12 -0800840 if(!resourceCheck(ctx, list)) {
841 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700842 return false;
843 }
844
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800845 return true;
846}
847
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800848/* Checks for conditions where YUV layers cannot be bypassed */
849bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Saurabh Shahe2474082013-05-15 16:32:13 -0700850 bool extAnimBlockFeature = mDpy && ctx->listStats[mDpy].isDisplayAnimating;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800851
Saurabh Shahe2474082013-05-15 16:32:13 -0700852 if(isSkipLayer(layer) && !extAnimBlockFeature) {
853 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800854 return false;
855 }
856
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700857 if(layer->transform & HWC_TRANSFORM_ROT_90 && !canUseRotator(ctx,mDpy)) {
858 ALOGD_IF(isDebug(), "%s: no free DMA pipe",__FUNCTION__);
859 return false;
860 }
861
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800862 if(isSecuring(ctx, layer)) {
863 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
864 return false;
865 }
866
Saurabh Shah4fdde762013-04-30 18:47:33 -0700867 if(!isValidDimension(ctx, layer)) {
868 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
869 __FUNCTION__);
870 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800871 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700872
Naseer Ahmeddc61a972013-07-10 17:50:54 -0400873 if(layer->planeAlpha < 0xFF) {
874 ALOGD_IF(isDebug(), "%s: Cannot handle YUV layer with plane alpha\
875 in video only mode",
876 __FUNCTION__);
877 return false;
878 }
879
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800880 return true;
881}
882
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530883/* starts at fromIndex and check for each layer to find
884 * if it it has overlapping with any Updating layer above it in zorder
885 * till the end of the batch. returns true if it finds any intersection */
886bool MDPComp::canPushBatchToTop(const hwc_display_contents_1_t* list,
887 int fromIndex, int toIndex) {
888 for(int i = fromIndex; i < toIndex; i++) {
889 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
890 if(intersectingUpdatingLayers(list, i+1, toIndex, i)) {
891 return false;
892 }
893 }
894 }
895 return true;
896}
897
898/* Checks if given layer at targetLayerIndex has any
899 * intersection with all the updating layers in beween
900 * fromIndex and toIndex. Returns true if it finds intersectiion */
901bool MDPComp::intersectingUpdatingLayers(const hwc_display_contents_1_t* list,
902 int fromIndex, int toIndex, int targetLayerIndex) {
903 for(int i = fromIndex; i <= toIndex; i++) {
904 if(!mCurrentFrame.isFBComposed[i]) {
905 if(areLayersIntersecting(&list->hwLayers[i],
906 &list->hwLayers[targetLayerIndex])) {
907 return true;
908 }
909 }
910 }
911 return false;
912}
913
914int MDPComp::getBatch(hwc_display_contents_1_t* list,
915 int& maxBatchStart, int& maxBatchEnd,
916 int& maxBatchCount) {
917 int i = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530918 int fbZOrder =-1;
919 while (i < mCurrentFrame.layerCount) {
920 int batchCount = 0;
921 int batchStart = i;
922 int batchEnd = i;
923 int fbZ = batchStart;
924 int firstZReverseIndex = -1;
Prabhanjan Kandula0ed2cc92013-12-06 12:39:04 +0530925 int updatingLayersAbove = 0;//Updating layer count in middle of batch
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530926 while(i < mCurrentFrame.layerCount) {
927 if(!mCurrentFrame.isFBComposed[i]) {
928 if(!batchCount) {
929 i++;
930 break;
931 }
932 updatingLayersAbove++;
933 i++;
934 continue;
935 } else {
936 if(mCurrentFrame.drop[i]) {
937 i++;
938 continue;
939 } else if(updatingLayersAbove <= 0) {
940 batchCount++;
941 batchEnd = i;
942 i++;
943 continue;
944 } else { //Layer is FBComposed, not a drop & updatingLayer > 0
945
946 // We have a valid updating layer already. If layer-i not
947 // have overlapping with all updating layers in between
948 // batch-start and i, then we can add layer i to batch.
949 if(!intersectingUpdatingLayers(list, batchStart, i-1, i)) {
950 batchCount++;
951 batchEnd = i;
952 i++;
953 continue;
954 } else if(canPushBatchToTop(list, batchStart, i)) {
955 //If All the non-updating layers with in this batch
956 //does not have intersection with the updating layers
957 //above in z-order, then we can safely move the batch to
958 //higher z-order. Increment fbZ as it is moving up.
959 if( firstZReverseIndex < 0) {
960 firstZReverseIndex = i;
961 }
962 batchCount++;
963 batchEnd = i;
964 fbZ += updatingLayersAbove;
965 i++;
966 updatingLayersAbove = 0;
967 continue;
968 } else {
969 //both failed.start the loop again from here.
970 if(firstZReverseIndex >= 0) {
971 i = firstZReverseIndex;
972 }
973 break;
974 }
975 }
976 }
977 }
978 if(batchCount > maxBatchCount) {
979 maxBatchCount = batchCount;
980 maxBatchStart = batchStart;
981 maxBatchEnd = batchEnd;
982 fbZOrder = fbZ;
983 }
984 }
985 return fbZOrder;
986}
987
988bool MDPComp::markLayersForCaching(hwc_context_t* ctx,
989 hwc_display_contents_1_t* list) {
990 /* Idea is to keep as many non-updating(cached) layers in FB and
991 * send rest of them through MDP. This is done in 2 steps.
992 * 1. Find the maximum contiguous batch of non-updating layers.
993 * 2. See if we can improve this batch size for caching by adding
994 * opaque layers around the batch, if they don't have
995 * any overlapping with the updating layers in between.
996 * NEVER mark an updating layer for caching.
997 * But cached ones can be marked for MDP */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800998
999 int maxBatchStart = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001000 int maxBatchEnd = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001001 int maxBatchCount = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301002 int fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001003
1004 /* All or Nothing is cached. No batching needed */
Saurabh Shahaa236822013-04-24 18:07:26 -07001005 if(!mCurrentFrame.fbCount) {
1006 mCurrentFrame.fbZ = -1;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001007 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -07001008 }
1009 if(!mCurrentFrame.mdpCount) {
1010 mCurrentFrame.fbZ = 0;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001011 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -07001012 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001013
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301014 fbZ = getBatch(list, maxBatchStart, maxBatchEnd, maxBatchCount);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001015
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301016 /* reset rest of the layers lying inside ROI for MDP comp */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001017 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001018 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001019 if((i < maxBatchStart || i > maxBatchEnd) &&
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301020 mCurrentFrame.isFBComposed[i]){
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001021 if(!mCurrentFrame.drop[i]){
1022 //If an unsupported layer is being attempted to
1023 //be pulled out we should fail
1024 if(not isSupportedForMDPComp(ctx, layer)) {
1025 return false;
1026 }
1027 mCurrentFrame.isFBComposed[i] = false;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001028 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001029 }
1030 }
1031
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301032 // update the frame data
1033 mCurrentFrame.fbZ = fbZ;
1034 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001035 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001036 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001037
1038 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301039 mCurrentFrame.fbCount);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001040
1041 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001042}
Saurabh Shah85234ec2013-04-12 17:09:00 -07001043
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001044void MDPComp::updateLayerCache(hwc_context_t* ctx,
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001045 hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001046 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001047 int fbCount = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001048
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001049 for(int i = 0; i < numAppLayers; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001050 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001051 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001052 if(!mCurrentFrame.drop[i])
1053 fbCount++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001054 mCurrentFrame.isFBComposed[i] = true;
1055 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -07001056 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001057 }
1058 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001059
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001060 mCurrentFrame.fbCount = fbCount;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001061 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount
1062 - mCurrentFrame.dropCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001063
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001064 ALOGD_IF(isDebug(),"%s: MDP count: %d FB count %d drop count: %d"
1065 ,__FUNCTION__, mCurrentFrame.mdpCount, mCurrentFrame.fbCount,
1066 mCurrentFrame.dropCount);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001067}
1068
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001069void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list,
1070 bool secureOnly) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001071 int nYuvCount = ctx->listStats[mDpy].yuvCount;
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001072 if(!nYuvCount && mDpy) {
1073 //Reset "No animation on external display" related parameters.
1074 ctx->mPrevCropVideo.left = ctx->mPrevCropVideo.top =
1075 ctx->mPrevCropVideo.right = ctx->mPrevCropVideo.bottom = 0;
1076 ctx->mPrevDestVideo.left = ctx->mPrevDestVideo.top =
1077 ctx->mPrevDestVideo.right = ctx->mPrevDestVideo.bottom = 0;
1078 ctx->mPrevTransformVideo = 0;
1079 return;
1080 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001081 for(int index = 0;index < nYuvCount; index++){
1082 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
1083 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
1084
1085 if(!isYUVDoable(ctx, layer)) {
1086 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
1087 mCurrentFrame.isFBComposed[nYuvIndex] = true;
1088 mCurrentFrame.fbCount++;
1089 }
1090 } else {
1091 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001092 private_handle_t *hnd = (private_handle_t *)layer->handle;
1093 if(!secureOnly || isSecureBuffer(hnd)) {
1094 mCurrentFrame.isFBComposed[nYuvIndex] = false;
1095 mCurrentFrame.fbCount--;
1096 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001097 }
1098 }
1099 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001100
1101 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001102 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
1103 ALOGD_IF(isDebug(),"%s: fb count: %d",__FUNCTION__,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001104 mCurrentFrame.fbCount);
1105}
1106
Saurabh Shahaa236822013-04-24 18:07:26 -07001107bool MDPComp::programMDP(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001108 if(!allocLayerPipes(ctx, list)) {
1109 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -07001110 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001111 }
1112
1113 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001114 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001115 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001116 int mdpIndex = mCurrentFrame.layerToMDP[index];
1117 hwc_layer_1_t* layer = &list->hwLayers[index];
1118
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301119 //Leave fbZ for framebuffer. CACHE/GLES layers go here.
1120 if(mdpNextZOrder == mCurrentFrame.fbZ) {
1121 mdpNextZOrder++;
1122 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001123 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1124 cur_pipe->zOrder = mdpNextZOrder++;
1125
radhakrishnac9a67412013-09-25 17:40:42 +05301126 private_handle_t *hnd = (private_handle_t *)layer->handle;
1127 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1128 if(configure4k2kYuv(ctx, layer,
1129 mCurrentFrame.mdpToLayer[mdpIndex])
1130 != 0 ){
1131 ALOGD_IF(isDebug(), "%s: Failed to configure split pipes \
1132 for layer %d",__FUNCTION__, index);
1133 return false;
1134 }
1135 else{
1136 mdpNextZOrder++;
1137 }
1138 continue;
1139 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001140 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
1141 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
radhakrishnac9a67412013-09-25 17:40:42 +05301142 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -07001143 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001144 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001145 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001146 }
1147
Saurabh Shahaa236822013-04-24 18:07:26 -07001148 return true;
1149}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001150
Saurabh Shah173f4242013-11-20 09:50:12 -08001151bool MDPComp::resourceCheck(hwc_context_t *ctx,
1152 hwc_display_contents_1_t *list) {
1153 const bool fbUsed = mCurrentFrame.fbCount;
1154 if(mCurrentFrame.mdpCount > sMaxPipesPerMixer - fbUsed) {
1155 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
1156 return false;
1157 }
1158
1159 if(!arePipesAvailable(ctx, list)) {
1160 return false;
1161 }
1162
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001163 double size = calcMDPBytesRead(ctx, list);
Saurabh Shah173f4242013-11-20 09:50:12 -08001164 if(!bandwidthCheck(ctx, size)) {
1165 ALOGD_IF(isDebug(), "%s: Exceeds bandwidth",__FUNCTION__);
1166 return false;
1167 }
1168
1169 return true;
1170}
1171
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001172double MDPComp::calcMDPBytesRead(hwc_context_t *ctx,
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001173 hwc_display_contents_1_t* list) {
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001174 double size = 0;
1175 const double GIG = 1000000000.0;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001176
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001177 //Skip for targets where no device tree value for bw is supplied
1178 if(sMaxBw <= 0.0) {
1179 return 0.0;
1180 }
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001181
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001182 for (uint32_t i = 0; i < list->numHwLayers - 1; i++) {
1183 if(!mCurrentFrame.isFBComposed[i]) {
1184 hwc_layer_1_t* layer = &list->hwLayers[i];
1185 private_handle_t *hnd = (private_handle_t *)layer->handle;
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001186 if (hnd) {
Saurabh Shah62e1d732013-09-17 10:44:05 -07001187 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah90789162013-09-16 10:29:20 -07001188 hwc_rect_t dst = layer->displayFrame;
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001189 float bpp = ((float)hnd->size) / (hnd->width * hnd->height);
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001190 size += (bpp * (crop.right - crop.left) *
1191 (crop.bottom - crop.top) *
1192 ctx->dpyAttr[mDpy].yres / (dst.bottom - dst.top)) /
1193 GIG;
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001194 }
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001195 }
1196 }
1197
1198 if(mCurrentFrame.fbCount) {
1199 hwc_layer_1_t* layer = &list->hwLayers[list->numHwLayers - 1];
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001200 int tempw, temph;
1201 size += (getBufferSizeAndDimensions(
1202 layer->displayFrame.right - layer->displayFrame.left,
1203 layer->displayFrame.bottom - layer->displayFrame.top,
1204 HAL_PIXEL_FORMAT_RGBA_8888,
1205 tempw, temph)) / GIG;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001206 }
1207
1208 return size;
1209}
1210
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001211bool MDPComp::bandwidthCheck(hwc_context_t *ctx, const double& size) {
1212 //Skip for targets where no device tree value for bw is supplied
1213 if(sMaxBw <= 0.0) {
1214 return true;
1215 }
1216
1217 double panelRefRate =
1218 1000000000.0 / ctx->dpyAttr[mDpy].vsync_period;
1219 if((size * panelRefRate) > (sMaxBw - sBwClaimed)) {
1220 return false;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001221 }
1222 return true;
1223}
1224
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301225bool MDPComp::hwLimitationsCheck(hwc_context_t* ctx,
1226 hwc_display_contents_1_t* list) {
1227
1228 //A-family hw limitation:
1229 //If a layer need alpha scaling, MDP can not support.
1230 if(ctx->mMDP.version < qdutils::MDSS_V5) {
1231 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1232 if(!mCurrentFrame.isFBComposed[i] &&
1233 isAlphaScaled( &list->hwLayers[i])) {
1234 ALOGD_IF(isDebug(), "%s:frame needs alphaScaling",__FUNCTION__);
1235 return false;
1236 }
1237 }
1238 }
1239
1240 // On 8x26 & 8974 hw, we have a limitation of downscaling+blending.
1241 //If multiple layers requires downscaling and also they are overlapping
1242 //fall back to GPU since MDSS can not handle it.
1243 if(qdutils::MDPVersion::getInstance().is8x74v2() ||
1244 qdutils::MDPVersion::getInstance().is8x26()) {
1245 for(int i = 0; i < mCurrentFrame.layerCount-1; ++i) {
1246 hwc_layer_1_t* botLayer = &list->hwLayers[i];
1247 if(!mCurrentFrame.isFBComposed[i] &&
1248 isDownscaleRequired(botLayer)) {
1249 //if layer-i is marked for MDP and needs downscaling
1250 //check if any MDP layer on top of i & overlaps with layer-i
1251 for(int j = i+1; j < mCurrentFrame.layerCount; ++j) {
1252 hwc_layer_1_t* topLayer = &list->hwLayers[j];
1253 if(!mCurrentFrame.isFBComposed[j] &&
1254 isDownscaleRequired(topLayer)) {
1255 hwc_rect_t r = getIntersection(botLayer->displayFrame,
1256 topLayer->displayFrame);
1257 if(isValidRect(r))
1258 return false;
1259 }
1260 }
1261 }
1262 }
1263 }
1264 return true;
1265}
1266
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001267int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001268 int ret = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -07001269 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001270 MDPVersion& mdpVersion = qdutils::MDPVersion::getInstance();
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -07001271
Saurabh Shahb39f8152013-08-22 10:21:44 -07001272 //reset old data
1273 mCurrentFrame.reset(numLayers);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001274 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1275 mCurrentFrame.dropCount = 0;
Prabhanjan Kandula088bd892013-07-02 23:47:13 +05301276
Saurabh Shahb39f8152013-08-22 10:21:44 -07001277 //number of app layers exceeds MAX_NUM_APP_LAYERS fall back to GPU
1278 //do not cache the information for next draw cycle.
1279 if(numLayers > MAX_NUM_APP_LAYERS) {
Prabhanjan Kandula25469a52013-07-12 16:19:31 +05301280 mCachedFrame.updateCounts(mCurrentFrame);
Arpita Banerjeed8965982013-11-08 17:27:33 -08001281 ALOGI("%s: Number of App layers exceeded the limit ",
Tatenda Chipeperekwa835337a2013-09-27 16:58:43 -07001282 __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001283 ret = -1;
Tatenda Chipeperekwa835337a2013-09-27 16:58:43 -07001284 return ret;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001285 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001286
Saurabh Shahb39f8152013-08-22 10:21:44 -07001287 //Hard conditions, if not met, cannot do MDP comp
1288 if(!isFrameDoable(ctx)) {
1289 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
1290 __FUNCTION__);
1291 reset(numLayers, list);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001292 ret = -1;
1293 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001294 }
1295
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001296 generateROI(ctx, list);
1297
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001298 //Convert from kbps to gbps
1299 sMaxBw = mdpVersion.getHighBw() / 1000000.0;
1300 if (ctx->mExtDisplay->isConnected() || ctx->mMDP.panel != MIPI_CMD_PANEL) {
1301 sMaxBw = mdpVersion.getLowBw() / 1000000.0;
1302 }
1303
Saurabh Shahb39f8152013-08-22 10:21:44 -07001304 //Check whether layers marked for MDP Composition is actually doable.
1305 if(isFullFrameDoable(ctx, list)) {
1306 mCurrentFrame.map();
1307 //Configure framebuffer first if applicable
1308 if(mCurrentFrame.fbZ >= 0) {
radhakrishnac9a67412013-09-25 17:40:42 +05301309 //If 4k2k Yuv layer split is possible, and if
1310 //fbz is above 4k2k layer, increment fb zorder by 1
1311 //as we split 4k2k layer and increment zorder for right half
1312 //of the layer
1313 if(sEnable4k2kYUVSplit){
1314 int n4k2kYuvCount = ctx->listStats[mDpy].yuv4k2kCount;
1315 for(int index = 0; index < n4k2kYuvCount; index++){
1316 int n4k2kYuvIndex =
1317 ctx->listStats[mDpy].yuv4k2kIndices[index];
1318 if(mCurrentFrame.fbZ > n4k2kYuvIndex){
1319 mCurrentFrame.fbZ += 1;
1320 }
1321 }
1322 }
Saurabh Shahb39f8152013-08-22 10:21:44 -07001323 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list,
1324 mCurrentFrame.fbZ)) {
1325 ALOGE("%s configure framebuffer failed", __func__);
1326 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -07001327 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001328 ret = -1;
1329 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001330 }
1331 }
1332 //Acquire and Program MDP pipes
1333 if(!programMDP(ctx, list)) {
1334 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -07001335 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001336 ret = -1;
1337 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001338 } else { //Success
1339 //Any change in composition types needs an FB refresh
1340 mCurrentFrame.needsRedraw = false;
Jeykumar Sankaran988d3682013-11-15 11:57:16 -08001341 if(!mCachedFrame.isSameFrame(mCurrentFrame, list) ||
Saurabh Shahb39f8152013-08-22 10:21:44 -07001342 (list->flags & HWC_GEOMETRY_CHANGED) ||
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +05301343 isSkipPresent(ctx, mDpy)) {
Saurabh Shahb39f8152013-08-22 10:21:44 -07001344 mCurrentFrame.needsRedraw = true;
1345 }
1346 }
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001347 } else if(isOnlyVideoDoable(ctx, list, false /*secure only*/) ||
1348 isOnlyVideoDoable(ctx, list, true /*secure only*/)) {
Saurabh Shahb39f8152013-08-22 10:21:44 -07001349 //All layers marked for MDP comp cannot be bypassed.
1350 //Try to compose atleast YUV layers through MDP comp and let
1351 //all the RGB layers compose in FB
1352 //Destination over
radhakrishnac9a67412013-09-25 17:40:42 +05301353
1354 if(sEnable4k2kYUVSplit){
1355 modifymdpCountfor4k2k(ctx, list);
1356 }
1357
Saurabh Shahb39f8152013-08-22 10:21:44 -07001358 mCurrentFrame.fbZ = -1;
1359 if(mCurrentFrame.fbCount)
1360 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
1361
1362 mCurrentFrame.map();
1363
1364 //Configure framebuffer first if applicable
1365 if(mCurrentFrame.fbZ >= 0) {
1366 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, mCurrentFrame.fbZ)) {
1367 ALOGE("%s configure framebuffer failed", __func__);
1368 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -07001369 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001370 ret = -1;
1371 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001372 }
1373 }
Saurabh Shahc7e4f1d2013-12-05 17:57:44 -08001374 if(!programMDP(ctx, list)) {
Saurabh Shahb39f8152013-08-22 10:21:44 -07001375 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -07001376 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001377 ret = -1;
1378 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001379 }
1380 } else {
1381 reset(numLayers, list);
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -08001382 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1383 mCurrentFrame.dropCount = 0;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001384 ret = -1;
1385 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001386 }
Saurabh Shahb39f8152013-08-22 10:21:44 -07001387 //UpdateLayerFlags
1388 setMDPCompLayerFlags(ctx, list);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001389 mCachedFrame.cacheAll(list);
Saurabh Shahb39f8152013-08-22 10:21:44 -07001390 mCachedFrame.updateCounts(mCurrentFrame);
1391
Prabhanjan Kandula25469a52013-07-12 16:19:31 +05301392 // unlock it before calling dump function to avoid deadlock
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001393 if(isDebug()) {
Saurabh Shahaa236822013-04-24 18:07:26 -07001394 ALOGD("GEOMETRY change: %d", (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001395 android::String8 sDump("");
1396 dump(sDump);
1397 ALOGE("%s",sDump.string());
1398 }
1399
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001400exit:
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001401 double panelRefRate =
1402 1000000000.0 / ctx->dpyAttr[mDpy].vsync_period;
1403 sBwClaimed += calcMDPBytesRead(ctx, list) * panelRefRate;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001404 return ret;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001405}
1406
radhakrishnac9a67412013-09-25 17:40:42 +05301407bool MDPComp::allocSplitVGPipesfor4k2k(hwc_context_t *ctx,
1408 hwc_display_contents_1_t* list, int index) {
1409
1410 bool bRet = true;
1411 hwc_layer_1_t* layer = &list->hwLayers[index];
1412 private_handle_t *hnd = (private_handle_t *)layer->handle;
1413 int mdpIndex = mCurrentFrame.layerToMDP[index];
1414 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
1415 info.pipeInfo = new MdpYUVPipeInfo;
1416 info.rot = NULL;
1417 MdpYUVPipeInfo& pipe_info = *(MdpYUVPipeInfo*)info.pipeInfo;
1418 ePipeType type = MDPCOMP_OV_VG;
1419
1420 pipe_info.lIndex = ovutils::OV_INVALID;
1421 pipe_info.rIndex = ovutils::OV_INVALID;
1422
1423 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
1424 if(pipe_info.lIndex == ovutils::OV_INVALID){
1425 bRet = false;
1426 ALOGD_IF(isDebug(),"%s: allocating first VG pipe failed",
1427 __FUNCTION__);
1428 }
1429 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
1430 if(pipe_info.rIndex == ovutils::OV_INVALID){
1431 bRet = false;
1432 ALOGD_IF(isDebug(),"%s: allocating second VG pipe failed",
1433 __FUNCTION__);
1434 }
1435 return bRet;
1436}
Saurabh Shah88e4d272013-09-03 13:31:29 -07001437//=============MDPCompNonSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001438
radhakrishnac9a67412013-09-25 17:40:42 +05301439void MDPCompNonSplit::modifymdpCountfor4k2k(hwc_context_t *ctx,
1440 hwc_display_contents_1_t* list){
1441 //As we split 4kx2k yuv layer and program to 2 VG pipes
1442 //(if available) increase mdpcount accordingly
1443 mCurrentFrame.mdpCount += ctx->listStats[mDpy].yuv4k2kCount;
1444}
1445
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001446/*
1447 * Configures pipe(s) for MDP composition
1448 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001449int MDPCompNonSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001450 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001451 MdpPipeInfoNonSplit& mdp_info =
1452 *(static_cast<MdpPipeInfoNonSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001453 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
1454 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1455 eIsFg isFg = IS_FG_OFF;
1456 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001457
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001458 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
1459 __FUNCTION__, layer, zOrder, dest);
1460
Saurabh Shah88e4d272013-09-03 13:31:29 -07001461 return configureNonSplit(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001462 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001463}
1464
Saurabh Shah88e4d272013-09-03 13:31:29 -07001465bool MDPCompNonSplit::arePipesAvailable(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001466 hwc_display_contents_1_t* list) {
1467 overlay::Overlay& ov = *ctx->mOverlay;
1468 int numPipesNeeded = mCurrentFrame.mdpCount;
1469 int availPipes = ov.availablePipes(mDpy, Overlay::MIXER_DEFAULT);
1470
1471 //Reserve pipe for FB
1472 if(mCurrentFrame.fbCount)
1473 availPipes -= 1;
1474
1475 if(numPipesNeeded > availPipes) {
1476 ALOGD_IF(isDebug(), "%s: Insufficient pipes, dpy %d needed %d, avail %d",
1477 __FUNCTION__, mDpy, numPipesNeeded, availPipes);
1478 return false;
1479 }
1480
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001481 if(not areVGPipesAvailable(ctx, list)) {
1482 return false;
1483 }
1484
1485 return true;
1486}
1487
1488bool MDPCompNonSplit::areVGPipesAvailable(hwc_context_t *ctx,
1489 hwc_display_contents_1_t* list) {
1490 overlay::Overlay& ov = *ctx->mOverlay;
1491 int pipesNeeded = 0;
1492 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1493 if(!mCurrentFrame.isFBComposed[i]) {
1494 hwc_layer_1_t* layer = &list->hwLayers[i];
1495 hwc_rect_t dst = layer->displayFrame;
1496 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301497 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1498 pipesNeeded = pipesNeeded + 2;
1499 }
1500 else if(isYuvBuffer(hnd)) {
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001501 pipesNeeded++;
1502 }
1503 }
1504 }
1505
1506 int availableVGPipes = ov.availablePipes(mDpy, ovutils::OV_MDP_PIPE_VG);
1507 if(pipesNeeded > availableVGPipes) {
1508 ALOGD_IF(isDebug(), "%s: Insufficient VG pipes for video layers"
1509 "dpy %d needed %d, avail %d",
1510 __FUNCTION__, mDpy, pipesNeeded, availableVGPipes);
1511 return false;
1512 }
1513
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001514 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001515}
1516
Saurabh Shah88e4d272013-09-03 13:31:29 -07001517bool MDPCompNonSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001518 hwc_display_contents_1_t* list) {
1519 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001520
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001521 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001522
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001523 hwc_layer_1_t* layer = &list->hwLayers[index];
1524 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301525 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1526 if(allocSplitVGPipesfor4k2k(ctx, list, index)){
1527 continue;
1528 }
1529 }
1530
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001531 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001532 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001533 info.pipeInfo = new MdpPipeInfoNonSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08001534 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001535 MdpPipeInfoNonSplit& pipe_info = *(MdpPipeInfoNonSplit*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001536 ePipeType type = MDPCOMP_OV_ANY;
1537
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001538 if(isYuvBuffer(hnd)) {
1539 type = MDPCOMP_OV_VG;
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301540 } else if(!qhwc::needsScaling(layer)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001541 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
1542 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001543 type = MDPCOMP_OV_DMA;
1544 }
1545
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001546 pipe_info.index = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001547 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001548 ALOGD_IF(isDebug(), "%s: Unable to get pipe type = %d",
1549 __FUNCTION__, (int) type);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001550 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001551 }
1552 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001553 return true;
1554}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001555
radhakrishnac9a67412013-09-25 17:40:42 +05301556int MDPCompNonSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1557 PipeLayerPair& PipeLayerPair) {
1558 MdpYUVPipeInfo& mdp_info =
1559 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1560 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1561 eIsFg isFg = IS_FG_OFF;
1562 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1563 eDest lDest = mdp_info.lIndex;
1564 eDest rDest = mdp_info.rIndex;
1565
1566 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1567 lDest, rDest, &PipeLayerPair.rot);
1568}
1569
Saurabh Shah88e4d272013-09-03 13:31:29 -07001570bool MDPCompNonSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001571
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001572 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001573 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1574 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -08001575 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001576
1577 if(!ctx || !list) {
1578 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001579 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001580 }
1581
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301582 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1583 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1584 return true;
1585 }
1586
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001587 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001588 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001589 idleInvalidator->markForSleep();
1590
1591 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001592 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001593
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001594 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1595 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001596 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001597 if(mCurrentFrame.isFBComposed[i]) continue;
1598
Naseer Ahmed5b6708a2012-08-02 13:46:08 -07001599 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001600 private_handle_t *hnd = (private_handle_t *)layer->handle;
1601 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001602 if (!(layer->flags & HWC_COLOR_FILL)) {
1603 ALOGE("%s handle null", __FUNCTION__);
1604 return false;
1605 }
1606 // No PLAY for Color layer
1607 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1608 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001609 }
1610
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001611 int mdpIndex = mCurrentFrame.layerToMDP[i];
1612
radhakrishnac9a67412013-09-25 17:40:42 +05301613 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1614 {
1615 MdpYUVPipeInfo& pipe_info =
1616 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1617 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1618 ovutils::eDest indexL = pipe_info.lIndex;
1619 ovutils::eDest indexR = pipe_info.rIndex;
1620 int fd = hnd->fd;
1621 uint32_t offset = hnd->offset;
1622 if(rot) {
1623 rot->queueBuffer(fd, offset);
1624 fd = rot->getDstMemId();
1625 offset = rot->getDstOffset();
1626 }
1627 if(indexL != ovutils::OV_INVALID) {
1628 ovutils::eDest destL = (ovutils::eDest)indexL;
1629 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1630 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1631 if (!ov.queueBuffer(fd, offset, destL)) {
1632 ALOGE("%s: queueBuffer failed for display:%d",
1633 __FUNCTION__, mDpy);
1634 return false;
1635 }
1636 }
1637
1638 if(indexR != ovutils::OV_INVALID) {
1639 ovutils::eDest destR = (ovutils::eDest)indexR;
1640 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1641 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1642 if (!ov.queueBuffer(fd, offset, destR)) {
1643 ALOGE("%s: queueBuffer failed for display:%d",
1644 __FUNCTION__, mDpy);
1645 return false;
1646 }
1647 }
1648 }
1649 else{
1650 MdpPipeInfoNonSplit& pipe_info =
Saurabh Shah88e4d272013-09-03 13:31:29 -07001651 *(MdpPipeInfoNonSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
radhakrishnac9a67412013-09-25 17:40:42 +05301652 ovutils::eDest dest = pipe_info.index;
1653 if(dest == ovutils::OV_INVALID) {
1654 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001655 return false;
radhakrishnac9a67412013-09-25 17:40:42 +05301656 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001657
radhakrishnac9a67412013-09-25 17:40:42 +05301658 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1659 continue;
1660 }
1661
1662 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1663 using pipe: %d", __FUNCTION__, layer,
1664 hnd, dest );
1665
1666 int fd = hnd->fd;
1667 uint32_t offset = hnd->offset;
1668
1669 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1670 if(rot) {
1671 if(!rot->queueBuffer(fd, offset))
1672 return false;
1673 fd = rot->getDstMemId();
1674 offset = rot->getDstOffset();
1675 }
1676
1677 if (!ov.queueBuffer(fd, offset, dest)) {
1678 ALOGE("%s: queueBuffer failed for display:%d ",
1679 __FUNCTION__, mDpy);
1680 return false;
1681 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001682 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001683
1684 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001685 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001686 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001687}
1688
Saurabh Shah88e4d272013-09-03 13:31:29 -07001689//=============MDPCompSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001690
radhakrishnac9a67412013-09-25 17:40:42 +05301691void MDPCompSplit::modifymdpCountfor4k2k(hwc_context_t *ctx,
1692 hwc_display_contents_1_t* list){
1693 //if 4kx2k yuv layer is totally present in either in left half
1694 //or right half then try splitting the yuv layer to avoid decimation
1695 int n4k2kYuvCount = ctx->listStats[mDpy].yuv4k2kCount;
1696 const int lSplit = getLeftSplit(ctx, mDpy);
1697 for(int index = 0; index < n4k2kYuvCount; index++){
1698 int n4k2kYuvIndex = ctx->listStats[mDpy].yuv4k2kIndices[index];
1699 hwc_layer_1_t* layer = &list->hwLayers[n4k2kYuvIndex];
1700 hwc_rect_t dst = layer->displayFrame;
1701
1702 if((dst.left > lSplit)||(dst.right < lSplit)){
1703 mCurrentFrame.mdpCount += 1;
1704 }
1705 }
1706}
1707
Saurabh Shah88e4d272013-09-03 13:31:29 -07001708int MDPCompSplit::pipesNeeded(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001709 hwc_display_contents_1_t* list,
1710 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001711 int pipesNeeded = 0;
Saurabh Shah67a38c32013-06-10 16:23:15 -07001712 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001713
1714 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001715
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001716 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1717 if(!mCurrentFrame.isFBComposed[i]) {
1718 hwc_layer_1_t* layer = &list->hwLayers[i];
1719 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001720 if(mixer == Overlay::MIXER_LEFT && dst.left < lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001721 pipesNeeded++;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001722 } else if(mixer == Overlay::MIXER_RIGHT && dst.right > lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001723 pipesNeeded++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001724 }
1725 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001726 }
1727 return pipesNeeded;
1728}
1729
Saurabh Shah88e4d272013-09-03 13:31:29 -07001730bool MDPCompSplit::arePipesAvailable(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001731 hwc_display_contents_1_t* list) {
1732 overlay::Overlay& ov = *ctx->mOverlay;
Saurabh Shah082468e2013-09-12 10:05:32 -07001733 int totalPipesNeeded = 0;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001734
1735 for(int i = 0; i < Overlay::MIXER_MAX; i++) {
1736 int numPipesNeeded = pipesNeeded(ctx, list, i);
1737 int availPipes = ov.availablePipes(mDpy, i);
1738
1739 //Reserve pipe(s)for FB
1740 if(mCurrentFrame.fbCount)
Saurabh Shah082468e2013-09-12 10:05:32 -07001741 numPipesNeeded += 1;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001742
Saurabh Shah082468e2013-09-12 10:05:32 -07001743 totalPipesNeeded += numPipesNeeded;
1744
1745 //Per mixer check.
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001746 if(numPipesNeeded > availPipes) {
1747 ALOGD_IF(isDebug(), "%s: Insufficient pipes for "
1748 "dpy %d mixer %d needed %d, avail %d",
1749 __FUNCTION__, mDpy, i, numPipesNeeded, availPipes);
1750 return false;
1751 }
1752 }
Saurabh Shah082468e2013-09-12 10:05:32 -07001753
1754 //Per display check, since unused pipes can get counted twice.
1755 int totalPipesAvailable = ov.availablePipes(mDpy);
1756 if(totalPipesNeeded > totalPipesAvailable) {
1757 ALOGD_IF(isDebug(), "%s: Insufficient pipes for "
1758 "dpy %d needed %d, avail %d",
1759 __FUNCTION__, mDpy, totalPipesNeeded, totalPipesAvailable);
1760 return false;
1761 }
1762
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001763 if(not areVGPipesAvailable(ctx, list)) {
1764 return false;
1765 }
1766
1767 return true;
1768}
1769
1770bool MDPCompSplit::areVGPipesAvailable(hwc_context_t *ctx,
1771 hwc_display_contents_1_t* list) {
1772 overlay::Overlay& ov = *ctx->mOverlay;
1773 int pipesNeeded = 0;
1774 const int lSplit = getLeftSplit(ctx, mDpy);
1775 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1776 if(!mCurrentFrame.isFBComposed[i]) {
1777 hwc_layer_1_t* layer = &list->hwLayers[i];
1778 hwc_rect_t dst = layer->displayFrame;
1779 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301780 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1781 if((dst.left > lSplit)||(dst.right < lSplit)){
1782 pipesNeeded = pipesNeeded + 2;
1783 continue;
1784 }
1785 }
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001786 if(isYuvBuffer(hnd)) {
1787 if(dst.left < lSplit) {
1788 pipesNeeded++;
1789 }
1790 if(dst.right > lSplit) {
1791 pipesNeeded++;
1792 }
1793 }
1794 }
1795 }
1796
1797 int availableVGPipes = ov.availablePipes(mDpy, ovutils::OV_MDP_PIPE_VG);
1798 if(pipesNeeded > availableVGPipes) {
1799 ALOGD_IF(isDebug(), "%s: Insufficient VG pipes for video layers"
1800 "dpy %d needed %d, avail %d",
1801 __FUNCTION__, mDpy, pipesNeeded, availableVGPipes);
1802 return false;
1803 }
1804
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001805 return true;
1806}
1807
Saurabh Shah88e4d272013-09-03 13:31:29 -07001808bool MDPCompSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
1809 MdpPipeInfoSplit& pipe_info,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001810 ePipeType type) {
1811 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001812 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001813
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001814 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001815 pipe_info.lIndex = ovutils::OV_INVALID;
1816 pipe_info.rIndex = ovutils::OV_INVALID;
1817
1818 if (dst.left < lSplit) {
1819 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_LEFT);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001820 if(pipe_info.lIndex == ovutils::OV_INVALID)
1821 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001822 }
1823
1824 if(dst.right > lSplit) {
1825 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_RIGHT);
1826 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001827 return false;
1828 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001829
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001830 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001831}
1832
Saurabh Shah88e4d272013-09-03 13:31:29 -07001833bool MDPCompSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001834 hwc_display_contents_1_t* list) {
1835 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001836
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001837 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001838
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001839 hwc_layer_1_t* layer = &list->hwLayers[index];
1840 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301841 hwc_rect_t dst = layer->displayFrame;
1842 const int lSplit = getLeftSplit(ctx, mDpy);
1843 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1844 if((dst.left > lSplit)||(dst.right < lSplit)){
1845 if(allocSplitVGPipesfor4k2k(ctx, list, index)){
1846 continue;
1847 }
1848 }
1849 }
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001850 int mdpIndex = mCurrentFrame.layerToMDP[index];
1851 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001852 info.pipeInfo = new MdpPipeInfoSplit;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001853 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001854 MdpPipeInfoSplit& pipe_info = *(MdpPipeInfoSplit*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001855 ePipeType type = MDPCOMP_OV_ANY;
1856
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001857 if(isYuvBuffer(hnd)) {
1858 type = MDPCOMP_OV_VG;
Sushil Chauhan15a2ea62013-09-04 18:28:36 -07001859 } else if(!qhwc::needsScalingWithSplit(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001860 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001861 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001862 type = MDPCOMP_OV_DMA;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001863 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001864
1865 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001866 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type = %d",
1867 __FUNCTION__, (int) type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001868 return false;
1869 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001870 }
1871 return true;
1872}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001873
radhakrishnac9a67412013-09-25 17:40:42 +05301874int MDPCompSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1875 PipeLayerPair& PipeLayerPair) {
1876 const int lSplit = getLeftSplit(ctx, mDpy);
1877 hwc_rect_t dst = layer->displayFrame;
1878 if((dst.left > lSplit)||(dst.right < lSplit)){
1879 MdpYUVPipeInfo& mdp_info =
1880 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1881 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1882 eIsFg isFg = IS_FG_OFF;
1883 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1884 eDest lDest = mdp_info.lIndex;
1885 eDest rDest = mdp_info.rIndex;
1886
1887 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1888 lDest, rDest, &PipeLayerPair.rot);
1889 }
1890 else{
1891 return configure(ctx, layer, PipeLayerPair);
1892 }
1893}
1894
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001895/*
1896 * Configures pipe(s) for MDP composition
1897 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001898int MDPCompSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001899 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001900 MdpPipeInfoSplit& mdp_info =
1901 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001902 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1903 eIsFg isFg = IS_FG_OFF;
1904 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1905 eDest lDest = mdp_info.lIndex;
1906 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001907
1908 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1909 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1910
Saurabh Shah88e4d272013-09-03 13:31:29 -07001911 return configureSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001912 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001913}
1914
Saurabh Shah88e4d272013-09-03 13:31:29 -07001915bool MDPCompSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001916
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001917 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001918 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1919 return true;
1920 }
1921
1922 if(!ctx || !list) {
1923 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001924 return false;
1925 }
1926
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301927 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1928 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1929 return true;
1930 }
1931
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001932 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001933 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001934 idleInvalidator->markForSleep();
1935
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001936 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001937 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001938
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001939 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1940 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001941 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001942 if(mCurrentFrame.isFBComposed[i]) continue;
1943
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001944 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001945 private_handle_t *hnd = (private_handle_t *)layer->handle;
1946 if(!hnd) {
1947 ALOGE("%s handle null", __FUNCTION__);
1948 return false;
1949 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001950
1951 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1952 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001953 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001954
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001955 int mdpIndex = mCurrentFrame.layerToMDP[i];
1956
radhakrishnac9a67412013-09-25 17:40:42 +05301957 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1958 {
1959 MdpYUVPipeInfo& pipe_info =
1960 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1961 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1962 ovutils::eDest indexL = pipe_info.lIndex;
1963 ovutils::eDest indexR = pipe_info.rIndex;
1964 int fd = hnd->fd;
1965 uint32_t offset = hnd->offset;
1966 if(rot) {
1967 rot->queueBuffer(fd, offset);
1968 fd = rot->getDstMemId();
1969 offset = rot->getDstOffset();
1970 }
1971 if(indexL != ovutils::OV_INVALID) {
1972 ovutils::eDest destL = (ovutils::eDest)indexL;
1973 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1974 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1975 if (!ov.queueBuffer(fd, offset, destL)) {
1976 ALOGE("%s: queueBuffer failed for display:%d",
1977 __FUNCTION__, mDpy);
1978 return false;
1979 }
1980 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001981
radhakrishnac9a67412013-09-25 17:40:42 +05301982 if(indexR != ovutils::OV_INVALID) {
1983 ovutils::eDest destR = (ovutils::eDest)indexR;
1984 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1985 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1986 if (!ov.queueBuffer(fd, offset, destR)) {
1987 ALOGE("%s: queueBuffer failed for display:%d",
1988 __FUNCTION__, mDpy);
1989 return false;
1990 }
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001991 }
1992 }
radhakrishnac9a67412013-09-25 17:40:42 +05301993 else{
1994 MdpPipeInfoSplit& pipe_info =
1995 *(MdpPipeInfoSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1996 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001997
radhakrishnac9a67412013-09-25 17:40:42 +05301998 ovutils::eDest indexL = pipe_info.lIndex;
1999 ovutils::eDest indexR = pipe_info.rIndex;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002000
radhakrishnac9a67412013-09-25 17:40:42 +05302001 int fd = hnd->fd;
2002 int offset = hnd->offset;
2003
2004 if(ctx->mAD->isModeOn()) {
2005 if(ctx->mAD->draw(ctx, fd, offset)) {
2006 fd = ctx->mAD->getDstFd(ctx);
2007 offset = ctx->mAD->getDstOffset(ctx);
2008 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002009 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002010
radhakrishnac9a67412013-09-25 17:40:42 +05302011 if(rot) {
2012 rot->queueBuffer(fd, offset);
2013 fd = rot->getDstMemId();
2014 offset = rot->getDstOffset();
2015 }
2016
2017 //************* play left mixer **********
2018 if(indexL != ovutils::OV_INVALID) {
2019 ovutils::eDest destL = (ovutils::eDest)indexL;
2020 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
2021 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
2022 if (!ov.queueBuffer(fd, offset, destL)) {
2023 ALOGE("%s: queueBuffer failed for left mixer",
2024 __FUNCTION__);
2025 return false;
2026 }
2027 }
2028
2029 //************* play right mixer **********
2030 if(indexR != ovutils::OV_INVALID) {
2031 ovutils::eDest destR = (ovutils::eDest)indexR;
2032 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
2033 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
2034 if (!ov.queueBuffer(fd, offset, destR)) {
2035 ALOGE("%s: queueBuffer failed for right mixer",
2036 __FUNCTION__);
2037 return false;
2038 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002039 }
2040 }
Saurabh Shahacf10202013-02-26 10:15:15 -08002041
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002042 layerProp[i].mFlags &= ~HWC_MDPCOMP;
2043 }
Saurabh Shahacf10202013-02-26 10:15:15 -08002044
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002045 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002046}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002047}; //namespace
2048