blob: ef7756771b11146668b68897a6fe1b58c1b30d7b [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
296 if(isNonIntegralSourceCrop(layer->sourceCropf))
297 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
Saurabh Shah4fdde762013-04-30 18:47:33 -0700326 const uint32_t downscale =
327 qdutils::MDPVersion::getInstance().getMaxMDPDownscale();
328 if(ctx->mMDP.version >= qdutils::MDSS_V5) {
329 /* Workaround for downscales larger than 4x.
330 * Will be removed once decimator block is enabled for MDSS
331 */
332 if(!qdutils::MDPVersion::getInstance().supportsDecimation()) {
333 if(crop_w > MAX_DISPLAY_DIM || w_dscale > downscale ||
334 h_dscale > downscale)
335 return false;
336 } else {
337 if(w_dscale > 64 || h_dscale > 64)
338 return false;
339 }
340 } else { //A-family
341 if(w_dscale > downscale || h_dscale > downscale)
342 return false;
343 }
344
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800345 return true;
346}
347
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700348ovutils::eDest MDPComp::getMdpPipe(hwc_context_t *ctx, ePipeType type,
349 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800350 overlay::Overlay& ov = *ctx->mOverlay;
351 ovutils::eDest mdp_pipe = ovutils::OV_INVALID;
352
353 switch(type) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800354 case MDPCOMP_OV_DMA:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700355 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_DMA, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800356 if(mdp_pipe != ovutils::OV_INVALID) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800357 return mdp_pipe;
358 }
359 case MDPCOMP_OV_ANY:
360 case MDPCOMP_OV_RGB:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700361 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800362 if(mdp_pipe != ovutils::OV_INVALID) {
363 return mdp_pipe;
364 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800365
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800366 if(type == MDPCOMP_OV_RGB) {
367 //Requested only for RGB pipe
368 break;
369 }
370 case MDPCOMP_OV_VG:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700371 return ov.nextPipe(ovutils::OV_MDP_PIPE_VG, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800372 default:
373 ALOGE("%s: Invalid pipe type",__FUNCTION__);
374 return ovutils::OV_INVALID;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800375 };
376 return ovutils::OV_INVALID;
377}
378
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800379bool MDPComp::isFrameDoable(hwc_context_t *ctx) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700380 bool ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700381 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800382
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800383 if(!isEnabled()) {
384 ALOGD_IF(isDebug(),"%s: MDP Comp. not enabled.", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700385 ret = false;
Saurabh Shahd4e65852013-06-17 11:33:53 -0700386 } else if(qdutils::MDPVersion::getInstance().is8x26() &&
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700387 ctx->mVideoTransFlag && ctx->mVirtualDisplay->isConnected()) {
Saurabh Shahd4e65852013-06-17 11:33:53 -0700388 //1 Padding round to shift pipes across mixers
389 ALOGD_IF(isDebug(),"%s: MDP Comp. video transition padding round",
390 __FUNCTION__);
391 ret = false;
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700392 } else if(ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isConfiguring ||
393 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isConfiguring) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800394 ALOGD_IF( isDebug(),"%s: External Display connection is pending",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800395 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700396 ret = false;
Saurabh Shahaa236822013-04-24 18:07:26 -0700397 } else if(ctx->isPaddingRound) {
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700398 ctx->isPaddingRound = false;
399 ALOGD_IF(isDebug(), "%s: padding round",__FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700400 ret = false;
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700401 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700402 return ret;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800403}
404
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700405bool MDPComp::validateAndApplyROI(hwc_context_t *ctx,
406 hwc_display_contents_1_t* list, hwc_rect_t roi) {
407 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
408
409 if(!isValidRect(roi))
410 return false;
411
412 for(int i = 0; i < numAppLayers; i++){
413 const hwc_layer_1_t* layer = &list->hwLayers[i];
414
415 hwc_rect_t dstRect = layer->displayFrame;
416 hwc_rect_t srcRect = layer->sourceCrop;
417 int transform = layer->transform;
418 trimLayer(ctx, mDpy, transform, srcRect, dstRect);
419
420 hwc_rect_t res = getIntersection(roi, dstRect);
421
422 int res_w = res.right - res.left;
423 int res_h = res.bottom - res.top;
424 int dst_w = dstRect.right - dstRect.left;
425 int dst_h = dstRect.bottom - dstRect.top;
426
427 if(!isValidRect(res)) {
428 mCurrentFrame.drop[i] = true;
429 mCurrentFrame.dropCount++;
430 }else {
431 /* Reset frame ROI when any layer which needs scaling also needs ROI
432 * cropping */
433 if((res_w != dst_w || res_h != dst_h) &&
434 needsScaling (ctx, layer, mDpy)) {
435 ALOGE("%s: Resetting ROI due to scaling", __FUNCTION__);
436 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
437 mCurrentFrame.dropCount = 0;
438 return false;
439 }
440 }
441 }
442 return true;
443}
444
445void MDPComp::generateROI(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
446 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
447
448 if(!sEnablePartialFrameUpdate) {
449 return;
450 }
451
452 if(mDpy || isDisplaySplit(ctx, mDpy)){
453 ALOGE_IF(isDebug(), "%s: ROI not supported for"
454 "the (1) external / virtual display's (2) dual DSI displays",
455 __FUNCTION__);
456 return;
457 }
458
459 if(list->flags & HWC_GEOMETRY_CHANGED)
460 return;
461
462 struct hwc_rect roi = (struct hwc_rect){0, 0, 0, 0};
463 for(int index = 0; index < numAppLayers; index++ ) {
464 if ((mCachedFrame.hnd[index] != list->hwLayers[index].handle) ||
465 isYuvBuffer((private_handle_t *)list->hwLayers[index].handle)) {
466 hwc_rect_t dstRect = list->hwLayers[index].displayFrame;
467 hwc_rect_t srcRect = list->hwLayers[index].sourceCrop;
468 int transform = list->hwLayers[index].transform;
469
470 /* Intersect against display boundaries */
471 trimLayer(ctx, mDpy, transform, srcRect, dstRect);
472 roi = getUnion(roi, dstRect);
473 }
474 }
475
476 if(!validateAndApplyROI(ctx, list, roi)){
477 roi = (struct hwc_rect) {0, 0,
478 (int)ctx->dpyAttr[mDpy].xres, (int)ctx->dpyAttr[mDpy].yres};
479 }
480
481 ctx->listStats[mDpy].roi.x = roi.left;
482 ctx->listStats[mDpy].roi.y = roi.top;
483 ctx->listStats[mDpy].roi.w = roi.right - roi.left;
484 ctx->listStats[mDpy].roi.h = roi.bottom - roi.top;
485
486 ALOGD_IF(isDebug(),"%s: generated ROI: [%d, %d, %d, %d]", __FUNCTION__,
487 roi.left, roi.top, roi.right, roi.bottom);
488}
489
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800490/* Checks for conditions where all the layers marked for MDP comp cannot be
491 * bypassed. On such conditions we try to bypass atleast YUV layers */
492bool MDPComp::isFullFrameDoable(hwc_context_t *ctx,
493 hwc_display_contents_1_t* list){
494
Saurabh Shahaa236822013-04-24 18:07:26 -0700495 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800496
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -0700497 if(sIdleFallBack && !ctx->listStats[mDpy].secureUI) {
Saurabh Shah2d998a92013-05-14 17:55:58 -0700498 ALOGD_IF(isDebug(), "%s: Idle fallback dpy %d",__FUNCTION__, mDpy);
499 return false;
500 }
501
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800502 if(isSkipPresent(ctx, mDpy)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700503 ALOGD_IF(isDebug(),"%s: SKIP present: %d",
504 __FUNCTION__,
505 isSkipPresent(ctx, mDpy));
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800506 return false;
507 }
508
Saurabh Shah9f084ad2013-05-02 11:28:09 -0700509 if(ctx->listStats[mDpy].needsAlphaScale
510 && ctx->mMDP.version < qdutils::MDSS_V5) {
511 ALOGD_IF(isDebug(), "%s: frame needs alpha downscaling",__FUNCTION__);
512 return false;
513 }
514
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800515 for(int i = 0; i < numAppLayers; ++i) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800516 hwc_layer_1_t* layer = &list->hwLayers[i];
517 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800518
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700519 if(isYuvBuffer(hnd) && has90Transform(layer)) {
520 if(!canUseRotator(ctx, mDpy)) {
521 ALOGD_IF(isDebug(), "%s: Can't use rotator for dpy %d",
522 __FUNCTION__, mDpy);
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700523 return false;
524 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800525 }
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530526
527 //For 8x26 with panel width>1k, if RGB layer needs HFLIP fail mdp comp
528 // may not need it if Gfx pre-rotation can handle all flips & rotations
529 if(qdutils::MDPVersion::getInstance().is8x26() &&
530 (ctx->dpyAttr[mDpy].xres > 1024) &&
531 (layer->transform & HWC_TRANSFORM_FLIP_H) &&
532 (!isYuvBuffer(hnd)))
533 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800534 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700535
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700536 if(ctx->mAD->isDoable()) {
537 return false;
538 }
539
Saurabh Shahaa236822013-04-24 18:07:26 -0700540 //If all above hard conditions are met we can do full or partial MDP comp.
541 bool ret = false;
542 if(fullMDPComp(ctx, list)) {
543 ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700544 } else if(partialMDPComp(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700545 ret = true;
546 }
547 return ret;
548}
549
550bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700551 //Will benefit presentation / secondary-only layer.
552 if((mDpy > HWC_DISPLAY_PRIMARY) &&
553 (list->numHwLayers - 1) > MAX_SEC_LAYERS) {
554 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
555 return false;
556 }
557
558 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
559 for(int i = 0; i < numAppLayers; i++) {
560 hwc_layer_1_t* layer = &list->hwLayers[i];
561 if(not isSupportedForMDPComp(ctx, layer)) {
562 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",__FUNCTION__);
563 return false;
564 }
565 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700566 mCurrentFrame.fbCount = 0;
567 mCurrentFrame.fbZ = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700568 memcpy(&mCurrentFrame.isFBComposed, &mCurrentFrame.drop,
569 sizeof(mCurrentFrame.isFBComposed));
570 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount -
571 mCurrentFrame.dropCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700572
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700573 if(mCurrentFrame.mdpCount > sMaxPipesPerMixer) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700574 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
575 return false;
576 }
577
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700578 if(!arePipesAvailable(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700579 return false;
580 }
581
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700582 uint32_t size = calcMDPBytesRead(ctx, list);
583 if(!bandwidthCheck(ctx, size)) {
584 ALOGD_IF(isDebug(), "%s: Exceeds bandwidth",__FUNCTION__);
585 return false;
586 }
587
Saurabh Shahaa236822013-04-24 18:07:26 -0700588 return true;
589}
590
591bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
592{
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700593 if(!sEnableMixedMode) {
594 //Mixed mode is disabled. No need to even try caching.
595 return false;
596 }
597
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700598 bool ret = false;
599 if(isLoadBasedCompDoable(ctx, list)) {
600 ret = loadBasedComp(ctx, list);
601 }
602
603 if(!ret) {
604 ret = cacheBasedComp(ctx, list);
605 }
606
607 return ret;
608}
609
610bool MDPComp::cacheBasedComp(hwc_context_t *ctx,
611 hwc_display_contents_1_t* list) {
612 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700613 mCurrentFrame.reset(numAppLayers);
614 updateLayerCache(ctx, list);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700615
616 //If an MDP marked layer is unsupported cannot do partial MDP Comp
617 for(int i = 0; i < numAppLayers; i++) {
618 if(!mCurrentFrame.isFBComposed[i]) {
619 hwc_layer_1_t* layer = &list->hwLayers[i];
620 if(not isSupportedForMDPComp(ctx, layer)) {
621 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",
622 __FUNCTION__);
623 return false;
624 }
625 }
626 }
627
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700628 updateYUV(ctx, list, false /*secure only*/);
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530629 bool ret = markLayersForCaching(ctx, list); //sets up fbZ also
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700630 if(!ret) {
631 ALOGD_IF(isDebug(),"%s: batching failed, dpy %d",__FUNCTION__, mDpy);
632 return false;
633 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700634
635 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700636
637 //Will benefit cases where a video has non-updating background.
638 if((mDpy > HWC_DISPLAY_PRIMARY) and
639 (mdpCount > MAX_SEC_LAYERS)) {
640 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
641 return false;
642 }
643
Saurabh Shahaa236822013-04-24 18:07:26 -0700644 if(mdpCount > (sMaxPipesPerMixer - 1)) { // -1 since FB is used
645 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
646 return false;
647 }
648
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700649 if(!arePipesAvailable(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700650 return false;
651 }
652
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700653 uint32_t size = calcMDPBytesRead(ctx, list);
654 if(!bandwidthCheck(ctx, size)) {
655 ALOGD_IF(isDebug(), "%s: Exceeds bandwidth",__FUNCTION__);
656 return false;
657 }
658
Saurabh Shahaa236822013-04-24 18:07:26 -0700659 return true;
660}
661
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700662bool MDPComp::loadBasedComp(hwc_context_t *ctx,
663 hwc_display_contents_1_t* list) {
664 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
665 mCurrentFrame.reset(numAppLayers);
666
667 //TODO BatchSize could be optimized further based on available pipes, split
668 //displays etc.
669 const int batchSize = numAppLayers - (sMaxPipesPerMixer - 1);
670 if(batchSize <= 0) {
671 ALOGD_IF(isDebug(), "%s: Not attempting", __FUNCTION__);
672 return false;
673 }
674
675 int minBatchStart = -1;
676 size_t minBatchPixelCount = SIZE_MAX;
677
678 for(int i = 0; i <= numAppLayers - batchSize; i++) {
679 uint32_t batchPixelCount = 0;
680 for(int j = i; j < i + batchSize; j++) {
681 hwc_layer_1_t* layer = &list->hwLayers[j];
682 hwc_rect_t crop = layer->sourceCrop;
683 batchPixelCount += (crop.right - crop.left) *
684 (crop.bottom - crop.top);
685 }
686
687 if(batchPixelCount < minBatchPixelCount) {
688 minBatchPixelCount = batchPixelCount;
689 minBatchStart = i;
690 }
691 }
692
693 if(minBatchStart < 0) {
694 ALOGD_IF(isDebug(), "%s: No batch found batchSize %d numAppLayers %d",
695 __FUNCTION__, batchSize, numAppLayers);
696 return false;
697 }
698
699 for(int i = 0; i < numAppLayers; i++) {
700 if(i < minBatchStart || i >= minBatchStart + batchSize) {
701 hwc_layer_1_t* layer = &list->hwLayers[i];
702 if(not isSupportedForMDPComp(ctx, layer)) {
703 ALOGD_IF(isDebug(), "%s: MDP unsupported layer found at %d",
704 __FUNCTION__, i);
705 return false;
706 }
707 mCurrentFrame.isFBComposed[i] = false;
708 }
709 }
710
711 mCurrentFrame.fbZ = minBatchStart;
712 mCurrentFrame.fbCount = batchSize;
713 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - batchSize;
714
715 if(!arePipesAvailable(ctx, list)) {
716 return false;
717 }
718
719 ALOGD_IF(isDebug(), "%s: fbZ %d batchSize %d",
720 __FUNCTION__, mCurrentFrame.fbZ, batchSize);
721 return true;
722}
723
724bool MDPComp::isLoadBasedCompDoable(hwc_context_t *ctx,
725 hwc_display_contents_1_t* list) {
726 if(mDpy or isSecurePresent(ctx, mDpy) or
727 not (list->flags & HWC_GEOMETRY_CHANGED)) {
728 return false;
729 }
730 return true;
731}
732
Saurabh Shahaa236822013-04-24 18:07:26 -0700733bool MDPComp::isOnlyVideoDoable(hwc_context_t *ctx,
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700734 hwc_display_contents_1_t* list, bool secureOnly) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700735 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700736
Saurabh Shahaa236822013-04-24 18:07:26 -0700737 mCurrentFrame.reset(numAppLayers);
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700738 updateYUV(ctx, list, secureOnly);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700739 int mdpCount = mCurrentFrame.mdpCount;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700740 int fbNeeded = (mCurrentFrame.fbCount != 0);
Saurabh Shahaa236822013-04-24 18:07:26 -0700741
742 if(!isYuvPresent(ctx, mDpy)) {
743 return false;
744 }
745
Saurabh Shah4fdde762013-04-30 18:47:33 -0700746 if(!mdpCount)
747 return false;
748
Saurabh Shahaa236822013-04-24 18:07:26 -0700749 if(mdpCount > (sMaxPipesPerMixer - fbNeeded)) {
750 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
751 return false;
752 }
753
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700754 if(!arePipesAvailable(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700755 return false;
756 }
757
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700758 uint32_t size = calcMDPBytesRead(ctx, list);
759 if(!bandwidthCheck(ctx, size)) {
760 ALOGD_IF(isDebug(), "%s: Exceeds bandwidth",__FUNCTION__);
761 return false;
762 }
763
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800764 return true;
765}
766
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800767/* Checks for conditions where YUV layers cannot be bypassed */
768bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Saurabh Shahe2474082013-05-15 16:32:13 -0700769 bool extAnimBlockFeature = mDpy && ctx->listStats[mDpy].isDisplayAnimating;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800770
Saurabh Shahe2474082013-05-15 16:32:13 -0700771 if(isSkipLayer(layer) && !extAnimBlockFeature) {
772 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800773 return false;
774 }
775
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700776 if(layer->transform & HWC_TRANSFORM_ROT_90 && !canUseRotator(ctx,mDpy)) {
777 ALOGD_IF(isDebug(), "%s: no free DMA pipe",__FUNCTION__);
778 return false;
779 }
780
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800781 if(isSecuring(ctx, layer)) {
782 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
783 return false;
784 }
785
Saurabh Shah4fdde762013-04-30 18:47:33 -0700786 if(!isValidDimension(ctx, layer)) {
787 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
788 __FUNCTION__);
789 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800790 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700791
Naseer Ahmeddc61a972013-07-10 17:50:54 -0400792 if(layer->planeAlpha < 0xFF) {
793 ALOGD_IF(isDebug(), "%s: Cannot handle YUV layer with plane alpha\
794 in video only mode",
795 __FUNCTION__);
796 return false;
797 }
798
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800799 return true;
800}
801
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530802/* starts at fromIndex and check for each layer to find
803 * if it it has overlapping with any Updating layer above it in zorder
804 * till the end of the batch. returns true if it finds any intersection */
805bool MDPComp::canPushBatchToTop(const hwc_display_contents_1_t* list,
806 int fromIndex, int toIndex) {
807 for(int i = fromIndex; i < toIndex; i++) {
808 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
809 if(intersectingUpdatingLayers(list, i+1, toIndex, i)) {
810 return false;
811 }
812 }
813 }
814 return true;
815}
816
817/* Checks if given layer at targetLayerIndex has any
818 * intersection with all the updating layers in beween
819 * fromIndex and toIndex. Returns true if it finds intersectiion */
820bool MDPComp::intersectingUpdatingLayers(const hwc_display_contents_1_t* list,
821 int fromIndex, int toIndex, int targetLayerIndex) {
822 for(int i = fromIndex; i <= toIndex; i++) {
823 if(!mCurrentFrame.isFBComposed[i]) {
824 if(areLayersIntersecting(&list->hwLayers[i],
825 &list->hwLayers[targetLayerIndex])) {
826 return true;
827 }
828 }
829 }
830 return false;
831}
832
833int MDPComp::getBatch(hwc_display_contents_1_t* list,
834 int& maxBatchStart, int& maxBatchEnd,
835 int& maxBatchCount) {
836 int i = 0;
837 int updatingLayersAbove = 0;//Updating layer count in middle of batch
838 int fbZOrder =-1;
839 while (i < mCurrentFrame.layerCount) {
840 int batchCount = 0;
841 int batchStart = i;
842 int batchEnd = i;
843 int fbZ = batchStart;
844 int firstZReverseIndex = -1;
845 while(i < mCurrentFrame.layerCount) {
846 if(!mCurrentFrame.isFBComposed[i]) {
847 if(!batchCount) {
848 i++;
849 break;
850 }
851 updatingLayersAbove++;
852 i++;
853 continue;
854 } else {
855 if(mCurrentFrame.drop[i]) {
856 i++;
857 continue;
858 } else if(updatingLayersAbove <= 0) {
859 batchCount++;
860 batchEnd = i;
861 i++;
862 continue;
863 } else { //Layer is FBComposed, not a drop & updatingLayer > 0
864
865 // We have a valid updating layer already. If layer-i not
866 // have overlapping with all updating layers in between
867 // batch-start and i, then we can add layer i to batch.
868 if(!intersectingUpdatingLayers(list, batchStart, i-1, i)) {
869 batchCount++;
870 batchEnd = i;
871 i++;
872 continue;
873 } else if(canPushBatchToTop(list, batchStart, i)) {
874 //If All the non-updating layers with in this batch
875 //does not have intersection with the updating layers
876 //above in z-order, then we can safely move the batch to
877 //higher z-order. Increment fbZ as it is moving up.
878 if( firstZReverseIndex < 0) {
879 firstZReverseIndex = i;
880 }
881 batchCount++;
882 batchEnd = i;
883 fbZ += updatingLayersAbove;
884 i++;
885 updatingLayersAbove = 0;
886 continue;
887 } else {
888 //both failed.start the loop again from here.
889 if(firstZReverseIndex >= 0) {
890 i = firstZReverseIndex;
891 }
892 break;
893 }
894 }
895 }
896 }
897 if(batchCount > maxBatchCount) {
898 maxBatchCount = batchCount;
899 maxBatchStart = batchStart;
900 maxBatchEnd = batchEnd;
901 fbZOrder = fbZ;
902 }
903 }
904 return fbZOrder;
905}
906
907bool MDPComp::markLayersForCaching(hwc_context_t* ctx,
908 hwc_display_contents_1_t* list) {
909 /* Idea is to keep as many non-updating(cached) layers in FB and
910 * send rest of them through MDP. This is done in 2 steps.
911 * 1. Find the maximum contiguous batch of non-updating layers.
912 * 2. See if we can improve this batch size for caching by adding
913 * opaque layers around the batch, if they don't have
914 * any overlapping with the updating layers in between.
915 * NEVER mark an updating layer for caching.
916 * But cached ones can be marked for MDP */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800917
918 int maxBatchStart = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700919 int maxBatchEnd = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800920 int maxBatchCount = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530921 int fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800922
923 /* All or Nothing is cached. No batching needed */
Saurabh Shahaa236822013-04-24 18:07:26 -0700924 if(!mCurrentFrame.fbCount) {
925 mCurrentFrame.fbZ = -1;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700926 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -0700927 }
928 if(!mCurrentFrame.mdpCount) {
929 mCurrentFrame.fbZ = 0;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700930 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -0700931 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800932
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530933 fbZ = getBatch(list, maxBatchStart, maxBatchEnd, maxBatchCount);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800934
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530935 /* reset rest of the layers lying inside ROI for MDP comp */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800936 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700937 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700938 if((i < maxBatchStart || i > maxBatchEnd) &&
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530939 mCurrentFrame.isFBComposed[i]){
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700940 if(!mCurrentFrame.drop[i]){
941 //If an unsupported layer is being attempted to
942 //be pulled out we should fail
943 if(not isSupportedForMDPComp(ctx, layer)) {
944 return false;
945 }
946 mCurrentFrame.isFBComposed[i] = false;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700947 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800948 }
949 }
950
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530951 // update the frame data
952 mCurrentFrame.fbZ = fbZ;
953 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700954 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700955 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800956
957 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530958 mCurrentFrame.fbCount);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700959
960 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800961}
Saurabh Shah85234ec2013-04-12 17:09:00 -0700962
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800963void MDPComp::updateLayerCache(hwc_context_t* ctx,
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700964 hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800965 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700966 int fbCount = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800967
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800968 for(int i = 0; i < numAppLayers; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700969 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800970 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700971 if(!mCurrentFrame.drop[i])
972 fbCount++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800973 mCurrentFrame.isFBComposed[i] = true;
974 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -0700975 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800976 mCachedFrame.hnd[i] = list->hwLayers[i].handle;
977 }
978 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700979
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700980 mCurrentFrame.fbCount = fbCount;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700981 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount
982 - mCurrentFrame.dropCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700983
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700984 ALOGD_IF(isDebug(),"%s: MDP count: %d FB count %d drop count: %d"
985 ,__FUNCTION__, mCurrentFrame.mdpCount, mCurrentFrame.fbCount,
986 mCurrentFrame.dropCount);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800987}
988
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700989void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list,
990 bool secureOnly) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800991 int nYuvCount = ctx->listStats[mDpy].yuvCount;
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700992 if(!nYuvCount && mDpy) {
993 //Reset "No animation on external display" related parameters.
994 ctx->mPrevCropVideo.left = ctx->mPrevCropVideo.top =
995 ctx->mPrevCropVideo.right = ctx->mPrevCropVideo.bottom = 0;
996 ctx->mPrevDestVideo.left = ctx->mPrevDestVideo.top =
997 ctx->mPrevDestVideo.right = ctx->mPrevDestVideo.bottom = 0;
998 ctx->mPrevTransformVideo = 0;
999 return;
1000 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001001 for(int index = 0;index < nYuvCount; index++){
1002 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
1003 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
1004
1005 if(!isYUVDoable(ctx, layer)) {
1006 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
1007 mCurrentFrame.isFBComposed[nYuvIndex] = true;
1008 mCurrentFrame.fbCount++;
1009 }
1010 } else {
1011 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001012 private_handle_t *hnd = (private_handle_t *)layer->handle;
1013 if(!secureOnly || isSecureBuffer(hnd)) {
1014 mCurrentFrame.isFBComposed[nYuvIndex] = false;
1015 mCurrentFrame.fbCount--;
1016 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001017 }
1018 }
1019 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001020
1021 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001022 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
1023 ALOGD_IF(isDebug(),"%s: fb count: %d",__FUNCTION__,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001024 mCurrentFrame.fbCount);
1025}
1026
Saurabh Shahaa236822013-04-24 18:07:26 -07001027bool MDPComp::programMDP(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001028 if(!allocLayerPipes(ctx, list)) {
1029 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -07001030 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001031 }
1032
1033 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001034 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001035 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001036 int mdpIndex = mCurrentFrame.layerToMDP[index];
1037 hwc_layer_1_t* layer = &list->hwLayers[index];
1038
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301039 //Leave fbZ for framebuffer. CACHE/GLES layers go here.
1040 if(mdpNextZOrder == mCurrentFrame.fbZ) {
1041 mdpNextZOrder++;
1042 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001043 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1044 cur_pipe->zOrder = mdpNextZOrder++;
1045
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301046
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001047 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
1048 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
1049 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -07001050 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001051 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001052 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001053 }
1054
Saurabh Shahaa236822013-04-24 18:07:26 -07001055 return true;
1056}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001057
Saurabh Shahaa236822013-04-24 18:07:26 -07001058bool MDPComp::programYUV(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
1059 if(!allocLayerPipes(ctx, list)) {
1060 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
1061 return false;
1062 }
1063 //If we are in this block, it means we have yuv + rgb layers both
1064 int mdpIdx = 0;
1065 for (int index = 0; index < mCurrentFrame.layerCount; index++) {
1066 if(!mCurrentFrame.isFBComposed[index]) {
1067 hwc_layer_1_t* layer = &list->hwLayers[index];
1068 int mdpIndex = mCurrentFrame.layerToMDP[index];
1069 MdpPipeInfo* cur_pipe =
1070 mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1071 cur_pipe->zOrder = mdpIdx++;
1072
1073 if(configure(ctx, layer,
1074 mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
1075 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
1076 layer %d",__FUNCTION__, index);
1077 return false;
1078 }
1079 }
1080 }
1081 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001082}
1083
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001084uint32_t MDPComp::calcMDPBytesRead(hwc_context_t *ctx,
1085 hwc_display_contents_1_t* list) {
1086 uint32_t size = 0;
1087
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001088 if(!qdutils::MDPVersion::getInstance().is8x74v2())
1089 return 0;
1090
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001091 for (uint32_t i = 0; i < list->numHwLayers - 1; i++) {
1092 if(!mCurrentFrame.isFBComposed[i]) {
1093 hwc_layer_1_t* layer = &list->hwLayers[i];
1094 private_handle_t *hnd = (private_handle_t *)layer->handle;
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001095 if (hnd) {
Saurabh Shah62e1d732013-09-17 10:44:05 -07001096 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah90789162013-09-16 10:29:20 -07001097 hwc_rect_t dst = layer->displayFrame;
1098 trimLayer(ctx, mDpy, layer->transform, crop, dst);
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001099 float bpp = ((float)hnd->size) / (hnd->width * hnd->height);
Saurabh Shah90789162013-09-16 10:29:20 -07001100 size += bpp * (crop.right - crop.left) *
1101 (crop.bottom - crop.top) *
1102 ctx->dpyAttr[mDpy].yres / (dst.bottom - dst.top);
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001103 }
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001104 }
1105 }
1106
1107 if(mCurrentFrame.fbCount) {
1108 hwc_layer_1_t* layer = &list->hwLayers[list->numHwLayers - 1];
1109 private_handle_t *hnd = (private_handle_t *)layer->handle;
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001110 if (hnd)
1111 size += hnd->size;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001112 }
1113
1114 return size;
1115}
1116
1117bool MDPComp::bandwidthCheck(hwc_context_t *ctx, const uint32_t& size) {
1118 //Will be added for other targets if we run into bandwidth issues and when
1119 //we have profiling data to set an upper limit.
1120 if(qdutils::MDPVersion::getInstance().is8x74v2()) {
1121 const uint32_t ONE_GIG = 1024 * 1024 * 1024;
1122 double panelRefRate =
1123 1000000000.0 / ctx->dpyAttr[mDpy].vsync_period;
1124 if((size + sCompBytesClaimed) > ((sMaxBw / panelRefRate) * ONE_GIG)) {
1125 return false;
1126 }
1127 }
1128 return true;
1129}
1130
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001131int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001132 int ret = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -07001133 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -07001134
Saurabh Shahb39f8152013-08-22 10:21:44 -07001135 //reset old data
1136 mCurrentFrame.reset(numLayers);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001137 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1138 mCurrentFrame.dropCount = 0;
Prabhanjan Kandula088bd892013-07-02 23:47:13 +05301139
Saurabh Shahb39f8152013-08-22 10:21:44 -07001140 //number of app layers exceeds MAX_NUM_APP_LAYERS fall back to GPU
1141 //do not cache the information for next draw cycle.
1142 if(numLayers > MAX_NUM_APP_LAYERS) {
Prabhanjan Kandula25469a52013-07-12 16:19:31 +05301143 mCachedFrame.updateCounts(mCurrentFrame);
Tatenda Chipeperekwa835337a2013-09-27 16:58:43 -07001144 ALOGE("%s: Number of App layers exceeded the limit ",
1145 __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001146 ret = -1;
Tatenda Chipeperekwa835337a2013-09-27 16:58:43 -07001147 return ret;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001148 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001149
Saurabh Shahb39f8152013-08-22 10:21:44 -07001150 //Hard conditions, if not met, cannot do MDP comp
1151 if(!isFrameDoable(ctx)) {
1152 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
1153 __FUNCTION__);
1154 reset(numLayers, list);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001155 ret = -1;
1156 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001157 }
1158
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001159 generateROI(ctx, list);
1160
Saurabh Shahb39f8152013-08-22 10:21:44 -07001161 //Check whether layers marked for MDP Composition is actually doable.
1162 if(isFullFrameDoable(ctx, list)) {
1163 mCurrentFrame.map();
1164 //Configure framebuffer first if applicable
1165 if(mCurrentFrame.fbZ >= 0) {
1166 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list,
1167 mCurrentFrame.fbZ)) {
1168 ALOGE("%s configure framebuffer failed", __func__);
1169 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -07001170 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001171 ret = -1;
1172 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001173 }
1174 }
1175 //Acquire and Program MDP pipes
1176 if(!programMDP(ctx, list)) {
1177 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -07001178 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001179 ret = -1;
1180 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001181 } else { //Success
1182 //Any change in composition types needs an FB refresh
1183 mCurrentFrame.needsRedraw = false;
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +05301184 if(!mCachedFrame.isSameFrame(mCurrentFrame) ||
Saurabh Shahb39f8152013-08-22 10:21:44 -07001185 (list->flags & HWC_GEOMETRY_CHANGED) ||
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +05301186 isSkipPresent(ctx, mDpy)) {
Saurabh Shahb39f8152013-08-22 10:21:44 -07001187 mCurrentFrame.needsRedraw = true;
1188 }
1189 }
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001190 } else if(isOnlyVideoDoable(ctx, list, false /*secure only*/) ||
1191 isOnlyVideoDoable(ctx, list, true /*secure only*/)) {
Saurabh Shahb39f8152013-08-22 10:21:44 -07001192 //All layers marked for MDP comp cannot be bypassed.
1193 //Try to compose atleast YUV layers through MDP comp and let
1194 //all the RGB layers compose in FB
1195 //Destination over
1196 mCurrentFrame.fbZ = -1;
1197 if(mCurrentFrame.fbCount)
1198 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
1199
1200 mCurrentFrame.map();
1201
1202 //Configure framebuffer first if applicable
1203 if(mCurrentFrame.fbZ >= 0) {
1204 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, mCurrentFrame.fbZ)) {
1205 ALOGE("%s configure framebuffer failed", __func__);
1206 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -07001207 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001208 ret = -1;
1209 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001210 }
1211 }
1212 if(!programYUV(ctx, list)) {
1213 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -07001214 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001215 ret = -1;
1216 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001217 }
1218 } else {
1219 reset(numLayers, list);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001220 ret = -1;
1221 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001222 }
1223
1224 //UpdateLayerFlags
1225 setMDPCompLayerFlags(ctx, list);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001226 mCachedFrame.cacheAll(list);
Saurabh Shahb39f8152013-08-22 10:21:44 -07001227 mCachedFrame.updateCounts(mCurrentFrame);
1228
Prabhanjan Kandula25469a52013-07-12 16:19:31 +05301229 // unlock it before calling dump function to avoid deadlock
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001230 if(isDebug()) {
Saurabh Shahaa236822013-04-24 18:07:26 -07001231 ALOGD("GEOMETRY change: %d", (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001232 android::String8 sDump("");
1233 dump(sDump);
1234 ALOGE("%s",sDump.string());
1235 }
1236
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001237exit:
1238 sCompBytesClaimed += calcMDPBytesRead(ctx, list);
1239 return ret;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001240}
1241
Saurabh Shah88e4d272013-09-03 13:31:29 -07001242//=============MDPCompNonSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001243
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001244/*
1245 * Configures pipe(s) for MDP composition
1246 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001247int MDPCompNonSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001248 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001249 MdpPipeInfoNonSplit& mdp_info =
1250 *(static_cast<MdpPipeInfoNonSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001251 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
1252 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1253 eIsFg isFg = IS_FG_OFF;
1254 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001255
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001256 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
1257 __FUNCTION__, layer, zOrder, dest);
1258
Saurabh Shah88e4d272013-09-03 13:31:29 -07001259 return configureNonSplit(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001260 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001261}
1262
Saurabh Shah88e4d272013-09-03 13:31:29 -07001263bool MDPCompNonSplit::arePipesAvailable(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001264 hwc_display_contents_1_t* list) {
1265 overlay::Overlay& ov = *ctx->mOverlay;
1266 int numPipesNeeded = mCurrentFrame.mdpCount;
1267 int availPipes = ov.availablePipes(mDpy, Overlay::MIXER_DEFAULT);
1268
1269 //Reserve pipe for FB
1270 if(mCurrentFrame.fbCount)
1271 availPipes -= 1;
1272
1273 if(numPipesNeeded > availPipes) {
1274 ALOGD_IF(isDebug(), "%s: Insufficient pipes, dpy %d needed %d, avail %d",
1275 __FUNCTION__, mDpy, numPipesNeeded, availPipes);
1276 return false;
1277 }
1278
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001279 if(not areVGPipesAvailable(ctx, list)) {
1280 return false;
1281 }
1282
1283 return true;
1284}
1285
1286bool MDPCompNonSplit::areVGPipesAvailable(hwc_context_t *ctx,
1287 hwc_display_contents_1_t* list) {
1288 overlay::Overlay& ov = *ctx->mOverlay;
1289 int pipesNeeded = 0;
1290 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1291 if(!mCurrentFrame.isFBComposed[i]) {
1292 hwc_layer_1_t* layer = &list->hwLayers[i];
1293 hwc_rect_t dst = layer->displayFrame;
1294 private_handle_t *hnd = (private_handle_t *)layer->handle;
1295 if(isYuvBuffer(hnd)) {
1296 pipesNeeded++;
1297 }
1298 }
1299 }
1300
1301 int availableVGPipes = ov.availablePipes(mDpy, ovutils::OV_MDP_PIPE_VG);
1302 if(pipesNeeded > availableVGPipes) {
1303 ALOGD_IF(isDebug(), "%s: Insufficient VG pipes for video layers"
1304 "dpy %d needed %d, avail %d",
1305 __FUNCTION__, mDpy, pipesNeeded, availableVGPipes);
1306 return false;
1307 }
1308
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001309 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001310}
1311
Saurabh Shah88e4d272013-09-03 13:31:29 -07001312bool MDPCompNonSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001313 hwc_display_contents_1_t* list) {
1314 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001315
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001316 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001317
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001318 hwc_layer_1_t* layer = &list->hwLayers[index];
1319 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001320 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001321 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001322 info.pipeInfo = new MdpPipeInfoNonSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08001323 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001324 MdpPipeInfoNonSplit& pipe_info = *(MdpPipeInfoNonSplit*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001325 ePipeType type = MDPCOMP_OV_ANY;
1326
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001327 if(isYuvBuffer(hnd)) {
1328 type = MDPCOMP_OV_VG;
Saurabh Shah8a117932013-05-23 12:48:13 -07001329 } else if(!qhwc::needsScaling(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001330 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
1331 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001332 type = MDPCOMP_OV_DMA;
1333 }
1334
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001335 pipe_info.index = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001336 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001337 ALOGD_IF(isDebug(), "%s: Unable to get pipe type = %d",
1338 __FUNCTION__, (int) type);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001339 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001340 }
1341 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001342 return true;
1343}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001344
Saurabh Shah88e4d272013-09-03 13:31:29 -07001345bool MDPCompNonSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001346
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001347 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001348 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1349 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -08001350 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001351
1352 if(!ctx || !list) {
1353 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001354 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001355 }
1356
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301357 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1358 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1359 return true;
1360 }
1361
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001362 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001363 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001364 idleInvalidator->markForSleep();
1365
1366 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001367 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001368
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001369 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1370 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001371 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001372 if(mCurrentFrame.isFBComposed[i]) continue;
1373
Naseer Ahmed5b6708a2012-08-02 13:46:08 -07001374 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001375 private_handle_t *hnd = (private_handle_t *)layer->handle;
1376 if(!hnd) {
1377 ALOGE("%s handle null", __FUNCTION__);
1378 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001379 }
1380
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001381 int mdpIndex = mCurrentFrame.layerToMDP[i];
1382
Saurabh Shah88e4d272013-09-03 13:31:29 -07001383 MdpPipeInfoNonSplit& pipe_info =
1384 *(MdpPipeInfoNonSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001385 ovutils::eDest dest = pipe_info.index;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001386 if(dest == ovutils::OV_INVALID) {
1387 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001388 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001389 }
1390
Saurabh Shahacf10202013-02-26 10:15:15 -08001391 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1392 continue;
1393 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001394
Saurabh Shahacf10202013-02-26 10:15:15 -08001395 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001396 using pipe: %d", __FUNCTION__, layer,
1397 hnd, dest );
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001398
Saurabh Shahacf10202013-02-26 10:15:15 -08001399 int fd = hnd->fd;
1400 uint32_t offset = hnd->offset;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001401
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001402 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -08001403 if(rot) {
1404 if(!rot->queueBuffer(fd, offset))
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001405 return false;
Saurabh Shahacf10202013-02-26 10:15:15 -08001406 fd = rot->getDstMemId();
1407 offset = rot->getDstOffset();
1408 }
1409
1410 if (!ov.queueBuffer(fd, offset, dest)) {
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301411 ALOGE("%s: queueBuffer failed for display:%d ", __FUNCTION__, mDpy);
Saurabh Shahacf10202013-02-26 10:15:15 -08001412 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001413 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001414
1415 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001416 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001417 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001418}
1419
Saurabh Shah88e4d272013-09-03 13:31:29 -07001420//=============MDPCompSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001421
Saurabh Shah88e4d272013-09-03 13:31:29 -07001422int MDPCompSplit::pipesNeeded(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001423 hwc_display_contents_1_t* list,
1424 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001425 int pipesNeeded = 0;
Saurabh Shah67a38c32013-06-10 16:23:15 -07001426 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001427
1428 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001429
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001430 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1431 if(!mCurrentFrame.isFBComposed[i]) {
1432 hwc_layer_1_t* layer = &list->hwLayers[i];
1433 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001434 if(mixer == Overlay::MIXER_LEFT && dst.left < lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001435 pipesNeeded++;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001436 } else if(mixer == Overlay::MIXER_RIGHT && dst.right > lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001437 pipesNeeded++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001438 }
1439 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001440 }
1441 return pipesNeeded;
1442}
1443
Saurabh Shah88e4d272013-09-03 13:31:29 -07001444bool MDPCompSplit::arePipesAvailable(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001445 hwc_display_contents_1_t* list) {
1446 overlay::Overlay& ov = *ctx->mOverlay;
Saurabh Shah082468e2013-09-12 10:05:32 -07001447 int totalPipesNeeded = 0;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001448
1449 for(int i = 0; i < Overlay::MIXER_MAX; i++) {
1450 int numPipesNeeded = pipesNeeded(ctx, list, i);
1451 int availPipes = ov.availablePipes(mDpy, i);
1452
1453 //Reserve pipe(s)for FB
1454 if(mCurrentFrame.fbCount)
Saurabh Shah082468e2013-09-12 10:05:32 -07001455 numPipesNeeded += 1;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001456
Saurabh Shah082468e2013-09-12 10:05:32 -07001457 totalPipesNeeded += numPipesNeeded;
1458
1459 //Per mixer check.
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001460 if(numPipesNeeded > availPipes) {
1461 ALOGD_IF(isDebug(), "%s: Insufficient pipes for "
1462 "dpy %d mixer %d needed %d, avail %d",
1463 __FUNCTION__, mDpy, i, numPipesNeeded, availPipes);
1464 return false;
1465 }
1466 }
Saurabh Shah082468e2013-09-12 10:05:32 -07001467
1468 //Per display check, since unused pipes can get counted twice.
1469 int totalPipesAvailable = ov.availablePipes(mDpy);
1470 if(totalPipesNeeded > totalPipesAvailable) {
1471 ALOGD_IF(isDebug(), "%s: Insufficient pipes for "
1472 "dpy %d needed %d, avail %d",
1473 __FUNCTION__, mDpy, totalPipesNeeded, totalPipesAvailable);
1474 return false;
1475 }
1476
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001477 if(not areVGPipesAvailable(ctx, list)) {
1478 return false;
1479 }
1480
1481 return true;
1482}
1483
1484bool MDPCompSplit::areVGPipesAvailable(hwc_context_t *ctx,
1485 hwc_display_contents_1_t* list) {
1486 overlay::Overlay& ov = *ctx->mOverlay;
1487 int pipesNeeded = 0;
1488 const int lSplit = getLeftSplit(ctx, mDpy);
1489 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1490 if(!mCurrentFrame.isFBComposed[i]) {
1491 hwc_layer_1_t* layer = &list->hwLayers[i];
1492 hwc_rect_t dst = layer->displayFrame;
1493 private_handle_t *hnd = (private_handle_t *)layer->handle;
1494 if(isYuvBuffer(hnd)) {
1495 if(dst.left < lSplit) {
1496 pipesNeeded++;
1497 }
1498 if(dst.right > lSplit) {
1499 pipesNeeded++;
1500 }
1501 }
1502 }
1503 }
1504
1505 int availableVGPipes = ov.availablePipes(mDpy, ovutils::OV_MDP_PIPE_VG);
1506 if(pipesNeeded > availableVGPipes) {
1507 ALOGD_IF(isDebug(), "%s: Insufficient VG pipes for video layers"
1508 "dpy %d needed %d, avail %d",
1509 __FUNCTION__, mDpy, pipesNeeded, availableVGPipes);
1510 return false;
1511 }
1512
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001513 return true;
1514}
1515
Saurabh Shah88e4d272013-09-03 13:31:29 -07001516bool MDPCompSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
1517 MdpPipeInfoSplit& pipe_info,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001518 ePipeType type) {
1519 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001520 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001521
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001522 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001523 pipe_info.lIndex = ovutils::OV_INVALID;
1524 pipe_info.rIndex = ovutils::OV_INVALID;
1525
1526 if (dst.left < lSplit) {
1527 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_LEFT);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001528 if(pipe_info.lIndex == ovutils::OV_INVALID)
1529 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001530 }
1531
1532 if(dst.right > lSplit) {
1533 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_RIGHT);
1534 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001535 return false;
1536 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001537
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001538 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001539}
1540
Saurabh Shah88e4d272013-09-03 13:31:29 -07001541bool MDPCompSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001542 hwc_display_contents_1_t* list) {
1543 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001544
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001545 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001546
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001547 hwc_layer_1_t* layer = &list->hwLayers[index];
1548 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001549 int mdpIndex = mCurrentFrame.layerToMDP[index];
1550 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001551 info.pipeInfo = new MdpPipeInfoSplit;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001552 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001553 MdpPipeInfoSplit& pipe_info = *(MdpPipeInfoSplit*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001554 ePipeType type = MDPCOMP_OV_ANY;
1555
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001556 if(isYuvBuffer(hnd)) {
1557 type = MDPCOMP_OV_VG;
Sushil Chauhan15a2ea62013-09-04 18:28:36 -07001558 } else if(!qhwc::needsScalingWithSplit(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001559 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001560 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001561 type = MDPCOMP_OV_DMA;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001562 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001563
1564 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001565 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type = %d",
1566 __FUNCTION__, (int) type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001567 return false;
1568 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001569 }
1570 return true;
1571}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001572
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001573/*
1574 * Configures pipe(s) for MDP composition
1575 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001576int MDPCompSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001577 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001578 MdpPipeInfoSplit& mdp_info =
1579 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001580 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1581 eIsFg isFg = IS_FG_OFF;
1582 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1583 eDest lDest = mdp_info.lIndex;
1584 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001585
1586 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1587 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1588
Saurabh Shah88e4d272013-09-03 13:31:29 -07001589 return configureSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001590 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001591}
1592
Saurabh Shah88e4d272013-09-03 13:31:29 -07001593bool MDPCompSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001594
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001595 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001596 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1597 return true;
1598 }
1599
1600 if(!ctx || !list) {
1601 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001602 return false;
1603 }
1604
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301605 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1606 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1607 return true;
1608 }
1609
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001610 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001611 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001612 idleInvalidator->markForSleep();
1613
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001614 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001615 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001616
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001617 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1618 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001619 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001620 if(mCurrentFrame.isFBComposed[i]) continue;
1621
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001622 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001623 private_handle_t *hnd = (private_handle_t *)layer->handle;
1624 if(!hnd) {
1625 ALOGE("%s handle null", __FUNCTION__);
1626 return false;
1627 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001628
1629 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1630 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001631 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001632
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001633 int mdpIndex = mCurrentFrame.layerToMDP[i];
1634
Saurabh Shah88e4d272013-09-03 13:31:29 -07001635 MdpPipeInfoSplit& pipe_info =
1636 *(MdpPipeInfoSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001637 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -08001638
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001639 ovutils::eDest indexL = pipe_info.lIndex;
1640 ovutils::eDest indexR = pipe_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001641
Saurabh Shahacf10202013-02-26 10:15:15 -08001642 int fd = hnd->fd;
1643 int offset = hnd->offset;
1644
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001645 if(ctx->mAD->isModeOn()) {
1646 if(ctx->mAD->draw(ctx, fd, offset)) {
1647 fd = ctx->mAD->getDstFd(ctx);
1648 offset = ctx->mAD->getDstOffset(ctx);
1649 }
1650 }
1651
Saurabh Shahacf10202013-02-26 10:15:15 -08001652 if(rot) {
1653 rot->queueBuffer(fd, offset);
1654 fd = rot->getDstMemId();
1655 offset = rot->getDstOffset();
1656 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001657
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001658 //************* play left mixer **********
1659 if(indexL != ovutils::OV_INVALID) {
1660 ovutils::eDest destL = (ovutils::eDest)indexL;
Saurabh Shahacf10202013-02-26 10:15:15 -08001661 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001662 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
Saurabh Shahacf10202013-02-26 10:15:15 -08001663 if (!ov.queueBuffer(fd, offset, destL)) {
1664 ALOGE("%s: queueBuffer failed for left mixer", __FUNCTION__);
1665 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001666 }
1667 }
1668
1669 //************* play right mixer **********
1670 if(indexR != ovutils::OV_INVALID) {
1671 ovutils::eDest destR = (ovutils::eDest)indexR;
Saurabh Shahacf10202013-02-26 10:15:15 -08001672 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001673 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
Saurabh Shahacf10202013-02-26 10:15:15 -08001674 if (!ov.queueBuffer(fd, offset, destR)) {
1675 ALOGE("%s: queueBuffer failed for right mixer", __FUNCTION__);
1676 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001677 }
1678 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001679
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001680 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1681 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001682
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001683 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001684}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001685}; //namespace
1686