blob: bc2f86ff473c39f65a1fd1b8b35d2605f2f04188 [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;
47uint32_t MDPComp::sCompBytesClaimed = 0;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070048
Saurabh Shah88e4d272013-09-03 13:31:29 -070049MDPComp* MDPComp::getObject(hwc_context_t *ctx, const int& dpy) {
50 if(isDisplaySplit(ctx, dpy)) {
51 return new MDPCompSplit(dpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080052 }
Saurabh Shah88e4d272013-09-03 13:31:29 -070053 return new MDPCompNonSplit(dpy);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080054}
55
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080056MDPComp::MDPComp(int dpy):mDpy(dpy){};
57
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080058void MDPComp::dump(android::String8& buf)
59{
Jeykumar Sankaran3c6bb042013-08-15 14:01:04 -070060 if(mCurrentFrame.layerCount > MAX_NUM_APP_LAYERS)
61 return;
62
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080063 dumpsys_log(buf,"HWC Map for Dpy: %s \n",
Jeykumar Sankaran27dee262013-08-01 17:09:54 -070064 (mDpy == 0) ? "\"PRIMARY\"" :
65 (mDpy == 1) ? "\"EXTERNAL\"" : "\"VIRTUAL\"");
Saurabh Shahe9bc60f2013-08-29 12:58:06 -070066 dumpsys_log(buf,"CURR_FRAME: layerCount:%2d mdpCount:%2d "
67 "fbCount:%2d \n", mCurrentFrame.layerCount,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080068 mCurrentFrame.mdpCount, mCurrentFrame.fbCount);
69 dumpsys_log(buf,"needsFBRedraw:%3s pipesUsed:%2d MaxPipesPerMixer: %d \n",
70 (mCurrentFrame.needsRedraw? "YES" : "NO"),
71 mCurrentFrame.mdpCount, sMaxPipesPerMixer);
72 dumpsys_log(buf," --------------------------------------------- \n");
73 dumpsys_log(buf," listIdx | cached? | mdpIndex | comptype | Z \n");
74 dumpsys_log(buf," --------------------------------------------- \n");
75 for(int index = 0; index < mCurrentFrame.layerCount; index++ )
76 dumpsys_log(buf," %7d | %7s | %8d | %9s | %2d \n",
77 index,
78 (mCurrentFrame.isFBComposed[index] ? "YES" : "NO"),
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -070079 mCurrentFrame.layerToMDP[index],
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080080 (mCurrentFrame.isFBComposed[index] ?
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -070081 (mCurrentFrame.drop[index] ? "DROP" :
82 (mCurrentFrame.needsRedraw ? "GLES" : "CACHE")) : "MDP"),
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080083 (mCurrentFrame.isFBComposed[index] ? mCurrentFrame.fbZ :
84 mCurrentFrame.mdpToLayer[mCurrentFrame.layerToMDP[index]].pipeInfo->zOrder));
85 dumpsys_log(buf,"\n");
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080086}
87
88bool MDPComp::init(hwc_context_t *ctx) {
89
90 if(!ctx) {
91 ALOGE("%s: Invalid hwc context!!",__FUNCTION__);
92 return false;
93 }
94
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080095 char property[PROPERTY_VALUE_MAX];
96
97 sEnabled = false;
98 if((property_get("persist.hwc.mdpcomp.enable", property, NULL) > 0) &&
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080099 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
100 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800101 sEnabled = true;
102 }
103
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700104 sEnableMixedMode = true;
105 if((property_get("debug.mdpcomp.mixedmode.disable", property, NULL) > 0) &&
106 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
107 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
108 sEnableMixedMode = false;
109 }
110
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800111 if(property_get("debug.mdpcomp.logs", property, NULL) > 0) {
112 if(atoi(property) != 0)
113 sDebugLogs = true;
114 }
115
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700116 if(property_get("persist.hwc.partialupdate.enable", property, NULL) > 0) {
117 if((atoi(property) != 0) && ctx->mMDP.panel == MIPI_CMD_PANEL &&
118 qdutils::MDPVersion::getInstance().is8x74v2())
119 sEnablePartialFrameUpdate = true;
120 }
121 ALOGE_IF(isDebug(), "%s: Partial Update applicable?: %d",__FUNCTION__,
122 sEnablePartialFrameUpdate);
123
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800124 sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
Saurabh Shah85234ec2013-04-12 17:09:00 -0700125 if(property_get("debug.mdpcomp.maxpermixer", property, "-1") > 0) {
126 int val = atoi(property);
127 if(val >= 0)
128 sMaxPipesPerMixer = min(val, MAX_PIPES_PER_MIXER);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800129 }
130
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700131 if(property_get("debug.mdpcomp.bw", property, "0") > 0) {
132 float val = atof(property);
133 if(val > 0.0f) {
134 sMaxBw = val;
135 }
136 }
137
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400138 if(ctx->mMDP.panel != MIPI_CMD_PANEL) {
139 // Idle invalidation is not necessary on command mode panels
140 long idle_timeout = DEFAULT_IDLE_TIME;
141 if(property_get("debug.mdpcomp.idletime", property, NULL) > 0) {
142 if(atoi(property) != 0)
143 idle_timeout = atoi(property);
144 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800145
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400146 //create Idle Invalidator only when not disabled through property
147 if(idle_timeout != -1)
148 idleInvalidator = IdleInvalidator::getInstance();
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800149
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400150 if(idleInvalidator == NULL) {
151 ALOGE("%s: failed to instantiate idleInvalidator object",
152 __FUNCTION__);
153 } else {
154 idleInvalidator->init(timeout_handler, ctx, idle_timeout);
155 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800156 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700157 return true;
158}
159
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700160void MDPComp::reset(const int& numLayers, hwc_display_contents_1_t* list) {
161 mCurrentFrame.reset(numLayers);
162 mCachedFrame.cacheAll(list);
163 mCachedFrame.updateCounts(mCurrentFrame);
164}
165
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700166void MDPComp::timeout_handler(void *udata) {
167 struct hwc_context_t* ctx = (struct hwc_context_t*)(udata);
168
169 if(!ctx) {
170 ALOGE("%s: received empty data in timer callback", __FUNCTION__);
171 return;
172 }
173
Jesse Hall3be78d92012-08-21 15:12:23 -0700174 if(!ctx->proc) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700175 ALOGE("%s: HWC proc not registered", __FUNCTION__);
176 return;
177 }
178 sIdleFallBack = true;
179 /* Trigger SF to redraw the current frame */
Jesse Hall3be78d92012-08-21 15:12:23 -0700180 ctx->proc->invalidate(ctx->proc);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700181}
182
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800183void MDPComp::setMDPCompLayerFlags(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800184 hwc_display_contents_1_t* list) {
185 LayerProp *layerProp = ctx->layerProp[mDpy];
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800186
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800187 for(int index = 0; index < ctx->listStats[mDpy].numAppLayers; index++) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800188 hwc_layer_1_t* layer = &(list->hwLayers[index]);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800189 if(!mCurrentFrame.isFBComposed[index]) {
190 layerProp[index].mFlags |= HWC_MDPCOMP;
191 layer->compositionType = HWC_OVERLAY;
192 layer->hints |= HWC_HINT_CLEAR_FB;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800193 } else {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700194 /* Drop the layer when its already present in FB OR when it lies
195 * outside frame's ROI */
196 if(!mCurrentFrame.needsRedraw || mCurrentFrame.drop[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800197 layer->compositionType = HWC_OVERLAY;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700198 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800199 }
200 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700201}
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500202
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800203MDPComp::FrameInfo::FrameInfo() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700204 reset(0);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800205}
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800206
Saurabh Shahaa236822013-04-24 18:07:26 -0700207void MDPComp::FrameInfo::reset(const int& numLayers) {
208 for(int i = 0 ; i < MAX_PIPES_PER_MIXER && numLayers; i++ ) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800209 if(mdpToLayer[i].pipeInfo) {
210 delete mdpToLayer[i].pipeInfo;
211 mdpToLayer[i].pipeInfo = NULL;
212 //We dont own the rotator
213 mdpToLayer[i].rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800214 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800215 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800216
217 memset(&mdpToLayer, 0, sizeof(mdpToLayer));
218 memset(&layerToMDP, -1, sizeof(layerToMDP));
Saurabh Shahaa236822013-04-24 18:07:26 -0700219 memset(&isFBComposed, 1, sizeof(isFBComposed));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800220
Saurabh Shahaa236822013-04-24 18:07:26 -0700221 layerCount = numLayers;
222 fbCount = numLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800223 mdpCount = 0;
Saurabh Shah2f3895f2013-05-02 10:13:31 -0700224 needsRedraw = true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800225 fbZ = 0;
226}
227
Saurabh Shahaa236822013-04-24 18:07:26 -0700228void MDPComp::FrameInfo::map() {
229 // populate layer and MDP maps
230 int mdpIdx = 0;
231 for(int idx = 0; idx < layerCount; idx++) {
232 if(!isFBComposed[idx]) {
233 mdpToLayer[mdpIdx].listIndex = idx;
234 layerToMDP[idx] = mdpIdx++;
235 }
236 }
237}
238
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800239MDPComp::LayerCache::LayerCache() {
240 reset();
241}
242
243void MDPComp::LayerCache::reset() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700244 memset(&hnd, 0, sizeof(hnd));
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530245 memset(&isFBComposed, true, sizeof(isFBComposed));
246 memset(&drop, false, sizeof(drop));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800247 layerCount = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -0700248}
249
250void MDPComp::LayerCache::cacheAll(hwc_display_contents_1_t* list) {
251 const int numAppLayers = list->numHwLayers - 1;
252 for(int i = 0; i < numAppLayers; i++) {
253 hnd[i] = list->hwLayers[i].handle;
254 }
255}
256
257void MDPComp::LayerCache::updateCounts(const FrameInfo& curFrame) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700258 layerCount = curFrame.layerCount;
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530259 memcpy(&isFBComposed, &curFrame.isFBComposed, sizeof(isFBComposed));
260 memcpy(&drop, &curFrame.drop, sizeof(drop));
261}
262
263bool MDPComp::LayerCache::isSameFrame(const FrameInfo& curFrame) {
264 if(layerCount != curFrame.layerCount)
265 return false;
266 for(int i = 0; i < curFrame.layerCount; i++) {
267 if((curFrame.isFBComposed[i] != isFBComposed[i]) ||
268 (curFrame.drop[i] != drop[i])) {
269 return false;
270 }
271 }
272 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800273}
274
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700275bool MDPComp::isSupportedForMDPComp(hwc_context_t *ctx, hwc_layer_1_t* layer) {
276 private_handle_t *hnd = (private_handle_t *)layer->handle;
277 if((not isYuvBuffer(hnd) and has90Transform(layer)) or
278 (not isValidDimension(ctx,layer))
279 //More conditions here, SKIP, sRGB+Blend etc
280 ) {
281 return false;
282 }
283 return true;
284}
285
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530286bool MDPComp::isValidDimension(hwc_context_t *ctx, hwc_layer_1_t *layer) {
Saurabh Shah4fdde762013-04-30 18:47:33 -0700287 const int dpy = HWC_DISPLAY_PRIMARY;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800288 private_handle_t *hnd = (private_handle_t *)layer->handle;
289
290 if(!hnd) {
291 ALOGE("%s: layer handle is NULL", __FUNCTION__);
292 return false;
293 }
294
Naseer Ahmede850a802013-09-06 13:12:52 -0400295 //XXX: Investigate doing this with pixel phase on MDSS
Naseer Ahmede77f8082013-10-10 13:42:48 -0400296 if(!isSecureBuffer(hnd) && isNonIntegralSourceCrop(layer->sourceCropf))
Naseer Ahmede850a802013-09-06 13:12:52 -0400297 return false;
298
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800299 int hw_w = ctx->dpyAttr[mDpy].xres;
300 int hw_h = ctx->dpyAttr[mDpy].yres;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800301
Saurabh Shah62e1d732013-09-17 10:44:05 -0700302 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700303 hwc_rect_t dst = layer->displayFrame;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800304
305 if(dst.left < 0 || dst.top < 0 || dst.right > hw_w || dst.bottom > hw_h) {
Saurabh Shah4fdde762013-04-30 18:47:33 -0700306 hwc_rect_t scissor = {0, 0, hw_w, hw_h };
307 qhwc::calculate_crop_rects(crop, dst, scissor, layer->transform);
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800308 }
309
Saurabh Shah4fdde762013-04-30 18:47:33 -0700310 int crop_w = crop.right - crop.left;
311 int crop_h = crop.bottom - crop.top;
312 int dst_w = dst.right - dst.left;
313 int dst_h = dst.bottom - dst.top;
314 float w_dscale = ceilf((float)crop_w / (float)dst_w);
315 float h_dscale = ceilf((float)crop_h / (float)dst_h);
316
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800317 /* Workaround for MDP HW limitation in DSI command mode panels where
318 * FPS will not go beyond 30 if buffers on RGB pipes are of width or height
319 * less than 5 pixels
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530320 * There also is a HW limilation in MDP, minimum block size is 2x2
321 * Fallback to GPU if height is less than 2.
322 */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800323 if((crop_w < 5)||(crop_h < 5))
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800324 return false;
325
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800326 if((w_dscale > 1.0f) || (h_dscale > 1.0f)) {
327 const uint32_t downscale =
Saurabh Shah4fdde762013-04-30 18:47:33 -0700328 qdutils::MDPVersion::getInstance().getMaxMDPDownscale();
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800329 if(ctx->mMDP.version >= qdutils::MDSS_V5) {
330 /* Workaround for downscales larger than 4x.
331 * Will be removed once decimator block is enabled for MDSS
332 */
333 if(!qdutils::MDPVersion::getInstance().supportsDecimation()) {
334 if(crop_w > MAX_DISPLAY_DIM || w_dscale > downscale ||
335 h_dscale > downscale)
336 return false;
337 } else {
338 if(w_dscale > 64 || h_dscale > 64)
339 return false;
340 }
341 } else { //A-family
342 if(w_dscale > downscale || h_dscale > downscale)
Saurabh Shah4fdde762013-04-30 18:47:33 -0700343 return false;
344 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700345 }
346
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800347 return true;
348}
349
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700350ovutils::eDest MDPComp::getMdpPipe(hwc_context_t *ctx, ePipeType type,
351 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800352 overlay::Overlay& ov = *ctx->mOverlay;
353 ovutils::eDest mdp_pipe = ovutils::OV_INVALID;
354
355 switch(type) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800356 case MDPCOMP_OV_DMA:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700357 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_DMA, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800358 if(mdp_pipe != ovutils::OV_INVALID) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800359 return mdp_pipe;
360 }
361 case MDPCOMP_OV_ANY:
362 case MDPCOMP_OV_RGB:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700363 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800364 if(mdp_pipe != ovutils::OV_INVALID) {
365 return mdp_pipe;
366 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800367
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800368 if(type == MDPCOMP_OV_RGB) {
369 //Requested only for RGB pipe
370 break;
371 }
372 case MDPCOMP_OV_VG:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700373 return ov.nextPipe(ovutils::OV_MDP_PIPE_VG, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800374 default:
375 ALOGE("%s: Invalid pipe type",__FUNCTION__);
376 return ovutils::OV_INVALID;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800377 };
378 return ovutils::OV_INVALID;
379}
380
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800381bool MDPComp::isFrameDoable(hwc_context_t *ctx) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700382 bool ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700383 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800384
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800385 if(!isEnabled()) {
386 ALOGD_IF(isDebug(),"%s: MDP Comp. not enabled.", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700387 ret = false;
Saurabh Shahd4e65852013-06-17 11:33:53 -0700388 } else if(qdutils::MDPVersion::getInstance().is8x26() &&
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700389 ctx->mVideoTransFlag && ctx->mVirtualDisplay->isConnected()) {
Saurabh Shahd4e65852013-06-17 11:33:53 -0700390 //1 Padding round to shift pipes across mixers
391 ALOGD_IF(isDebug(),"%s: MDP Comp. video transition padding round",
392 __FUNCTION__);
393 ret = false;
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700394 } else if(ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isConfiguring ||
395 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isConfiguring) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800396 ALOGD_IF( isDebug(),"%s: External Display connection is pending",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800397 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700398 ret = false;
Saurabh Shahaa236822013-04-24 18:07:26 -0700399 } else if(ctx->isPaddingRound) {
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700400 ctx->isPaddingRound = false;
401 ALOGD_IF(isDebug(), "%s: padding round",__FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700402 ret = false;
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700403 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700404 return ret;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800405}
406
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700407bool MDPComp::validateAndApplyROI(hwc_context_t *ctx,
408 hwc_display_contents_1_t* list, hwc_rect_t roi) {
409 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
410
411 if(!isValidRect(roi))
412 return false;
413
414 for(int i = 0; i < numAppLayers; i++){
415 const hwc_layer_1_t* layer = &list->hwLayers[i];
416
417 hwc_rect_t dstRect = layer->displayFrame;
Arun Kumar K.R91090c72013-10-28 19:40:18 -0700418 hwc_rect_t srcRect = integerizeSourceCrop(layer->sourceCropf);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700419 int transform = layer->transform;
420 trimLayer(ctx, mDpy, transform, srcRect, dstRect);
421
422 hwc_rect_t res = getIntersection(roi, dstRect);
423
424 int res_w = res.right - res.left;
425 int res_h = res.bottom - res.top;
426 int dst_w = dstRect.right - dstRect.left;
427 int dst_h = dstRect.bottom - dstRect.top;
428
429 if(!isValidRect(res)) {
430 mCurrentFrame.drop[i] = true;
431 mCurrentFrame.dropCount++;
432 }else {
433 /* Reset frame ROI when any layer which needs scaling also needs ROI
434 * cropping */
435 if((res_w != dst_w || res_h != dst_h) &&
436 needsScaling (ctx, layer, mDpy)) {
437 ALOGE("%s: Resetting ROI due to scaling", __FUNCTION__);
438 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
439 mCurrentFrame.dropCount = 0;
440 return false;
441 }
442 }
443 }
444 return true;
445}
446
447void MDPComp::generateROI(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
448 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
449
450 if(!sEnablePartialFrameUpdate) {
451 return;
452 }
453
454 if(mDpy || isDisplaySplit(ctx, mDpy)){
455 ALOGE_IF(isDebug(), "%s: ROI not supported for"
456 "the (1) external / virtual display's (2) dual DSI displays",
457 __FUNCTION__);
458 return;
459 }
460
461 if(list->flags & HWC_GEOMETRY_CHANGED)
462 return;
463
464 struct hwc_rect roi = (struct hwc_rect){0, 0, 0, 0};
465 for(int index = 0; index < numAppLayers; index++ ) {
466 if ((mCachedFrame.hnd[index] != list->hwLayers[index].handle) ||
467 isYuvBuffer((private_handle_t *)list->hwLayers[index].handle)) {
468 hwc_rect_t dstRect = list->hwLayers[index].displayFrame;
Arun Kumar K.R91090c72013-10-28 19:40:18 -0700469 hwc_rect_t srcRect = integerizeSourceCrop(
470 list->hwLayers[index].sourceCropf);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700471 int transform = list->hwLayers[index].transform;
472
473 /* Intersect against display boundaries */
474 trimLayer(ctx, mDpy, transform, srcRect, dstRect);
475 roi = getUnion(roi, dstRect);
476 }
477 }
478
479 if(!validateAndApplyROI(ctx, list, roi)){
480 roi = (struct hwc_rect) {0, 0,
481 (int)ctx->dpyAttr[mDpy].xres, (int)ctx->dpyAttr[mDpy].yres};
482 }
483
484 ctx->listStats[mDpy].roi.x = roi.left;
485 ctx->listStats[mDpy].roi.y = roi.top;
486 ctx->listStats[mDpy].roi.w = roi.right - roi.left;
487 ctx->listStats[mDpy].roi.h = roi.bottom - roi.top;
488
489 ALOGD_IF(isDebug(),"%s: generated ROI: [%d, %d, %d, %d]", __FUNCTION__,
490 roi.left, roi.top, roi.right, roi.bottom);
491}
492
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800493/* Checks for conditions where all the layers marked for MDP comp cannot be
494 * bypassed. On such conditions we try to bypass atleast YUV layers */
495bool MDPComp::isFullFrameDoable(hwc_context_t *ctx,
496 hwc_display_contents_1_t* list){
497
Saurabh Shahaa236822013-04-24 18:07:26 -0700498 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800499
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -0700500 if(sIdleFallBack && !ctx->listStats[mDpy].secureUI) {
Saurabh Shah2d998a92013-05-14 17:55:58 -0700501 ALOGD_IF(isDebug(), "%s: Idle fallback dpy %d",__FUNCTION__, mDpy);
502 return false;
503 }
504
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800505 if(isSkipPresent(ctx, mDpy)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700506 ALOGD_IF(isDebug(),"%s: SKIP present: %d",
507 __FUNCTION__,
508 isSkipPresent(ctx, mDpy));
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800509 return false;
510 }
511
Saurabh Shah9f084ad2013-05-02 11:28:09 -0700512 if(ctx->listStats[mDpy].needsAlphaScale
513 && ctx->mMDP.version < qdutils::MDSS_V5) {
514 ALOGD_IF(isDebug(), "%s: frame needs alpha downscaling",__FUNCTION__);
515 return false;
516 }
517
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800518 for(int i = 0; i < numAppLayers; ++i) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800519 hwc_layer_1_t* layer = &list->hwLayers[i];
520 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800521
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700522 if(isYuvBuffer(hnd) && has90Transform(layer)) {
523 if(!canUseRotator(ctx, mDpy)) {
524 ALOGD_IF(isDebug(), "%s: Can't use rotator for dpy %d",
525 __FUNCTION__, mDpy);
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700526 return false;
527 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800528 }
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530529
530 //For 8x26 with panel width>1k, if RGB layer needs HFLIP fail mdp comp
531 // may not need it if Gfx pre-rotation can handle all flips & rotations
532 if(qdutils::MDPVersion::getInstance().is8x26() &&
533 (ctx->dpyAttr[mDpy].xres > 1024) &&
534 (layer->transform & HWC_TRANSFORM_FLIP_H) &&
535 (!isYuvBuffer(hnd)))
536 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800537 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700538
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700539 if(ctx->mAD->isDoable()) {
540 return false;
541 }
542
Saurabh Shahaa236822013-04-24 18:07:26 -0700543 //If all above hard conditions are met we can do full or partial MDP comp.
544 bool ret = false;
545 if(fullMDPComp(ctx, list)) {
546 ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700547 } else if(partialMDPComp(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700548 ret = true;
549 }
550 return ret;
551}
552
553bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700554 //Will benefit presentation / secondary-only layer.
555 if((mDpy > HWC_DISPLAY_PRIMARY) &&
556 (list->numHwLayers - 1) > MAX_SEC_LAYERS) {
557 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
558 return false;
559 }
560
561 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
562 for(int i = 0; i < numAppLayers; i++) {
563 hwc_layer_1_t* layer = &list->hwLayers[i];
564 if(not isSupportedForMDPComp(ctx, layer)) {
565 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",__FUNCTION__);
566 return false;
567 }
568 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700569 mCurrentFrame.fbCount = 0;
570 mCurrentFrame.fbZ = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700571 memcpy(&mCurrentFrame.isFBComposed, &mCurrentFrame.drop,
572 sizeof(mCurrentFrame.isFBComposed));
573 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount -
574 mCurrentFrame.dropCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700575
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700576 if(mCurrentFrame.mdpCount > sMaxPipesPerMixer) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700577 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
578 return false;
579 }
580
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700581 if(!arePipesAvailable(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700582 return false;
583 }
584
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700585 uint32_t size = calcMDPBytesRead(ctx, list);
586 if(!bandwidthCheck(ctx, size)) {
587 ALOGD_IF(isDebug(), "%s: Exceeds bandwidth",__FUNCTION__);
588 return false;
589 }
590
Saurabh Shahaa236822013-04-24 18:07:26 -0700591 return true;
592}
593
594bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
595{
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700596 if(!sEnableMixedMode) {
597 //Mixed mode is disabled. No need to even try caching.
598 return false;
599 }
600
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700601 bool ret = false;
602 if(isLoadBasedCompDoable(ctx, list)) {
603 ret = loadBasedComp(ctx, list);
604 }
605
606 if(!ret) {
607 ret = cacheBasedComp(ctx, list);
608 }
609
610 return ret;
611}
612
613bool MDPComp::cacheBasedComp(hwc_context_t *ctx,
614 hwc_display_contents_1_t* list) {
615 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700616 mCurrentFrame.reset(numAppLayers);
617 updateLayerCache(ctx, list);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700618
619 //If an MDP marked layer is unsupported cannot do partial MDP Comp
620 for(int i = 0; i < numAppLayers; i++) {
621 if(!mCurrentFrame.isFBComposed[i]) {
622 hwc_layer_1_t* layer = &list->hwLayers[i];
623 if(not isSupportedForMDPComp(ctx, layer)) {
624 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",
625 __FUNCTION__);
626 return false;
627 }
628 }
629 }
630
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700631 updateYUV(ctx, list, false /*secure only*/);
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530632 bool ret = markLayersForCaching(ctx, list); //sets up fbZ also
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700633 if(!ret) {
634 ALOGD_IF(isDebug(),"%s: batching failed, dpy %d",__FUNCTION__, mDpy);
635 return false;
636 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700637
638 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700639
640 //Will benefit cases where a video has non-updating background.
641 if((mDpy > HWC_DISPLAY_PRIMARY) and
642 (mdpCount > MAX_SEC_LAYERS)) {
643 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
644 return false;
645 }
646
Saurabh Shahaa236822013-04-24 18:07:26 -0700647 if(mdpCount > (sMaxPipesPerMixer - 1)) { // -1 since FB is used
648 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
649 return false;
650 }
651
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700652 if(!arePipesAvailable(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700653 return false;
654 }
655
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700656 uint32_t size = calcMDPBytesRead(ctx, list);
657 if(!bandwidthCheck(ctx, size)) {
658 ALOGD_IF(isDebug(), "%s: Exceeds bandwidth",__FUNCTION__);
659 return false;
660 }
661
Saurabh Shahaa236822013-04-24 18:07:26 -0700662 return true;
663}
664
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700665bool MDPComp::loadBasedComp(hwc_context_t *ctx,
666 hwc_display_contents_1_t* list) {
667 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
668 mCurrentFrame.reset(numAppLayers);
669
670 //TODO BatchSize could be optimized further based on available pipes, split
671 //displays etc.
672 const int batchSize = numAppLayers - (sMaxPipesPerMixer - 1);
673 if(batchSize <= 0) {
674 ALOGD_IF(isDebug(), "%s: Not attempting", __FUNCTION__);
675 return false;
676 }
677
678 int minBatchStart = -1;
679 size_t minBatchPixelCount = SIZE_MAX;
680
681 for(int i = 0; i <= numAppLayers - batchSize; i++) {
682 uint32_t batchPixelCount = 0;
683 for(int j = i; j < i + batchSize; j++) {
684 hwc_layer_1_t* layer = &list->hwLayers[j];
Arun Kumar K.R91090c72013-10-28 19:40:18 -0700685 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700686 batchPixelCount += (crop.right - crop.left) *
687 (crop.bottom - crop.top);
688 }
689
690 if(batchPixelCount < minBatchPixelCount) {
691 minBatchPixelCount = batchPixelCount;
692 minBatchStart = i;
693 }
694 }
695
696 if(minBatchStart < 0) {
697 ALOGD_IF(isDebug(), "%s: No batch found batchSize %d numAppLayers %d",
698 __FUNCTION__, batchSize, numAppLayers);
699 return false;
700 }
701
702 for(int i = 0; i < numAppLayers; i++) {
703 if(i < minBatchStart || i >= minBatchStart + batchSize) {
704 hwc_layer_1_t* layer = &list->hwLayers[i];
705 if(not isSupportedForMDPComp(ctx, layer)) {
706 ALOGD_IF(isDebug(), "%s: MDP unsupported layer found at %d",
707 __FUNCTION__, i);
708 return false;
709 }
710 mCurrentFrame.isFBComposed[i] = false;
711 }
712 }
713
714 mCurrentFrame.fbZ = minBatchStart;
715 mCurrentFrame.fbCount = batchSize;
716 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - batchSize;
717
718 if(!arePipesAvailable(ctx, list)) {
719 return false;
720 }
721
722 ALOGD_IF(isDebug(), "%s: fbZ %d batchSize %d",
723 __FUNCTION__, mCurrentFrame.fbZ, batchSize);
724 return true;
725}
726
727bool MDPComp::isLoadBasedCompDoable(hwc_context_t *ctx,
728 hwc_display_contents_1_t* list) {
729 if(mDpy or isSecurePresent(ctx, mDpy) or
730 not (list->flags & HWC_GEOMETRY_CHANGED)) {
731 return false;
732 }
733 return true;
734}
735
Saurabh Shahaa236822013-04-24 18:07:26 -0700736bool MDPComp::isOnlyVideoDoable(hwc_context_t *ctx,
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700737 hwc_display_contents_1_t* list, bool secureOnly) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700738 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700739
Saurabh Shahaa236822013-04-24 18:07:26 -0700740 mCurrentFrame.reset(numAppLayers);
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700741 updateYUV(ctx, list, secureOnly);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700742 int mdpCount = mCurrentFrame.mdpCount;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700743 int fbNeeded = (mCurrentFrame.fbCount != 0);
Saurabh Shahaa236822013-04-24 18:07:26 -0700744
745 if(!isYuvPresent(ctx, mDpy)) {
746 return false;
747 }
748
Saurabh Shah4fdde762013-04-30 18:47:33 -0700749 if(!mdpCount)
750 return false;
751
Saurabh Shahaa236822013-04-24 18:07:26 -0700752 if(mdpCount > (sMaxPipesPerMixer - fbNeeded)) {
753 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
754 return false;
755 }
756
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700757 if(!arePipesAvailable(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700758 return false;
759 }
760
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700761 uint32_t size = calcMDPBytesRead(ctx, list);
762 if(!bandwidthCheck(ctx, size)) {
763 ALOGD_IF(isDebug(), "%s: Exceeds bandwidth",__FUNCTION__);
764 return false;
765 }
766
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800767 return true;
768}
769
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800770/* Checks for conditions where YUV layers cannot be bypassed */
771bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Saurabh Shahe2474082013-05-15 16:32:13 -0700772 bool extAnimBlockFeature = mDpy && ctx->listStats[mDpy].isDisplayAnimating;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800773
Saurabh Shahe2474082013-05-15 16:32:13 -0700774 if(isSkipLayer(layer) && !extAnimBlockFeature) {
775 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800776 return false;
777 }
778
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700779 if(layer->transform & HWC_TRANSFORM_ROT_90 && !canUseRotator(ctx,mDpy)) {
780 ALOGD_IF(isDebug(), "%s: no free DMA pipe",__FUNCTION__);
781 return false;
782 }
783
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800784 if(isSecuring(ctx, layer)) {
785 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
786 return false;
787 }
788
Saurabh Shah4fdde762013-04-30 18:47:33 -0700789 if(!isValidDimension(ctx, layer)) {
790 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
791 __FUNCTION__);
792 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800793 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700794
Naseer Ahmeddc61a972013-07-10 17:50:54 -0400795 if(layer->planeAlpha < 0xFF) {
796 ALOGD_IF(isDebug(), "%s: Cannot handle YUV layer with plane alpha\
797 in video only mode",
798 __FUNCTION__);
799 return false;
800 }
801
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800802 return true;
803}
804
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530805/* starts at fromIndex and check for each layer to find
806 * if it it has overlapping with any Updating layer above it in zorder
807 * till the end of the batch. returns true if it finds any intersection */
808bool MDPComp::canPushBatchToTop(const hwc_display_contents_1_t* list,
809 int fromIndex, int toIndex) {
810 for(int i = fromIndex; i < toIndex; i++) {
811 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
812 if(intersectingUpdatingLayers(list, i+1, toIndex, i)) {
813 return false;
814 }
815 }
816 }
817 return true;
818}
819
820/* Checks if given layer at targetLayerIndex has any
821 * intersection with all the updating layers in beween
822 * fromIndex and toIndex. Returns true if it finds intersectiion */
823bool MDPComp::intersectingUpdatingLayers(const hwc_display_contents_1_t* list,
824 int fromIndex, int toIndex, int targetLayerIndex) {
825 for(int i = fromIndex; i <= toIndex; i++) {
826 if(!mCurrentFrame.isFBComposed[i]) {
827 if(areLayersIntersecting(&list->hwLayers[i],
828 &list->hwLayers[targetLayerIndex])) {
829 return true;
830 }
831 }
832 }
833 return false;
834}
835
836int MDPComp::getBatch(hwc_display_contents_1_t* list,
837 int& maxBatchStart, int& maxBatchEnd,
838 int& maxBatchCount) {
839 int i = 0;
840 int updatingLayersAbove = 0;//Updating layer count in middle of batch
841 int fbZOrder =-1;
842 while (i < mCurrentFrame.layerCount) {
843 int batchCount = 0;
844 int batchStart = i;
845 int batchEnd = i;
846 int fbZ = batchStart;
847 int firstZReverseIndex = -1;
848 while(i < mCurrentFrame.layerCount) {
849 if(!mCurrentFrame.isFBComposed[i]) {
850 if(!batchCount) {
851 i++;
852 break;
853 }
854 updatingLayersAbove++;
855 i++;
856 continue;
857 } else {
858 if(mCurrentFrame.drop[i]) {
859 i++;
860 continue;
861 } else if(updatingLayersAbove <= 0) {
862 batchCount++;
863 batchEnd = i;
864 i++;
865 continue;
866 } else { //Layer is FBComposed, not a drop & updatingLayer > 0
867
868 // We have a valid updating layer already. If layer-i not
869 // have overlapping with all updating layers in between
870 // batch-start and i, then we can add layer i to batch.
871 if(!intersectingUpdatingLayers(list, batchStart, i-1, i)) {
872 batchCount++;
873 batchEnd = i;
874 i++;
875 continue;
876 } else if(canPushBatchToTop(list, batchStart, i)) {
877 //If All the non-updating layers with in this batch
878 //does not have intersection with the updating layers
879 //above in z-order, then we can safely move the batch to
880 //higher z-order. Increment fbZ as it is moving up.
881 if( firstZReverseIndex < 0) {
882 firstZReverseIndex = i;
883 }
884 batchCount++;
885 batchEnd = i;
886 fbZ += updatingLayersAbove;
887 i++;
888 updatingLayersAbove = 0;
889 continue;
890 } else {
891 //both failed.start the loop again from here.
892 if(firstZReverseIndex >= 0) {
893 i = firstZReverseIndex;
894 }
895 break;
896 }
897 }
898 }
899 }
900 if(batchCount > maxBatchCount) {
901 maxBatchCount = batchCount;
902 maxBatchStart = batchStart;
903 maxBatchEnd = batchEnd;
904 fbZOrder = fbZ;
905 }
906 }
907 return fbZOrder;
908}
909
910bool MDPComp::markLayersForCaching(hwc_context_t* ctx,
911 hwc_display_contents_1_t* list) {
912 /* Idea is to keep as many non-updating(cached) layers in FB and
913 * send rest of them through MDP. This is done in 2 steps.
914 * 1. Find the maximum contiguous batch of non-updating layers.
915 * 2. See if we can improve this batch size for caching by adding
916 * opaque layers around the batch, if they don't have
917 * any overlapping with the updating layers in between.
918 * NEVER mark an updating layer for caching.
919 * But cached ones can be marked for MDP */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800920
921 int maxBatchStart = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700922 int maxBatchEnd = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800923 int maxBatchCount = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530924 int fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800925
926 /* All or Nothing is cached. No batching needed */
Saurabh Shahaa236822013-04-24 18:07:26 -0700927 if(!mCurrentFrame.fbCount) {
928 mCurrentFrame.fbZ = -1;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700929 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -0700930 }
931 if(!mCurrentFrame.mdpCount) {
932 mCurrentFrame.fbZ = 0;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700933 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -0700934 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800935
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530936 fbZ = getBatch(list, maxBatchStart, maxBatchEnd, maxBatchCount);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800937
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530938 /* reset rest of the layers lying inside ROI for MDP comp */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800939 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700940 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700941 if((i < maxBatchStart || i > maxBatchEnd) &&
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530942 mCurrentFrame.isFBComposed[i]){
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700943 if(!mCurrentFrame.drop[i]){
944 //If an unsupported layer is being attempted to
945 //be pulled out we should fail
946 if(not isSupportedForMDPComp(ctx, layer)) {
947 return false;
948 }
949 mCurrentFrame.isFBComposed[i] = false;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700950 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800951 }
952 }
953
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530954 // update the frame data
955 mCurrentFrame.fbZ = fbZ;
956 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700957 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700958 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800959
960 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530961 mCurrentFrame.fbCount);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700962
963 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800964}
Saurabh Shah85234ec2013-04-12 17:09:00 -0700965
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800966void MDPComp::updateLayerCache(hwc_context_t* ctx,
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700967 hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800968 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700969 int fbCount = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800970
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800971 for(int i = 0; i < numAppLayers; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700972 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800973 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700974 if(!mCurrentFrame.drop[i])
975 fbCount++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800976 mCurrentFrame.isFBComposed[i] = true;
977 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -0700978 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800979 mCachedFrame.hnd[i] = list->hwLayers[i].handle;
980 }
981 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700982
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700983 mCurrentFrame.fbCount = fbCount;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700984 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount
985 - mCurrentFrame.dropCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700986
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700987 ALOGD_IF(isDebug(),"%s: MDP count: %d FB count %d drop count: %d"
988 ,__FUNCTION__, mCurrentFrame.mdpCount, mCurrentFrame.fbCount,
989 mCurrentFrame.dropCount);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800990}
991
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700992void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list,
993 bool secureOnly) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800994 int nYuvCount = ctx->listStats[mDpy].yuvCount;
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700995 if(!nYuvCount && mDpy) {
996 //Reset "No animation on external display" related parameters.
997 ctx->mPrevCropVideo.left = ctx->mPrevCropVideo.top =
998 ctx->mPrevCropVideo.right = ctx->mPrevCropVideo.bottom = 0;
999 ctx->mPrevDestVideo.left = ctx->mPrevDestVideo.top =
1000 ctx->mPrevDestVideo.right = ctx->mPrevDestVideo.bottom = 0;
1001 ctx->mPrevTransformVideo = 0;
1002 return;
1003 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001004 for(int index = 0;index < nYuvCount; index++){
1005 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
1006 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
1007
1008 if(!isYUVDoable(ctx, layer)) {
1009 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
1010 mCurrentFrame.isFBComposed[nYuvIndex] = true;
1011 mCurrentFrame.fbCount++;
1012 }
1013 } else {
1014 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001015 private_handle_t *hnd = (private_handle_t *)layer->handle;
1016 if(!secureOnly || isSecureBuffer(hnd)) {
1017 mCurrentFrame.isFBComposed[nYuvIndex] = false;
1018 mCurrentFrame.fbCount--;
1019 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001020 }
1021 }
1022 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001023
1024 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001025 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
1026 ALOGD_IF(isDebug(),"%s: fb count: %d",__FUNCTION__,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001027 mCurrentFrame.fbCount);
1028}
1029
Saurabh Shahaa236822013-04-24 18:07:26 -07001030bool MDPComp::programMDP(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001031 if(!allocLayerPipes(ctx, list)) {
1032 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -07001033 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001034 }
1035
1036 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001037 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001038 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001039 int mdpIndex = mCurrentFrame.layerToMDP[index];
1040 hwc_layer_1_t* layer = &list->hwLayers[index];
1041
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301042 //Leave fbZ for framebuffer. CACHE/GLES layers go here.
1043 if(mdpNextZOrder == mCurrentFrame.fbZ) {
1044 mdpNextZOrder++;
1045 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001046 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1047 cur_pipe->zOrder = mdpNextZOrder++;
1048
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301049
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001050 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
1051 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
1052 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -07001053 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001054 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001055 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001056 }
1057
Saurabh Shahaa236822013-04-24 18:07:26 -07001058 return true;
1059}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001060
Saurabh Shahaa236822013-04-24 18:07:26 -07001061bool MDPComp::programYUV(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
1062 if(!allocLayerPipes(ctx, list)) {
1063 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
1064 return false;
1065 }
1066 //If we are in this block, it means we have yuv + rgb layers both
1067 int mdpIdx = 0;
1068 for (int index = 0; index < mCurrentFrame.layerCount; index++) {
1069 if(!mCurrentFrame.isFBComposed[index]) {
1070 hwc_layer_1_t* layer = &list->hwLayers[index];
1071 int mdpIndex = mCurrentFrame.layerToMDP[index];
1072 MdpPipeInfo* cur_pipe =
1073 mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1074 cur_pipe->zOrder = mdpIdx++;
1075
1076 if(configure(ctx, layer,
1077 mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
1078 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
1079 layer %d",__FUNCTION__, index);
1080 return false;
1081 }
1082 }
1083 }
1084 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001085}
1086
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001087uint32_t MDPComp::calcMDPBytesRead(hwc_context_t *ctx,
1088 hwc_display_contents_1_t* list) {
1089 uint32_t size = 0;
1090
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001091 if(!qdutils::MDPVersion::getInstance().is8x74v2())
1092 return 0;
1093
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001094 for (uint32_t i = 0; i < list->numHwLayers - 1; i++) {
1095 if(!mCurrentFrame.isFBComposed[i]) {
1096 hwc_layer_1_t* layer = &list->hwLayers[i];
1097 private_handle_t *hnd = (private_handle_t *)layer->handle;
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001098 if (hnd) {
Saurabh Shah62e1d732013-09-17 10:44:05 -07001099 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah90789162013-09-16 10:29:20 -07001100 hwc_rect_t dst = layer->displayFrame;
1101 trimLayer(ctx, mDpy, layer->transform, crop, dst);
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001102 float bpp = ((float)hnd->size) / (hnd->width * hnd->height);
Saurabh Shah90789162013-09-16 10:29:20 -07001103 size += bpp * (crop.right - crop.left) *
1104 (crop.bottom - crop.top) *
1105 ctx->dpyAttr[mDpy].yres / (dst.bottom - dst.top);
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001106 }
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001107 }
1108 }
1109
1110 if(mCurrentFrame.fbCount) {
1111 hwc_layer_1_t* layer = &list->hwLayers[list->numHwLayers - 1];
1112 private_handle_t *hnd = (private_handle_t *)layer->handle;
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001113 if (hnd)
1114 size += hnd->size;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001115 }
1116
1117 return size;
1118}
1119
1120bool MDPComp::bandwidthCheck(hwc_context_t *ctx, const uint32_t& size) {
1121 //Will be added for other targets if we run into bandwidth issues and when
1122 //we have profiling data to set an upper limit.
1123 if(qdutils::MDPVersion::getInstance().is8x74v2()) {
1124 const uint32_t ONE_GIG = 1024 * 1024 * 1024;
1125 double panelRefRate =
1126 1000000000.0 / ctx->dpyAttr[mDpy].vsync_period;
1127 if((size + sCompBytesClaimed) > ((sMaxBw / panelRefRate) * ONE_GIG)) {
1128 return false;
1129 }
1130 }
1131 return true;
1132}
1133
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001134int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001135 int ret = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -07001136 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -07001137
Saurabh Shahb39f8152013-08-22 10:21:44 -07001138 //reset old data
1139 mCurrentFrame.reset(numLayers);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001140 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1141 mCurrentFrame.dropCount = 0;
Prabhanjan Kandula088bd892013-07-02 23:47:13 +05301142
Saurabh Shahb39f8152013-08-22 10:21:44 -07001143 //number of app layers exceeds MAX_NUM_APP_LAYERS fall back to GPU
1144 //do not cache the information for next draw cycle.
1145 if(numLayers > MAX_NUM_APP_LAYERS) {
Prabhanjan Kandula25469a52013-07-12 16:19:31 +05301146 mCachedFrame.updateCounts(mCurrentFrame);
Tatenda Chipeperekwa835337a2013-09-27 16:58:43 -07001147 ALOGE("%s: Number of App layers exceeded the limit ",
1148 __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001149 ret = -1;
Tatenda Chipeperekwa835337a2013-09-27 16:58:43 -07001150 return ret;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001151 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001152
Saurabh Shahb39f8152013-08-22 10:21:44 -07001153 //Hard conditions, if not met, cannot do MDP comp
1154 if(!isFrameDoable(ctx)) {
1155 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
1156 __FUNCTION__);
1157 reset(numLayers, list);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001158 ret = -1;
1159 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001160 }
1161
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001162 generateROI(ctx, list);
1163
Saurabh Shahb39f8152013-08-22 10:21:44 -07001164 //Check whether layers marked for MDP Composition is actually doable.
1165 if(isFullFrameDoable(ctx, list)) {
1166 mCurrentFrame.map();
1167 //Configure framebuffer first if applicable
1168 if(mCurrentFrame.fbZ >= 0) {
1169 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list,
1170 mCurrentFrame.fbZ)) {
1171 ALOGE("%s configure framebuffer failed", __func__);
1172 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -07001173 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001174 ret = -1;
1175 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001176 }
1177 }
1178 //Acquire and Program MDP pipes
1179 if(!programMDP(ctx, list)) {
1180 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -07001181 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001182 ret = -1;
1183 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001184 } else { //Success
1185 //Any change in composition types needs an FB refresh
1186 mCurrentFrame.needsRedraw = false;
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +05301187 if(!mCachedFrame.isSameFrame(mCurrentFrame) ||
Saurabh Shahb39f8152013-08-22 10:21:44 -07001188 (list->flags & HWC_GEOMETRY_CHANGED) ||
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +05301189 isSkipPresent(ctx, mDpy)) {
Saurabh Shahb39f8152013-08-22 10:21:44 -07001190 mCurrentFrame.needsRedraw = true;
1191 }
1192 }
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001193 } else if(isOnlyVideoDoable(ctx, list, false /*secure only*/) ||
1194 isOnlyVideoDoable(ctx, list, true /*secure only*/)) {
Saurabh Shahb39f8152013-08-22 10:21:44 -07001195 //All layers marked for MDP comp cannot be bypassed.
1196 //Try to compose atleast YUV layers through MDP comp and let
1197 //all the RGB layers compose in FB
1198 //Destination over
1199 mCurrentFrame.fbZ = -1;
1200 if(mCurrentFrame.fbCount)
1201 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
1202
1203 mCurrentFrame.map();
1204
1205 //Configure framebuffer first if applicable
1206 if(mCurrentFrame.fbZ >= 0) {
1207 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, mCurrentFrame.fbZ)) {
1208 ALOGE("%s configure framebuffer failed", __func__);
1209 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -07001210 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001211 ret = -1;
1212 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001213 }
1214 }
1215 if(!programYUV(ctx, list)) {
1216 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -07001217 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001218 ret = -1;
1219 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001220 }
1221 } else {
1222 reset(numLayers, list);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001223 ret = -1;
1224 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001225 }
1226
1227 //UpdateLayerFlags
1228 setMDPCompLayerFlags(ctx, list);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001229 mCachedFrame.cacheAll(list);
Saurabh Shahb39f8152013-08-22 10:21:44 -07001230 mCachedFrame.updateCounts(mCurrentFrame);
1231
Prabhanjan Kandula25469a52013-07-12 16:19:31 +05301232 // unlock it before calling dump function to avoid deadlock
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001233 if(isDebug()) {
Saurabh Shahaa236822013-04-24 18:07:26 -07001234 ALOGD("GEOMETRY change: %d", (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001235 android::String8 sDump("");
1236 dump(sDump);
1237 ALOGE("%s",sDump.string());
1238 }
1239
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001240exit:
1241 sCompBytesClaimed += calcMDPBytesRead(ctx, list);
1242 return ret;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001243}
1244
Saurabh Shah88e4d272013-09-03 13:31:29 -07001245//=============MDPCompNonSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001246
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001247/*
1248 * Configures pipe(s) for MDP composition
1249 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001250int MDPCompNonSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001251 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001252 MdpPipeInfoNonSplit& mdp_info =
1253 *(static_cast<MdpPipeInfoNonSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001254 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
1255 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1256 eIsFg isFg = IS_FG_OFF;
1257 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001258
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001259 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
1260 __FUNCTION__, layer, zOrder, dest);
1261
Saurabh Shah88e4d272013-09-03 13:31:29 -07001262 return configureNonSplit(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001263 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001264}
1265
Saurabh Shah88e4d272013-09-03 13:31:29 -07001266bool MDPCompNonSplit::arePipesAvailable(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001267 hwc_display_contents_1_t* list) {
1268 overlay::Overlay& ov = *ctx->mOverlay;
1269 int numPipesNeeded = mCurrentFrame.mdpCount;
1270 int availPipes = ov.availablePipes(mDpy, Overlay::MIXER_DEFAULT);
1271
1272 //Reserve pipe for FB
1273 if(mCurrentFrame.fbCount)
1274 availPipes -= 1;
1275
1276 if(numPipesNeeded > availPipes) {
1277 ALOGD_IF(isDebug(), "%s: Insufficient pipes, dpy %d needed %d, avail %d",
1278 __FUNCTION__, mDpy, numPipesNeeded, availPipes);
1279 return false;
1280 }
1281
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001282 if(not areVGPipesAvailable(ctx, list)) {
1283 return false;
1284 }
1285
1286 return true;
1287}
1288
1289bool MDPCompNonSplit::areVGPipesAvailable(hwc_context_t *ctx,
1290 hwc_display_contents_1_t* list) {
1291 overlay::Overlay& ov = *ctx->mOverlay;
1292 int pipesNeeded = 0;
1293 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1294 if(!mCurrentFrame.isFBComposed[i]) {
1295 hwc_layer_1_t* layer = &list->hwLayers[i];
1296 hwc_rect_t dst = layer->displayFrame;
1297 private_handle_t *hnd = (private_handle_t *)layer->handle;
1298 if(isYuvBuffer(hnd)) {
1299 pipesNeeded++;
1300 }
1301 }
1302 }
1303
1304 int availableVGPipes = ov.availablePipes(mDpy, ovutils::OV_MDP_PIPE_VG);
1305 if(pipesNeeded > availableVGPipes) {
1306 ALOGD_IF(isDebug(), "%s: Insufficient VG pipes for video layers"
1307 "dpy %d needed %d, avail %d",
1308 __FUNCTION__, mDpy, pipesNeeded, availableVGPipes);
1309 return false;
1310 }
1311
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001312 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001313}
1314
Saurabh Shah88e4d272013-09-03 13:31:29 -07001315bool MDPCompNonSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001316 hwc_display_contents_1_t* list) {
1317 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001318
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001319 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001320
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001321 hwc_layer_1_t* layer = &list->hwLayers[index];
1322 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001323 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001324 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001325 info.pipeInfo = new MdpPipeInfoNonSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08001326 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001327 MdpPipeInfoNonSplit& pipe_info = *(MdpPipeInfoNonSplit*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001328 ePipeType type = MDPCOMP_OV_ANY;
1329
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001330 if(isYuvBuffer(hnd)) {
1331 type = MDPCOMP_OV_VG;
Saurabh Shah8a117932013-05-23 12:48:13 -07001332 } else if(!qhwc::needsScaling(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001333 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
1334 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001335 type = MDPCOMP_OV_DMA;
1336 }
1337
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001338 pipe_info.index = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001339 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001340 ALOGD_IF(isDebug(), "%s: Unable to get pipe type = %d",
1341 __FUNCTION__, (int) type);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001342 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001343 }
1344 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001345 return true;
1346}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001347
Saurabh Shah88e4d272013-09-03 13:31:29 -07001348bool MDPCompNonSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001349
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001350 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001351 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1352 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -08001353 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001354
1355 if(!ctx || !list) {
1356 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001357 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001358 }
1359
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301360 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1361 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1362 return true;
1363 }
1364
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001365 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001366 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001367 idleInvalidator->markForSleep();
1368
1369 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001370 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001371
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001372 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1373 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001374 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001375 if(mCurrentFrame.isFBComposed[i]) continue;
1376
Naseer Ahmed5b6708a2012-08-02 13:46:08 -07001377 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001378 private_handle_t *hnd = (private_handle_t *)layer->handle;
1379 if(!hnd) {
1380 ALOGE("%s handle null", __FUNCTION__);
1381 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001382 }
1383
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001384 int mdpIndex = mCurrentFrame.layerToMDP[i];
1385
Saurabh Shah88e4d272013-09-03 13:31:29 -07001386 MdpPipeInfoNonSplit& pipe_info =
1387 *(MdpPipeInfoNonSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001388 ovutils::eDest dest = pipe_info.index;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001389 if(dest == ovutils::OV_INVALID) {
1390 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001391 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001392 }
1393
Saurabh Shahacf10202013-02-26 10:15:15 -08001394 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1395 continue;
1396 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001397
Saurabh Shahacf10202013-02-26 10:15:15 -08001398 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001399 using pipe: %d", __FUNCTION__, layer,
1400 hnd, dest );
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001401
Saurabh Shahacf10202013-02-26 10:15:15 -08001402 int fd = hnd->fd;
1403 uint32_t offset = hnd->offset;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001404
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001405 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -08001406 if(rot) {
1407 if(!rot->queueBuffer(fd, offset))
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001408 return false;
Saurabh Shahacf10202013-02-26 10:15:15 -08001409 fd = rot->getDstMemId();
1410 offset = rot->getDstOffset();
1411 }
1412
1413 if (!ov.queueBuffer(fd, offset, dest)) {
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301414 ALOGE("%s: queueBuffer failed for display:%d ", __FUNCTION__, mDpy);
Saurabh Shahacf10202013-02-26 10:15:15 -08001415 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001416 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001417
1418 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001419 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001420 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001421}
1422
Saurabh Shah88e4d272013-09-03 13:31:29 -07001423//=============MDPCompSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001424
Saurabh Shah88e4d272013-09-03 13:31:29 -07001425int MDPCompSplit::pipesNeeded(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001426 hwc_display_contents_1_t* list,
1427 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001428 int pipesNeeded = 0;
Saurabh Shah67a38c32013-06-10 16:23:15 -07001429 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001430
1431 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001432
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001433 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1434 if(!mCurrentFrame.isFBComposed[i]) {
1435 hwc_layer_1_t* layer = &list->hwLayers[i];
1436 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001437 if(mixer == Overlay::MIXER_LEFT && dst.left < lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001438 pipesNeeded++;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001439 } else if(mixer == Overlay::MIXER_RIGHT && dst.right > lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001440 pipesNeeded++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001441 }
1442 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001443 }
1444 return pipesNeeded;
1445}
1446
Saurabh Shah88e4d272013-09-03 13:31:29 -07001447bool MDPCompSplit::arePipesAvailable(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001448 hwc_display_contents_1_t* list) {
1449 overlay::Overlay& ov = *ctx->mOverlay;
Saurabh Shah082468e2013-09-12 10:05:32 -07001450 int totalPipesNeeded = 0;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001451
1452 for(int i = 0; i < Overlay::MIXER_MAX; i++) {
1453 int numPipesNeeded = pipesNeeded(ctx, list, i);
1454 int availPipes = ov.availablePipes(mDpy, i);
1455
1456 //Reserve pipe(s)for FB
1457 if(mCurrentFrame.fbCount)
Saurabh Shah082468e2013-09-12 10:05:32 -07001458 numPipesNeeded += 1;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001459
Saurabh Shah082468e2013-09-12 10:05:32 -07001460 totalPipesNeeded += numPipesNeeded;
1461
1462 //Per mixer check.
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001463 if(numPipesNeeded > availPipes) {
1464 ALOGD_IF(isDebug(), "%s: Insufficient pipes for "
1465 "dpy %d mixer %d needed %d, avail %d",
1466 __FUNCTION__, mDpy, i, numPipesNeeded, availPipes);
1467 return false;
1468 }
1469 }
Saurabh Shah082468e2013-09-12 10:05:32 -07001470
1471 //Per display check, since unused pipes can get counted twice.
1472 int totalPipesAvailable = ov.availablePipes(mDpy);
1473 if(totalPipesNeeded > totalPipesAvailable) {
1474 ALOGD_IF(isDebug(), "%s: Insufficient pipes for "
1475 "dpy %d needed %d, avail %d",
1476 __FUNCTION__, mDpy, totalPipesNeeded, totalPipesAvailable);
1477 return false;
1478 }
1479
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001480 if(not areVGPipesAvailable(ctx, list)) {
1481 return false;
1482 }
1483
1484 return true;
1485}
1486
1487bool MDPCompSplit::areVGPipesAvailable(hwc_context_t *ctx,
1488 hwc_display_contents_1_t* list) {
1489 overlay::Overlay& ov = *ctx->mOverlay;
1490 int pipesNeeded = 0;
1491 const int lSplit = getLeftSplit(ctx, mDpy);
1492 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1493 if(!mCurrentFrame.isFBComposed[i]) {
1494 hwc_layer_1_t* layer = &list->hwLayers[i];
1495 hwc_rect_t dst = layer->displayFrame;
1496 private_handle_t *hnd = (private_handle_t *)layer->handle;
1497 if(isYuvBuffer(hnd)) {
1498 if(dst.left < lSplit) {
1499 pipesNeeded++;
1500 }
1501 if(dst.right > lSplit) {
1502 pipesNeeded++;
1503 }
1504 }
1505 }
1506 }
1507
1508 int availableVGPipes = ov.availablePipes(mDpy, ovutils::OV_MDP_PIPE_VG);
1509 if(pipesNeeded > availableVGPipes) {
1510 ALOGD_IF(isDebug(), "%s: Insufficient VG pipes for video layers"
1511 "dpy %d needed %d, avail %d",
1512 __FUNCTION__, mDpy, pipesNeeded, availableVGPipes);
1513 return false;
1514 }
1515
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001516 return true;
1517}
1518
Saurabh Shah88e4d272013-09-03 13:31:29 -07001519bool MDPCompSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
1520 MdpPipeInfoSplit& pipe_info,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001521 ePipeType type) {
1522 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001523 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001524
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001525 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001526 pipe_info.lIndex = ovutils::OV_INVALID;
1527 pipe_info.rIndex = ovutils::OV_INVALID;
1528
1529 if (dst.left < lSplit) {
1530 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_LEFT);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001531 if(pipe_info.lIndex == ovutils::OV_INVALID)
1532 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001533 }
1534
1535 if(dst.right > lSplit) {
1536 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_RIGHT);
1537 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001538 return false;
1539 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001540
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001541 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001542}
1543
Saurabh Shah88e4d272013-09-03 13:31:29 -07001544bool MDPCompSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001545 hwc_display_contents_1_t* list) {
1546 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001547
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001548 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001549
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001550 hwc_layer_1_t* layer = &list->hwLayers[index];
1551 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001552 int mdpIndex = mCurrentFrame.layerToMDP[index];
1553 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001554 info.pipeInfo = new MdpPipeInfoSplit;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001555 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001556 MdpPipeInfoSplit& pipe_info = *(MdpPipeInfoSplit*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001557 ePipeType type = MDPCOMP_OV_ANY;
1558
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001559 if(isYuvBuffer(hnd)) {
1560 type = MDPCOMP_OV_VG;
Sushil Chauhan15a2ea62013-09-04 18:28:36 -07001561 } else if(!qhwc::needsScalingWithSplit(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001562 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001563 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001564 type = MDPCOMP_OV_DMA;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001565 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001566
1567 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001568 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type = %d",
1569 __FUNCTION__, (int) type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001570 return false;
1571 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001572 }
1573 return true;
1574}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001575
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001576/*
1577 * Configures pipe(s) for MDP composition
1578 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001579int MDPCompSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001580 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001581 MdpPipeInfoSplit& mdp_info =
1582 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001583 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1584 eIsFg isFg = IS_FG_OFF;
1585 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1586 eDest lDest = mdp_info.lIndex;
1587 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001588
1589 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1590 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1591
Saurabh Shah88e4d272013-09-03 13:31:29 -07001592 return configureSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001593 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001594}
1595
Saurabh Shah88e4d272013-09-03 13:31:29 -07001596bool MDPCompSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001597
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001598 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001599 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1600 return true;
1601 }
1602
1603 if(!ctx || !list) {
1604 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001605 return false;
1606 }
1607
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301608 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1609 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1610 return true;
1611 }
1612
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001613 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001614 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001615 idleInvalidator->markForSleep();
1616
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001617 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001618 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001619
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001620 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1621 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001622 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001623 if(mCurrentFrame.isFBComposed[i]) continue;
1624
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001625 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001626 private_handle_t *hnd = (private_handle_t *)layer->handle;
1627 if(!hnd) {
1628 ALOGE("%s handle null", __FUNCTION__);
1629 return false;
1630 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001631
1632 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1633 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001634 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001635
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001636 int mdpIndex = mCurrentFrame.layerToMDP[i];
1637
Saurabh Shah88e4d272013-09-03 13:31:29 -07001638 MdpPipeInfoSplit& pipe_info =
1639 *(MdpPipeInfoSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001640 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -08001641
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001642 ovutils::eDest indexL = pipe_info.lIndex;
1643 ovutils::eDest indexR = pipe_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001644
Saurabh Shahacf10202013-02-26 10:15:15 -08001645 int fd = hnd->fd;
1646 int offset = hnd->offset;
1647
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001648 if(ctx->mAD->isModeOn()) {
1649 if(ctx->mAD->draw(ctx, fd, offset)) {
1650 fd = ctx->mAD->getDstFd(ctx);
1651 offset = ctx->mAD->getDstOffset(ctx);
1652 }
1653 }
1654
Saurabh Shahacf10202013-02-26 10:15:15 -08001655 if(rot) {
1656 rot->queueBuffer(fd, offset);
1657 fd = rot->getDstMemId();
1658 offset = rot->getDstOffset();
1659 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001660
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001661 //************* play left mixer **********
1662 if(indexL != ovutils::OV_INVALID) {
1663 ovutils::eDest destL = (ovutils::eDest)indexL;
Saurabh Shahacf10202013-02-26 10:15:15 -08001664 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001665 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
Saurabh Shahacf10202013-02-26 10:15:15 -08001666 if (!ov.queueBuffer(fd, offset, destL)) {
1667 ALOGE("%s: queueBuffer failed for left mixer", __FUNCTION__);
1668 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001669 }
1670 }
1671
1672 //************* play right mixer **********
1673 if(indexR != ovutils::OV_INVALID) {
1674 ovutils::eDest destR = (ovutils::eDest)indexR;
Saurabh Shahacf10202013-02-26 10:15:15 -08001675 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001676 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
Saurabh Shahacf10202013-02-26 10:15:15 -08001677 if (!ov.queueBuffer(fd, offset, destR)) {
1678 ALOGE("%s: queueBuffer failed for right mixer", __FUNCTION__);
1679 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001680 }
1681 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001682
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001683 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1684 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001685
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001686 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001687}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001688}; //namespace
1689