blob: 1f86f59f4fa17eea7696bd3d8089ee8b83fe5d20 [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 Shah8c5c8522013-08-29 17:32:49 -070046float MDPComp::sMaxBw = 2.3f;
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
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700132 if(property_get("debug.mdpcomp.bw", property, "0") > 0) {
133 float val = atof(property);
134 if(val > 0.0f) {
135 sMaxBw = val;
136 }
137 }
138
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400139 if(ctx->mMDP.panel != MIPI_CMD_PANEL) {
140 // Idle invalidation is not necessary on command mode panels
141 long idle_timeout = DEFAULT_IDLE_TIME;
142 if(property_get("debug.mdpcomp.idletime", property, NULL) > 0) {
143 if(atoi(property) != 0)
144 idle_timeout = atoi(property);
145 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800146
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400147 //create Idle Invalidator only when not disabled through property
148 if(idle_timeout != -1)
149 idleInvalidator = IdleInvalidator::getInstance();
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800150
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400151 if(idleInvalidator == NULL) {
152 ALOGE("%s: failed to instantiate idleInvalidator object",
153 __FUNCTION__);
154 } else {
155 idleInvalidator->init(timeout_handler, ctx, idle_timeout);
156 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800157 }
radhakrishnac9a67412013-09-25 17:40:42 +0530158
159 if((property_get("debug.mdpcomp.4k2kSplit", property, "0") > 0) &&
160 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
161 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
162 sEnable4k2kYUVSplit = true;
163 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700164 return true;
165}
166
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700167void MDPComp::reset(const int& numLayers, hwc_display_contents_1_t* list) {
168 mCurrentFrame.reset(numLayers);
169 mCachedFrame.cacheAll(list);
170 mCachedFrame.updateCounts(mCurrentFrame);
171}
172
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700173void MDPComp::timeout_handler(void *udata) {
174 struct hwc_context_t* ctx = (struct hwc_context_t*)(udata);
175
176 if(!ctx) {
177 ALOGE("%s: received empty data in timer callback", __FUNCTION__);
178 return;
179 }
180
Jesse Hall3be78d92012-08-21 15:12:23 -0700181 if(!ctx->proc) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700182 ALOGE("%s: HWC proc not registered", __FUNCTION__);
183 return;
184 }
185 sIdleFallBack = true;
186 /* Trigger SF to redraw the current frame */
Jesse Hall3be78d92012-08-21 15:12:23 -0700187 ctx->proc->invalidate(ctx->proc);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700188}
189
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800190void MDPComp::setMDPCompLayerFlags(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800191 hwc_display_contents_1_t* list) {
192 LayerProp *layerProp = ctx->layerProp[mDpy];
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800193
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800194 for(int index = 0; index < ctx->listStats[mDpy].numAppLayers; index++) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800195 hwc_layer_1_t* layer = &(list->hwLayers[index]);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800196 if(!mCurrentFrame.isFBComposed[index]) {
197 layerProp[index].mFlags |= HWC_MDPCOMP;
198 layer->compositionType = HWC_OVERLAY;
199 layer->hints |= HWC_HINT_CLEAR_FB;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800200 } else {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700201 /* Drop the layer when its already present in FB OR when it lies
202 * outside frame's ROI */
203 if(!mCurrentFrame.needsRedraw || mCurrentFrame.drop[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800204 layer->compositionType = HWC_OVERLAY;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700205 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800206 }
207 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700208}
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500209
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800210MDPComp::FrameInfo::FrameInfo() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700211 reset(0);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800212}
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800213
Saurabh Shahaa236822013-04-24 18:07:26 -0700214void MDPComp::FrameInfo::reset(const int& numLayers) {
215 for(int i = 0 ; i < MAX_PIPES_PER_MIXER && numLayers; i++ ) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800216 if(mdpToLayer[i].pipeInfo) {
217 delete mdpToLayer[i].pipeInfo;
218 mdpToLayer[i].pipeInfo = NULL;
219 //We dont own the rotator
220 mdpToLayer[i].rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800221 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800222 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800223
224 memset(&mdpToLayer, 0, sizeof(mdpToLayer));
225 memset(&layerToMDP, -1, sizeof(layerToMDP));
Saurabh Shahaa236822013-04-24 18:07:26 -0700226 memset(&isFBComposed, 1, sizeof(isFBComposed));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800227
Saurabh Shahaa236822013-04-24 18:07:26 -0700228 layerCount = numLayers;
229 fbCount = numLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800230 mdpCount = 0;
Saurabh Shah2f3895f2013-05-02 10:13:31 -0700231 needsRedraw = true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800232 fbZ = 0;
233}
234
Saurabh Shahaa236822013-04-24 18:07:26 -0700235void MDPComp::FrameInfo::map() {
236 // populate layer and MDP maps
237 int mdpIdx = 0;
238 for(int idx = 0; idx < layerCount; idx++) {
239 if(!isFBComposed[idx]) {
240 mdpToLayer[mdpIdx].listIndex = idx;
241 layerToMDP[idx] = mdpIdx++;
242 }
243 }
244}
245
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800246MDPComp::LayerCache::LayerCache() {
247 reset();
248}
249
250void MDPComp::LayerCache::reset() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700251 memset(&hnd, 0, sizeof(hnd));
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530252 memset(&isFBComposed, true, sizeof(isFBComposed));
253 memset(&drop, false, sizeof(drop));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800254 layerCount = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -0700255}
256
257void MDPComp::LayerCache::cacheAll(hwc_display_contents_1_t* list) {
258 const int numAppLayers = list->numHwLayers - 1;
259 for(int i = 0; i < numAppLayers; i++) {
260 hnd[i] = list->hwLayers[i].handle;
261 }
262}
263
264void MDPComp::LayerCache::updateCounts(const FrameInfo& curFrame) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700265 layerCount = curFrame.layerCount;
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530266 memcpy(&isFBComposed, &curFrame.isFBComposed, sizeof(isFBComposed));
267 memcpy(&drop, &curFrame.drop, sizeof(drop));
268}
269
Jeykumar Sankaran988d3682013-11-15 11:57:16 -0800270bool MDPComp::LayerCache::isSameFrame(const FrameInfo& curFrame,
271 hwc_display_contents_1_t* list) {
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530272 if(layerCount != curFrame.layerCount)
273 return false;
274 for(int i = 0; i < curFrame.layerCount; i++) {
275 if((curFrame.isFBComposed[i] != isFBComposed[i]) ||
276 (curFrame.drop[i] != drop[i])) {
277 return false;
278 }
Jeykumar Sankaran988d3682013-11-15 11:57:16 -0800279 if(curFrame.isFBComposed[i] &&
280 (hnd[i] != list->hwLayers[i].handle)){
281 return false;
282 }
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530283 }
284 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800285}
286
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700287bool MDPComp::isSupportedForMDPComp(hwc_context_t *ctx, hwc_layer_1_t* layer) {
288 private_handle_t *hnd = (private_handle_t *)layer->handle;
289 if((not isYuvBuffer(hnd) and has90Transform(layer)) or
290 (not isValidDimension(ctx,layer))
291 //More conditions here, SKIP, sRGB+Blend etc
292 ) {
293 return false;
294 }
295 return true;
296}
297
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530298bool MDPComp::isValidDimension(hwc_context_t *ctx, hwc_layer_1_t *layer) {
Saurabh Shah4fdde762013-04-30 18:47:33 -0700299 const int dpy = HWC_DISPLAY_PRIMARY;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800300 private_handle_t *hnd = (private_handle_t *)layer->handle;
301
302 if(!hnd) {
303 ALOGE("%s: layer handle is NULL", __FUNCTION__);
304 return false;
305 }
306
Naseer Ahmede850a802013-09-06 13:12:52 -0400307 //XXX: Investigate doing this with pixel phase on MDSS
Naseer Ahmede77f8082013-10-10 13:42:48 -0400308 if(!isSecureBuffer(hnd) && isNonIntegralSourceCrop(layer->sourceCropf))
Naseer Ahmede850a802013-09-06 13:12:52 -0400309 return false;
310
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800311 int hw_w = ctx->dpyAttr[mDpy].xres;
312 int hw_h = ctx->dpyAttr[mDpy].yres;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800313
Saurabh Shah62e1d732013-09-17 10:44:05 -0700314 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700315 hwc_rect_t dst = layer->displayFrame;
Saurabh Shah4fdde762013-04-30 18:47:33 -0700316 int crop_w = crop.right - crop.left;
317 int crop_h = crop.bottom - crop.top;
318 int dst_w = dst.right - dst.left;
319 int dst_h = dst.bottom - dst.top;
320 float w_dscale = ceilf((float)crop_w / (float)dst_w);
321 float h_dscale = ceilf((float)crop_h / (float)dst_h);
322
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800323 /* Workaround for MDP HW limitation in DSI command mode panels where
324 * FPS will not go beyond 30 if buffers on RGB pipes are of width or height
325 * less than 5 pixels
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530326 * There also is a HW limilation in MDP, minimum block size is 2x2
327 * Fallback to GPU if height is less than 2.
328 */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800329 if((crop_w < 5)||(crop_h < 5))
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800330 return false;
331
Saurabh Shah4fdde762013-04-30 18:47:33 -0700332 const uint32_t downscale =
333 qdutils::MDPVersion::getInstance().getMaxMDPDownscale();
334 if(ctx->mMDP.version >= qdutils::MDSS_V5) {
335 /* Workaround for downscales larger than 4x.
336 * Will be removed once decimator block is enabled for MDSS
337 */
338 if(!qdutils::MDPVersion::getInstance().supportsDecimation()) {
339 if(crop_w > MAX_DISPLAY_DIM || w_dscale > downscale ||
340 h_dscale > downscale)
341 return false;
342 } else {
343 if(w_dscale > 64 || h_dscale > 64)
344 return false;
345 }
346 } else { //A-family
347 if(w_dscale > downscale || h_dscale > downscale)
348 return false;
349 }
350
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800351 return true;
352}
353
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700354ovutils::eDest MDPComp::getMdpPipe(hwc_context_t *ctx, ePipeType type,
355 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800356 overlay::Overlay& ov = *ctx->mOverlay;
357 ovutils::eDest mdp_pipe = ovutils::OV_INVALID;
358
359 switch(type) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800360 case MDPCOMP_OV_DMA:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700361 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_DMA, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800362 if(mdp_pipe != ovutils::OV_INVALID) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800363 return mdp_pipe;
364 }
365 case MDPCOMP_OV_ANY:
366 case MDPCOMP_OV_RGB:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700367 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800368 if(mdp_pipe != ovutils::OV_INVALID) {
369 return mdp_pipe;
370 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800371
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800372 if(type == MDPCOMP_OV_RGB) {
373 //Requested only for RGB pipe
374 break;
375 }
376 case MDPCOMP_OV_VG:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700377 return ov.nextPipe(ovutils::OV_MDP_PIPE_VG, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800378 default:
379 ALOGE("%s: Invalid pipe type",__FUNCTION__);
380 return ovutils::OV_INVALID;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800381 };
382 return ovutils::OV_INVALID;
383}
384
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800385bool MDPComp::isFrameDoable(hwc_context_t *ctx) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700386 bool ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700387 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800388
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800389 if(!isEnabled()) {
390 ALOGD_IF(isDebug(),"%s: MDP Comp. not enabled.", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700391 ret = false;
Saurabh Shahd4e65852013-06-17 11:33:53 -0700392 } else if(qdutils::MDPVersion::getInstance().is8x26() &&
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700393 ctx->mVideoTransFlag && ctx->mVirtualDisplay->isConnected()) {
Saurabh Shahd4e65852013-06-17 11:33:53 -0700394 //1 Padding round to shift pipes across mixers
395 ALOGD_IF(isDebug(),"%s: MDP Comp. video transition padding round",
396 __FUNCTION__);
397 ret = false;
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700398 } else if(ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isConfiguring ||
399 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isConfiguring) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800400 ALOGD_IF( isDebug(),"%s: External Display connection is pending",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800401 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700402 ret = false;
Saurabh Shahaa236822013-04-24 18:07:26 -0700403 } else if(ctx->isPaddingRound) {
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700404 ctx->isPaddingRound = false;
405 ALOGD_IF(isDebug(), "%s: padding round",__FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700406 ret = false;
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700407 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700408 return ret;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800409}
410
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800411/*
412 * 1) Identify layers that are not visible in the updating ROI and drop them
413 * from composition.
414 * 2) If we have a scaling layers which needs cropping against generated ROI.
415 * Reset ROI to full resolution.
416 */
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700417bool MDPComp::validateAndApplyROI(hwc_context_t *ctx,
418 hwc_display_contents_1_t* list, hwc_rect_t roi) {
419 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
420
421 if(!isValidRect(roi))
422 return false;
423
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800424 hwc_rect_t visibleRect = roi;
425
426 for(int i = numAppLayers - 1; i >= 0; i--){
427
428 if(!isValidRect(visibleRect)) {
429 mCurrentFrame.drop[i] = true;
430 mCurrentFrame.dropCount++;
431 }
432
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700433 const hwc_layer_1_t* layer = &list->hwLayers[i];
434
435 hwc_rect_t dstRect = layer->displayFrame;
Arun Kumar K.R91090c72013-10-28 19:40:18 -0700436 hwc_rect_t srcRect = integerizeSourceCrop(layer->sourceCropf);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700437 int transform = layer->transform;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700438
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800439 hwc_rect_t res = getIntersection(visibleRect, dstRect);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700440
441 int res_w = res.right - res.left;
442 int res_h = res.bottom - res.top;
443 int dst_w = dstRect.right - dstRect.left;
444 int dst_h = dstRect.bottom - dstRect.top;
445
446 if(!isValidRect(res)) {
447 mCurrentFrame.drop[i] = true;
448 mCurrentFrame.dropCount++;
449 }else {
450 /* Reset frame ROI when any layer which needs scaling also needs ROI
451 * cropping */
452 if((res_w != dst_w || res_h != dst_h) &&
453 needsScaling (ctx, layer, mDpy)) {
Arpita Banerjeed8965982013-11-08 17:27:33 -0800454 ALOGI("%s: Resetting ROI due to scaling", __FUNCTION__);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700455 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
456 mCurrentFrame.dropCount = 0;
457 return false;
458 }
459 }
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800460
461 if (layer->blending == HWC_BLENDING_NONE)
462 visibleRect = deductRect(visibleRect, res);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700463 }
464 return true;
465}
466
467void MDPComp::generateROI(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
468 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
469
470 if(!sEnablePartialFrameUpdate) {
471 return;
472 }
473
474 if(mDpy || isDisplaySplit(ctx, mDpy)){
475 ALOGE_IF(isDebug(), "%s: ROI not supported for"
476 "the (1) external / virtual display's (2) dual DSI displays",
477 __FUNCTION__);
478 return;
479 }
480
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800481 if(isSkipPresent(ctx, mDpy))
482 return;
483
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700484 if(list->flags & HWC_GEOMETRY_CHANGED)
485 return;
486
487 struct hwc_rect roi = (struct hwc_rect){0, 0, 0, 0};
488 for(int index = 0; index < numAppLayers; index++ ) {
489 if ((mCachedFrame.hnd[index] != list->hwLayers[index].handle) ||
490 isYuvBuffer((private_handle_t *)list->hwLayers[index].handle)) {
491 hwc_rect_t dstRect = list->hwLayers[index].displayFrame;
Arun Kumar K.R91090c72013-10-28 19:40:18 -0700492 hwc_rect_t srcRect = integerizeSourceCrop(
493 list->hwLayers[index].sourceCropf);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700494 int transform = list->hwLayers[index].transform;
495
496 /* Intersect against display boundaries */
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700497 roi = getUnion(roi, dstRect);
498 }
499 }
500
501 if(!validateAndApplyROI(ctx, list, roi)){
502 roi = (struct hwc_rect) {0, 0,
503 (int)ctx->dpyAttr[mDpy].xres, (int)ctx->dpyAttr[mDpy].yres};
504 }
505
506 ctx->listStats[mDpy].roi.x = roi.left;
507 ctx->listStats[mDpy].roi.y = roi.top;
508 ctx->listStats[mDpy].roi.w = roi.right - roi.left;
509 ctx->listStats[mDpy].roi.h = roi.bottom - roi.top;
510
511 ALOGD_IF(isDebug(),"%s: generated ROI: [%d, %d, %d, %d]", __FUNCTION__,
512 roi.left, roi.top, roi.right, roi.bottom);
513}
514
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800515/* Checks for conditions where all the layers marked for MDP comp cannot be
516 * bypassed. On such conditions we try to bypass atleast YUV layers */
517bool MDPComp::isFullFrameDoable(hwc_context_t *ctx,
518 hwc_display_contents_1_t* list){
519
Saurabh Shahaa236822013-04-24 18:07:26 -0700520 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800521
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -0700522 if(sIdleFallBack && !ctx->listStats[mDpy].secureUI) {
Saurabh Shah2d998a92013-05-14 17:55:58 -0700523 ALOGD_IF(isDebug(), "%s: Idle fallback dpy %d",__FUNCTION__, mDpy);
524 return false;
525 }
526
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800527 if(isSkipPresent(ctx, mDpy)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700528 ALOGD_IF(isDebug(),"%s: SKIP present: %d",
529 __FUNCTION__,
530 isSkipPresent(ctx, mDpy));
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800531 return false;
532 }
533
Saurabh Shah9f084ad2013-05-02 11:28:09 -0700534 if(ctx->listStats[mDpy].needsAlphaScale
535 && ctx->mMDP.version < qdutils::MDSS_V5) {
536 ALOGD_IF(isDebug(), "%s: frame needs alpha downscaling",__FUNCTION__);
537 return false;
538 }
539
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800540 for(int i = 0; i < numAppLayers; ++i) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800541 hwc_layer_1_t* layer = &list->hwLayers[i];
542 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800543
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700544 if(isYuvBuffer(hnd) && has90Transform(layer)) {
545 if(!canUseRotator(ctx, mDpy)) {
546 ALOGD_IF(isDebug(), "%s: Can't use rotator for dpy %d",
547 __FUNCTION__, mDpy);
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700548 return false;
549 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800550 }
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530551
552 //For 8x26 with panel width>1k, if RGB layer needs HFLIP fail mdp comp
553 // may not need it if Gfx pre-rotation can handle all flips & rotations
554 if(qdutils::MDPVersion::getInstance().is8x26() &&
555 (ctx->dpyAttr[mDpy].xres > 1024) &&
556 (layer->transform & HWC_TRANSFORM_FLIP_H) &&
557 (!isYuvBuffer(hnd)))
558 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800559 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700560
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700561 if(ctx->mAD->isDoable()) {
562 return false;
563 }
564
Saurabh Shahaa236822013-04-24 18:07:26 -0700565 //If all above hard conditions are met we can do full or partial MDP comp.
566 bool ret = false;
567 if(fullMDPComp(ctx, list)) {
568 ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700569 } else if(partialMDPComp(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700570 ret = true;
571 }
572 return ret;
573}
574
575bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700576 //Will benefit presentation / secondary-only layer.
577 if((mDpy > HWC_DISPLAY_PRIMARY) &&
578 (list->numHwLayers - 1) > MAX_SEC_LAYERS) {
579 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
580 return false;
581 }
582
583 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
584 for(int i = 0; i < numAppLayers; i++) {
585 hwc_layer_1_t* layer = &list->hwLayers[i];
586 if(not isSupportedForMDPComp(ctx, layer)) {
587 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",__FUNCTION__);
588 return false;
589 }
590 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700591 mCurrentFrame.fbCount = 0;
592 mCurrentFrame.fbZ = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700593 memcpy(&mCurrentFrame.isFBComposed, &mCurrentFrame.drop,
594 sizeof(mCurrentFrame.isFBComposed));
595 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount -
596 mCurrentFrame.dropCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700597
radhakrishnac9a67412013-09-25 17:40:42 +0530598 if(sEnable4k2kYUVSplit){
599 modifymdpCountfor4k2k(ctx, list);
600 }
601
Saurabh Shah173f4242013-11-20 09:50:12 -0800602 if(!resourceCheck(ctx, list)) {
603 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700604 return false;
605 }
606
Saurabh Shahaa236822013-04-24 18:07:26 -0700607 return true;
608}
609
610bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
611{
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700612 if(!sEnableMixedMode) {
613 //Mixed mode is disabled. No need to even try caching.
614 return false;
615 }
616
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700617 bool ret = false;
618 if(isLoadBasedCompDoable(ctx, list)) {
Saurabh Shahb772ae32013-11-18 15:40:02 -0800619 ret = loadBasedCompPreferGPU(ctx, list) ||
620 loadBasedCompPreferMDP(ctx, list);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700621 }
622
623 if(!ret) {
624 ret = cacheBasedComp(ctx, list);
625 }
626
627 return ret;
628}
629
630bool MDPComp::cacheBasedComp(hwc_context_t *ctx,
631 hwc_display_contents_1_t* list) {
632 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700633 mCurrentFrame.reset(numAppLayers);
634 updateLayerCache(ctx, list);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700635
636 //If an MDP marked layer is unsupported cannot do partial MDP Comp
637 for(int i = 0; i < numAppLayers; i++) {
638 if(!mCurrentFrame.isFBComposed[i]) {
639 hwc_layer_1_t* layer = &list->hwLayers[i];
640 if(not isSupportedForMDPComp(ctx, layer)) {
641 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",
642 __FUNCTION__);
643 return false;
644 }
645 }
646 }
647
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700648 updateYUV(ctx, list, false /*secure only*/);
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530649 bool ret = markLayersForCaching(ctx, list); //sets up fbZ also
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700650 if(!ret) {
651 ALOGD_IF(isDebug(),"%s: batching failed, dpy %d",__FUNCTION__, mDpy);
652 return false;
653 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700654
655 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700656
radhakrishnac9a67412013-09-25 17:40:42 +0530657 if(sEnable4k2kYUVSplit){
658 modifymdpCountfor4k2k(ctx, list);
659 }
660
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700661 //Will benefit cases where a video has non-updating background.
662 if((mDpy > HWC_DISPLAY_PRIMARY) and
663 (mdpCount > MAX_SEC_LAYERS)) {
664 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
665 return false;
666 }
667
Saurabh Shah173f4242013-11-20 09:50:12 -0800668 if(!resourceCheck(ctx, list)) {
669 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700670 return false;
671 }
672
Saurabh Shahaa236822013-04-24 18:07:26 -0700673 return true;
674}
675
Saurabh Shahb772ae32013-11-18 15:40:02 -0800676bool MDPComp::loadBasedCompPreferGPU(hwc_context_t *ctx,
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700677 hwc_display_contents_1_t* list) {
678 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
679 mCurrentFrame.reset(numAppLayers);
680
Saurabh Shahb772ae32013-11-18 15:40:02 -0800681 int stagesForMDP = min(sMaxPipesPerMixer, ctx->mOverlay->availablePipes(
682 mDpy, Overlay::MIXER_DEFAULT));
683 //If MDP has X possible stages, it can take X layers.
684 const int batchSize = numAppLayers - (stagesForMDP - 1); //1 for FB
685
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700686 if(batchSize <= 0) {
687 ALOGD_IF(isDebug(), "%s: Not attempting", __FUNCTION__);
688 return false;
689 }
690
691 int minBatchStart = -1;
692 size_t minBatchPixelCount = SIZE_MAX;
693
694 for(int i = 0; i <= numAppLayers - batchSize; i++) {
695 uint32_t batchPixelCount = 0;
696 for(int j = i; j < i + batchSize; j++) {
697 hwc_layer_1_t* layer = &list->hwLayers[j];
Arun Kumar K.R91090c72013-10-28 19:40:18 -0700698 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700699 batchPixelCount += (crop.right - crop.left) *
700 (crop.bottom - crop.top);
701 }
702
703 if(batchPixelCount < minBatchPixelCount) {
704 minBatchPixelCount = batchPixelCount;
705 minBatchStart = i;
706 }
707 }
708
709 if(minBatchStart < 0) {
710 ALOGD_IF(isDebug(), "%s: No batch found batchSize %d numAppLayers %d",
711 __FUNCTION__, batchSize, numAppLayers);
712 return false;
713 }
714
715 for(int i = 0; i < numAppLayers; i++) {
716 if(i < minBatchStart || i >= minBatchStart + batchSize) {
717 hwc_layer_1_t* layer = &list->hwLayers[i];
718 if(not isSupportedForMDPComp(ctx, layer)) {
719 ALOGD_IF(isDebug(), "%s: MDP unsupported layer found at %d",
720 __FUNCTION__, i);
721 return false;
722 }
723 mCurrentFrame.isFBComposed[i] = false;
724 }
725 }
726
727 mCurrentFrame.fbZ = minBatchStart;
728 mCurrentFrame.fbCount = batchSize;
729 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - batchSize;
730
radhakrishnac9a67412013-09-25 17:40:42 +0530731 if(sEnable4k2kYUVSplit){
732 modifymdpCountfor4k2k(ctx, list);
733 }
734
Saurabh Shah173f4242013-11-20 09:50:12 -0800735 if(!resourceCheck(ctx, list)) {
736 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700737 return false;
738 }
739
740 ALOGD_IF(isDebug(), "%s: fbZ %d batchSize %d",
741 __FUNCTION__, mCurrentFrame.fbZ, batchSize);
742 return true;
743}
744
Saurabh Shahb772ae32013-11-18 15:40:02 -0800745bool MDPComp::loadBasedCompPreferMDP(hwc_context_t *ctx,
746 hwc_display_contents_1_t* list) {
747 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
748 //TODO get the ib from sysfs node.
749 //Full screen is from ib perspective, not actual full screen
750 const int bpp = 4;
751 double panelRefRate =
752 1000000000.0 / ctx->dpyAttr[mDpy].vsync_period;
753
754 double bwLeft = sMaxBw - sBwClaimed;
755
756 const int fullScreenLayers = bwLeft * 1000000000 / (ctx->dpyAttr[mDpy].xres
757 * ctx->dpyAttr[mDpy].yres * bpp * panelRefRate);
758
759 const int fbBatchSize = numAppLayers - (fullScreenLayers - 1);
760 //If batch size is not at least 2, we aren't really preferring MDP, since
761 //only 1 layer going to GPU could actually translate into an entire FB
762 //needed to be fetched by MDP, thus needing more b/w rather than less.
763 if(fbBatchSize < 2 || fbBatchSize > numAppLayers) {
764 ALOGD_IF(isDebug(), "%s: Not attempting", __FUNCTION__);
765 return false;
766 }
767
768 //Top-most layers constitute FB batch
769 const int fbBatchStart = numAppLayers - fbBatchSize;
770
771 //Bottom-most layers constitute MDP batch
772 for(int i = 0; i < fbBatchStart; i++) {
773 hwc_layer_1_t* layer = &list->hwLayers[i];
774 if(not isSupportedForMDPComp(ctx, layer)) {
775 ALOGD_IF(isDebug(), "%s: MDP unsupported layer found at %d",
776 __FUNCTION__, i);
777 return false;
778 }
779 mCurrentFrame.isFBComposed[i] = false;
780 }
781
782 mCurrentFrame.fbZ = fbBatchStart;
783 mCurrentFrame.fbCount = fbBatchSize;
784 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - fbBatchSize;
785
radhakrishnac9a67412013-09-25 17:40:42 +0530786 if(sEnable4k2kYUVSplit){
787 modifymdpCountfor4k2k(ctx, list);
788 }
789
Saurabh Shahb772ae32013-11-18 15:40:02 -0800790 if(!resourceCheck(ctx, list)) {
791 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
792 return false;
793 }
794
795 ALOGD_IF(isDebug(), "%s: FB Z %d, num app layers %d, MDP Batch Size %d",
796 __FUNCTION__, mCurrentFrame.fbZ, numAppLayers,
797 numAppLayers - fbBatchSize);
798
799 return true;
800}
801
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700802bool MDPComp::isLoadBasedCompDoable(hwc_context_t *ctx,
803 hwc_display_contents_1_t* list) {
804 if(mDpy or isSecurePresent(ctx, mDpy) or
805 not (list->flags & HWC_GEOMETRY_CHANGED)) {
806 return false;
807 }
808 return true;
809}
810
Saurabh Shahaa236822013-04-24 18:07:26 -0700811bool MDPComp::isOnlyVideoDoable(hwc_context_t *ctx,
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700812 hwc_display_contents_1_t* list, bool secureOnly) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700813 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700814
Saurabh Shahaa236822013-04-24 18:07:26 -0700815 mCurrentFrame.reset(numAppLayers);
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700816 updateYUV(ctx, list, secureOnly);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700817 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700818
819 if(!isYuvPresent(ctx, mDpy)) {
820 return false;
821 }
822
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -0800823 /* Bail out if we are processing only secured video layers
824 * and we dont have any */
825 if(!isSecurePresent(ctx, mDpy) && secureOnly){
826 return false;
827 }
828
Saurabh Shah4fdde762013-04-30 18:47:33 -0700829 if(!mdpCount)
830 return false;
831
Saurabh Shah173f4242013-11-20 09:50:12 -0800832 if(!resourceCheck(ctx, list)) {
833 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700834 return false;
835 }
836
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800837 return true;
838}
839
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800840/* Checks for conditions where YUV layers cannot be bypassed */
841bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Saurabh Shahe2474082013-05-15 16:32:13 -0700842 bool extAnimBlockFeature = mDpy && ctx->listStats[mDpy].isDisplayAnimating;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800843
Saurabh Shahe2474082013-05-15 16:32:13 -0700844 if(isSkipLayer(layer) && !extAnimBlockFeature) {
845 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800846 return false;
847 }
848
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700849 if(layer->transform & HWC_TRANSFORM_ROT_90 && !canUseRotator(ctx,mDpy)) {
850 ALOGD_IF(isDebug(), "%s: no free DMA pipe",__FUNCTION__);
851 return false;
852 }
853
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800854 if(isSecuring(ctx, layer)) {
855 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
856 return false;
857 }
858
Saurabh Shah4fdde762013-04-30 18:47:33 -0700859 if(!isValidDimension(ctx, layer)) {
860 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
861 __FUNCTION__);
862 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800863 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700864
Naseer Ahmeddc61a972013-07-10 17:50:54 -0400865 if(layer->planeAlpha < 0xFF) {
866 ALOGD_IF(isDebug(), "%s: Cannot handle YUV layer with plane alpha\
867 in video only mode",
868 __FUNCTION__);
869 return false;
870 }
871
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800872 return true;
873}
874
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530875/* starts at fromIndex and check for each layer to find
876 * if it it has overlapping with any Updating layer above it in zorder
877 * till the end of the batch. returns true if it finds any intersection */
878bool MDPComp::canPushBatchToTop(const hwc_display_contents_1_t* list,
879 int fromIndex, int toIndex) {
880 for(int i = fromIndex; i < toIndex; i++) {
881 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
882 if(intersectingUpdatingLayers(list, i+1, toIndex, i)) {
883 return false;
884 }
885 }
886 }
887 return true;
888}
889
890/* Checks if given layer at targetLayerIndex has any
891 * intersection with all the updating layers in beween
892 * fromIndex and toIndex. Returns true if it finds intersectiion */
893bool MDPComp::intersectingUpdatingLayers(const hwc_display_contents_1_t* list,
894 int fromIndex, int toIndex, int targetLayerIndex) {
895 for(int i = fromIndex; i <= toIndex; i++) {
896 if(!mCurrentFrame.isFBComposed[i]) {
897 if(areLayersIntersecting(&list->hwLayers[i],
898 &list->hwLayers[targetLayerIndex])) {
899 return true;
900 }
901 }
902 }
903 return false;
904}
905
906int MDPComp::getBatch(hwc_display_contents_1_t* list,
907 int& maxBatchStart, int& maxBatchEnd,
908 int& maxBatchCount) {
909 int i = 0;
910 int updatingLayersAbove = 0;//Updating layer count in middle of batch
911 int fbZOrder =-1;
912 while (i < mCurrentFrame.layerCount) {
913 int batchCount = 0;
914 int batchStart = i;
915 int batchEnd = i;
916 int fbZ = batchStart;
917 int firstZReverseIndex = -1;
918 while(i < mCurrentFrame.layerCount) {
919 if(!mCurrentFrame.isFBComposed[i]) {
920 if(!batchCount) {
921 i++;
922 break;
923 }
924 updatingLayersAbove++;
925 i++;
926 continue;
927 } else {
928 if(mCurrentFrame.drop[i]) {
929 i++;
930 continue;
931 } else if(updatingLayersAbove <= 0) {
932 batchCount++;
933 batchEnd = i;
934 i++;
935 continue;
936 } else { //Layer is FBComposed, not a drop & updatingLayer > 0
937
938 // We have a valid updating layer already. If layer-i not
939 // have overlapping with all updating layers in between
940 // batch-start and i, then we can add layer i to batch.
941 if(!intersectingUpdatingLayers(list, batchStart, i-1, i)) {
942 batchCount++;
943 batchEnd = i;
944 i++;
945 continue;
946 } else if(canPushBatchToTop(list, batchStart, i)) {
947 //If All the non-updating layers with in this batch
948 //does not have intersection with the updating layers
949 //above in z-order, then we can safely move the batch to
950 //higher z-order. Increment fbZ as it is moving up.
951 if( firstZReverseIndex < 0) {
952 firstZReverseIndex = i;
953 }
954 batchCount++;
955 batchEnd = i;
956 fbZ += updatingLayersAbove;
957 i++;
958 updatingLayersAbove = 0;
959 continue;
960 } else {
961 //both failed.start the loop again from here.
962 if(firstZReverseIndex >= 0) {
963 i = firstZReverseIndex;
964 }
965 break;
966 }
967 }
968 }
969 }
970 if(batchCount > maxBatchCount) {
971 maxBatchCount = batchCount;
972 maxBatchStart = batchStart;
973 maxBatchEnd = batchEnd;
974 fbZOrder = fbZ;
975 }
976 }
977 return fbZOrder;
978}
979
980bool MDPComp::markLayersForCaching(hwc_context_t* ctx,
981 hwc_display_contents_1_t* list) {
982 /* Idea is to keep as many non-updating(cached) layers in FB and
983 * send rest of them through MDP. This is done in 2 steps.
984 * 1. Find the maximum contiguous batch of non-updating layers.
985 * 2. See if we can improve this batch size for caching by adding
986 * opaque layers around the batch, if they don't have
987 * any overlapping with the updating layers in between.
988 * NEVER mark an updating layer for caching.
989 * But cached ones can be marked for MDP */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800990
991 int maxBatchStart = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700992 int maxBatchEnd = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800993 int maxBatchCount = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530994 int fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800995
996 /* All or Nothing is cached. No batching needed */
Saurabh Shahaa236822013-04-24 18:07:26 -0700997 if(!mCurrentFrame.fbCount) {
998 mCurrentFrame.fbZ = -1;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700999 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -07001000 }
1001 if(!mCurrentFrame.mdpCount) {
1002 mCurrentFrame.fbZ = 0;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001003 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -07001004 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001005
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301006 fbZ = getBatch(list, maxBatchStart, maxBatchEnd, maxBatchCount);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001007
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301008 /* reset rest of the layers lying inside ROI for MDP comp */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001009 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001010 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001011 if((i < maxBatchStart || i > maxBatchEnd) &&
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301012 mCurrentFrame.isFBComposed[i]){
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001013 if(!mCurrentFrame.drop[i]){
1014 //If an unsupported layer is being attempted to
1015 //be pulled out we should fail
1016 if(not isSupportedForMDPComp(ctx, layer)) {
1017 return false;
1018 }
1019 mCurrentFrame.isFBComposed[i] = false;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001020 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001021 }
1022 }
1023
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301024 // update the frame data
1025 mCurrentFrame.fbZ = fbZ;
1026 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001027 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001028 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001029
1030 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301031 mCurrentFrame.fbCount);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001032
1033 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001034}
Saurabh Shah85234ec2013-04-12 17:09:00 -07001035
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001036void MDPComp::updateLayerCache(hwc_context_t* ctx,
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001037 hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001038 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001039 int fbCount = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001040
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001041 for(int i = 0; i < numAppLayers; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001042 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001043 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001044 if(!mCurrentFrame.drop[i])
1045 fbCount++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001046 mCurrentFrame.isFBComposed[i] = true;
1047 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -07001048 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001049 }
1050 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001051
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001052 mCurrentFrame.fbCount = fbCount;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001053 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount
1054 - mCurrentFrame.dropCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001055
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001056 ALOGD_IF(isDebug(),"%s: MDP count: %d FB count %d drop count: %d"
1057 ,__FUNCTION__, mCurrentFrame.mdpCount, mCurrentFrame.fbCount,
1058 mCurrentFrame.dropCount);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001059}
1060
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001061void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list,
1062 bool secureOnly) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001063 int nYuvCount = ctx->listStats[mDpy].yuvCount;
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001064 if(!nYuvCount && mDpy) {
1065 //Reset "No animation on external display" related parameters.
1066 ctx->mPrevCropVideo.left = ctx->mPrevCropVideo.top =
1067 ctx->mPrevCropVideo.right = ctx->mPrevCropVideo.bottom = 0;
1068 ctx->mPrevDestVideo.left = ctx->mPrevDestVideo.top =
1069 ctx->mPrevDestVideo.right = ctx->mPrevDestVideo.bottom = 0;
1070 ctx->mPrevTransformVideo = 0;
1071 return;
1072 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001073 for(int index = 0;index < nYuvCount; index++){
1074 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
1075 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
1076
1077 if(!isYUVDoable(ctx, layer)) {
1078 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
1079 mCurrentFrame.isFBComposed[nYuvIndex] = true;
1080 mCurrentFrame.fbCount++;
1081 }
1082 } else {
1083 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001084 private_handle_t *hnd = (private_handle_t *)layer->handle;
1085 if(!secureOnly || isSecureBuffer(hnd)) {
1086 mCurrentFrame.isFBComposed[nYuvIndex] = false;
1087 mCurrentFrame.fbCount--;
1088 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001089 }
1090 }
1091 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001092
1093 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001094 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
1095 ALOGD_IF(isDebug(),"%s: fb count: %d",__FUNCTION__,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001096 mCurrentFrame.fbCount);
1097}
1098
Saurabh Shahaa236822013-04-24 18:07:26 -07001099bool MDPComp::programMDP(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001100 if(!allocLayerPipes(ctx, list)) {
1101 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -07001102 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001103 }
1104
1105 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001106 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001107 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001108 int mdpIndex = mCurrentFrame.layerToMDP[index];
1109 hwc_layer_1_t* layer = &list->hwLayers[index];
1110
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301111 //Leave fbZ for framebuffer. CACHE/GLES layers go here.
1112 if(mdpNextZOrder == mCurrentFrame.fbZ) {
1113 mdpNextZOrder++;
1114 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001115 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1116 cur_pipe->zOrder = mdpNextZOrder++;
1117
radhakrishnac9a67412013-09-25 17:40:42 +05301118 private_handle_t *hnd = (private_handle_t *)layer->handle;
1119 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1120 if(configure4k2kYuv(ctx, layer,
1121 mCurrentFrame.mdpToLayer[mdpIndex])
1122 != 0 ){
1123 ALOGD_IF(isDebug(), "%s: Failed to configure split pipes \
1124 for layer %d",__FUNCTION__, index);
1125 return false;
1126 }
1127 else{
1128 mdpNextZOrder++;
1129 }
1130 continue;
1131 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001132 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
1133 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
radhakrishnac9a67412013-09-25 17:40:42 +05301134 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -07001135 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001136 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001137 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001138 }
1139
Saurabh Shahaa236822013-04-24 18:07:26 -07001140 return true;
1141}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001142
Saurabh Shahaa236822013-04-24 18:07:26 -07001143bool MDPComp::programYUV(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
1144 if(!allocLayerPipes(ctx, list)) {
1145 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
1146 return false;
1147 }
1148 //If we are in this block, it means we have yuv + rgb layers both
1149 int mdpIdx = 0;
1150 for (int index = 0; index < mCurrentFrame.layerCount; index++) {
1151 if(!mCurrentFrame.isFBComposed[index]) {
1152 hwc_layer_1_t* layer = &list->hwLayers[index];
1153 int mdpIndex = mCurrentFrame.layerToMDP[index];
1154 MdpPipeInfo* cur_pipe =
1155 mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1156 cur_pipe->zOrder = mdpIdx++;
1157
radhakrishnac9a67412013-09-25 17:40:42 +05301158 private_handle_t *hnd = (private_handle_t *)layer->handle;
1159 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1160 if(configure4k2kYuv(ctx, layer,
1161 mCurrentFrame.mdpToLayer[mdpIndex])
1162 != 0 ){
1163 ALOGD_IF(isDebug(), "%s: Failed to configure split pipes \
1164 for layer %d",__FUNCTION__, index);
1165 return false;
1166 }
1167 else{
1168 mdpIdx++;
1169 }
1170 continue;
1171 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001172 if(configure(ctx, layer,
1173 mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
1174 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
1175 layer %d",__FUNCTION__, index);
1176 return false;
1177 }
1178 }
1179 }
1180 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001181}
1182
Saurabh Shah173f4242013-11-20 09:50:12 -08001183bool MDPComp::resourceCheck(hwc_context_t *ctx,
1184 hwc_display_contents_1_t *list) {
1185 const bool fbUsed = mCurrentFrame.fbCount;
1186 if(mCurrentFrame.mdpCount > sMaxPipesPerMixer - fbUsed) {
1187 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
1188 return false;
1189 }
1190
1191 if(!arePipesAvailable(ctx, list)) {
1192 return false;
1193 }
1194
1195 uint32_t size = calcMDPBytesRead(ctx, list);
1196 if(!bandwidthCheck(ctx, size)) {
1197 ALOGD_IF(isDebug(), "%s: Exceeds bandwidth",__FUNCTION__);
1198 return false;
1199 }
1200
1201 return true;
1202}
1203
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001204uint32_t MDPComp::calcMDPBytesRead(hwc_context_t *ctx,
1205 hwc_display_contents_1_t* list) {
1206 uint32_t size = 0;
1207
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001208 if(!qdutils::MDPVersion::getInstance().is8x74v2())
1209 return 0;
1210
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001211 for (uint32_t i = 0; i < list->numHwLayers - 1; i++) {
1212 if(!mCurrentFrame.isFBComposed[i]) {
1213 hwc_layer_1_t* layer = &list->hwLayers[i];
1214 private_handle_t *hnd = (private_handle_t *)layer->handle;
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001215 if (hnd) {
Saurabh Shah62e1d732013-09-17 10:44:05 -07001216 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah90789162013-09-16 10:29:20 -07001217 hwc_rect_t dst = layer->displayFrame;
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001218 float bpp = ((float)hnd->size) / (hnd->width * hnd->height);
Saurabh Shah90789162013-09-16 10:29:20 -07001219 size += bpp * (crop.right - crop.left) *
1220 (crop.bottom - crop.top) *
1221 ctx->dpyAttr[mDpy].yres / (dst.bottom - dst.top);
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001222 }
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001223 }
1224 }
1225
1226 if(mCurrentFrame.fbCount) {
1227 hwc_layer_1_t* layer = &list->hwLayers[list->numHwLayers - 1];
1228 private_handle_t *hnd = (private_handle_t *)layer->handle;
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001229 if (hnd)
1230 size += hnd->size;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001231 }
1232
1233 return size;
1234}
1235
1236bool MDPComp::bandwidthCheck(hwc_context_t *ctx, const uint32_t& size) {
1237 //Will be added for other targets if we run into bandwidth issues and when
1238 //we have profiling data to set an upper limit.
1239 if(qdutils::MDPVersion::getInstance().is8x74v2()) {
Saurabh Shah3c1a6b02013-11-22 11:10:20 -08001240 const uint32_t ONE_GIG = 1000 * 1000 * 1000;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001241 double panelRefRate =
1242 1000000000.0 / ctx->dpyAttr[mDpy].vsync_period;
Saurabh Shah3c1a6b02013-11-22 11:10:20 -08001243 if((size * panelRefRate) > ((sMaxBw - sBwClaimed) * ONE_GIG)) {
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001244 return false;
1245 }
1246 }
1247 return true;
1248}
1249
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001250int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001251 int ret = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -07001252 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -07001253
Saurabh Shahb39f8152013-08-22 10:21:44 -07001254 //reset old data
1255 mCurrentFrame.reset(numLayers);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001256 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1257 mCurrentFrame.dropCount = 0;
Prabhanjan Kandula088bd892013-07-02 23:47:13 +05301258
Saurabh Shahb39f8152013-08-22 10:21:44 -07001259 //number of app layers exceeds MAX_NUM_APP_LAYERS fall back to GPU
1260 //do not cache the information for next draw cycle.
1261 if(numLayers > MAX_NUM_APP_LAYERS) {
Prabhanjan Kandula25469a52013-07-12 16:19:31 +05301262 mCachedFrame.updateCounts(mCurrentFrame);
Arpita Banerjeed8965982013-11-08 17:27:33 -08001263 ALOGI("%s: Number of App layers exceeded the limit ",
Tatenda Chipeperekwa835337a2013-09-27 16:58:43 -07001264 __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001265 ret = -1;
Tatenda Chipeperekwa835337a2013-09-27 16:58:43 -07001266 return ret;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001267 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001268
Saurabh Shahb39f8152013-08-22 10:21:44 -07001269 //Hard conditions, if not met, cannot do MDP comp
1270 if(!isFrameDoable(ctx)) {
1271 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
1272 __FUNCTION__);
1273 reset(numLayers, list);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001274 ret = -1;
1275 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001276 }
1277
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001278 generateROI(ctx, list);
1279
Saurabh Shahb39f8152013-08-22 10:21:44 -07001280 //Check whether layers marked for MDP Composition is actually doable.
1281 if(isFullFrameDoable(ctx, list)) {
1282 mCurrentFrame.map();
1283 //Configure framebuffer first if applicable
1284 if(mCurrentFrame.fbZ >= 0) {
radhakrishnac9a67412013-09-25 17:40:42 +05301285 //If 4k2k Yuv layer split is possible, and if
1286 //fbz is above 4k2k layer, increment fb zorder by 1
1287 //as we split 4k2k layer and increment zorder for right half
1288 //of the layer
1289 if(sEnable4k2kYUVSplit){
1290 int n4k2kYuvCount = ctx->listStats[mDpy].yuv4k2kCount;
1291 for(int index = 0; index < n4k2kYuvCount; index++){
1292 int n4k2kYuvIndex =
1293 ctx->listStats[mDpy].yuv4k2kIndices[index];
1294 if(mCurrentFrame.fbZ > n4k2kYuvIndex){
1295 mCurrentFrame.fbZ += 1;
1296 }
1297 }
1298 }
Saurabh Shahb39f8152013-08-22 10:21:44 -07001299 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list,
1300 mCurrentFrame.fbZ)) {
1301 ALOGE("%s configure framebuffer failed", __func__);
1302 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -07001303 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001304 ret = -1;
1305 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001306 }
1307 }
1308 //Acquire and Program MDP pipes
1309 if(!programMDP(ctx, list)) {
1310 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -07001311 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001312 ret = -1;
1313 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001314 } else { //Success
1315 //Any change in composition types needs an FB refresh
1316 mCurrentFrame.needsRedraw = false;
Jeykumar Sankaran988d3682013-11-15 11:57:16 -08001317 if(!mCachedFrame.isSameFrame(mCurrentFrame, list) ||
Saurabh Shahb39f8152013-08-22 10:21:44 -07001318 (list->flags & HWC_GEOMETRY_CHANGED) ||
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +05301319 isSkipPresent(ctx, mDpy)) {
Saurabh Shahb39f8152013-08-22 10:21:44 -07001320 mCurrentFrame.needsRedraw = true;
1321 }
1322 }
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001323 } else if(isOnlyVideoDoable(ctx, list, false /*secure only*/) ||
1324 isOnlyVideoDoable(ctx, list, true /*secure only*/)) {
Saurabh Shahb39f8152013-08-22 10:21:44 -07001325 //All layers marked for MDP comp cannot be bypassed.
1326 //Try to compose atleast YUV layers through MDP comp and let
1327 //all the RGB layers compose in FB
1328 //Destination over
radhakrishnac9a67412013-09-25 17:40:42 +05301329
1330 if(sEnable4k2kYUVSplit){
1331 modifymdpCountfor4k2k(ctx, list);
1332 }
1333
Saurabh Shahb39f8152013-08-22 10:21:44 -07001334 mCurrentFrame.fbZ = -1;
1335 if(mCurrentFrame.fbCount)
1336 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
1337
1338 mCurrentFrame.map();
1339
1340 //Configure framebuffer first if applicable
1341 if(mCurrentFrame.fbZ >= 0) {
1342 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, mCurrentFrame.fbZ)) {
1343 ALOGE("%s configure framebuffer failed", __func__);
1344 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -07001345 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001346 ret = -1;
1347 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001348 }
1349 }
1350 if(!programYUV(ctx, list)) {
1351 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -07001352 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001353 ret = -1;
1354 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001355 }
1356 } else {
1357 reset(numLayers, list);
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -08001358 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1359 mCurrentFrame.dropCount = 0;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001360 ret = -1;
1361 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001362 }
Saurabh Shahb39f8152013-08-22 10:21:44 -07001363 //UpdateLayerFlags
1364 setMDPCompLayerFlags(ctx, list);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001365 mCachedFrame.cacheAll(list);
Saurabh Shahb39f8152013-08-22 10:21:44 -07001366 mCachedFrame.updateCounts(mCurrentFrame);
1367
Prabhanjan Kandula25469a52013-07-12 16:19:31 +05301368 // unlock it before calling dump function to avoid deadlock
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001369 if(isDebug()) {
Saurabh Shahaa236822013-04-24 18:07:26 -07001370 ALOGD("GEOMETRY change: %d", (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001371 android::String8 sDump("");
1372 dump(sDump);
1373 ALOGE("%s",sDump.string());
1374 }
1375
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001376exit:
Saurabh Shah3c1a6b02013-11-22 11:10:20 -08001377 //gbps (bytes / nanosec = gigabytes / sec)
1378 sBwClaimed += calcMDPBytesRead(ctx, list) /
1379 (double)ctx->dpyAttr[mDpy].vsync_period;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001380 return ret;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001381}
1382
radhakrishnac9a67412013-09-25 17:40:42 +05301383bool MDPComp::allocSplitVGPipesfor4k2k(hwc_context_t *ctx,
1384 hwc_display_contents_1_t* list, int index) {
1385
1386 bool bRet = true;
1387 hwc_layer_1_t* layer = &list->hwLayers[index];
1388 private_handle_t *hnd = (private_handle_t *)layer->handle;
1389 int mdpIndex = mCurrentFrame.layerToMDP[index];
1390 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
1391 info.pipeInfo = new MdpYUVPipeInfo;
1392 info.rot = NULL;
1393 MdpYUVPipeInfo& pipe_info = *(MdpYUVPipeInfo*)info.pipeInfo;
1394 ePipeType type = MDPCOMP_OV_VG;
1395
1396 pipe_info.lIndex = ovutils::OV_INVALID;
1397 pipe_info.rIndex = ovutils::OV_INVALID;
1398
1399 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
1400 if(pipe_info.lIndex == ovutils::OV_INVALID){
1401 bRet = false;
1402 ALOGD_IF(isDebug(),"%s: allocating first VG pipe failed",
1403 __FUNCTION__);
1404 }
1405 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
1406 if(pipe_info.rIndex == ovutils::OV_INVALID){
1407 bRet = false;
1408 ALOGD_IF(isDebug(),"%s: allocating second VG pipe failed",
1409 __FUNCTION__);
1410 }
1411 return bRet;
1412}
Saurabh Shah88e4d272013-09-03 13:31:29 -07001413//=============MDPCompNonSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001414
radhakrishnac9a67412013-09-25 17:40:42 +05301415void MDPCompNonSplit::modifymdpCountfor4k2k(hwc_context_t *ctx,
1416 hwc_display_contents_1_t* list){
1417 //As we split 4kx2k yuv layer and program to 2 VG pipes
1418 //(if available) increase mdpcount accordingly
1419 mCurrentFrame.mdpCount += ctx->listStats[mDpy].yuv4k2kCount;
1420}
1421
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001422/*
1423 * Configures pipe(s) for MDP composition
1424 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001425int MDPCompNonSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001426 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001427 MdpPipeInfoNonSplit& mdp_info =
1428 *(static_cast<MdpPipeInfoNonSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001429 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
1430 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1431 eIsFg isFg = IS_FG_OFF;
1432 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001433
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001434 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
1435 __FUNCTION__, layer, zOrder, dest);
1436
Saurabh Shah88e4d272013-09-03 13:31:29 -07001437 return configureNonSplit(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001438 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001439}
1440
Saurabh Shah88e4d272013-09-03 13:31:29 -07001441bool MDPCompNonSplit::arePipesAvailable(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001442 hwc_display_contents_1_t* list) {
1443 overlay::Overlay& ov = *ctx->mOverlay;
1444 int numPipesNeeded = mCurrentFrame.mdpCount;
1445 int availPipes = ov.availablePipes(mDpy, Overlay::MIXER_DEFAULT);
1446
1447 //Reserve pipe for FB
1448 if(mCurrentFrame.fbCount)
1449 availPipes -= 1;
1450
1451 if(numPipesNeeded > availPipes) {
1452 ALOGD_IF(isDebug(), "%s: Insufficient pipes, dpy %d needed %d, avail %d",
1453 __FUNCTION__, mDpy, numPipesNeeded, availPipes);
1454 return false;
1455 }
1456
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001457 if(not areVGPipesAvailable(ctx, list)) {
1458 return false;
1459 }
1460
1461 return true;
1462}
1463
1464bool MDPCompNonSplit::areVGPipesAvailable(hwc_context_t *ctx,
1465 hwc_display_contents_1_t* list) {
1466 overlay::Overlay& ov = *ctx->mOverlay;
1467 int pipesNeeded = 0;
1468 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1469 if(!mCurrentFrame.isFBComposed[i]) {
1470 hwc_layer_1_t* layer = &list->hwLayers[i];
1471 hwc_rect_t dst = layer->displayFrame;
1472 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301473 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1474 pipesNeeded = pipesNeeded + 2;
1475 }
1476 else if(isYuvBuffer(hnd)) {
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001477 pipesNeeded++;
1478 }
1479 }
1480 }
1481
1482 int availableVGPipes = ov.availablePipes(mDpy, ovutils::OV_MDP_PIPE_VG);
1483 if(pipesNeeded > availableVGPipes) {
1484 ALOGD_IF(isDebug(), "%s: Insufficient VG pipes for video layers"
1485 "dpy %d needed %d, avail %d",
1486 __FUNCTION__, mDpy, pipesNeeded, availableVGPipes);
1487 return false;
1488 }
1489
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001490 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001491}
1492
Saurabh Shah88e4d272013-09-03 13:31:29 -07001493bool MDPCompNonSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001494 hwc_display_contents_1_t* list) {
1495 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001496
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001497 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001498
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001499 hwc_layer_1_t* layer = &list->hwLayers[index];
1500 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301501 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1502 if(allocSplitVGPipesfor4k2k(ctx, list, index)){
1503 continue;
1504 }
1505 }
1506
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001507 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001508 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001509 info.pipeInfo = new MdpPipeInfoNonSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08001510 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001511 MdpPipeInfoNonSplit& pipe_info = *(MdpPipeInfoNonSplit*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001512 ePipeType type = MDPCOMP_OV_ANY;
1513
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001514 if(isYuvBuffer(hnd)) {
1515 type = MDPCOMP_OV_VG;
Saurabh Shah8a117932013-05-23 12:48:13 -07001516 } else if(!qhwc::needsScaling(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001517 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
1518 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001519 type = MDPCOMP_OV_DMA;
1520 }
1521
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001522 pipe_info.index = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001523 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001524 ALOGD_IF(isDebug(), "%s: Unable to get pipe type = %d",
1525 __FUNCTION__, (int) type);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001526 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001527 }
1528 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001529 return true;
1530}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001531
radhakrishnac9a67412013-09-25 17:40:42 +05301532int MDPCompNonSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1533 PipeLayerPair& PipeLayerPair) {
1534 MdpYUVPipeInfo& mdp_info =
1535 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1536 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1537 eIsFg isFg = IS_FG_OFF;
1538 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1539 eDest lDest = mdp_info.lIndex;
1540 eDest rDest = mdp_info.rIndex;
1541
1542 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1543 lDest, rDest, &PipeLayerPair.rot);
1544}
1545
Saurabh Shah88e4d272013-09-03 13:31:29 -07001546bool MDPCompNonSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001547
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001548 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001549 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1550 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -08001551 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001552
1553 if(!ctx || !list) {
1554 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001555 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001556 }
1557
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301558 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1559 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1560 return true;
1561 }
1562
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001563 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001564 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001565 idleInvalidator->markForSleep();
1566
1567 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001568 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001569
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001570 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1571 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001572 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001573 if(mCurrentFrame.isFBComposed[i]) continue;
1574
Naseer Ahmed5b6708a2012-08-02 13:46:08 -07001575 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001576 private_handle_t *hnd = (private_handle_t *)layer->handle;
1577 if(!hnd) {
1578 ALOGE("%s handle null", __FUNCTION__);
1579 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001580 }
1581
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001582 int mdpIndex = mCurrentFrame.layerToMDP[i];
1583
radhakrishnac9a67412013-09-25 17:40:42 +05301584 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1585 {
1586 MdpYUVPipeInfo& pipe_info =
1587 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1588 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1589 ovutils::eDest indexL = pipe_info.lIndex;
1590 ovutils::eDest indexR = pipe_info.rIndex;
1591 int fd = hnd->fd;
1592 uint32_t offset = hnd->offset;
1593 if(rot) {
1594 rot->queueBuffer(fd, offset);
1595 fd = rot->getDstMemId();
1596 offset = rot->getDstOffset();
1597 }
1598 if(indexL != ovutils::OV_INVALID) {
1599 ovutils::eDest destL = (ovutils::eDest)indexL;
1600 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1601 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1602 if (!ov.queueBuffer(fd, offset, destL)) {
1603 ALOGE("%s: queueBuffer failed for display:%d",
1604 __FUNCTION__, mDpy);
1605 return false;
1606 }
1607 }
1608
1609 if(indexR != ovutils::OV_INVALID) {
1610 ovutils::eDest destR = (ovutils::eDest)indexR;
1611 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1612 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1613 if (!ov.queueBuffer(fd, offset, destR)) {
1614 ALOGE("%s: queueBuffer failed for display:%d",
1615 __FUNCTION__, mDpy);
1616 return false;
1617 }
1618 }
1619 }
1620 else{
1621 MdpPipeInfoNonSplit& pipe_info =
Saurabh Shah88e4d272013-09-03 13:31:29 -07001622 *(MdpPipeInfoNonSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
radhakrishnac9a67412013-09-25 17:40:42 +05301623 ovutils::eDest dest = pipe_info.index;
1624 if(dest == ovutils::OV_INVALID) {
1625 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001626 return false;
radhakrishnac9a67412013-09-25 17:40:42 +05301627 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001628
radhakrishnac9a67412013-09-25 17:40:42 +05301629 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1630 continue;
1631 }
1632
1633 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1634 using pipe: %d", __FUNCTION__, layer,
1635 hnd, dest );
1636
1637 int fd = hnd->fd;
1638 uint32_t offset = hnd->offset;
1639
1640 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1641 if(rot) {
1642 if(!rot->queueBuffer(fd, offset))
1643 return false;
1644 fd = rot->getDstMemId();
1645 offset = rot->getDstOffset();
1646 }
1647
1648 if (!ov.queueBuffer(fd, offset, dest)) {
1649 ALOGE("%s: queueBuffer failed for display:%d ",
1650 __FUNCTION__, mDpy);
1651 return false;
1652 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001653 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001654
1655 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001656 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001657 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001658}
1659
Saurabh Shah88e4d272013-09-03 13:31:29 -07001660//=============MDPCompSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001661
radhakrishnac9a67412013-09-25 17:40:42 +05301662void MDPCompSplit::modifymdpCountfor4k2k(hwc_context_t *ctx,
1663 hwc_display_contents_1_t* list){
1664 //if 4kx2k yuv layer is totally present in either in left half
1665 //or right half then try splitting the yuv layer to avoid decimation
1666 int n4k2kYuvCount = ctx->listStats[mDpy].yuv4k2kCount;
1667 const int lSplit = getLeftSplit(ctx, mDpy);
1668 for(int index = 0; index < n4k2kYuvCount; index++){
1669 int n4k2kYuvIndex = ctx->listStats[mDpy].yuv4k2kIndices[index];
1670 hwc_layer_1_t* layer = &list->hwLayers[n4k2kYuvIndex];
1671 hwc_rect_t dst = layer->displayFrame;
1672
1673 if((dst.left > lSplit)||(dst.right < lSplit)){
1674 mCurrentFrame.mdpCount += 1;
1675 }
1676 }
1677}
1678
Saurabh Shah88e4d272013-09-03 13:31:29 -07001679int MDPCompSplit::pipesNeeded(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001680 hwc_display_contents_1_t* list,
1681 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001682 int pipesNeeded = 0;
Saurabh Shah67a38c32013-06-10 16:23:15 -07001683 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001684
1685 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001686
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001687 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1688 if(!mCurrentFrame.isFBComposed[i]) {
1689 hwc_layer_1_t* layer = &list->hwLayers[i];
1690 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001691 if(mixer == Overlay::MIXER_LEFT && dst.left < lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001692 pipesNeeded++;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001693 } else if(mixer == Overlay::MIXER_RIGHT && dst.right > lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001694 pipesNeeded++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001695 }
1696 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001697 }
1698 return pipesNeeded;
1699}
1700
Saurabh Shah88e4d272013-09-03 13:31:29 -07001701bool MDPCompSplit::arePipesAvailable(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001702 hwc_display_contents_1_t* list) {
1703 overlay::Overlay& ov = *ctx->mOverlay;
Saurabh Shah082468e2013-09-12 10:05:32 -07001704 int totalPipesNeeded = 0;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001705
1706 for(int i = 0; i < Overlay::MIXER_MAX; i++) {
1707 int numPipesNeeded = pipesNeeded(ctx, list, i);
1708 int availPipes = ov.availablePipes(mDpy, i);
1709
1710 //Reserve pipe(s)for FB
1711 if(mCurrentFrame.fbCount)
Saurabh Shah082468e2013-09-12 10:05:32 -07001712 numPipesNeeded += 1;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001713
Saurabh Shah082468e2013-09-12 10:05:32 -07001714 totalPipesNeeded += numPipesNeeded;
1715
1716 //Per mixer check.
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001717 if(numPipesNeeded > availPipes) {
1718 ALOGD_IF(isDebug(), "%s: Insufficient pipes for "
1719 "dpy %d mixer %d needed %d, avail %d",
1720 __FUNCTION__, mDpy, i, numPipesNeeded, availPipes);
1721 return false;
1722 }
1723 }
Saurabh Shah082468e2013-09-12 10:05:32 -07001724
1725 //Per display check, since unused pipes can get counted twice.
1726 int totalPipesAvailable = ov.availablePipes(mDpy);
1727 if(totalPipesNeeded > totalPipesAvailable) {
1728 ALOGD_IF(isDebug(), "%s: Insufficient pipes for "
1729 "dpy %d needed %d, avail %d",
1730 __FUNCTION__, mDpy, totalPipesNeeded, totalPipesAvailable);
1731 return false;
1732 }
1733
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001734 if(not areVGPipesAvailable(ctx, list)) {
1735 return false;
1736 }
1737
1738 return true;
1739}
1740
1741bool MDPCompSplit::areVGPipesAvailable(hwc_context_t *ctx,
1742 hwc_display_contents_1_t* list) {
1743 overlay::Overlay& ov = *ctx->mOverlay;
1744 int pipesNeeded = 0;
1745 const int lSplit = getLeftSplit(ctx, mDpy);
1746 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1747 if(!mCurrentFrame.isFBComposed[i]) {
1748 hwc_layer_1_t* layer = &list->hwLayers[i];
1749 hwc_rect_t dst = layer->displayFrame;
1750 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301751 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1752 if((dst.left > lSplit)||(dst.right < lSplit)){
1753 pipesNeeded = pipesNeeded + 2;
1754 continue;
1755 }
1756 }
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001757 if(isYuvBuffer(hnd)) {
1758 if(dst.left < lSplit) {
1759 pipesNeeded++;
1760 }
1761 if(dst.right > lSplit) {
1762 pipesNeeded++;
1763 }
1764 }
1765 }
1766 }
1767
1768 int availableVGPipes = ov.availablePipes(mDpy, ovutils::OV_MDP_PIPE_VG);
1769 if(pipesNeeded > availableVGPipes) {
1770 ALOGD_IF(isDebug(), "%s: Insufficient VG pipes for video layers"
1771 "dpy %d needed %d, avail %d",
1772 __FUNCTION__, mDpy, pipesNeeded, availableVGPipes);
1773 return false;
1774 }
1775
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001776 return true;
1777}
1778
Saurabh Shah88e4d272013-09-03 13:31:29 -07001779bool MDPCompSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
1780 MdpPipeInfoSplit& pipe_info,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001781 ePipeType type) {
1782 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001783 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001784
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001785 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001786 pipe_info.lIndex = ovutils::OV_INVALID;
1787 pipe_info.rIndex = ovutils::OV_INVALID;
1788
1789 if (dst.left < lSplit) {
1790 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_LEFT);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001791 if(pipe_info.lIndex == ovutils::OV_INVALID)
1792 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001793 }
1794
1795 if(dst.right > lSplit) {
1796 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_RIGHT);
1797 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001798 return false;
1799 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001800
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001801 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001802}
1803
Saurabh Shah88e4d272013-09-03 13:31:29 -07001804bool MDPCompSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001805 hwc_display_contents_1_t* list) {
1806 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001807
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001808 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001809
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001810 hwc_layer_1_t* layer = &list->hwLayers[index];
1811 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301812 hwc_rect_t dst = layer->displayFrame;
1813 const int lSplit = getLeftSplit(ctx, mDpy);
1814 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1815 if((dst.left > lSplit)||(dst.right < lSplit)){
1816 if(allocSplitVGPipesfor4k2k(ctx, list, index)){
1817 continue;
1818 }
1819 }
1820 }
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001821 int mdpIndex = mCurrentFrame.layerToMDP[index];
1822 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001823 info.pipeInfo = new MdpPipeInfoSplit;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001824 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001825 MdpPipeInfoSplit& pipe_info = *(MdpPipeInfoSplit*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001826 ePipeType type = MDPCOMP_OV_ANY;
1827
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001828 if(isYuvBuffer(hnd)) {
1829 type = MDPCOMP_OV_VG;
Sushil Chauhan15a2ea62013-09-04 18:28:36 -07001830 } else if(!qhwc::needsScalingWithSplit(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001831 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001832 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001833 type = MDPCOMP_OV_DMA;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001834 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001835
1836 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001837 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type = %d",
1838 __FUNCTION__, (int) type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001839 return false;
1840 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001841 }
1842 return true;
1843}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001844
radhakrishnac9a67412013-09-25 17:40:42 +05301845int MDPCompSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1846 PipeLayerPair& PipeLayerPair) {
1847 const int lSplit = getLeftSplit(ctx, mDpy);
1848 hwc_rect_t dst = layer->displayFrame;
1849 if((dst.left > lSplit)||(dst.right < lSplit)){
1850 MdpYUVPipeInfo& mdp_info =
1851 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1852 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1853 eIsFg isFg = IS_FG_OFF;
1854 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1855 eDest lDest = mdp_info.lIndex;
1856 eDest rDest = mdp_info.rIndex;
1857
1858 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1859 lDest, rDest, &PipeLayerPair.rot);
1860 }
1861 else{
1862 return configure(ctx, layer, PipeLayerPair);
1863 }
1864}
1865
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001866/*
1867 * Configures pipe(s) for MDP composition
1868 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001869int MDPCompSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001870 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001871 MdpPipeInfoSplit& mdp_info =
1872 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001873 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1874 eIsFg isFg = IS_FG_OFF;
1875 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1876 eDest lDest = mdp_info.lIndex;
1877 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001878
1879 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1880 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1881
Saurabh Shah88e4d272013-09-03 13:31:29 -07001882 return configureSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001883 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001884}
1885
Saurabh Shah88e4d272013-09-03 13:31:29 -07001886bool MDPCompSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001887
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001888 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001889 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1890 return true;
1891 }
1892
1893 if(!ctx || !list) {
1894 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001895 return false;
1896 }
1897
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301898 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1899 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1900 return true;
1901 }
1902
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001903 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001904 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001905 idleInvalidator->markForSleep();
1906
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001907 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001908 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001909
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001910 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1911 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001912 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001913 if(mCurrentFrame.isFBComposed[i]) continue;
1914
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001915 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001916 private_handle_t *hnd = (private_handle_t *)layer->handle;
1917 if(!hnd) {
1918 ALOGE("%s handle null", __FUNCTION__);
1919 return false;
1920 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001921
1922 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1923 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001924 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001925
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001926 int mdpIndex = mCurrentFrame.layerToMDP[i];
1927
radhakrishnac9a67412013-09-25 17:40:42 +05301928 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1929 {
1930 MdpYUVPipeInfo& pipe_info =
1931 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1932 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1933 ovutils::eDest indexL = pipe_info.lIndex;
1934 ovutils::eDest indexR = pipe_info.rIndex;
1935 int fd = hnd->fd;
1936 uint32_t offset = hnd->offset;
1937 if(rot) {
1938 rot->queueBuffer(fd, offset);
1939 fd = rot->getDstMemId();
1940 offset = rot->getDstOffset();
1941 }
1942 if(indexL != ovutils::OV_INVALID) {
1943 ovutils::eDest destL = (ovutils::eDest)indexL;
1944 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1945 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1946 if (!ov.queueBuffer(fd, offset, destL)) {
1947 ALOGE("%s: queueBuffer failed for display:%d",
1948 __FUNCTION__, mDpy);
1949 return false;
1950 }
1951 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001952
radhakrishnac9a67412013-09-25 17:40:42 +05301953 if(indexR != ovutils::OV_INVALID) {
1954 ovutils::eDest destR = (ovutils::eDest)indexR;
1955 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1956 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1957 if (!ov.queueBuffer(fd, offset, destR)) {
1958 ALOGE("%s: queueBuffer failed for display:%d",
1959 __FUNCTION__, mDpy);
1960 return false;
1961 }
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001962 }
1963 }
radhakrishnac9a67412013-09-25 17:40:42 +05301964 else{
1965 MdpPipeInfoSplit& pipe_info =
1966 *(MdpPipeInfoSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1967 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001968
radhakrishnac9a67412013-09-25 17:40:42 +05301969 ovutils::eDest indexL = pipe_info.lIndex;
1970 ovutils::eDest indexR = pipe_info.rIndex;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001971
radhakrishnac9a67412013-09-25 17:40:42 +05301972 int fd = hnd->fd;
1973 int offset = hnd->offset;
1974
1975 if(ctx->mAD->isModeOn()) {
1976 if(ctx->mAD->draw(ctx, fd, offset)) {
1977 fd = ctx->mAD->getDstFd(ctx);
1978 offset = ctx->mAD->getDstOffset(ctx);
1979 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001980 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001981
radhakrishnac9a67412013-09-25 17:40:42 +05301982 if(rot) {
1983 rot->queueBuffer(fd, offset);
1984 fd = rot->getDstMemId();
1985 offset = rot->getDstOffset();
1986 }
1987
1988 //************* play left mixer **********
1989 if(indexL != ovutils::OV_INVALID) {
1990 ovutils::eDest destL = (ovutils::eDest)indexL;
1991 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1992 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1993 if (!ov.queueBuffer(fd, offset, destL)) {
1994 ALOGE("%s: queueBuffer failed for left mixer",
1995 __FUNCTION__);
1996 return false;
1997 }
1998 }
1999
2000 //************* play right mixer **********
2001 if(indexR != ovutils::OV_INVALID) {
2002 ovutils::eDest destR = (ovutils::eDest)indexR;
2003 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
2004 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
2005 if (!ov.queueBuffer(fd, offset, destR)) {
2006 ALOGE("%s: queueBuffer failed for right mixer",
2007 __FUNCTION__);
2008 return false;
2009 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002010 }
2011 }
Saurabh Shahacf10202013-02-26 10:15:15 -08002012
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002013 layerProp[i].mFlags &= ~HWC_MDPCOMP;
2014 }
Saurabh Shahacf10202013-02-26 10:15:15 -08002015
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002016 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002017}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002018}; //namespace
2019