blob: 7d4fa3edcde0240662a71265c273050983163bb1 [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 }
589 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700590 mCurrentFrame.fbCount = 0;
591 mCurrentFrame.fbZ = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700592 memcpy(&mCurrentFrame.isFBComposed, &mCurrentFrame.drop,
593 sizeof(mCurrentFrame.isFBComposed));
594 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount -
595 mCurrentFrame.dropCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700596
Saurabh Shah173f4242013-11-20 09:50:12 -0800597 if(!resourceCheck(ctx, list)) {
598 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700599 return false;
600 }
601
Saurabh Shahaa236822013-04-24 18:07:26 -0700602 return true;
603}
604
605bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
606{
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700607 if(!sEnableMixedMode) {
608 //Mixed mode is disabled. No need to even try caching.
609 return false;
610 }
611
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700612 bool ret = false;
613 if(isLoadBasedCompDoable(ctx, list)) {
Saurabh Shahb772ae32013-11-18 15:40:02 -0800614 ret = loadBasedCompPreferGPU(ctx, list) ||
615 loadBasedCompPreferMDP(ctx, list);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700616 }
617
618 if(!ret) {
619 ret = cacheBasedComp(ctx, list);
620 }
621
622 return ret;
623}
624
625bool MDPComp::cacheBasedComp(hwc_context_t *ctx,
626 hwc_display_contents_1_t* list) {
627 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700628 mCurrentFrame.reset(numAppLayers);
629 updateLayerCache(ctx, list);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700630
631 //If an MDP marked layer is unsupported cannot do partial MDP Comp
632 for(int i = 0; i < numAppLayers; i++) {
633 if(!mCurrentFrame.isFBComposed[i]) {
634 hwc_layer_1_t* layer = &list->hwLayers[i];
635 if(not isSupportedForMDPComp(ctx, layer)) {
636 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",
637 __FUNCTION__);
638 return false;
639 }
640 }
641 }
642
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700643 updateYUV(ctx, list, false /*secure only*/);
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530644 bool ret = markLayersForCaching(ctx, list); //sets up fbZ also
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700645 if(!ret) {
646 ALOGD_IF(isDebug(),"%s: batching failed, dpy %d",__FUNCTION__, mDpy);
647 return false;
648 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700649
650 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700651
652 //Will benefit cases where a video has non-updating background.
653 if((mDpy > HWC_DISPLAY_PRIMARY) and
654 (mdpCount > MAX_SEC_LAYERS)) {
655 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
656 return false;
657 }
658
Saurabh Shah173f4242013-11-20 09:50:12 -0800659 if(!resourceCheck(ctx, list)) {
660 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700661 return false;
662 }
663
Saurabh Shahaa236822013-04-24 18:07:26 -0700664 return true;
665}
666
Saurabh Shahb772ae32013-11-18 15:40:02 -0800667bool MDPComp::loadBasedCompPreferGPU(hwc_context_t *ctx,
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700668 hwc_display_contents_1_t* list) {
669 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
670 mCurrentFrame.reset(numAppLayers);
671
Saurabh Shahb772ae32013-11-18 15:40:02 -0800672 int stagesForMDP = min(sMaxPipesPerMixer, ctx->mOverlay->availablePipes(
673 mDpy, Overlay::MIXER_DEFAULT));
674 //If MDP has X possible stages, it can take X layers.
675 const int batchSize = numAppLayers - (stagesForMDP - 1); //1 for FB
676
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700677 if(batchSize <= 0) {
678 ALOGD_IF(isDebug(), "%s: Not attempting", __FUNCTION__);
679 return false;
680 }
681
682 int minBatchStart = -1;
683 size_t minBatchPixelCount = SIZE_MAX;
684
685 for(int i = 0; i <= numAppLayers - batchSize; i++) {
686 uint32_t batchPixelCount = 0;
687 for(int j = i; j < i + batchSize; j++) {
688 hwc_layer_1_t* layer = &list->hwLayers[j];
Arun Kumar K.R91090c72013-10-28 19:40:18 -0700689 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700690 batchPixelCount += (crop.right - crop.left) *
691 (crop.bottom - crop.top);
692 }
693
694 if(batchPixelCount < minBatchPixelCount) {
695 minBatchPixelCount = batchPixelCount;
696 minBatchStart = i;
697 }
698 }
699
700 if(minBatchStart < 0) {
701 ALOGD_IF(isDebug(), "%s: No batch found batchSize %d numAppLayers %d",
702 __FUNCTION__, batchSize, numAppLayers);
703 return false;
704 }
705
706 for(int i = 0; i < numAppLayers; i++) {
707 if(i < minBatchStart || i >= minBatchStart + batchSize) {
708 hwc_layer_1_t* layer = &list->hwLayers[i];
709 if(not isSupportedForMDPComp(ctx, layer)) {
710 ALOGD_IF(isDebug(), "%s: MDP unsupported layer found at %d",
711 __FUNCTION__, i);
712 return false;
713 }
714 mCurrentFrame.isFBComposed[i] = false;
715 }
716 }
717
718 mCurrentFrame.fbZ = minBatchStart;
719 mCurrentFrame.fbCount = batchSize;
720 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - batchSize;
721
Saurabh Shah173f4242013-11-20 09:50:12 -0800722 if(!resourceCheck(ctx, list)) {
723 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700724 return false;
725 }
726
727 ALOGD_IF(isDebug(), "%s: fbZ %d batchSize %d",
728 __FUNCTION__, mCurrentFrame.fbZ, batchSize);
729 return true;
730}
731
Saurabh Shahb772ae32013-11-18 15:40:02 -0800732bool MDPComp::loadBasedCompPreferMDP(hwc_context_t *ctx,
733 hwc_display_contents_1_t* list) {
734 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
735 //TODO get the ib from sysfs node.
736 //Full screen is from ib perspective, not actual full screen
737 const int bpp = 4;
738 double panelRefRate =
739 1000000000.0 / ctx->dpyAttr[mDpy].vsync_period;
740
741 double bwLeft = sMaxBw - sBwClaimed;
742
743 const int fullScreenLayers = bwLeft * 1000000000 / (ctx->dpyAttr[mDpy].xres
744 * ctx->dpyAttr[mDpy].yres * bpp * panelRefRate);
745
746 const int fbBatchSize = numAppLayers - (fullScreenLayers - 1);
747 //If batch size is not at least 2, we aren't really preferring MDP, since
748 //only 1 layer going to GPU could actually translate into an entire FB
749 //needed to be fetched by MDP, thus needing more b/w rather than less.
750 if(fbBatchSize < 2 || fbBatchSize > numAppLayers) {
751 ALOGD_IF(isDebug(), "%s: Not attempting", __FUNCTION__);
752 return false;
753 }
754
755 //Top-most layers constitute FB batch
756 const int fbBatchStart = numAppLayers - fbBatchSize;
757
758 //Bottom-most layers constitute MDP batch
759 for(int i = 0; i < fbBatchStart; i++) {
760 hwc_layer_1_t* layer = &list->hwLayers[i];
761 if(not isSupportedForMDPComp(ctx, layer)) {
762 ALOGD_IF(isDebug(), "%s: MDP unsupported layer found at %d",
763 __FUNCTION__, i);
764 return false;
765 }
766 mCurrentFrame.isFBComposed[i] = false;
767 }
768
769 mCurrentFrame.fbZ = fbBatchStart;
770 mCurrentFrame.fbCount = fbBatchSize;
771 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - fbBatchSize;
772
773 if(!resourceCheck(ctx, list)) {
774 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
775 return false;
776 }
777
778 ALOGD_IF(isDebug(), "%s: FB Z %d, num app layers %d, MDP Batch Size %d",
779 __FUNCTION__, mCurrentFrame.fbZ, numAppLayers,
780 numAppLayers - fbBatchSize);
781
782 return true;
783}
784
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700785bool MDPComp::isLoadBasedCompDoable(hwc_context_t *ctx,
786 hwc_display_contents_1_t* list) {
787 if(mDpy or isSecurePresent(ctx, mDpy) or
788 not (list->flags & HWC_GEOMETRY_CHANGED)) {
789 return false;
790 }
791 return true;
792}
793
Saurabh Shahaa236822013-04-24 18:07:26 -0700794bool MDPComp::isOnlyVideoDoable(hwc_context_t *ctx,
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700795 hwc_display_contents_1_t* list, bool secureOnly) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700796 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700797
Saurabh Shahaa236822013-04-24 18:07:26 -0700798 mCurrentFrame.reset(numAppLayers);
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700799 updateYUV(ctx, list, secureOnly);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700800 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700801
802 if(!isYuvPresent(ctx, mDpy)) {
803 return false;
804 }
805
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -0800806 /* Bail out if we are processing only secured video layers
807 * and we dont have any */
808 if(!isSecurePresent(ctx, mDpy) && secureOnly){
809 return false;
810 }
811
Saurabh Shah4fdde762013-04-30 18:47:33 -0700812 if(!mdpCount)
813 return false;
814
Saurabh Shah173f4242013-11-20 09:50:12 -0800815 if(!resourceCheck(ctx, list)) {
816 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700817 return false;
818 }
819
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800820 return true;
821}
822
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800823/* Checks for conditions where YUV layers cannot be bypassed */
824bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Saurabh Shahe2474082013-05-15 16:32:13 -0700825 bool extAnimBlockFeature = mDpy && ctx->listStats[mDpy].isDisplayAnimating;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800826
Saurabh Shahe2474082013-05-15 16:32:13 -0700827 if(isSkipLayer(layer) && !extAnimBlockFeature) {
828 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800829 return false;
830 }
831
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700832 if(layer->transform & HWC_TRANSFORM_ROT_90 && !canUseRotator(ctx,mDpy)) {
833 ALOGD_IF(isDebug(), "%s: no free DMA pipe",__FUNCTION__);
834 return false;
835 }
836
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800837 if(isSecuring(ctx, layer)) {
838 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
839 return false;
840 }
841
Saurabh Shah4fdde762013-04-30 18:47:33 -0700842 if(!isValidDimension(ctx, layer)) {
843 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
844 __FUNCTION__);
845 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800846 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700847
Naseer Ahmeddc61a972013-07-10 17:50:54 -0400848 if(layer->planeAlpha < 0xFF) {
849 ALOGD_IF(isDebug(), "%s: Cannot handle YUV layer with plane alpha\
850 in video only mode",
851 __FUNCTION__);
852 return false;
853 }
854
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800855 return true;
856}
857
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530858/* starts at fromIndex and check for each layer to find
859 * if it it has overlapping with any Updating layer above it in zorder
860 * till the end of the batch. returns true if it finds any intersection */
861bool MDPComp::canPushBatchToTop(const hwc_display_contents_1_t* list,
862 int fromIndex, int toIndex) {
863 for(int i = fromIndex; i < toIndex; i++) {
864 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
865 if(intersectingUpdatingLayers(list, i+1, toIndex, i)) {
866 return false;
867 }
868 }
869 }
870 return true;
871}
872
873/* Checks if given layer at targetLayerIndex has any
874 * intersection with all the updating layers in beween
875 * fromIndex and toIndex. Returns true if it finds intersectiion */
876bool MDPComp::intersectingUpdatingLayers(const hwc_display_contents_1_t* list,
877 int fromIndex, int toIndex, int targetLayerIndex) {
878 for(int i = fromIndex; i <= toIndex; i++) {
879 if(!mCurrentFrame.isFBComposed[i]) {
880 if(areLayersIntersecting(&list->hwLayers[i],
881 &list->hwLayers[targetLayerIndex])) {
882 return true;
883 }
884 }
885 }
886 return false;
887}
888
889int MDPComp::getBatch(hwc_display_contents_1_t* list,
890 int& maxBatchStart, int& maxBatchEnd,
891 int& maxBatchCount) {
892 int i = 0;
893 int updatingLayersAbove = 0;//Updating layer count in middle of batch
894 int fbZOrder =-1;
895 while (i < mCurrentFrame.layerCount) {
896 int batchCount = 0;
897 int batchStart = i;
898 int batchEnd = i;
899 int fbZ = batchStart;
900 int firstZReverseIndex = -1;
901 while(i < mCurrentFrame.layerCount) {
902 if(!mCurrentFrame.isFBComposed[i]) {
903 if(!batchCount) {
904 i++;
905 break;
906 }
907 updatingLayersAbove++;
908 i++;
909 continue;
910 } else {
911 if(mCurrentFrame.drop[i]) {
912 i++;
913 continue;
914 } else if(updatingLayersAbove <= 0) {
915 batchCount++;
916 batchEnd = i;
917 i++;
918 continue;
919 } else { //Layer is FBComposed, not a drop & updatingLayer > 0
920
921 // We have a valid updating layer already. If layer-i not
922 // have overlapping with all updating layers in between
923 // batch-start and i, then we can add layer i to batch.
924 if(!intersectingUpdatingLayers(list, batchStart, i-1, i)) {
925 batchCount++;
926 batchEnd = i;
927 i++;
928 continue;
929 } else if(canPushBatchToTop(list, batchStart, i)) {
930 //If All the non-updating layers with in this batch
931 //does not have intersection with the updating layers
932 //above in z-order, then we can safely move the batch to
933 //higher z-order. Increment fbZ as it is moving up.
934 if( firstZReverseIndex < 0) {
935 firstZReverseIndex = i;
936 }
937 batchCount++;
938 batchEnd = i;
939 fbZ += updatingLayersAbove;
940 i++;
941 updatingLayersAbove = 0;
942 continue;
943 } else {
944 //both failed.start the loop again from here.
945 if(firstZReverseIndex >= 0) {
946 i = firstZReverseIndex;
947 }
948 break;
949 }
950 }
951 }
952 }
953 if(batchCount > maxBatchCount) {
954 maxBatchCount = batchCount;
955 maxBatchStart = batchStart;
956 maxBatchEnd = batchEnd;
957 fbZOrder = fbZ;
958 }
959 }
960 return fbZOrder;
961}
962
963bool MDPComp::markLayersForCaching(hwc_context_t* ctx,
964 hwc_display_contents_1_t* list) {
965 /* Idea is to keep as many non-updating(cached) layers in FB and
966 * send rest of them through MDP. This is done in 2 steps.
967 * 1. Find the maximum contiguous batch of non-updating layers.
968 * 2. See if we can improve this batch size for caching by adding
969 * opaque layers around the batch, if they don't have
970 * any overlapping with the updating layers in between.
971 * NEVER mark an updating layer for caching.
972 * But cached ones can be marked for MDP */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800973
974 int maxBatchStart = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700975 int maxBatchEnd = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800976 int maxBatchCount = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530977 int fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800978
979 /* All or Nothing is cached. No batching needed */
Saurabh Shahaa236822013-04-24 18:07:26 -0700980 if(!mCurrentFrame.fbCount) {
981 mCurrentFrame.fbZ = -1;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700982 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -0700983 }
984 if(!mCurrentFrame.mdpCount) {
985 mCurrentFrame.fbZ = 0;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700986 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -0700987 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800988
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530989 fbZ = getBatch(list, maxBatchStart, maxBatchEnd, maxBatchCount);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800990
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530991 /* reset rest of the layers lying inside ROI for MDP comp */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800992 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700993 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700994 if((i < maxBatchStart || i > maxBatchEnd) &&
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530995 mCurrentFrame.isFBComposed[i]){
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700996 if(!mCurrentFrame.drop[i]){
997 //If an unsupported layer is being attempted to
998 //be pulled out we should fail
999 if(not isSupportedForMDPComp(ctx, layer)) {
1000 return false;
1001 }
1002 mCurrentFrame.isFBComposed[i] = false;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001003 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001004 }
1005 }
1006
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301007 // update the frame data
1008 mCurrentFrame.fbZ = fbZ;
1009 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001010 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001011 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001012
1013 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301014 mCurrentFrame.fbCount);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001015
1016 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001017}
Saurabh Shah85234ec2013-04-12 17:09:00 -07001018
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001019void MDPComp::updateLayerCache(hwc_context_t* ctx,
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001020 hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001021 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001022 int fbCount = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001023
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001024 for(int i = 0; i < numAppLayers; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001025 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001026 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001027 if(!mCurrentFrame.drop[i])
1028 fbCount++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001029 mCurrentFrame.isFBComposed[i] = true;
1030 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -07001031 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001032 }
1033 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001034
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001035 mCurrentFrame.fbCount = fbCount;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001036 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount
1037 - mCurrentFrame.dropCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001038
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001039 ALOGD_IF(isDebug(),"%s: MDP count: %d FB count %d drop count: %d"
1040 ,__FUNCTION__, mCurrentFrame.mdpCount, mCurrentFrame.fbCount,
1041 mCurrentFrame.dropCount);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001042}
1043
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001044void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list,
1045 bool secureOnly) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001046 int nYuvCount = ctx->listStats[mDpy].yuvCount;
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001047 if(!nYuvCount && mDpy) {
1048 //Reset "No animation on external display" related parameters.
1049 ctx->mPrevCropVideo.left = ctx->mPrevCropVideo.top =
1050 ctx->mPrevCropVideo.right = ctx->mPrevCropVideo.bottom = 0;
1051 ctx->mPrevDestVideo.left = ctx->mPrevDestVideo.top =
1052 ctx->mPrevDestVideo.right = ctx->mPrevDestVideo.bottom = 0;
1053 ctx->mPrevTransformVideo = 0;
1054 return;
1055 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001056 for(int index = 0;index < nYuvCount; index++){
1057 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
1058 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
1059
1060 if(!isYUVDoable(ctx, layer)) {
1061 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
1062 mCurrentFrame.isFBComposed[nYuvIndex] = true;
1063 mCurrentFrame.fbCount++;
1064 }
1065 } else {
1066 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001067 private_handle_t *hnd = (private_handle_t *)layer->handle;
1068 if(!secureOnly || isSecureBuffer(hnd)) {
1069 mCurrentFrame.isFBComposed[nYuvIndex] = false;
1070 mCurrentFrame.fbCount--;
1071 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001072 }
1073 }
1074 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001075
1076 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001077 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
1078 ALOGD_IF(isDebug(),"%s: fb count: %d",__FUNCTION__,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001079 mCurrentFrame.fbCount);
1080}
1081
Saurabh Shahaa236822013-04-24 18:07:26 -07001082bool MDPComp::programMDP(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001083 if(!allocLayerPipes(ctx, list)) {
1084 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -07001085 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001086 }
1087
1088 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001089 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001090 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001091 int mdpIndex = mCurrentFrame.layerToMDP[index];
1092 hwc_layer_1_t* layer = &list->hwLayers[index];
1093
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301094 //Leave fbZ for framebuffer. CACHE/GLES layers go here.
1095 if(mdpNextZOrder == mCurrentFrame.fbZ) {
1096 mdpNextZOrder++;
1097 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001098 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1099 cur_pipe->zOrder = mdpNextZOrder++;
1100
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301101
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001102 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
1103 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
1104 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -07001105 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001106 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001107 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001108 }
1109
Saurabh Shahaa236822013-04-24 18:07:26 -07001110 return true;
1111}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001112
Saurabh Shahaa236822013-04-24 18:07:26 -07001113bool MDPComp::programYUV(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
1114 if(!allocLayerPipes(ctx, list)) {
1115 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
1116 return false;
1117 }
1118 //If we are in this block, it means we have yuv + rgb layers both
1119 int mdpIdx = 0;
1120 for (int index = 0; index < mCurrentFrame.layerCount; index++) {
1121 if(!mCurrentFrame.isFBComposed[index]) {
1122 hwc_layer_1_t* layer = &list->hwLayers[index];
1123 int mdpIndex = mCurrentFrame.layerToMDP[index];
1124 MdpPipeInfo* cur_pipe =
1125 mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1126 cur_pipe->zOrder = mdpIdx++;
1127
1128 if(configure(ctx, layer,
1129 mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
1130 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
1131 layer %d",__FUNCTION__, index);
1132 return false;
1133 }
1134 }
1135 }
1136 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001137}
1138
Saurabh Shah173f4242013-11-20 09:50:12 -08001139bool MDPComp::resourceCheck(hwc_context_t *ctx,
1140 hwc_display_contents_1_t *list) {
1141 const bool fbUsed = mCurrentFrame.fbCount;
1142 if(mCurrentFrame.mdpCount > sMaxPipesPerMixer - fbUsed) {
1143 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
1144 return false;
1145 }
1146
1147 if(!arePipesAvailable(ctx, list)) {
1148 return false;
1149 }
1150
1151 uint32_t size = calcMDPBytesRead(ctx, list);
1152 if(!bandwidthCheck(ctx, size)) {
1153 ALOGD_IF(isDebug(), "%s: Exceeds bandwidth",__FUNCTION__);
1154 return false;
1155 }
1156
1157 return true;
1158}
1159
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001160uint32_t MDPComp::calcMDPBytesRead(hwc_context_t *ctx,
1161 hwc_display_contents_1_t* list) {
1162 uint32_t size = 0;
1163
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001164 if(!qdutils::MDPVersion::getInstance().is8x74v2())
1165 return 0;
1166
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001167 for (uint32_t i = 0; i < list->numHwLayers - 1; i++) {
1168 if(!mCurrentFrame.isFBComposed[i]) {
1169 hwc_layer_1_t* layer = &list->hwLayers[i];
1170 private_handle_t *hnd = (private_handle_t *)layer->handle;
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001171 if (hnd) {
Saurabh Shah62e1d732013-09-17 10:44:05 -07001172 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah90789162013-09-16 10:29:20 -07001173 hwc_rect_t dst = layer->displayFrame;
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001174 float bpp = ((float)hnd->size) / (hnd->width * hnd->height);
Saurabh Shah90789162013-09-16 10:29:20 -07001175 size += bpp * (crop.right - crop.left) *
1176 (crop.bottom - crop.top) *
1177 ctx->dpyAttr[mDpy].yres / (dst.bottom - dst.top);
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001178 }
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001179 }
1180 }
1181
1182 if(mCurrentFrame.fbCount) {
1183 hwc_layer_1_t* layer = &list->hwLayers[list->numHwLayers - 1];
1184 private_handle_t *hnd = (private_handle_t *)layer->handle;
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001185 if (hnd)
1186 size += hnd->size;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001187 }
1188
1189 return size;
1190}
1191
1192bool MDPComp::bandwidthCheck(hwc_context_t *ctx, const uint32_t& size) {
1193 //Will be added for other targets if we run into bandwidth issues and when
1194 //we have profiling data to set an upper limit.
1195 if(qdutils::MDPVersion::getInstance().is8x74v2()) {
Saurabh Shah3c1a6b02013-11-22 11:10:20 -08001196 const uint32_t ONE_GIG = 1000 * 1000 * 1000;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001197 double panelRefRate =
1198 1000000000.0 / ctx->dpyAttr[mDpy].vsync_period;
Saurabh Shah3c1a6b02013-11-22 11:10:20 -08001199 if((size * panelRefRate) > ((sMaxBw - sBwClaimed) * ONE_GIG)) {
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001200 return false;
1201 }
1202 }
1203 return true;
1204}
1205
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001206int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001207 int ret = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -07001208 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -07001209
Saurabh Shahb39f8152013-08-22 10:21:44 -07001210 //reset old data
1211 mCurrentFrame.reset(numLayers);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001212 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1213 mCurrentFrame.dropCount = 0;
Prabhanjan Kandula088bd892013-07-02 23:47:13 +05301214
Saurabh Shahb39f8152013-08-22 10:21:44 -07001215 //number of app layers exceeds MAX_NUM_APP_LAYERS fall back to GPU
1216 //do not cache the information for next draw cycle.
1217 if(numLayers > MAX_NUM_APP_LAYERS) {
Prabhanjan Kandula25469a52013-07-12 16:19:31 +05301218 mCachedFrame.updateCounts(mCurrentFrame);
Arpita Banerjeed8965982013-11-08 17:27:33 -08001219 ALOGI("%s: Number of App layers exceeded the limit ",
Tatenda Chipeperekwa835337a2013-09-27 16:58:43 -07001220 __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001221 ret = -1;
Tatenda Chipeperekwa835337a2013-09-27 16:58:43 -07001222 return ret;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001223 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001224
Saurabh Shahb39f8152013-08-22 10:21:44 -07001225 //Hard conditions, if not met, cannot do MDP comp
1226 if(!isFrameDoable(ctx)) {
1227 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
1228 __FUNCTION__);
1229 reset(numLayers, list);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001230 ret = -1;
1231 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001232 }
1233
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001234 generateROI(ctx, list);
1235
Saurabh Shahb39f8152013-08-22 10:21:44 -07001236 //Check whether layers marked for MDP Composition is actually doable.
1237 if(isFullFrameDoable(ctx, list)) {
1238 mCurrentFrame.map();
1239 //Configure framebuffer first if applicable
1240 if(mCurrentFrame.fbZ >= 0) {
1241 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list,
1242 mCurrentFrame.fbZ)) {
1243 ALOGE("%s configure framebuffer failed", __func__);
1244 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -07001245 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001246 ret = -1;
1247 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001248 }
1249 }
1250 //Acquire and Program MDP pipes
1251 if(!programMDP(ctx, list)) {
1252 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -07001253 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001254 ret = -1;
1255 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001256 } else { //Success
1257 //Any change in composition types needs an FB refresh
1258 mCurrentFrame.needsRedraw = false;
Jeykumar Sankaran988d3682013-11-15 11:57:16 -08001259 if(!mCachedFrame.isSameFrame(mCurrentFrame, list) ||
Saurabh Shahb39f8152013-08-22 10:21:44 -07001260 (list->flags & HWC_GEOMETRY_CHANGED) ||
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +05301261 isSkipPresent(ctx, mDpy)) {
Saurabh Shahb39f8152013-08-22 10:21:44 -07001262 mCurrentFrame.needsRedraw = true;
1263 }
1264 }
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001265 } else if(isOnlyVideoDoable(ctx, list, false /*secure only*/) ||
1266 isOnlyVideoDoable(ctx, list, true /*secure only*/)) {
Saurabh Shahb39f8152013-08-22 10:21:44 -07001267 //All layers marked for MDP comp cannot be bypassed.
1268 //Try to compose atleast YUV layers through MDP comp and let
1269 //all the RGB layers compose in FB
1270 //Destination over
1271 mCurrentFrame.fbZ = -1;
1272 if(mCurrentFrame.fbCount)
1273 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
1274
1275 mCurrentFrame.map();
1276
1277 //Configure framebuffer first if applicable
1278 if(mCurrentFrame.fbZ >= 0) {
1279 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, mCurrentFrame.fbZ)) {
1280 ALOGE("%s configure framebuffer failed", __func__);
1281 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -07001282 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001283 ret = -1;
1284 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001285 }
1286 }
1287 if(!programYUV(ctx, list)) {
1288 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -07001289 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001290 ret = -1;
1291 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001292 }
1293 } else {
1294 reset(numLayers, list);
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -08001295 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1296 mCurrentFrame.dropCount = 0;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001297 ret = -1;
1298 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001299 }
Saurabh Shahb39f8152013-08-22 10:21:44 -07001300 //UpdateLayerFlags
1301 setMDPCompLayerFlags(ctx, list);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001302 mCachedFrame.cacheAll(list);
Saurabh Shahb39f8152013-08-22 10:21:44 -07001303 mCachedFrame.updateCounts(mCurrentFrame);
1304
Prabhanjan Kandula25469a52013-07-12 16:19:31 +05301305 // unlock it before calling dump function to avoid deadlock
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001306 if(isDebug()) {
Saurabh Shahaa236822013-04-24 18:07:26 -07001307 ALOGD("GEOMETRY change: %d", (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001308 android::String8 sDump("");
1309 dump(sDump);
1310 ALOGE("%s",sDump.string());
1311 }
1312
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001313exit:
Saurabh Shah3c1a6b02013-11-22 11:10:20 -08001314 //gbps (bytes / nanosec = gigabytes / sec)
1315 sBwClaimed += calcMDPBytesRead(ctx, list) /
1316 (double)ctx->dpyAttr[mDpy].vsync_period;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001317 return ret;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001318}
1319
Saurabh Shah88e4d272013-09-03 13:31:29 -07001320//=============MDPCompNonSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001321
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001322/*
1323 * Configures pipe(s) for MDP composition
1324 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001325int MDPCompNonSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001326 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001327 MdpPipeInfoNonSplit& mdp_info =
1328 *(static_cast<MdpPipeInfoNonSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001329 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
1330 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1331 eIsFg isFg = IS_FG_OFF;
1332 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001333
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001334 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
1335 __FUNCTION__, layer, zOrder, dest);
1336
Saurabh Shah88e4d272013-09-03 13:31:29 -07001337 return configureNonSplit(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001338 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001339}
1340
Saurabh Shah88e4d272013-09-03 13:31:29 -07001341bool MDPCompNonSplit::arePipesAvailable(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001342 hwc_display_contents_1_t* list) {
1343 overlay::Overlay& ov = *ctx->mOverlay;
1344 int numPipesNeeded = mCurrentFrame.mdpCount;
1345 int availPipes = ov.availablePipes(mDpy, Overlay::MIXER_DEFAULT);
1346
1347 //Reserve pipe for FB
1348 if(mCurrentFrame.fbCount)
1349 availPipes -= 1;
1350
1351 if(numPipesNeeded > availPipes) {
1352 ALOGD_IF(isDebug(), "%s: Insufficient pipes, dpy %d needed %d, avail %d",
1353 __FUNCTION__, mDpy, numPipesNeeded, availPipes);
1354 return false;
1355 }
1356
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001357 if(not areVGPipesAvailable(ctx, list)) {
1358 return false;
1359 }
1360
1361 return true;
1362}
1363
1364bool MDPCompNonSplit::areVGPipesAvailable(hwc_context_t *ctx,
1365 hwc_display_contents_1_t* list) {
1366 overlay::Overlay& ov = *ctx->mOverlay;
1367 int pipesNeeded = 0;
1368 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1369 if(!mCurrentFrame.isFBComposed[i]) {
1370 hwc_layer_1_t* layer = &list->hwLayers[i];
1371 hwc_rect_t dst = layer->displayFrame;
1372 private_handle_t *hnd = (private_handle_t *)layer->handle;
1373 if(isYuvBuffer(hnd)) {
1374 pipesNeeded++;
1375 }
1376 }
1377 }
1378
1379 int availableVGPipes = ov.availablePipes(mDpy, ovutils::OV_MDP_PIPE_VG);
1380 if(pipesNeeded > availableVGPipes) {
1381 ALOGD_IF(isDebug(), "%s: Insufficient VG pipes for video layers"
1382 "dpy %d needed %d, avail %d",
1383 __FUNCTION__, mDpy, pipesNeeded, availableVGPipes);
1384 return false;
1385 }
1386
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001387 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001388}
1389
Saurabh Shah88e4d272013-09-03 13:31:29 -07001390bool MDPCompNonSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001391 hwc_display_contents_1_t* list) {
1392 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001393
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001394 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001395
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001396 hwc_layer_1_t* layer = &list->hwLayers[index];
1397 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001398 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001399 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001400 info.pipeInfo = new MdpPipeInfoNonSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08001401 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001402 MdpPipeInfoNonSplit& pipe_info = *(MdpPipeInfoNonSplit*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001403 ePipeType type = MDPCOMP_OV_ANY;
1404
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001405 if(isYuvBuffer(hnd)) {
1406 type = MDPCOMP_OV_VG;
Saurabh Shah8a117932013-05-23 12:48:13 -07001407 } else if(!qhwc::needsScaling(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001408 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
1409 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001410 type = MDPCOMP_OV_DMA;
1411 }
1412
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001413 pipe_info.index = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001414 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001415 ALOGD_IF(isDebug(), "%s: Unable to get pipe type = %d",
1416 __FUNCTION__, (int) type);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001417 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001418 }
1419 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001420 return true;
1421}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001422
Saurabh Shah88e4d272013-09-03 13:31:29 -07001423bool MDPCompNonSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001424
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001425 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001426 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1427 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -08001428 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001429
1430 if(!ctx || !list) {
1431 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001432 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001433 }
1434
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301435 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1436 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1437 return true;
1438 }
1439
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001440 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001441 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001442 idleInvalidator->markForSleep();
1443
1444 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001445 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001446
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001447 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1448 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001449 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001450 if(mCurrentFrame.isFBComposed[i]) continue;
1451
Naseer Ahmed5b6708a2012-08-02 13:46:08 -07001452 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001453 private_handle_t *hnd = (private_handle_t *)layer->handle;
1454 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001455 if (!(layer->flags & HWC_COLOR_FILL)) {
1456 ALOGE("%s handle null", __FUNCTION__);
1457 return false;
1458 }
1459 // No PLAY for Color layer
1460 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1461 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001462 }
1463
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001464 int mdpIndex = mCurrentFrame.layerToMDP[i];
1465
Saurabh Shah88e4d272013-09-03 13:31:29 -07001466 MdpPipeInfoNonSplit& pipe_info =
1467 *(MdpPipeInfoNonSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001468 ovutils::eDest dest = pipe_info.index;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001469 if(dest == ovutils::OV_INVALID) {
1470 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001471 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001472 }
1473
Saurabh Shahacf10202013-02-26 10:15:15 -08001474 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1475 continue;
1476 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001477
Saurabh Shahacf10202013-02-26 10:15:15 -08001478 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001479 using pipe: %d", __FUNCTION__, layer,
1480 hnd, dest );
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001481
Saurabh Shahacf10202013-02-26 10:15:15 -08001482 int fd = hnd->fd;
1483 uint32_t offset = hnd->offset;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001484
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001485 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -08001486 if(rot) {
1487 if(!rot->queueBuffer(fd, offset))
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001488 return false;
Saurabh Shahacf10202013-02-26 10:15:15 -08001489 fd = rot->getDstMemId();
1490 offset = rot->getDstOffset();
1491 }
1492
1493 if (!ov.queueBuffer(fd, offset, dest)) {
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301494 ALOGE("%s: queueBuffer failed for display:%d ", __FUNCTION__, mDpy);
Saurabh Shahacf10202013-02-26 10:15:15 -08001495 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001496 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001497
1498 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001499 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001500 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001501}
1502
Saurabh Shah88e4d272013-09-03 13:31:29 -07001503//=============MDPCompSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001504
Saurabh Shah88e4d272013-09-03 13:31:29 -07001505int MDPCompSplit::pipesNeeded(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001506 hwc_display_contents_1_t* list,
1507 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001508 int pipesNeeded = 0;
Saurabh Shah67a38c32013-06-10 16:23:15 -07001509 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001510
1511 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001512
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001513 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1514 if(!mCurrentFrame.isFBComposed[i]) {
1515 hwc_layer_1_t* layer = &list->hwLayers[i];
1516 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001517 if(mixer == Overlay::MIXER_LEFT && dst.left < lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001518 pipesNeeded++;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001519 } else if(mixer == Overlay::MIXER_RIGHT && dst.right > lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001520 pipesNeeded++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001521 }
1522 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001523 }
1524 return pipesNeeded;
1525}
1526
Saurabh Shah88e4d272013-09-03 13:31:29 -07001527bool MDPCompSplit::arePipesAvailable(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001528 hwc_display_contents_1_t* list) {
1529 overlay::Overlay& ov = *ctx->mOverlay;
Saurabh Shah082468e2013-09-12 10:05:32 -07001530 int totalPipesNeeded = 0;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001531
1532 for(int i = 0; i < Overlay::MIXER_MAX; i++) {
1533 int numPipesNeeded = pipesNeeded(ctx, list, i);
1534 int availPipes = ov.availablePipes(mDpy, i);
1535
1536 //Reserve pipe(s)for FB
1537 if(mCurrentFrame.fbCount)
Saurabh Shah082468e2013-09-12 10:05:32 -07001538 numPipesNeeded += 1;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001539
Saurabh Shah082468e2013-09-12 10:05:32 -07001540 totalPipesNeeded += numPipesNeeded;
1541
1542 //Per mixer check.
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001543 if(numPipesNeeded > availPipes) {
1544 ALOGD_IF(isDebug(), "%s: Insufficient pipes for "
1545 "dpy %d mixer %d needed %d, avail %d",
1546 __FUNCTION__, mDpy, i, numPipesNeeded, availPipes);
1547 return false;
1548 }
1549 }
Saurabh Shah082468e2013-09-12 10:05:32 -07001550
1551 //Per display check, since unused pipes can get counted twice.
1552 int totalPipesAvailable = ov.availablePipes(mDpy);
1553 if(totalPipesNeeded > totalPipesAvailable) {
1554 ALOGD_IF(isDebug(), "%s: Insufficient pipes for "
1555 "dpy %d needed %d, avail %d",
1556 __FUNCTION__, mDpy, totalPipesNeeded, totalPipesAvailable);
1557 return false;
1558 }
1559
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001560 if(not areVGPipesAvailable(ctx, list)) {
1561 return false;
1562 }
1563
1564 return true;
1565}
1566
1567bool MDPCompSplit::areVGPipesAvailable(hwc_context_t *ctx,
1568 hwc_display_contents_1_t* list) {
1569 overlay::Overlay& ov = *ctx->mOverlay;
1570 int pipesNeeded = 0;
1571 const int lSplit = getLeftSplit(ctx, mDpy);
1572 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1573 if(!mCurrentFrame.isFBComposed[i]) {
1574 hwc_layer_1_t* layer = &list->hwLayers[i];
1575 hwc_rect_t dst = layer->displayFrame;
1576 private_handle_t *hnd = (private_handle_t *)layer->handle;
1577 if(isYuvBuffer(hnd)) {
1578 if(dst.left < lSplit) {
1579 pipesNeeded++;
1580 }
1581 if(dst.right > lSplit) {
1582 pipesNeeded++;
1583 }
1584 }
1585 }
1586 }
1587
1588 int availableVGPipes = ov.availablePipes(mDpy, ovutils::OV_MDP_PIPE_VG);
1589 if(pipesNeeded > availableVGPipes) {
1590 ALOGD_IF(isDebug(), "%s: Insufficient VG pipes for video layers"
1591 "dpy %d needed %d, avail %d",
1592 __FUNCTION__, mDpy, pipesNeeded, availableVGPipes);
1593 return false;
1594 }
1595
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001596 return true;
1597}
1598
Saurabh Shah88e4d272013-09-03 13:31:29 -07001599bool MDPCompSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
1600 MdpPipeInfoSplit& pipe_info,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001601 ePipeType type) {
1602 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001603 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001604
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001605 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001606 pipe_info.lIndex = ovutils::OV_INVALID;
1607 pipe_info.rIndex = ovutils::OV_INVALID;
1608
1609 if (dst.left < lSplit) {
1610 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_LEFT);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001611 if(pipe_info.lIndex == ovutils::OV_INVALID)
1612 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001613 }
1614
1615 if(dst.right > lSplit) {
1616 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_RIGHT);
1617 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001618 return false;
1619 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001620
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001621 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001622}
1623
Saurabh Shah88e4d272013-09-03 13:31:29 -07001624bool MDPCompSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001625 hwc_display_contents_1_t* list) {
1626 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001627
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001628 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001629
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001630 hwc_layer_1_t* layer = &list->hwLayers[index];
1631 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001632 int mdpIndex = mCurrentFrame.layerToMDP[index];
1633 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001634 info.pipeInfo = new MdpPipeInfoSplit;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001635 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001636 MdpPipeInfoSplit& pipe_info = *(MdpPipeInfoSplit*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001637 ePipeType type = MDPCOMP_OV_ANY;
1638
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001639 if(isYuvBuffer(hnd)) {
1640 type = MDPCOMP_OV_VG;
Sushil Chauhan15a2ea62013-09-04 18:28:36 -07001641 } else if(!qhwc::needsScalingWithSplit(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001642 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001643 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001644 type = MDPCOMP_OV_DMA;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001645 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001646
1647 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001648 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type = %d",
1649 __FUNCTION__, (int) type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001650 return false;
1651 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001652 }
1653 return true;
1654}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001655
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001656/*
1657 * Configures pipe(s) for MDP composition
1658 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001659int MDPCompSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001660 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001661 MdpPipeInfoSplit& mdp_info =
1662 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001663 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1664 eIsFg isFg = IS_FG_OFF;
1665 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1666 eDest lDest = mdp_info.lIndex;
1667 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001668
1669 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1670 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1671
Saurabh Shah88e4d272013-09-03 13:31:29 -07001672 return configureSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001673 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001674}
1675
Saurabh Shah88e4d272013-09-03 13:31:29 -07001676bool MDPCompSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001677
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001678 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001679 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1680 return true;
1681 }
1682
1683 if(!ctx || !list) {
1684 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001685 return false;
1686 }
1687
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301688 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1689 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1690 return true;
1691 }
1692
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001693 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001694 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001695 idleInvalidator->markForSleep();
1696
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001697 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001698 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001699
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001700 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1701 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001702 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001703 if(mCurrentFrame.isFBComposed[i]) continue;
1704
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001705 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001706 private_handle_t *hnd = (private_handle_t *)layer->handle;
1707 if(!hnd) {
1708 ALOGE("%s handle null", __FUNCTION__);
1709 return false;
1710 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001711
1712 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1713 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001714 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001715
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001716 int mdpIndex = mCurrentFrame.layerToMDP[i];
1717
Saurabh Shah88e4d272013-09-03 13:31:29 -07001718 MdpPipeInfoSplit& pipe_info =
1719 *(MdpPipeInfoSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001720 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -08001721
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001722 ovutils::eDest indexL = pipe_info.lIndex;
1723 ovutils::eDest indexR = pipe_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001724
Saurabh Shahacf10202013-02-26 10:15:15 -08001725 int fd = hnd->fd;
1726 int offset = hnd->offset;
1727
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001728 if(ctx->mAD->isModeOn()) {
1729 if(ctx->mAD->draw(ctx, fd, offset)) {
1730 fd = ctx->mAD->getDstFd(ctx);
1731 offset = ctx->mAD->getDstOffset(ctx);
1732 }
1733 }
1734
Saurabh Shahacf10202013-02-26 10:15:15 -08001735 if(rot) {
1736 rot->queueBuffer(fd, offset);
1737 fd = rot->getDstMemId();
1738 offset = rot->getDstOffset();
1739 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001740
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001741 //************* play left mixer **********
1742 if(indexL != ovutils::OV_INVALID) {
1743 ovutils::eDest destL = (ovutils::eDest)indexL;
Saurabh Shahacf10202013-02-26 10:15:15 -08001744 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001745 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
Saurabh Shahacf10202013-02-26 10:15:15 -08001746 if (!ov.queueBuffer(fd, offset, destL)) {
1747 ALOGE("%s: queueBuffer failed for left mixer", __FUNCTION__);
1748 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001749 }
1750 }
1751
1752 //************* play right mixer **********
1753 if(indexR != ovutils::OV_INVALID) {
1754 ovutils::eDest destR = (ovutils::eDest)indexR;
Saurabh Shahacf10202013-02-26 10:15:15 -08001755 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001756 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
Saurabh Shahacf10202013-02-26 10:15:15 -08001757 if (!ov.queueBuffer(fd, offset, destR)) {
1758 ALOGE("%s: queueBuffer failed for right mixer", __FUNCTION__);
1759 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001760 }
1761 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001762
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001763 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1764 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001765
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001766 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001767}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001768}; //namespace
1769