blob: 8a56ca6028bb4835d2a3306da305cad29e7dec99 [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
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800329 if((w_dscale > 1.0f) || (h_dscale > 1.0f)) {
330 const uint32_t downscale =
Saurabh Shah4fdde762013-04-30 18:47:33 -0700331 qdutils::MDPVersion::getInstance().getMaxMDPDownscale();
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800332 if(ctx->mMDP.version >= qdutils::MDSS_V5) {
333 /* Workaround for downscales larger than 4x.
334 * Will be removed once decimator block is enabled for MDSS
335 */
336 if(!qdutils::MDPVersion::getInstance().supportsDecimation()) {
337 if(crop_w > MAX_DISPLAY_DIM || w_dscale > downscale ||
338 h_dscale > downscale)
339 return false;
340 } else {
341 if(w_dscale > 64 || h_dscale > 64)
342 return false;
343 }
344 } else { //A-family
345 if(w_dscale > downscale || h_dscale > downscale)
Saurabh Shah4fdde762013-04-30 18:47:33 -0700346 return false;
347 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700348 }
349
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800350 return true;
351}
352
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700353ovutils::eDest MDPComp::getMdpPipe(hwc_context_t *ctx, ePipeType type,
354 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800355 overlay::Overlay& ov = *ctx->mOverlay;
356 ovutils::eDest mdp_pipe = ovutils::OV_INVALID;
357
358 switch(type) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800359 case MDPCOMP_OV_DMA:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700360 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_DMA, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800361 if(mdp_pipe != ovutils::OV_INVALID) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800362 return mdp_pipe;
363 }
364 case MDPCOMP_OV_ANY:
365 case MDPCOMP_OV_RGB:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700366 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800367 if(mdp_pipe != ovutils::OV_INVALID) {
368 return mdp_pipe;
369 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800370
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800371 if(type == MDPCOMP_OV_RGB) {
372 //Requested only for RGB pipe
373 break;
374 }
375 case MDPCOMP_OV_VG:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700376 return ov.nextPipe(ovutils::OV_MDP_PIPE_VG, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800377 default:
378 ALOGE("%s: Invalid pipe type",__FUNCTION__);
379 return ovutils::OV_INVALID;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800380 };
381 return ovutils::OV_INVALID;
382}
383
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800384bool MDPComp::isFrameDoable(hwc_context_t *ctx) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700385 bool ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700386 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800387
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800388 if(!isEnabled()) {
389 ALOGD_IF(isDebug(),"%s: MDP Comp. not enabled.", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700390 ret = false;
Saurabh Shahd4e65852013-06-17 11:33:53 -0700391 } else if(qdutils::MDPVersion::getInstance().is8x26() &&
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700392 ctx->mVideoTransFlag && ctx->mVirtualDisplay->isConnected()) {
Saurabh Shahd4e65852013-06-17 11:33:53 -0700393 //1 Padding round to shift pipes across mixers
394 ALOGD_IF(isDebug(),"%s: MDP Comp. video transition padding round",
395 __FUNCTION__);
396 ret = false;
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700397 } else if(ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isConfiguring ||
398 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isConfiguring) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800399 ALOGD_IF( isDebug(),"%s: External Display connection is pending",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800400 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700401 ret = false;
Saurabh Shahaa236822013-04-24 18:07:26 -0700402 } else if(ctx->isPaddingRound) {
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700403 ctx->isPaddingRound = false;
404 ALOGD_IF(isDebug(), "%s: padding round",__FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700405 ret = false;
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700406 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700407 return ret;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800408}
409
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800410/*
411 * 1) Identify layers that are not visible in the updating ROI and drop them
412 * from composition.
413 * 2) If we have a scaling layers which needs cropping against generated ROI.
414 * Reset ROI to full resolution.
415 */
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700416bool MDPComp::validateAndApplyROI(hwc_context_t *ctx,
417 hwc_display_contents_1_t* list, hwc_rect_t roi) {
418 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
419
420 if(!isValidRect(roi))
421 return false;
422
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800423 hwc_rect_t visibleRect = roi;
424
425 for(int i = numAppLayers - 1; i >= 0; i--){
426
427 if(!isValidRect(visibleRect)) {
428 mCurrentFrame.drop[i] = true;
429 mCurrentFrame.dropCount++;
430 }
431
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700432 const hwc_layer_1_t* layer = &list->hwLayers[i];
433
434 hwc_rect_t dstRect = layer->displayFrame;
Arun Kumar K.R91090c72013-10-28 19:40:18 -0700435 hwc_rect_t srcRect = integerizeSourceCrop(layer->sourceCropf);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700436 int transform = layer->transform;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700437
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800438 hwc_rect_t res = getIntersection(visibleRect, dstRect);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700439
440 int res_w = res.right - res.left;
441 int res_h = res.bottom - res.top;
442 int dst_w = dstRect.right - dstRect.left;
443 int dst_h = dstRect.bottom - dstRect.top;
444
445 if(!isValidRect(res)) {
446 mCurrentFrame.drop[i] = true;
447 mCurrentFrame.dropCount++;
448 }else {
449 /* Reset frame ROI when any layer which needs scaling also needs ROI
450 * cropping */
451 if((res_w != dst_w || res_h != dst_h) &&
452 needsScaling (ctx, layer, mDpy)) {
Arpita Banerjeed8965982013-11-08 17:27:33 -0800453 ALOGI("%s: Resetting ROI due to scaling", __FUNCTION__);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700454 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
455 mCurrentFrame.dropCount = 0;
456 return false;
457 }
458 }
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800459
460 if (layer->blending == HWC_BLENDING_NONE)
461 visibleRect = deductRect(visibleRect, res);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700462 }
463 return true;
464}
465
466void MDPComp::generateROI(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
467 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
468
469 if(!sEnablePartialFrameUpdate) {
470 return;
471 }
472
473 if(mDpy || isDisplaySplit(ctx, mDpy)){
474 ALOGE_IF(isDebug(), "%s: ROI not supported for"
475 "the (1) external / virtual display's (2) dual DSI displays",
476 __FUNCTION__);
477 return;
478 }
479
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800480 if(isSkipPresent(ctx, mDpy))
481 return;
482
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700483 if(list->flags & HWC_GEOMETRY_CHANGED)
484 return;
485
486 struct hwc_rect roi = (struct hwc_rect){0, 0, 0, 0};
487 for(int index = 0; index < numAppLayers; index++ ) {
488 if ((mCachedFrame.hnd[index] != list->hwLayers[index].handle) ||
489 isYuvBuffer((private_handle_t *)list->hwLayers[index].handle)) {
490 hwc_rect_t dstRect = list->hwLayers[index].displayFrame;
Arun Kumar K.R91090c72013-10-28 19:40:18 -0700491 hwc_rect_t srcRect = integerizeSourceCrop(
492 list->hwLayers[index].sourceCropf);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700493 int transform = list->hwLayers[index].transform;
494
495 /* Intersect against display boundaries */
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700496 roi = getUnion(roi, dstRect);
497 }
498 }
499
500 if(!validateAndApplyROI(ctx, list, roi)){
501 roi = (struct hwc_rect) {0, 0,
502 (int)ctx->dpyAttr[mDpy].xres, (int)ctx->dpyAttr[mDpy].yres};
503 }
504
505 ctx->listStats[mDpy].roi.x = roi.left;
506 ctx->listStats[mDpy].roi.y = roi.top;
507 ctx->listStats[mDpy].roi.w = roi.right - roi.left;
508 ctx->listStats[mDpy].roi.h = roi.bottom - roi.top;
509
510 ALOGD_IF(isDebug(),"%s: generated ROI: [%d, %d, %d, %d]", __FUNCTION__,
511 roi.left, roi.top, roi.right, roi.bottom);
512}
513
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800514/* Checks for conditions where all the layers marked for MDP comp cannot be
515 * bypassed. On such conditions we try to bypass atleast YUV layers */
516bool MDPComp::isFullFrameDoable(hwc_context_t *ctx,
517 hwc_display_contents_1_t* list){
518
Saurabh Shahaa236822013-04-24 18:07:26 -0700519 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800520
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -0700521 if(sIdleFallBack && !ctx->listStats[mDpy].secureUI) {
Saurabh Shah2d998a92013-05-14 17:55:58 -0700522 ALOGD_IF(isDebug(), "%s: Idle fallback dpy %d",__FUNCTION__, mDpy);
523 return false;
524 }
525
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800526 if(isSkipPresent(ctx, mDpy)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700527 ALOGD_IF(isDebug(),"%s: SKIP present: %d",
528 __FUNCTION__,
529 isSkipPresent(ctx, mDpy));
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800530 return false;
531 }
532
Saurabh Shah9f084ad2013-05-02 11:28:09 -0700533 if(ctx->listStats[mDpy].needsAlphaScale
534 && ctx->mMDP.version < qdutils::MDSS_V5) {
535 ALOGD_IF(isDebug(), "%s: frame needs alpha downscaling",__FUNCTION__);
536 return false;
537 }
538
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800539 for(int i = 0; i < numAppLayers; ++i) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800540 hwc_layer_1_t* layer = &list->hwLayers[i];
541 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800542
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700543 if(isYuvBuffer(hnd) && has90Transform(layer)) {
544 if(!canUseRotator(ctx, mDpy)) {
545 ALOGD_IF(isDebug(), "%s: Can't use rotator for dpy %d",
546 __FUNCTION__, mDpy);
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700547 return false;
548 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800549 }
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530550
551 //For 8x26 with panel width>1k, if RGB layer needs HFLIP fail mdp comp
552 // may not need it if Gfx pre-rotation can handle all flips & rotations
553 if(qdutils::MDPVersion::getInstance().is8x26() &&
554 (ctx->dpyAttr[mDpy].xres > 1024) &&
555 (layer->transform & HWC_TRANSFORM_FLIP_H) &&
556 (!isYuvBuffer(hnd)))
557 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800558 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700559
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700560 if(ctx->mAD->isDoable()) {
561 return false;
562 }
563
Saurabh Shahaa236822013-04-24 18:07:26 -0700564 //If all above hard conditions are met we can do full or partial MDP comp.
565 bool ret = false;
566 if(fullMDPComp(ctx, list)) {
567 ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700568 } else if(partialMDPComp(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700569 ret = true;
570 }
571 return ret;
572}
573
574bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700575 //Will benefit presentation / secondary-only layer.
576 if((mDpy > HWC_DISPLAY_PRIMARY) &&
577 (list->numHwLayers - 1) > MAX_SEC_LAYERS) {
578 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
579 return false;
580 }
581
582 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
583 for(int i = 0; i < numAppLayers; i++) {
584 hwc_layer_1_t* layer = &list->hwLayers[i];
585 if(not isSupportedForMDPComp(ctx, layer)) {
586 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",__FUNCTION__);
587 return false;
588 }
Yang Xu9c1eb2b2013-11-26 01:28:13 +0800589
590 //For 8x26, if there is only one layer which needs scale for secondary
591 //while no scale for primary display, DMA pipe is occupied by primary.
592 //If need to fall back to GLES composition, virtual display lacks DMA
593 //pipe and error is reported.
594 if(qdutils::MDPVersion::getInstance().is8x26() &&
595 mDpy >= HWC_DISPLAY_EXTERNAL &&
596 qhwc::needsScaling(ctx, layer, mDpy))
597 return false;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700598 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700599 mCurrentFrame.fbCount = 0;
600 mCurrentFrame.fbZ = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700601 memcpy(&mCurrentFrame.isFBComposed, &mCurrentFrame.drop,
602 sizeof(mCurrentFrame.isFBComposed));
603 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount -
604 mCurrentFrame.dropCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700605
Saurabh Shah173f4242013-11-20 09:50:12 -0800606 if(!resourceCheck(ctx, list)) {
607 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700608 return false;
609 }
610
Saurabh Shahaa236822013-04-24 18:07:26 -0700611 return true;
612}
613
614bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
615{
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700616 if(!sEnableMixedMode) {
617 //Mixed mode is disabled. No need to even try caching.
618 return false;
619 }
620
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700621 bool ret = false;
622 if(isLoadBasedCompDoable(ctx, list)) {
Saurabh Shahb772ae32013-11-18 15:40:02 -0800623 ret = loadBasedCompPreferGPU(ctx, list) ||
624 loadBasedCompPreferMDP(ctx, list);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700625 }
626
627 if(!ret) {
628 ret = cacheBasedComp(ctx, list);
629 }
630
631 return ret;
632}
633
634bool MDPComp::cacheBasedComp(hwc_context_t *ctx,
635 hwc_display_contents_1_t* list) {
636 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700637 mCurrentFrame.reset(numAppLayers);
638 updateLayerCache(ctx, list);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700639
640 //If an MDP marked layer is unsupported cannot do partial MDP Comp
641 for(int i = 0; i < numAppLayers; i++) {
642 if(!mCurrentFrame.isFBComposed[i]) {
643 hwc_layer_1_t* layer = &list->hwLayers[i];
644 if(not isSupportedForMDPComp(ctx, layer)) {
645 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",
646 __FUNCTION__);
647 return false;
648 }
649 }
650 }
651
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700652 updateYUV(ctx, list, false /*secure only*/);
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530653 bool ret = markLayersForCaching(ctx, list); //sets up fbZ also
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700654 if(!ret) {
655 ALOGD_IF(isDebug(),"%s: batching failed, dpy %d",__FUNCTION__, mDpy);
656 return false;
657 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700658
659 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700660
661 //Will benefit cases where a video has non-updating background.
662 if((mDpy > HWC_DISPLAY_PRIMARY) and
663 (mdpCount > MAX_SEC_LAYERS)) {
664 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
665 return false;
666 }
667
Saurabh Shah173f4242013-11-20 09:50:12 -0800668 if(!resourceCheck(ctx, list)) {
669 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700670 return false;
671 }
672
Saurabh Shahaa236822013-04-24 18:07:26 -0700673 return true;
674}
675
Saurabh Shahb772ae32013-11-18 15:40:02 -0800676bool MDPComp::loadBasedCompPreferGPU(hwc_context_t *ctx,
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700677 hwc_display_contents_1_t* list) {
678 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
679 mCurrentFrame.reset(numAppLayers);
680
Saurabh Shahb772ae32013-11-18 15:40:02 -0800681 int stagesForMDP = min(sMaxPipesPerMixer, ctx->mOverlay->availablePipes(
682 mDpy, Overlay::MIXER_DEFAULT));
683 //If MDP has X possible stages, it can take X layers.
684 const int batchSize = numAppLayers - (stagesForMDP - 1); //1 for FB
685
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700686 if(batchSize <= 0) {
687 ALOGD_IF(isDebug(), "%s: Not attempting", __FUNCTION__);
688 return false;
689 }
690
691 int minBatchStart = -1;
692 size_t minBatchPixelCount = SIZE_MAX;
693
694 for(int i = 0; i <= numAppLayers - batchSize; i++) {
695 uint32_t batchPixelCount = 0;
696 for(int j = i; j < i + batchSize; j++) {
697 hwc_layer_1_t* layer = &list->hwLayers[j];
Arun Kumar K.R91090c72013-10-28 19:40:18 -0700698 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700699 batchPixelCount += (crop.right - crop.left) *
700 (crop.bottom - crop.top);
701 }
702
703 if(batchPixelCount < minBatchPixelCount) {
704 minBatchPixelCount = batchPixelCount;
705 minBatchStart = i;
706 }
707 }
708
709 if(minBatchStart < 0) {
710 ALOGD_IF(isDebug(), "%s: No batch found batchSize %d numAppLayers %d",
711 __FUNCTION__, batchSize, numAppLayers);
712 return false;
713 }
714
715 for(int i = 0; i < numAppLayers; i++) {
716 if(i < minBatchStart || i >= minBatchStart + batchSize) {
717 hwc_layer_1_t* layer = &list->hwLayers[i];
718 if(not isSupportedForMDPComp(ctx, layer)) {
719 ALOGD_IF(isDebug(), "%s: MDP unsupported layer found at %d",
720 __FUNCTION__, i);
721 return false;
722 }
723 mCurrentFrame.isFBComposed[i] = false;
724 }
725 }
726
727 mCurrentFrame.fbZ = minBatchStart;
728 mCurrentFrame.fbCount = batchSize;
729 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - batchSize;
730
Saurabh Shah173f4242013-11-20 09:50:12 -0800731 if(!resourceCheck(ctx, list)) {
732 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700733 return false;
734 }
735
736 ALOGD_IF(isDebug(), "%s: fbZ %d batchSize %d",
737 __FUNCTION__, mCurrentFrame.fbZ, batchSize);
738 return true;
739}
740
Saurabh Shahb772ae32013-11-18 15:40:02 -0800741bool MDPComp::loadBasedCompPreferMDP(hwc_context_t *ctx,
742 hwc_display_contents_1_t* list) {
743 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
744 //TODO get the ib from sysfs node.
745 //Full screen is from ib perspective, not actual full screen
746 const int bpp = 4;
747 double panelRefRate =
748 1000000000.0 / ctx->dpyAttr[mDpy].vsync_period;
749
750 double bwLeft = sMaxBw - sBwClaimed;
751
752 const int fullScreenLayers = bwLeft * 1000000000 / (ctx->dpyAttr[mDpy].xres
753 * ctx->dpyAttr[mDpy].yres * bpp * panelRefRate);
754
755 const int fbBatchSize = numAppLayers - (fullScreenLayers - 1);
756 //If batch size is not at least 2, we aren't really preferring MDP, since
757 //only 1 layer going to GPU could actually translate into an entire FB
758 //needed to be fetched by MDP, thus needing more b/w rather than less.
759 if(fbBatchSize < 2 || fbBatchSize > numAppLayers) {
760 ALOGD_IF(isDebug(), "%s: Not attempting", __FUNCTION__);
761 return false;
762 }
763
764 //Top-most layers constitute FB batch
765 const int fbBatchStart = numAppLayers - fbBatchSize;
766
767 //Bottom-most layers constitute MDP batch
768 for(int i = 0; i < fbBatchStart; i++) {
769 hwc_layer_1_t* layer = &list->hwLayers[i];
770 if(not isSupportedForMDPComp(ctx, layer)) {
771 ALOGD_IF(isDebug(), "%s: MDP unsupported layer found at %d",
772 __FUNCTION__, i);
773 return false;
774 }
775 mCurrentFrame.isFBComposed[i] = false;
776 }
777
778 mCurrentFrame.fbZ = fbBatchStart;
779 mCurrentFrame.fbCount = fbBatchSize;
780 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - fbBatchSize;
781
782 if(!resourceCheck(ctx, list)) {
783 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
784 return false;
785 }
786
787 ALOGD_IF(isDebug(), "%s: FB Z %d, num app layers %d, MDP Batch Size %d",
788 __FUNCTION__, mCurrentFrame.fbZ, numAppLayers,
789 numAppLayers - fbBatchSize);
790
791 return true;
792}
793
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700794bool MDPComp::isLoadBasedCompDoable(hwc_context_t *ctx,
795 hwc_display_contents_1_t* list) {
796 if(mDpy or isSecurePresent(ctx, mDpy) or
797 not (list->flags & HWC_GEOMETRY_CHANGED)) {
798 return false;
799 }
800 return true;
801}
802
Saurabh Shahaa236822013-04-24 18:07:26 -0700803bool MDPComp::isOnlyVideoDoable(hwc_context_t *ctx,
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700804 hwc_display_contents_1_t* list, bool secureOnly) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700805 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700806
Saurabh Shahaa236822013-04-24 18:07:26 -0700807 mCurrentFrame.reset(numAppLayers);
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700808 updateYUV(ctx, list, secureOnly);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700809 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700810
811 if(!isYuvPresent(ctx, mDpy)) {
812 return false;
813 }
814
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -0800815 /* Bail out if we are processing only secured video layers
816 * and we dont have any */
817 if(!isSecurePresent(ctx, mDpy) && secureOnly){
818 return false;
819 }
820
Saurabh Shah4fdde762013-04-30 18:47:33 -0700821 if(!mdpCount)
822 return false;
823
Saurabh Shah173f4242013-11-20 09:50:12 -0800824 if(!resourceCheck(ctx, list)) {
825 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700826 return false;
827 }
828
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800829 return true;
830}
831
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800832/* Checks for conditions where YUV layers cannot be bypassed */
833bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Saurabh Shahe2474082013-05-15 16:32:13 -0700834 bool extAnimBlockFeature = mDpy && ctx->listStats[mDpy].isDisplayAnimating;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800835
Saurabh Shahe2474082013-05-15 16:32:13 -0700836 if(isSkipLayer(layer) && !extAnimBlockFeature) {
837 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800838 return false;
839 }
840
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700841 if(layer->transform & HWC_TRANSFORM_ROT_90 && !canUseRotator(ctx,mDpy)) {
842 ALOGD_IF(isDebug(), "%s: no free DMA pipe",__FUNCTION__);
843 return false;
844 }
845
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800846 if(isSecuring(ctx, layer)) {
847 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
848 return false;
849 }
850
Saurabh Shah4fdde762013-04-30 18:47:33 -0700851 if(!isValidDimension(ctx, layer)) {
852 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
853 __FUNCTION__);
854 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800855 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700856
Naseer Ahmeddc61a972013-07-10 17:50:54 -0400857 if(layer->planeAlpha < 0xFF) {
858 ALOGD_IF(isDebug(), "%s: Cannot handle YUV layer with plane alpha\
859 in video only mode",
860 __FUNCTION__);
861 return false;
862 }
863
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800864 return true;
865}
866
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530867/* starts at fromIndex and check for each layer to find
868 * if it it has overlapping with any Updating layer above it in zorder
869 * till the end of the batch. returns true if it finds any intersection */
870bool MDPComp::canPushBatchToTop(const hwc_display_contents_1_t* list,
871 int fromIndex, int toIndex) {
872 for(int i = fromIndex; i < toIndex; i++) {
873 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
874 if(intersectingUpdatingLayers(list, i+1, toIndex, i)) {
875 return false;
876 }
877 }
878 }
879 return true;
880}
881
882/* Checks if given layer at targetLayerIndex has any
883 * intersection with all the updating layers in beween
884 * fromIndex and toIndex. Returns true if it finds intersectiion */
885bool MDPComp::intersectingUpdatingLayers(const hwc_display_contents_1_t* list,
886 int fromIndex, int toIndex, int targetLayerIndex) {
887 for(int i = fromIndex; i <= toIndex; i++) {
888 if(!mCurrentFrame.isFBComposed[i]) {
889 if(areLayersIntersecting(&list->hwLayers[i],
890 &list->hwLayers[targetLayerIndex])) {
891 return true;
892 }
893 }
894 }
895 return false;
896}
897
898int MDPComp::getBatch(hwc_display_contents_1_t* list,
899 int& maxBatchStart, int& maxBatchEnd,
900 int& maxBatchCount) {
901 int i = 0;
902 int updatingLayersAbove = 0;//Updating layer count in middle of batch
903 int fbZOrder =-1;
904 while (i < mCurrentFrame.layerCount) {
905 int batchCount = 0;
906 int batchStart = i;
907 int batchEnd = i;
908 int fbZ = batchStart;
909 int firstZReverseIndex = -1;
910 while(i < mCurrentFrame.layerCount) {
911 if(!mCurrentFrame.isFBComposed[i]) {
912 if(!batchCount) {
913 i++;
914 break;
915 }
916 updatingLayersAbove++;
917 i++;
918 continue;
919 } else {
920 if(mCurrentFrame.drop[i]) {
921 i++;
922 continue;
923 } else if(updatingLayersAbove <= 0) {
924 batchCount++;
925 batchEnd = i;
926 i++;
927 continue;
928 } else { //Layer is FBComposed, not a drop & updatingLayer > 0
929
930 // We have a valid updating layer already. If layer-i not
931 // have overlapping with all updating layers in between
932 // batch-start and i, then we can add layer i to batch.
933 if(!intersectingUpdatingLayers(list, batchStart, i-1, i)) {
934 batchCount++;
935 batchEnd = i;
936 i++;
937 continue;
938 } else if(canPushBatchToTop(list, batchStart, i)) {
939 //If All the non-updating layers with in this batch
940 //does not have intersection with the updating layers
941 //above in z-order, then we can safely move the batch to
942 //higher z-order. Increment fbZ as it is moving up.
943 if( firstZReverseIndex < 0) {
944 firstZReverseIndex = i;
945 }
946 batchCount++;
947 batchEnd = i;
948 fbZ += updatingLayersAbove;
949 i++;
950 updatingLayersAbove = 0;
951 continue;
952 } else {
953 //both failed.start the loop again from here.
954 if(firstZReverseIndex >= 0) {
955 i = firstZReverseIndex;
956 }
957 break;
958 }
959 }
960 }
961 }
962 if(batchCount > maxBatchCount) {
963 maxBatchCount = batchCount;
964 maxBatchStart = batchStart;
965 maxBatchEnd = batchEnd;
966 fbZOrder = fbZ;
967 }
968 }
969 return fbZOrder;
970}
971
972bool MDPComp::markLayersForCaching(hwc_context_t* ctx,
973 hwc_display_contents_1_t* list) {
974 /* Idea is to keep as many non-updating(cached) layers in FB and
975 * send rest of them through MDP. This is done in 2 steps.
976 * 1. Find the maximum contiguous batch of non-updating layers.
977 * 2. See if we can improve this batch size for caching by adding
978 * opaque layers around the batch, if they don't have
979 * any overlapping with the updating layers in between.
980 * NEVER mark an updating layer for caching.
981 * But cached ones can be marked for MDP */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800982
983 int maxBatchStart = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700984 int maxBatchEnd = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800985 int maxBatchCount = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530986 int fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800987
988 /* All or Nothing is cached. No batching needed */
Saurabh Shahaa236822013-04-24 18:07:26 -0700989 if(!mCurrentFrame.fbCount) {
990 mCurrentFrame.fbZ = -1;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700991 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -0700992 }
993 if(!mCurrentFrame.mdpCount) {
994 mCurrentFrame.fbZ = 0;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700995 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -0700996 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800997
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530998 fbZ = getBatch(list, maxBatchStart, maxBatchEnd, maxBatchCount);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800999
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301000 /* reset rest of the layers lying inside ROI for MDP comp */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001001 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001002 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001003 if((i < maxBatchStart || i > maxBatchEnd) &&
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301004 mCurrentFrame.isFBComposed[i]){
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001005 if(!mCurrentFrame.drop[i]){
1006 //If an unsupported layer is being attempted to
1007 //be pulled out we should fail
1008 if(not isSupportedForMDPComp(ctx, layer)) {
1009 return false;
1010 }
1011 mCurrentFrame.isFBComposed[i] = false;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001012 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001013 }
1014 }
1015
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301016 // update the frame data
1017 mCurrentFrame.fbZ = fbZ;
1018 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001019 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001020 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001021
1022 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301023 mCurrentFrame.fbCount);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001024
1025 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001026}
Saurabh Shah85234ec2013-04-12 17:09:00 -07001027
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001028void MDPComp::updateLayerCache(hwc_context_t* ctx,
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001029 hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001030 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001031 int fbCount = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001032
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001033 for(int i = 0; i < numAppLayers; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001034 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001035 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001036 if(!mCurrentFrame.drop[i])
1037 fbCount++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001038 mCurrentFrame.isFBComposed[i] = true;
1039 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -07001040 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001041 }
1042 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001043
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001044 mCurrentFrame.fbCount = fbCount;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001045 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount
1046 - mCurrentFrame.dropCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001047
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001048 ALOGD_IF(isDebug(),"%s: MDP count: %d FB count %d drop count: %d"
1049 ,__FUNCTION__, mCurrentFrame.mdpCount, mCurrentFrame.fbCount,
1050 mCurrentFrame.dropCount);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001051}
1052
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001053void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list,
1054 bool secureOnly) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001055 int nYuvCount = ctx->listStats[mDpy].yuvCount;
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001056 if(!nYuvCount && mDpy) {
1057 //Reset "No animation on external display" related parameters.
1058 ctx->mPrevCropVideo.left = ctx->mPrevCropVideo.top =
1059 ctx->mPrevCropVideo.right = ctx->mPrevCropVideo.bottom = 0;
1060 ctx->mPrevDestVideo.left = ctx->mPrevDestVideo.top =
1061 ctx->mPrevDestVideo.right = ctx->mPrevDestVideo.bottom = 0;
1062 ctx->mPrevTransformVideo = 0;
1063 return;
1064 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001065 for(int index = 0;index < nYuvCount; index++){
1066 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
1067 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
1068
1069 if(!isYUVDoable(ctx, layer)) {
1070 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
1071 mCurrentFrame.isFBComposed[nYuvIndex] = true;
1072 mCurrentFrame.fbCount++;
1073 }
1074 } else {
1075 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001076 private_handle_t *hnd = (private_handle_t *)layer->handle;
1077 if(!secureOnly || isSecureBuffer(hnd)) {
1078 mCurrentFrame.isFBComposed[nYuvIndex] = false;
1079 mCurrentFrame.fbCount--;
1080 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001081 }
1082 }
1083 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001084
1085 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001086 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
1087 ALOGD_IF(isDebug(),"%s: fb count: %d",__FUNCTION__,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001088 mCurrentFrame.fbCount);
1089}
1090
Saurabh Shahaa236822013-04-24 18:07:26 -07001091bool MDPComp::programMDP(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001092 if(!allocLayerPipes(ctx, list)) {
1093 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -07001094 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001095 }
1096
1097 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001098 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001099 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001100 int mdpIndex = mCurrentFrame.layerToMDP[index];
1101 hwc_layer_1_t* layer = &list->hwLayers[index];
1102
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301103 //Leave fbZ for framebuffer. CACHE/GLES layers go here.
1104 if(mdpNextZOrder == mCurrentFrame.fbZ) {
1105 mdpNextZOrder++;
1106 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001107 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1108 cur_pipe->zOrder = mdpNextZOrder++;
1109
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301110
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001111 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
1112 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
1113 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -07001114 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001115 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001116 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001117 }
1118
Saurabh Shahaa236822013-04-24 18:07:26 -07001119 return true;
1120}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001121
Saurabh Shahaa236822013-04-24 18:07:26 -07001122bool MDPComp::programYUV(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
1123 if(!allocLayerPipes(ctx, list)) {
1124 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
1125 return false;
1126 }
1127 //If we are in this block, it means we have yuv + rgb layers both
1128 int mdpIdx = 0;
1129 for (int index = 0; index < mCurrentFrame.layerCount; index++) {
1130 if(!mCurrentFrame.isFBComposed[index]) {
1131 hwc_layer_1_t* layer = &list->hwLayers[index];
1132 int mdpIndex = mCurrentFrame.layerToMDP[index];
1133 MdpPipeInfo* cur_pipe =
1134 mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1135 cur_pipe->zOrder = mdpIdx++;
1136
1137 if(configure(ctx, layer,
1138 mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
1139 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
1140 layer %d",__FUNCTION__, index);
1141 return false;
1142 }
1143 }
1144 }
1145 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001146}
1147
Saurabh Shah173f4242013-11-20 09:50:12 -08001148bool MDPComp::resourceCheck(hwc_context_t *ctx,
1149 hwc_display_contents_1_t *list) {
1150 const bool fbUsed = mCurrentFrame.fbCount;
1151 if(mCurrentFrame.mdpCount > sMaxPipesPerMixer - fbUsed) {
1152 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
1153 return false;
1154 }
1155
1156 if(!arePipesAvailable(ctx, list)) {
1157 return false;
1158 }
1159
1160 uint32_t size = calcMDPBytesRead(ctx, list);
1161 if(!bandwidthCheck(ctx, size)) {
1162 ALOGD_IF(isDebug(), "%s: Exceeds bandwidth",__FUNCTION__);
1163 return false;
1164 }
1165
1166 return true;
1167}
1168
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001169uint32_t MDPComp::calcMDPBytesRead(hwc_context_t *ctx,
1170 hwc_display_contents_1_t* list) {
1171 uint32_t size = 0;
1172
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001173 if(!qdutils::MDPVersion::getInstance().is8x74v2())
1174 return 0;
1175
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001176 for (uint32_t i = 0; i < list->numHwLayers - 1; i++) {
1177 if(!mCurrentFrame.isFBComposed[i]) {
1178 hwc_layer_1_t* layer = &list->hwLayers[i];
1179 private_handle_t *hnd = (private_handle_t *)layer->handle;
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001180 if (hnd) {
Saurabh Shah62e1d732013-09-17 10:44:05 -07001181 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah90789162013-09-16 10:29:20 -07001182 hwc_rect_t dst = layer->displayFrame;
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001183 float bpp = ((float)hnd->size) / (hnd->width * hnd->height);
Saurabh Shah90789162013-09-16 10:29:20 -07001184 size += bpp * (crop.right - crop.left) *
1185 (crop.bottom - crop.top) *
1186 ctx->dpyAttr[mDpy].yres / (dst.bottom - dst.top);
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001187 }
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001188 }
1189 }
1190
1191 if(mCurrentFrame.fbCount) {
1192 hwc_layer_1_t* layer = &list->hwLayers[list->numHwLayers - 1];
1193 private_handle_t *hnd = (private_handle_t *)layer->handle;
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001194 if (hnd)
1195 size += hnd->size;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001196 }
1197
1198 return size;
1199}
1200
1201bool MDPComp::bandwidthCheck(hwc_context_t *ctx, const uint32_t& size) {
1202 //Will be added for other targets if we run into bandwidth issues and when
1203 //we have profiling data to set an upper limit.
1204 if(qdutils::MDPVersion::getInstance().is8x74v2()) {
Saurabh Shah3c1a6b02013-11-22 11:10:20 -08001205 const uint32_t ONE_GIG = 1000 * 1000 * 1000;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001206 double panelRefRate =
1207 1000000000.0 / ctx->dpyAttr[mDpy].vsync_period;
Saurabh Shah3c1a6b02013-11-22 11:10:20 -08001208 if((size * panelRefRate) > ((sMaxBw - sBwClaimed) * ONE_GIG)) {
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001209 return false;
1210 }
1211 }
1212 return true;
1213}
1214
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001215int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001216 int ret = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -07001217 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -07001218
Saurabh Shahb39f8152013-08-22 10:21:44 -07001219 //reset old data
1220 mCurrentFrame.reset(numLayers);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001221 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1222 mCurrentFrame.dropCount = 0;
Prabhanjan Kandula088bd892013-07-02 23:47:13 +05301223
Saurabh Shahb39f8152013-08-22 10:21:44 -07001224 //number of app layers exceeds MAX_NUM_APP_LAYERS fall back to GPU
1225 //do not cache the information for next draw cycle.
1226 if(numLayers > MAX_NUM_APP_LAYERS) {
Prabhanjan Kandula25469a52013-07-12 16:19:31 +05301227 mCachedFrame.updateCounts(mCurrentFrame);
Arpita Banerjeed8965982013-11-08 17:27:33 -08001228 ALOGI("%s: Number of App layers exceeded the limit ",
Tatenda Chipeperekwa835337a2013-09-27 16:58:43 -07001229 __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001230 ret = -1;
Tatenda Chipeperekwa835337a2013-09-27 16:58:43 -07001231 return ret;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001232 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001233
Saurabh Shahb39f8152013-08-22 10:21:44 -07001234 //Hard conditions, if not met, cannot do MDP comp
1235 if(!isFrameDoable(ctx)) {
1236 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
1237 __FUNCTION__);
1238 reset(numLayers, list);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001239 ret = -1;
1240 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001241 }
1242
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001243 generateROI(ctx, list);
1244
Saurabh Shahb39f8152013-08-22 10:21:44 -07001245 //Check whether layers marked for MDP Composition is actually doable.
1246 if(isFullFrameDoable(ctx, list)) {
1247 mCurrentFrame.map();
1248 //Configure framebuffer first if applicable
1249 if(mCurrentFrame.fbZ >= 0) {
1250 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list,
1251 mCurrentFrame.fbZ)) {
1252 ALOGE("%s configure framebuffer failed", __func__);
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 }
1258 }
1259 //Acquire and Program MDP pipes
1260 if(!programMDP(ctx, list)) {
1261 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -07001262 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001263 ret = -1;
1264 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001265 } else { //Success
1266 //Any change in composition types needs an FB refresh
1267 mCurrentFrame.needsRedraw = false;
Jeykumar Sankaran988d3682013-11-15 11:57:16 -08001268 if(!mCachedFrame.isSameFrame(mCurrentFrame, list) ||
Saurabh Shahb39f8152013-08-22 10:21:44 -07001269 (list->flags & HWC_GEOMETRY_CHANGED) ||
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +05301270 isSkipPresent(ctx, mDpy)) {
Saurabh Shahb39f8152013-08-22 10:21:44 -07001271 mCurrentFrame.needsRedraw = true;
1272 }
1273 }
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001274 } else if(isOnlyVideoDoable(ctx, list, false /*secure only*/) ||
1275 isOnlyVideoDoable(ctx, list, true /*secure only*/)) {
Saurabh Shahb39f8152013-08-22 10:21:44 -07001276 //All layers marked for MDP comp cannot be bypassed.
1277 //Try to compose atleast YUV layers through MDP comp and let
1278 //all the RGB layers compose in FB
1279 //Destination over
1280 mCurrentFrame.fbZ = -1;
1281 if(mCurrentFrame.fbCount)
1282 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
1283
1284 mCurrentFrame.map();
1285
1286 //Configure framebuffer first if applicable
1287 if(mCurrentFrame.fbZ >= 0) {
1288 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, mCurrentFrame.fbZ)) {
1289 ALOGE("%s configure framebuffer failed", __func__);
1290 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -07001291 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001292 ret = -1;
1293 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001294 }
1295 }
1296 if(!programYUV(ctx, list)) {
1297 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -07001298 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001299 ret = -1;
1300 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001301 }
1302 } else {
1303 reset(numLayers, list);
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -08001304 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1305 mCurrentFrame.dropCount = 0;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001306 ret = -1;
1307 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001308 }
Saurabh Shahb39f8152013-08-22 10:21:44 -07001309 //UpdateLayerFlags
1310 setMDPCompLayerFlags(ctx, list);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001311 mCachedFrame.cacheAll(list);
Saurabh Shahb39f8152013-08-22 10:21:44 -07001312 mCachedFrame.updateCounts(mCurrentFrame);
1313
Prabhanjan Kandula25469a52013-07-12 16:19:31 +05301314 // unlock it before calling dump function to avoid deadlock
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001315 if(isDebug()) {
Saurabh Shahaa236822013-04-24 18:07:26 -07001316 ALOGD("GEOMETRY change: %d", (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001317 android::String8 sDump("");
1318 dump(sDump);
1319 ALOGE("%s",sDump.string());
1320 }
1321
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001322exit:
Saurabh Shah3c1a6b02013-11-22 11:10:20 -08001323 //gbps (bytes / nanosec = gigabytes / sec)
1324 sBwClaimed += calcMDPBytesRead(ctx, list) /
1325 (double)ctx->dpyAttr[mDpy].vsync_period;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001326 return ret;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001327}
1328
Saurabh Shah88e4d272013-09-03 13:31:29 -07001329//=============MDPCompNonSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001330
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001331/*
1332 * Configures pipe(s) for MDP composition
1333 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001334int MDPCompNonSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001335 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001336 MdpPipeInfoNonSplit& mdp_info =
1337 *(static_cast<MdpPipeInfoNonSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001338 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
1339 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1340 eIsFg isFg = IS_FG_OFF;
1341 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001342
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001343 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
1344 __FUNCTION__, layer, zOrder, dest);
1345
Saurabh Shah88e4d272013-09-03 13:31:29 -07001346 return configureNonSplit(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001347 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001348}
1349
Saurabh Shah88e4d272013-09-03 13:31:29 -07001350bool MDPCompNonSplit::arePipesAvailable(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001351 hwc_display_contents_1_t* list) {
1352 overlay::Overlay& ov = *ctx->mOverlay;
1353 int numPipesNeeded = mCurrentFrame.mdpCount;
1354 int availPipes = ov.availablePipes(mDpy, Overlay::MIXER_DEFAULT);
1355
1356 //Reserve pipe for FB
1357 if(mCurrentFrame.fbCount)
1358 availPipes -= 1;
1359
1360 if(numPipesNeeded > availPipes) {
1361 ALOGD_IF(isDebug(), "%s: Insufficient pipes, dpy %d needed %d, avail %d",
1362 __FUNCTION__, mDpy, numPipesNeeded, availPipes);
1363 return false;
1364 }
1365
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001366 if(not areVGPipesAvailable(ctx, list)) {
1367 return false;
1368 }
1369
1370 return true;
1371}
1372
1373bool MDPCompNonSplit::areVGPipesAvailable(hwc_context_t *ctx,
1374 hwc_display_contents_1_t* list) {
1375 overlay::Overlay& ov = *ctx->mOverlay;
1376 int pipesNeeded = 0;
1377 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1378 if(!mCurrentFrame.isFBComposed[i]) {
1379 hwc_layer_1_t* layer = &list->hwLayers[i];
1380 hwc_rect_t dst = layer->displayFrame;
1381 private_handle_t *hnd = (private_handle_t *)layer->handle;
1382 if(isYuvBuffer(hnd)) {
1383 pipesNeeded++;
1384 }
1385 }
1386 }
1387
1388 int availableVGPipes = ov.availablePipes(mDpy, ovutils::OV_MDP_PIPE_VG);
1389 if(pipesNeeded > availableVGPipes) {
1390 ALOGD_IF(isDebug(), "%s: Insufficient VG pipes for video layers"
1391 "dpy %d needed %d, avail %d",
1392 __FUNCTION__, mDpy, pipesNeeded, availableVGPipes);
1393 return false;
1394 }
1395
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001396 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001397}
1398
Saurabh Shah88e4d272013-09-03 13:31:29 -07001399bool MDPCompNonSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001400 hwc_display_contents_1_t* list) {
1401 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001402
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001403 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001404
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001405 hwc_layer_1_t* layer = &list->hwLayers[index];
1406 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001407 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001408 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001409 info.pipeInfo = new MdpPipeInfoNonSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08001410 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001411 MdpPipeInfoNonSplit& pipe_info = *(MdpPipeInfoNonSplit*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001412 ePipeType type = MDPCOMP_OV_ANY;
1413
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001414 if(isYuvBuffer(hnd)) {
1415 type = MDPCOMP_OV_VG;
Saurabh Shah8a117932013-05-23 12:48:13 -07001416 } else if(!qhwc::needsScaling(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001417 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
1418 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001419 type = MDPCOMP_OV_DMA;
1420 }
1421
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001422 pipe_info.index = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001423 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001424 ALOGD_IF(isDebug(), "%s: Unable to get pipe type = %d",
1425 __FUNCTION__, (int) type);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001426 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001427 }
1428 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001429 return true;
1430}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001431
Saurabh Shah88e4d272013-09-03 13:31:29 -07001432bool MDPCompNonSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001433
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001434 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001435 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1436 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -08001437 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001438
1439 if(!ctx || !list) {
1440 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001441 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001442 }
1443
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301444 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1445 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1446 return true;
1447 }
1448
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001449 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001450 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001451 idleInvalidator->markForSleep();
1452
1453 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001454 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001455
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001456 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1457 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001458 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001459 if(mCurrentFrame.isFBComposed[i]) continue;
1460
Naseer Ahmed5b6708a2012-08-02 13:46:08 -07001461 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001462 private_handle_t *hnd = (private_handle_t *)layer->handle;
1463 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001464 if (!(layer->flags & HWC_COLOR_FILL)) {
1465 ALOGE("%s handle null", __FUNCTION__);
1466 return false;
1467 }
1468 // No PLAY for Color layer
1469 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1470 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001471 }
1472
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001473 int mdpIndex = mCurrentFrame.layerToMDP[i];
1474
Saurabh Shah88e4d272013-09-03 13:31:29 -07001475 MdpPipeInfoNonSplit& pipe_info =
1476 *(MdpPipeInfoNonSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001477 ovutils::eDest dest = pipe_info.index;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001478 if(dest == ovutils::OV_INVALID) {
1479 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001480 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001481 }
1482
Saurabh Shahacf10202013-02-26 10:15:15 -08001483 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1484 continue;
1485 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001486
Saurabh Shahacf10202013-02-26 10:15:15 -08001487 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001488 using pipe: %d", __FUNCTION__, layer,
1489 hnd, dest );
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001490
Saurabh Shahacf10202013-02-26 10:15:15 -08001491 int fd = hnd->fd;
1492 uint32_t offset = hnd->offset;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001493
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001494 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -08001495 if(rot) {
1496 if(!rot->queueBuffer(fd, offset))
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001497 return false;
Saurabh Shahacf10202013-02-26 10:15:15 -08001498 fd = rot->getDstMemId();
1499 offset = rot->getDstOffset();
1500 }
1501
1502 if (!ov.queueBuffer(fd, offset, dest)) {
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301503 ALOGE("%s: queueBuffer failed for display:%d ", __FUNCTION__, mDpy);
Saurabh Shahacf10202013-02-26 10:15:15 -08001504 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001505 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001506
1507 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001508 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001509 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001510}
1511
Saurabh Shah88e4d272013-09-03 13:31:29 -07001512//=============MDPCompSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001513
Saurabh Shah88e4d272013-09-03 13:31:29 -07001514int MDPCompSplit::pipesNeeded(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001515 hwc_display_contents_1_t* list,
1516 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001517 int pipesNeeded = 0;
Saurabh Shah67a38c32013-06-10 16:23:15 -07001518 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001519
1520 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001521
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001522 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1523 if(!mCurrentFrame.isFBComposed[i]) {
1524 hwc_layer_1_t* layer = &list->hwLayers[i];
1525 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001526 if(mixer == Overlay::MIXER_LEFT && dst.left < lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001527 pipesNeeded++;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001528 } else if(mixer == Overlay::MIXER_RIGHT && dst.right > lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001529 pipesNeeded++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001530 }
1531 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001532 }
1533 return pipesNeeded;
1534}
1535
Saurabh Shah88e4d272013-09-03 13:31:29 -07001536bool MDPCompSplit::arePipesAvailable(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001537 hwc_display_contents_1_t* list) {
1538 overlay::Overlay& ov = *ctx->mOverlay;
Saurabh Shah082468e2013-09-12 10:05:32 -07001539 int totalPipesNeeded = 0;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001540
1541 for(int i = 0; i < Overlay::MIXER_MAX; i++) {
1542 int numPipesNeeded = pipesNeeded(ctx, list, i);
1543 int availPipes = ov.availablePipes(mDpy, i);
1544
1545 //Reserve pipe(s)for FB
1546 if(mCurrentFrame.fbCount)
Saurabh Shah082468e2013-09-12 10:05:32 -07001547 numPipesNeeded += 1;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001548
Saurabh Shah082468e2013-09-12 10:05:32 -07001549 totalPipesNeeded += numPipesNeeded;
1550
1551 //Per mixer check.
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001552 if(numPipesNeeded > availPipes) {
1553 ALOGD_IF(isDebug(), "%s: Insufficient pipes for "
1554 "dpy %d mixer %d needed %d, avail %d",
1555 __FUNCTION__, mDpy, i, numPipesNeeded, availPipes);
1556 return false;
1557 }
1558 }
Saurabh Shah082468e2013-09-12 10:05:32 -07001559
1560 //Per display check, since unused pipes can get counted twice.
1561 int totalPipesAvailable = ov.availablePipes(mDpy);
1562 if(totalPipesNeeded > totalPipesAvailable) {
1563 ALOGD_IF(isDebug(), "%s: Insufficient pipes for "
1564 "dpy %d needed %d, avail %d",
1565 __FUNCTION__, mDpy, totalPipesNeeded, totalPipesAvailable);
1566 return false;
1567 }
1568
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001569 if(not areVGPipesAvailable(ctx, list)) {
1570 return false;
1571 }
1572
1573 return true;
1574}
1575
1576bool MDPCompSplit::areVGPipesAvailable(hwc_context_t *ctx,
1577 hwc_display_contents_1_t* list) {
1578 overlay::Overlay& ov = *ctx->mOverlay;
1579 int pipesNeeded = 0;
1580 const int lSplit = getLeftSplit(ctx, mDpy);
1581 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1582 if(!mCurrentFrame.isFBComposed[i]) {
1583 hwc_layer_1_t* layer = &list->hwLayers[i];
1584 hwc_rect_t dst = layer->displayFrame;
1585 private_handle_t *hnd = (private_handle_t *)layer->handle;
1586 if(isYuvBuffer(hnd)) {
1587 if(dst.left < lSplit) {
1588 pipesNeeded++;
1589 }
1590 if(dst.right > lSplit) {
1591 pipesNeeded++;
1592 }
1593 }
1594 }
1595 }
1596
1597 int availableVGPipes = ov.availablePipes(mDpy, ovutils::OV_MDP_PIPE_VG);
1598 if(pipesNeeded > availableVGPipes) {
1599 ALOGD_IF(isDebug(), "%s: Insufficient VG pipes for video layers"
1600 "dpy %d needed %d, avail %d",
1601 __FUNCTION__, mDpy, pipesNeeded, availableVGPipes);
1602 return false;
1603 }
1604
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001605 return true;
1606}
1607
Saurabh Shah88e4d272013-09-03 13:31:29 -07001608bool MDPCompSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
1609 MdpPipeInfoSplit& pipe_info,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001610 ePipeType type) {
1611 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001612 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001613
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001614 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001615 pipe_info.lIndex = ovutils::OV_INVALID;
1616 pipe_info.rIndex = ovutils::OV_INVALID;
1617
1618 if (dst.left < lSplit) {
1619 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_LEFT);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001620 if(pipe_info.lIndex == ovutils::OV_INVALID)
1621 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001622 }
1623
1624 if(dst.right > lSplit) {
1625 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_RIGHT);
1626 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001627 return false;
1628 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001629
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001630 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001631}
1632
Saurabh Shah88e4d272013-09-03 13:31:29 -07001633bool MDPCompSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001634 hwc_display_contents_1_t* list) {
1635 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001636
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001637 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001638
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001639 hwc_layer_1_t* layer = &list->hwLayers[index];
1640 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001641 int mdpIndex = mCurrentFrame.layerToMDP[index];
1642 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001643 info.pipeInfo = new MdpPipeInfoSplit;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001644 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001645 MdpPipeInfoSplit& pipe_info = *(MdpPipeInfoSplit*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001646 ePipeType type = MDPCOMP_OV_ANY;
1647
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001648 if(isYuvBuffer(hnd)) {
1649 type = MDPCOMP_OV_VG;
Sushil Chauhan15a2ea62013-09-04 18:28:36 -07001650 } else if(!qhwc::needsScalingWithSplit(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001651 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001652 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001653 type = MDPCOMP_OV_DMA;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001654 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001655
1656 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001657 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type = %d",
1658 __FUNCTION__, (int) type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001659 return false;
1660 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001661 }
1662 return true;
1663}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001664
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001665/*
1666 * Configures pipe(s) for MDP composition
1667 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001668int MDPCompSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001669 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001670 MdpPipeInfoSplit& mdp_info =
1671 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001672 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1673 eIsFg isFg = IS_FG_OFF;
1674 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1675 eDest lDest = mdp_info.lIndex;
1676 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001677
1678 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1679 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1680
Saurabh Shah88e4d272013-09-03 13:31:29 -07001681 return configureSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001682 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001683}
1684
Saurabh Shah88e4d272013-09-03 13:31:29 -07001685bool MDPCompSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001686
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001687 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001688 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1689 return true;
1690 }
1691
1692 if(!ctx || !list) {
1693 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001694 return false;
1695 }
1696
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301697 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1698 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1699 return true;
1700 }
1701
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001702 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001703 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001704 idleInvalidator->markForSleep();
1705
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001706 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001707 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001708
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001709 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1710 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001711 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001712 if(mCurrentFrame.isFBComposed[i]) continue;
1713
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001714 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001715 private_handle_t *hnd = (private_handle_t *)layer->handle;
1716 if(!hnd) {
1717 ALOGE("%s handle null", __FUNCTION__);
1718 return false;
1719 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001720
1721 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1722 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001723 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001724
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001725 int mdpIndex = mCurrentFrame.layerToMDP[i];
1726
Saurabh Shah88e4d272013-09-03 13:31:29 -07001727 MdpPipeInfoSplit& pipe_info =
1728 *(MdpPipeInfoSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001729 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -08001730
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001731 ovutils::eDest indexL = pipe_info.lIndex;
1732 ovutils::eDest indexR = pipe_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001733
Saurabh Shahacf10202013-02-26 10:15:15 -08001734 int fd = hnd->fd;
1735 int offset = hnd->offset;
1736
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001737 if(ctx->mAD->isModeOn()) {
1738 if(ctx->mAD->draw(ctx, fd, offset)) {
1739 fd = ctx->mAD->getDstFd(ctx);
1740 offset = ctx->mAD->getDstOffset(ctx);
1741 }
1742 }
1743
Saurabh Shahacf10202013-02-26 10:15:15 -08001744 if(rot) {
1745 rot->queueBuffer(fd, offset);
1746 fd = rot->getDstMemId();
1747 offset = rot->getDstOffset();
1748 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001749
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001750 //************* play left mixer **********
1751 if(indexL != ovutils::OV_INVALID) {
1752 ovutils::eDest destL = (ovutils::eDest)indexL;
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, indexL );
Saurabh Shahacf10202013-02-26 10:15:15 -08001755 if (!ov.queueBuffer(fd, offset, destL)) {
1756 ALOGE("%s: queueBuffer failed for left mixer", __FUNCTION__);
1757 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001758 }
1759 }
1760
1761 //************* play right mixer **********
1762 if(indexR != ovutils::OV_INVALID) {
1763 ovutils::eDest destR = (ovutils::eDest)indexR;
Saurabh Shahacf10202013-02-26 10:15:15 -08001764 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001765 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
Saurabh Shahacf10202013-02-26 10:15:15 -08001766 if (!ov.queueBuffer(fd, offset, destR)) {
1767 ALOGE("%s: queueBuffer failed for right mixer", __FUNCTION__);
1768 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001769 }
1770 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001771
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001772 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1773 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001774
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001775 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001776}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001777}; //namespace
1778