blob: a524a78c407c773571fd1ba8f392ed4df961b7b6 [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) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -0700291 if (layer->flags & HWC_COLOR_FILL) {
292 // Color layer
293 return true;
294 }
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800295 ALOGE("%s: layer handle is NULL", __FUNCTION__);
296 return false;
297 }
298
Naseer Ahmede850a802013-09-06 13:12:52 -0400299 //XXX: Investigate doing this with pixel phase on MDSS
Naseer Ahmede77f8082013-10-10 13:42:48 -0400300 if(!isSecureBuffer(hnd) && isNonIntegralSourceCrop(layer->sourceCropf))
Naseer Ahmede850a802013-09-06 13:12:52 -0400301 return false;
302
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800303 int hw_w = ctx->dpyAttr[mDpy].xres;
304 int hw_h = ctx->dpyAttr[mDpy].yres;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800305
Saurabh Shah62e1d732013-09-17 10:44:05 -0700306 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700307 hwc_rect_t dst = layer->displayFrame;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800308
309 if(dst.left < 0 || dst.top < 0 || dst.right > hw_w || dst.bottom > hw_h) {
Saurabh Shah4fdde762013-04-30 18:47:33 -0700310 hwc_rect_t scissor = {0, 0, hw_w, hw_h };
311 qhwc::calculate_crop_rects(crop, dst, scissor, layer->transform);
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800312 }
313
Saurabh Shah4fdde762013-04-30 18:47:33 -0700314 int crop_w = crop.right - crop.left;
315 int crop_h = crop.bottom - crop.top;
316 int dst_w = dst.right - dst.left;
317 int dst_h = dst.bottom - dst.top;
318 float w_dscale = ceilf((float)crop_w / (float)dst_w);
319 float h_dscale = ceilf((float)crop_h / (float)dst_h);
320
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800321 /* Workaround for MDP HW limitation in DSI command mode panels where
322 * FPS will not go beyond 30 if buffers on RGB pipes are of width or height
323 * less than 5 pixels
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530324 * There also is a HW limilation in MDP, minimum block size is 2x2
325 * Fallback to GPU if height is less than 2.
326 */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800327 if((crop_w < 5)||(crop_h < 5))
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800328 return false;
329
Saurabh Shah4fdde762013-04-30 18:47:33 -0700330 const uint32_t downscale =
331 qdutils::MDPVersion::getInstance().getMaxMDPDownscale();
332 if(ctx->mMDP.version >= qdutils::MDSS_V5) {
333 /* Workaround for downscales larger than 4x.
334 * Will be removed once decimator block is enabled for MDSS
335 */
336 if(!qdutils::MDPVersion::getInstance().supportsDecimation()) {
337 if(crop_w > MAX_DISPLAY_DIM || w_dscale > downscale ||
338 h_dscale > downscale)
339 return false;
340 } else {
341 if(w_dscale > 64 || h_dscale > 64)
342 return false;
343 }
344 } else { //A-family
345 if(w_dscale > downscale || h_dscale > downscale)
346 return false;
347 }
348
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800349 return true;
350}
351
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700352ovutils::eDest MDPComp::getMdpPipe(hwc_context_t *ctx, ePipeType type,
353 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800354 overlay::Overlay& ov = *ctx->mOverlay;
355 ovutils::eDest mdp_pipe = ovutils::OV_INVALID;
356
357 switch(type) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800358 case MDPCOMP_OV_DMA:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700359 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_DMA, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800360 if(mdp_pipe != ovutils::OV_INVALID) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800361 return mdp_pipe;
362 }
363 case MDPCOMP_OV_ANY:
364 case MDPCOMP_OV_RGB:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700365 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800366 if(mdp_pipe != ovutils::OV_INVALID) {
367 return mdp_pipe;
368 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800369
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800370 if(type == MDPCOMP_OV_RGB) {
371 //Requested only for RGB pipe
372 break;
373 }
374 case MDPCOMP_OV_VG:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700375 return ov.nextPipe(ovutils::OV_MDP_PIPE_VG, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800376 default:
377 ALOGE("%s: Invalid pipe type",__FUNCTION__);
378 return ovutils::OV_INVALID;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800379 };
380 return ovutils::OV_INVALID;
381}
382
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800383bool MDPComp::isFrameDoable(hwc_context_t *ctx) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700384 bool ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700385 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800386
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800387 if(!isEnabled()) {
388 ALOGD_IF(isDebug(),"%s: MDP Comp. not enabled.", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700389 ret = false;
Saurabh Shahd4e65852013-06-17 11:33:53 -0700390 } else if(qdutils::MDPVersion::getInstance().is8x26() &&
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700391 ctx->mVideoTransFlag && ctx->mVirtualDisplay->isConnected()) {
Saurabh Shahd4e65852013-06-17 11:33:53 -0700392 //1 Padding round to shift pipes across mixers
393 ALOGD_IF(isDebug(),"%s: MDP Comp. video transition padding round",
394 __FUNCTION__);
395 ret = false;
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700396 } else if(ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isConfiguring ||
397 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isConfiguring) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800398 ALOGD_IF( isDebug(),"%s: External Display connection is pending",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800399 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700400 ret = false;
Saurabh Shahaa236822013-04-24 18:07:26 -0700401 } else if(ctx->isPaddingRound) {
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700402 ctx->isPaddingRound = false;
403 ALOGD_IF(isDebug(), "%s: padding round",__FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700404 ret = false;
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700405 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700406 return ret;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800407}
408
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700409bool MDPComp::validateAndApplyROI(hwc_context_t *ctx,
410 hwc_display_contents_1_t* list, hwc_rect_t roi) {
411 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
412
413 if(!isValidRect(roi))
414 return false;
415
416 for(int i = 0; i < numAppLayers; i++){
417 const hwc_layer_1_t* layer = &list->hwLayers[i];
418
419 hwc_rect_t dstRect = layer->displayFrame;
Arun Kumar K.R91090c72013-10-28 19:40:18 -0700420 hwc_rect_t srcRect = integerizeSourceCrop(layer->sourceCropf);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700421 int transform = layer->transform;
422 trimLayer(ctx, mDpy, transform, srcRect, dstRect);
423
424 hwc_rect_t res = getIntersection(roi, dstRect);
425
426 int res_w = res.right - res.left;
427 int res_h = res.bottom - res.top;
428 int dst_w = dstRect.right - dstRect.left;
429 int dst_h = dstRect.bottom - dstRect.top;
430
431 if(!isValidRect(res)) {
432 mCurrentFrame.drop[i] = true;
433 mCurrentFrame.dropCount++;
434 }else {
435 /* Reset frame ROI when any layer which needs scaling also needs ROI
436 * cropping */
437 if((res_w != dst_w || res_h != dst_h) &&
438 needsScaling (ctx, layer, mDpy)) {
439 ALOGE("%s: Resetting ROI due to scaling", __FUNCTION__);
440 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
441 mCurrentFrame.dropCount = 0;
442 return false;
443 }
444 }
445 }
446 return true;
447}
448
449void MDPComp::generateROI(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
450 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
451
452 if(!sEnablePartialFrameUpdate) {
453 return;
454 }
455
456 if(mDpy || isDisplaySplit(ctx, mDpy)){
457 ALOGE_IF(isDebug(), "%s: ROI not supported for"
458 "the (1) external / virtual display's (2) dual DSI displays",
459 __FUNCTION__);
460 return;
461 }
462
463 if(list->flags & HWC_GEOMETRY_CHANGED)
464 return;
465
466 struct hwc_rect roi = (struct hwc_rect){0, 0, 0, 0};
467 for(int index = 0; index < numAppLayers; index++ ) {
468 if ((mCachedFrame.hnd[index] != list->hwLayers[index].handle) ||
469 isYuvBuffer((private_handle_t *)list->hwLayers[index].handle)) {
470 hwc_rect_t dstRect = list->hwLayers[index].displayFrame;
Arun Kumar K.R91090c72013-10-28 19:40:18 -0700471 hwc_rect_t srcRect = integerizeSourceCrop(
472 list->hwLayers[index].sourceCropf);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700473 int transform = list->hwLayers[index].transform;
474
475 /* Intersect against display boundaries */
476 trimLayer(ctx, mDpy, transform, srcRect, dstRect);
477 roi = getUnion(roi, dstRect);
478 }
479 }
480
481 if(!validateAndApplyROI(ctx, list, roi)){
482 roi = (struct hwc_rect) {0, 0,
483 (int)ctx->dpyAttr[mDpy].xres, (int)ctx->dpyAttr[mDpy].yres};
484 }
485
486 ctx->listStats[mDpy].roi.x = roi.left;
487 ctx->listStats[mDpy].roi.y = roi.top;
488 ctx->listStats[mDpy].roi.w = roi.right - roi.left;
489 ctx->listStats[mDpy].roi.h = roi.bottom - roi.top;
490
491 ALOGD_IF(isDebug(),"%s: generated ROI: [%d, %d, %d, %d]", __FUNCTION__,
492 roi.left, roi.top, roi.right, roi.bottom);
493}
494
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800495/* Checks for conditions where all the layers marked for MDP comp cannot be
496 * bypassed. On such conditions we try to bypass atleast YUV layers */
497bool MDPComp::isFullFrameDoable(hwc_context_t *ctx,
498 hwc_display_contents_1_t* list){
499
Saurabh Shahaa236822013-04-24 18:07:26 -0700500 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800501
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -0700502 if(sIdleFallBack && !ctx->listStats[mDpy].secureUI) {
Saurabh Shah2d998a92013-05-14 17:55:58 -0700503 ALOGD_IF(isDebug(), "%s: Idle fallback dpy %d",__FUNCTION__, mDpy);
504 return false;
505 }
506
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800507 if(isSkipPresent(ctx, mDpy)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700508 ALOGD_IF(isDebug(),"%s: SKIP present: %d",
509 __FUNCTION__,
510 isSkipPresent(ctx, mDpy));
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800511 return false;
512 }
513
Saurabh Shah9f084ad2013-05-02 11:28:09 -0700514 if(ctx->listStats[mDpy].needsAlphaScale
515 && ctx->mMDP.version < qdutils::MDSS_V5) {
516 ALOGD_IF(isDebug(), "%s: frame needs alpha downscaling",__FUNCTION__);
517 return false;
518 }
519
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800520 for(int i = 0; i < numAppLayers; ++i) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800521 hwc_layer_1_t* layer = &list->hwLayers[i];
522 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800523
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700524 if(isYuvBuffer(hnd) && has90Transform(layer)) {
525 if(!canUseRotator(ctx, mDpy)) {
526 ALOGD_IF(isDebug(), "%s: Can't use rotator for dpy %d",
527 __FUNCTION__, mDpy);
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700528 return false;
529 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800530 }
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530531
532 //For 8x26 with panel width>1k, if RGB layer needs HFLIP fail mdp comp
533 // may not need it if Gfx pre-rotation can handle all flips & rotations
534 if(qdutils::MDPVersion::getInstance().is8x26() &&
535 (ctx->dpyAttr[mDpy].xres > 1024) &&
536 (layer->transform & HWC_TRANSFORM_FLIP_H) &&
537 (!isYuvBuffer(hnd)))
538 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800539 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700540
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700541 if(ctx->mAD->isDoable()) {
542 return false;
543 }
544
Saurabh Shahaa236822013-04-24 18:07:26 -0700545 //If all above hard conditions are met we can do full or partial MDP comp.
546 bool ret = false;
547 if(fullMDPComp(ctx, list)) {
548 ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700549 } else if(partialMDPComp(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700550 ret = true;
551 }
552 return ret;
553}
554
555bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700556 //Will benefit presentation / secondary-only layer.
557 if((mDpy > HWC_DISPLAY_PRIMARY) &&
558 (list->numHwLayers - 1) > MAX_SEC_LAYERS) {
559 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
560 return false;
561 }
562
563 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
564 for(int i = 0; i < numAppLayers; i++) {
565 hwc_layer_1_t* layer = &list->hwLayers[i];
566 if(not isSupportedForMDPComp(ctx, layer)) {
567 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",__FUNCTION__);
568 return false;
569 }
570 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700571 mCurrentFrame.fbCount = 0;
572 mCurrentFrame.fbZ = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700573 memcpy(&mCurrentFrame.isFBComposed, &mCurrentFrame.drop,
574 sizeof(mCurrentFrame.isFBComposed));
575 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount -
576 mCurrentFrame.dropCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700577
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700578 if(mCurrentFrame.mdpCount > sMaxPipesPerMixer) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700579 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
580 return false;
581 }
582
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700583 if(!arePipesAvailable(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700584 return false;
585 }
586
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700587 uint32_t size = calcMDPBytesRead(ctx, list);
588 if(!bandwidthCheck(ctx, size)) {
589 ALOGD_IF(isDebug(), "%s: Exceeds bandwidth",__FUNCTION__);
590 return false;
591 }
592
Saurabh Shahaa236822013-04-24 18:07:26 -0700593 return true;
594}
595
596bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
597{
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700598 if(!sEnableMixedMode) {
599 //Mixed mode is disabled. No need to even try caching.
600 return false;
601 }
602
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700603 bool ret = false;
604 if(isLoadBasedCompDoable(ctx, list)) {
605 ret = loadBasedComp(ctx, list);
606 }
607
608 if(!ret) {
609 ret = cacheBasedComp(ctx, list);
610 }
611
612 return ret;
613}
614
615bool MDPComp::cacheBasedComp(hwc_context_t *ctx,
616 hwc_display_contents_1_t* list) {
617 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700618 mCurrentFrame.reset(numAppLayers);
619 updateLayerCache(ctx, list);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700620
621 //If an MDP marked layer is unsupported cannot do partial MDP Comp
622 for(int i = 0; i < numAppLayers; i++) {
623 if(!mCurrentFrame.isFBComposed[i]) {
624 hwc_layer_1_t* layer = &list->hwLayers[i];
625 if(not isSupportedForMDPComp(ctx, layer)) {
626 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",
627 __FUNCTION__);
628 return false;
629 }
630 }
631 }
632
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700633 updateYUV(ctx, list, false /*secure only*/);
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530634 bool ret = markLayersForCaching(ctx, list); //sets up fbZ also
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700635 if(!ret) {
636 ALOGD_IF(isDebug(),"%s: batching failed, dpy %d",__FUNCTION__, mDpy);
637 return false;
638 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700639
640 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700641
642 //Will benefit cases where a video has non-updating background.
643 if((mDpy > HWC_DISPLAY_PRIMARY) and
644 (mdpCount > MAX_SEC_LAYERS)) {
645 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
646 return false;
647 }
648
Saurabh Shahaa236822013-04-24 18:07:26 -0700649 if(mdpCount > (sMaxPipesPerMixer - 1)) { // -1 since FB is used
650 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
651 return false;
652 }
653
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700654 if(!arePipesAvailable(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700655 return false;
656 }
657
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700658 uint32_t size = calcMDPBytesRead(ctx, list);
659 if(!bandwidthCheck(ctx, size)) {
660 ALOGD_IF(isDebug(), "%s: Exceeds bandwidth",__FUNCTION__);
661 return false;
662 }
663
Saurabh Shahaa236822013-04-24 18:07:26 -0700664 return true;
665}
666
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700667bool MDPComp::loadBasedComp(hwc_context_t *ctx,
668 hwc_display_contents_1_t* list) {
669 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
670 mCurrentFrame.reset(numAppLayers);
671
672 //TODO BatchSize could be optimized further based on available pipes, split
673 //displays etc.
674 const int batchSize = numAppLayers - (sMaxPipesPerMixer - 1);
675 if(batchSize <= 0) {
676 ALOGD_IF(isDebug(), "%s: Not attempting", __FUNCTION__);
677 return false;
678 }
679
680 int minBatchStart = -1;
681 size_t minBatchPixelCount = SIZE_MAX;
682
683 for(int i = 0; i <= numAppLayers - batchSize; i++) {
684 uint32_t batchPixelCount = 0;
685 for(int j = i; j < i + batchSize; j++) {
686 hwc_layer_1_t* layer = &list->hwLayers[j];
Arun Kumar K.R91090c72013-10-28 19:40:18 -0700687 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700688 batchPixelCount += (crop.right - crop.left) *
689 (crop.bottom - crop.top);
690 }
691
692 if(batchPixelCount < minBatchPixelCount) {
693 minBatchPixelCount = batchPixelCount;
694 minBatchStart = i;
695 }
696 }
697
698 if(minBatchStart < 0) {
699 ALOGD_IF(isDebug(), "%s: No batch found batchSize %d numAppLayers %d",
700 __FUNCTION__, batchSize, numAppLayers);
701 return false;
702 }
703
704 for(int i = 0; i < numAppLayers; i++) {
705 if(i < minBatchStart || i >= minBatchStart + batchSize) {
706 hwc_layer_1_t* layer = &list->hwLayers[i];
707 if(not isSupportedForMDPComp(ctx, layer)) {
708 ALOGD_IF(isDebug(), "%s: MDP unsupported layer found at %d",
709 __FUNCTION__, i);
710 return false;
711 }
712 mCurrentFrame.isFBComposed[i] = false;
713 }
714 }
715
716 mCurrentFrame.fbZ = minBatchStart;
717 mCurrentFrame.fbCount = batchSize;
718 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - batchSize;
719
720 if(!arePipesAvailable(ctx, list)) {
721 return false;
722 }
723
724 ALOGD_IF(isDebug(), "%s: fbZ %d batchSize %d",
725 __FUNCTION__, mCurrentFrame.fbZ, batchSize);
726 return true;
727}
728
729bool MDPComp::isLoadBasedCompDoable(hwc_context_t *ctx,
730 hwc_display_contents_1_t* list) {
731 if(mDpy or isSecurePresent(ctx, mDpy) or
732 not (list->flags & HWC_GEOMETRY_CHANGED)) {
733 return false;
734 }
735 return true;
736}
737
Saurabh Shahaa236822013-04-24 18:07:26 -0700738bool MDPComp::isOnlyVideoDoable(hwc_context_t *ctx,
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700739 hwc_display_contents_1_t* list, bool secureOnly) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700740 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700741
Saurabh Shahaa236822013-04-24 18:07:26 -0700742 mCurrentFrame.reset(numAppLayers);
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700743 updateYUV(ctx, list, secureOnly);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700744 int mdpCount = mCurrentFrame.mdpCount;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700745 int fbNeeded = (mCurrentFrame.fbCount != 0);
Saurabh Shahaa236822013-04-24 18:07:26 -0700746
747 if(!isYuvPresent(ctx, mDpy)) {
748 return false;
749 }
750
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -0800751 /* Bail out if we are processing only secured video layers
752 * and we dont have any */
753 if(!isSecurePresent(ctx, mDpy) && secureOnly){
754 return false;
755 }
756
Saurabh Shah4fdde762013-04-30 18:47:33 -0700757 if(!mdpCount)
758 return false;
759
Saurabh Shahaa236822013-04-24 18:07:26 -0700760 if(mdpCount > (sMaxPipesPerMixer - fbNeeded)) {
761 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
762 return false;
763 }
764
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700765 if(!arePipesAvailable(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700766 return false;
767 }
768
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700769 uint32_t size = calcMDPBytesRead(ctx, list);
770 if(!bandwidthCheck(ctx, size)) {
771 ALOGD_IF(isDebug(), "%s: Exceeds bandwidth",__FUNCTION__);
772 return false;
773 }
774
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800775 return true;
776}
777
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800778/* Checks for conditions where YUV layers cannot be bypassed */
779bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Saurabh Shahe2474082013-05-15 16:32:13 -0700780 bool extAnimBlockFeature = mDpy && ctx->listStats[mDpy].isDisplayAnimating;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800781
Saurabh Shahe2474082013-05-15 16:32:13 -0700782 if(isSkipLayer(layer) && !extAnimBlockFeature) {
783 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800784 return false;
785 }
786
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700787 if(layer->transform & HWC_TRANSFORM_ROT_90 && !canUseRotator(ctx,mDpy)) {
788 ALOGD_IF(isDebug(), "%s: no free DMA pipe",__FUNCTION__);
789 return false;
790 }
791
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800792 if(isSecuring(ctx, layer)) {
793 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
794 return false;
795 }
796
Saurabh Shah4fdde762013-04-30 18:47:33 -0700797 if(!isValidDimension(ctx, layer)) {
798 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
799 __FUNCTION__);
800 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800801 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700802
Naseer Ahmeddc61a972013-07-10 17:50:54 -0400803 if(layer->planeAlpha < 0xFF) {
804 ALOGD_IF(isDebug(), "%s: Cannot handle YUV layer with plane alpha\
805 in video only mode",
806 __FUNCTION__);
807 return false;
808 }
809
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800810 return true;
811}
812
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530813/* starts at fromIndex and check for each layer to find
814 * if it it has overlapping with any Updating layer above it in zorder
815 * till the end of the batch. returns true if it finds any intersection */
816bool MDPComp::canPushBatchToTop(const hwc_display_contents_1_t* list,
817 int fromIndex, int toIndex) {
818 for(int i = fromIndex; i < toIndex; i++) {
819 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
820 if(intersectingUpdatingLayers(list, i+1, toIndex, i)) {
821 return false;
822 }
823 }
824 }
825 return true;
826}
827
828/* Checks if given layer at targetLayerIndex has any
829 * intersection with all the updating layers in beween
830 * fromIndex and toIndex. Returns true if it finds intersectiion */
831bool MDPComp::intersectingUpdatingLayers(const hwc_display_contents_1_t* list,
832 int fromIndex, int toIndex, int targetLayerIndex) {
833 for(int i = fromIndex; i <= toIndex; i++) {
834 if(!mCurrentFrame.isFBComposed[i]) {
835 if(areLayersIntersecting(&list->hwLayers[i],
836 &list->hwLayers[targetLayerIndex])) {
837 return true;
838 }
839 }
840 }
841 return false;
842}
843
844int MDPComp::getBatch(hwc_display_contents_1_t* list,
845 int& maxBatchStart, int& maxBatchEnd,
846 int& maxBatchCount) {
847 int i = 0;
848 int updatingLayersAbove = 0;//Updating layer count in middle of batch
849 int fbZOrder =-1;
850 while (i < mCurrentFrame.layerCount) {
851 int batchCount = 0;
852 int batchStart = i;
853 int batchEnd = i;
854 int fbZ = batchStart;
855 int firstZReverseIndex = -1;
856 while(i < mCurrentFrame.layerCount) {
857 if(!mCurrentFrame.isFBComposed[i]) {
858 if(!batchCount) {
859 i++;
860 break;
861 }
862 updatingLayersAbove++;
863 i++;
864 continue;
865 } else {
866 if(mCurrentFrame.drop[i]) {
867 i++;
868 continue;
869 } else if(updatingLayersAbove <= 0) {
870 batchCount++;
871 batchEnd = i;
872 i++;
873 continue;
874 } else { //Layer is FBComposed, not a drop & updatingLayer > 0
875
876 // We have a valid updating layer already. If layer-i not
877 // have overlapping with all updating layers in between
878 // batch-start and i, then we can add layer i to batch.
879 if(!intersectingUpdatingLayers(list, batchStart, i-1, i)) {
880 batchCount++;
881 batchEnd = i;
882 i++;
883 continue;
884 } else if(canPushBatchToTop(list, batchStart, i)) {
885 //If All the non-updating layers with in this batch
886 //does not have intersection with the updating layers
887 //above in z-order, then we can safely move the batch to
888 //higher z-order. Increment fbZ as it is moving up.
889 if( firstZReverseIndex < 0) {
890 firstZReverseIndex = i;
891 }
892 batchCount++;
893 batchEnd = i;
894 fbZ += updatingLayersAbove;
895 i++;
896 updatingLayersAbove = 0;
897 continue;
898 } else {
899 //both failed.start the loop again from here.
900 if(firstZReverseIndex >= 0) {
901 i = firstZReverseIndex;
902 }
903 break;
904 }
905 }
906 }
907 }
908 if(batchCount > maxBatchCount) {
909 maxBatchCount = batchCount;
910 maxBatchStart = batchStart;
911 maxBatchEnd = batchEnd;
912 fbZOrder = fbZ;
913 }
914 }
915 return fbZOrder;
916}
917
918bool MDPComp::markLayersForCaching(hwc_context_t* ctx,
919 hwc_display_contents_1_t* list) {
920 /* Idea is to keep as many non-updating(cached) layers in FB and
921 * send rest of them through MDP. This is done in 2 steps.
922 * 1. Find the maximum contiguous batch of non-updating layers.
923 * 2. See if we can improve this batch size for caching by adding
924 * opaque layers around the batch, if they don't have
925 * any overlapping with the updating layers in between.
926 * NEVER mark an updating layer for caching.
927 * But cached ones can be marked for MDP */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800928
929 int maxBatchStart = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700930 int maxBatchEnd = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800931 int maxBatchCount = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530932 int fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800933
934 /* All or Nothing is cached. No batching needed */
Saurabh Shahaa236822013-04-24 18:07:26 -0700935 if(!mCurrentFrame.fbCount) {
936 mCurrentFrame.fbZ = -1;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700937 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -0700938 }
939 if(!mCurrentFrame.mdpCount) {
940 mCurrentFrame.fbZ = 0;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700941 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -0700942 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800943
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530944 fbZ = getBatch(list, maxBatchStart, maxBatchEnd, maxBatchCount);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800945
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530946 /* reset rest of the layers lying inside ROI for MDP comp */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800947 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700948 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700949 if((i < maxBatchStart || i > maxBatchEnd) &&
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530950 mCurrentFrame.isFBComposed[i]){
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700951 if(!mCurrentFrame.drop[i]){
952 //If an unsupported layer is being attempted to
953 //be pulled out we should fail
954 if(not isSupportedForMDPComp(ctx, layer)) {
955 return false;
956 }
957 mCurrentFrame.isFBComposed[i] = false;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700958 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800959 }
960 }
961
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530962 // update the frame data
963 mCurrentFrame.fbZ = fbZ;
964 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700965 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700966 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800967
968 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530969 mCurrentFrame.fbCount);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700970
971 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800972}
Saurabh Shah85234ec2013-04-12 17:09:00 -0700973
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800974void MDPComp::updateLayerCache(hwc_context_t* ctx,
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700975 hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800976 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700977 int fbCount = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800978
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800979 for(int i = 0; i < numAppLayers; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700980 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800981 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700982 if(!mCurrentFrame.drop[i])
983 fbCount++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800984 mCurrentFrame.isFBComposed[i] = true;
985 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -0700986 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800987 mCachedFrame.hnd[i] = list->hwLayers[i].handle;
988 }
989 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700990
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700991 mCurrentFrame.fbCount = fbCount;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700992 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount
993 - mCurrentFrame.dropCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700994
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700995 ALOGD_IF(isDebug(),"%s: MDP count: %d FB count %d drop count: %d"
996 ,__FUNCTION__, mCurrentFrame.mdpCount, mCurrentFrame.fbCount,
997 mCurrentFrame.dropCount);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800998}
999
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001000void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list,
1001 bool secureOnly) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001002 int nYuvCount = ctx->listStats[mDpy].yuvCount;
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001003 if(!nYuvCount && mDpy) {
1004 //Reset "No animation on external display" related parameters.
1005 ctx->mPrevCropVideo.left = ctx->mPrevCropVideo.top =
1006 ctx->mPrevCropVideo.right = ctx->mPrevCropVideo.bottom = 0;
1007 ctx->mPrevDestVideo.left = ctx->mPrevDestVideo.top =
1008 ctx->mPrevDestVideo.right = ctx->mPrevDestVideo.bottom = 0;
1009 ctx->mPrevTransformVideo = 0;
1010 return;
1011 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001012 for(int index = 0;index < nYuvCount; index++){
1013 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
1014 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
1015
1016 if(!isYUVDoable(ctx, layer)) {
1017 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
1018 mCurrentFrame.isFBComposed[nYuvIndex] = true;
1019 mCurrentFrame.fbCount++;
1020 }
1021 } else {
1022 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001023 private_handle_t *hnd = (private_handle_t *)layer->handle;
1024 if(!secureOnly || isSecureBuffer(hnd)) {
1025 mCurrentFrame.isFBComposed[nYuvIndex] = false;
1026 mCurrentFrame.fbCount--;
1027 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001028 }
1029 }
1030 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001031
1032 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001033 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
1034 ALOGD_IF(isDebug(),"%s: fb count: %d",__FUNCTION__,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001035 mCurrentFrame.fbCount);
1036}
1037
Saurabh Shahaa236822013-04-24 18:07:26 -07001038bool MDPComp::programMDP(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001039 if(!allocLayerPipes(ctx, list)) {
1040 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -07001041 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001042 }
1043
1044 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001045 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001046 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001047 int mdpIndex = mCurrentFrame.layerToMDP[index];
1048 hwc_layer_1_t* layer = &list->hwLayers[index];
1049
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301050 //Leave fbZ for framebuffer. CACHE/GLES layers go here.
1051 if(mdpNextZOrder == mCurrentFrame.fbZ) {
1052 mdpNextZOrder++;
1053 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001054 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1055 cur_pipe->zOrder = mdpNextZOrder++;
1056
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301057
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001058 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
1059 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
1060 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -07001061 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001062 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001063 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001064 }
1065
Saurabh Shahaa236822013-04-24 18:07:26 -07001066 return true;
1067}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001068
Saurabh Shahaa236822013-04-24 18:07:26 -07001069bool MDPComp::programYUV(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
1070 if(!allocLayerPipes(ctx, list)) {
1071 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
1072 return false;
1073 }
1074 //If we are in this block, it means we have yuv + rgb layers both
1075 int mdpIdx = 0;
1076 for (int index = 0; index < mCurrentFrame.layerCount; index++) {
1077 if(!mCurrentFrame.isFBComposed[index]) {
1078 hwc_layer_1_t* layer = &list->hwLayers[index];
1079 int mdpIndex = mCurrentFrame.layerToMDP[index];
1080 MdpPipeInfo* cur_pipe =
1081 mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1082 cur_pipe->zOrder = mdpIdx++;
1083
1084 if(configure(ctx, layer,
1085 mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
1086 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
1087 layer %d",__FUNCTION__, index);
1088 return false;
1089 }
1090 }
1091 }
1092 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001093}
1094
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001095uint32_t MDPComp::calcMDPBytesRead(hwc_context_t *ctx,
1096 hwc_display_contents_1_t* list) {
1097 uint32_t size = 0;
1098
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001099 if(!qdutils::MDPVersion::getInstance().is8x74v2())
1100 return 0;
1101
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001102 for (uint32_t i = 0; i < list->numHwLayers - 1; i++) {
1103 if(!mCurrentFrame.isFBComposed[i]) {
1104 hwc_layer_1_t* layer = &list->hwLayers[i];
1105 private_handle_t *hnd = (private_handle_t *)layer->handle;
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001106 if (hnd) {
Saurabh Shah62e1d732013-09-17 10:44:05 -07001107 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah90789162013-09-16 10:29:20 -07001108 hwc_rect_t dst = layer->displayFrame;
1109 trimLayer(ctx, mDpy, layer->transform, crop, dst);
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001110 float bpp = ((float)hnd->size) / (hnd->width * hnd->height);
Saurabh Shah90789162013-09-16 10:29:20 -07001111 size += bpp * (crop.right - crop.left) *
1112 (crop.bottom - crop.top) *
1113 ctx->dpyAttr[mDpy].yres / (dst.bottom - dst.top);
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001114 }
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001115 }
1116 }
1117
1118 if(mCurrentFrame.fbCount) {
1119 hwc_layer_1_t* layer = &list->hwLayers[list->numHwLayers - 1];
1120 private_handle_t *hnd = (private_handle_t *)layer->handle;
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001121 if (hnd)
1122 size += hnd->size;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001123 }
1124
1125 return size;
1126}
1127
1128bool MDPComp::bandwidthCheck(hwc_context_t *ctx, const uint32_t& size) {
1129 //Will be added for other targets if we run into bandwidth issues and when
1130 //we have profiling data to set an upper limit.
1131 if(qdutils::MDPVersion::getInstance().is8x74v2()) {
1132 const uint32_t ONE_GIG = 1024 * 1024 * 1024;
1133 double panelRefRate =
1134 1000000000.0 / ctx->dpyAttr[mDpy].vsync_period;
1135 if((size + sCompBytesClaimed) > ((sMaxBw / panelRefRate) * ONE_GIG)) {
1136 return false;
1137 }
1138 }
1139 return true;
1140}
1141
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001142int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001143 int ret = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -07001144 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -07001145
Saurabh Shahb39f8152013-08-22 10:21:44 -07001146 //reset old data
1147 mCurrentFrame.reset(numLayers);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001148 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1149 mCurrentFrame.dropCount = 0;
Prabhanjan Kandula088bd892013-07-02 23:47:13 +05301150
Saurabh Shahb39f8152013-08-22 10:21:44 -07001151 //number of app layers exceeds MAX_NUM_APP_LAYERS fall back to GPU
1152 //do not cache the information for next draw cycle.
1153 if(numLayers > MAX_NUM_APP_LAYERS) {
Prabhanjan Kandula25469a52013-07-12 16:19:31 +05301154 mCachedFrame.updateCounts(mCurrentFrame);
Tatenda Chipeperekwa835337a2013-09-27 16:58:43 -07001155 ALOGE("%s: Number of App layers exceeded the limit ",
1156 __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001157 ret = -1;
Tatenda Chipeperekwa835337a2013-09-27 16:58:43 -07001158 return ret;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001159 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001160
Saurabh Shahb39f8152013-08-22 10:21:44 -07001161 //Hard conditions, if not met, cannot do MDP comp
1162 if(!isFrameDoable(ctx)) {
1163 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
1164 __FUNCTION__);
1165 reset(numLayers, list);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001166 ret = -1;
1167 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001168 }
1169
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001170 generateROI(ctx, list);
1171
Saurabh Shahb39f8152013-08-22 10:21:44 -07001172 //Check whether layers marked for MDP Composition is actually doable.
1173 if(isFullFrameDoable(ctx, list)) {
1174 mCurrentFrame.map();
1175 //Configure framebuffer first if applicable
1176 if(mCurrentFrame.fbZ >= 0) {
1177 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list,
1178 mCurrentFrame.fbZ)) {
1179 ALOGE("%s configure framebuffer failed", __func__);
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 }
1185 }
1186 //Acquire and Program MDP pipes
1187 if(!programMDP(ctx, list)) {
1188 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -07001189 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001190 ret = -1;
1191 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001192 } else { //Success
1193 //Any change in composition types needs an FB refresh
1194 mCurrentFrame.needsRedraw = false;
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +05301195 if(!mCachedFrame.isSameFrame(mCurrentFrame) ||
Saurabh Shahb39f8152013-08-22 10:21:44 -07001196 (list->flags & HWC_GEOMETRY_CHANGED) ||
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +05301197 isSkipPresent(ctx, mDpy)) {
Saurabh Shahb39f8152013-08-22 10:21:44 -07001198 mCurrentFrame.needsRedraw = true;
1199 }
1200 }
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001201 } else if(isOnlyVideoDoable(ctx, list, false /*secure only*/) ||
1202 isOnlyVideoDoable(ctx, list, true /*secure only*/)) {
Saurabh Shahb39f8152013-08-22 10:21:44 -07001203 //All layers marked for MDP comp cannot be bypassed.
1204 //Try to compose atleast YUV layers through MDP comp and let
1205 //all the RGB layers compose in FB
1206 //Destination over
1207 mCurrentFrame.fbZ = -1;
1208 if(mCurrentFrame.fbCount)
1209 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
1210
1211 mCurrentFrame.map();
1212
1213 //Configure framebuffer first if applicable
1214 if(mCurrentFrame.fbZ >= 0) {
1215 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, mCurrentFrame.fbZ)) {
1216 ALOGE("%s configure framebuffer failed", __func__);
1217 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -07001218 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001219 ret = -1;
1220 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001221 }
1222 }
1223 if(!programYUV(ctx, list)) {
1224 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -07001225 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001226 ret = -1;
1227 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001228 }
1229 } else {
1230 reset(numLayers, list);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001231 ret = -1;
1232 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001233 }
1234
1235 //UpdateLayerFlags
1236 setMDPCompLayerFlags(ctx, list);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001237 mCachedFrame.cacheAll(list);
Saurabh Shahb39f8152013-08-22 10:21:44 -07001238 mCachedFrame.updateCounts(mCurrentFrame);
1239
Prabhanjan Kandula25469a52013-07-12 16:19:31 +05301240 // unlock it before calling dump function to avoid deadlock
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001241 if(isDebug()) {
Saurabh Shahaa236822013-04-24 18:07:26 -07001242 ALOGD("GEOMETRY change: %d", (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001243 android::String8 sDump("");
1244 dump(sDump);
1245 ALOGE("%s",sDump.string());
1246 }
1247
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001248exit:
1249 sCompBytesClaimed += calcMDPBytesRead(ctx, list);
1250 return ret;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001251}
1252
Saurabh Shah88e4d272013-09-03 13:31:29 -07001253//=============MDPCompNonSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001254
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001255/*
1256 * Configures pipe(s) for MDP composition
1257 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001258int MDPCompNonSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001259 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001260 MdpPipeInfoNonSplit& mdp_info =
1261 *(static_cast<MdpPipeInfoNonSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001262 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
1263 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1264 eIsFg isFg = IS_FG_OFF;
1265 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001266
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001267 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
1268 __FUNCTION__, layer, zOrder, dest);
1269
Saurabh Shah88e4d272013-09-03 13:31:29 -07001270 return configureNonSplit(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001271 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001272}
1273
Saurabh Shah88e4d272013-09-03 13:31:29 -07001274bool MDPCompNonSplit::arePipesAvailable(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001275 hwc_display_contents_1_t* list) {
1276 overlay::Overlay& ov = *ctx->mOverlay;
1277 int numPipesNeeded = mCurrentFrame.mdpCount;
1278 int availPipes = ov.availablePipes(mDpy, Overlay::MIXER_DEFAULT);
1279
1280 //Reserve pipe for FB
1281 if(mCurrentFrame.fbCount)
1282 availPipes -= 1;
1283
1284 if(numPipesNeeded > availPipes) {
1285 ALOGD_IF(isDebug(), "%s: Insufficient pipes, dpy %d needed %d, avail %d",
1286 __FUNCTION__, mDpy, numPipesNeeded, availPipes);
1287 return false;
1288 }
1289
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001290 if(not areVGPipesAvailable(ctx, list)) {
1291 return false;
1292 }
1293
1294 return true;
1295}
1296
1297bool MDPCompNonSplit::areVGPipesAvailable(hwc_context_t *ctx,
1298 hwc_display_contents_1_t* list) {
1299 overlay::Overlay& ov = *ctx->mOverlay;
1300 int pipesNeeded = 0;
1301 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1302 if(!mCurrentFrame.isFBComposed[i]) {
1303 hwc_layer_1_t* layer = &list->hwLayers[i];
1304 hwc_rect_t dst = layer->displayFrame;
1305 private_handle_t *hnd = (private_handle_t *)layer->handle;
1306 if(isYuvBuffer(hnd)) {
1307 pipesNeeded++;
1308 }
1309 }
1310 }
1311
1312 int availableVGPipes = ov.availablePipes(mDpy, ovutils::OV_MDP_PIPE_VG);
1313 if(pipesNeeded > availableVGPipes) {
1314 ALOGD_IF(isDebug(), "%s: Insufficient VG pipes for video layers"
1315 "dpy %d needed %d, avail %d",
1316 __FUNCTION__, mDpy, pipesNeeded, availableVGPipes);
1317 return false;
1318 }
1319
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001320 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001321}
1322
Saurabh Shah88e4d272013-09-03 13:31:29 -07001323bool MDPCompNonSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001324 hwc_display_contents_1_t* list) {
1325 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001326
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001327 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001328
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001329 hwc_layer_1_t* layer = &list->hwLayers[index];
1330 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001331 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001332 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001333 info.pipeInfo = new MdpPipeInfoNonSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08001334 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001335 MdpPipeInfoNonSplit& pipe_info = *(MdpPipeInfoNonSplit*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001336 ePipeType type = MDPCOMP_OV_ANY;
1337
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001338 if(isYuvBuffer(hnd)) {
1339 type = MDPCOMP_OV_VG;
Saurabh Shah8a117932013-05-23 12:48:13 -07001340 } else if(!qhwc::needsScaling(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001341 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
1342 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001343 type = MDPCOMP_OV_DMA;
1344 }
1345
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001346 pipe_info.index = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001347 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001348 ALOGD_IF(isDebug(), "%s: Unable to get pipe type = %d",
1349 __FUNCTION__, (int) type);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001350 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001351 }
1352 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001353 return true;
1354}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001355
Saurabh Shah88e4d272013-09-03 13:31:29 -07001356bool MDPCompNonSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001357
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001358 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001359 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1360 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -08001361 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001362
1363 if(!ctx || !list) {
1364 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001365 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001366 }
1367
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301368 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1369 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1370 return true;
1371 }
1372
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001373 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001374 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001375 idleInvalidator->markForSleep();
1376
1377 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001378 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001379
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001380 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1381 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001382 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001383 if(mCurrentFrame.isFBComposed[i]) continue;
1384
Naseer Ahmed5b6708a2012-08-02 13:46:08 -07001385 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001386 private_handle_t *hnd = (private_handle_t *)layer->handle;
1387 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001388 if (!(layer->flags & HWC_COLOR_FILL)) {
1389 ALOGE("%s handle null", __FUNCTION__);
1390 return false;
1391 }
1392 // No PLAY for Color layer
1393 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1394 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001395 }
1396
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001397 int mdpIndex = mCurrentFrame.layerToMDP[i];
1398
Saurabh Shah88e4d272013-09-03 13:31:29 -07001399 MdpPipeInfoNonSplit& pipe_info =
1400 *(MdpPipeInfoNonSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001401 ovutils::eDest dest = pipe_info.index;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001402 if(dest == ovutils::OV_INVALID) {
1403 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001404 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001405 }
1406
Saurabh Shahacf10202013-02-26 10:15:15 -08001407 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1408 continue;
1409 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001410
Saurabh Shahacf10202013-02-26 10:15:15 -08001411 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001412 using pipe: %d", __FUNCTION__, layer,
1413 hnd, dest );
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001414
Saurabh Shahacf10202013-02-26 10:15:15 -08001415 int fd = hnd->fd;
1416 uint32_t offset = hnd->offset;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001417
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001418 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -08001419 if(rot) {
1420 if(!rot->queueBuffer(fd, offset))
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001421 return false;
Saurabh Shahacf10202013-02-26 10:15:15 -08001422 fd = rot->getDstMemId();
1423 offset = rot->getDstOffset();
1424 }
1425
1426 if (!ov.queueBuffer(fd, offset, dest)) {
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301427 ALOGE("%s: queueBuffer failed for display:%d ", __FUNCTION__, mDpy);
Saurabh Shahacf10202013-02-26 10:15:15 -08001428 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001429 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001430
1431 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001432 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001433 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001434}
1435
Saurabh Shah88e4d272013-09-03 13:31:29 -07001436//=============MDPCompSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001437
Saurabh Shah88e4d272013-09-03 13:31:29 -07001438int MDPCompSplit::pipesNeeded(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001439 hwc_display_contents_1_t* list,
1440 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001441 int pipesNeeded = 0;
Saurabh Shah67a38c32013-06-10 16:23:15 -07001442 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001443
1444 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001445
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001446 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1447 if(!mCurrentFrame.isFBComposed[i]) {
1448 hwc_layer_1_t* layer = &list->hwLayers[i];
1449 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001450 if(mixer == Overlay::MIXER_LEFT && dst.left < lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001451 pipesNeeded++;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001452 } else if(mixer == Overlay::MIXER_RIGHT && dst.right > lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001453 pipesNeeded++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001454 }
1455 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001456 }
1457 return pipesNeeded;
1458}
1459
Saurabh Shah88e4d272013-09-03 13:31:29 -07001460bool MDPCompSplit::arePipesAvailable(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001461 hwc_display_contents_1_t* list) {
1462 overlay::Overlay& ov = *ctx->mOverlay;
Saurabh Shah082468e2013-09-12 10:05:32 -07001463 int totalPipesNeeded = 0;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001464
1465 for(int i = 0; i < Overlay::MIXER_MAX; i++) {
1466 int numPipesNeeded = pipesNeeded(ctx, list, i);
1467 int availPipes = ov.availablePipes(mDpy, i);
1468
1469 //Reserve pipe(s)for FB
1470 if(mCurrentFrame.fbCount)
Saurabh Shah082468e2013-09-12 10:05:32 -07001471 numPipesNeeded += 1;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001472
Saurabh Shah082468e2013-09-12 10:05:32 -07001473 totalPipesNeeded += numPipesNeeded;
1474
1475 //Per mixer check.
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001476 if(numPipesNeeded > availPipes) {
1477 ALOGD_IF(isDebug(), "%s: Insufficient pipes for "
1478 "dpy %d mixer %d needed %d, avail %d",
1479 __FUNCTION__, mDpy, i, numPipesNeeded, availPipes);
1480 return false;
1481 }
1482 }
Saurabh Shah082468e2013-09-12 10:05:32 -07001483
1484 //Per display check, since unused pipes can get counted twice.
1485 int totalPipesAvailable = ov.availablePipes(mDpy);
1486 if(totalPipesNeeded > totalPipesAvailable) {
1487 ALOGD_IF(isDebug(), "%s: Insufficient pipes for "
1488 "dpy %d needed %d, avail %d",
1489 __FUNCTION__, mDpy, totalPipesNeeded, totalPipesAvailable);
1490 return false;
1491 }
1492
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001493 if(not areVGPipesAvailable(ctx, list)) {
1494 return false;
1495 }
1496
1497 return true;
1498}
1499
1500bool MDPCompSplit::areVGPipesAvailable(hwc_context_t *ctx,
1501 hwc_display_contents_1_t* list) {
1502 overlay::Overlay& ov = *ctx->mOverlay;
1503 int pipesNeeded = 0;
1504 const int lSplit = getLeftSplit(ctx, mDpy);
1505 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1506 if(!mCurrentFrame.isFBComposed[i]) {
1507 hwc_layer_1_t* layer = &list->hwLayers[i];
1508 hwc_rect_t dst = layer->displayFrame;
1509 private_handle_t *hnd = (private_handle_t *)layer->handle;
1510 if(isYuvBuffer(hnd)) {
1511 if(dst.left < lSplit) {
1512 pipesNeeded++;
1513 }
1514 if(dst.right > lSplit) {
1515 pipesNeeded++;
1516 }
1517 }
1518 }
1519 }
1520
1521 int availableVGPipes = ov.availablePipes(mDpy, ovutils::OV_MDP_PIPE_VG);
1522 if(pipesNeeded > availableVGPipes) {
1523 ALOGD_IF(isDebug(), "%s: Insufficient VG pipes for video layers"
1524 "dpy %d needed %d, avail %d",
1525 __FUNCTION__, mDpy, pipesNeeded, availableVGPipes);
1526 return false;
1527 }
1528
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001529 return true;
1530}
1531
Saurabh Shah88e4d272013-09-03 13:31:29 -07001532bool MDPCompSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
1533 MdpPipeInfoSplit& pipe_info,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001534 ePipeType type) {
1535 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001536 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001537
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001538 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001539 pipe_info.lIndex = ovutils::OV_INVALID;
1540 pipe_info.rIndex = ovutils::OV_INVALID;
1541
1542 if (dst.left < lSplit) {
1543 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_LEFT);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001544 if(pipe_info.lIndex == ovutils::OV_INVALID)
1545 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001546 }
1547
1548 if(dst.right > lSplit) {
1549 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_RIGHT);
1550 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001551 return false;
1552 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001553
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001554 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001555}
1556
Saurabh Shah88e4d272013-09-03 13:31:29 -07001557bool MDPCompSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001558 hwc_display_contents_1_t* list) {
1559 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001560
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001561 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001562
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001563 hwc_layer_1_t* layer = &list->hwLayers[index];
1564 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001565 int mdpIndex = mCurrentFrame.layerToMDP[index];
1566 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001567 info.pipeInfo = new MdpPipeInfoSplit;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001568 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001569 MdpPipeInfoSplit& pipe_info = *(MdpPipeInfoSplit*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001570 ePipeType type = MDPCOMP_OV_ANY;
1571
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001572 if(isYuvBuffer(hnd)) {
1573 type = MDPCOMP_OV_VG;
Sushil Chauhan15a2ea62013-09-04 18:28:36 -07001574 } else if(!qhwc::needsScalingWithSplit(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001575 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001576 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001577 type = MDPCOMP_OV_DMA;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001578 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001579
1580 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001581 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type = %d",
1582 __FUNCTION__, (int) type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001583 return false;
1584 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001585 }
1586 return true;
1587}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001588
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001589/*
1590 * Configures pipe(s) for MDP composition
1591 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001592int MDPCompSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001593 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001594 MdpPipeInfoSplit& mdp_info =
1595 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001596 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1597 eIsFg isFg = IS_FG_OFF;
1598 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1599 eDest lDest = mdp_info.lIndex;
1600 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001601
1602 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1603 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1604
Saurabh Shah88e4d272013-09-03 13:31:29 -07001605 return configureSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001606 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001607}
1608
Saurabh Shah88e4d272013-09-03 13:31:29 -07001609bool MDPCompSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001610
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001611 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001612 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1613 return true;
1614 }
1615
1616 if(!ctx || !list) {
1617 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001618 return false;
1619 }
1620
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301621 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1622 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1623 return true;
1624 }
1625
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001626 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001627 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001628 idleInvalidator->markForSleep();
1629
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001630 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001631 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001632
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001633 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1634 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001635 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001636 if(mCurrentFrame.isFBComposed[i]) continue;
1637
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001638 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001639 private_handle_t *hnd = (private_handle_t *)layer->handle;
1640 if(!hnd) {
1641 ALOGE("%s handle null", __FUNCTION__);
1642 return false;
1643 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001644
1645 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1646 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001647 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001648
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001649 int mdpIndex = mCurrentFrame.layerToMDP[i];
1650
Saurabh Shah88e4d272013-09-03 13:31:29 -07001651 MdpPipeInfoSplit& pipe_info =
1652 *(MdpPipeInfoSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001653 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -08001654
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001655 ovutils::eDest indexL = pipe_info.lIndex;
1656 ovutils::eDest indexR = pipe_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001657
Saurabh Shahacf10202013-02-26 10:15:15 -08001658 int fd = hnd->fd;
1659 int offset = hnd->offset;
1660
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001661 if(ctx->mAD->isModeOn()) {
1662 if(ctx->mAD->draw(ctx, fd, offset)) {
1663 fd = ctx->mAD->getDstFd(ctx);
1664 offset = ctx->mAD->getDstOffset(ctx);
1665 }
1666 }
1667
Saurabh Shahacf10202013-02-26 10:15:15 -08001668 if(rot) {
1669 rot->queueBuffer(fd, offset);
1670 fd = rot->getDstMemId();
1671 offset = rot->getDstOffset();
1672 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001673
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001674 //************* play left mixer **********
1675 if(indexL != ovutils::OV_INVALID) {
1676 ovutils::eDest destL = (ovutils::eDest)indexL;
Saurabh Shahacf10202013-02-26 10:15:15 -08001677 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001678 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
Saurabh Shahacf10202013-02-26 10:15:15 -08001679 if (!ov.queueBuffer(fd, offset, destL)) {
1680 ALOGE("%s: queueBuffer failed for left mixer", __FUNCTION__);
1681 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001682 }
1683 }
1684
1685 //************* play right mixer **********
1686 if(indexR != ovutils::OV_INVALID) {
1687 ovutils::eDest destR = (ovutils::eDest)indexR;
Saurabh Shahacf10202013-02-26 10:15:15 -08001688 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001689 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
Saurabh Shahacf10202013-02-26 10:15:15 -08001690 if (!ov.queueBuffer(fd, offset, destR)) {
1691 ALOGE("%s: queueBuffer failed for right mixer", __FUNCTION__);
1692 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001693 }
1694 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001695
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001696 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1697 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001698
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001699 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001700}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001701}; //namespace
1702