blob: db4dbe8158655b2b5ec68c4c3f83c1e04440523c [file] [log] [blame]
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001/*
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002 * Copyright (C) 2012-2013, The Linux Foundation. All rights reserved.
Naseer Ahmed7c958d42012-07-31 18:57:03 -07003 * Not a Contribution, Apache license notifications and license are retained
4 * for attribution purposes only.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
Saurabh Shah4fdde762013-04-30 18:47:33 -070019#include <math.h>
Naseer Ahmed7c958d42012-07-31 18:57:03 -070020#include "hwc_mdpcomp.h"
Naseer Ahmed54821fe2012-11-28 18:44:38 -050021#include <sys/ioctl.h>
Saurabh Shah56f610d2012-08-07 15:27:06 -070022#include "external.h"
Jeykumar Sankaran27dee262013-08-01 17:09:54 -070023#include "virtual.h"
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -080024#include "qdMetaData.h"
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -080025#include "mdp_version.h"
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -070026#include "hwc_fbupdate.h"
Saurabh Shaha9da08f2013-07-03 13:27:53 -070027#include "hwc_ad.h"
Saurabh Shahacf10202013-02-26 10:15:15 -080028#include <overlayRotator.h>
29
Saurabh Shah85234ec2013-04-12 17:09:00 -070030using namespace overlay;
Saurabh Shahbd2d0832013-04-04 14:33:08 -070031using namespace qdutils;
Saurabh Shahacf10202013-02-26 10:15:15 -080032using namespace overlay::utils;
33namespace ovutils = overlay::utils;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070034
Naseer Ahmed7c958d42012-07-31 18:57:03 -070035namespace qhwc {
36
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080037//==============MDPComp========================================================
38
Naseer Ahmed7c958d42012-07-31 18:57:03 -070039IdleInvalidator *MDPComp::idleInvalidator = NULL;
40bool MDPComp::sIdleFallBack = false;
41bool MDPComp::sDebugLogs = false;
Naseer Ahmed54821fe2012-11-28 18:44:38 -050042bool MDPComp::sEnabled = false;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -070043bool MDPComp::sEnableMixedMode = true;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -070044bool MDPComp::sEnablePartialFrameUpdate = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080045int MDPComp::sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
Saurabh Shahf5f2b132013-11-25 12:08:35 -080046double MDPComp::sMaxBw = 0.0;
Saurabh Shah3c1a6b02013-11-22 11:10:20 -080047double MDPComp::sBwClaimed = 0.0;
radhakrishnac9a67412013-09-25 17:40:42 +053048bool MDPComp::sEnable4k2kYUVSplit = false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070049
Saurabh Shah88e4d272013-09-03 13:31:29 -070050MDPComp* MDPComp::getObject(hwc_context_t *ctx, const int& dpy) {
51 if(isDisplaySplit(ctx, dpy)) {
52 return new MDPCompSplit(dpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080053 }
Saurabh Shah88e4d272013-09-03 13:31:29 -070054 return new MDPCompNonSplit(dpy);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080055}
56
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080057MDPComp::MDPComp(int dpy):mDpy(dpy){};
58
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080059void MDPComp::dump(android::String8& buf)
60{
Jeykumar Sankaran3c6bb042013-08-15 14:01:04 -070061 if(mCurrentFrame.layerCount > MAX_NUM_APP_LAYERS)
62 return;
63
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080064 dumpsys_log(buf,"HWC Map for Dpy: %s \n",
Jeykumar Sankaran27dee262013-08-01 17:09:54 -070065 (mDpy == 0) ? "\"PRIMARY\"" :
66 (mDpy == 1) ? "\"EXTERNAL\"" : "\"VIRTUAL\"");
Saurabh Shahe9bc60f2013-08-29 12:58:06 -070067 dumpsys_log(buf,"CURR_FRAME: layerCount:%2d mdpCount:%2d "
68 "fbCount:%2d \n", mCurrentFrame.layerCount,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080069 mCurrentFrame.mdpCount, mCurrentFrame.fbCount);
70 dumpsys_log(buf,"needsFBRedraw:%3s pipesUsed:%2d MaxPipesPerMixer: %d \n",
71 (mCurrentFrame.needsRedraw? "YES" : "NO"),
72 mCurrentFrame.mdpCount, sMaxPipesPerMixer);
73 dumpsys_log(buf," --------------------------------------------- \n");
74 dumpsys_log(buf," listIdx | cached? | mdpIndex | comptype | Z \n");
75 dumpsys_log(buf," --------------------------------------------- \n");
76 for(int index = 0; index < mCurrentFrame.layerCount; index++ )
77 dumpsys_log(buf," %7d | %7s | %8d | %9s | %2d \n",
78 index,
79 (mCurrentFrame.isFBComposed[index] ? "YES" : "NO"),
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -070080 mCurrentFrame.layerToMDP[index],
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080081 (mCurrentFrame.isFBComposed[index] ?
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -070082 (mCurrentFrame.drop[index] ? "DROP" :
83 (mCurrentFrame.needsRedraw ? "GLES" : "CACHE")) : "MDP"),
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080084 (mCurrentFrame.isFBComposed[index] ? mCurrentFrame.fbZ :
85 mCurrentFrame.mdpToLayer[mCurrentFrame.layerToMDP[index]].pipeInfo->zOrder));
86 dumpsys_log(buf,"\n");
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080087}
88
89bool MDPComp::init(hwc_context_t *ctx) {
90
91 if(!ctx) {
92 ALOGE("%s: Invalid hwc context!!",__FUNCTION__);
93 return false;
94 }
95
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080096 char property[PROPERTY_VALUE_MAX];
97
98 sEnabled = false;
99 if((property_get("persist.hwc.mdpcomp.enable", property, NULL) > 0) &&
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800100 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
101 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800102 sEnabled = true;
103 }
104
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700105 sEnableMixedMode = true;
106 if((property_get("debug.mdpcomp.mixedmode.disable", property, NULL) > 0) &&
107 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
108 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
109 sEnableMixedMode = false;
110 }
111
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800112 if(property_get("debug.mdpcomp.logs", property, NULL) > 0) {
113 if(atoi(property) != 0)
114 sDebugLogs = true;
115 }
116
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700117 if(property_get("persist.hwc.partialupdate.enable", property, NULL) > 0) {
118 if((atoi(property) != 0) && ctx->mMDP.panel == MIPI_CMD_PANEL &&
119 qdutils::MDPVersion::getInstance().is8x74v2())
120 sEnablePartialFrameUpdate = true;
121 }
122 ALOGE_IF(isDebug(), "%s: Partial Update applicable?: %d",__FUNCTION__,
123 sEnablePartialFrameUpdate);
124
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800125 sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
Saurabh Shah85234ec2013-04-12 17:09:00 -0700126 if(property_get("debug.mdpcomp.maxpermixer", property, "-1") > 0) {
127 int val = atoi(property);
128 if(val >= 0)
129 sMaxPipesPerMixer = min(val, MAX_PIPES_PER_MIXER);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800130 }
131
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400132 if(ctx->mMDP.panel != MIPI_CMD_PANEL) {
133 // Idle invalidation is not necessary on command mode panels
134 long idle_timeout = DEFAULT_IDLE_TIME;
135 if(property_get("debug.mdpcomp.idletime", property, NULL) > 0) {
136 if(atoi(property) != 0)
137 idle_timeout = atoi(property);
138 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800139
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400140 //create Idle Invalidator only when not disabled through property
141 if(idle_timeout != -1)
142 idleInvalidator = IdleInvalidator::getInstance();
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800143
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400144 if(idleInvalidator == NULL) {
145 ALOGE("%s: failed to instantiate idleInvalidator object",
146 __FUNCTION__);
147 } else {
148 idleInvalidator->init(timeout_handler, ctx, idle_timeout);
149 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800150 }
radhakrishnac9a67412013-09-25 17:40:42 +0530151
152 if((property_get("debug.mdpcomp.4k2kSplit", property, "0") > 0) &&
153 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
154 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
155 sEnable4k2kYUVSplit = true;
156 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700157 return true;
158}
159
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800160void MDPComp::reset(hwc_context_t *ctx) {
161 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700162 mCurrentFrame.reset(numLayers);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800163 ctx->mOverlay->clear(mDpy);
164 ctx->mLayerRotMap[mDpy]->clear();
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700165}
166
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700167void MDPComp::timeout_handler(void *udata) {
168 struct hwc_context_t* ctx = (struct hwc_context_t*)(udata);
169
170 if(!ctx) {
171 ALOGE("%s: received empty data in timer callback", __FUNCTION__);
172 return;
173 }
174
Jesse Hall3be78d92012-08-21 15:12:23 -0700175 if(!ctx->proc) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700176 ALOGE("%s: HWC proc not registered", __FUNCTION__);
177 return;
178 }
179 sIdleFallBack = true;
180 /* Trigger SF to redraw the current frame */
Jesse Hall3be78d92012-08-21 15:12:23 -0700181 ctx->proc->invalidate(ctx->proc);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700182}
183
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800184void MDPComp::setMDPCompLayerFlags(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800185 hwc_display_contents_1_t* list) {
186 LayerProp *layerProp = ctx->layerProp[mDpy];
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800187
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800188 for(int index = 0; index < ctx->listStats[mDpy].numAppLayers; index++) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800189 hwc_layer_1_t* layer = &(list->hwLayers[index]);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800190 if(!mCurrentFrame.isFBComposed[index]) {
191 layerProp[index].mFlags |= HWC_MDPCOMP;
192 layer->compositionType = HWC_OVERLAY;
193 layer->hints |= HWC_HINT_CLEAR_FB;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800194 } else {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700195 /* Drop the layer when its already present in FB OR when it lies
196 * outside frame's ROI */
197 if(!mCurrentFrame.needsRedraw || mCurrentFrame.drop[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800198 layer->compositionType = HWC_OVERLAY;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700199 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800200 }
201 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700202}
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500203
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800204void MDPComp::setRedraw(hwc_context_t *ctx,
205 hwc_display_contents_1_t* list) {
206 mCurrentFrame.needsRedraw = false;
207 if(!mCachedFrame.isSameFrame(mCurrentFrame, list) ||
208 (list->flags & HWC_GEOMETRY_CHANGED) ||
209 isSkipPresent(ctx, mDpy)) {
210 mCurrentFrame.needsRedraw = true;
211 }
212}
213
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800214MDPComp::FrameInfo::FrameInfo() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700215 reset(0);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800216}
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800217
Saurabh Shahaa236822013-04-24 18:07:26 -0700218void MDPComp::FrameInfo::reset(const int& numLayers) {
219 for(int i = 0 ; i < MAX_PIPES_PER_MIXER && numLayers; i++ ) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800220 if(mdpToLayer[i].pipeInfo) {
221 delete mdpToLayer[i].pipeInfo;
222 mdpToLayer[i].pipeInfo = NULL;
223 //We dont own the rotator
224 mdpToLayer[i].rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800225 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800226 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800227
228 memset(&mdpToLayer, 0, sizeof(mdpToLayer));
229 memset(&layerToMDP, -1, sizeof(layerToMDP));
Saurabh Shahaa236822013-04-24 18:07:26 -0700230 memset(&isFBComposed, 1, sizeof(isFBComposed));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800231
Saurabh Shahaa236822013-04-24 18:07:26 -0700232 layerCount = numLayers;
233 fbCount = numLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800234 mdpCount = 0;
Saurabh Shah2f3895f2013-05-02 10:13:31 -0700235 needsRedraw = true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800236 fbZ = 0;
237}
238
Saurabh Shahaa236822013-04-24 18:07:26 -0700239void MDPComp::FrameInfo::map() {
240 // populate layer and MDP maps
241 int mdpIdx = 0;
242 for(int idx = 0; idx < layerCount; idx++) {
243 if(!isFBComposed[idx]) {
244 mdpToLayer[mdpIdx].listIndex = idx;
245 layerToMDP[idx] = mdpIdx++;
246 }
247 }
248}
249
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800250MDPComp::LayerCache::LayerCache() {
251 reset();
252}
253
254void MDPComp::LayerCache::reset() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700255 memset(&hnd, 0, sizeof(hnd));
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530256 memset(&isFBComposed, true, sizeof(isFBComposed));
257 memset(&drop, false, sizeof(drop));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800258 layerCount = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -0700259}
260
261void MDPComp::LayerCache::cacheAll(hwc_display_contents_1_t* list) {
262 const int numAppLayers = list->numHwLayers - 1;
263 for(int i = 0; i < numAppLayers; i++) {
264 hnd[i] = list->hwLayers[i].handle;
265 }
266}
267
268void MDPComp::LayerCache::updateCounts(const FrameInfo& curFrame) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700269 layerCount = curFrame.layerCount;
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530270 memcpy(&isFBComposed, &curFrame.isFBComposed, sizeof(isFBComposed));
271 memcpy(&drop, &curFrame.drop, sizeof(drop));
272}
273
Jeykumar Sankaran988d3682013-11-15 11:57:16 -0800274bool MDPComp::LayerCache::isSameFrame(const FrameInfo& curFrame,
275 hwc_display_contents_1_t* list) {
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530276 if(layerCount != curFrame.layerCount)
277 return false;
278 for(int i = 0; i < curFrame.layerCount; i++) {
279 if((curFrame.isFBComposed[i] != isFBComposed[i]) ||
280 (curFrame.drop[i] != drop[i])) {
281 return false;
282 }
Jeykumar Sankaran988d3682013-11-15 11:57:16 -0800283 if(curFrame.isFBComposed[i] &&
284 (hnd[i] != list->hwLayers[i].handle)){
285 return false;
286 }
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530287 }
288 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800289}
290
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700291bool MDPComp::isSupportedForMDPComp(hwc_context_t *ctx, hwc_layer_1_t* layer) {
292 private_handle_t *hnd = (private_handle_t *)layer->handle;
293 if((not isYuvBuffer(hnd) and has90Transform(layer)) or
294 (not isValidDimension(ctx,layer))
295 //More conditions here, SKIP, sRGB+Blend etc
296 ) {
297 return false;
298 }
299 return true;
300}
301
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530302bool MDPComp::isValidDimension(hwc_context_t *ctx, hwc_layer_1_t *layer) {
Saurabh Shah4fdde762013-04-30 18:47:33 -0700303 const int dpy = HWC_DISPLAY_PRIMARY;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800304 private_handle_t *hnd = (private_handle_t *)layer->handle;
305
306 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -0700307 if (layer->flags & HWC_COLOR_FILL) {
308 // Color layer
309 return true;
310 }
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800311 ALOGE("%s: layer handle is NULL", __FUNCTION__);
312 return false;
313 }
314
Naseer Ahmede850a802013-09-06 13:12:52 -0400315 //XXX: Investigate doing this with pixel phase on MDSS
Naseer Ahmede77f8082013-10-10 13:42:48 -0400316 if(!isSecureBuffer(hnd) && isNonIntegralSourceCrop(layer->sourceCropf))
Naseer Ahmede850a802013-09-06 13:12:52 -0400317 return false;
318
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800319 int hw_w = ctx->dpyAttr[mDpy].xres;
320 int hw_h = ctx->dpyAttr[mDpy].yres;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800321
Saurabh Shah62e1d732013-09-17 10:44:05 -0700322 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700323 hwc_rect_t dst = layer->displayFrame;
Saurabh Shah4fdde762013-04-30 18:47:33 -0700324 int crop_w = crop.right - crop.left;
325 int crop_h = crop.bottom - crop.top;
326 int dst_w = dst.right - dst.left;
327 int dst_h = dst.bottom - dst.top;
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800328 float w_scale = ((float)crop_w / (float)dst_w);
329 float h_scale = ((float)crop_h / (float)dst_h);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700330
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800331 /* Workaround for MDP HW limitation in DSI command mode panels where
332 * FPS will not go beyond 30 if buffers on RGB pipes are of width or height
333 * less than 5 pixels
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530334 * There also is a HW limilation in MDP, minimum block size is 2x2
335 * Fallback to GPU if height is less than 2.
336 */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800337 if((crop_w < 5)||(crop_h < 5))
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800338 return false;
339
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800340 if((w_scale > 1.0f) || (h_scale > 1.0f)) {
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800341 const uint32_t downscale =
Saurabh Shah4fdde762013-04-30 18:47:33 -0700342 qdutils::MDPVersion::getInstance().getMaxMDPDownscale();
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800343 const float w_dscale = w_scale;
344 const float h_dscale = h_scale;
345
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800346 if(ctx->mMDP.version >= qdutils::MDSS_V5) {
347 /* Workaround for downscales larger than 4x.
348 * Will be removed once decimator block is enabled for MDSS
349 */
350 if(!qdutils::MDPVersion::getInstance().supportsDecimation()) {
351 if(crop_w > MAX_DISPLAY_DIM || w_dscale > downscale ||
352 h_dscale > downscale)
353 return false;
354 } else {
355 if(w_dscale > 64 || h_dscale > 64)
356 return false;
357 }
358 } else { //A-family
359 if(w_dscale > downscale || h_dscale > downscale)
Saurabh Shah4fdde762013-04-30 18:47:33 -0700360 return false;
361 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700362 }
363
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800364 if((w_scale < 1.0f) || (h_scale < 1.0f)) {
365 const uint32_t upscale =
366 qdutils::MDPVersion::getInstance().getMaxMDPUpscale();
367 const float w_uscale = 1.0f / w_scale;
368 const float h_uscale = 1.0f / h_scale;
369
370 if(w_uscale > upscale || h_uscale > upscale)
371 return false;
372 }
373
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800374 return true;
375}
376
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700377ovutils::eDest MDPComp::getMdpPipe(hwc_context_t *ctx, ePipeType type,
378 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800379 overlay::Overlay& ov = *ctx->mOverlay;
380 ovutils::eDest mdp_pipe = ovutils::OV_INVALID;
381
382 switch(type) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800383 case MDPCOMP_OV_DMA:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700384 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_DMA, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800385 if(mdp_pipe != ovutils::OV_INVALID) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800386 return mdp_pipe;
387 }
388 case MDPCOMP_OV_ANY:
389 case MDPCOMP_OV_RGB:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700390 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800391 if(mdp_pipe != ovutils::OV_INVALID) {
392 return mdp_pipe;
393 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800394
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800395 if(type == MDPCOMP_OV_RGB) {
396 //Requested only for RGB pipe
397 break;
398 }
399 case MDPCOMP_OV_VG:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700400 return ov.nextPipe(ovutils::OV_MDP_PIPE_VG, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800401 default:
402 ALOGE("%s: Invalid pipe type",__FUNCTION__);
403 return ovutils::OV_INVALID;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800404 };
405 return ovutils::OV_INVALID;
406}
407
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800408bool MDPComp::isFrameDoable(hwc_context_t *ctx) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700409 bool ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700410 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800411
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800412 if(!isEnabled()) {
413 ALOGD_IF(isDebug(),"%s: MDP Comp. not enabled.", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700414 ret = false;
Saurabh Shahd4e65852013-06-17 11:33:53 -0700415 } else if(qdutils::MDPVersion::getInstance().is8x26() &&
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -0800416 ctx->mVideoTransFlag &&
417 isSecondaryConnected(ctx)) {
Saurabh Shahd4e65852013-06-17 11:33:53 -0700418 //1 Padding round to shift pipes across mixers
419 ALOGD_IF(isDebug(),"%s: MDP Comp. video transition padding round",
420 __FUNCTION__);
421 ret = false;
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -0800422 } else if(isSecondaryConfiguring(ctx)) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800423 ALOGD_IF( isDebug(),"%s: External Display connection is pending",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800424 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700425 ret = false;
Saurabh Shahaa236822013-04-24 18:07:26 -0700426 } else if(ctx->isPaddingRound) {
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700427 ctx->isPaddingRound = false;
428 ALOGD_IF(isDebug(), "%s: padding round",__FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700429 ret = false;
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700430 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700431 return ret;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800432}
433
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800434/*
435 * 1) Identify layers that are not visible in the updating ROI and drop them
436 * from composition.
437 * 2) If we have a scaling layers which needs cropping against generated ROI.
438 * Reset ROI to full resolution.
439 */
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700440bool MDPComp::validateAndApplyROI(hwc_context_t *ctx,
441 hwc_display_contents_1_t* list, hwc_rect_t roi) {
442 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
443
444 if(!isValidRect(roi))
445 return false;
446
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800447 hwc_rect_t visibleRect = roi;
448
449 for(int i = numAppLayers - 1; i >= 0; i--){
450
451 if(!isValidRect(visibleRect)) {
452 mCurrentFrame.drop[i] = true;
453 mCurrentFrame.dropCount++;
454 }
455
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700456 const hwc_layer_1_t* layer = &list->hwLayers[i];
457
458 hwc_rect_t dstRect = layer->displayFrame;
Arun Kumar K.R91090c72013-10-28 19:40:18 -0700459 hwc_rect_t srcRect = integerizeSourceCrop(layer->sourceCropf);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700460 int transform = layer->transform;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700461
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800462 hwc_rect_t res = getIntersection(visibleRect, dstRect);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700463
464 int res_w = res.right - res.left;
465 int res_h = res.bottom - res.top;
466 int dst_w = dstRect.right - dstRect.left;
467 int dst_h = dstRect.bottom - dstRect.top;
468
469 if(!isValidRect(res)) {
470 mCurrentFrame.drop[i] = true;
471 mCurrentFrame.dropCount++;
472 }else {
473 /* Reset frame ROI when any layer which needs scaling also needs ROI
474 * cropping */
475 if((res_w != dst_w || res_h != dst_h) &&
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530476 needsScaling (layer)) {
Arpita Banerjeed8965982013-11-08 17:27:33 -0800477 ALOGI("%s: Resetting ROI due to scaling", __FUNCTION__);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700478 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
479 mCurrentFrame.dropCount = 0;
480 return false;
481 }
482 }
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800483
484 if (layer->blending == HWC_BLENDING_NONE)
485 visibleRect = deductRect(visibleRect, res);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700486 }
487 return true;
488}
489
490void MDPComp::generateROI(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
491 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
492
493 if(!sEnablePartialFrameUpdate) {
494 return;
495 }
496
497 if(mDpy || isDisplaySplit(ctx, mDpy)){
498 ALOGE_IF(isDebug(), "%s: ROI not supported for"
499 "the (1) external / virtual display's (2) dual DSI displays",
500 __FUNCTION__);
501 return;
502 }
503
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800504 if(isSkipPresent(ctx, mDpy))
505 return;
506
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700507 if(list->flags & HWC_GEOMETRY_CHANGED)
508 return;
509
510 struct hwc_rect roi = (struct hwc_rect){0, 0, 0, 0};
511 for(int index = 0; index < numAppLayers; index++ ) {
512 if ((mCachedFrame.hnd[index] != list->hwLayers[index].handle) ||
513 isYuvBuffer((private_handle_t *)list->hwLayers[index].handle)) {
514 hwc_rect_t dstRect = list->hwLayers[index].displayFrame;
Arun Kumar K.R91090c72013-10-28 19:40:18 -0700515 hwc_rect_t srcRect = integerizeSourceCrop(
516 list->hwLayers[index].sourceCropf);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700517 int transform = list->hwLayers[index].transform;
518
519 /* Intersect against display boundaries */
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700520 roi = getUnion(roi, dstRect);
521 }
522 }
523
524 if(!validateAndApplyROI(ctx, list, roi)){
525 roi = (struct hwc_rect) {0, 0,
526 (int)ctx->dpyAttr[mDpy].xres, (int)ctx->dpyAttr[mDpy].yres};
527 }
528
529 ctx->listStats[mDpy].roi.x = roi.left;
530 ctx->listStats[mDpy].roi.y = roi.top;
531 ctx->listStats[mDpy].roi.w = roi.right - roi.left;
532 ctx->listStats[mDpy].roi.h = roi.bottom - roi.top;
533
534 ALOGD_IF(isDebug(),"%s: generated ROI: [%d, %d, %d, %d]", __FUNCTION__,
535 roi.left, roi.top, roi.right, roi.bottom);
536}
537
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800538/* Checks for conditions where all the layers marked for MDP comp cannot be
539 * bypassed. On such conditions we try to bypass atleast YUV layers */
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800540bool MDPComp::tryFullFrame(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800541 hwc_display_contents_1_t* list){
542
Saurabh Shahaa236822013-04-24 18:07:26 -0700543 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800544
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -0700545 if(sIdleFallBack && !ctx->listStats[mDpy].secureUI) {
Saurabh Shah2d998a92013-05-14 17:55:58 -0700546 ALOGD_IF(isDebug(), "%s: Idle fallback dpy %d",__FUNCTION__, mDpy);
547 return false;
548 }
549
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800550 if(isSkipPresent(ctx, mDpy)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700551 ALOGD_IF(isDebug(),"%s: SKIP present: %d",
552 __FUNCTION__,
553 isSkipPresent(ctx, mDpy));
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800554 return false;
555 }
556
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800557 // check for action safe flag and downscale mode which requires scaling.
558 if(ctx->dpyAttr[mDpy].mActionSafePresent
559 || ctx->dpyAttr[mDpy].mDownScaleMode) {
560 ALOGD_IF(isDebug(), "%s: Scaling needed for this frame",__FUNCTION__);
561 return false;
562 }
563
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800564 for(int i = 0; i < numAppLayers; ++i) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800565 hwc_layer_1_t* layer = &list->hwLayers[i];
566 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800567
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700568 if(isYuvBuffer(hnd) && has90Transform(layer)) {
569 if(!canUseRotator(ctx, mDpy)) {
570 ALOGD_IF(isDebug(), "%s: Can't use rotator for dpy %d",
571 __FUNCTION__, mDpy);
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700572 return false;
573 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800574 }
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530575
576 //For 8x26 with panel width>1k, if RGB layer needs HFLIP fail mdp comp
577 // may not need it if Gfx pre-rotation can handle all flips & rotations
578 if(qdutils::MDPVersion::getInstance().is8x26() &&
579 (ctx->dpyAttr[mDpy].xres > 1024) &&
580 (layer->transform & HWC_TRANSFORM_FLIP_H) &&
581 (!isYuvBuffer(hnd)))
582 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800583 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700584
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700585 if(ctx->mAD->isDoable()) {
586 return false;
587 }
588
Saurabh Shahaa236822013-04-24 18:07:26 -0700589 //If all above hard conditions are met we can do full or partial MDP comp.
590 bool ret = false;
591 if(fullMDPComp(ctx, list)) {
592 ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700593 } else if(partialMDPComp(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700594 ret = true;
595 }
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530596
Saurabh Shahaa236822013-04-24 18:07:26 -0700597 return ret;
598}
599
600bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700601 //Will benefit presentation / secondary-only layer.
602 if((mDpy > HWC_DISPLAY_PRIMARY) &&
603 (list->numHwLayers - 1) > MAX_SEC_LAYERS) {
604 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
605 return false;
606 }
607
608 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
609 for(int i = 0; i < numAppLayers; i++) {
610 hwc_layer_1_t* layer = &list->hwLayers[i];
611 if(not isSupportedForMDPComp(ctx, layer)) {
612 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",__FUNCTION__);
613 return false;
614 }
Yang Xu9c1eb2b2013-11-26 01:28:13 +0800615
616 //For 8x26, if there is only one layer which needs scale for secondary
617 //while no scale for primary display, DMA pipe is occupied by primary.
618 //If need to fall back to GLES composition, virtual display lacks DMA
619 //pipe and error is reported.
620 if(qdutils::MDPVersion::getInstance().is8x26() &&
621 mDpy >= HWC_DISPLAY_EXTERNAL &&
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530622 qhwc::needsScaling(layer))
Yang Xu9c1eb2b2013-11-26 01:28:13 +0800623 return false;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700624 }
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800625
Saurabh Shahaa236822013-04-24 18:07:26 -0700626 mCurrentFrame.fbCount = 0;
627 mCurrentFrame.fbZ = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700628 memcpy(&mCurrentFrame.isFBComposed, &mCurrentFrame.drop,
629 sizeof(mCurrentFrame.isFBComposed));
630 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount -
631 mCurrentFrame.dropCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700632
radhakrishnac9a67412013-09-25 17:40:42 +0530633 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800634 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530635 }
636
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800637 if(!postHeuristicsHandling(ctx, list)) {
638 ALOGD_IF(isDebug(), "post heuristic handling failed");
639 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700640 return false;
641 }
642
Saurabh Shahaa236822013-04-24 18:07:26 -0700643 return true;
644}
645
646bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
647{
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700648 if(!sEnableMixedMode) {
649 //Mixed mode is disabled. No need to even try caching.
650 return false;
651 }
652
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700653 bool ret = false;
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800654 if(list->flags & HWC_GEOMETRY_CHANGED) { //Try load based first
655 ret = loadBasedCompPreferGPU(ctx, list) or
656 loadBasedCompPreferMDP(ctx, list) or
657 cacheBasedComp(ctx, list);
658 } else {
659 ret = cacheBasedComp(ctx, list) or
660 loadBasedCompPreferGPU(ctx, list) or
Saurabh Shahb772ae32013-11-18 15:40:02 -0800661 loadBasedCompPreferMDP(ctx, list);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700662 }
663
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700664 return ret;
665}
666
667bool MDPComp::cacheBasedComp(hwc_context_t *ctx,
668 hwc_display_contents_1_t* list) {
669 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700670 mCurrentFrame.reset(numAppLayers);
671 updateLayerCache(ctx, list);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700672
673 //If an MDP marked layer is unsupported cannot do partial MDP Comp
674 for(int i = 0; i < numAppLayers; i++) {
675 if(!mCurrentFrame.isFBComposed[i]) {
676 hwc_layer_1_t* layer = &list->hwLayers[i];
677 if(not isSupportedForMDPComp(ctx, layer)) {
678 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",
679 __FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800680 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700681 return false;
682 }
683 }
684 }
685
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700686 updateYUV(ctx, list, false /*secure only*/);
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530687 bool ret = markLayersForCaching(ctx, list); //sets up fbZ also
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700688 if(!ret) {
689 ALOGD_IF(isDebug(),"%s: batching failed, dpy %d",__FUNCTION__, mDpy);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800690 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700691 return false;
692 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700693
694 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700695
radhakrishnac9a67412013-09-25 17:40:42 +0530696 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800697 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530698 }
699
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700700 //Will benefit cases where a video has non-updating background.
701 if((mDpy > HWC_DISPLAY_PRIMARY) and
702 (mdpCount > MAX_SEC_LAYERS)) {
703 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800704 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700705 return false;
706 }
707
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800708 if(!postHeuristicsHandling(ctx, list)) {
709 ALOGD_IF(isDebug(), "post heuristic handling failed");
710 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700711 return false;
712 }
713
Saurabh Shahaa236822013-04-24 18:07:26 -0700714 return true;
715}
716
Saurabh Shahb772ae32013-11-18 15:40:02 -0800717bool MDPComp::loadBasedCompPreferGPU(hwc_context_t *ctx,
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700718 hwc_display_contents_1_t* list) {
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800719 if(not isLoadBasedCompDoable(ctx, list)) {
720 return false;
721 }
722
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700723 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
724 mCurrentFrame.reset(numAppLayers);
725
Saurabh Shahb772ae32013-11-18 15:40:02 -0800726 int stagesForMDP = min(sMaxPipesPerMixer, ctx->mOverlay->availablePipes(
727 mDpy, Overlay::MIXER_DEFAULT));
728 //If MDP has X possible stages, it can take X layers.
729 const int batchSize = numAppLayers - (stagesForMDP - 1); //1 for FB
730
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700731 if(batchSize <= 0) {
732 ALOGD_IF(isDebug(), "%s: Not attempting", __FUNCTION__);
733 return false;
734 }
735
736 int minBatchStart = -1;
737 size_t minBatchPixelCount = SIZE_MAX;
738
739 for(int i = 0; i <= numAppLayers - batchSize; i++) {
740 uint32_t batchPixelCount = 0;
741 for(int j = i; j < i + batchSize; j++) {
742 hwc_layer_1_t* layer = &list->hwLayers[j];
Arun Kumar K.R91090c72013-10-28 19:40:18 -0700743 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700744 batchPixelCount += (crop.right - crop.left) *
745 (crop.bottom - crop.top);
746 }
747
748 if(batchPixelCount < minBatchPixelCount) {
749 minBatchPixelCount = batchPixelCount;
750 minBatchStart = i;
751 }
752 }
753
754 if(minBatchStart < 0) {
755 ALOGD_IF(isDebug(), "%s: No batch found batchSize %d numAppLayers %d",
756 __FUNCTION__, batchSize, numAppLayers);
757 return false;
758 }
759
760 for(int i = 0; i < numAppLayers; i++) {
761 if(i < minBatchStart || i >= minBatchStart + batchSize) {
762 hwc_layer_1_t* layer = &list->hwLayers[i];
763 if(not isSupportedForMDPComp(ctx, layer)) {
764 ALOGD_IF(isDebug(), "%s: MDP unsupported layer found at %d",
765 __FUNCTION__, i);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800766 reset(ctx);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700767 return false;
768 }
769 mCurrentFrame.isFBComposed[i] = false;
770 }
771 }
772
773 mCurrentFrame.fbZ = minBatchStart;
774 mCurrentFrame.fbCount = batchSize;
775 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - batchSize;
776
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800777 ALOGD_IF(isDebug(), "%s: fbZ %d batchSize %d",
778 __FUNCTION__, mCurrentFrame.fbZ, batchSize);
779
radhakrishnac9a67412013-09-25 17:40:42 +0530780 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800781 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530782 }
783
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800784 if(!postHeuristicsHandling(ctx, list)) {
785 ALOGD_IF(isDebug(), "post heuristic handling failed");
786 reset(ctx);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700787 return false;
788 }
789
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700790 return true;
791}
792
Saurabh Shahb772ae32013-11-18 15:40:02 -0800793bool MDPComp::loadBasedCompPreferMDP(hwc_context_t *ctx,
794 hwc_display_contents_1_t* list) {
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800795 if(not isLoadBasedCompDoable(ctx, list)) {
796 return false;
797 }
798
Saurabh Shahb772ae32013-11-18 15:40:02 -0800799 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800800 mCurrentFrame.reset(numAppLayers);
801
Saurabh Shahb772ae32013-11-18 15:40:02 -0800802 //Full screen is from ib perspective, not actual full screen
803 const int bpp = 4;
804 double panelRefRate =
805 1000000000.0 / ctx->dpyAttr[mDpy].vsync_period;
806
807 double bwLeft = sMaxBw - sBwClaimed;
808
809 const int fullScreenLayers = bwLeft * 1000000000 / (ctx->dpyAttr[mDpy].xres
810 * ctx->dpyAttr[mDpy].yres * bpp * panelRefRate);
811
812 const int fbBatchSize = numAppLayers - (fullScreenLayers - 1);
813 //If batch size is not at least 2, we aren't really preferring MDP, since
814 //only 1 layer going to GPU could actually translate into an entire FB
815 //needed to be fetched by MDP, thus needing more b/w rather than less.
816 if(fbBatchSize < 2 || fbBatchSize > numAppLayers) {
817 ALOGD_IF(isDebug(), "%s: Not attempting", __FUNCTION__);
818 return false;
819 }
820
821 //Top-most layers constitute FB batch
822 const int fbBatchStart = numAppLayers - fbBatchSize;
823
824 //Bottom-most layers constitute MDP batch
825 for(int i = 0; i < fbBatchStart; i++) {
826 hwc_layer_1_t* layer = &list->hwLayers[i];
827 if(not isSupportedForMDPComp(ctx, layer)) {
828 ALOGD_IF(isDebug(), "%s: MDP unsupported layer found at %d",
829 __FUNCTION__, i);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800830 reset(ctx);
Saurabh Shahb772ae32013-11-18 15:40:02 -0800831 return false;
832 }
833 mCurrentFrame.isFBComposed[i] = false;
834 }
835
836 mCurrentFrame.fbZ = fbBatchStart;
837 mCurrentFrame.fbCount = fbBatchSize;
838 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - fbBatchSize;
839
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800840 ALOGD_IF(isDebug(), "%s: FB Z %d, num app layers %d, MDP Batch Size %d",
841 __FUNCTION__, mCurrentFrame.fbZ, numAppLayers,
842 numAppLayers - fbBatchSize);
843
radhakrishnac9a67412013-09-25 17:40:42 +0530844 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800845 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530846 }
847
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800848 if(!postHeuristicsHandling(ctx, list)) {
849 ALOGD_IF(isDebug(), "post heuristic handling failed");
850 reset(ctx);
Saurabh Shahb772ae32013-11-18 15:40:02 -0800851 return false;
852 }
853
Saurabh Shahb772ae32013-11-18 15:40:02 -0800854 return true;
855}
856
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700857bool MDPComp::isLoadBasedCompDoable(hwc_context_t *ctx,
858 hwc_display_contents_1_t* list) {
Prabhanjan Kandula3dbbd882013-12-11 14:43:46 +0530859 if(mDpy or isSecurePresent(ctx, mDpy) or
860 isYuvPresent(ctx, mDpy)) {
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700861 return false;
862 }
863 return true;
864}
865
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800866bool MDPComp::tryVideoOnly(hwc_context_t *ctx,
867 hwc_display_contents_1_t* list) {
868 const bool secureOnly = true;
869 return videoOnlyComp(ctx, list, not secureOnly) or
870 videoOnlyComp(ctx, list, secureOnly);
871}
872
873bool MDPComp::videoOnlyComp(hwc_context_t *ctx,
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700874 hwc_display_contents_1_t* list, bool secureOnly) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700875 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700876
Saurabh Shahaa236822013-04-24 18:07:26 -0700877 mCurrentFrame.reset(numAppLayers);
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700878 updateYUV(ctx, list, secureOnly);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700879 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700880
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800881 if(!isYuvPresent(ctx, mDpy) or (mdpCount == 0)) {
882 reset(ctx);
Saurabh Shahaa236822013-04-24 18:07:26 -0700883 return false;
884 }
885
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -0800886 /* Bail out if we are processing only secured video layers
887 * and we dont have any */
888 if(!isSecurePresent(ctx, mDpy) && secureOnly){
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800889 reset(ctx);
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -0800890 return false;
891 }
892
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800893 if(mCurrentFrame.fbCount)
894 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
Saurabh Shah4fdde762013-04-30 18:47:33 -0700895
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800896 if(sEnable4k2kYUVSplit){
897 adjustForSourceSplit(ctx, list);
898 }
899
900 if(!postHeuristicsHandling(ctx, list)) {
901 ALOGD_IF(isDebug(), "post heuristic handling failed");
902 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700903 return false;
904 }
905
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800906 return true;
907}
908
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800909/* Checks for conditions where YUV layers cannot be bypassed */
910bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -0700911 if(isSkipLayer(layer)) {
Saurabh Shahe2474082013-05-15 16:32:13 -0700912 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800913 return false;
914 }
915
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700916 if(layer->transform & HWC_TRANSFORM_ROT_90 && !canUseRotator(ctx,mDpy)) {
917 ALOGD_IF(isDebug(), "%s: no free DMA pipe",__FUNCTION__);
918 return false;
919 }
920
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800921 if(isSecuring(ctx, layer)) {
922 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
923 return false;
924 }
925
Saurabh Shah4fdde762013-04-30 18:47:33 -0700926 if(!isValidDimension(ctx, layer)) {
927 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
928 __FUNCTION__);
929 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800930 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700931
Naseer Ahmeddc61a972013-07-10 17:50:54 -0400932 if(layer->planeAlpha < 0xFF) {
933 ALOGD_IF(isDebug(), "%s: Cannot handle YUV layer with plane alpha\
934 in video only mode",
935 __FUNCTION__);
936 return false;
937 }
938
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800939 return true;
940}
941
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530942/* starts at fromIndex and check for each layer to find
943 * if it it has overlapping with any Updating layer above it in zorder
944 * till the end of the batch. returns true if it finds any intersection */
945bool MDPComp::canPushBatchToTop(const hwc_display_contents_1_t* list,
946 int fromIndex, int toIndex) {
947 for(int i = fromIndex; i < toIndex; i++) {
948 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
949 if(intersectingUpdatingLayers(list, i+1, toIndex, i)) {
950 return false;
951 }
952 }
953 }
954 return true;
955}
956
957/* Checks if given layer at targetLayerIndex has any
958 * intersection with all the updating layers in beween
959 * fromIndex and toIndex. Returns true if it finds intersectiion */
960bool MDPComp::intersectingUpdatingLayers(const hwc_display_contents_1_t* list,
961 int fromIndex, int toIndex, int targetLayerIndex) {
962 for(int i = fromIndex; i <= toIndex; i++) {
963 if(!mCurrentFrame.isFBComposed[i]) {
964 if(areLayersIntersecting(&list->hwLayers[i],
965 &list->hwLayers[targetLayerIndex])) {
966 return true;
967 }
968 }
969 }
970 return false;
971}
972
973int MDPComp::getBatch(hwc_display_contents_1_t* list,
974 int& maxBatchStart, int& maxBatchEnd,
975 int& maxBatchCount) {
976 int i = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530977 int fbZOrder =-1;
978 while (i < mCurrentFrame.layerCount) {
979 int batchCount = 0;
980 int batchStart = i;
981 int batchEnd = i;
982 int fbZ = batchStart;
983 int firstZReverseIndex = -1;
Prabhanjan Kandula0ed2cc92013-12-06 12:39:04 +0530984 int updatingLayersAbove = 0;//Updating layer count in middle of batch
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530985 while(i < mCurrentFrame.layerCount) {
986 if(!mCurrentFrame.isFBComposed[i]) {
987 if(!batchCount) {
988 i++;
989 break;
990 }
991 updatingLayersAbove++;
992 i++;
993 continue;
994 } else {
995 if(mCurrentFrame.drop[i]) {
996 i++;
997 continue;
998 } else if(updatingLayersAbove <= 0) {
999 batchCount++;
1000 batchEnd = i;
1001 i++;
1002 continue;
1003 } else { //Layer is FBComposed, not a drop & updatingLayer > 0
1004
1005 // We have a valid updating layer already. If layer-i not
1006 // have overlapping with all updating layers in between
1007 // batch-start and i, then we can add layer i to batch.
1008 if(!intersectingUpdatingLayers(list, batchStart, i-1, i)) {
1009 batchCount++;
1010 batchEnd = i;
1011 i++;
1012 continue;
1013 } else if(canPushBatchToTop(list, batchStart, i)) {
1014 //If All the non-updating layers with in this batch
1015 //does not have intersection with the updating layers
1016 //above in z-order, then we can safely move the batch to
1017 //higher z-order. Increment fbZ as it is moving up.
1018 if( firstZReverseIndex < 0) {
1019 firstZReverseIndex = i;
1020 }
1021 batchCount++;
1022 batchEnd = i;
1023 fbZ += updatingLayersAbove;
1024 i++;
1025 updatingLayersAbove = 0;
1026 continue;
1027 } else {
1028 //both failed.start the loop again from here.
1029 if(firstZReverseIndex >= 0) {
1030 i = firstZReverseIndex;
1031 }
1032 break;
1033 }
1034 }
1035 }
1036 }
1037 if(batchCount > maxBatchCount) {
1038 maxBatchCount = batchCount;
1039 maxBatchStart = batchStart;
1040 maxBatchEnd = batchEnd;
1041 fbZOrder = fbZ;
1042 }
1043 }
1044 return fbZOrder;
1045}
1046
1047bool MDPComp::markLayersForCaching(hwc_context_t* ctx,
1048 hwc_display_contents_1_t* list) {
1049 /* Idea is to keep as many non-updating(cached) layers in FB and
1050 * send rest of them through MDP. This is done in 2 steps.
1051 * 1. Find the maximum contiguous batch of non-updating layers.
1052 * 2. See if we can improve this batch size for caching by adding
1053 * opaque layers around the batch, if they don't have
1054 * any overlapping with the updating layers in between.
1055 * NEVER mark an updating layer for caching.
1056 * But cached ones can be marked for MDP */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001057
1058 int maxBatchStart = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001059 int maxBatchEnd = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001060 int maxBatchCount = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301061 int fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001062
1063 /* All or Nothing is cached. No batching needed */
Saurabh Shahaa236822013-04-24 18:07:26 -07001064 if(!mCurrentFrame.fbCount) {
1065 mCurrentFrame.fbZ = -1;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001066 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -07001067 }
1068 if(!mCurrentFrame.mdpCount) {
1069 mCurrentFrame.fbZ = 0;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001070 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -07001071 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001072
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301073 fbZ = getBatch(list, maxBatchStart, maxBatchEnd, maxBatchCount);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001074
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301075 /* reset rest of the layers lying inside ROI for MDP comp */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001076 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001077 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001078 if((i < maxBatchStart || i > maxBatchEnd) &&
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301079 mCurrentFrame.isFBComposed[i]){
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001080 if(!mCurrentFrame.drop[i]){
1081 //If an unsupported layer is being attempted to
1082 //be pulled out we should fail
1083 if(not isSupportedForMDPComp(ctx, layer)) {
1084 return false;
1085 }
1086 mCurrentFrame.isFBComposed[i] = false;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001087 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001088 }
1089 }
1090
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301091 // update the frame data
1092 mCurrentFrame.fbZ = fbZ;
1093 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001094 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001095 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001096
1097 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301098 mCurrentFrame.fbCount);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001099
1100 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001101}
Saurabh Shah85234ec2013-04-12 17:09:00 -07001102
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001103void MDPComp::updateLayerCache(hwc_context_t* ctx,
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001104 hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001105 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001106 int fbCount = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001107
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001108 for(int i = 0; i < numAppLayers; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001109 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001110 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001111 if(!mCurrentFrame.drop[i])
1112 fbCount++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001113 mCurrentFrame.isFBComposed[i] = true;
1114 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -07001115 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001116 }
1117 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001118
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001119 mCurrentFrame.fbCount = fbCount;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001120 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount
1121 - mCurrentFrame.dropCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001122
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001123 ALOGD_IF(isDebug(),"%s: MDP count: %d FB count %d drop count: %d"
1124 ,__FUNCTION__, mCurrentFrame.mdpCount, mCurrentFrame.fbCount,
1125 mCurrentFrame.dropCount);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001126}
1127
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001128void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list,
1129 bool secureOnly) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001130 int nYuvCount = ctx->listStats[mDpy].yuvCount;
1131 for(int index = 0;index < nYuvCount; index++){
1132 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
1133 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
1134
1135 if(!isYUVDoable(ctx, layer)) {
1136 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
1137 mCurrentFrame.isFBComposed[nYuvIndex] = true;
1138 mCurrentFrame.fbCount++;
1139 }
1140 } else {
1141 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001142 private_handle_t *hnd = (private_handle_t *)layer->handle;
1143 if(!secureOnly || isSecureBuffer(hnd)) {
1144 mCurrentFrame.isFBComposed[nYuvIndex] = false;
1145 mCurrentFrame.fbCount--;
1146 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001147 }
1148 }
1149 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001150
1151 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001152 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
1153 ALOGD_IF(isDebug(),"%s: fb count: %d",__FUNCTION__,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001154 mCurrentFrame.fbCount);
1155}
1156
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001157bool MDPComp::postHeuristicsHandling(hwc_context_t *ctx,
1158 hwc_display_contents_1_t* list) {
1159
1160 //Capability checks
1161 if(!resourceCheck(ctx, list)) {
1162 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
1163 return false;
1164 }
1165
1166 //Limitations checks
1167 if(!hwLimitationsCheck(ctx, list)) {
1168 ALOGD_IF(isDebug(), "%s: HW limitations",__FUNCTION__);
1169 return false;
1170 }
1171
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001172 //Configure framebuffer first if applicable
1173 if(mCurrentFrame.fbZ >= 0) {
1174 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, mCurrentFrame.fbZ)) {
1175 ALOGD_IF(isDebug(), "%s configure framebuffer failed",
1176 __FUNCTION__);
1177 return false;
1178 }
1179 }
1180
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001181 mCurrentFrame.map();
1182
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001183 if(!allocLayerPipes(ctx, list)) {
1184 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -07001185 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001186 }
1187
1188 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001189 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001190 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001191 int mdpIndex = mCurrentFrame.layerToMDP[index];
1192 hwc_layer_1_t* layer = &list->hwLayers[index];
1193
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301194 //Leave fbZ for framebuffer. CACHE/GLES layers go here.
1195 if(mdpNextZOrder == mCurrentFrame.fbZ) {
1196 mdpNextZOrder++;
1197 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001198 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1199 cur_pipe->zOrder = mdpNextZOrder++;
1200
radhakrishnac9a67412013-09-25 17:40:42 +05301201 private_handle_t *hnd = (private_handle_t *)layer->handle;
1202 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1203 if(configure4k2kYuv(ctx, layer,
1204 mCurrentFrame.mdpToLayer[mdpIndex])
1205 != 0 ){
1206 ALOGD_IF(isDebug(), "%s: Failed to configure split pipes \
1207 for layer %d",__FUNCTION__, index);
1208 return false;
1209 }
1210 else{
1211 mdpNextZOrder++;
1212 }
1213 continue;
1214 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001215 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
1216 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
radhakrishnac9a67412013-09-25 17:40:42 +05301217 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -07001218 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001219 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001220 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001221 }
1222
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001223 setRedraw(ctx, list);
Saurabh Shahaa236822013-04-24 18:07:26 -07001224 return true;
1225}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001226
Saurabh Shah173f4242013-11-20 09:50:12 -08001227bool MDPComp::resourceCheck(hwc_context_t *ctx,
1228 hwc_display_contents_1_t *list) {
1229 const bool fbUsed = mCurrentFrame.fbCount;
1230 if(mCurrentFrame.mdpCount > sMaxPipesPerMixer - fbUsed) {
1231 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
1232 return false;
1233 }
1234
1235 if(!arePipesAvailable(ctx, list)) {
1236 return false;
1237 }
1238
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001239 double size = calcMDPBytesRead(ctx, list);
Saurabh Shah173f4242013-11-20 09:50:12 -08001240 if(!bandwidthCheck(ctx, size)) {
1241 ALOGD_IF(isDebug(), "%s: Exceeds bandwidth",__FUNCTION__);
1242 return false;
1243 }
1244
1245 return true;
1246}
1247
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001248double MDPComp::calcMDPBytesRead(hwc_context_t *ctx,
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001249 hwc_display_contents_1_t* list) {
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001250 double size = 0;
1251 const double GIG = 1000000000.0;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001252
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001253 //Skip for targets where no device tree value for bw is supplied
1254 if(sMaxBw <= 0.0) {
1255 return 0.0;
1256 }
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001257
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001258 for (uint32_t i = 0; i < list->numHwLayers - 1; i++) {
1259 if(!mCurrentFrame.isFBComposed[i]) {
1260 hwc_layer_1_t* layer = &list->hwLayers[i];
1261 private_handle_t *hnd = (private_handle_t *)layer->handle;
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001262 if (hnd) {
Saurabh Shah62e1d732013-09-17 10:44:05 -07001263 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah90789162013-09-16 10:29:20 -07001264 hwc_rect_t dst = layer->displayFrame;
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001265 float bpp = ((float)hnd->size) / (hnd->width * hnd->height);
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001266 size += (bpp * (crop.right - crop.left) *
1267 (crop.bottom - crop.top) *
1268 ctx->dpyAttr[mDpy].yres / (dst.bottom - dst.top)) /
1269 GIG;
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001270 }
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001271 }
1272 }
1273
1274 if(mCurrentFrame.fbCount) {
1275 hwc_layer_1_t* layer = &list->hwLayers[list->numHwLayers - 1];
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001276 int tempw, temph;
1277 size += (getBufferSizeAndDimensions(
1278 layer->displayFrame.right - layer->displayFrame.left,
1279 layer->displayFrame.bottom - layer->displayFrame.top,
1280 HAL_PIXEL_FORMAT_RGBA_8888,
1281 tempw, temph)) / GIG;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001282 }
1283
1284 return size;
1285}
1286
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001287bool MDPComp::bandwidthCheck(hwc_context_t *ctx, const double& size) {
1288 //Skip for targets where no device tree value for bw is supplied
1289 if(sMaxBw <= 0.0) {
1290 return true;
1291 }
1292
1293 double panelRefRate =
1294 1000000000.0 / ctx->dpyAttr[mDpy].vsync_period;
1295 if((size * panelRefRate) > (sMaxBw - sBwClaimed)) {
1296 return false;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001297 }
1298 return true;
1299}
1300
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301301bool MDPComp::hwLimitationsCheck(hwc_context_t* ctx,
1302 hwc_display_contents_1_t* list) {
1303
1304 //A-family hw limitation:
1305 //If a layer need alpha scaling, MDP can not support.
1306 if(ctx->mMDP.version < qdutils::MDSS_V5) {
1307 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1308 if(!mCurrentFrame.isFBComposed[i] &&
1309 isAlphaScaled( &list->hwLayers[i])) {
1310 ALOGD_IF(isDebug(), "%s:frame needs alphaScaling",__FUNCTION__);
1311 return false;
1312 }
1313 }
1314 }
1315
1316 // On 8x26 & 8974 hw, we have a limitation of downscaling+blending.
1317 //If multiple layers requires downscaling and also they are overlapping
1318 //fall back to GPU since MDSS can not handle it.
1319 if(qdutils::MDPVersion::getInstance().is8x74v2() ||
1320 qdutils::MDPVersion::getInstance().is8x26()) {
1321 for(int i = 0; i < mCurrentFrame.layerCount-1; ++i) {
1322 hwc_layer_1_t* botLayer = &list->hwLayers[i];
1323 if(!mCurrentFrame.isFBComposed[i] &&
1324 isDownscaleRequired(botLayer)) {
1325 //if layer-i is marked for MDP and needs downscaling
1326 //check if any MDP layer on top of i & overlaps with layer-i
1327 for(int j = i+1; j < mCurrentFrame.layerCount; ++j) {
1328 hwc_layer_1_t* topLayer = &list->hwLayers[j];
1329 if(!mCurrentFrame.isFBComposed[j] &&
1330 isDownscaleRequired(topLayer)) {
1331 hwc_rect_t r = getIntersection(botLayer->displayFrame,
1332 topLayer->displayFrame);
1333 if(isValidRect(r))
1334 return false;
1335 }
1336 }
1337 }
1338 }
1339 }
1340 return true;
1341}
1342
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001343int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001344 int ret = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -07001345 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001346 MDPVersion& mdpVersion = qdutils::MDPVersion::getInstance();
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -07001347
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001348 //number of app layers exceeds MAX_NUM_APP_LAYERS fall back to GPU
1349 //do not cache the information for next draw cycle.
1350 if(numLayers > MAX_NUM_APP_LAYERS) {
1351 ALOGI("%s: Number of App layers exceeded the limit ",
1352 __FUNCTION__);
1353 mCachedFrame.reset();
1354 return -1;
1355 }
1356
Saurabh Shahb39f8152013-08-22 10:21:44 -07001357 //reset old data
1358 mCurrentFrame.reset(numLayers);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001359 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1360 mCurrentFrame.dropCount = 0;
Prabhanjan Kandula088bd892013-07-02 23:47:13 +05301361
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -07001362 // Detect the start of animation and fall back to GPU only once to cache
1363 // all the layers in FB and display FB content untill animation completes.
1364 if(ctx->listStats[mDpy].isDisplayAnimating) {
1365 mCurrentFrame.needsRedraw = false;
1366 if(ctx->mAnimationState[mDpy] == ANIMATION_STOPPED) {
1367 mCurrentFrame.needsRedraw = true;
1368 ctx->mAnimationState[mDpy] = ANIMATION_STARTED;
1369 }
1370 setMDPCompLayerFlags(ctx, list);
1371 mCachedFrame.updateCounts(mCurrentFrame);
1372 ret = -1;
1373 return ret;
1374 } else {
1375 ctx->mAnimationState[mDpy] = ANIMATION_STOPPED;
1376 }
1377
Saurabh Shahb39f8152013-08-22 10:21:44 -07001378 //Hard conditions, if not met, cannot do MDP comp
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001379 if(isFrameDoable(ctx)) {
1380 generateROI(ctx, list);
Saurabh Shahb39f8152013-08-22 10:21:44 -07001381
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001382 //Convert from kbps to gbps
1383 sMaxBw = mdpVersion.getHighBw() / 1000000.0;
1384 if (ctx->mExtDisplay->isConnected() ||
1385 ctx->mMDP.panel != MIPI_CMD_PANEL) {
1386 sMaxBw = mdpVersion.getLowBw() / 1000000.0;
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001387 }
1388
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001389 if(tryFullFrame(ctx, list) || tryVideoOnly(ctx, list)) {
1390 setMDPCompLayerFlags(ctx, list);
1391 } else {
1392 reset(ctx);
1393 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1394 mCurrentFrame.dropCount = 0;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001395 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001396 }
1397 } else {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001398 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
1399 __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001400 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001401 }
Saurabh Shahb39f8152013-08-22 10:21:44 -07001402
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001403 if(isDebug()) {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001404 ALOGD("GEOMETRY change: %d",
1405 (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001406 android::String8 sDump("");
1407 dump(sDump);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001408 ALOGD("%s",sDump.string());
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001409 }
1410
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001411 mCachedFrame.cacheAll(list);
1412 mCachedFrame.updateCounts(mCurrentFrame);
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001413 double panelRefRate =
1414 1000000000.0 / ctx->dpyAttr[mDpy].vsync_period;
1415 sBwClaimed += calcMDPBytesRead(ctx, list) * panelRefRate;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001416 return ret;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001417}
1418
radhakrishnac9a67412013-09-25 17:40:42 +05301419bool MDPComp::allocSplitVGPipesfor4k2k(hwc_context_t *ctx,
1420 hwc_display_contents_1_t* list, int index) {
1421
1422 bool bRet = true;
1423 hwc_layer_1_t* layer = &list->hwLayers[index];
1424 private_handle_t *hnd = (private_handle_t *)layer->handle;
1425 int mdpIndex = mCurrentFrame.layerToMDP[index];
1426 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
1427 info.pipeInfo = new MdpYUVPipeInfo;
1428 info.rot = NULL;
1429 MdpYUVPipeInfo& pipe_info = *(MdpYUVPipeInfo*)info.pipeInfo;
1430 ePipeType type = MDPCOMP_OV_VG;
1431
1432 pipe_info.lIndex = ovutils::OV_INVALID;
1433 pipe_info.rIndex = ovutils::OV_INVALID;
1434
1435 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
1436 if(pipe_info.lIndex == ovutils::OV_INVALID){
1437 bRet = false;
1438 ALOGD_IF(isDebug(),"%s: allocating first VG pipe failed",
1439 __FUNCTION__);
1440 }
1441 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
1442 if(pipe_info.rIndex == ovutils::OV_INVALID){
1443 bRet = false;
1444 ALOGD_IF(isDebug(),"%s: allocating second VG pipe failed",
1445 __FUNCTION__);
1446 }
1447 return bRet;
1448}
Saurabh Shah88e4d272013-09-03 13:31:29 -07001449//=============MDPCompNonSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001450
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001451void MDPCompNonSplit::adjustForSourceSplit(hwc_context_t *ctx,
radhakrishnac9a67412013-09-25 17:40:42 +05301452 hwc_display_contents_1_t* list){
1453 //As we split 4kx2k yuv layer and program to 2 VG pipes
1454 //(if available) increase mdpcount accordingly
1455 mCurrentFrame.mdpCount += ctx->listStats[mDpy].yuv4k2kCount;
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001456
1457 //If 4k2k Yuv layer split is possible, and if
1458 //fbz is above 4k2k layer, increment fb zorder by 1
1459 //as we split 4k2k layer and increment zorder for right half
1460 //of the layer
1461 if(mCurrentFrame.fbZ >= 0) {
1462 int n4k2kYuvCount = ctx->listStats[mDpy].yuv4k2kCount;
1463 for(int index = 0; index < n4k2kYuvCount; index++){
1464 int n4k2kYuvIndex =
1465 ctx->listStats[mDpy].yuv4k2kIndices[index];
1466 if(mCurrentFrame.fbZ > n4k2kYuvIndex){
1467 mCurrentFrame.fbZ += 1;
1468 }
1469 }
1470 }
radhakrishnac9a67412013-09-25 17:40:42 +05301471}
1472
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001473/*
1474 * Configures pipe(s) for MDP composition
1475 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001476int MDPCompNonSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001477 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001478 MdpPipeInfoNonSplit& mdp_info =
1479 *(static_cast<MdpPipeInfoNonSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001480 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
1481 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1482 eIsFg isFg = IS_FG_OFF;
1483 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001484
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001485 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
1486 __FUNCTION__, layer, zOrder, dest);
1487
Saurabh Shah88e4d272013-09-03 13:31:29 -07001488 return configureNonSplit(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001489 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001490}
1491
Saurabh Shah88e4d272013-09-03 13:31:29 -07001492bool MDPCompNonSplit::arePipesAvailable(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001493 hwc_display_contents_1_t* list) {
1494 overlay::Overlay& ov = *ctx->mOverlay;
1495 int numPipesNeeded = mCurrentFrame.mdpCount;
1496 int availPipes = ov.availablePipes(mDpy, Overlay::MIXER_DEFAULT);
1497
1498 //Reserve pipe for FB
1499 if(mCurrentFrame.fbCount)
1500 availPipes -= 1;
1501
1502 if(numPipesNeeded > availPipes) {
1503 ALOGD_IF(isDebug(), "%s: Insufficient pipes, dpy %d needed %d, avail %d",
1504 __FUNCTION__, mDpy, numPipesNeeded, availPipes);
1505 return false;
1506 }
1507
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001508 if(not areVGPipesAvailable(ctx, list)) {
1509 return false;
1510 }
1511
1512 return true;
1513}
1514
1515bool MDPCompNonSplit::areVGPipesAvailable(hwc_context_t *ctx,
1516 hwc_display_contents_1_t* list) {
1517 overlay::Overlay& ov = *ctx->mOverlay;
1518 int pipesNeeded = 0;
1519 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1520 if(!mCurrentFrame.isFBComposed[i]) {
1521 hwc_layer_1_t* layer = &list->hwLayers[i];
1522 hwc_rect_t dst = layer->displayFrame;
1523 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301524 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1525 pipesNeeded = pipesNeeded + 2;
1526 }
1527 else if(isYuvBuffer(hnd)) {
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001528 pipesNeeded++;
1529 }
1530 }
1531 }
1532
1533 int availableVGPipes = ov.availablePipes(mDpy, ovutils::OV_MDP_PIPE_VG);
1534 if(pipesNeeded > availableVGPipes) {
1535 ALOGD_IF(isDebug(), "%s: Insufficient VG pipes for video layers"
1536 "dpy %d needed %d, avail %d",
1537 __FUNCTION__, mDpy, pipesNeeded, availableVGPipes);
1538 return false;
1539 }
1540
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001541 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001542}
1543
Saurabh Shah88e4d272013-09-03 13:31:29 -07001544bool MDPCompNonSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001545 hwc_display_contents_1_t* list) {
1546 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001547
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001548 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001549
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001550 hwc_layer_1_t* layer = &list->hwLayers[index];
1551 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301552 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1553 if(allocSplitVGPipesfor4k2k(ctx, list, index)){
1554 continue;
1555 }
1556 }
1557
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001558 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001559 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001560 info.pipeInfo = new MdpPipeInfoNonSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08001561 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001562 MdpPipeInfoNonSplit& pipe_info = *(MdpPipeInfoNonSplit*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001563 ePipeType type = MDPCOMP_OV_ANY;
1564
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001565 if(isYuvBuffer(hnd)) {
1566 type = MDPCOMP_OV_VG;
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301567 } else if(!qhwc::needsScaling(layer)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001568 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
1569 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001570 type = MDPCOMP_OV_DMA;
1571 }
1572
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001573 pipe_info.index = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001574 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001575 ALOGD_IF(isDebug(), "%s: Unable to get pipe type = %d",
1576 __FUNCTION__, (int) type);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001577 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001578 }
1579 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001580 return true;
1581}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001582
radhakrishnac9a67412013-09-25 17:40:42 +05301583int MDPCompNonSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1584 PipeLayerPair& PipeLayerPair) {
1585 MdpYUVPipeInfo& mdp_info =
1586 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1587 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1588 eIsFg isFg = IS_FG_OFF;
1589 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1590 eDest lDest = mdp_info.lIndex;
1591 eDest rDest = mdp_info.rIndex;
1592
1593 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1594 lDest, rDest, &PipeLayerPair.rot);
1595}
1596
Saurabh Shah88e4d272013-09-03 13:31:29 -07001597bool MDPCompNonSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001598
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001599 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001600 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1601 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -08001602 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001603
1604 if(!ctx || !list) {
1605 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001606 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001607 }
1608
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301609 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1610 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1611 return true;
1612 }
1613
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001614 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001615 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001616 idleInvalidator->markForSleep();
1617
1618 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001619 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001620
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001621 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1622 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001623 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001624 if(mCurrentFrame.isFBComposed[i]) continue;
1625
Naseer Ahmed5b6708a2012-08-02 13:46:08 -07001626 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001627 private_handle_t *hnd = (private_handle_t *)layer->handle;
1628 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001629 if (!(layer->flags & HWC_COLOR_FILL)) {
1630 ALOGE("%s handle null", __FUNCTION__);
1631 return false;
1632 }
1633 // No PLAY for Color layer
1634 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1635 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001636 }
1637
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001638 int mdpIndex = mCurrentFrame.layerToMDP[i];
1639
radhakrishnac9a67412013-09-25 17:40:42 +05301640 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1641 {
1642 MdpYUVPipeInfo& pipe_info =
1643 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1644 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1645 ovutils::eDest indexL = pipe_info.lIndex;
1646 ovutils::eDest indexR = pipe_info.rIndex;
1647 int fd = hnd->fd;
1648 uint32_t offset = hnd->offset;
1649 if(rot) {
1650 rot->queueBuffer(fd, offset);
1651 fd = rot->getDstMemId();
1652 offset = rot->getDstOffset();
1653 }
1654 if(indexL != ovutils::OV_INVALID) {
1655 ovutils::eDest destL = (ovutils::eDest)indexL;
1656 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1657 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1658 if (!ov.queueBuffer(fd, offset, destL)) {
1659 ALOGE("%s: queueBuffer failed for display:%d",
1660 __FUNCTION__, mDpy);
1661 return false;
1662 }
1663 }
1664
1665 if(indexR != ovutils::OV_INVALID) {
1666 ovutils::eDest destR = (ovutils::eDest)indexR;
1667 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1668 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1669 if (!ov.queueBuffer(fd, offset, destR)) {
1670 ALOGE("%s: queueBuffer failed for display:%d",
1671 __FUNCTION__, mDpy);
1672 return false;
1673 }
1674 }
1675 }
1676 else{
1677 MdpPipeInfoNonSplit& pipe_info =
Saurabh Shah88e4d272013-09-03 13:31:29 -07001678 *(MdpPipeInfoNonSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
radhakrishnac9a67412013-09-25 17:40:42 +05301679 ovutils::eDest dest = pipe_info.index;
1680 if(dest == ovutils::OV_INVALID) {
1681 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001682 return false;
radhakrishnac9a67412013-09-25 17:40:42 +05301683 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001684
radhakrishnac9a67412013-09-25 17:40:42 +05301685 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1686 continue;
1687 }
1688
1689 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1690 using pipe: %d", __FUNCTION__, layer,
1691 hnd, dest );
1692
1693 int fd = hnd->fd;
1694 uint32_t offset = hnd->offset;
1695
1696 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1697 if(rot) {
1698 if(!rot->queueBuffer(fd, offset))
1699 return false;
1700 fd = rot->getDstMemId();
1701 offset = rot->getDstOffset();
1702 }
1703
1704 if (!ov.queueBuffer(fd, offset, dest)) {
1705 ALOGE("%s: queueBuffer failed for display:%d ",
1706 __FUNCTION__, mDpy);
1707 return false;
1708 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001709 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001710
1711 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001712 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001713 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001714}
1715
Saurabh Shah88e4d272013-09-03 13:31:29 -07001716//=============MDPCompSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001717
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001718void MDPCompSplit::adjustForSourceSplit(hwc_context_t *ctx,
radhakrishnac9a67412013-09-25 17:40:42 +05301719 hwc_display_contents_1_t* list){
1720 //if 4kx2k yuv layer is totally present in either in left half
1721 //or right half then try splitting the yuv layer to avoid decimation
1722 int n4k2kYuvCount = ctx->listStats[mDpy].yuv4k2kCount;
1723 const int lSplit = getLeftSplit(ctx, mDpy);
1724 for(int index = 0; index < n4k2kYuvCount; index++){
1725 int n4k2kYuvIndex = ctx->listStats[mDpy].yuv4k2kIndices[index];
1726 hwc_layer_1_t* layer = &list->hwLayers[n4k2kYuvIndex];
1727 hwc_rect_t dst = layer->displayFrame;
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001728 if((dst.left > lSplit) || (dst.right < lSplit)) {
radhakrishnac9a67412013-09-25 17:40:42 +05301729 mCurrentFrame.mdpCount += 1;
1730 }
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001731 if(mCurrentFrame.fbZ > n4k2kYuvIndex){
1732 mCurrentFrame.fbZ += 1;
1733 }
radhakrishnac9a67412013-09-25 17:40:42 +05301734 }
1735}
1736
Saurabh Shah88e4d272013-09-03 13:31:29 -07001737int MDPCompSplit::pipesNeeded(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001738 hwc_display_contents_1_t* list,
1739 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001740 int pipesNeeded = 0;
Saurabh Shah67a38c32013-06-10 16:23:15 -07001741 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001742
1743 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001744
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001745 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1746 if(!mCurrentFrame.isFBComposed[i]) {
1747 hwc_layer_1_t* layer = &list->hwLayers[i];
1748 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001749 if(mixer == Overlay::MIXER_LEFT && dst.left < lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001750 pipesNeeded++;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001751 } else if(mixer == Overlay::MIXER_RIGHT && dst.right > lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001752 pipesNeeded++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001753 }
1754 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001755 }
1756 return pipesNeeded;
1757}
1758
Saurabh Shah88e4d272013-09-03 13:31:29 -07001759bool MDPCompSplit::arePipesAvailable(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001760 hwc_display_contents_1_t* list) {
1761 overlay::Overlay& ov = *ctx->mOverlay;
Saurabh Shah082468e2013-09-12 10:05:32 -07001762 int totalPipesNeeded = 0;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001763
1764 for(int i = 0; i < Overlay::MIXER_MAX; i++) {
1765 int numPipesNeeded = pipesNeeded(ctx, list, i);
1766 int availPipes = ov.availablePipes(mDpy, i);
1767
1768 //Reserve pipe(s)for FB
1769 if(mCurrentFrame.fbCount)
Saurabh Shah082468e2013-09-12 10:05:32 -07001770 numPipesNeeded += 1;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001771
Saurabh Shah082468e2013-09-12 10:05:32 -07001772 totalPipesNeeded += numPipesNeeded;
1773
1774 //Per mixer check.
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001775 if(numPipesNeeded > availPipes) {
1776 ALOGD_IF(isDebug(), "%s: Insufficient pipes for "
1777 "dpy %d mixer %d needed %d, avail %d",
1778 __FUNCTION__, mDpy, i, numPipesNeeded, availPipes);
1779 return false;
1780 }
1781 }
Saurabh Shah082468e2013-09-12 10:05:32 -07001782
1783 //Per display check, since unused pipes can get counted twice.
1784 int totalPipesAvailable = ov.availablePipes(mDpy);
1785 if(totalPipesNeeded > totalPipesAvailable) {
1786 ALOGD_IF(isDebug(), "%s: Insufficient pipes for "
1787 "dpy %d needed %d, avail %d",
1788 __FUNCTION__, mDpy, totalPipesNeeded, totalPipesAvailable);
1789 return false;
1790 }
1791
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001792 if(not areVGPipesAvailable(ctx, list)) {
1793 return false;
1794 }
1795
1796 return true;
1797}
1798
1799bool MDPCompSplit::areVGPipesAvailable(hwc_context_t *ctx,
1800 hwc_display_contents_1_t* list) {
1801 overlay::Overlay& ov = *ctx->mOverlay;
1802 int pipesNeeded = 0;
1803 const int lSplit = getLeftSplit(ctx, mDpy);
1804 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1805 if(!mCurrentFrame.isFBComposed[i]) {
1806 hwc_layer_1_t* layer = &list->hwLayers[i];
1807 hwc_rect_t dst = layer->displayFrame;
1808 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301809 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1810 if((dst.left > lSplit)||(dst.right < lSplit)){
1811 pipesNeeded = pipesNeeded + 2;
1812 continue;
1813 }
1814 }
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001815 if(isYuvBuffer(hnd)) {
1816 if(dst.left < lSplit) {
1817 pipesNeeded++;
1818 }
1819 if(dst.right > lSplit) {
1820 pipesNeeded++;
1821 }
1822 }
1823 }
1824 }
1825
1826 int availableVGPipes = ov.availablePipes(mDpy, ovutils::OV_MDP_PIPE_VG);
1827 if(pipesNeeded > availableVGPipes) {
1828 ALOGD_IF(isDebug(), "%s: Insufficient VG pipes for video layers"
1829 "dpy %d needed %d, avail %d",
1830 __FUNCTION__, mDpy, pipesNeeded, availableVGPipes);
1831 return false;
1832 }
1833
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001834 return true;
1835}
1836
Saurabh Shah88e4d272013-09-03 13:31:29 -07001837bool MDPCompSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
1838 MdpPipeInfoSplit& pipe_info,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001839 ePipeType type) {
1840 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001841 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001842
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001843 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001844 pipe_info.lIndex = ovutils::OV_INVALID;
1845 pipe_info.rIndex = ovutils::OV_INVALID;
1846
1847 if (dst.left < lSplit) {
1848 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_LEFT);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001849 if(pipe_info.lIndex == ovutils::OV_INVALID)
1850 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001851 }
1852
1853 if(dst.right > lSplit) {
1854 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_RIGHT);
1855 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001856 return false;
1857 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001858
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001859 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001860}
1861
Saurabh Shah88e4d272013-09-03 13:31:29 -07001862bool MDPCompSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001863 hwc_display_contents_1_t* list) {
1864 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001865
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001866 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001867
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001868 hwc_layer_1_t* layer = &list->hwLayers[index];
1869 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301870 hwc_rect_t dst = layer->displayFrame;
1871 const int lSplit = getLeftSplit(ctx, mDpy);
1872 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1873 if((dst.left > lSplit)||(dst.right < lSplit)){
1874 if(allocSplitVGPipesfor4k2k(ctx, list, index)){
1875 continue;
1876 }
1877 }
1878 }
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001879 int mdpIndex = mCurrentFrame.layerToMDP[index];
1880 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001881 info.pipeInfo = new MdpPipeInfoSplit;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001882 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001883 MdpPipeInfoSplit& pipe_info = *(MdpPipeInfoSplit*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001884 ePipeType type = MDPCOMP_OV_ANY;
1885
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001886 if(isYuvBuffer(hnd)) {
1887 type = MDPCOMP_OV_VG;
Sushil Chauhan15a2ea62013-09-04 18:28:36 -07001888 } else if(!qhwc::needsScalingWithSplit(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001889 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001890 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001891 type = MDPCOMP_OV_DMA;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001892 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001893
1894 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001895 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type = %d",
1896 __FUNCTION__, (int) type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001897 return false;
1898 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001899 }
1900 return true;
1901}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001902
radhakrishnac9a67412013-09-25 17:40:42 +05301903int MDPCompSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1904 PipeLayerPair& PipeLayerPair) {
1905 const int lSplit = getLeftSplit(ctx, mDpy);
1906 hwc_rect_t dst = layer->displayFrame;
1907 if((dst.left > lSplit)||(dst.right < lSplit)){
1908 MdpYUVPipeInfo& mdp_info =
1909 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1910 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1911 eIsFg isFg = IS_FG_OFF;
1912 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1913 eDest lDest = mdp_info.lIndex;
1914 eDest rDest = mdp_info.rIndex;
1915
1916 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1917 lDest, rDest, &PipeLayerPair.rot);
1918 }
1919 else{
1920 return configure(ctx, layer, PipeLayerPair);
1921 }
1922}
1923
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001924/*
1925 * Configures pipe(s) for MDP composition
1926 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001927int MDPCompSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001928 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001929 MdpPipeInfoSplit& mdp_info =
1930 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001931 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1932 eIsFg isFg = IS_FG_OFF;
1933 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1934 eDest lDest = mdp_info.lIndex;
1935 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001936
1937 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1938 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1939
Saurabh Shah88e4d272013-09-03 13:31:29 -07001940 return configureSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001941 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001942}
1943
Saurabh Shah88e4d272013-09-03 13:31:29 -07001944bool MDPCompSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001945
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001946 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001947 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1948 return true;
1949 }
1950
1951 if(!ctx || !list) {
1952 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001953 return false;
1954 }
1955
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301956 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1957 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1958 return true;
1959 }
1960
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001961 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001962 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001963 idleInvalidator->markForSleep();
1964
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001965 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001966 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001967
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001968 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1969 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001970 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001971 if(mCurrentFrame.isFBComposed[i]) continue;
1972
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001973 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001974 private_handle_t *hnd = (private_handle_t *)layer->handle;
1975 if(!hnd) {
1976 ALOGE("%s handle null", __FUNCTION__);
1977 return false;
1978 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001979
1980 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1981 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001982 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001983
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001984 int mdpIndex = mCurrentFrame.layerToMDP[i];
1985
radhakrishnac9a67412013-09-25 17:40:42 +05301986 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1987 {
1988 MdpYUVPipeInfo& pipe_info =
1989 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1990 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1991 ovutils::eDest indexL = pipe_info.lIndex;
1992 ovutils::eDest indexR = pipe_info.rIndex;
1993 int fd = hnd->fd;
1994 uint32_t offset = hnd->offset;
1995 if(rot) {
1996 rot->queueBuffer(fd, offset);
1997 fd = rot->getDstMemId();
1998 offset = rot->getDstOffset();
1999 }
2000 if(indexL != ovutils::OV_INVALID) {
2001 ovutils::eDest destL = (ovutils::eDest)indexL;
2002 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
2003 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
2004 if (!ov.queueBuffer(fd, offset, destL)) {
2005 ALOGE("%s: queueBuffer failed for display:%d",
2006 __FUNCTION__, mDpy);
2007 return false;
2008 }
2009 }
Saurabh Shahacf10202013-02-26 10:15:15 -08002010
radhakrishnac9a67412013-09-25 17:40:42 +05302011 if(indexR != ovutils::OV_INVALID) {
2012 ovutils::eDest destR = (ovutils::eDest)indexR;
2013 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
2014 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
2015 if (!ov.queueBuffer(fd, offset, destR)) {
2016 ALOGE("%s: queueBuffer failed for display:%d",
2017 __FUNCTION__, mDpy);
2018 return false;
2019 }
Saurabh Shaha9da08f2013-07-03 13:27:53 -07002020 }
2021 }
radhakrishnac9a67412013-09-25 17:40:42 +05302022 else{
2023 MdpPipeInfoSplit& pipe_info =
2024 *(MdpPipeInfoSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
2025 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07002026
radhakrishnac9a67412013-09-25 17:40:42 +05302027 ovutils::eDest indexL = pipe_info.lIndex;
2028 ovutils::eDest indexR = pipe_info.rIndex;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002029
radhakrishnac9a67412013-09-25 17:40:42 +05302030 int fd = hnd->fd;
2031 int offset = hnd->offset;
2032
2033 if(ctx->mAD->isModeOn()) {
2034 if(ctx->mAD->draw(ctx, fd, offset)) {
2035 fd = ctx->mAD->getDstFd(ctx);
2036 offset = ctx->mAD->getDstOffset(ctx);
2037 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002038 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002039
radhakrishnac9a67412013-09-25 17:40:42 +05302040 if(rot) {
2041 rot->queueBuffer(fd, offset);
2042 fd = rot->getDstMemId();
2043 offset = rot->getDstOffset();
2044 }
2045
2046 //************* play left mixer **********
2047 if(indexL != ovutils::OV_INVALID) {
2048 ovutils::eDest destL = (ovutils::eDest)indexL;
2049 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
2050 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
2051 if (!ov.queueBuffer(fd, offset, destL)) {
2052 ALOGE("%s: queueBuffer failed for left mixer",
2053 __FUNCTION__);
2054 return false;
2055 }
2056 }
2057
2058 //************* play right mixer **********
2059 if(indexR != ovutils::OV_INVALID) {
2060 ovutils::eDest destR = (ovutils::eDest)indexR;
2061 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
2062 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
2063 if (!ov.queueBuffer(fd, offset, destR)) {
2064 ALOGE("%s: queueBuffer failed for right mixer",
2065 __FUNCTION__);
2066 return false;
2067 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002068 }
2069 }
Saurabh Shahacf10202013-02-26 10:15:15 -08002070
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002071 layerProp[i].mFlags &= ~HWC_MDPCOMP;
2072 }
Saurabh Shahacf10202013-02-26 10:15:15 -08002073
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002074 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002075}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002076}; //namespace
2077