blob: 01f4b995a34a7e20df6cc2ead691c950def13f41 [file] [log] [blame]
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001/*
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002 * Copyright (C) 2012-2013, The Linux Foundation. All rights reserved.
Naseer Ahmed7c958d42012-07-31 18:57:03 -07003 * Not a Contribution, Apache license notifications and license are retained
4 * for attribution purposes only.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
Saurabh Shah4fdde762013-04-30 18:47:33 -070019#include <math.h>
Naseer Ahmed7c958d42012-07-31 18:57:03 -070020#include "hwc_mdpcomp.h"
Naseer Ahmed54821fe2012-11-28 18:44:38 -050021#include <sys/ioctl.h>
Saurabh Shah56f610d2012-08-07 15:27:06 -070022#include "external.h"
Jeykumar Sankaran27dee262013-08-01 17:09:54 -070023#include "virtual.h"
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -080024#include "qdMetaData.h"
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -080025#include "mdp_version.h"
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -070026#include "hwc_fbupdate.h"
Saurabh Shaha9da08f2013-07-03 13:27:53 -070027#include "hwc_ad.h"
Saurabh Shahacf10202013-02-26 10:15:15 -080028#include <overlayRotator.h>
29
Saurabh Shah85234ec2013-04-12 17:09:00 -070030using namespace overlay;
Saurabh Shahbd2d0832013-04-04 14:33:08 -070031using namespace qdutils;
Saurabh Shahacf10202013-02-26 10:15:15 -080032using namespace overlay::utils;
33namespace ovutils = overlay::utils;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070034
Naseer Ahmed7c958d42012-07-31 18:57:03 -070035namespace qhwc {
36
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080037//==============MDPComp========================================================
38
Naseer Ahmed7c958d42012-07-31 18:57:03 -070039IdleInvalidator *MDPComp::idleInvalidator = NULL;
40bool MDPComp::sIdleFallBack = false;
41bool MDPComp::sDebugLogs = false;
Naseer Ahmed54821fe2012-11-28 18:44:38 -050042bool MDPComp::sEnabled = false;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -070043bool MDPComp::sEnableMixedMode = true;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -070044bool MDPComp::sEnablePartialFrameUpdate = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080045int MDPComp::sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
Saurabh Shah8c5c8522013-08-29 17:32:49 -070046float MDPComp::sMaxBw = 2.3f;
Saurabh Shah3c1a6b02013-11-22 11:10:20 -080047double MDPComp::sBwClaimed = 0.0;
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
Jeykumar Sankaran988d3682013-11-15 11:57:16 -0800263bool MDPComp::LayerCache::isSameFrame(const FrameInfo& curFrame,
264 hwc_display_contents_1_t* list) {
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530265 if(layerCount != curFrame.layerCount)
266 return false;
267 for(int i = 0; i < curFrame.layerCount; i++) {
268 if((curFrame.isFBComposed[i] != isFBComposed[i]) ||
269 (curFrame.drop[i] != drop[i])) {
270 return false;
271 }
Jeykumar Sankaran988d3682013-11-15 11:57:16 -0800272 if(curFrame.isFBComposed[i] &&
273 (hnd[i] != list->hwLayers[i].handle)){
274 return false;
275 }
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530276 }
277 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800278}
279
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700280bool MDPComp::isSupportedForMDPComp(hwc_context_t *ctx, hwc_layer_1_t* layer) {
281 private_handle_t *hnd = (private_handle_t *)layer->handle;
282 if((not isYuvBuffer(hnd) and has90Transform(layer)) or
283 (not isValidDimension(ctx,layer))
284 //More conditions here, SKIP, sRGB+Blend etc
285 ) {
286 return false;
287 }
288 return true;
289}
290
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530291bool MDPComp::isValidDimension(hwc_context_t *ctx, hwc_layer_1_t *layer) {
Saurabh Shah4fdde762013-04-30 18:47:33 -0700292 const int dpy = HWC_DISPLAY_PRIMARY;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800293 private_handle_t *hnd = (private_handle_t *)layer->handle;
294
295 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -0700296 if (layer->flags & HWC_COLOR_FILL) {
297 // Color layer
298 return true;
299 }
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800300 ALOGE("%s: layer handle is NULL", __FUNCTION__);
301 return false;
302 }
303
Naseer Ahmede850a802013-09-06 13:12:52 -0400304 //XXX: Investigate doing this with pixel phase on MDSS
Naseer Ahmede77f8082013-10-10 13:42:48 -0400305 if(!isSecureBuffer(hnd) && isNonIntegralSourceCrop(layer->sourceCropf))
Naseer Ahmede850a802013-09-06 13:12:52 -0400306 return false;
307
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800308 int hw_w = ctx->dpyAttr[mDpy].xres;
309 int hw_h = ctx->dpyAttr[mDpy].yres;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800310
Saurabh Shah62e1d732013-09-17 10:44:05 -0700311 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700312 hwc_rect_t dst = layer->displayFrame;
Saurabh Shah4fdde762013-04-30 18:47:33 -0700313 int crop_w = crop.right - crop.left;
314 int crop_h = crop.bottom - crop.top;
315 int dst_w = dst.right - dst.left;
316 int dst_h = dst.bottom - dst.top;
317 float w_dscale = ceilf((float)crop_w / (float)dst_w);
318 float h_dscale = ceilf((float)crop_h / (float)dst_h);
319
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800320 /* Workaround for MDP HW limitation in DSI command mode panels where
321 * FPS will not go beyond 30 if buffers on RGB pipes are of width or height
322 * less than 5 pixels
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530323 * There also is a HW limilation in MDP, minimum block size is 2x2
324 * Fallback to GPU if height is less than 2.
325 */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800326 if((crop_w < 5)||(crop_h < 5))
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800327 return false;
328
Saurabh Shah4fdde762013-04-30 18:47:33 -0700329 const uint32_t downscale =
330 qdutils::MDPVersion::getInstance().getMaxMDPDownscale();
331 if(ctx->mMDP.version >= qdutils::MDSS_V5) {
332 /* Workaround for downscales larger than 4x.
333 * Will be removed once decimator block is enabled for MDSS
334 */
335 if(!qdutils::MDPVersion::getInstance().supportsDecimation()) {
336 if(crop_w > MAX_DISPLAY_DIM || w_dscale > downscale ||
337 h_dscale > downscale)
338 return false;
339 } else {
340 if(w_dscale > 64 || h_dscale > 64)
341 return false;
342 }
343 } else { //A-family
344 if(w_dscale > downscale || h_dscale > downscale)
345 return false;
346 }
347
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800348 return true;
349}
350
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700351ovutils::eDest MDPComp::getMdpPipe(hwc_context_t *ctx, ePipeType type,
352 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800353 overlay::Overlay& ov = *ctx->mOverlay;
354 ovutils::eDest mdp_pipe = ovutils::OV_INVALID;
355
356 switch(type) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800357 case MDPCOMP_OV_DMA:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700358 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_DMA, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800359 if(mdp_pipe != ovutils::OV_INVALID) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800360 return mdp_pipe;
361 }
362 case MDPCOMP_OV_ANY:
363 case MDPCOMP_OV_RGB:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700364 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800365 if(mdp_pipe != ovutils::OV_INVALID) {
366 return mdp_pipe;
367 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800368
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800369 if(type == MDPCOMP_OV_RGB) {
370 //Requested only for RGB pipe
371 break;
372 }
373 case MDPCOMP_OV_VG:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700374 return ov.nextPipe(ovutils::OV_MDP_PIPE_VG, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800375 default:
376 ALOGE("%s: Invalid pipe type",__FUNCTION__);
377 return ovutils::OV_INVALID;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800378 };
379 return ovutils::OV_INVALID;
380}
381
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800382bool MDPComp::isFrameDoable(hwc_context_t *ctx) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700383 bool ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700384 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800385
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800386 if(!isEnabled()) {
387 ALOGD_IF(isDebug(),"%s: MDP Comp. not enabled.", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700388 ret = false;
Saurabh Shahd4e65852013-06-17 11:33:53 -0700389 } else if(qdutils::MDPVersion::getInstance().is8x26() &&
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700390 ctx->mVideoTransFlag && ctx->mVirtualDisplay->isConnected()) {
Saurabh Shahd4e65852013-06-17 11:33:53 -0700391 //1 Padding round to shift pipes across mixers
392 ALOGD_IF(isDebug(),"%s: MDP Comp. video transition padding round",
393 __FUNCTION__);
394 ret = false;
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700395 } else if(ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isConfiguring ||
396 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isConfiguring) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800397 ALOGD_IF( isDebug(),"%s: External Display connection is pending",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800398 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700399 ret = false;
Saurabh Shahaa236822013-04-24 18:07:26 -0700400 } else if(ctx->isPaddingRound) {
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700401 ctx->isPaddingRound = false;
402 ALOGD_IF(isDebug(), "%s: padding round",__FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700403 ret = false;
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700404 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700405 return ret;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800406}
407
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800408/*
409 * 1) Identify layers that are not visible in the updating ROI and drop them
410 * from composition.
411 * 2) If we have a scaling layers which needs cropping against generated ROI.
412 * Reset ROI to full resolution.
413 */
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700414bool MDPComp::validateAndApplyROI(hwc_context_t *ctx,
415 hwc_display_contents_1_t* list, hwc_rect_t roi) {
416 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
417
418 if(!isValidRect(roi))
419 return false;
420
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800421 hwc_rect_t visibleRect = roi;
422
423 for(int i = numAppLayers - 1; i >= 0; i--){
424
425 if(!isValidRect(visibleRect)) {
426 mCurrentFrame.drop[i] = true;
427 mCurrentFrame.dropCount++;
428 }
429
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700430 const hwc_layer_1_t* layer = &list->hwLayers[i];
431
432 hwc_rect_t dstRect = layer->displayFrame;
Arun Kumar K.R91090c72013-10-28 19:40:18 -0700433 hwc_rect_t srcRect = integerizeSourceCrop(layer->sourceCropf);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700434 int transform = layer->transform;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700435
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800436 hwc_rect_t res = getIntersection(visibleRect, dstRect);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700437
438 int res_w = res.right - res.left;
439 int res_h = res.bottom - res.top;
440 int dst_w = dstRect.right - dstRect.left;
441 int dst_h = dstRect.bottom - dstRect.top;
442
443 if(!isValidRect(res)) {
444 mCurrentFrame.drop[i] = true;
445 mCurrentFrame.dropCount++;
446 }else {
447 /* Reset frame ROI when any layer which needs scaling also needs ROI
448 * cropping */
449 if((res_w != dst_w || res_h != dst_h) &&
450 needsScaling (ctx, layer, mDpy)) {
Arpita Banerjeed8965982013-11-08 17:27:33 -0800451 ALOGI("%s: Resetting ROI due to scaling", __FUNCTION__);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700452 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
453 mCurrentFrame.dropCount = 0;
454 return false;
455 }
456 }
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800457
458 if (layer->blending == HWC_BLENDING_NONE)
459 visibleRect = deductRect(visibleRect, res);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700460 }
461 return true;
462}
463
464void MDPComp::generateROI(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
465 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
466
467 if(!sEnablePartialFrameUpdate) {
468 return;
469 }
470
471 if(mDpy || isDisplaySplit(ctx, mDpy)){
472 ALOGE_IF(isDebug(), "%s: ROI not supported for"
473 "the (1) external / virtual display's (2) dual DSI displays",
474 __FUNCTION__);
475 return;
476 }
477
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800478 if(isSkipPresent(ctx, mDpy))
479 return;
480
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700481 if(list->flags & HWC_GEOMETRY_CHANGED)
482 return;
483
484 struct hwc_rect roi = (struct hwc_rect){0, 0, 0, 0};
485 for(int index = 0; index < numAppLayers; index++ ) {
486 if ((mCachedFrame.hnd[index] != list->hwLayers[index].handle) ||
487 isYuvBuffer((private_handle_t *)list->hwLayers[index].handle)) {
488 hwc_rect_t dstRect = list->hwLayers[index].displayFrame;
Arun Kumar K.R91090c72013-10-28 19:40:18 -0700489 hwc_rect_t srcRect = integerizeSourceCrop(
490 list->hwLayers[index].sourceCropf);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700491 int transform = list->hwLayers[index].transform;
492
493 /* Intersect against display boundaries */
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700494 roi = getUnion(roi, dstRect);
495 }
496 }
497
498 if(!validateAndApplyROI(ctx, list, roi)){
499 roi = (struct hwc_rect) {0, 0,
500 (int)ctx->dpyAttr[mDpy].xres, (int)ctx->dpyAttr[mDpy].yres};
501 }
502
503 ctx->listStats[mDpy].roi.x = roi.left;
504 ctx->listStats[mDpy].roi.y = roi.top;
505 ctx->listStats[mDpy].roi.w = roi.right - roi.left;
506 ctx->listStats[mDpy].roi.h = roi.bottom - roi.top;
507
508 ALOGD_IF(isDebug(),"%s: generated ROI: [%d, %d, %d, %d]", __FUNCTION__,
509 roi.left, roi.top, roi.right, roi.bottom);
510}
511
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800512/* Checks for conditions where all the layers marked for MDP comp cannot be
513 * bypassed. On such conditions we try to bypass atleast YUV layers */
514bool MDPComp::isFullFrameDoable(hwc_context_t *ctx,
515 hwc_display_contents_1_t* list){
516
Saurabh Shahaa236822013-04-24 18:07:26 -0700517 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800518
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -0700519 if(sIdleFallBack && !ctx->listStats[mDpy].secureUI) {
Saurabh Shah2d998a92013-05-14 17:55:58 -0700520 ALOGD_IF(isDebug(), "%s: Idle fallback dpy %d",__FUNCTION__, mDpy);
521 return false;
522 }
523
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800524 if(isSkipPresent(ctx, mDpy)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700525 ALOGD_IF(isDebug(),"%s: SKIP present: %d",
526 __FUNCTION__,
527 isSkipPresent(ctx, mDpy));
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800528 return false;
529 }
530
Saurabh Shah9f084ad2013-05-02 11:28:09 -0700531 if(ctx->listStats[mDpy].needsAlphaScale
532 && ctx->mMDP.version < qdutils::MDSS_V5) {
533 ALOGD_IF(isDebug(), "%s: frame needs alpha downscaling",__FUNCTION__);
534 return false;
535 }
536
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800537 for(int i = 0; i < numAppLayers; ++i) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800538 hwc_layer_1_t* layer = &list->hwLayers[i];
539 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800540
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700541 if(isYuvBuffer(hnd) && has90Transform(layer)) {
542 if(!canUseRotator(ctx, mDpy)) {
543 ALOGD_IF(isDebug(), "%s: Can't use rotator for dpy %d",
544 __FUNCTION__, mDpy);
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700545 return false;
546 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800547 }
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530548
549 //For 8x26 with panel width>1k, if RGB layer needs HFLIP fail mdp comp
550 // may not need it if Gfx pre-rotation can handle all flips & rotations
551 if(qdutils::MDPVersion::getInstance().is8x26() &&
552 (ctx->dpyAttr[mDpy].xres > 1024) &&
553 (layer->transform & HWC_TRANSFORM_FLIP_H) &&
554 (!isYuvBuffer(hnd)))
555 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800556 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700557
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700558 if(ctx->mAD->isDoable()) {
559 return false;
560 }
561
Saurabh Shahaa236822013-04-24 18:07:26 -0700562 //If all above hard conditions are met we can do full or partial MDP comp.
563 bool ret = false;
564 if(fullMDPComp(ctx, list)) {
565 ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700566 } else if(partialMDPComp(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700567 ret = true;
568 }
569 return ret;
570}
571
572bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700573 //Will benefit presentation / secondary-only layer.
574 if((mDpy > HWC_DISPLAY_PRIMARY) &&
575 (list->numHwLayers - 1) > MAX_SEC_LAYERS) {
576 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
577 return false;
578 }
579
580 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
581 for(int i = 0; i < numAppLayers; i++) {
582 hwc_layer_1_t* layer = &list->hwLayers[i];
583 if(not isSupportedForMDPComp(ctx, layer)) {
584 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",__FUNCTION__);
585 return false;
586 }
587 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700588 mCurrentFrame.fbCount = 0;
589 mCurrentFrame.fbZ = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700590 memcpy(&mCurrentFrame.isFBComposed, &mCurrentFrame.drop,
591 sizeof(mCurrentFrame.isFBComposed));
592 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount -
593 mCurrentFrame.dropCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700594
Saurabh Shah173f4242013-11-20 09:50:12 -0800595 if(!resourceCheck(ctx, list)) {
596 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700597 return false;
598 }
599
Saurabh Shahaa236822013-04-24 18:07:26 -0700600 return true;
601}
602
603bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
604{
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700605 if(!sEnableMixedMode) {
606 //Mixed mode is disabled. No need to even try caching.
607 return false;
608 }
609
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700610 bool ret = false;
611 if(isLoadBasedCompDoable(ctx, list)) {
Saurabh Shahb772ae32013-11-18 15:40:02 -0800612 ret = loadBasedCompPreferGPU(ctx, list) ||
613 loadBasedCompPreferMDP(ctx, list);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700614 }
615
616 if(!ret) {
617 ret = cacheBasedComp(ctx, list);
618 }
619
620 return ret;
621}
622
623bool MDPComp::cacheBasedComp(hwc_context_t *ctx,
624 hwc_display_contents_1_t* list) {
625 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700626 mCurrentFrame.reset(numAppLayers);
627 updateLayerCache(ctx, list);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700628
629 //If an MDP marked layer is unsupported cannot do partial MDP Comp
630 for(int i = 0; i < numAppLayers; i++) {
631 if(!mCurrentFrame.isFBComposed[i]) {
632 hwc_layer_1_t* layer = &list->hwLayers[i];
633 if(not isSupportedForMDPComp(ctx, layer)) {
634 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",
635 __FUNCTION__);
636 return false;
637 }
638 }
639 }
640
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700641 updateYUV(ctx, list, false /*secure only*/);
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530642 bool ret = markLayersForCaching(ctx, list); //sets up fbZ also
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700643 if(!ret) {
644 ALOGD_IF(isDebug(),"%s: batching failed, dpy %d",__FUNCTION__, mDpy);
645 return false;
646 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700647
648 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700649
650 //Will benefit cases where a video has non-updating background.
651 if((mDpy > HWC_DISPLAY_PRIMARY) and
652 (mdpCount > MAX_SEC_LAYERS)) {
653 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
654 return false;
655 }
656
Saurabh Shah173f4242013-11-20 09:50:12 -0800657 if(!resourceCheck(ctx, list)) {
658 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700659 return false;
660 }
661
Saurabh Shahaa236822013-04-24 18:07:26 -0700662 return true;
663}
664
Saurabh Shahb772ae32013-11-18 15:40:02 -0800665bool MDPComp::loadBasedCompPreferGPU(hwc_context_t *ctx,
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700666 hwc_display_contents_1_t* list) {
667 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
668 mCurrentFrame.reset(numAppLayers);
669
Saurabh Shahb772ae32013-11-18 15:40:02 -0800670 int stagesForMDP = min(sMaxPipesPerMixer, ctx->mOverlay->availablePipes(
671 mDpy, Overlay::MIXER_DEFAULT));
672 //If MDP has X possible stages, it can take X layers.
673 const int batchSize = numAppLayers - (stagesForMDP - 1); //1 for FB
674
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700675 if(batchSize <= 0) {
676 ALOGD_IF(isDebug(), "%s: Not attempting", __FUNCTION__);
677 return false;
678 }
679
680 int minBatchStart = -1;
681 size_t minBatchPixelCount = SIZE_MAX;
682
683 for(int i = 0; i <= numAppLayers - batchSize; i++) {
684 uint32_t batchPixelCount = 0;
685 for(int j = i; j < i + batchSize; j++) {
686 hwc_layer_1_t* layer = &list->hwLayers[j];
Arun Kumar K.R91090c72013-10-28 19:40:18 -0700687 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700688 batchPixelCount += (crop.right - crop.left) *
689 (crop.bottom - crop.top);
690 }
691
692 if(batchPixelCount < minBatchPixelCount) {
693 minBatchPixelCount = batchPixelCount;
694 minBatchStart = i;
695 }
696 }
697
698 if(minBatchStart < 0) {
699 ALOGD_IF(isDebug(), "%s: No batch found batchSize %d numAppLayers %d",
700 __FUNCTION__, batchSize, numAppLayers);
701 return false;
702 }
703
704 for(int i = 0; i < numAppLayers; i++) {
705 if(i < minBatchStart || i >= minBatchStart + batchSize) {
706 hwc_layer_1_t* layer = &list->hwLayers[i];
707 if(not isSupportedForMDPComp(ctx, layer)) {
708 ALOGD_IF(isDebug(), "%s: MDP unsupported layer found at %d",
709 __FUNCTION__, i);
710 return false;
711 }
712 mCurrentFrame.isFBComposed[i] = false;
713 }
714 }
715
716 mCurrentFrame.fbZ = minBatchStart;
717 mCurrentFrame.fbCount = batchSize;
718 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - batchSize;
719
Saurabh Shah173f4242013-11-20 09:50:12 -0800720 if(!resourceCheck(ctx, list)) {
721 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700722 return false;
723 }
724
725 ALOGD_IF(isDebug(), "%s: fbZ %d batchSize %d",
726 __FUNCTION__, mCurrentFrame.fbZ, batchSize);
727 return true;
728}
729
Saurabh Shahb772ae32013-11-18 15:40:02 -0800730bool MDPComp::loadBasedCompPreferMDP(hwc_context_t *ctx,
731 hwc_display_contents_1_t* list) {
732 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
733 //TODO get the ib from sysfs node.
734 //Full screen is from ib perspective, not actual full screen
735 const int bpp = 4;
736 double panelRefRate =
737 1000000000.0 / ctx->dpyAttr[mDpy].vsync_period;
738
739 double bwLeft = sMaxBw - sBwClaimed;
740
741 const int fullScreenLayers = bwLeft * 1000000000 / (ctx->dpyAttr[mDpy].xres
742 * ctx->dpyAttr[mDpy].yres * bpp * panelRefRate);
743
744 const int fbBatchSize = numAppLayers - (fullScreenLayers - 1);
745 //If batch size is not at least 2, we aren't really preferring MDP, since
746 //only 1 layer going to GPU could actually translate into an entire FB
747 //needed to be fetched by MDP, thus needing more b/w rather than less.
748 if(fbBatchSize < 2 || fbBatchSize > numAppLayers) {
749 ALOGD_IF(isDebug(), "%s: Not attempting", __FUNCTION__);
750 return false;
751 }
752
753 //Top-most layers constitute FB batch
754 const int fbBatchStart = numAppLayers - fbBatchSize;
755
756 //Bottom-most layers constitute MDP batch
757 for(int i = 0; i < fbBatchStart; i++) {
758 hwc_layer_1_t* layer = &list->hwLayers[i];
759 if(not isSupportedForMDPComp(ctx, layer)) {
760 ALOGD_IF(isDebug(), "%s: MDP unsupported layer found at %d",
761 __FUNCTION__, i);
762 return false;
763 }
764 mCurrentFrame.isFBComposed[i] = false;
765 }
766
767 mCurrentFrame.fbZ = fbBatchStart;
768 mCurrentFrame.fbCount = fbBatchSize;
769 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - fbBatchSize;
770
771 if(!resourceCheck(ctx, list)) {
772 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
773 return false;
774 }
775
776 ALOGD_IF(isDebug(), "%s: FB Z %d, num app layers %d, MDP Batch Size %d",
777 __FUNCTION__, mCurrentFrame.fbZ, numAppLayers,
778 numAppLayers - fbBatchSize);
779
780 return true;
781}
782
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700783bool MDPComp::isLoadBasedCompDoable(hwc_context_t *ctx,
784 hwc_display_contents_1_t* list) {
785 if(mDpy or isSecurePresent(ctx, mDpy) or
786 not (list->flags & HWC_GEOMETRY_CHANGED)) {
787 return false;
788 }
789 return true;
790}
791
Saurabh Shahaa236822013-04-24 18:07:26 -0700792bool MDPComp::isOnlyVideoDoable(hwc_context_t *ctx,
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700793 hwc_display_contents_1_t* list, bool secureOnly) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700794 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700795
Saurabh Shahaa236822013-04-24 18:07:26 -0700796 mCurrentFrame.reset(numAppLayers);
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700797 updateYUV(ctx, list, secureOnly);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700798 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700799
800 if(!isYuvPresent(ctx, mDpy)) {
801 return false;
802 }
803
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -0800804 /* Bail out if we are processing only secured video layers
805 * and we dont have any */
806 if(!isSecurePresent(ctx, mDpy) && secureOnly){
807 return false;
808 }
809
Saurabh Shah4fdde762013-04-30 18:47:33 -0700810 if(!mdpCount)
811 return false;
812
Saurabh Shah173f4242013-11-20 09:50:12 -0800813 if(!resourceCheck(ctx, list)) {
814 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700815 return false;
816 }
817
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800818 return true;
819}
820
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800821/* Checks for conditions where YUV layers cannot be bypassed */
822bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Saurabh Shahe2474082013-05-15 16:32:13 -0700823 bool extAnimBlockFeature = mDpy && ctx->listStats[mDpy].isDisplayAnimating;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800824
Saurabh Shahe2474082013-05-15 16:32:13 -0700825 if(isSkipLayer(layer) && !extAnimBlockFeature) {
826 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800827 return false;
828 }
829
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700830 if(layer->transform & HWC_TRANSFORM_ROT_90 && !canUseRotator(ctx,mDpy)) {
831 ALOGD_IF(isDebug(), "%s: no free DMA pipe",__FUNCTION__);
832 return false;
833 }
834
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800835 if(isSecuring(ctx, layer)) {
836 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
837 return false;
838 }
839
Saurabh Shah4fdde762013-04-30 18:47:33 -0700840 if(!isValidDimension(ctx, layer)) {
841 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
842 __FUNCTION__);
843 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800844 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700845
Naseer Ahmeddc61a972013-07-10 17:50:54 -0400846 if(layer->planeAlpha < 0xFF) {
847 ALOGD_IF(isDebug(), "%s: Cannot handle YUV layer with plane alpha\
848 in video only mode",
849 __FUNCTION__);
850 return false;
851 }
852
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800853 return true;
854}
855
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530856/* starts at fromIndex and check for each layer to find
857 * if it it has overlapping with any Updating layer above it in zorder
858 * till the end of the batch. returns true if it finds any intersection */
859bool MDPComp::canPushBatchToTop(const hwc_display_contents_1_t* list,
860 int fromIndex, int toIndex) {
861 for(int i = fromIndex; i < toIndex; i++) {
862 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
863 if(intersectingUpdatingLayers(list, i+1, toIndex, i)) {
864 return false;
865 }
866 }
867 }
868 return true;
869}
870
871/* Checks if given layer at targetLayerIndex has any
872 * intersection with all the updating layers in beween
873 * fromIndex and toIndex. Returns true if it finds intersectiion */
874bool MDPComp::intersectingUpdatingLayers(const hwc_display_contents_1_t* list,
875 int fromIndex, int toIndex, int targetLayerIndex) {
876 for(int i = fromIndex; i <= toIndex; i++) {
877 if(!mCurrentFrame.isFBComposed[i]) {
878 if(areLayersIntersecting(&list->hwLayers[i],
879 &list->hwLayers[targetLayerIndex])) {
880 return true;
881 }
882 }
883 }
884 return false;
885}
886
887int MDPComp::getBatch(hwc_display_contents_1_t* list,
888 int& maxBatchStart, int& maxBatchEnd,
889 int& maxBatchCount) {
890 int i = 0;
891 int updatingLayersAbove = 0;//Updating layer count in middle of batch
892 int fbZOrder =-1;
893 while (i < mCurrentFrame.layerCount) {
894 int batchCount = 0;
895 int batchStart = i;
896 int batchEnd = i;
897 int fbZ = batchStart;
898 int firstZReverseIndex = -1;
899 while(i < mCurrentFrame.layerCount) {
900 if(!mCurrentFrame.isFBComposed[i]) {
901 if(!batchCount) {
902 i++;
903 break;
904 }
905 updatingLayersAbove++;
906 i++;
907 continue;
908 } else {
909 if(mCurrentFrame.drop[i]) {
910 i++;
911 continue;
912 } else if(updatingLayersAbove <= 0) {
913 batchCount++;
914 batchEnd = i;
915 i++;
916 continue;
917 } else { //Layer is FBComposed, not a drop & updatingLayer > 0
918
919 // We have a valid updating layer already. If layer-i not
920 // have overlapping with all updating layers in between
921 // batch-start and i, then we can add layer i to batch.
922 if(!intersectingUpdatingLayers(list, batchStart, i-1, i)) {
923 batchCount++;
924 batchEnd = i;
925 i++;
926 continue;
927 } else if(canPushBatchToTop(list, batchStart, i)) {
928 //If All the non-updating layers with in this batch
929 //does not have intersection with the updating layers
930 //above in z-order, then we can safely move the batch to
931 //higher z-order. Increment fbZ as it is moving up.
932 if( firstZReverseIndex < 0) {
933 firstZReverseIndex = i;
934 }
935 batchCount++;
936 batchEnd = i;
937 fbZ += updatingLayersAbove;
938 i++;
939 updatingLayersAbove = 0;
940 continue;
941 } else {
942 //both failed.start the loop again from here.
943 if(firstZReverseIndex >= 0) {
944 i = firstZReverseIndex;
945 }
946 break;
947 }
948 }
949 }
950 }
951 if(batchCount > maxBatchCount) {
952 maxBatchCount = batchCount;
953 maxBatchStart = batchStart;
954 maxBatchEnd = batchEnd;
955 fbZOrder = fbZ;
956 }
957 }
958 return fbZOrder;
959}
960
961bool MDPComp::markLayersForCaching(hwc_context_t* ctx,
962 hwc_display_contents_1_t* list) {
963 /* Idea is to keep as many non-updating(cached) layers in FB and
964 * send rest of them through MDP. This is done in 2 steps.
965 * 1. Find the maximum contiguous batch of non-updating layers.
966 * 2. See if we can improve this batch size for caching by adding
967 * opaque layers around the batch, if they don't have
968 * any overlapping with the updating layers in between.
969 * NEVER mark an updating layer for caching.
970 * But cached ones can be marked for MDP */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800971
972 int maxBatchStart = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700973 int maxBatchEnd = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800974 int maxBatchCount = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530975 int fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800976
977 /* All or Nothing is cached. No batching needed */
Saurabh Shahaa236822013-04-24 18:07:26 -0700978 if(!mCurrentFrame.fbCount) {
979 mCurrentFrame.fbZ = -1;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700980 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -0700981 }
982 if(!mCurrentFrame.mdpCount) {
983 mCurrentFrame.fbZ = 0;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700984 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -0700985 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800986
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530987 fbZ = getBatch(list, maxBatchStart, maxBatchEnd, maxBatchCount);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800988
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530989 /* reset rest of the layers lying inside ROI for MDP comp */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800990 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700991 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700992 if((i < maxBatchStart || i > maxBatchEnd) &&
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530993 mCurrentFrame.isFBComposed[i]){
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700994 if(!mCurrentFrame.drop[i]){
995 //If an unsupported layer is being attempted to
996 //be pulled out we should fail
997 if(not isSupportedForMDPComp(ctx, layer)) {
998 return false;
999 }
1000 mCurrentFrame.isFBComposed[i] = false;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001001 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001002 }
1003 }
1004
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301005 // update the frame data
1006 mCurrentFrame.fbZ = fbZ;
1007 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001008 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001009 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001010
1011 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301012 mCurrentFrame.fbCount);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001013
1014 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001015}
Saurabh Shah85234ec2013-04-12 17:09:00 -07001016
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001017void MDPComp::updateLayerCache(hwc_context_t* ctx,
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001018 hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001019 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001020 int fbCount = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001021
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001022 for(int i = 0; i < numAppLayers; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001023 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001024 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001025 if(!mCurrentFrame.drop[i])
1026 fbCount++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001027 mCurrentFrame.isFBComposed[i] = true;
1028 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -07001029 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001030 }
1031 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001032
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001033 mCurrentFrame.fbCount = fbCount;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001034 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount
1035 - mCurrentFrame.dropCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001036
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001037 ALOGD_IF(isDebug(),"%s: MDP count: %d FB count %d drop count: %d"
1038 ,__FUNCTION__, mCurrentFrame.mdpCount, mCurrentFrame.fbCount,
1039 mCurrentFrame.dropCount);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001040}
1041
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001042void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list,
1043 bool secureOnly) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001044 int nYuvCount = ctx->listStats[mDpy].yuvCount;
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001045 if(!nYuvCount && mDpy) {
1046 //Reset "No animation on external display" related parameters.
1047 ctx->mPrevCropVideo.left = ctx->mPrevCropVideo.top =
1048 ctx->mPrevCropVideo.right = ctx->mPrevCropVideo.bottom = 0;
1049 ctx->mPrevDestVideo.left = ctx->mPrevDestVideo.top =
1050 ctx->mPrevDestVideo.right = ctx->mPrevDestVideo.bottom = 0;
1051 ctx->mPrevTransformVideo = 0;
1052 return;
1053 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001054 for(int index = 0;index < nYuvCount; index++){
1055 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
1056 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
1057
1058 if(!isYUVDoable(ctx, layer)) {
1059 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
1060 mCurrentFrame.isFBComposed[nYuvIndex] = true;
1061 mCurrentFrame.fbCount++;
1062 }
1063 } else {
1064 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001065 private_handle_t *hnd = (private_handle_t *)layer->handle;
1066 if(!secureOnly || isSecureBuffer(hnd)) {
1067 mCurrentFrame.isFBComposed[nYuvIndex] = false;
1068 mCurrentFrame.fbCount--;
1069 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001070 }
1071 }
1072 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001073
1074 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001075 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
1076 ALOGD_IF(isDebug(),"%s: fb count: %d",__FUNCTION__,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001077 mCurrentFrame.fbCount);
1078}
1079
Saurabh Shahaa236822013-04-24 18:07:26 -07001080bool MDPComp::programMDP(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001081 if(!allocLayerPipes(ctx, list)) {
1082 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -07001083 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001084 }
1085
1086 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001087 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001088 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001089 int mdpIndex = mCurrentFrame.layerToMDP[index];
1090 hwc_layer_1_t* layer = &list->hwLayers[index];
1091
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301092 //Leave fbZ for framebuffer. CACHE/GLES layers go here.
1093 if(mdpNextZOrder == mCurrentFrame.fbZ) {
1094 mdpNextZOrder++;
1095 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001096 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1097 cur_pipe->zOrder = mdpNextZOrder++;
1098
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301099
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001100 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
1101 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
1102 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -07001103 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001104 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001105 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001106 }
1107
Saurabh Shahaa236822013-04-24 18:07:26 -07001108 return true;
1109}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001110
Saurabh Shahaa236822013-04-24 18:07:26 -07001111bool MDPComp::programYUV(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
1112 if(!allocLayerPipes(ctx, list)) {
1113 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
1114 return false;
1115 }
1116 //If we are in this block, it means we have yuv + rgb layers both
1117 int mdpIdx = 0;
1118 for (int index = 0; index < mCurrentFrame.layerCount; index++) {
1119 if(!mCurrentFrame.isFBComposed[index]) {
1120 hwc_layer_1_t* layer = &list->hwLayers[index];
1121 int mdpIndex = mCurrentFrame.layerToMDP[index];
1122 MdpPipeInfo* cur_pipe =
1123 mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1124 cur_pipe->zOrder = mdpIdx++;
1125
1126 if(configure(ctx, layer,
1127 mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
1128 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
1129 layer %d",__FUNCTION__, index);
1130 return false;
1131 }
1132 }
1133 }
1134 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001135}
1136
Saurabh Shah173f4242013-11-20 09:50:12 -08001137bool MDPComp::resourceCheck(hwc_context_t *ctx,
1138 hwc_display_contents_1_t *list) {
1139 const bool fbUsed = mCurrentFrame.fbCount;
1140 if(mCurrentFrame.mdpCount > sMaxPipesPerMixer - fbUsed) {
1141 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
1142 return false;
1143 }
1144
1145 if(!arePipesAvailable(ctx, list)) {
1146 return false;
1147 }
1148
1149 uint32_t size = calcMDPBytesRead(ctx, list);
1150 if(!bandwidthCheck(ctx, size)) {
1151 ALOGD_IF(isDebug(), "%s: Exceeds bandwidth",__FUNCTION__);
1152 return false;
1153 }
1154
1155 return true;
1156}
1157
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001158uint32_t MDPComp::calcMDPBytesRead(hwc_context_t *ctx,
1159 hwc_display_contents_1_t* list) {
1160 uint32_t size = 0;
1161
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001162 if(!qdutils::MDPVersion::getInstance().is8x74v2())
1163 return 0;
1164
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001165 for (uint32_t i = 0; i < list->numHwLayers - 1; i++) {
1166 if(!mCurrentFrame.isFBComposed[i]) {
1167 hwc_layer_1_t* layer = &list->hwLayers[i];
1168 private_handle_t *hnd = (private_handle_t *)layer->handle;
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001169 if (hnd) {
Saurabh Shah62e1d732013-09-17 10:44:05 -07001170 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah90789162013-09-16 10:29:20 -07001171 hwc_rect_t dst = layer->displayFrame;
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001172 float bpp = ((float)hnd->size) / (hnd->width * hnd->height);
Saurabh Shah90789162013-09-16 10:29:20 -07001173 size += bpp * (crop.right - crop.left) *
1174 (crop.bottom - crop.top) *
1175 ctx->dpyAttr[mDpy].yres / (dst.bottom - dst.top);
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001176 }
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001177 }
1178 }
1179
1180 if(mCurrentFrame.fbCount) {
1181 hwc_layer_1_t* layer = &list->hwLayers[list->numHwLayers - 1];
1182 private_handle_t *hnd = (private_handle_t *)layer->handle;
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001183 if (hnd)
1184 size += hnd->size;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001185 }
1186
1187 return size;
1188}
1189
1190bool MDPComp::bandwidthCheck(hwc_context_t *ctx, const uint32_t& size) {
1191 //Will be added for other targets if we run into bandwidth issues and when
1192 //we have profiling data to set an upper limit.
1193 if(qdutils::MDPVersion::getInstance().is8x74v2()) {
Saurabh Shah3c1a6b02013-11-22 11:10:20 -08001194 const uint32_t ONE_GIG = 1000 * 1000 * 1000;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001195 double panelRefRate =
1196 1000000000.0 / ctx->dpyAttr[mDpy].vsync_period;
Saurabh Shah3c1a6b02013-11-22 11:10:20 -08001197 if((size * panelRefRate) > ((sMaxBw - sBwClaimed) * ONE_GIG)) {
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001198 return false;
1199 }
1200 }
1201 return true;
1202}
1203
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001204int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001205 int ret = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -07001206 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -07001207
Saurabh Shahb39f8152013-08-22 10:21:44 -07001208 //reset old data
1209 mCurrentFrame.reset(numLayers);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001210 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1211 mCurrentFrame.dropCount = 0;
Prabhanjan Kandula088bd892013-07-02 23:47:13 +05301212
Saurabh Shahb39f8152013-08-22 10:21:44 -07001213 //number of app layers exceeds MAX_NUM_APP_LAYERS fall back to GPU
1214 //do not cache the information for next draw cycle.
1215 if(numLayers > MAX_NUM_APP_LAYERS) {
Prabhanjan Kandula25469a52013-07-12 16:19:31 +05301216 mCachedFrame.updateCounts(mCurrentFrame);
Arpita Banerjeed8965982013-11-08 17:27:33 -08001217 ALOGI("%s: Number of App layers exceeded the limit ",
Tatenda Chipeperekwa835337a2013-09-27 16:58:43 -07001218 __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001219 ret = -1;
Tatenda Chipeperekwa835337a2013-09-27 16:58:43 -07001220 return ret;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001221 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001222
Saurabh Shahb39f8152013-08-22 10:21:44 -07001223 //Hard conditions, if not met, cannot do MDP comp
1224 if(!isFrameDoable(ctx)) {
1225 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
1226 __FUNCTION__);
1227 reset(numLayers, list);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001228 ret = -1;
1229 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001230 }
1231
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001232 generateROI(ctx, list);
1233
Saurabh Shahb39f8152013-08-22 10:21:44 -07001234 //Check whether layers marked for MDP Composition is actually doable.
1235 if(isFullFrameDoable(ctx, list)) {
1236 mCurrentFrame.map();
1237 //Configure framebuffer first if applicable
1238 if(mCurrentFrame.fbZ >= 0) {
1239 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list,
1240 mCurrentFrame.fbZ)) {
1241 ALOGE("%s configure framebuffer failed", __func__);
1242 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -07001243 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001244 ret = -1;
1245 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001246 }
1247 }
1248 //Acquire and Program MDP pipes
1249 if(!programMDP(ctx, list)) {
1250 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -07001251 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001252 ret = -1;
1253 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001254 } else { //Success
1255 //Any change in composition types needs an FB refresh
1256 mCurrentFrame.needsRedraw = false;
Jeykumar Sankaran988d3682013-11-15 11:57:16 -08001257 if(!mCachedFrame.isSameFrame(mCurrentFrame, list) ||
Saurabh Shahb39f8152013-08-22 10:21:44 -07001258 (list->flags & HWC_GEOMETRY_CHANGED) ||
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +05301259 isSkipPresent(ctx, mDpy)) {
Saurabh Shahb39f8152013-08-22 10:21:44 -07001260 mCurrentFrame.needsRedraw = true;
1261 }
1262 }
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001263 } else if(isOnlyVideoDoable(ctx, list, false /*secure only*/) ||
1264 isOnlyVideoDoable(ctx, list, true /*secure only*/)) {
Saurabh Shahb39f8152013-08-22 10:21:44 -07001265 //All layers marked for MDP comp cannot be bypassed.
1266 //Try to compose atleast YUV layers through MDP comp and let
1267 //all the RGB layers compose in FB
1268 //Destination over
1269 mCurrentFrame.fbZ = -1;
1270 if(mCurrentFrame.fbCount)
1271 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
1272
1273 mCurrentFrame.map();
1274
1275 //Configure framebuffer first if applicable
1276 if(mCurrentFrame.fbZ >= 0) {
1277 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, mCurrentFrame.fbZ)) {
1278 ALOGE("%s configure framebuffer failed", __func__);
1279 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -07001280 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001281 ret = -1;
1282 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001283 }
1284 }
1285 if(!programYUV(ctx, list)) {
1286 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -07001287 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001288 ret = -1;
1289 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001290 }
1291 } else {
1292 reset(numLayers, list);
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -08001293 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1294 mCurrentFrame.dropCount = 0;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001295 ret = -1;
1296 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001297 }
Saurabh Shahb39f8152013-08-22 10:21:44 -07001298 //UpdateLayerFlags
1299 setMDPCompLayerFlags(ctx, list);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001300 mCachedFrame.cacheAll(list);
Saurabh Shahb39f8152013-08-22 10:21:44 -07001301 mCachedFrame.updateCounts(mCurrentFrame);
1302
Prabhanjan Kandula25469a52013-07-12 16:19:31 +05301303 // unlock it before calling dump function to avoid deadlock
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001304 if(isDebug()) {
Saurabh Shahaa236822013-04-24 18:07:26 -07001305 ALOGD("GEOMETRY change: %d", (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001306 android::String8 sDump("");
1307 dump(sDump);
1308 ALOGE("%s",sDump.string());
1309 }
1310
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001311exit:
Saurabh Shah3c1a6b02013-11-22 11:10:20 -08001312 //gbps (bytes / nanosec = gigabytes / sec)
1313 sBwClaimed += calcMDPBytesRead(ctx, list) /
1314 (double)ctx->dpyAttr[mDpy].vsync_period;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001315 return ret;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001316}
1317
Saurabh Shah88e4d272013-09-03 13:31:29 -07001318//=============MDPCompNonSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001319
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001320/*
1321 * Configures pipe(s) for MDP composition
1322 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001323int MDPCompNonSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001324 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001325 MdpPipeInfoNonSplit& mdp_info =
1326 *(static_cast<MdpPipeInfoNonSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001327 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
1328 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1329 eIsFg isFg = IS_FG_OFF;
1330 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001331
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001332 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
1333 __FUNCTION__, layer, zOrder, dest);
1334
Saurabh Shah88e4d272013-09-03 13:31:29 -07001335 return configureNonSplit(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001336 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001337}
1338
Saurabh Shah88e4d272013-09-03 13:31:29 -07001339bool MDPCompNonSplit::arePipesAvailable(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001340 hwc_display_contents_1_t* list) {
1341 overlay::Overlay& ov = *ctx->mOverlay;
1342 int numPipesNeeded = mCurrentFrame.mdpCount;
1343 int availPipes = ov.availablePipes(mDpy, Overlay::MIXER_DEFAULT);
1344
1345 //Reserve pipe for FB
1346 if(mCurrentFrame.fbCount)
1347 availPipes -= 1;
1348
1349 if(numPipesNeeded > availPipes) {
1350 ALOGD_IF(isDebug(), "%s: Insufficient pipes, dpy %d needed %d, avail %d",
1351 __FUNCTION__, mDpy, numPipesNeeded, availPipes);
1352 return false;
1353 }
1354
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001355 if(not areVGPipesAvailable(ctx, list)) {
1356 return false;
1357 }
1358
1359 return true;
1360}
1361
1362bool MDPCompNonSplit::areVGPipesAvailable(hwc_context_t *ctx,
1363 hwc_display_contents_1_t* list) {
1364 overlay::Overlay& ov = *ctx->mOverlay;
1365 int pipesNeeded = 0;
1366 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1367 if(!mCurrentFrame.isFBComposed[i]) {
1368 hwc_layer_1_t* layer = &list->hwLayers[i];
1369 hwc_rect_t dst = layer->displayFrame;
1370 private_handle_t *hnd = (private_handle_t *)layer->handle;
1371 if(isYuvBuffer(hnd)) {
1372 pipesNeeded++;
1373 }
1374 }
1375 }
1376
1377 int availableVGPipes = ov.availablePipes(mDpy, ovutils::OV_MDP_PIPE_VG);
1378 if(pipesNeeded > availableVGPipes) {
1379 ALOGD_IF(isDebug(), "%s: Insufficient VG pipes for video layers"
1380 "dpy %d needed %d, avail %d",
1381 __FUNCTION__, mDpy, pipesNeeded, availableVGPipes);
1382 return false;
1383 }
1384
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001385 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001386}
1387
Saurabh Shah88e4d272013-09-03 13:31:29 -07001388bool MDPCompNonSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001389 hwc_display_contents_1_t* list) {
1390 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001391
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001392 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001393
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001394 hwc_layer_1_t* layer = &list->hwLayers[index];
1395 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001396 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001397 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001398 info.pipeInfo = new MdpPipeInfoNonSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08001399 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001400 MdpPipeInfoNonSplit& pipe_info = *(MdpPipeInfoNonSplit*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001401 ePipeType type = MDPCOMP_OV_ANY;
1402
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001403 if(isYuvBuffer(hnd)) {
1404 type = MDPCOMP_OV_VG;
Saurabh Shah8a117932013-05-23 12:48:13 -07001405 } else if(!qhwc::needsScaling(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001406 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
1407 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001408 type = MDPCOMP_OV_DMA;
1409 }
1410
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001411 pipe_info.index = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001412 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001413 ALOGD_IF(isDebug(), "%s: Unable to get pipe type = %d",
1414 __FUNCTION__, (int) type);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001415 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001416 }
1417 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001418 return true;
1419}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001420
Saurabh Shah88e4d272013-09-03 13:31:29 -07001421bool MDPCompNonSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001422
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001423 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001424 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1425 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -08001426 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001427
1428 if(!ctx || !list) {
1429 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001430 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001431 }
1432
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301433 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1434 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1435 return true;
1436 }
1437
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001438 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001439 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001440 idleInvalidator->markForSleep();
1441
1442 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001443 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001444
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001445 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1446 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001447 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001448 if(mCurrentFrame.isFBComposed[i]) continue;
1449
Naseer Ahmed5b6708a2012-08-02 13:46:08 -07001450 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001451 private_handle_t *hnd = (private_handle_t *)layer->handle;
1452 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001453 if (!(layer->flags & HWC_COLOR_FILL)) {
1454 ALOGE("%s handle null", __FUNCTION__);
1455 return false;
1456 }
1457 // No PLAY for Color layer
1458 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1459 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001460 }
1461
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001462 int mdpIndex = mCurrentFrame.layerToMDP[i];
1463
Saurabh Shah88e4d272013-09-03 13:31:29 -07001464 MdpPipeInfoNonSplit& pipe_info =
1465 *(MdpPipeInfoNonSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001466 ovutils::eDest dest = pipe_info.index;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001467 if(dest == ovutils::OV_INVALID) {
1468 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001469 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001470 }
1471
Saurabh Shahacf10202013-02-26 10:15:15 -08001472 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1473 continue;
1474 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001475
Saurabh Shahacf10202013-02-26 10:15:15 -08001476 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001477 using pipe: %d", __FUNCTION__, layer,
1478 hnd, dest );
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001479
Saurabh Shahacf10202013-02-26 10:15:15 -08001480 int fd = hnd->fd;
1481 uint32_t offset = hnd->offset;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001482
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001483 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -08001484 if(rot) {
1485 if(!rot->queueBuffer(fd, offset))
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001486 return false;
Saurabh Shahacf10202013-02-26 10:15:15 -08001487 fd = rot->getDstMemId();
1488 offset = rot->getDstOffset();
1489 }
1490
1491 if (!ov.queueBuffer(fd, offset, dest)) {
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301492 ALOGE("%s: queueBuffer failed for display:%d ", __FUNCTION__, mDpy);
Saurabh Shahacf10202013-02-26 10:15:15 -08001493 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001494 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001495
1496 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001497 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001498 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001499}
1500
Saurabh Shah88e4d272013-09-03 13:31:29 -07001501//=============MDPCompSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001502
Saurabh Shah88e4d272013-09-03 13:31:29 -07001503int MDPCompSplit::pipesNeeded(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001504 hwc_display_contents_1_t* list,
1505 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001506 int pipesNeeded = 0;
Saurabh Shah67a38c32013-06-10 16:23:15 -07001507 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001508
1509 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001510
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001511 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1512 if(!mCurrentFrame.isFBComposed[i]) {
1513 hwc_layer_1_t* layer = &list->hwLayers[i];
1514 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001515 if(mixer == Overlay::MIXER_LEFT && dst.left < lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001516 pipesNeeded++;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001517 } else if(mixer == Overlay::MIXER_RIGHT && dst.right > lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001518 pipesNeeded++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001519 }
1520 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001521 }
1522 return pipesNeeded;
1523}
1524
Saurabh Shah88e4d272013-09-03 13:31:29 -07001525bool MDPCompSplit::arePipesAvailable(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001526 hwc_display_contents_1_t* list) {
1527 overlay::Overlay& ov = *ctx->mOverlay;
Saurabh Shah082468e2013-09-12 10:05:32 -07001528 int totalPipesNeeded = 0;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001529
1530 for(int i = 0; i < Overlay::MIXER_MAX; i++) {
1531 int numPipesNeeded = pipesNeeded(ctx, list, i);
1532 int availPipes = ov.availablePipes(mDpy, i);
1533
1534 //Reserve pipe(s)for FB
1535 if(mCurrentFrame.fbCount)
Saurabh Shah082468e2013-09-12 10:05:32 -07001536 numPipesNeeded += 1;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001537
Saurabh Shah082468e2013-09-12 10:05:32 -07001538 totalPipesNeeded += numPipesNeeded;
1539
1540 //Per mixer check.
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001541 if(numPipesNeeded > availPipes) {
1542 ALOGD_IF(isDebug(), "%s: Insufficient pipes for "
1543 "dpy %d mixer %d needed %d, avail %d",
1544 __FUNCTION__, mDpy, i, numPipesNeeded, availPipes);
1545 return false;
1546 }
1547 }
Saurabh Shah082468e2013-09-12 10:05:32 -07001548
1549 //Per display check, since unused pipes can get counted twice.
1550 int totalPipesAvailable = ov.availablePipes(mDpy);
1551 if(totalPipesNeeded > totalPipesAvailable) {
1552 ALOGD_IF(isDebug(), "%s: Insufficient pipes for "
1553 "dpy %d needed %d, avail %d",
1554 __FUNCTION__, mDpy, totalPipesNeeded, totalPipesAvailable);
1555 return false;
1556 }
1557
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001558 if(not areVGPipesAvailable(ctx, list)) {
1559 return false;
1560 }
1561
1562 return true;
1563}
1564
1565bool MDPCompSplit::areVGPipesAvailable(hwc_context_t *ctx,
1566 hwc_display_contents_1_t* list) {
1567 overlay::Overlay& ov = *ctx->mOverlay;
1568 int pipesNeeded = 0;
1569 const int lSplit = getLeftSplit(ctx, mDpy);
1570 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1571 if(!mCurrentFrame.isFBComposed[i]) {
1572 hwc_layer_1_t* layer = &list->hwLayers[i];
1573 hwc_rect_t dst = layer->displayFrame;
1574 private_handle_t *hnd = (private_handle_t *)layer->handle;
1575 if(isYuvBuffer(hnd)) {
1576 if(dst.left < lSplit) {
1577 pipesNeeded++;
1578 }
1579 if(dst.right > lSplit) {
1580 pipesNeeded++;
1581 }
1582 }
1583 }
1584 }
1585
1586 int availableVGPipes = ov.availablePipes(mDpy, ovutils::OV_MDP_PIPE_VG);
1587 if(pipesNeeded > availableVGPipes) {
1588 ALOGD_IF(isDebug(), "%s: Insufficient VG pipes for video layers"
1589 "dpy %d needed %d, avail %d",
1590 __FUNCTION__, mDpy, pipesNeeded, availableVGPipes);
1591 return false;
1592 }
1593
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001594 return true;
1595}
1596
Saurabh Shah88e4d272013-09-03 13:31:29 -07001597bool MDPCompSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
1598 MdpPipeInfoSplit& pipe_info,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001599 ePipeType type) {
1600 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001601 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001602
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001603 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001604 pipe_info.lIndex = ovutils::OV_INVALID;
1605 pipe_info.rIndex = ovutils::OV_INVALID;
1606
1607 if (dst.left < lSplit) {
1608 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_LEFT);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001609 if(pipe_info.lIndex == ovutils::OV_INVALID)
1610 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001611 }
1612
1613 if(dst.right > lSplit) {
1614 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_RIGHT);
1615 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001616 return false;
1617 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001618
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001619 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001620}
1621
Saurabh Shah88e4d272013-09-03 13:31:29 -07001622bool MDPCompSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001623 hwc_display_contents_1_t* list) {
1624 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001625
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001626 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001627
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001628 hwc_layer_1_t* layer = &list->hwLayers[index];
1629 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001630 int mdpIndex = mCurrentFrame.layerToMDP[index];
1631 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001632 info.pipeInfo = new MdpPipeInfoSplit;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001633 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001634 MdpPipeInfoSplit& pipe_info = *(MdpPipeInfoSplit*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001635 ePipeType type = MDPCOMP_OV_ANY;
1636
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001637 if(isYuvBuffer(hnd)) {
1638 type = MDPCOMP_OV_VG;
Sushil Chauhan15a2ea62013-09-04 18:28:36 -07001639 } else if(!qhwc::needsScalingWithSplit(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001640 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001641 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001642 type = MDPCOMP_OV_DMA;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001643 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001644
1645 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001646 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type = %d",
1647 __FUNCTION__, (int) type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001648 return false;
1649 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001650 }
1651 return true;
1652}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001653
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001654/*
1655 * Configures pipe(s) for MDP composition
1656 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001657int MDPCompSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001658 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001659 MdpPipeInfoSplit& mdp_info =
1660 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001661 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1662 eIsFg isFg = IS_FG_OFF;
1663 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1664 eDest lDest = mdp_info.lIndex;
1665 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001666
1667 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1668 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1669
Saurabh Shah88e4d272013-09-03 13:31:29 -07001670 return configureSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001671 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001672}
1673
Saurabh Shah88e4d272013-09-03 13:31:29 -07001674bool MDPCompSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001675
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001676 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001677 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1678 return true;
1679 }
1680
1681 if(!ctx || !list) {
1682 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001683 return false;
1684 }
1685
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301686 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1687 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1688 return true;
1689 }
1690
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001691 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001692 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001693 idleInvalidator->markForSleep();
1694
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001695 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001696 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001697
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001698 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1699 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001700 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001701 if(mCurrentFrame.isFBComposed[i]) continue;
1702
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001703 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001704 private_handle_t *hnd = (private_handle_t *)layer->handle;
1705 if(!hnd) {
1706 ALOGE("%s handle null", __FUNCTION__);
1707 return false;
1708 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001709
1710 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1711 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001712 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001713
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001714 int mdpIndex = mCurrentFrame.layerToMDP[i];
1715
Saurabh Shah88e4d272013-09-03 13:31:29 -07001716 MdpPipeInfoSplit& pipe_info =
1717 *(MdpPipeInfoSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001718 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -08001719
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001720 ovutils::eDest indexL = pipe_info.lIndex;
1721 ovutils::eDest indexR = pipe_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001722
Saurabh Shahacf10202013-02-26 10:15:15 -08001723 int fd = hnd->fd;
1724 int offset = hnd->offset;
1725
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001726 if(ctx->mAD->isModeOn()) {
1727 if(ctx->mAD->draw(ctx, fd, offset)) {
1728 fd = ctx->mAD->getDstFd(ctx);
1729 offset = ctx->mAD->getDstOffset(ctx);
1730 }
1731 }
1732
Saurabh Shahacf10202013-02-26 10:15:15 -08001733 if(rot) {
1734 rot->queueBuffer(fd, offset);
1735 fd = rot->getDstMemId();
1736 offset = rot->getDstOffset();
1737 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001738
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001739 //************* play left mixer **********
1740 if(indexL != ovutils::OV_INVALID) {
1741 ovutils::eDest destL = (ovutils::eDest)indexL;
Saurabh Shahacf10202013-02-26 10:15:15 -08001742 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001743 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
Saurabh Shahacf10202013-02-26 10:15:15 -08001744 if (!ov.queueBuffer(fd, offset, destL)) {
1745 ALOGE("%s: queueBuffer failed for left mixer", __FUNCTION__);
1746 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001747 }
1748 }
1749
1750 //************* play right mixer **********
1751 if(indexR != ovutils::OV_INVALID) {
1752 ovutils::eDest destR = (ovutils::eDest)indexR;
Saurabh Shahacf10202013-02-26 10:15:15 -08001753 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001754 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
Saurabh Shahacf10202013-02-26 10:15:15 -08001755 if (!ov.queueBuffer(fd, offset, destR)) {
1756 ALOGE("%s: queueBuffer failed for right mixer", __FUNCTION__);
1757 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001758 }
1759 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001760
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001761 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1762 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001763
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001764 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001765}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001766}; //namespace
1767