blob: 4f4584e2a93c2b4c633f599db0ebf50ced99659b [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) &&
452 needsScaling (ctx, layer, mDpy)) {
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
Saurabh Shah9f084ad2013-05-02 11:28:09 -0700533 if(ctx->listStats[mDpy].needsAlphaScale
534 && ctx->mMDP.version < qdutils::MDSS_V5) {
535 ALOGD_IF(isDebug(), "%s: frame needs alpha downscaling",__FUNCTION__);
536 return false;
537 }
538
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800539 for(int i = 0; i < numAppLayers; ++i) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800540 hwc_layer_1_t* layer = &list->hwLayers[i];
541 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800542
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700543 if(isYuvBuffer(hnd) && has90Transform(layer)) {
544 if(!canUseRotator(ctx, mDpy)) {
545 ALOGD_IF(isDebug(), "%s: Can't use rotator for dpy %d",
546 __FUNCTION__, mDpy);
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700547 return false;
548 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800549 }
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530550
551 //For 8x26 with panel width>1k, if RGB layer needs HFLIP fail mdp comp
552 // may not need it if Gfx pre-rotation can handle all flips & rotations
553 if(qdutils::MDPVersion::getInstance().is8x26() &&
554 (ctx->dpyAttr[mDpy].xres > 1024) &&
555 (layer->transform & HWC_TRANSFORM_FLIP_H) &&
556 (!isYuvBuffer(hnd)))
557 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800558 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700559
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700560 if(ctx->mAD->isDoable()) {
561 return false;
562 }
563
Saurabh Shahaa236822013-04-24 18:07:26 -0700564 //If all above hard conditions are met we can do full or partial MDP comp.
565 bool ret = false;
566 if(fullMDPComp(ctx, list)) {
567 ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700568 } else if(partialMDPComp(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700569 ret = true;
570 }
571 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 &&
596 qhwc::needsScaling(ctx, layer, mDpy))
597 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) {
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -0700850 if(isSkipLayer(layer)) {
Saurabh Shahe2474082013-05-15 16:32:13 -0700851 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800852 return false;
853 }
854
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700855 if(layer->transform & HWC_TRANSFORM_ROT_90 && !canUseRotator(ctx,mDpy)) {
856 ALOGD_IF(isDebug(), "%s: no free DMA pipe",__FUNCTION__);
857 return false;
858 }
859
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800860 if(isSecuring(ctx, layer)) {
861 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
862 return false;
863 }
864
Saurabh Shah4fdde762013-04-30 18:47:33 -0700865 if(!isValidDimension(ctx, layer)) {
866 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
867 __FUNCTION__);
868 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800869 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700870
Naseer Ahmeddc61a972013-07-10 17:50:54 -0400871 if(layer->planeAlpha < 0xFF) {
872 ALOGD_IF(isDebug(), "%s: Cannot handle YUV layer with plane alpha\
873 in video only mode",
874 __FUNCTION__);
875 return false;
876 }
877
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800878 return true;
879}
880
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530881/* starts at fromIndex and check for each layer to find
882 * if it it has overlapping with any Updating layer above it in zorder
883 * till the end of the batch. returns true if it finds any intersection */
884bool MDPComp::canPushBatchToTop(const hwc_display_contents_1_t* list,
885 int fromIndex, int toIndex) {
886 for(int i = fromIndex; i < toIndex; i++) {
887 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
888 if(intersectingUpdatingLayers(list, i+1, toIndex, i)) {
889 return false;
890 }
891 }
892 }
893 return true;
894}
895
896/* Checks if given layer at targetLayerIndex has any
897 * intersection with all the updating layers in beween
898 * fromIndex and toIndex. Returns true if it finds intersectiion */
899bool MDPComp::intersectingUpdatingLayers(const hwc_display_contents_1_t* list,
900 int fromIndex, int toIndex, int targetLayerIndex) {
901 for(int i = fromIndex; i <= toIndex; i++) {
902 if(!mCurrentFrame.isFBComposed[i]) {
903 if(areLayersIntersecting(&list->hwLayers[i],
904 &list->hwLayers[targetLayerIndex])) {
905 return true;
906 }
907 }
908 }
909 return false;
910}
911
912int MDPComp::getBatch(hwc_display_contents_1_t* list,
913 int& maxBatchStart, int& maxBatchEnd,
914 int& maxBatchCount) {
915 int i = 0;
916 int updatingLayersAbove = 0;//Updating layer count in middle of batch
917 int fbZOrder =-1;
918 while (i < mCurrentFrame.layerCount) {
919 int batchCount = 0;
920 int batchStart = i;
921 int batchEnd = i;
922 int fbZ = batchStart;
923 int firstZReverseIndex = -1;
924 while(i < mCurrentFrame.layerCount) {
925 if(!mCurrentFrame.isFBComposed[i]) {
926 if(!batchCount) {
927 i++;
928 break;
929 }
930 updatingLayersAbove++;
931 i++;
932 continue;
933 } else {
934 if(mCurrentFrame.drop[i]) {
935 i++;
936 continue;
937 } else if(updatingLayersAbove <= 0) {
938 batchCount++;
939 batchEnd = i;
940 i++;
941 continue;
942 } else { //Layer is FBComposed, not a drop & updatingLayer > 0
943
944 // We have a valid updating layer already. If layer-i not
945 // have overlapping with all updating layers in between
946 // batch-start and i, then we can add layer i to batch.
947 if(!intersectingUpdatingLayers(list, batchStart, i-1, i)) {
948 batchCount++;
949 batchEnd = i;
950 i++;
951 continue;
952 } else if(canPushBatchToTop(list, batchStart, i)) {
953 //If All the non-updating layers with in this batch
954 //does not have intersection with the updating layers
955 //above in z-order, then we can safely move the batch to
956 //higher z-order. Increment fbZ as it is moving up.
957 if( firstZReverseIndex < 0) {
958 firstZReverseIndex = i;
959 }
960 batchCount++;
961 batchEnd = i;
962 fbZ += updatingLayersAbove;
963 i++;
964 updatingLayersAbove = 0;
965 continue;
966 } else {
967 //both failed.start the loop again from here.
968 if(firstZReverseIndex >= 0) {
969 i = firstZReverseIndex;
970 }
971 break;
972 }
973 }
974 }
975 }
976 if(batchCount > maxBatchCount) {
977 maxBatchCount = batchCount;
978 maxBatchStart = batchStart;
979 maxBatchEnd = batchEnd;
980 fbZOrder = fbZ;
981 }
982 }
983 return fbZOrder;
984}
985
986bool MDPComp::markLayersForCaching(hwc_context_t* ctx,
987 hwc_display_contents_1_t* list) {
988 /* Idea is to keep as many non-updating(cached) layers in FB and
989 * send rest of them through MDP. This is done in 2 steps.
990 * 1. Find the maximum contiguous batch of non-updating layers.
991 * 2. See if we can improve this batch size for caching by adding
992 * opaque layers around the batch, if they don't have
993 * any overlapping with the updating layers in between.
994 * NEVER mark an updating layer for caching.
995 * But cached ones can be marked for MDP */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800996
997 int maxBatchStart = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700998 int maxBatchEnd = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800999 int maxBatchCount = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301000 int fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001001
1002 /* All or Nothing is cached. No batching needed */
Saurabh Shahaa236822013-04-24 18:07:26 -07001003 if(!mCurrentFrame.fbCount) {
1004 mCurrentFrame.fbZ = -1;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001005 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -07001006 }
1007 if(!mCurrentFrame.mdpCount) {
1008 mCurrentFrame.fbZ = 0;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001009 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -07001010 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001011
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301012 fbZ = getBatch(list, maxBatchStart, maxBatchEnd, maxBatchCount);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001013
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301014 /* reset rest of the layers lying inside ROI for MDP comp */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001015 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001016 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001017 if((i < maxBatchStart || i > maxBatchEnd) &&
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301018 mCurrentFrame.isFBComposed[i]){
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001019 if(!mCurrentFrame.drop[i]){
1020 //If an unsupported layer is being attempted to
1021 //be pulled out we should fail
1022 if(not isSupportedForMDPComp(ctx, layer)) {
1023 return false;
1024 }
1025 mCurrentFrame.isFBComposed[i] = false;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001026 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001027 }
1028 }
1029
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301030 // update the frame data
1031 mCurrentFrame.fbZ = fbZ;
1032 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001033 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001034 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001035
1036 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301037 mCurrentFrame.fbCount);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001038
1039 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001040}
Saurabh Shah85234ec2013-04-12 17:09:00 -07001041
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001042void MDPComp::updateLayerCache(hwc_context_t* ctx,
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001043 hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001044 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001045 int fbCount = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001046
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001047 for(int i = 0; i < numAppLayers; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001048 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001049 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001050 if(!mCurrentFrame.drop[i])
1051 fbCount++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001052 mCurrentFrame.isFBComposed[i] = true;
1053 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -07001054 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001055 }
1056 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001057
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001058 mCurrentFrame.fbCount = fbCount;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001059 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount
1060 - mCurrentFrame.dropCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001061
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001062 ALOGD_IF(isDebug(),"%s: MDP count: %d FB count %d drop count: %d"
1063 ,__FUNCTION__, mCurrentFrame.mdpCount, mCurrentFrame.fbCount,
1064 mCurrentFrame.dropCount);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001065}
1066
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001067void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list,
1068 bool secureOnly) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001069 int nYuvCount = ctx->listStats[mDpy].yuvCount;
1070 for(int index = 0;index < nYuvCount; index++){
1071 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
1072 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
1073
1074 if(!isYUVDoable(ctx, layer)) {
1075 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
1076 mCurrentFrame.isFBComposed[nYuvIndex] = true;
1077 mCurrentFrame.fbCount++;
1078 }
1079 } else {
1080 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001081 private_handle_t *hnd = (private_handle_t *)layer->handle;
1082 if(!secureOnly || isSecureBuffer(hnd)) {
1083 mCurrentFrame.isFBComposed[nYuvIndex] = false;
1084 mCurrentFrame.fbCount--;
1085 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001086 }
1087 }
1088 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001089
1090 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001091 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
1092 ALOGD_IF(isDebug(),"%s: fb count: %d",__FUNCTION__,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001093 mCurrentFrame.fbCount);
1094}
1095
Saurabh Shahaa236822013-04-24 18:07:26 -07001096bool MDPComp::programMDP(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001097 if(!allocLayerPipes(ctx, list)) {
1098 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -07001099 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001100 }
1101
1102 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001103 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001104 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001105 int mdpIndex = mCurrentFrame.layerToMDP[index];
1106 hwc_layer_1_t* layer = &list->hwLayers[index];
1107
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301108 //Leave fbZ for framebuffer. CACHE/GLES layers go here.
1109 if(mdpNextZOrder == mCurrentFrame.fbZ) {
1110 mdpNextZOrder++;
1111 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001112 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1113 cur_pipe->zOrder = mdpNextZOrder++;
1114
radhakrishnac9a67412013-09-25 17:40:42 +05301115 private_handle_t *hnd = (private_handle_t *)layer->handle;
1116 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1117 if(configure4k2kYuv(ctx, layer,
1118 mCurrentFrame.mdpToLayer[mdpIndex])
1119 != 0 ){
1120 ALOGD_IF(isDebug(), "%s: Failed to configure split pipes \
1121 for layer %d",__FUNCTION__, index);
1122 return false;
1123 }
1124 else{
1125 mdpNextZOrder++;
1126 }
1127 continue;
1128 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001129 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
1130 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
radhakrishnac9a67412013-09-25 17:40:42 +05301131 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -07001132 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001133 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001134 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001135 }
1136
Saurabh Shahaa236822013-04-24 18:07:26 -07001137 return true;
1138}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001139
Saurabh Shah173f4242013-11-20 09:50:12 -08001140bool MDPComp::resourceCheck(hwc_context_t *ctx,
1141 hwc_display_contents_1_t *list) {
1142 const bool fbUsed = mCurrentFrame.fbCount;
1143 if(mCurrentFrame.mdpCount > sMaxPipesPerMixer - fbUsed) {
1144 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
1145 return false;
1146 }
1147
1148 if(!arePipesAvailable(ctx, list)) {
1149 return false;
1150 }
1151
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001152 double size = calcMDPBytesRead(ctx, list);
Saurabh Shah173f4242013-11-20 09:50:12 -08001153 if(!bandwidthCheck(ctx, size)) {
1154 ALOGD_IF(isDebug(), "%s: Exceeds bandwidth",__FUNCTION__);
1155 return false;
1156 }
1157
1158 return true;
1159}
1160
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001161double MDPComp::calcMDPBytesRead(hwc_context_t *ctx,
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001162 hwc_display_contents_1_t* list) {
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001163 double size = 0;
1164 const double GIG = 1000000000.0;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001165
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001166 //Skip for targets where no device tree value for bw is supplied
1167 if(sMaxBw <= 0.0) {
1168 return 0.0;
1169 }
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001170
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001171 for (uint32_t i = 0; i < list->numHwLayers - 1; i++) {
1172 if(!mCurrentFrame.isFBComposed[i]) {
1173 hwc_layer_1_t* layer = &list->hwLayers[i];
1174 private_handle_t *hnd = (private_handle_t *)layer->handle;
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001175 if (hnd) {
Saurabh Shah62e1d732013-09-17 10:44:05 -07001176 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah90789162013-09-16 10:29:20 -07001177 hwc_rect_t dst = layer->displayFrame;
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001178 float bpp = ((float)hnd->size) / (hnd->width * hnd->height);
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001179 size += (bpp * (crop.right - crop.left) *
1180 (crop.bottom - crop.top) *
1181 ctx->dpyAttr[mDpy].yres / (dst.bottom - dst.top)) /
1182 GIG;
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001183 }
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001184 }
1185 }
1186
1187 if(mCurrentFrame.fbCount) {
1188 hwc_layer_1_t* layer = &list->hwLayers[list->numHwLayers - 1];
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001189 int tempw, temph;
1190 size += (getBufferSizeAndDimensions(
1191 layer->displayFrame.right - layer->displayFrame.left,
1192 layer->displayFrame.bottom - layer->displayFrame.top,
1193 HAL_PIXEL_FORMAT_RGBA_8888,
1194 tempw, temph)) / GIG;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001195 }
1196
1197 return size;
1198}
1199
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001200bool MDPComp::bandwidthCheck(hwc_context_t *ctx, const double& size) {
1201 //Skip for targets where no device tree value for bw is supplied
1202 if(sMaxBw <= 0.0) {
1203 return true;
1204 }
1205
1206 double panelRefRate =
1207 1000000000.0 / ctx->dpyAttr[mDpy].vsync_period;
1208 if((size * panelRefRate) > (sMaxBw - sBwClaimed)) {
1209 return false;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001210 }
1211 return true;
1212}
1213
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001214int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001215 int ret = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -07001216 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001217 MDPVersion& mdpVersion = qdutils::MDPVersion::getInstance();
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -07001218
Saurabh Shahb39f8152013-08-22 10:21:44 -07001219 //reset old data
1220 mCurrentFrame.reset(numLayers);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001221 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1222 mCurrentFrame.dropCount = 0;
Prabhanjan Kandula088bd892013-07-02 23:47:13 +05301223
Saurabh Shahb39f8152013-08-22 10:21:44 -07001224 //number of app layers exceeds MAX_NUM_APP_LAYERS fall back to GPU
1225 //do not cache the information for next draw cycle.
1226 if(numLayers > MAX_NUM_APP_LAYERS) {
Prabhanjan Kandula25469a52013-07-12 16:19:31 +05301227 mCachedFrame.updateCounts(mCurrentFrame);
Arpita Banerjeed8965982013-11-08 17:27:33 -08001228 ALOGI("%s: Number of App layers exceeded the limit ",
Tatenda Chipeperekwa835337a2013-09-27 16:58:43 -07001229 __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001230 ret = -1;
Tatenda Chipeperekwa835337a2013-09-27 16:58:43 -07001231 return ret;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001232 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001233
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -07001234 // Detect the start of animation and fall back to GPU only once to cache
1235 // all the layers in FB and display FB content untill animation completes.
1236 if(ctx->listStats[mDpy].isDisplayAnimating) {
1237 mCurrentFrame.needsRedraw = false;
1238 if(ctx->mAnimationState[mDpy] == ANIMATION_STOPPED) {
1239 mCurrentFrame.needsRedraw = true;
1240 ctx->mAnimationState[mDpy] = ANIMATION_STARTED;
1241 }
1242 setMDPCompLayerFlags(ctx, list);
1243 mCachedFrame.updateCounts(mCurrentFrame);
1244 ret = -1;
1245 return ret;
1246 } else {
1247 ctx->mAnimationState[mDpy] = ANIMATION_STOPPED;
1248 }
1249
Saurabh Shahb39f8152013-08-22 10:21:44 -07001250 //Hard conditions, if not met, cannot do MDP comp
1251 if(!isFrameDoable(ctx)) {
1252 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
1253 __FUNCTION__);
1254 reset(numLayers, list);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001255 ret = -1;
1256 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001257 }
1258
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001259 generateROI(ctx, list);
1260
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001261 //Convert from kbps to gbps
1262 sMaxBw = mdpVersion.getHighBw() / 1000000.0;
1263 if (ctx->mExtDisplay->isConnected() || ctx->mMDP.panel != MIPI_CMD_PANEL) {
1264 sMaxBw = mdpVersion.getLowBw() / 1000000.0;
1265 }
1266
Saurabh Shahb39f8152013-08-22 10:21:44 -07001267 //Check whether layers marked for MDP Composition is actually doable.
1268 if(isFullFrameDoable(ctx, list)) {
1269 mCurrentFrame.map();
1270 //Configure framebuffer first if applicable
1271 if(mCurrentFrame.fbZ >= 0) {
radhakrishnac9a67412013-09-25 17:40:42 +05301272 //If 4k2k Yuv layer split is possible, and if
1273 //fbz is above 4k2k layer, increment fb zorder by 1
1274 //as we split 4k2k layer and increment zorder for right half
1275 //of the layer
1276 if(sEnable4k2kYUVSplit){
1277 int n4k2kYuvCount = ctx->listStats[mDpy].yuv4k2kCount;
1278 for(int index = 0; index < n4k2kYuvCount; index++){
1279 int n4k2kYuvIndex =
1280 ctx->listStats[mDpy].yuv4k2kIndices[index];
1281 if(mCurrentFrame.fbZ > n4k2kYuvIndex){
1282 mCurrentFrame.fbZ += 1;
1283 }
1284 }
1285 }
Saurabh Shahb39f8152013-08-22 10:21:44 -07001286 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list,
1287 mCurrentFrame.fbZ)) {
1288 ALOGE("%s configure framebuffer failed", __func__);
1289 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -07001290 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001291 ret = -1;
1292 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001293 }
1294 }
1295 //Acquire and Program MDP pipes
1296 if(!programMDP(ctx, list)) {
1297 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -07001298 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001299 ret = -1;
1300 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001301 } else { //Success
1302 //Any change in composition types needs an FB refresh
1303 mCurrentFrame.needsRedraw = false;
Jeykumar Sankaran988d3682013-11-15 11:57:16 -08001304 if(!mCachedFrame.isSameFrame(mCurrentFrame, list) ||
Saurabh Shahb39f8152013-08-22 10:21:44 -07001305 (list->flags & HWC_GEOMETRY_CHANGED) ||
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +05301306 isSkipPresent(ctx, mDpy)) {
Saurabh Shahb39f8152013-08-22 10:21:44 -07001307 mCurrentFrame.needsRedraw = true;
1308 }
1309 }
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001310 } else if(isOnlyVideoDoable(ctx, list, false /*secure only*/) ||
1311 isOnlyVideoDoable(ctx, list, true /*secure only*/)) {
Saurabh Shahb39f8152013-08-22 10:21:44 -07001312 //All layers marked for MDP comp cannot be bypassed.
1313 //Try to compose atleast YUV layers through MDP comp and let
1314 //all the RGB layers compose in FB
1315 //Destination over
radhakrishnac9a67412013-09-25 17:40:42 +05301316
1317 if(sEnable4k2kYUVSplit){
1318 modifymdpCountfor4k2k(ctx, list);
1319 }
1320
Saurabh Shahb39f8152013-08-22 10:21:44 -07001321 mCurrentFrame.fbZ = -1;
1322 if(mCurrentFrame.fbCount)
1323 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
1324
1325 mCurrentFrame.map();
1326
1327 //Configure framebuffer first if applicable
1328 if(mCurrentFrame.fbZ >= 0) {
1329 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, mCurrentFrame.fbZ)) {
1330 ALOGE("%s configure framebuffer failed", __func__);
1331 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -07001332 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001333 ret = -1;
1334 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001335 }
1336 }
Saurabh Shahc7e4f1d2013-12-05 17:57:44 -08001337 if(!programMDP(ctx, list)) {
Saurabh Shahb39f8152013-08-22 10:21:44 -07001338 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -07001339 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001340 ret = -1;
1341 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001342 }
1343 } else {
1344 reset(numLayers, list);
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -08001345 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1346 mCurrentFrame.dropCount = 0;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001347 ret = -1;
1348 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001349 }
Saurabh Shahb39f8152013-08-22 10:21:44 -07001350 //UpdateLayerFlags
1351 setMDPCompLayerFlags(ctx, list);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001352 mCachedFrame.cacheAll(list);
Saurabh Shahb39f8152013-08-22 10:21:44 -07001353 mCachedFrame.updateCounts(mCurrentFrame);
1354
Prabhanjan Kandula25469a52013-07-12 16:19:31 +05301355 // unlock it before calling dump function to avoid deadlock
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001356 if(isDebug()) {
Saurabh Shahaa236822013-04-24 18:07:26 -07001357 ALOGD("GEOMETRY change: %d", (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001358 android::String8 sDump("");
1359 dump(sDump);
1360 ALOGE("%s",sDump.string());
1361 }
1362
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001363exit:
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001364 double panelRefRate =
1365 1000000000.0 / ctx->dpyAttr[mDpy].vsync_period;
1366 sBwClaimed += calcMDPBytesRead(ctx, list) * panelRefRate;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001367 return ret;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001368}
1369
radhakrishnac9a67412013-09-25 17:40:42 +05301370bool MDPComp::allocSplitVGPipesfor4k2k(hwc_context_t *ctx,
1371 hwc_display_contents_1_t* list, int index) {
1372
1373 bool bRet = true;
1374 hwc_layer_1_t* layer = &list->hwLayers[index];
1375 private_handle_t *hnd = (private_handle_t *)layer->handle;
1376 int mdpIndex = mCurrentFrame.layerToMDP[index];
1377 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
1378 info.pipeInfo = new MdpYUVPipeInfo;
1379 info.rot = NULL;
1380 MdpYUVPipeInfo& pipe_info = *(MdpYUVPipeInfo*)info.pipeInfo;
1381 ePipeType type = MDPCOMP_OV_VG;
1382
1383 pipe_info.lIndex = ovutils::OV_INVALID;
1384 pipe_info.rIndex = ovutils::OV_INVALID;
1385
1386 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
1387 if(pipe_info.lIndex == ovutils::OV_INVALID){
1388 bRet = false;
1389 ALOGD_IF(isDebug(),"%s: allocating first VG pipe failed",
1390 __FUNCTION__);
1391 }
1392 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
1393 if(pipe_info.rIndex == ovutils::OV_INVALID){
1394 bRet = false;
1395 ALOGD_IF(isDebug(),"%s: allocating second VG pipe failed",
1396 __FUNCTION__);
1397 }
1398 return bRet;
1399}
Saurabh Shah88e4d272013-09-03 13:31:29 -07001400//=============MDPCompNonSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001401
radhakrishnac9a67412013-09-25 17:40:42 +05301402void MDPCompNonSplit::modifymdpCountfor4k2k(hwc_context_t *ctx,
1403 hwc_display_contents_1_t* list){
1404 //As we split 4kx2k yuv layer and program to 2 VG pipes
1405 //(if available) increase mdpcount accordingly
1406 mCurrentFrame.mdpCount += ctx->listStats[mDpy].yuv4k2kCount;
1407}
1408
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001409/*
1410 * Configures pipe(s) for MDP composition
1411 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001412int MDPCompNonSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001413 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001414 MdpPipeInfoNonSplit& mdp_info =
1415 *(static_cast<MdpPipeInfoNonSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001416 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
1417 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1418 eIsFg isFg = IS_FG_OFF;
1419 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001420
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001421 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
1422 __FUNCTION__, layer, zOrder, dest);
1423
Saurabh Shah88e4d272013-09-03 13:31:29 -07001424 return configureNonSplit(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001425 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001426}
1427
Saurabh Shah88e4d272013-09-03 13:31:29 -07001428bool MDPCompNonSplit::arePipesAvailable(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001429 hwc_display_contents_1_t* list) {
1430 overlay::Overlay& ov = *ctx->mOverlay;
1431 int numPipesNeeded = mCurrentFrame.mdpCount;
1432 int availPipes = ov.availablePipes(mDpy, Overlay::MIXER_DEFAULT);
1433
1434 //Reserve pipe for FB
1435 if(mCurrentFrame.fbCount)
1436 availPipes -= 1;
1437
1438 if(numPipesNeeded > availPipes) {
1439 ALOGD_IF(isDebug(), "%s: Insufficient pipes, dpy %d needed %d, avail %d",
1440 __FUNCTION__, mDpy, numPipesNeeded, availPipes);
1441 return false;
1442 }
1443
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001444 if(not areVGPipesAvailable(ctx, list)) {
1445 return false;
1446 }
1447
1448 return true;
1449}
1450
1451bool MDPCompNonSplit::areVGPipesAvailable(hwc_context_t *ctx,
1452 hwc_display_contents_1_t* list) {
1453 overlay::Overlay& ov = *ctx->mOverlay;
1454 int pipesNeeded = 0;
1455 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1456 if(!mCurrentFrame.isFBComposed[i]) {
1457 hwc_layer_1_t* layer = &list->hwLayers[i];
1458 hwc_rect_t dst = layer->displayFrame;
1459 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301460 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1461 pipesNeeded = pipesNeeded + 2;
1462 }
1463 else if(isYuvBuffer(hnd)) {
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001464 pipesNeeded++;
1465 }
1466 }
1467 }
1468
1469 int availableVGPipes = ov.availablePipes(mDpy, ovutils::OV_MDP_PIPE_VG);
1470 if(pipesNeeded > availableVGPipes) {
1471 ALOGD_IF(isDebug(), "%s: Insufficient VG pipes for video layers"
1472 "dpy %d needed %d, avail %d",
1473 __FUNCTION__, mDpy, pipesNeeded, availableVGPipes);
1474 return false;
1475 }
1476
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001477 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001478}
1479
Saurabh Shah88e4d272013-09-03 13:31:29 -07001480bool MDPCompNonSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001481 hwc_display_contents_1_t* list) {
1482 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001483
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001484 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001485
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001486 hwc_layer_1_t* layer = &list->hwLayers[index];
1487 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301488 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1489 if(allocSplitVGPipesfor4k2k(ctx, list, index)){
1490 continue;
1491 }
1492 }
1493
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001494 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001495 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001496 info.pipeInfo = new MdpPipeInfoNonSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08001497 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001498 MdpPipeInfoNonSplit& pipe_info = *(MdpPipeInfoNonSplit*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001499 ePipeType type = MDPCOMP_OV_ANY;
1500
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001501 if(isYuvBuffer(hnd)) {
1502 type = MDPCOMP_OV_VG;
Saurabh Shah8a117932013-05-23 12:48:13 -07001503 } else if(!qhwc::needsScaling(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001504 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
1505 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001506 type = MDPCOMP_OV_DMA;
1507 }
1508
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001509 pipe_info.index = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001510 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001511 ALOGD_IF(isDebug(), "%s: Unable to get pipe type = %d",
1512 __FUNCTION__, (int) type);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001513 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001514 }
1515 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001516 return true;
1517}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001518
radhakrishnac9a67412013-09-25 17:40:42 +05301519int MDPCompNonSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1520 PipeLayerPair& PipeLayerPair) {
1521 MdpYUVPipeInfo& mdp_info =
1522 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1523 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1524 eIsFg isFg = IS_FG_OFF;
1525 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1526 eDest lDest = mdp_info.lIndex;
1527 eDest rDest = mdp_info.rIndex;
1528
1529 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1530 lDest, rDest, &PipeLayerPair.rot);
1531}
1532
Saurabh Shah88e4d272013-09-03 13:31:29 -07001533bool MDPCompNonSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001534
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001535 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001536 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1537 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -08001538 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001539
1540 if(!ctx || !list) {
1541 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001542 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001543 }
1544
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301545 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1546 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1547 return true;
1548 }
1549
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001550 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001551 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001552 idleInvalidator->markForSleep();
1553
1554 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001555 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001556
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001557 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1558 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001559 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001560 if(mCurrentFrame.isFBComposed[i]) continue;
1561
Naseer Ahmed5b6708a2012-08-02 13:46:08 -07001562 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001563 private_handle_t *hnd = (private_handle_t *)layer->handle;
1564 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001565 if (!(layer->flags & HWC_COLOR_FILL)) {
1566 ALOGE("%s handle null", __FUNCTION__);
1567 return false;
1568 }
1569 // No PLAY for Color layer
1570 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1571 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001572 }
1573
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001574 int mdpIndex = mCurrentFrame.layerToMDP[i];
1575
radhakrishnac9a67412013-09-25 17:40:42 +05301576 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1577 {
1578 MdpYUVPipeInfo& pipe_info =
1579 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1580 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1581 ovutils::eDest indexL = pipe_info.lIndex;
1582 ovutils::eDest indexR = pipe_info.rIndex;
1583 int fd = hnd->fd;
1584 uint32_t offset = hnd->offset;
1585 if(rot) {
1586 rot->queueBuffer(fd, offset);
1587 fd = rot->getDstMemId();
1588 offset = rot->getDstOffset();
1589 }
1590 if(indexL != ovutils::OV_INVALID) {
1591 ovutils::eDest destL = (ovutils::eDest)indexL;
1592 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1593 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1594 if (!ov.queueBuffer(fd, offset, destL)) {
1595 ALOGE("%s: queueBuffer failed for display:%d",
1596 __FUNCTION__, mDpy);
1597 return false;
1598 }
1599 }
1600
1601 if(indexR != ovutils::OV_INVALID) {
1602 ovutils::eDest destR = (ovutils::eDest)indexR;
1603 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1604 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1605 if (!ov.queueBuffer(fd, offset, destR)) {
1606 ALOGE("%s: queueBuffer failed for display:%d",
1607 __FUNCTION__, mDpy);
1608 return false;
1609 }
1610 }
1611 }
1612 else{
1613 MdpPipeInfoNonSplit& pipe_info =
Saurabh Shah88e4d272013-09-03 13:31:29 -07001614 *(MdpPipeInfoNonSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
radhakrishnac9a67412013-09-25 17:40:42 +05301615 ovutils::eDest dest = pipe_info.index;
1616 if(dest == ovutils::OV_INVALID) {
1617 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001618 return false;
radhakrishnac9a67412013-09-25 17:40:42 +05301619 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001620
radhakrishnac9a67412013-09-25 17:40:42 +05301621 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1622 continue;
1623 }
1624
1625 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1626 using pipe: %d", __FUNCTION__, layer,
1627 hnd, dest );
1628
1629 int fd = hnd->fd;
1630 uint32_t offset = hnd->offset;
1631
1632 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1633 if(rot) {
1634 if(!rot->queueBuffer(fd, offset))
1635 return false;
1636 fd = rot->getDstMemId();
1637 offset = rot->getDstOffset();
1638 }
1639
1640 if (!ov.queueBuffer(fd, offset, dest)) {
1641 ALOGE("%s: queueBuffer failed for display:%d ",
1642 __FUNCTION__, mDpy);
1643 return false;
1644 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001645 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001646
1647 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001648 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001649 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001650}
1651
Saurabh Shah88e4d272013-09-03 13:31:29 -07001652//=============MDPCompSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001653
radhakrishnac9a67412013-09-25 17:40:42 +05301654void MDPCompSplit::modifymdpCountfor4k2k(hwc_context_t *ctx,
1655 hwc_display_contents_1_t* list){
1656 //if 4kx2k yuv layer is totally present in either in left half
1657 //or right half then try splitting the yuv layer to avoid decimation
1658 int n4k2kYuvCount = ctx->listStats[mDpy].yuv4k2kCount;
1659 const int lSplit = getLeftSplit(ctx, mDpy);
1660 for(int index = 0; index < n4k2kYuvCount; index++){
1661 int n4k2kYuvIndex = ctx->listStats[mDpy].yuv4k2kIndices[index];
1662 hwc_layer_1_t* layer = &list->hwLayers[n4k2kYuvIndex];
1663 hwc_rect_t dst = layer->displayFrame;
1664
1665 if((dst.left > lSplit)||(dst.right < lSplit)){
1666 mCurrentFrame.mdpCount += 1;
1667 }
1668 }
1669}
1670
Saurabh Shah88e4d272013-09-03 13:31:29 -07001671int MDPCompSplit::pipesNeeded(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001672 hwc_display_contents_1_t* list,
1673 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001674 int pipesNeeded = 0;
Saurabh Shah67a38c32013-06-10 16:23:15 -07001675 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001676
1677 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001678
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001679 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1680 if(!mCurrentFrame.isFBComposed[i]) {
1681 hwc_layer_1_t* layer = &list->hwLayers[i];
1682 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001683 if(mixer == Overlay::MIXER_LEFT && dst.left < lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001684 pipesNeeded++;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001685 } else if(mixer == Overlay::MIXER_RIGHT && dst.right > lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001686 pipesNeeded++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001687 }
1688 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001689 }
1690 return pipesNeeded;
1691}
1692
Saurabh Shah88e4d272013-09-03 13:31:29 -07001693bool MDPCompSplit::arePipesAvailable(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001694 hwc_display_contents_1_t* list) {
1695 overlay::Overlay& ov = *ctx->mOverlay;
Saurabh Shah082468e2013-09-12 10:05:32 -07001696 int totalPipesNeeded = 0;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001697
1698 for(int i = 0; i < Overlay::MIXER_MAX; i++) {
1699 int numPipesNeeded = pipesNeeded(ctx, list, i);
1700 int availPipes = ov.availablePipes(mDpy, i);
1701
1702 //Reserve pipe(s)for FB
1703 if(mCurrentFrame.fbCount)
Saurabh Shah082468e2013-09-12 10:05:32 -07001704 numPipesNeeded += 1;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001705
Saurabh Shah082468e2013-09-12 10:05:32 -07001706 totalPipesNeeded += numPipesNeeded;
1707
1708 //Per mixer check.
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001709 if(numPipesNeeded > availPipes) {
1710 ALOGD_IF(isDebug(), "%s: Insufficient pipes for "
1711 "dpy %d mixer %d needed %d, avail %d",
1712 __FUNCTION__, mDpy, i, numPipesNeeded, availPipes);
1713 return false;
1714 }
1715 }
Saurabh Shah082468e2013-09-12 10:05:32 -07001716
1717 //Per display check, since unused pipes can get counted twice.
1718 int totalPipesAvailable = ov.availablePipes(mDpy);
1719 if(totalPipesNeeded > totalPipesAvailable) {
1720 ALOGD_IF(isDebug(), "%s: Insufficient pipes for "
1721 "dpy %d needed %d, avail %d",
1722 __FUNCTION__, mDpy, totalPipesNeeded, totalPipesAvailable);
1723 return false;
1724 }
1725
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001726 if(not areVGPipesAvailable(ctx, list)) {
1727 return false;
1728 }
1729
1730 return true;
1731}
1732
1733bool MDPCompSplit::areVGPipesAvailable(hwc_context_t *ctx,
1734 hwc_display_contents_1_t* list) {
1735 overlay::Overlay& ov = *ctx->mOverlay;
1736 int pipesNeeded = 0;
1737 const int lSplit = getLeftSplit(ctx, mDpy);
1738 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1739 if(!mCurrentFrame.isFBComposed[i]) {
1740 hwc_layer_1_t* layer = &list->hwLayers[i];
1741 hwc_rect_t dst = layer->displayFrame;
1742 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301743 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1744 if((dst.left > lSplit)||(dst.right < lSplit)){
1745 pipesNeeded = pipesNeeded + 2;
1746 continue;
1747 }
1748 }
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001749 if(isYuvBuffer(hnd)) {
1750 if(dst.left < lSplit) {
1751 pipesNeeded++;
1752 }
1753 if(dst.right > lSplit) {
1754 pipesNeeded++;
1755 }
1756 }
1757 }
1758 }
1759
1760 int availableVGPipes = ov.availablePipes(mDpy, ovutils::OV_MDP_PIPE_VG);
1761 if(pipesNeeded > availableVGPipes) {
1762 ALOGD_IF(isDebug(), "%s: Insufficient VG pipes for video layers"
1763 "dpy %d needed %d, avail %d",
1764 __FUNCTION__, mDpy, pipesNeeded, availableVGPipes);
1765 return false;
1766 }
1767
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001768 return true;
1769}
1770
Saurabh Shah88e4d272013-09-03 13:31:29 -07001771bool MDPCompSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
1772 MdpPipeInfoSplit& pipe_info,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001773 ePipeType type) {
1774 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001775 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001776
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001777 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001778 pipe_info.lIndex = ovutils::OV_INVALID;
1779 pipe_info.rIndex = ovutils::OV_INVALID;
1780
1781 if (dst.left < lSplit) {
1782 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_LEFT);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001783 if(pipe_info.lIndex == ovutils::OV_INVALID)
1784 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001785 }
1786
1787 if(dst.right > lSplit) {
1788 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_RIGHT);
1789 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001790 return false;
1791 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001792
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001793 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001794}
1795
Saurabh Shah88e4d272013-09-03 13:31:29 -07001796bool MDPCompSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001797 hwc_display_contents_1_t* list) {
1798 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001799
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001800 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001801
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001802 hwc_layer_1_t* layer = &list->hwLayers[index];
1803 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301804 hwc_rect_t dst = layer->displayFrame;
1805 const int lSplit = getLeftSplit(ctx, mDpy);
1806 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1807 if((dst.left > lSplit)||(dst.right < lSplit)){
1808 if(allocSplitVGPipesfor4k2k(ctx, list, index)){
1809 continue;
1810 }
1811 }
1812 }
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001813 int mdpIndex = mCurrentFrame.layerToMDP[index];
1814 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001815 info.pipeInfo = new MdpPipeInfoSplit;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001816 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001817 MdpPipeInfoSplit& pipe_info = *(MdpPipeInfoSplit*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001818 ePipeType type = MDPCOMP_OV_ANY;
1819
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001820 if(isYuvBuffer(hnd)) {
1821 type = MDPCOMP_OV_VG;
Sushil Chauhan15a2ea62013-09-04 18:28:36 -07001822 } else if(!qhwc::needsScalingWithSplit(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001823 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001824 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001825 type = MDPCOMP_OV_DMA;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001826 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001827
1828 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001829 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type = %d",
1830 __FUNCTION__, (int) type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001831 return false;
1832 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001833 }
1834 return true;
1835}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001836
radhakrishnac9a67412013-09-25 17:40:42 +05301837int MDPCompSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1838 PipeLayerPair& PipeLayerPair) {
1839 const int lSplit = getLeftSplit(ctx, mDpy);
1840 hwc_rect_t dst = layer->displayFrame;
1841 if((dst.left > lSplit)||(dst.right < lSplit)){
1842 MdpYUVPipeInfo& mdp_info =
1843 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1844 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1845 eIsFg isFg = IS_FG_OFF;
1846 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1847 eDest lDest = mdp_info.lIndex;
1848 eDest rDest = mdp_info.rIndex;
1849
1850 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1851 lDest, rDest, &PipeLayerPair.rot);
1852 }
1853 else{
1854 return configure(ctx, layer, PipeLayerPair);
1855 }
1856}
1857
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001858/*
1859 * Configures pipe(s) for MDP composition
1860 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001861int MDPCompSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001862 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001863 MdpPipeInfoSplit& mdp_info =
1864 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001865 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1866 eIsFg isFg = IS_FG_OFF;
1867 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1868 eDest lDest = mdp_info.lIndex;
1869 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001870
1871 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1872 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1873
Saurabh Shah88e4d272013-09-03 13:31:29 -07001874 return configureSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001875 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001876}
1877
Saurabh Shah88e4d272013-09-03 13:31:29 -07001878bool MDPCompSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001879
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001880 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001881 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1882 return true;
1883 }
1884
1885 if(!ctx || !list) {
1886 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001887 return false;
1888 }
1889
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301890 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1891 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1892 return true;
1893 }
1894
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001895 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001896 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001897 idleInvalidator->markForSleep();
1898
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001899 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001900 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001901
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001902 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1903 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001904 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001905 if(mCurrentFrame.isFBComposed[i]) continue;
1906
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001907 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001908 private_handle_t *hnd = (private_handle_t *)layer->handle;
1909 if(!hnd) {
1910 ALOGE("%s handle null", __FUNCTION__);
1911 return false;
1912 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001913
1914 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1915 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001916 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001917
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001918 int mdpIndex = mCurrentFrame.layerToMDP[i];
1919
radhakrishnac9a67412013-09-25 17:40:42 +05301920 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1921 {
1922 MdpYUVPipeInfo& pipe_info =
1923 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1924 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1925 ovutils::eDest indexL = pipe_info.lIndex;
1926 ovutils::eDest indexR = pipe_info.rIndex;
1927 int fd = hnd->fd;
1928 uint32_t offset = hnd->offset;
1929 if(rot) {
1930 rot->queueBuffer(fd, offset);
1931 fd = rot->getDstMemId();
1932 offset = rot->getDstOffset();
1933 }
1934 if(indexL != ovutils::OV_INVALID) {
1935 ovutils::eDest destL = (ovutils::eDest)indexL;
1936 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1937 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1938 if (!ov.queueBuffer(fd, offset, destL)) {
1939 ALOGE("%s: queueBuffer failed for display:%d",
1940 __FUNCTION__, mDpy);
1941 return false;
1942 }
1943 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001944
radhakrishnac9a67412013-09-25 17:40:42 +05301945 if(indexR != ovutils::OV_INVALID) {
1946 ovutils::eDest destR = (ovutils::eDest)indexR;
1947 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1948 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1949 if (!ov.queueBuffer(fd, offset, destR)) {
1950 ALOGE("%s: queueBuffer failed for display:%d",
1951 __FUNCTION__, mDpy);
1952 return false;
1953 }
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001954 }
1955 }
radhakrishnac9a67412013-09-25 17:40:42 +05301956 else{
1957 MdpPipeInfoSplit& pipe_info =
1958 *(MdpPipeInfoSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1959 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001960
radhakrishnac9a67412013-09-25 17:40:42 +05301961 ovutils::eDest indexL = pipe_info.lIndex;
1962 ovutils::eDest indexR = pipe_info.rIndex;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001963
radhakrishnac9a67412013-09-25 17:40:42 +05301964 int fd = hnd->fd;
1965 int offset = hnd->offset;
1966
1967 if(ctx->mAD->isModeOn()) {
1968 if(ctx->mAD->draw(ctx, fd, offset)) {
1969 fd = ctx->mAD->getDstFd(ctx);
1970 offset = ctx->mAD->getDstOffset(ctx);
1971 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001972 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001973
radhakrishnac9a67412013-09-25 17:40:42 +05301974 if(rot) {
1975 rot->queueBuffer(fd, offset);
1976 fd = rot->getDstMemId();
1977 offset = rot->getDstOffset();
1978 }
1979
1980 //************* play left mixer **********
1981 if(indexL != ovutils::OV_INVALID) {
1982 ovutils::eDest destL = (ovutils::eDest)indexL;
1983 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1984 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1985 if (!ov.queueBuffer(fd, offset, destL)) {
1986 ALOGE("%s: queueBuffer failed for left mixer",
1987 __FUNCTION__);
1988 return false;
1989 }
1990 }
1991
1992 //************* play right mixer **********
1993 if(indexR != ovutils::OV_INVALID) {
1994 ovutils::eDest destR = (ovutils::eDest)indexR;
1995 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1996 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1997 if (!ov.queueBuffer(fd, offset, destR)) {
1998 ALOGE("%s: queueBuffer failed for right mixer",
1999 __FUNCTION__);
2000 return false;
2001 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002002 }
2003 }
Saurabh Shahacf10202013-02-26 10:15:15 -08002004
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002005 layerProp[i].mFlags &= ~HWC_MDPCOMP;
2006 }
Saurabh Shahacf10202013-02-26 10:15:15 -08002007
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002008 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002009}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002010}; //namespace
2011