blob: cd4fad4305506746f78603da6a415931a5c462aa [file] [log] [blame]
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001/*
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002 * Copyright (C) 2012-2013, The Linux Foundation. All rights reserved.
Naseer Ahmed7c958d42012-07-31 18:57:03 -07003 * Not a Contribution, Apache license notifications and license are retained
4 * for attribution purposes only.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
Saurabh Shah4fdde762013-04-30 18:47:33 -070019#include <math.h>
Naseer Ahmed7c958d42012-07-31 18:57:03 -070020#include "hwc_mdpcomp.h"
Naseer Ahmed54821fe2012-11-28 18:44:38 -050021#include <sys/ioctl.h>
Saurabh Shah56f610d2012-08-07 15:27:06 -070022#include "external.h"
Jeykumar Sankaran27dee262013-08-01 17:09:54 -070023#include "virtual.h"
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -080024#include "qdMetaData.h"
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -080025#include "mdp_version.h"
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -070026#include "hwc_fbupdate.h"
Saurabh Shaha9da08f2013-07-03 13:27:53 -070027#include "hwc_ad.h"
Saurabh Shahacf10202013-02-26 10:15:15 -080028#include <overlayRotator.h>
29
Saurabh Shah85234ec2013-04-12 17:09:00 -070030using namespace overlay;
Saurabh Shahbd2d0832013-04-04 14:33:08 -070031using namespace qdutils;
Saurabh Shahacf10202013-02-26 10:15:15 -080032using namespace overlay::utils;
33namespace ovutils = overlay::utils;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070034
Naseer Ahmed7c958d42012-07-31 18:57:03 -070035namespace qhwc {
36
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080037//==============MDPComp========================================================
38
Naseer Ahmed7c958d42012-07-31 18:57:03 -070039IdleInvalidator *MDPComp::idleInvalidator = NULL;
40bool MDPComp::sIdleFallBack = false;
41bool MDPComp::sDebugLogs = false;
Naseer Ahmed54821fe2012-11-28 18:44:38 -050042bool MDPComp::sEnabled = false;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -070043bool MDPComp::sEnableMixedMode = true;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -070044bool MDPComp::sEnablePartialFrameUpdate = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080045int MDPComp::sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
Saurabh Shah8c5c8522013-08-29 17:32:49 -070046float MDPComp::sMaxBw = 2.3f;
47uint32_t MDPComp::sCompBytesClaimed = 0;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070048
Saurabh Shah88e4d272013-09-03 13:31:29 -070049MDPComp* MDPComp::getObject(hwc_context_t *ctx, const int& dpy) {
50 if(isDisplaySplit(ctx, dpy)) {
51 return new MDPCompSplit(dpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080052 }
Saurabh Shah88e4d272013-09-03 13:31:29 -070053 return new MDPCompNonSplit(dpy);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080054}
55
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080056MDPComp::MDPComp(int dpy):mDpy(dpy){};
57
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080058void MDPComp::dump(android::String8& buf)
59{
Jeykumar Sankaran3c6bb042013-08-15 14:01:04 -070060 if(mCurrentFrame.layerCount > MAX_NUM_APP_LAYERS)
61 return;
62
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080063 dumpsys_log(buf,"HWC Map for Dpy: %s \n",
Jeykumar Sankaran27dee262013-08-01 17:09:54 -070064 (mDpy == 0) ? "\"PRIMARY\"" :
65 (mDpy == 1) ? "\"EXTERNAL\"" : "\"VIRTUAL\"");
Saurabh Shahe9bc60f2013-08-29 12:58:06 -070066 dumpsys_log(buf,"CURR_FRAME: layerCount:%2d mdpCount:%2d "
67 "fbCount:%2d \n", mCurrentFrame.layerCount,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080068 mCurrentFrame.mdpCount, mCurrentFrame.fbCount);
69 dumpsys_log(buf,"needsFBRedraw:%3s pipesUsed:%2d MaxPipesPerMixer: %d \n",
70 (mCurrentFrame.needsRedraw? "YES" : "NO"),
71 mCurrentFrame.mdpCount, sMaxPipesPerMixer);
72 dumpsys_log(buf," --------------------------------------------- \n");
73 dumpsys_log(buf," listIdx | cached? | mdpIndex | comptype | Z \n");
74 dumpsys_log(buf," --------------------------------------------- \n");
75 for(int index = 0; index < mCurrentFrame.layerCount; index++ )
76 dumpsys_log(buf," %7d | %7s | %8d | %9s | %2d \n",
77 index,
78 (mCurrentFrame.isFBComposed[index] ? "YES" : "NO"),
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -070079 mCurrentFrame.layerToMDP[index],
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080080 (mCurrentFrame.isFBComposed[index] ?
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -070081 (mCurrentFrame.drop[index] ? "DROP" :
82 (mCurrentFrame.needsRedraw ? "GLES" : "CACHE")) : "MDP"),
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080083 (mCurrentFrame.isFBComposed[index] ? mCurrentFrame.fbZ :
84 mCurrentFrame.mdpToLayer[mCurrentFrame.layerToMDP[index]].pipeInfo->zOrder));
85 dumpsys_log(buf,"\n");
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080086}
87
88bool MDPComp::init(hwc_context_t *ctx) {
89
90 if(!ctx) {
91 ALOGE("%s: Invalid hwc context!!",__FUNCTION__);
92 return false;
93 }
94
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080095 char property[PROPERTY_VALUE_MAX];
96
97 sEnabled = false;
98 if((property_get("persist.hwc.mdpcomp.enable", property, NULL) > 0) &&
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080099 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
100 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800101 sEnabled = true;
102 }
103
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700104 sEnableMixedMode = true;
105 if((property_get("debug.mdpcomp.mixedmode.disable", property, NULL) > 0) &&
106 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
107 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
108 sEnableMixedMode = false;
109 }
110
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800111 if(property_get("debug.mdpcomp.logs", property, NULL) > 0) {
112 if(atoi(property) != 0)
113 sDebugLogs = true;
114 }
115
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700116 if(property_get("persist.hwc.partialupdate.enable", property, NULL) > 0) {
117 if((atoi(property) != 0) && ctx->mMDP.panel == MIPI_CMD_PANEL &&
118 qdutils::MDPVersion::getInstance().is8x74v2())
119 sEnablePartialFrameUpdate = true;
120 }
121 ALOGE_IF(isDebug(), "%s: Partial Update applicable?: %d",__FUNCTION__,
122 sEnablePartialFrameUpdate);
123
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800124 sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
Saurabh Shah85234ec2013-04-12 17:09:00 -0700125 if(property_get("debug.mdpcomp.maxpermixer", property, "-1") > 0) {
126 int val = atoi(property);
127 if(val >= 0)
128 sMaxPipesPerMixer = min(val, MAX_PIPES_PER_MIXER);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800129 }
130
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700131 if(property_get("debug.mdpcomp.bw", property, "0") > 0) {
132 float val = atof(property);
133 if(val > 0.0f) {
134 sMaxBw = val;
135 }
136 }
137
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400138 if(ctx->mMDP.panel != MIPI_CMD_PANEL) {
139 // Idle invalidation is not necessary on command mode panels
140 long idle_timeout = DEFAULT_IDLE_TIME;
141 if(property_get("debug.mdpcomp.idletime", property, NULL) > 0) {
142 if(atoi(property) != 0)
143 idle_timeout = atoi(property);
144 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800145
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400146 //create Idle Invalidator only when not disabled through property
147 if(idle_timeout != -1)
148 idleInvalidator = IdleInvalidator::getInstance();
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800149
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400150 if(idleInvalidator == NULL) {
151 ALOGE("%s: failed to instantiate idleInvalidator object",
152 __FUNCTION__);
153 } else {
154 idleInvalidator->init(timeout_handler, ctx, idle_timeout);
155 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800156 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700157 return true;
158}
159
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700160void MDPComp::reset(const int& numLayers, hwc_display_contents_1_t* list) {
161 mCurrentFrame.reset(numLayers);
162 mCachedFrame.cacheAll(list);
163 mCachedFrame.updateCounts(mCurrentFrame);
164}
165
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700166void MDPComp::timeout_handler(void *udata) {
167 struct hwc_context_t* ctx = (struct hwc_context_t*)(udata);
168
169 if(!ctx) {
170 ALOGE("%s: received empty data in timer callback", __FUNCTION__);
171 return;
172 }
173
Jesse Hall3be78d92012-08-21 15:12:23 -0700174 if(!ctx->proc) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700175 ALOGE("%s: HWC proc not registered", __FUNCTION__);
176 return;
177 }
178 sIdleFallBack = true;
179 /* Trigger SF to redraw the current frame */
Jesse Hall3be78d92012-08-21 15:12:23 -0700180 ctx->proc->invalidate(ctx->proc);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700181}
182
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800183void MDPComp::setMDPCompLayerFlags(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800184 hwc_display_contents_1_t* list) {
185 LayerProp *layerProp = ctx->layerProp[mDpy];
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800186
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800187 for(int index = 0; index < ctx->listStats[mDpy].numAppLayers; index++) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800188 hwc_layer_1_t* layer = &(list->hwLayers[index]);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800189 if(!mCurrentFrame.isFBComposed[index]) {
190 layerProp[index].mFlags |= HWC_MDPCOMP;
191 layer->compositionType = HWC_OVERLAY;
192 layer->hints |= HWC_HINT_CLEAR_FB;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800193 } else {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700194 /* Drop the layer when its already present in FB OR when it lies
195 * outside frame's ROI */
196 if(!mCurrentFrame.needsRedraw || mCurrentFrame.drop[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800197 layer->compositionType = HWC_OVERLAY;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700198 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800199 }
200 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700201}
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500202
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800203MDPComp::FrameInfo::FrameInfo() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700204 reset(0);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800205}
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800206
Saurabh Shahaa236822013-04-24 18:07:26 -0700207void MDPComp::FrameInfo::reset(const int& numLayers) {
208 for(int i = 0 ; i < MAX_PIPES_PER_MIXER && numLayers; i++ ) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800209 if(mdpToLayer[i].pipeInfo) {
210 delete mdpToLayer[i].pipeInfo;
211 mdpToLayer[i].pipeInfo = NULL;
212 //We dont own the rotator
213 mdpToLayer[i].rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800214 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800215 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800216
217 memset(&mdpToLayer, 0, sizeof(mdpToLayer));
218 memset(&layerToMDP, -1, sizeof(layerToMDP));
Saurabh Shahaa236822013-04-24 18:07:26 -0700219 memset(&isFBComposed, 1, sizeof(isFBComposed));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800220
Saurabh Shahaa236822013-04-24 18:07:26 -0700221 layerCount = numLayers;
222 fbCount = numLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800223 mdpCount = 0;
Saurabh Shah2f3895f2013-05-02 10:13:31 -0700224 needsRedraw = true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800225 fbZ = 0;
226}
227
Saurabh Shahaa236822013-04-24 18:07:26 -0700228void MDPComp::FrameInfo::map() {
229 // populate layer and MDP maps
230 int mdpIdx = 0;
231 for(int idx = 0; idx < layerCount; idx++) {
232 if(!isFBComposed[idx]) {
233 mdpToLayer[mdpIdx].listIndex = idx;
234 layerToMDP[idx] = mdpIdx++;
235 }
236 }
237}
238
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800239MDPComp::LayerCache::LayerCache() {
240 reset();
241}
242
243void MDPComp::LayerCache::reset() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700244 memset(&hnd, 0, sizeof(hnd));
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530245 memset(&isFBComposed, true, sizeof(isFBComposed));
246 memset(&drop, false, sizeof(drop));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800247 layerCount = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -0700248}
249
250void MDPComp::LayerCache::cacheAll(hwc_display_contents_1_t* list) {
251 const int numAppLayers = list->numHwLayers - 1;
252 for(int i = 0; i < numAppLayers; i++) {
253 hnd[i] = list->hwLayers[i].handle;
254 }
255}
256
257void MDPComp::LayerCache::updateCounts(const FrameInfo& curFrame) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700258 layerCount = curFrame.layerCount;
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530259 memcpy(&isFBComposed, &curFrame.isFBComposed, sizeof(isFBComposed));
260 memcpy(&drop, &curFrame.drop, sizeof(drop));
261}
262
263bool MDPComp::LayerCache::isSameFrame(const FrameInfo& curFrame) {
264 if(layerCount != curFrame.layerCount)
265 return false;
266 for(int i = 0; i < curFrame.layerCount; i++) {
267 if((curFrame.isFBComposed[i] != isFBComposed[i]) ||
268 (curFrame.drop[i] != drop[i])) {
269 return false;
270 }
271 }
272 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800273}
274
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700275bool MDPComp::isSupportedForMDPComp(hwc_context_t *ctx, hwc_layer_1_t* layer) {
276 private_handle_t *hnd = (private_handle_t *)layer->handle;
277 if((not isYuvBuffer(hnd) and has90Transform(layer)) or
278 (not isValidDimension(ctx,layer))
279 //More conditions here, SKIP, sRGB+Blend etc
280 ) {
281 return false;
282 }
283 return true;
284}
285
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530286bool MDPComp::isValidDimension(hwc_context_t *ctx, hwc_layer_1_t *layer) {
Saurabh Shah4fdde762013-04-30 18:47:33 -0700287 const int dpy = HWC_DISPLAY_PRIMARY;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800288 private_handle_t *hnd = (private_handle_t *)layer->handle;
289
290 if(!hnd) {
291 ALOGE("%s: layer handle is NULL", __FUNCTION__);
292 return false;
293 }
294
Naseer Ahmede850a802013-09-06 13:12:52 -0400295 //XXX: Investigate doing this with pixel phase on MDSS
Naseer Ahmede77f8082013-10-10 13:42:48 -0400296 if(!isSecureBuffer(hnd) && isNonIntegralSourceCrop(layer->sourceCropf))
Naseer Ahmede850a802013-09-06 13:12:52 -0400297 return false;
298
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800299 int hw_w = ctx->dpyAttr[mDpy].xres;
300 int hw_h = ctx->dpyAttr[mDpy].yres;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800301
Saurabh Shah62e1d732013-09-17 10:44:05 -0700302 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700303 hwc_rect_t dst = layer->displayFrame;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800304
305 if(dst.left < 0 || dst.top < 0 || dst.right > hw_w || dst.bottom > hw_h) {
Saurabh Shah4fdde762013-04-30 18:47:33 -0700306 hwc_rect_t scissor = {0, 0, hw_w, hw_h };
307 qhwc::calculate_crop_rects(crop, dst, scissor, layer->transform);
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800308 }
309
Saurabh Shah4fdde762013-04-30 18:47:33 -0700310 int crop_w = crop.right - crop.left;
311 int crop_h = crop.bottom - crop.top;
312 int dst_w = dst.right - dst.left;
313 int dst_h = dst.bottom - dst.top;
314 float w_dscale = ceilf((float)crop_w / (float)dst_w);
315 float h_dscale = ceilf((float)crop_h / (float)dst_h);
316
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800317 /* Workaround for MDP HW limitation in DSI command mode panels where
318 * FPS will not go beyond 30 if buffers on RGB pipes are of width or height
319 * less than 5 pixels
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530320 * There also is a HW limilation in MDP, minimum block size is 2x2
321 * Fallback to GPU if height is less than 2.
322 */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800323 if((crop_w < 5)||(crop_h < 5))
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800324 return false;
325
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 Sankaran862d87c2013-11-08 16:47:26 -0800405/*
406 * 1) Identify layers that are not visible in the updating ROI and drop them
407 * from composition.
408 * 2) If we have a scaling layers which needs cropping against generated ROI.
409 * Reset ROI to full resolution.
410 */
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700411bool MDPComp::validateAndApplyROI(hwc_context_t *ctx,
412 hwc_display_contents_1_t* list, hwc_rect_t roi) {
413 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
414
415 if(!isValidRect(roi))
416 return false;
417
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800418 hwc_rect_t visibleRect = roi;
419
420 for(int i = numAppLayers - 1; i >= 0; i--){
421
422 if(!isValidRect(visibleRect)) {
423 mCurrentFrame.drop[i] = true;
424 mCurrentFrame.dropCount++;
425 }
426
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700427 const hwc_layer_1_t* layer = &list->hwLayers[i];
428
429 hwc_rect_t dstRect = layer->displayFrame;
Arun Kumar K.R91090c72013-10-28 19:40:18 -0700430 hwc_rect_t srcRect = integerizeSourceCrop(layer->sourceCropf);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700431 int transform = layer->transform;
432 trimLayer(ctx, mDpy, transform, srcRect, dstRect);
433
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800434 hwc_rect_t res = getIntersection(visibleRect, dstRect);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700435
436 int res_w = res.right - res.left;
437 int res_h = res.bottom - res.top;
438 int dst_w = dstRect.right - dstRect.left;
439 int dst_h = dstRect.bottom - dstRect.top;
440
441 if(!isValidRect(res)) {
442 mCurrentFrame.drop[i] = true;
443 mCurrentFrame.dropCount++;
444 }else {
445 /* Reset frame ROI when any layer which needs scaling also needs ROI
446 * cropping */
447 if((res_w != dst_w || res_h != dst_h) &&
448 needsScaling (ctx, layer, mDpy)) {
449 ALOGE("%s: Resetting ROI due to scaling", __FUNCTION__);
450 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
451 mCurrentFrame.dropCount = 0;
452 return false;
453 }
454 }
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800455
456 if (layer->blending == HWC_BLENDING_NONE)
457 visibleRect = deductRect(visibleRect, res);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700458 }
459 return true;
460}
461
462void MDPComp::generateROI(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
463 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
464
465 if(!sEnablePartialFrameUpdate) {
466 return;
467 }
468
469 if(mDpy || isDisplaySplit(ctx, mDpy)){
470 ALOGE_IF(isDebug(), "%s: ROI not supported for"
471 "the (1) external / virtual display's (2) dual DSI displays",
472 __FUNCTION__);
473 return;
474 }
475
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800476 if(isSkipPresent(ctx, mDpy))
477 return;
478
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700479 if(list->flags & HWC_GEOMETRY_CHANGED)
480 return;
481
482 struct hwc_rect roi = (struct hwc_rect){0, 0, 0, 0};
483 for(int index = 0; index < numAppLayers; index++ ) {
484 if ((mCachedFrame.hnd[index] != list->hwLayers[index].handle) ||
485 isYuvBuffer((private_handle_t *)list->hwLayers[index].handle)) {
486 hwc_rect_t dstRect = list->hwLayers[index].displayFrame;
Arun Kumar K.R91090c72013-10-28 19:40:18 -0700487 hwc_rect_t srcRect = integerizeSourceCrop(
488 list->hwLayers[index].sourceCropf);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700489 int transform = list->hwLayers[index].transform;
490
491 /* Intersect against display boundaries */
492 trimLayer(ctx, mDpy, transform, srcRect, dstRect);
493 roi = getUnion(roi, dstRect);
494 }
495 }
496
497 if(!validateAndApplyROI(ctx, list, roi)){
498 roi = (struct hwc_rect) {0, 0,
499 (int)ctx->dpyAttr[mDpy].xres, (int)ctx->dpyAttr[mDpy].yres};
500 }
501
502 ctx->listStats[mDpy].roi.x = roi.left;
503 ctx->listStats[mDpy].roi.y = roi.top;
504 ctx->listStats[mDpy].roi.w = roi.right - roi.left;
505 ctx->listStats[mDpy].roi.h = roi.bottom - roi.top;
506
507 ALOGD_IF(isDebug(),"%s: generated ROI: [%d, %d, %d, %d]", __FUNCTION__,
508 roi.left, roi.top, roi.right, roi.bottom);
509}
510
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800511/* Checks for conditions where all the layers marked for MDP comp cannot be
512 * bypassed. On such conditions we try to bypass atleast YUV layers */
513bool MDPComp::isFullFrameDoable(hwc_context_t *ctx,
514 hwc_display_contents_1_t* list){
515
Saurabh Shahaa236822013-04-24 18:07:26 -0700516 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800517
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -0700518 if(sIdleFallBack && !ctx->listStats[mDpy].secureUI) {
Saurabh Shah2d998a92013-05-14 17:55:58 -0700519 ALOGD_IF(isDebug(), "%s: Idle fallback dpy %d",__FUNCTION__, mDpy);
520 return false;
521 }
522
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800523 if(isSkipPresent(ctx, mDpy)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700524 ALOGD_IF(isDebug(),"%s: SKIP present: %d",
525 __FUNCTION__,
526 isSkipPresent(ctx, mDpy));
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800527 return false;
528 }
529
Saurabh Shah9f084ad2013-05-02 11:28:09 -0700530 if(ctx->listStats[mDpy].needsAlphaScale
531 && ctx->mMDP.version < qdutils::MDSS_V5) {
532 ALOGD_IF(isDebug(), "%s: frame needs alpha downscaling",__FUNCTION__);
533 return false;
534 }
535
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800536 for(int i = 0; i < numAppLayers; ++i) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800537 hwc_layer_1_t* layer = &list->hwLayers[i];
538 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800539
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700540 if(isYuvBuffer(hnd) && has90Transform(layer)) {
541 if(!canUseRotator(ctx, mDpy)) {
542 ALOGD_IF(isDebug(), "%s: Can't use rotator for dpy %d",
543 __FUNCTION__, mDpy);
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700544 return false;
545 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800546 }
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530547
548 //For 8x26 with panel width>1k, if RGB layer needs HFLIP fail mdp comp
549 // may not need it if Gfx pre-rotation can handle all flips & rotations
550 if(qdutils::MDPVersion::getInstance().is8x26() &&
551 (ctx->dpyAttr[mDpy].xres > 1024) &&
552 (layer->transform & HWC_TRANSFORM_FLIP_H) &&
553 (!isYuvBuffer(hnd)))
554 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800555 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700556
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700557 if(ctx->mAD->isDoable()) {
558 return false;
559 }
560
Saurabh Shahaa236822013-04-24 18:07:26 -0700561 //If all above hard conditions are met we can do full or partial MDP comp.
562 bool ret = false;
563 if(fullMDPComp(ctx, list)) {
564 ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700565 } else if(partialMDPComp(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700566 ret = true;
567 }
568 return ret;
569}
570
571bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700572 //Will benefit presentation / secondary-only layer.
573 if((mDpy > HWC_DISPLAY_PRIMARY) &&
574 (list->numHwLayers - 1) > MAX_SEC_LAYERS) {
575 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
576 return false;
577 }
578
579 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
580 for(int i = 0; i < numAppLayers; i++) {
581 hwc_layer_1_t* layer = &list->hwLayers[i];
582 if(not isSupportedForMDPComp(ctx, layer)) {
583 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",__FUNCTION__);
584 return false;
585 }
586 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700587 mCurrentFrame.fbCount = 0;
588 mCurrentFrame.fbZ = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700589 memcpy(&mCurrentFrame.isFBComposed, &mCurrentFrame.drop,
590 sizeof(mCurrentFrame.isFBComposed));
591 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount -
592 mCurrentFrame.dropCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700593
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700594 if(mCurrentFrame.mdpCount > sMaxPipesPerMixer) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700595 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
596 return false;
597 }
598
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700599 if(!arePipesAvailable(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700600 return false;
601 }
602
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700603 uint32_t size = calcMDPBytesRead(ctx, list);
604 if(!bandwidthCheck(ctx, size)) {
605 ALOGD_IF(isDebug(), "%s: Exceeds bandwidth",__FUNCTION__);
606 return false;
607 }
608
Saurabh Shahaa236822013-04-24 18:07:26 -0700609 return true;
610}
611
612bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
613{
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700614 if(!sEnableMixedMode) {
615 //Mixed mode is disabled. No need to even try caching.
616 return false;
617 }
618
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700619 bool ret = false;
620 if(isLoadBasedCompDoable(ctx, list)) {
621 ret = loadBasedComp(ctx, list);
622 }
623
624 if(!ret) {
625 ret = cacheBasedComp(ctx, list);
626 }
627
628 return ret;
629}
630
631bool MDPComp::cacheBasedComp(hwc_context_t *ctx,
632 hwc_display_contents_1_t* list) {
633 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700634 mCurrentFrame.reset(numAppLayers);
635 updateLayerCache(ctx, list);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700636
637 //If an MDP marked layer is unsupported cannot do partial MDP Comp
638 for(int i = 0; i < numAppLayers; i++) {
639 if(!mCurrentFrame.isFBComposed[i]) {
640 hwc_layer_1_t* layer = &list->hwLayers[i];
641 if(not isSupportedForMDPComp(ctx, layer)) {
642 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",
643 __FUNCTION__);
644 return false;
645 }
646 }
647 }
648
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700649 updateYUV(ctx, list, false /*secure only*/);
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530650 bool ret = markLayersForCaching(ctx, list); //sets up fbZ also
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700651 if(!ret) {
652 ALOGD_IF(isDebug(),"%s: batching failed, dpy %d",__FUNCTION__, mDpy);
653 return false;
654 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700655
656 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700657
658 //Will benefit cases where a video has non-updating background.
659 if((mDpy > HWC_DISPLAY_PRIMARY) and
660 (mdpCount > MAX_SEC_LAYERS)) {
661 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
662 return false;
663 }
664
Saurabh Shahaa236822013-04-24 18:07:26 -0700665 if(mdpCount > (sMaxPipesPerMixer - 1)) { // -1 since FB is used
666 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
667 return false;
668 }
669
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700670 if(!arePipesAvailable(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700671 return false;
672 }
673
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700674 uint32_t size = calcMDPBytesRead(ctx, list);
675 if(!bandwidthCheck(ctx, size)) {
676 ALOGD_IF(isDebug(), "%s: Exceeds bandwidth",__FUNCTION__);
677 return false;
678 }
679
Saurabh Shahaa236822013-04-24 18:07:26 -0700680 return true;
681}
682
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700683bool MDPComp::loadBasedComp(hwc_context_t *ctx,
684 hwc_display_contents_1_t* list) {
685 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
686 mCurrentFrame.reset(numAppLayers);
687
688 //TODO BatchSize could be optimized further based on available pipes, split
689 //displays etc.
690 const int batchSize = numAppLayers - (sMaxPipesPerMixer - 1);
691 if(batchSize <= 0) {
692 ALOGD_IF(isDebug(), "%s: Not attempting", __FUNCTION__);
693 return false;
694 }
695
696 int minBatchStart = -1;
697 size_t minBatchPixelCount = SIZE_MAX;
698
699 for(int i = 0; i <= numAppLayers - batchSize; i++) {
700 uint32_t batchPixelCount = 0;
701 for(int j = i; j < i + batchSize; j++) {
702 hwc_layer_1_t* layer = &list->hwLayers[j];
Arun Kumar K.R91090c72013-10-28 19:40:18 -0700703 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700704 batchPixelCount += (crop.right - crop.left) *
705 (crop.bottom - crop.top);
706 }
707
708 if(batchPixelCount < minBatchPixelCount) {
709 minBatchPixelCount = batchPixelCount;
710 minBatchStart = i;
711 }
712 }
713
714 if(minBatchStart < 0) {
715 ALOGD_IF(isDebug(), "%s: No batch found batchSize %d numAppLayers %d",
716 __FUNCTION__, batchSize, numAppLayers);
717 return false;
718 }
719
720 for(int i = 0; i < numAppLayers; i++) {
721 if(i < minBatchStart || i >= minBatchStart + batchSize) {
722 hwc_layer_1_t* layer = &list->hwLayers[i];
723 if(not isSupportedForMDPComp(ctx, layer)) {
724 ALOGD_IF(isDebug(), "%s: MDP unsupported layer found at %d",
725 __FUNCTION__, i);
726 return false;
727 }
728 mCurrentFrame.isFBComposed[i] = false;
729 }
730 }
731
732 mCurrentFrame.fbZ = minBatchStart;
733 mCurrentFrame.fbCount = batchSize;
734 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - batchSize;
735
736 if(!arePipesAvailable(ctx, list)) {
737 return false;
738 }
739
740 ALOGD_IF(isDebug(), "%s: fbZ %d batchSize %d",
741 __FUNCTION__, mCurrentFrame.fbZ, batchSize);
742 return true;
743}
744
745bool MDPComp::isLoadBasedCompDoable(hwc_context_t *ctx,
746 hwc_display_contents_1_t* list) {
747 if(mDpy or isSecurePresent(ctx, mDpy) or
748 not (list->flags & HWC_GEOMETRY_CHANGED)) {
749 return false;
750 }
751 return true;
752}
753
Saurabh Shahaa236822013-04-24 18:07:26 -0700754bool MDPComp::isOnlyVideoDoable(hwc_context_t *ctx,
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700755 hwc_display_contents_1_t* list, bool secureOnly) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700756 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700757
Saurabh Shahaa236822013-04-24 18:07:26 -0700758 mCurrentFrame.reset(numAppLayers);
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700759 updateYUV(ctx, list, secureOnly);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700760 int mdpCount = mCurrentFrame.mdpCount;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700761 int fbNeeded = (mCurrentFrame.fbCount != 0);
Saurabh Shahaa236822013-04-24 18:07:26 -0700762
763 if(!isYuvPresent(ctx, mDpy)) {
764 return false;
765 }
766
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -0800767 /* Bail out if we are processing only secured video layers
768 * and we dont have any */
769 if(!isSecurePresent(ctx, mDpy) && secureOnly){
770 return false;
771 }
772
Saurabh Shah4fdde762013-04-30 18:47:33 -0700773 if(!mdpCount)
774 return false;
775
Saurabh Shahaa236822013-04-24 18:07:26 -0700776 if(mdpCount > (sMaxPipesPerMixer - fbNeeded)) {
777 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
778 return false;
779 }
780
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700781 if(!arePipesAvailable(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700782 return false;
783 }
784
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700785 uint32_t size = calcMDPBytesRead(ctx, list);
786 if(!bandwidthCheck(ctx, size)) {
787 ALOGD_IF(isDebug(), "%s: Exceeds bandwidth",__FUNCTION__);
788 return false;
789 }
790
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800791 return true;
792}
793
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800794/* Checks for conditions where YUV layers cannot be bypassed */
795bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Saurabh Shahe2474082013-05-15 16:32:13 -0700796 bool extAnimBlockFeature = mDpy && ctx->listStats[mDpy].isDisplayAnimating;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800797
Saurabh Shahe2474082013-05-15 16:32:13 -0700798 if(isSkipLayer(layer) && !extAnimBlockFeature) {
799 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800800 return false;
801 }
802
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700803 if(layer->transform & HWC_TRANSFORM_ROT_90 && !canUseRotator(ctx,mDpy)) {
804 ALOGD_IF(isDebug(), "%s: no free DMA pipe",__FUNCTION__);
805 return false;
806 }
807
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800808 if(isSecuring(ctx, layer)) {
809 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
810 return false;
811 }
812
Saurabh Shah4fdde762013-04-30 18:47:33 -0700813 if(!isValidDimension(ctx, layer)) {
814 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
815 __FUNCTION__);
816 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800817 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700818
Naseer Ahmeddc61a972013-07-10 17:50:54 -0400819 if(layer->planeAlpha < 0xFF) {
820 ALOGD_IF(isDebug(), "%s: Cannot handle YUV layer with plane alpha\
821 in video only mode",
822 __FUNCTION__);
823 return false;
824 }
825
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800826 return true;
827}
828
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530829/* starts at fromIndex and check for each layer to find
830 * if it it has overlapping with any Updating layer above it in zorder
831 * till the end of the batch. returns true if it finds any intersection */
832bool MDPComp::canPushBatchToTop(const hwc_display_contents_1_t* list,
833 int fromIndex, int toIndex) {
834 for(int i = fromIndex; i < toIndex; i++) {
835 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
836 if(intersectingUpdatingLayers(list, i+1, toIndex, i)) {
837 return false;
838 }
839 }
840 }
841 return true;
842}
843
844/* Checks if given layer at targetLayerIndex has any
845 * intersection with all the updating layers in beween
846 * fromIndex and toIndex. Returns true if it finds intersectiion */
847bool MDPComp::intersectingUpdatingLayers(const hwc_display_contents_1_t* list,
848 int fromIndex, int toIndex, int targetLayerIndex) {
849 for(int i = fromIndex; i <= toIndex; i++) {
850 if(!mCurrentFrame.isFBComposed[i]) {
851 if(areLayersIntersecting(&list->hwLayers[i],
852 &list->hwLayers[targetLayerIndex])) {
853 return true;
854 }
855 }
856 }
857 return false;
858}
859
860int MDPComp::getBatch(hwc_display_contents_1_t* list,
861 int& maxBatchStart, int& maxBatchEnd,
862 int& maxBatchCount) {
863 int i = 0;
864 int updatingLayersAbove = 0;//Updating layer count in middle of batch
865 int fbZOrder =-1;
866 while (i < mCurrentFrame.layerCount) {
867 int batchCount = 0;
868 int batchStart = i;
869 int batchEnd = i;
870 int fbZ = batchStart;
871 int firstZReverseIndex = -1;
872 while(i < mCurrentFrame.layerCount) {
873 if(!mCurrentFrame.isFBComposed[i]) {
874 if(!batchCount) {
875 i++;
876 break;
877 }
878 updatingLayersAbove++;
879 i++;
880 continue;
881 } else {
882 if(mCurrentFrame.drop[i]) {
883 i++;
884 continue;
885 } else if(updatingLayersAbove <= 0) {
886 batchCount++;
887 batchEnd = i;
888 i++;
889 continue;
890 } else { //Layer is FBComposed, not a drop & updatingLayer > 0
891
892 // We have a valid updating layer already. If layer-i not
893 // have overlapping with all updating layers in between
894 // batch-start and i, then we can add layer i to batch.
895 if(!intersectingUpdatingLayers(list, batchStart, i-1, i)) {
896 batchCount++;
897 batchEnd = i;
898 i++;
899 continue;
900 } else if(canPushBatchToTop(list, batchStart, i)) {
901 //If All the non-updating layers with in this batch
902 //does not have intersection with the updating layers
903 //above in z-order, then we can safely move the batch to
904 //higher z-order. Increment fbZ as it is moving up.
905 if( firstZReverseIndex < 0) {
906 firstZReverseIndex = i;
907 }
908 batchCount++;
909 batchEnd = i;
910 fbZ += updatingLayersAbove;
911 i++;
912 updatingLayersAbove = 0;
913 continue;
914 } else {
915 //both failed.start the loop again from here.
916 if(firstZReverseIndex >= 0) {
917 i = firstZReverseIndex;
918 }
919 break;
920 }
921 }
922 }
923 }
924 if(batchCount > maxBatchCount) {
925 maxBatchCount = batchCount;
926 maxBatchStart = batchStart;
927 maxBatchEnd = batchEnd;
928 fbZOrder = fbZ;
929 }
930 }
931 return fbZOrder;
932}
933
934bool MDPComp::markLayersForCaching(hwc_context_t* ctx,
935 hwc_display_contents_1_t* list) {
936 /* Idea is to keep as many non-updating(cached) layers in FB and
937 * send rest of them through MDP. This is done in 2 steps.
938 * 1. Find the maximum contiguous batch of non-updating layers.
939 * 2. See if we can improve this batch size for caching by adding
940 * opaque layers around the batch, if they don't have
941 * any overlapping with the updating layers in between.
942 * NEVER mark an updating layer for caching.
943 * But cached ones can be marked for MDP */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800944
945 int maxBatchStart = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700946 int maxBatchEnd = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800947 int maxBatchCount = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530948 int fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800949
950 /* All or Nothing is cached. No batching needed */
Saurabh Shahaa236822013-04-24 18:07:26 -0700951 if(!mCurrentFrame.fbCount) {
952 mCurrentFrame.fbZ = -1;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700953 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -0700954 }
955 if(!mCurrentFrame.mdpCount) {
956 mCurrentFrame.fbZ = 0;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700957 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -0700958 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800959
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530960 fbZ = getBatch(list, maxBatchStart, maxBatchEnd, maxBatchCount);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800961
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530962 /* reset rest of the layers lying inside ROI for MDP comp */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800963 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700964 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700965 if((i < maxBatchStart || i > maxBatchEnd) &&
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530966 mCurrentFrame.isFBComposed[i]){
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700967 if(!mCurrentFrame.drop[i]){
968 //If an unsupported layer is being attempted to
969 //be pulled out we should fail
970 if(not isSupportedForMDPComp(ctx, layer)) {
971 return false;
972 }
973 mCurrentFrame.isFBComposed[i] = false;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700974 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800975 }
976 }
977
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530978 // update the frame data
979 mCurrentFrame.fbZ = fbZ;
980 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700981 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700982 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800983
984 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530985 mCurrentFrame.fbCount);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700986
987 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800988}
Saurabh Shah85234ec2013-04-12 17:09:00 -0700989
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800990void MDPComp::updateLayerCache(hwc_context_t* ctx,
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700991 hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800992 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700993 int fbCount = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800994
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800995 for(int i = 0; i < numAppLayers; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700996 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800997 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700998 if(!mCurrentFrame.drop[i])
999 fbCount++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001000 mCurrentFrame.isFBComposed[i] = true;
1001 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -07001002 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001003 mCachedFrame.hnd[i] = list->hwLayers[i].handle;
1004 }
1005 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001006
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001007 mCurrentFrame.fbCount = fbCount;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001008 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount
1009 - mCurrentFrame.dropCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001010
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001011 ALOGD_IF(isDebug(),"%s: MDP count: %d FB count %d drop count: %d"
1012 ,__FUNCTION__, mCurrentFrame.mdpCount, mCurrentFrame.fbCount,
1013 mCurrentFrame.dropCount);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001014}
1015
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001016void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list,
1017 bool secureOnly) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001018 int nYuvCount = ctx->listStats[mDpy].yuvCount;
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001019 if(!nYuvCount && mDpy) {
1020 //Reset "No animation on external display" related parameters.
1021 ctx->mPrevCropVideo.left = ctx->mPrevCropVideo.top =
1022 ctx->mPrevCropVideo.right = ctx->mPrevCropVideo.bottom = 0;
1023 ctx->mPrevDestVideo.left = ctx->mPrevDestVideo.top =
1024 ctx->mPrevDestVideo.right = ctx->mPrevDestVideo.bottom = 0;
1025 ctx->mPrevTransformVideo = 0;
1026 return;
1027 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001028 for(int index = 0;index < nYuvCount; index++){
1029 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
1030 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
1031
1032 if(!isYUVDoable(ctx, layer)) {
1033 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
1034 mCurrentFrame.isFBComposed[nYuvIndex] = true;
1035 mCurrentFrame.fbCount++;
1036 }
1037 } else {
1038 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001039 private_handle_t *hnd = (private_handle_t *)layer->handle;
1040 if(!secureOnly || isSecureBuffer(hnd)) {
1041 mCurrentFrame.isFBComposed[nYuvIndex] = false;
1042 mCurrentFrame.fbCount--;
1043 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001044 }
1045 }
1046 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001047
1048 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001049 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
1050 ALOGD_IF(isDebug(),"%s: fb count: %d",__FUNCTION__,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001051 mCurrentFrame.fbCount);
1052}
1053
Saurabh Shahaa236822013-04-24 18:07:26 -07001054bool MDPComp::programMDP(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001055 if(!allocLayerPipes(ctx, list)) {
1056 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -07001057 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001058 }
1059
1060 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001061 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001062 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001063 int mdpIndex = mCurrentFrame.layerToMDP[index];
1064 hwc_layer_1_t* layer = &list->hwLayers[index];
1065
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301066 //Leave fbZ for framebuffer. CACHE/GLES layers go here.
1067 if(mdpNextZOrder == mCurrentFrame.fbZ) {
1068 mdpNextZOrder++;
1069 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001070 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1071 cur_pipe->zOrder = mdpNextZOrder++;
1072
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301073
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001074 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
1075 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
1076 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -07001077 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001078 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001079 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001080 }
1081
Saurabh Shahaa236822013-04-24 18:07:26 -07001082 return true;
1083}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001084
Saurabh Shahaa236822013-04-24 18:07:26 -07001085bool MDPComp::programYUV(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
1086 if(!allocLayerPipes(ctx, list)) {
1087 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
1088 return false;
1089 }
1090 //If we are in this block, it means we have yuv + rgb layers both
1091 int mdpIdx = 0;
1092 for (int index = 0; index < mCurrentFrame.layerCount; index++) {
1093 if(!mCurrentFrame.isFBComposed[index]) {
1094 hwc_layer_1_t* layer = &list->hwLayers[index];
1095 int mdpIndex = mCurrentFrame.layerToMDP[index];
1096 MdpPipeInfo* cur_pipe =
1097 mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1098 cur_pipe->zOrder = mdpIdx++;
1099
1100 if(configure(ctx, layer,
1101 mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
1102 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
1103 layer %d",__FUNCTION__, index);
1104 return false;
1105 }
1106 }
1107 }
1108 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001109}
1110
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001111uint32_t MDPComp::calcMDPBytesRead(hwc_context_t *ctx,
1112 hwc_display_contents_1_t* list) {
1113 uint32_t size = 0;
1114
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001115 if(!qdutils::MDPVersion::getInstance().is8x74v2())
1116 return 0;
1117
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001118 for (uint32_t i = 0; i < list->numHwLayers - 1; i++) {
1119 if(!mCurrentFrame.isFBComposed[i]) {
1120 hwc_layer_1_t* layer = &list->hwLayers[i];
1121 private_handle_t *hnd = (private_handle_t *)layer->handle;
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001122 if (hnd) {
Saurabh Shah62e1d732013-09-17 10:44:05 -07001123 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah90789162013-09-16 10:29:20 -07001124 hwc_rect_t dst = layer->displayFrame;
1125 trimLayer(ctx, mDpy, layer->transform, crop, dst);
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001126 float bpp = ((float)hnd->size) / (hnd->width * hnd->height);
Saurabh Shah90789162013-09-16 10:29:20 -07001127 size += bpp * (crop.right - crop.left) *
1128 (crop.bottom - crop.top) *
1129 ctx->dpyAttr[mDpy].yres / (dst.bottom - dst.top);
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001130 }
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001131 }
1132 }
1133
1134 if(mCurrentFrame.fbCount) {
1135 hwc_layer_1_t* layer = &list->hwLayers[list->numHwLayers - 1];
1136 private_handle_t *hnd = (private_handle_t *)layer->handle;
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001137 if (hnd)
1138 size += hnd->size;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001139 }
1140
1141 return size;
1142}
1143
1144bool MDPComp::bandwidthCheck(hwc_context_t *ctx, const uint32_t& size) {
1145 //Will be added for other targets if we run into bandwidth issues and when
1146 //we have profiling data to set an upper limit.
1147 if(qdutils::MDPVersion::getInstance().is8x74v2()) {
1148 const uint32_t ONE_GIG = 1024 * 1024 * 1024;
1149 double panelRefRate =
1150 1000000000.0 / ctx->dpyAttr[mDpy].vsync_period;
1151 if((size + sCompBytesClaimed) > ((sMaxBw / panelRefRate) * ONE_GIG)) {
1152 return false;
1153 }
1154 }
1155 return true;
1156}
1157
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001158int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001159 int ret = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -07001160 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -07001161
Saurabh Shahb39f8152013-08-22 10:21:44 -07001162 //reset old data
1163 mCurrentFrame.reset(numLayers);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001164 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1165 mCurrentFrame.dropCount = 0;
Prabhanjan Kandula088bd892013-07-02 23:47:13 +05301166
Saurabh Shahb39f8152013-08-22 10:21:44 -07001167 //number of app layers exceeds MAX_NUM_APP_LAYERS fall back to GPU
1168 //do not cache the information for next draw cycle.
1169 if(numLayers > MAX_NUM_APP_LAYERS) {
Prabhanjan Kandula25469a52013-07-12 16:19:31 +05301170 mCachedFrame.updateCounts(mCurrentFrame);
Tatenda Chipeperekwa835337a2013-09-27 16:58:43 -07001171 ALOGE("%s: Number of App layers exceeded the limit ",
1172 __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001173 ret = -1;
Tatenda Chipeperekwa835337a2013-09-27 16:58:43 -07001174 return ret;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001175 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001176
Saurabh Shahb39f8152013-08-22 10:21:44 -07001177 //Hard conditions, if not met, cannot do MDP comp
1178 if(!isFrameDoable(ctx)) {
1179 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
1180 __FUNCTION__);
1181 reset(numLayers, list);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001182 ret = -1;
1183 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001184 }
1185
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001186 generateROI(ctx, list);
1187
Saurabh Shahb39f8152013-08-22 10:21:44 -07001188 //Check whether layers marked for MDP Composition is actually doable.
1189 if(isFullFrameDoable(ctx, list)) {
1190 mCurrentFrame.map();
1191 //Configure framebuffer first if applicable
1192 if(mCurrentFrame.fbZ >= 0) {
1193 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list,
1194 mCurrentFrame.fbZ)) {
1195 ALOGE("%s configure framebuffer failed", __func__);
1196 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -07001197 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001198 ret = -1;
1199 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001200 }
1201 }
1202 //Acquire and Program MDP pipes
1203 if(!programMDP(ctx, list)) {
1204 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -07001205 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001206 ret = -1;
1207 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001208 } else { //Success
1209 //Any change in composition types needs an FB refresh
1210 mCurrentFrame.needsRedraw = false;
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +05301211 if(!mCachedFrame.isSameFrame(mCurrentFrame) ||
Saurabh Shahb39f8152013-08-22 10:21:44 -07001212 (list->flags & HWC_GEOMETRY_CHANGED) ||
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +05301213 isSkipPresent(ctx, mDpy)) {
Saurabh Shahb39f8152013-08-22 10:21:44 -07001214 mCurrentFrame.needsRedraw = true;
1215 }
1216 }
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001217 } else if(isOnlyVideoDoable(ctx, list, false /*secure only*/) ||
1218 isOnlyVideoDoable(ctx, list, true /*secure only*/)) {
Saurabh Shahb39f8152013-08-22 10:21:44 -07001219 //All layers marked for MDP comp cannot be bypassed.
1220 //Try to compose atleast YUV layers through MDP comp and let
1221 //all the RGB layers compose in FB
1222 //Destination over
1223 mCurrentFrame.fbZ = -1;
1224 if(mCurrentFrame.fbCount)
1225 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
1226
1227 mCurrentFrame.map();
1228
1229 //Configure framebuffer first if applicable
1230 if(mCurrentFrame.fbZ >= 0) {
1231 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, mCurrentFrame.fbZ)) {
1232 ALOGE("%s configure framebuffer failed", __func__);
1233 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -07001234 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001235 ret = -1;
1236 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001237 }
1238 }
1239 if(!programYUV(ctx, list)) {
1240 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -07001241 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001242 ret = -1;
1243 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001244 }
1245 } else {
1246 reset(numLayers, list);
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -08001247 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1248 mCurrentFrame.dropCount = 0;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001249 ret = -1;
1250 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001251 }
Saurabh Shahb39f8152013-08-22 10:21:44 -07001252 //UpdateLayerFlags
1253 setMDPCompLayerFlags(ctx, list);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001254 mCachedFrame.cacheAll(list);
Saurabh Shahb39f8152013-08-22 10:21:44 -07001255 mCachedFrame.updateCounts(mCurrentFrame);
1256
Prabhanjan Kandula25469a52013-07-12 16:19:31 +05301257 // unlock it before calling dump function to avoid deadlock
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001258 if(isDebug()) {
Saurabh Shahaa236822013-04-24 18:07:26 -07001259 ALOGD("GEOMETRY change: %d", (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001260 android::String8 sDump("");
1261 dump(sDump);
1262 ALOGE("%s",sDump.string());
1263 }
1264
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001265exit:
1266 sCompBytesClaimed += calcMDPBytesRead(ctx, list);
1267 return ret;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001268}
1269
Saurabh Shah88e4d272013-09-03 13:31:29 -07001270//=============MDPCompNonSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001271
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001272/*
1273 * Configures pipe(s) for MDP composition
1274 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001275int MDPCompNonSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001276 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001277 MdpPipeInfoNonSplit& mdp_info =
1278 *(static_cast<MdpPipeInfoNonSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001279 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
1280 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1281 eIsFg isFg = IS_FG_OFF;
1282 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001283
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001284 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
1285 __FUNCTION__, layer, zOrder, dest);
1286
Saurabh Shah88e4d272013-09-03 13:31:29 -07001287 return configureNonSplit(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001288 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001289}
1290
Saurabh Shah88e4d272013-09-03 13:31:29 -07001291bool MDPCompNonSplit::arePipesAvailable(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001292 hwc_display_contents_1_t* list) {
1293 overlay::Overlay& ov = *ctx->mOverlay;
1294 int numPipesNeeded = mCurrentFrame.mdpCount;
1295 int availPipes = ov.availablePipes(mDpy, Overlay::MIXER_DEFAULT);
1296
1297 //Reserve pipe for FB
1298 if(mCurrentFrame.fbCount)
1299 availPipes -= 1;
1300
1301 if(numPipesNeeded > availPipes) {
1302 ALOGD_IF(isDebug(), "%s: Insufficient pipes, dpy %d needed %d, avail %d",
1303 __FUNCTION__, mDpy, numPipesNeeded, availPipes);
1304 return false;
1305 }
1306
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001307 if(not areVGPipesAvailable(ctx, list)) {
1308 return false;
1309 }
1310
1311 return true;
1312}
1313
1314bool MDPCompNonSplit::areVGPipesAvailable(hwc_context_t *ctx,
1315 hwc_display_contents_1_t* list) {
1316 overlay::Overlay& ov = *ctx->mOverlay;
1317 int pipesNeeded = 0;
1318 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1319 if(!mCurrentFrame.isFBComposed[i]) {
1320 hwc_layer_1_t* layer = &list->hwLayers[i];
1321 hwc_rect_t dst = layer->displayFrame;
1322 private_handle_t *hnd = (private_handle_t *)layer->handle;
1323 if(isYuvBuffer(hnd)) {
1324 pipesNeeded++;
1325 }
1326 }
1327 }
1328
1329 int availableVGPipes = ov.availablePipes(mDpy, ovutils::OV_MDP_PIPE_VG);
1330 if(pipesNeeded > availableVGPipes) {
1331 ALOGD_IF(isDebug(), "%s: Insufficient VG pipes for video layers"
1332 "dpy %d needed %d, avail %d",
1333 __FUNCTION__, mDpy, pipesNeeded, availableVGPipes);
1334 return false;
1335 }
1336
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001337 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001338}
1339
Saurabh Shah88e4d272013-09-03 13:31:29 -07001340bool MDPCompNonSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001341 hwc_display_contents_1_t* list) {
1342 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001343
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001344 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001345
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001346 hwc_layer_1_t* layer = &list->hwLayers[index];
1347 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001348 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001349 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001350 info.pipeInfo = new MdpPipeInfoNonSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08001351 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001352 MdpPipeInfoNonSplit& pipe_info = *(MdpPipeInfoNonSplit*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001353 ePipeType type = MDPCOMP_OV_ANY;
1354
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001355 if(isYuvBuffer(hnd)) {
1356 type = MDPCOMP_OV_VG;
Saurabh Shah8a117932013-05-23 12:48:13 -07001357 } else if(!qhwc::needsScaling(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001358 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
1359 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001360 type = MDPCOMP_OV_DMA;
1361 }
1362
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001363 pipe_info.index = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001364 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001365 ALOGD_IF(isDebug(), "%s: Unable to get pipe type = %d",
1366 __FUNCTION__, (int) type);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001367 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001368 }
1369 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001370 return true;
1371}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001372
Saurabh Shah88e4d272013-09-03 13:31:29 -07001373bool MDPCompNonSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001374
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001375 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001376 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1377 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -08001378 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001379
1380 if(!ctx || !list) {
1381 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001382 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001383 }
1384
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301385 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1386 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1387 return true;
1388 }
1389
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001390 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001391 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001392 idleInvalidator->markForSleep();
1393
1394 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001395 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001396
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001397 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1398 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001399 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001400 if(mCurrentFrame.isFBComposed[i]) continue;
1401
Naseer Ahmed5b6708a2012-08-02 13:46:08 -07001402 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001403 private_handle_t *hnd = (private_handle_t *)layer->handle;
1404 if(!hnd) {
1405 ALOGE("%s handle null", __FUNCTION__);
1406 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001407 }
1408
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001409 int mdpIndex = mCurrentFrame.layerToMDP[i];
1410
Saurabh Shah88e4d272013-09-03 13:31:29 -07001411 MdpPipeInfoNonSplit& pipe_info =
1412 *(MdpPipeInfoNonSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001413 ovutils::eDest dest = pipe_info.index;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001414 if(dest == ovutils::OV_INVALID) {
1415 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001416 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001417 }
1418
Saurabh Shahacf10202013-02-26 10:15:15 -08001419 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1420 continue;
1421 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001422
Saurabh Shahacf10202013-02-26 10:15:15 -08001423 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001424 using pipe: %d", __FUNCTION__, layer,
1425 hnd, dest );
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001426
Saurabh Shahacf10202013-02-26 10:15:15 -08001427 int fd = hnd->fd;
1428 uint32_t offset = hnd->offset;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001429
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001430 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -08001431 if(rot) {
1432 if(!rot->queueBuffer(fd, offset))
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001433 return false;
Saurabh Shahacf10202013-02-26 10:15:15 -08001434 fd = rot->getDstMemId();
1435 offset = rot->getDstOffset();
1436 }
1437
1438 if (!ov.queueBuffer(fd, offset, dest)) {
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301439 ALOGE("%s: queueBuffer failed for display:%d ", __FUNCTION__, mDpy);
Saurabh Shahacf10202013-02-26 10:15:15 -08001440 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001441 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001442
1443 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001444 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001445 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001446}
1447
Saurabh Shah88e4d272013-09-03 13:31:29 -07001448//=============MDPCompSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001449
Saurabh Shah88e4d272013-09-03 13:31:29 -07001450int MDPCompSplit::pipesNeeded(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001451 hwc_display_contents_1_t* list,
1452 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001453 int pipesNeeded = 0;
Saurabh Shah67a38c32013-06-10 16:23:15 -07001454 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001455
1456 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001457
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001458 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1459 if(!mCurrentFrame.isFBComposed[i]) {
1460 hwc_layer_1_t* layer = &list->hwLayers[i];
1461 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001462 if(mixer == Overlay::MIXER_LEFT && dst.left < lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001463 pipesNeeded++;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001464 } else if(mixer == Overlay::MIXER_RIGHT && dst.right > lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001465 pipesNeeded++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001466 }
1467 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001468 }
1469 return pipesNeeded;
1470}
1471
Saurabh Shah88e4d272013-09-03 13:31:29 -07001472bool MDPCompSplit::arePipesAvailable(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001473 hwc_display_contents_1_t* list) {
1474 overlay::Overlay& ov = *ctx->mOverlay;
Saurabh Shah082468e2013-09-12 10:05:32 -07001475 int totalPipesNeeded = 0;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001476
1477 for(int i = 0; i < Overlay::MIXER_MAX; i++) {
1478 int numPipesNeeded = pipesNeeded(ctx, list, i);
1479 int availPipes = ov.availablePipes(mDpy, i);
1480
1481 //Reserve pipe(s)for FB
1482 if(mCurrentFrame.fbCount)
Saurabh Shah082468e2013-09-12 10:05:32 -07001483 numPipesNeeded += 1;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001484
Saurabh Shah082468e2013-09-12 10:05:32 -07001485 totalPipesNeeded += numPipesNeeded;
1486
1487 //Per mixer check.
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001488 if(numPipesNeeded > availPipes) {
1489 ALOGD_IF(isDebug(), "%s: Insufficient pipes for "
1490 "dpy %d mixer %d needed %d, avail %d",
1491 __FUNCTION__, mDpy, i, numPipesNeeded, availPipes);
1492 return false;
1493 }
1494 }
Saurabh Shah082468e2013-09-12 10:05:32 -07001495
1496 //Per display check, since unused pipes can get counted twice.
1497 int totalPipesAvailable = ov.availablePipes(mDpy);
1498 if(totalPipesNeeded > totalPipesAvailable) {
1499 ALOGD_IF(isDebug(), "%s: Insufficient pipes for "
1500 "dpy %d needed %d, avail %d",
1501 __FUNCTION__, mDpy, totalPipesNeeded, totalPipesAvailable);
1502 return false;
1503 }
1504
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001505 if(not areVGPipesAvailable(ctx, list)) {
1506 return false;
1507 }
1508
1509 return true;
1510}
1511
1512bool MDPCompSplit::areVGPipesAvailable(hwc_context_t *ctx,
1513 hwc_display_contents_1_t* list) {
1514 overlay::Overlay& ov = *ctx->mOverlay;
1515 int pipesNeeded = 0;
1516 const int lSplit = getLeftSplit(ctx, mDpy);
1517 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1518 if(!mCurrentFrame.isFBComposed[i]) {
1519 hwc_layer_1_t* layer = &list->hwLayers[i];
1520 hwc_rect_t dst = layer->displayFrame;
1521 private_handle_t *hnd = (private_handle_t *)layer->handle;
1522 if(isYuvBuffer(hnd)) {
1523 if(dst.left < lSplit) {
1524 pipesNeeded++;
1525 }
1526 if(dst.right > lSplit) {
1527 pipesNeeded++;
1528 }
1529 }
1530 }
1531 }
1532
1533 int availableVGPipes = ov.availablePipes(mDpy, ovutils::OV_MDP_PIPE_VG);
1534 if(pipesNeeded > availableVGPipes) {
1535 ALOGD_IF(isDebug(), "%s: Insufficient VG pipes for video layers"
1536 "dpy %d needed %d, avail %d",
1537 __FUNCTION__, mDpy, pipesNeeded, availableVGPipes);
1538 return false;
1539 }
1540
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001541 return true;
1542}
1543
Saurabh Shah88e4d272013-09-03 13:31:29 -07001544bool MDPCompSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
1545 MdpPipeInfoSplit& pipe_info,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001546 ePipeType type) {
1547 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001548 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001549
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001550 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001551 pipe_info.lIndex = ovutils::OV_INVALID;
1552 pipe_info.rIndex = ovutils::OV_INVALID;
1553
1554 if (dst.left < lSplit) {
1555 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_LEFT);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001556 if(pipe_info.lIndex == ovutils::OV_INVALID)
1557 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001558 }
1559
1560 if(dst.right > lSplit) {
1561 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_RIGHT);
1562 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001563 return false;
1564 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001565
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001566 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001567}
1568
Saurabh Shah88e4d272013-09-03 13:31:29 -07001569bool MDPCompSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001570 hwc_display_contents_1_t* list) {
1571 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001572
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001573 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001574
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001575 hwc_layer_1_t* layer = &list->hwLayers[index];
1576 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001577 int mdpIndex = mCurrentFrame.layerToMDP[index];
1578 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001579 info.pipeInfo = new MdpPipeInfoSplit;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001580 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001581 MdpPipeInfoSplit& pipe_info = *(MdpPipeInfoSplit*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001582 ePipeType type = MDPCOMP_OV_ANY;
1583
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001584 if(isYuvBuffer(hnd)) {
1585 type = MDPCOMP_OV_VG;
Sushil Chauhan15a2ea62013-09-04 18:28:36 -07001586 } else if(!qhwc::needsScalingWithSplit(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001587 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001588 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001589 type = MDPCOMP_OV_DMA;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001590 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001591
1592 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001593 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type = %d",
1594 __FUNCTION__, (int) type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001595 return false;
1596 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001597 }
1598 return true;
1599}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001600
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001601/*
1602 * Configures pipe(s) for MDP composition
1603 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001604int MDPCompSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001605 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001606 MdpPipeInfoSplit& mdp_info =
1607 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001608 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1609 eIsFg isFg = IS_FG_OFF;
1610 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1611 eDest lDest = mdp_info.lIndex;
1612 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001613
1614 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1615 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1616
Saurabh Shah88e4d272013-09-03 13:31:29 -07001617 return configureSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001618 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001619}
1620
Saurabh Shah88e4d272013-09-03 13:31:29 -07001621bool MDPCompSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001622
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001623 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001624 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1625 return true;
1626 }
1627
1628 if(!ctx || !list) {
1629 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001630 return false;
1631 }
1632
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301633 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1634 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1635 return true;
1636 }
1637
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001638 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001639 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001640 idleInvalidator->markForSleep();
1641
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001642 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001643 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001644
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001645 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1646 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001647 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001648 if(mCurrentFrame.isFBComposed[i]) continue;
1649
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001650 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001651 private_handle_t *hnd = (private_handle_t *)layer->handle;
1652 if(!hnd) {
1653 ALOGE("%s handle null", __FUNCTION__);
1654 return false;
1655 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001656
1657 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1658 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001659 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001660
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001661 int mdpIndex = mCurrentFrame.layerToMDP[i];
1662
Saurabh Shah88e4d272013-09-03 13:31:29 -07001663 MdpPipeInfoSplit& pipe_info =
1664 *(MdpPipeInfoSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001665 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -08001666
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001667 ovutils::eDest indexL = pipe_info.lIndex;
1668 ovutils::eDest indexR = pipe_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001669
Saurabh Shahacf10202013-02-26 10:15:15 -08001670 int fd = hnd->fd;
1671 int offset = hnd->offset;
1672
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001673 if(ctx->mAD->isModeOn()) {
1674 if(ctx->mAD->draw(ctx, fd, offset)) {
1675 fd = ctx->mAD->getDstFd(ctx);
1676 offset = ctx->mAD->getDstOffset(ctx);
1677 }
1678 }
1679
Saurabh Shahacf10202013-02-26 10:15:15 -08001680 if(rot) {
1681 rot->queueBuffer(fd, offset);
1682 fd = rot->getDstMemId();
1683 offset = rot->getDstOffset();
1684 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001685
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001686 //************* play left mixer **********
1687 if(indexL != ovutils::OV_INVALID) {
1688 ovutils::eDest destL = (ovutils::eDest)indexL;
Saurabh Shahacf10202013-02-26 10:15:15 -08001689 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001690 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
Saurabh Shahacf10202013-02-26 10:15:15 -08001691 if (!ov.queueBuffer(fd, offset, destL)) {
1692 ALOGE("%s: queueBuffer failed for left mixer", __FUNCTION__);
1693 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001694 }
1695 }
1696
1697 //************* play right mixer **********
1698 if(indexR != ovutils::OV_INVALID) {
1699 ovutils::eDest destR = (ovutils::eDest)indexR;
Saurabh Shahacf10202013-02-26 10:15:15 -08001700 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001701 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
Saurabh Shahacf10202013-02-26 10:15:15 -08001702 if (!ov.queueBuffer(fd, offset, destR)) {
1703 ALOGE("%s: queueBuffer failed for right mixer", __FUNCTION__);
1704 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001705 }
1706 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001707
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001708 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1709 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001710
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001711 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001712}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001713}; //namespace
1714