blob: 47446d6f45315508de4a7128a2864aa299d3a402 [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 Shahf5f2b132013-11-25 12:08:35 -080046double MDPComp::sMaxBw = 0.0;
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
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400131 if(ctx->mMDP.panel != MIPI_CMD_PANEL) {
132 // Idle invalidation is not necessary on command mode panels
133 long idle_timeout = DEFAULT_IDLE_TIME;
134 if(property_get("debug.mdpcomp.idletime", property, NULL) > 0) {
135 if(atoi(property) != 0)
136 idle_timeout = atoi(property);
137 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800138
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400139 //create Idle Invalidator only when not disabled through property
140 if(idle_timeout != -1)
141 idleInvalidator = IdleInvalidator::getInstance();
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800142
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400143 if(idleInvalidator == NULL) {
144 ALOGE("%s: failed to instantiate idleInvalidator object",
145 __FUNCTION__);
146 } else {
147 idleInvalidator->init(timeout_handler, ctx, idle_timeout);
148 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800149 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700150 return true;
151}
152
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700153void MDPComp::reset(const int& numLayers, hwc_display_contents_1_t* list) {
154 mCurrentFrame.reset(numLayers);
155 mCachedFrame.cacheAll(list);
156 mCachedFrame.updateCounts(mCurrentFrame);
157}
158
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700159void MDPComp::timeout_handler(void *udata) {
160 struct hwc_context_t* ctx = (struct hwc_context_t*)(udata);
161
162 if(!ctx) {
163 ALOGE("%s: received empty data in timer callback", __FUNCTION__);
164 return;
165 }
166
Jesse Hall3be78d92012-08-21 15:12:23 -0700167 if(!ctx->proc) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700168 ALOGE("%s: HWC proc not registered", __FUNCTION__);
169 return;
170 }
171 sIdleFallBack = true;
172 /* Trigger SF to redraw the current frame */
Jesse Hall3be78d92012-08-21 15:12:23 -0700173 ctx->proc->invalidate(ctx->proc);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700174}
175
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800176void MDPComp::setMDPCompLayerFlags(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800177 hwc_display_contents_1_t* list) {
178 LayerProp *layerProp = ctx->layerProp[mDpy];
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800179
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800180 for(int index = 0; index < ctx->listStats[mDpy].numAppLayers; index++) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800181 hwc_layer_1_t* layer = &(list->hwLayers[index]);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800182 if(!mCurrentFrame.isFBComposed[index]) {
183 layerProp[index].mFlags |= HWC_MDPCOMP;
184 layer->compositionType = HWC_OVERLAY;
185 layer->hints |= HWC_HINT_CLEAR_FB;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800186 } else {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700187 /* Drop the layer when its already present in FB OR when it lies
188 * outside frame's ROI */
189 if(!mCurrentFrame.needsRedraw || mCurrentFrame.drop[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800190 layer->compositionType = HWC_OVERLAY;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700191 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800192 }
193 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700194}
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500195
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800196MDPComp::FrameInfo::FrameInfo() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700197 reset(0);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800198}
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800199
Saurabh Shahaa236822013-04-24 18:07:26 -0700200void MDPComp::FrameInfo::reset(const int& numLayers) {
201 for(int i = 0 ; i < MAX_PIPES_PER_MIXER && numLayers; i++ ) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800202 if(mdpToLayer[i].pipeInfo) {
203 delete mdpToLayer[i].pipeInfo;
204 mdpToLayer[i].pipeInfo = NULL;
205 //We dont own the rotator
206 mdpToLayer[i].rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800207 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800208 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800209
210 memset(&mdpToLayer, 0, sizeof(mdpToLayer));
211 memset(&layerToMDP, -1, sizeof(layerToMDP));
Saurabh Shahaa236822013-04-24 18:07:26 -0700212 memset(&isFBComposed, 1, sizeof(isFBComposed));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800213
Saurabh Shahaa236822013-04-24 18:07:26 -0700214 layerCount = numLayers;
215 fbCount = numLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800216 mdpCount = 0;
Saurabh Shah2f3895f2013-05-02 10:13:31 -0700217 needsRedraw = true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800218 fbZ = 0;
219}
220
Saurabh Shahaa236822013-04-24 18:07:26 -0700221void MDPComp::FrameInfo::map() {
222 // populate layer and MDP maps
223 int mdpIdx = 0;
224 for(int idx = 0; idx < layerCount; idx++) {
225 if(!isFBComposed[idx]) {
226 mdpToLayer[mdpIdx].listIndex = idx;
227 layerToMDP[idx] = mdpIdx++;
228 }
229 }
230}
231
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800232MDPComp::LayerCache::LayerCache() {
233 reset();
234}
235
236void MDPComp::LayerCache::reset() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700237 memset(&hnd, 0, sizeof(hnd));
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530238 memset(&isFBComposed, true, sizeof(isFBComposed));
239 memset(&drop, false, sizeof(drop));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800240 layerCount = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -0700241}
242
243void MDPComp::LayerCache::cacheAll(hwc_display_contents_1_t* list) {
244 const int numAppLayers = list->numHwLayers - 1;
245 for(int i = 0; i < numAppLayers; i++) {
246 hnd[i] = list->hwLayers[i].handle;
247 }
248}
249
250void MDPComp::LayerCache::updateCounts(const FrameInfo& curFrame) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700251 layerCount = curFrame.layerCount;
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530252 memcpy(&isFBComposed, &curFrame.isFBComposed, sizeof(isFBComposed));
253 memcpy(&drop, &curFrame.drop, sizeof(drop));
254}
255
Jeykumar Sankaran988d3682013-11-15 11:57:16 -0800256bool MDPComp::LayerCache::isSameFrame(const FrameInfo& curFrame,
257 hwc_display_contents_1_t* list) {
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530258 if(layerCount != curFrame.layerCount)
259 return false;
260 for(int i = 0; i < curFrame.layerCount; i++) {
261 if((curFrame.isFBComposed[i] != isFBComposed[i]) ||
262 (curFrame.drop[i] != drop[i])) {
263 return false;
264 }
Jeykumar Sankaran988d3682013-11-15 11:57:16 -0800265 if(curFrame.isFBComposed[i] &&
266 (hnd[i] != list->hwLayers[i].handle)){
267 return false;
268 }
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530269 }
270 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800271}
272
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700273bool MDPComp::isSupportedForMDPComp(hwc_context_t *ctx, hwc_layer_1_t* layer) {
274 private_handle_t *hnd = (private_handle_t *)layer->handle;
275 if((not isYuvBuffer(hnd) and has90Transform(layer)) or
276 (not isValidDimension(ctx,layer))
277 //More conditions here, SKIP, sRGB+Blend etc
278 ) {
279 return false;
280 }
281 return true;
282}
283
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530284bool MDPComp::isValidDimension(hwc_context_t *ctx, hwc_layer_1_t *layer) {
Saurabh Shah4fdde762013-04-30 18:47:33 -0700285 const int dpy = HWC_DISPLAY_PRIMARY;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800286 private_handle_t *hnd = (private_handle_t *)layer->handle;
287
288 if(!hnd) {
289 ALOGE("%s: layer handle is NULL", __FUNCTION__);
290 return false;
291 }
292
Naseer Ahmede850a802013-09-06 13:12:52 -0400293 //XXX: Investigate doing this with pixel phase on MDSS
Naseer Ahmede77f8082013-10-10 13:42:48 -0400294 if(!isSecureBuffer(hnd) && isNonIntegralSourceCrop(layer->sourceCropf))
Naseer Ahmede850a802013-09-06 13:12:52 -0400295 return false;
296
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800297 int hw_w = ctx->dpyAttr[mDpy].xres;
298 int hw_h = ctx->dpyAttr[mDpy].yres;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800299
Saurabh Shah62e1d732013-09-17 10:44:05 -0700300 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700301 hwc_rect_t dst = layer->displayFrame;
Saurabh Shah4fdde762013-04-30 18:47:33 -0700302 int crop_w = crop.right - crop.left;
303 int crop_h = crop.bottom - crop.top;
304 int dst_w = dst.right - dst.left;
305 int dst_h = dst.bottom - dst.top;
306 float w_dscale = ceilf((float)crop_w / (float)dst_w);
307 float h_dscale = ceilf((float)crop_h / (float)dst_h);
308
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800309 /* Workaround for MDP HW limitation in DSI command mode panels where
310 * FPS will not go beyond 30 if buffers on RGB pipes are of width or height
311 * less than 5 pixels
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530312 * There also is a HW limilation in MDP, minimum block size is 2x2
313 * Fallback to GPU if height is less than 2.
314 */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800315 if((crop_w < 5)||(crop_h < 5))
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800316 return false;
317
Saurabh Shah4fdde762013-04-30 18:47:33 -0700318 const uint32_t downscale =
319 qdutils::MDPVersion::getInstance().getMaxMDPDownscale();
320 if(ctx->mMDP.version >= qdutils::MDSS_V5) {
321 /* Workaround for downscales larger than 4x.
322 * Will be removed once decimator block is enabled for MDSS
323 */
324 if(!qdutils::MDPVersion::getInstance().supportsDecimation()) {
325 if(crop_w > MAX_DISPLAY_DIM || w_dscale > downscale ||
326 h_dscale > downscale)
327 return false;
328 } else {
329 if(w_dscale > 64 || h_dscale > 64)
330 return false;
331 }
332 } else { //A-family
333 if(w_dscale > downscale || h_dscale > downscale)
334 return false;
335 }
336
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800337 return true;
338}
339
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700340ovutils::eDest MDPComp::getMdpPipe(hwc_context_t *ctx, ePipeType type,
341 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800342 overlay::Overlay& ov = *ctx->mOverlay;
343 ovutils::eDest mdp_pipe = ovutils::OV_INVALID;
344
345 switch(type) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800346 case MDPCOMP_OV_DMA:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700347 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_DMA, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800348 if(mdp_pipe != ovutils::OV_INVALID) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800349 return mdp_pipe;
350 }
351 case MDPCOMP_OV_ANY:
352 case MDPCOMP_OV_RGB:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700353 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800354 if(mdp_pipe != ovutils::OV_INVALID) {
355 return mdp_pipe;
356 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800357
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800358 if(type == MDPCOMP_OV_RGB) {
359 //Requested only for RGB pipe
360 break;
361 }
362 case MDPCOMP_OV_VG:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700363 return ov.nextPipe(ovutils::OV_MDP_PIPE_VG, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800364 default:
365 ALOGE("%s: Invalid pipe type",__FUNCTION__);
366 return ovutils::OV_INVALID;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800367 };
368 return ovutils::OV_INVALID;
369}
370
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800371bool MDPComp::isFrameDoable(hwc_context_t *ctx) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700372 bool ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700373 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800374
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800375 if(!isEnabled()) {
376 ALOGD_IF(isDebug(),"%s: MDP Comp. not enabled.", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700377 ret = false;
Saurabh Shahd4e65852013-06-17 11:33:53 -0700378 } else if(qdutils::MDPVersion::getInstance().is8x26() &&
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700379 ctx->mVideoTransFlag && ctx->mVirtualDisplay->isConnected()) {
Saurabh Shahd4e65852013-06-17 11:33:53 -0700380 //1 Padding round to shift pipes across mixers
381 ALOGD_IF(isDebug(),"%s: MDP Comp. video transition padding round",
382 __FUNCTION__);
383 ret = false;
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700384 } else if(ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isConfiguring ||
385 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isConfiguring) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800386 ALOGD_IF( isDebug(),"%s: External Display connection is pending",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800387 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700388 ret = false;
Saurabh Shahaa236822013-04-24 18:07:26 -0700389 } else if(ctx->isPaddingRound) {
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700390 ctx->isPaddingRound = false;
391 ALOGD_IF(isDebug(), "%s: padding round",__FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700392 ret = false;
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700393 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700394 return ret;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800395}
396
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800397/*
398 * 1) Identify layers that are not visible in the updating ROI and drop them
399 * from composition.
400 * 2) If we have a scaling layers which needs cropping against generated ROI.
401 * Reset ROI to full resolution.
402 */
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700403bool MDPComp::validateAndApplyROI(hwc_context_t *ctx,
404 hwc_display_contents_1_t* list, hwc_rect_t roi) {
405 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
406
407 if(!isValidRect(roi))
408 return false;
409
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800410 hwc_rect_t visibleRect = roi;
411
412 for(int i = numAppLayers - 1; i >= 0; i--){
413
414 if(!isValidRect(visibleRect)) {
415 mCurrentFrame.drop[i] = true;
416 mCurrentFrame.dropCount++;
417 }
418
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700419 const hwc_layer_1_t* layer = &list->hwLayers[i];
420
421 hwc_rect_t dstRect = layer->displayFrame;
Arun Kumar K.R91090c72013-10-28 19:40:18 -0700422 hwc_rect_t srcRect = integerizeSourceCrop(layer->sourceCropf);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700423 int transform = layer->transform;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700424
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800425 hwc_rect_t res = getIntersection(visibleRect, dstRect);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700426
427 int res_w = res.right - res.left;
428 int res_h = res.bottom - res.top;
429 int dst_w = dstRect.right - dstRect.left;
430 int dst_h = dstRect.bottom - dstRect.top;
431
432 if(!isValidRect(res)) {
433 mCurrentFrame.drop[i] = true;
434 mCurrentFrame.dropCount++;
435 }else {
436 /* Reset frame ROI when any layer which needs scaling also needs ROI
437 * cropping */
438 if((res_w != dst_w || res_h != dst_h) &&
439 needsScaling (ctx, layer, mDpy)) {
Arpita Banerjeed8965982013-11-08 17:27:33 -0800440 ALOGI("%s: Resetting ROI due to scaling", __FUNCTION__);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700441 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
442 mCurrentFrame.dropCount = 0;
443 return false;
444 }
445 }
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800446
447 if (layer->blending == HWC_BLENDING_NONE)
448 visibleRect = deductRect(visibleRect, res);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700449 }
450 return true;
451}
452
453void MDPComp::generateROI(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
454 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
455
456 if(!sEnablePartialFrameUpdate) {
457 return;
458 }
459
460 if(mDpy || isDisplaySplit(ctx, mDpy)){
461 ALOGE_IF(isDebug(), "%s: ROI not supported for"
462 "the (1) external / virtual display's (2) dual DSI displays",
463 __FUNCTION__);
464 return;
465 }
466
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800467 if(isSkipPresent(ctx, mDpy))
468 return;
469
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700470 if(list->flags & HWC_GEOMETRY_CHANGED)
471 return;
472
473 struct hwc_rect roi = (struct hwc_rect){0, 0, 0, 0};
474 for(int index = 0; index < numAppLayers; index++ ) {
475 if ((mCachedFrame.hnd[index] != list->hwLayers[index].handle) ||
476 isYuvBuffer((private_handle_t *)list->hwLayers[index].handle)) {
477 hwc_rect_t dstRect = list->hwLayers[index].displayFrame;
Arun Kumar K.R91090c72013-10-28 19:40:18 -0700478 hwc_rect_t srcRect = integerizeSourceCrop(
479 list->hwLayers[index].sourceCropf);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700480 int transform = list->hwLayers[index].transform;
481
482 /* Intersect against display boundaries */
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700483 roi = getUnion(roi, dstRect);
484 }
485 }
486
487 if(!validateAndApplyROI(ctx, list, roi)){
488 roi = (struct hwc_rect) {0, 0,
489 (int)ctx->dpyAttr[mDpy].xres, (int)ctx->dpyAttr[mDpy].yres};
490 }
491
492 ctx->listStats[mDpy].roi.x = roi.left;
493 ctx->listStats[mDpy].roi.y = roi.top;
494 ctx->listStats[mDpy].roi.w = roi.right - roi.left;
495 ctx->listStats[mDpy].roi.h = roi.bottom - roi.top;
496
497 ALOGD_IF(isDebug(),"%s: generated ROI: [%d, %d, %d, %d]", __FUNCTION__,
498 roi.left, roi.top, roi.right, roi.bottom);
499}
500
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800501/* Checks for conditions where all the layers marked for MDP comp cannot be
502 * bypassed. On such conditions we try to bypass atleast YUV layers */
503bool MDPComp::isFullFrameDoable(hwc_context_t *ctx,
504 hwc_display_contents_1_t* list){
505
Saurabh Shahaa236822013-04-24 18:07:26 -0700506 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800507
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -0700508 if(sIdleFallBack && !ctx->listStats[mDpy].secureUI) {
Saurabh Shah2d998a92013-05-14 17:55:58 -0700509 ALOGD_IF(isDebug(), "%s: Idle fallback dpy %d",__FUNCTION__, mDpy);
510 return false;
511 }
512
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800513 if(isSkipPresent(ctx, mDpy)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700514 ALOGD_IF(isDebug(),"%s: SKIP present: %d",
515 __FUNCTION__,
516 isSkipPresent(ctx, mDpy));
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800517 return false;
518 }
519
Saurabh Shah9f084ad2013-05-02 11:28:09 -0700520 if(ctx->listStats[mDpy].needsAlphaScale
521 && ctx->mMDP.version < qdutils::MDSS_V5) {
522 ALOGD_IF(isDebug(), "%s: frame needs alpha downscaling",__FUNCTION__);
523 return false;
524 }
525
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800526 for(int i = 0; i < numAppLayers; ++i) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800527 hwc_layer_1_t* layer = &list->hwLayers[i];
528 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800529
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700530 if(isYuvBuffer(hnd) && has90Transform(layer)) {
531 if(!canUseRotator(ctx, mDpy)) {
532 ALOGD_IF(isDebug(), "%s: Can't use rotator for dpy %d",
533 __FUNCTION__, mDpy);
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700534 return false;
535 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800536 }
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530537
538 //For 8x26 with panel width>1k, if RGB layer needs HFLIP fail mdp comp
539 // may not need it if Gfx pre-rotation can handle all flips & rotations
540 if(qdutils::MDPVersion::getInstance().is8x26() &&
541 (ctx->dpyAttr[mDpy].xres > 1024) &&
542 (layer->transform & HWC_TRANSFORM_FLIP_H) &&
543 (!isYuvBuffer(hnd)))
544 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800545 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700546
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700547 if(ctx->mAD->isDoable()) {
548 return false;
549 }
550
Saurabh Shahaa236822013-04-24 18:07:26 -0700551 //If all above hard conditions are met we can do full or partial MDP comp.
552 bool ret = false;
553 if(fullMDPComp(ctx, list)) {
554 ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700555 } else if(partialMDPComp(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700556 ret = true;
557 }
558 return ret;
559}
560
561bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700562 //Will benefit presentation / secondary-only layer.
563 if((mDpy > HWC_DISPLAY_PRIMARY) &&
564 (list->numHwLayers - 1) > MAX_SEC_LAYERS) {
565 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
566 return false;
567 }
568
569 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
570 for(int i = 0; i < numAppLayers; i++) {
571 hwc_layer_1_t* layer = &list->hwLayers[i];
572 if(not isSupportedForMDPComp(ctx, layer)) {
573 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",__FUNCTION__);
574 return false;
575 }
576 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700577 mCurrentFrame.fbCount = 0;
578 mCurrentFrame.fbZ = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700579 memcpy(&mCurrentFrame.isFBComposed, &mCurrentFrame.drop,
580 sizeof(mCurrentFrame.isFBComposed));
581 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount -
582 mCurrentFrame.dropCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700583
Saurabh Shah173f4242013-11-20 09:50:12 -0800584 if(!resourceCheck(ctx, list)) {
585 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700586 return false;
587 }
588
Saurabh Shahaa236822013-04-24 18:07:26 -0700589 return true;
590}
591
592bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
593{
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700594 if(!sEnableMixedMode) {
595 //Mixed mode is disabled. No need to even try caching.
596 return false;
597 }
598
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700599 bool ret = false;
600 if(isLoadBasedCompDoable(ctx, list)) {
Saurabh Shahb772ae32013-11-18 15:40:02 -0800601 ret = loadBasedCompPreferGPU(ctx, list) ||
602 loadBasedCompPreferMDP(ctx, list);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700603 }
604
605 if(!ret) {
606 ret = cacheBasedComp(ctx, list);
607 }
608
609 return ret;
610}
611
612bool MDPComp::cacheBasedComp(hwc_context_t *ctx,
613 hwc_display_contents_1_t* list) {
614 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700615 mCurrentFrame.reset(numAppLayers);
616 updateLayerCache(ctx, list);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700617
618 //If an MDP marked layer is unsupported cannot do partial MDP Comp
619 for(int i = 0; i < numAppLayers; i++) {
620 if(!mCurrentFrame.isFBComposed[i]) {
621 hwc_layer_1_t* layer = &list->hwLayers[i];
622 if(not isSupportedForMDPComp(ctx, layer)) {
623 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",
624 __FUNCTION__);
625 return false;
626 }
627 }
628 }
629
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700630 updateYUV(ctx, list, false /*secure only*/);
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530631 bool ret = markLayersForCaching(ctx, list); //sets up fbZ also
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700632 if(!ret) {
633 ALOGD_IF(isDebug(),"%s: batching failed, dpy %d",__FUNCTION__, mDpy);
634 return false;
635 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700636
637 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700638
639 //Will benefit cases where a video has non-updating background.
640 if((mDpy > HWC_DISPLAY_PRIMARY) and
641 (mdpCount > MAX_SEC_LAYERS)) {
642 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
643 return false;
644 }
645
Saurabh Shah173f4242013-11-20 09:50:12 -0800646 if(!resourceCheck(ctx, list)) {
647 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700648 return false;
649 }
650
Saurabh Shahaa236822013-04-24 18:07:26 -0700651 return true;
652}
653
Saurabh Shahb772ae32013-11-18 15:40:02 -0800654bool MDPComp::loadBasedCompPreferGPU(hwc_context_t *ctx,
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700655 hwc_display_contents_1_t* list) {
656 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
657 mCurrentFrame.reset(numAppLayers);
658
Saurabh Shahb772ae32013-11-18 15:40:02 -0800659 int stagesForMDP = min(sMaxPipesPerMixer, ctx->mOverlay->availablePipes(
660 mDpy, Overlay::MIXER_DEFAULT));
661 //If MDP has X possible stages, it can take X layers.
662 const int batchSize = numAppLayers - (stagesForMDP - 1); //1 for FB
663
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700664 if(batchSize <= 0) {
665 ALOGD_IF(isDebug(), "%s: Not attempting", __FUNCTION__);
666 return false;
667 }
668
669 int minBatchStart = -1;
670 size_t minBatchPixelCount = SIZE_MAX;
671
672 for(int i = 0; i <= numAppLayers - batchSize; i++) {
673 uint32_t batchPixelCount = 0;
674 for(int j = i; j < i + batchSize; j++) {
675 hwc_layer_1_t* layer = &list->hwLayers[j];
Arun Kumar K.R91090c72013-10-28 19:40:18 -0700676 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700677 batchPixelCount += (crop.right - crop.left) *
678 (crop.bottom - crop.top);
679 }
680
681 if(batchPixelCount < minBatchPixelCount) {
682 minBatchPixelCount = batchPixelCount;
683 minBatchStart = i;
684 }
685 }
686
687 if(minBatchStart < 0) {
688 ALOGD_IF(isDebug(), "%s: No batch found batchSize %d numAppLayers %d",
689 __FUNCTION__, batchSize, numAppLayers);
690 return false;
691 }
692
693 for(int i = 0; i < numAppLayers; i++) {
694 if(i < minBatchStart || i >= minBatchStart + batchSize) {
695 hwc_layer_1_t* layer = &list->hwLayers[i];
696 if(not isSupportedForMDPComp(ctx, layer)) {
697 ALOGD_IF(isDebug(), "%s: MDP unsupported layer found at %d",
698 __FUNCTION__, i);
699 return false;
700 }
701 mCurrentFrame.isFBComposed[i] = false;
702 }
703 }
704
705 mCurrentFrame.fbZ = minBatchStart;
706 mCurrentFrame.fbCount = batchSize;
707 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - batchSize;
708
Saurabh Shah173f4242013-11-20 09:50:12 -0800709 if(!resourceCheck(ctx, list)) {
710 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700711 return false;
712 }
713
714 ALOGD_IF(isDebug(), "%s: fbZ %d batchSize %d",
715 __FUNCTION__, mCurrentFrame.fbZ, batchSize);
716 return true;
717}
718
Saurabh Shahb772ae32013-11-18 15:40:02 -0800719bool MDPComp::loadBasedCompPreferMDP(hwc_context_t *ctx,
720 hwc_display_contents_1_t* list) {
721 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
722 //TODO get the ib from sysfs node.
723 //Full screen is from ib perspective, not actual full screen
724 const int bpp = 4;
725 double panelRefRate =
726 1000000000.0 / ctx->dpyAttr[mDpy].vsync_period;
727
728 double bwLeft = sMaxBw - sBwClaimed;
729
730 const int fullScreenLayers = bwLeft * 1000000000 / (ctx->dpyAttr[mDpy].xres
731 * ctx->dpyAttr[mDpy].yres * bpp * panelRefRate);
732
733 const int fbBatchSize = numAppLayers - (fullScreenLayers - 1);
734 //If batch size is not at least 2, we aren't really preferring MDP, since
735 //only 1 layer going to GPU could actually translate into an entire FB
736 //needed to be fetched by MDP, thus needing more b/w rather than less.
737 if(fbBatchSize < 2 || fbBatchSize > numAppLayers) {
738 ALOGD_IF(isDebug(), "%s: Not attempting", __FUNCTION__);
739 return false;
740 }
741
742 //Top-most layers constitute FB batch
743 const int fbBatchStart = numAppLayers - fbBatchSize;
744
745 //Bottom-most layers constitute MDP batch
746 for(int i = 0; i < fbBatchStart; i++) {
747 hwc_layer_1_t* layer = &list->hwLayers[i];
748 if(not isSupportedForMDPComp(ctx, layer)) {
749 ALOGD_IF(isDebug(), "%s: MDP unsupported layer found at %d",
750 __FUNCTION__, i);
751 return false;
752 }
753 mCurrentFrame.isFBComposed[i] = false;
754 }
755
756 mCurrentFrame.fbZ = fbBatchStart;
757 mCurrentFrame.fbCount = fbBatchSize;
758 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - fbBatchSize;
759
760 if(!resourceCheck(ctx, list)) {
761 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
762 return false;
763 }
764
765 ALOGD_IF(isDebug(), "%s: FB Z %d, num app layers %d, MDP Batch Size %d",
766 __FUNCTION__, mCurrentFrame.fbZ, numAppLayers,
767 numAppLayers - fbBatchSize);
768
769 return true;
770}
771
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700772bool MDPComp::isLoadBasedCompDoable(hwc_context_t *ctx,
773 hwc_display_contents_1_t* list) {
774 if(mDpy or isSecurePresent(ctx, mDpy) or
775 not (list->flags & HWC_GEOMETRY_CHANGED)) {
776 return false;
777 }
778 return true;
779}
780
Saurabh Shahaa236822013-04-24 18:07:26 -0700781bool MDPComp::isOnlyVideoDoable(hwc_context_t *ctx,
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700782 hwc_display_contents_1_t* list, bool secureOnly) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700783 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700784
Saurabh Shahaa236822013-04-24 18:07:26 -0700785 mCurrentFrame.reset(numAppLayers);
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700786 updateYUV(ctx, list, secureOnly);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700787 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700788
789 if(!isYuvPresent(ctx, mDpy)) {
790 return false;
791 }
792
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -0800793 /* Bail out if we are processing only secured video layers
794 * and we dont have any */
795 if(!isSecurePresent(ctx, mDpy) && secureOnly){
796 return false;
797 }
798
Saurabh Shah4fdde762013-04-30 18:47:33 -0700799 if(!mdpCount)
800 return false;
801
Saurabh Shah173f4242013-11-20 09:50:12 -0800802 if(!resourceCheck(ctx, list)) {
803 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700804 return false;
805 }
806
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800807 return true;
808}
809
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800810/* Checks for conditions where YUV layers cannot be bypassed */
811bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Saurabh Shahe2474082013-05-15 16:32:13 -0700812 bool extAnimBlockFeature = mDpy && ctx->listStats[mDpy].isDisplayAnimating;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800813
Saurabh Shahe2474082013-05-15 16:32:13 -0700814 if(isSkipLayer(layer) && !extAnimBlockFeature) {
815 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800816 return false;
817 }
818
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700819 if(layer->transform & HWC_TRANSFORM_ROT_90 && !canUseRotator(ctx,mDpy)) {
820 ALOGD_IF(isDebug(), "%s: no free DMA pipe",__FUNCTION__);
821 return false;
822 }
823
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800824 if(isSecuring(ctx, layer)) {
825 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
826 return false;
827 }
828
Saurabh Shah4fdde762013-04-30 18:47:33 -0700829 if(!isValidDimension(ctx, layer)) {
830 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
831 __FUNCTION__);
832 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800833 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700834
Naseer Ahmeddc61a972013-07-10 17:50:54 -0400835 if(layer->planeAlpha < 0xFF) {
836 ALOGD_IF(isDebug(), "%s: Cannot handle YUV layer with plane alpha\
837 in video only mode",
838 __FUNCTION__);
839 return false;
840 }
841
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800842 return true;
843}
844
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530845/* starts at fromIndex and check for each layer to find
846 * if it it has overlapping with any Updating layer above it in zorder
847 * till the end of the batch. returns true if it finds any intersection */
848bool MDPComp::canPushBatchToTop(const hwc_display_contents_1_t* list,
849 int fromIndex, int toIndex) {
850 for(int i = fromIndex; i < toIndex; i++) {
851 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
852 if(intersectingUpdatingLayers(list, i+1, toIndex, i)) {
853 return false;
854 }
855 }
856 }
857 return true;
858}
859
860/* Checks if given layer at targetLayerIndex has any
861 * intersection with all the updating layers in beween
862 * fromIndex and toIndex. Returns true if it finds intersectiion */
863bool MDPComp::intersectingUpdatingLayers(const hwc_display_contents_1_t* list,
864 int fromIndex, int toIndex, int targetLayerIndex) {
865 for(int i = fromIndex; i <= toIndex; i++) {
866 if(!mCurrentFrame.isFBComposed[i]) {
867 if(areLayersIntersecting(&list->hwLayers[i],
868 &list->hwLayers[targetLayerIndex])) {
869 return true;
870 }
871 }
872 }
873 return false;
874}
875
876int MDPComp::getBatch(hwc_display_contents_1_t* list,
877 int& maxBatchStart, int& maxBatchEnd,
878 int& maxBatchCount) {
879 int i = 0;
880 int updatingLayersAbove = 0;//Updating layer count in middle of batch
881 int fbZOrder =-1;
882 while (i < mCurrentFrame.layerCount) {
883 int batchCount = 0;
884 int batchStart = i;
885 int batchEnd = i;
886 int fbZ = batchStart;
887 int firstZReverseIndex = -1;
888 while(i < mCurrentFrame.layerCount) {
889 if(!mCurrentFrame.isFBComposed[i]) {
890 if(!batchCount) {
891 i++;
892 break;
893 }
894 updatingLayersAbove++;
895 i++;
896 continue;
897 } else {
898 if(mCurrentFrame.drop[i]) {
899 i++;
900 continue;
901 } else if(updatingLayersAbove <= 0) {
902 batchCount++;
903 batchEnd = i;
904 i++;
905 continue;
906 } else { //Layer is FBComposed, not a drop & updatingLayer > 0
907
908 // We have a valid updating layer already. If layer-i not
909 // have overlapping with all updating layers in between
910 // batch-start and i, then we can add layer i to batch.
911 if(!intersectingUpdatingLayers(list, batchStart, i-1, i)) {
912 batchCount++;
913 batchEnd = i;
914 i++;
915 continue;
916 } else if(canPushBatchToTop(list, batchStart, i)) {
917 //If All the non-updating layers with in this batch
918 //does not have intersection with the updating layers
919 //above in z-order, then we can safely move the batch to
920 //higher z-order. Increment fbZ as it is moving up.
921 if( firstZReverseIndex < 0) {
922 firstZReverseIndex = i;
923 }
924 batchCount++;
925 batchEnd = i;
926 fbZ += updatingLayersAbove;
927 i++;
928 updatingLayersAbove = 0;
929 continue;
930 } else {
931 //both failed.start the loop again from here.
932 if(firstZReverseIndex >= 0) {
933 i = firstZReverseIndex;
934 }
935 break;
936 }
937 }
938 }
939 }
940 if(batchCount > maxBatchCount) {
941 maxBatchCount = batchCount;
942 maxBatchStart = batchStart;
943 maxBatchEnd = batchEnd;
944 fbZOrder = fbZ;
945 }
946 }
947 return fbZOrder;
948}
949
950bool MDPComp::markLayersForCaching(hwc_context_t* ctx,
951 hwc_display_contents_1_t* list) {
952 /* Idea is to keep as many non-updating(cached) layers in FB and
953 * send rest of them through MDP. This is done in 2 steps.
954 * 1. Find the maximum contiguous batch of non-updating layers.
955 * 2. See if we can improve this batch size for caching by adding
956 * opaque layers around the batch, if they don't have
957 * any overlapping with the updating layers in between.
958 * NEVER mark an updating layer for caching.
959 * But cached ones can be marked for MDP */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800960
961 int maxBatchStart = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700962 int maxBatchEnd = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800963 int maxBatchCount = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530964 int fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800965
966 /* All or Nothing is cached. No batching needed */
Saurabh Shahaa236822013-04-24 18:07:26 -0700967 if(!mCurrentFrame.fbCount) {
968 mCurrentFrame.fbZ = -1;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700969 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -0700970 }
971 if(!mCurrentFrame.mdpCount) {
972 mCurrentFrame.fbZ = 0;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700973 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -0700974 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800975
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530976 fbZ = getBatch(list, maxBatchStart, maxBatchEnd, maxBatchCount);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800977
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530978 /* reset rest of the layers lying inside ROI for MDP comp */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800979 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700980 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700981 if((i < maxBatchStart || i > maxBatchEnd) &&
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530982 mCurrentFrame.isFBComposed[i]){
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700983 if(!mCurrentFrame.drop[i]){
984 //If an unsupported layer is being attempted to
985 //be pulled out we should fail
986 if(not isSupportedForMDPComp(ctx, layer)) {
987 return false;
988 }
989 mCurrentFrame.isFBComposed[i] = false;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700990 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800991 }
992 }
993
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530994 // update the frame data
995 mCurrentFrame.fbZ = fbZ;
996 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700997 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700998 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800999
1000 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301001 mCurrentFrame.fbCount);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001002
1003 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001004}
Saurabh Shah85234ec2013-04-12 17:09:00 -07001005
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001006void MDPComp::updateLayerCache(hwc_context_t* ctx,
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001007 hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001008 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001009 int fbCount = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001010
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001011 for(int i = 0; i < numAppLayers; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001012 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001013 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001014 if(!mCurrentFrame.drop[i])
1015 fbCount++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001016 mCurrentFrame.isFBComposed[i] = true;
1017 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -07001018 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001019 }
1020 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001021
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001022 mCurrentFrame.fbCount = fbCount;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001023 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount
1024 - mCurrentFrame.dropCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001025
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001026 ALOGD_IF(isDebug(),"%s: MDP count: %d FB count %d drop count: %d"
1027 ,__FUNCTION__, mCurrentFrame.mdpCount, mCurrentFrame.fbCount,
1028 mCurrentFrame.dropCount);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001029}
1030
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001031void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list,
1032 bool secureOnly) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001033 int nYuvCount = ctx->listStats[mDpy].yuvCount;
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001034 if(!nYuvCount && mDpy) {
1035 //Reset "No animation on external display" related parameters.
1036 ctx->mPrevCropVideo.left = ctx->mPrevCropVideo.top =
1037 ctx->mPrevCropVideo.right = ctx->mPrevCropVideo.bottom = 0;
1038 ctx->mPrevDestVideo.left = ctx->mPrevDestVideo.top =
1039 ctx->mPrevDestVideo.right = ctx->mPrevDestVideo.bottom = 0;
1040 ctx->mPrevTransformVideo = 0;
1041 return;
1042 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001043 for(int index = 0;index < nYuvCount; index++){
1044 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
1045 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
1046
1047 if(!isYUVDoable(ctx, layer)) {
1048 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
1049 mCurrentFrame.isFBComposed[nYuvIndex] = true;
1050 mCurrentFrame.fbCount++;
1051 }
1052 } else {
1053 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001054 private_handle_t *hnd = (private_handle_t *)layer->handle;
1055 if(!secureOnly || isSecureBuffer(hnd)) {
1056 mCurrentFrame.isFBComposed[nYuvIndex] = false;
1057 mCurrentFrame.fbCount--;
1058 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001059 }
1060 }
1061 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001062
1063 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001064 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
1065 ALOGD_IF(isDebug(),"%s: fb count: %d",__FUNCTION__,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001066 mCurrentFrame.fbCount);
1067}
1068
Saurabh Shahaa236822013-04-24 18:07:26 -07001069bool MDPComp::programMDP(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001070 if(!allocLayerPipes(ctx, list)) {
1071 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -07001072 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001073 }
1074
1075 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001076 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001077 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001078 int mdpIndex = mCurrentFrame.layerToMDP[index];
1079 hwc_layer_1_t* layer = &list->hwLayers[index];
1080
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301081 //Leave fbZ for framebuffer. CACHE/GLES layers go here.
1082 if(mdpNextZOrder == mCurrentFrame.fbZ) {
1083 mdpNextZOrder++;
1084 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001085 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1086 cur_pipe->zOrder = mdpNextZOrder++;
1087
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301088
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001089 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
1090 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
1091 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -07001092 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001093 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001094 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001095 }
1096
Saurabh Shahaa236822013-04-24 18:07:26 -07001097 return true;
1098}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001099
Saurabh Shahaa236822013-04-24 18:07:26 -07001100bool MDPComp::programYUV(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
1101 if(!allocLayerPipes(ctx, list)) {
1102 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
1103 return false;
1104 }
1105 //If we are in this block, it means we have yuv + rgb layers both
1106 int mdpIdx = 0;
1107 for (int index = 0; index < mCurrentFrame.layerCount; index++) {
1108 if(!mCurrentFrame.isFBComposed[index]) {
1109 hwc_layer_1_t* layer = &list->hwLayers[index];
1110 int mdpIndex = mCurrentFrame.layerToMDP[index];
1111 MdpPipeInfo* cur_pipe =
1112 mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1113 cur_pipe->zOrder = mdpIdx++;
1114
1115 if(configure(ctx, layer,
1116 mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
1117 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
1118 layer %d",__FUNCTION__, index);
1119 return false;
1120 }
1121 }
1122 }
1123 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001124}
1125
Saurabh Shah173f4242013-11-20 09:50:12 -08001126bool MDPComp::resourceCheck(hwc_context_t *ctx,
1127 hwc_display_contents_1_t *list) {
1128 const bool fbUsed = mCurrentFrame.fbCount;
1129 if(mCurrentFrame.mdpCount > sMaxPipesPerMixer - fbUsed) {
1130 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
1131 return false;
1132 }
1133
1134 if(!arePipesAvailable(ctx, list)) {
1135 return false;
1136 }
1137
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001138 double size = calcMDPBytesRead(ctx, list);
Saurabh Shah173f4242013-11-20 09:50:12 -08001139 if(!bandwidthCheck(ctx, size)) {
1140 ALOGD_IF(isDebug(), "%s: Exceeds bandwidth",__FUNCTION__);
1141 return false;
1142 }
1143
1144 return true;
1145}
1146
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001147double MDPComp::calcMDPBytesRead(hwc_context_t *ctx,
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001148 hwc_display_contents_1_t* list) {
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001149 double size = 0;
1150 const double GIG = 1000000000.0;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001151
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001152 //Skip for targets where no device tree value for bw is supplied
1153 if(sMaxBw <= 0.0) {
1154 return 0.0;
1155 }
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001156
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001157 for (uint32_t i = 0; i < list->numHwLayers - 1; i++) {
1158 if(!mCurrentFrame.isFBComposed[i]) {
1159 hwc_layer_1_t* layer = &list->hwLayers[i];
1160 private_handle_t *hnd = (private_handle_t *)layer->handle;
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001161 if (hnd) {
Saurabh Shah62e1d732013-09-17 10:44:05 -07001162 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah90789162013-09-16 10:29:20 -07001163 hwc_rect_t dst = layer->displayFrame;
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001164 float bpp = ((float)hnd->size) / (hnd->width * hnd->height);
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001165 size += (bpp * (crop.right - crop.left) *
1166 (crop.bottom - crop.top) *
1167 ctx->dpyAttr[mDpy].yres / (dst.bottom - dst.top)) /
1168 GIG;
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001169 }
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001170 }
1171 }
1172
1173 if(mCurrentFrame.fbCount) {
1174 hwc_layer_1_t* layer = &list->hwLayers[list->numHwLayers - 1];
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001175 int tempw, temph;
1176 size += (getBufferSizeAndDimensions(
1177 layer->displayFrame.right - layer->displayFrame.left,
1178 layer->displayFrame.bottom - layer->displayFrame.top,
1179 HAL_PIXEL_FORMAT_RGBA_8888,
1180 tempw, temph)) / GIG;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001181 }
1182
1183 return size;
1184}
1185
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001186bool MDPComp::bandwidthCheck(hwc_context_t *ctx, const double& size) {
1187 //Skip for targets where no device tree value for bw is supplied
1188 if(sMaxBw <= 0.0) {
1189 return true;
1190 }
1191
1192 double panelRefRate =
1193 1000000000.0 / ctx->dpyAttr[mDpy].vsync_period;
1194 if((size * panelRefRate) > (sMaxBw - sBwClaimed)) {
1195 return false;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001196 }
1197 return true;
1198}
1199
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001200int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001201 int ret = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -07001202 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001203 MDPVersion& mdpVersion = qdutils::MDPVersion::getInstance();
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -07001204
Saurabh Shahb39f8152013-08-22 10:21:44 -07001205 //reset old data
1206 mCurrentFrame.reset(numLayers);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001207 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1208 mCurrentFrame.dropCount = 0;
Prabhanjan Kandula088bd892013-07-02 23:47:13 +05301209
Saurabh Shahb39f8152013-08-22 10:21:44 -07001210 //number of app layers exceeds MAX_NUM_APP_LAYERS fall back to GPU
1211 //do not cache the information for next draw cycle.
1212 if(numLayers > MAX_NUM_APP_LAYERS) {
Prabhanjan Kandula25469a52013-07-12 16:19:31 +05301213 mCachedFrame.updateCounts(mCurrentFrame);
Arpita Banerjeed8965982013-11-08 17:27:33 -08001214 ALOGI("%s: Number of App layers exceeded the limit ",
Tatenda Chipeperekwa835337a2013-09-27 16:58:43 -07001215 __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001216 ret = -1;
Tatenda Chipeperekwa835337a2013-09-27 16:58:43 -07001217 return ret;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001218 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001219
Saurabh Shahb39f8152013-08-22 10:21:44 -07001220 //Hard conditions, if not met, cannot do MDP comp
1221 if(!isFrameDoable(ctx)) {
1222 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
1223 __FUNCTION__);
1224 reset(numLayers, list);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001225 ret = -1;
1226 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001227 }
1228
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001229 generateROI(ctx, list);
1230
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001231 //Convert from kbps to gbps
1232 sMaxBw = mdpVersion.getHighBw() / 1000000.0;
1233 if (ctx->mExtDisplay->isConnected() || ctx->mMDP.panel != MIPI_CMD_PANEL) {
1234 sMaxBw = mdpVersion.getLowBw() / 1000000.0;
1235 }
1236
Saurabh Shahb39f8152013-08-22 10:21:44 -07001237 //Check whether layers marked for MDP Composition is actually doable.
1238 if(isFullFrameDoable(ctx, list)) {
1239 mCurrentFrame.map();
1240 //Configure framebuffer first if applicable
1241 if(mCurrentFrame.fbZ >= 0) {
1242 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list,
1243 mCurrentFrame.fbZ)) {
1244 ALOGE("%s configure framebuffer failed", __func__);
1245 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -07001246 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001247 ret = -1;
1248 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001249 }
1250 }
1251 //Acquire and Program MDP pipes
1252 if(!programMDP(ctx, list)) {
1253 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -07001254 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001255 ret = -1;
1256 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001257 } else { //Success
1258 //Any change in composition types needs an FB refresh
1259 mCurrentFrame.needsRedraw = false;
Jeykumar Sankaran988d3682013-11-15 11:57:16 -08001260 if(!mCachedFrame.isSameFrame(mCurrentFrame, list) ||
Saurabh Shahb39f8152013-08-22 10:21:44 -07001261 (list->flags & HWC_GEOMETRY_CHANGED) ||
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +05301262 isSkipPresent(ctx, mDpy)) {
Saurabh Shahb39f8152013-08-22 10:21:44 -07001263 mCurrentFrame.needsRedraw = true;
1264 }
1265 }
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001266 } else if(isOnlyVideoDoable(ctx, list, false /*secure only*/) ||
1267 isOnlyVideoDoable(ctx, list, true /*secure only*/)) {
Saurabh Shahb39f8152013-08-22 10:21:44 -07001268 //All layers marked for MDP comp cannot be bypassed.
1269 //Try to compose atleast YUV layers through MDP comp and let
1270 //all the RGB layers compose in FB
1271 //Destination over
1272 mCurrentFrame.fbZ = -1;
1273 if(mCurrentFrame.fbCount)
1274 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
1275
1276 mCurrentFrame.map();
1277
1278 //Configure framebuffer first if applicable
1279 if(mCurrentFrame.fbZ >= 0) {
1280 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, mCurrentFrame.fbZ)) {
1281 ALOGE("%s configure framebuffer failed", __func__);
1282 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -07001283 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001284 ret = -1;
1285 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001286 }
1287 }
1288 if(!programYUV(ctx, list)) {
1289 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -07001290 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001291 ret = -1;
1292 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001293 }
1294 } else {
1295 reset(numLayers, list);
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -08001296 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1297 mCurrentFrame.dropCount = 0;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001298 ret = -1;
1299 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001300 }
Saurabh Shahb39f8152013-08-22 10:21:44 -07001301 //UpdateLayerFlags
1302 setMDPCompLayerFlags(ctx, list);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001303 mCachedFrame.cacheAll(list);
Saurabh Shahb39f8152013-08-22 10:21:44 -07001304 mCachedFrame.updateCounts(mCurrentFrame);
1305
Prabhanjan Kandula25469a52013-07-12 16:19:31 +05301306 // unlock it before calling dump function to avoid deadlock
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001307 if(isDebug()) {
Saurabh Shahaa236822013-04-24 18:07:26 -07001308 ALOGD("GEOMETRY change: %d", (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001309 android::String8 sDump("");
1310 dump(sDump);
1311 ALOGE("%s",sDump.string());
1312 }
1313
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001314exit:
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001315 double panelRefRate =
1316 1000000000.0 / ctx->dpyAttr[mDpy].vsync_period;
1317 sBwClaimed += calcMDPBytesRead(ctx, list) * panelRefRate;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001318 return ret;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001319}
1320
Saurabh Shah88e4d272013-09-03 13:31:29 -07001321//=============MDPCompNonSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001322
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001323/*
1324 * Configures pipe(s) for MDP composition
1325 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001326int MDPCompNonSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001327 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001328 MdpPipeInfoNonSplit& mdp_info =
1329 *(static_cast<MdpPipeInfoNonSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001330 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
1331 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1332 eIsFg isFg = IS_FG_OFF;
1333 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001334
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001335 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
1336 __FUNCTION__, layer, zOrder, dest);
1337
Saurabh Shah88e4d272013-09-03 13:31:29 -07001338 return configureNonSplit(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001339 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001340}
1341
Saurabh Shah88e4d272013-09-03 13:31:29 -07001342bool MDPCompNonSplit::arePipesAvailable(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001343 hwc_display_contents_1_t* list) {
1344 overlay::Overlay& ov = *ctx->mOverlay;
1345 int numPipesNeeded = mCurrentFrame.mdpCount;
1346 int availPipes = ov.availablePipes(mDpy, Overlay::MIXER_DEFAULT);
1347
1348 //Reserve pipe for FB
1349 if(mCurrentFrame.fbCount)
1350 availPipes -= 1;
1351
1352 if(numPipesNeeded > availPipes) {
1353 ALOGD_IF(isDebug(), "%s: Insufficient pipes, dpy %d needed %d, avail %d",
1354 __FUNCTION__, mDpy, numPipesNeeded, availPipes);
1355 return false;
1356 }
1357
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001358 if(not areVGPipesAvailable(ctx, list)) {
1359 return false;
1360 }
1361
1362 return true;
1363}
1364
1365bool MDPCompNonSplit::areVGPipesAvailable(hwc_context_t *ctx,
1366 hwc_display_contents_1_t* list) {
1367 overlay::Overlay& ov = *ctx->mOverlay;
1368 int pipesNeeded = 0;
1369 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1370 if(!mCurrentFrame.isFBComposed[i]) {
1371 hwc_layer_1_t* layer = &list->hwLayers[i];
1372 hwc_rect_t dst = layer->displayFrame;
1373 private_handle_t *hnd = (private_handle_t *)layer->handle;
1374 if(isYuvBuffer(hnd)) {
1375 pipesNeeded++;
1376 }
1377 }
1378 }
1379
1380 int availableVGPipes = ov.availablePipes(mDpy, ovutils::OV_MDP_PIPE_VG);
1381 if(pipesNeeded > availableVGPipes) {
1382 ALOGD_IF(isDebug(), "%s: Insufficient VG pipes for video layers"
1383 "dpy %d needed %d, avail %d",
1384 __FUNCTION__, mDpy, pipesNeeded, availableVGPipes);
1385 return false;
1386 }
1387
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001388 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001389}
1390
Saurabh Shah88e4d272013-09-03 13:31:29 -07001391bool MDPCompNonSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001392 hwc_display_contents_1_t* list) {
1393 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001394
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001395 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001396
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001397 hwc_layer_1_t* layer = &list->hwLayers[index];
1398 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001399 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001400 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001401 info.pipeInfo = new MdpPipeInfoNonSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08001402 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001403 MdpPipeInfoNonSplit& pipe_info = *(MdpPipeInfoNonSplit*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001404 ePipeType type = MDPCOMP_OV_ANY;
1405
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001406 if(isYuvBuffer(hnd)) {
1407 type = MDPCOMP_OV_VG;
Saurabh Shah8a117932013-05-23 12:48:13 -07001408 } else if(!qhwc::needsScaling(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001409 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
1410 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001411 type = MDPCOMP_OV_DMA;
1412 }
1413
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001414 pipe_info.index = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001415 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001416 ALOGD_IF(isDebug(), "%s: Unable to get pipe type = %d",
1417 __FUNCTION__, (int) type);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001418 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001419 }
1420 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001421 return true;
1422}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001423
Saurabh Shah88e4d272013-09-03 13:31:29 -07001424bool MDPCompNonSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001425
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001426 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001427 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1428 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -08001429 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001430
1431 if(!ctx || !list) {
1432 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001433 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001434 }
1435
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301436 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1437 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1438 return true;
1439 }
1440
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001441 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001442 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001443 idleInvalidator->markForSleep();
1444
1445 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001446 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001447
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001448 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1449 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001450 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001451 if(mCurrentFrame.isFBComposed[i]) continue;
1452
Naseer Ahmed5b6708a2012-08-02 13:46:08 -07001453 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001454 private_handle_t *hnd = (private_handle_t *)layer->handle;
1455 if(!hnd) {
1456 ALOGE("%s handle null", __FUNCTION__);
1457 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001458 }
1459
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001460 int mdpIndex = mCurrentFrame.layerToMDP[i];
1461
Saurabh Shah88e4d272013-09-03 13:31:29 -07001462 MdpPipeInfoNonSplit& pipe_info =
1463 *(MdpPipeInfoNonSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001464 ovutils::eDest dest = pipe_info.index;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001465 if(dest == ovutils::OV_INVALID) {
1466 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001467 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001468 }
1469
Saurabh Shahacf10202013-02-26 10:15:15 -08001470 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1471 continue;
1472 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001473
Saurabh Shahacf10202013-02-26 10:15:15 -08001474 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001475 using pipe: %d", __FUNCTION__, layer,
1476 hnd, dest );
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001477
Saurabh Shahacf10202013-02-26 10:15:15 -08001478 int fd = hnd->fd;
1479 uint32_t offset = hnd->offset;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001480
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001481 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -08001482 if(rot) {
1483 if(!rot->queueBuffer(fd, offset))
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001484 return false;
Saurabh Shahacf10202013-02-26 10:15:15 -08001485 fd = rot->getDstMemId();
1486 offset = rot->getDstOffset();
1487 }
1488
1489 if (!ov.queueBuffer(fd, offset, dest)) {
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301490 ALOGE("%s: queueBuffer failed for display:%d ", __FUNCTION__, mDpy);
Saurabh Shahacf10202013-02-26 10:15:15 -08001491 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001492 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001493
1494 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001495 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001496 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001497}
1498
Saurabh Shah88e4d272013-09-03 13:31:29 -07001499//=============MDPCompSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001500
Saurabh Shah88e4d272013-09-03 13:31:29 -07001501int MDPCompSplit::pipesNeeded(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001502 hwc_display_contents_1_t* list,
1503 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001504 int pipesNeeded = 0;
Saurabh Shah67a38c32013-06-10 16:23:15 -07001505 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001506
1507 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001508
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001509 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1510 if(!mCurrentFrame.isFBComposed[i]) {
1511 hwc_layer_1_t* layer = &list->hwLayers[i];
1512 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001513 if(mixer == Overlay::MIXER_LEFT && dst.left < lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001514 pipesNeeded++;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001515 } else if(mixer == Overlay::MIXER_RIGHT && dst.right > lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001516 pipesNeeded++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001517 }
1518 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001519 }
1520 return pipesNeeded;
1521}
1522
Saurabh Shah88e4d272013-09-03 13:31:29 -07001523bool MDPCompSplit::arePipesAvailable(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001524 hwc_display_contents_1_t* list) {
1525 overlay::Overlay& ov = *ctx->mOverlay;
Saurabh Shah082468e2013-09-12 10:05:32 -07001526 int totalPipesNeeded = 0;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001527
1528 for(int i = 0; i < Overlay::MIXER_MAX; i++) {
1529 int numPipesNeeded = pipesNeeded(ctx, list, i);
1530 int availPipes = ov.availablePipes(mDpy, i);
1531
1532 //Reserve pipe(s)for FB
1533 if(mCurrentFrame.fbCount)
Saurabh Shah082468e2013-09-12 10:05:32 -07001534 numPipesNeeded += 1;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001535
Saurabh Shah082468e2013-09-12 10:05:32 -07001536 totalPipesNeeded += numPipesNeeded;
1537
1538 //Per mixer check.
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001539 if(numPipesNeeded > availPipes) {
1540 ALOGD_IF(isDebug(), "%s: Insufficient pipes for "
1541 "dpy %d mixer %d needed %d, avail %d",
1542 __FUNCTION__, mDpy, i, numPipesNeeded, availPipes);
1543 return false;
1544 }
1545 }
Saurabh Shah082468e2013-09-12 10:05:32 -07001546
1547 //Per display check, since unused pipes can get counted twice.
1548 int totalPipesAvailable = ov.availablePipes(mDpy);
1549 if(totalPipesNeeded > totalPipesAvailable) {
1550 ALOGD_IF(isDebug(), "%s: Insufficient pipes for "
1551 "dpy %d needed %d, avail %d",
1552 __FUNCTION__, mDpy, totalPipesNeeded, totalPipesAvailable);
1553 return false;
1554 }
1555
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001556 if(not areVGPipesAvailable(ctx, list)) {
1557 return false;
1558 }
1559
1560 return true;
1561}
1562
1563bool MDPCompSplit::areVGPipesAvailable(hwc_context_t *ctx,
1564 hwc_display_contents_1_t* list) {
1565 overlay::Overlay& ov = *ctx->mOverlay;
1566 int pipesNeeded = 0;
1567 const int lSplit = getLeftSplit(ctx, mDpy);
1568 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1569 if(!mCurrentFrame.isFBComposed[i]) {
1570 hwc_layer_1_t* layer = &list->hwLayers[i];
1571 hwc_rect_t dst = layer->displayFrame;
1572 private_handle_t *hnd = (private_handle_t *)layer->handle;
1573 if(isYuvBuffer(hnd)) {
1574 if(dst.left < lSplit) {
1575 pipesNeeded++;
1576 }
1577 if(dst.right > lSplit) {
1578 pipesNeeded++;
1579 }
1580 }
1581 }
1582 }
1583
1584 int availableVGPipes = ov.availablePipes(mDpy, ovutils::OV_MDP_PIPE_VG);
1585 if(pipesNeeded > availableVGPipes) {
1586 ALOGD_IF(isDebug(), "%s: Insufficient VG pipes for video layers"
1587 "dpy %d needed %d, avail %d",
1588 __FUNCTION__, mDpy, pipesNeeded, availableVGPipes);
1589 return false;
1590 }
1591
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001592 return true;
1593}
1594
Saurabh Shah88e4d272013-09-03 13:31:29 -07001595bool MDPCompSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
1596 MdpPipeInfoSplit& pipe_info,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001597 ePipeType type) {
1598 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001599 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001600
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001601 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001602 pipe_info.lIndex = ovutils::OV_INVALID;
1603 pipe_info.rIndex = ovutils::OV_INVALID;
1604
1605 if (dst.left < lSplit) {
1606 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_LEFT);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001607 if(pipe_info.lIndex == ovutils::OV_INVALID)
1608 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001609 }
1610
1611 if(dst.right > lSplit) {
1612 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_RIGHT);
1613 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001614 return false;
1615 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001616
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001617 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001618}
1619
Saurabh Shah88e4d272013-09-03 13:31:29 -07001620bool MDPCompSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001621 hwc_display_contents_1_t* list) {
1622 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001623
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001624 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001625
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001626 hwc_layer_1_t* layer = &list->hwLayers[index];
1627 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001628 int mdpIndex = mCurrentFrame.layerToMDP[index];
1629 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001630 info.pipeInfo = new MdpPipeInfoSplit;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001631 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001632 MdpPipeInfoSplit& pipe_info = *(MdpPipeInfoSplit*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001633 ePipeType type = MDPCOMP_OV_ANY;
1634
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001635 if(isYuvBuffer(hnd)) {
1636 type = MDPCOMP_OV_VG;
Sushil Chauhan15a2ea62013-09-04 18:28:36 -07001637 } else if(!qhwc::needsScalingWithSplit(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001638 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001639 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001640 type = MDPCOMP_OV_DMA;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001641 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001642
1643 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001644 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type = %d",
1645 __FUNCTION__, (int) type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001646 return false;
1647 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001648 }
1649 return true;
1650}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001651
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001652/*
1653 * Configures pipe(s) for MDP composition
1654 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001655int MDPCompSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001656 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001657 MdpPipeInfoSplit& mdp_info =
1658 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001659 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1660 eIsFg isFg = IS_FG_OFF;
1661 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1662 eDest lDest = mdp_info.lIndex;
1663 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001664
1665 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1666 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1667
Saurabh Shah88e4d272013-09-03 13:31:29 -07001668 return configureSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001669 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001670}
1671
Saurabh Shah88e4d272013-09-03 13:31:29 -07001672bool MDPCompSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001673
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001674 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001675 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1676 return true;
1677 }
1678
1679 if(!ctx || !list) {
1680 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001681 return false;
1682 }
1683
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301684 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1685 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1686 return true;
1687 }
1688
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001689 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001690 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001691 idleInvalidator->markForSleep();
1692
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001693 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001694 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001695
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001696 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1697 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001698 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001699 if(mCurrentFrame.isFBComposed[i]) continue;
1700
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001701 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001702 private_handle_t *hnd = (private_handle_t *)layer->handle;
1703 if(!hnd) {
1704 ALOGE("%s handle null", __FUNCTION__);
1705 return false;
1706 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001707
1708 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1709 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001710 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001711
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001712 int mdpIndex = mCurrentFrame.layerToMDP[i];
1713
Saurabh Shah88e4d272013-09-03 13:31:29 -07001714 MdpPipeInfoSplit& pipe_info =
1715 *(MdpPipeInfoSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001716 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -08001717
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001718 ovutils::eDest indexL = pipe_info.lIndex;
1719 ovutils::eDest indexR = pipe_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001720
Saurabh Shahacf10202013-02-26 10:15:15 -08001721 int fd = hnd->fd;
1722 int offset = hnd->offset;
1723
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001724 if(ctx->mAD->isModeOn()) {
1725 if(ctx->mAD->draw(ctx, fd, offset)) {
1726 fd = ctx->mAD->getDstFd(ctx);
1727 offset = ctx->mAD->getDstOffset(ctx);
1728 }
1729 }
1730
Saurabh Shahacf10202013-02-26 10:15:15 -08001731 if(rot) {
1732 rot->queueBuffer(fd, offset);
1733 fd = rot->getDstMemId();
1734 offset = rot->getDstOffset();
1735 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001736
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001737 //************* play left mixer **********
1738 if(indexL != ovutils::OV_INVALID) {
1739 ovutils::eDest destL = (ovutils::eDest)indexL;
Saurabh Shahacf10202013-02-26 10:15:15 -08001740 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001741 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
Saurabh Shahacf10202013-02-26 10:15:15 -08001742 if (!ov.queueBuffer(fd, offset, destL)) {
1743 ALOGE("%s: queueBuffer failed for left mixer", __FUNCTION__);
1744 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001745 }
1746 }
1747
1748 //************* play right mixer **********
1749 if(indexR != ovutils::OV_INVALID) {
1750 ovutils::eDest destR = (ovutils::eDest)indexR;
Saurabh Shahacf10202013-02-26 10:15:15 -08001751 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001752 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
Saurabh Shahacf10202013-02-26 10:15:15 -08001753 if (!ov.queueBuffer(fd, offset, destR)) {
1754 ALOGE("%s: queueBuffer failed for right mixer", __FUNCTION__);
1755 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001756 }
1757 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001758
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001759 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1760 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001761
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001762 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001763}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001764}; //namespace
1765