blob: 8008d39eec2f5693fd7013468441f1aa2663eca7 [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;
Arun Kumar K.R2e2871c2014-01-10 12:47:06 -0800544 int priDispW = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800545
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -0700546 if(sIdleFallBack && !ctx->listStats[mDpy].secureUI) {
Saurabh Shah2d998a92013-05-14 17:55:58 -0700547 ALOGD_IF(isDebug(), "%s: Idle fallback dpy %d",__FUNCTION__, mDpy);
548 return false;
549 }
550
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800551 if(isSkipPresent(ctx, mDpy)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700552 ALOGD_IF(isDebug(),"%s: SKIP present: %d",
553 __FUNCTION__,
554 isSkipPresent(ctx, mDpy));
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800555 return false;
556 }
557
Arun Kumar K.R2e2871c2014-01-10 12:47:06 -0800558 if(mDpy > HWC_DISPLAY_PRIMARY && (priDispW > MAX_DISPLAY_DIM) &&
559 (ctx->dpyAttr[mDpy].xres < MAX_DISPLAY_DIM)) {
560 // Disable MDP comp on Secondary when the primary is highres panel and
561 // the secondary is a normal 1080p, because, MDP comp on secondary under
562 // in such usecase, decimation gets used for downscale and there will be
563 // a quality mismatch when there will be a fallback to GPU comp
564 ALOGD_IF(isDebug(), "%s: Disable MDP Compositon for Secondary Disp",
565 __FUNCTION__);
566 return false;
567 }
568
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800569 // check for action safe flag and downscale mode which requires scaling.
570 if(ctx->dpyAttr[mDpy].mActionSafePresent
571 || ctx->dpyAttr[mDpy].mDownScaleMode) {
572 ALOGD_IF(isDebug(), "%s: Scaling needed for this frame",__FUNCTION__);
573 return false;
574 }
575
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800576 for(int i = 0; i < numAppLayers; ++i) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800577 hwc_layer_1_t* layer = &list->hwLayers[i];
578 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800579
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700580 if(isYuvBuffer(hnd) && has90Transform(layer)) {
581 if(!canUseRotator(ctx, mDpy)) {
582 ALOGD_IF(isDebug(), "%s: Can't use rotator for dpy %d",
583 __FUNCTION__, mDpy);
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700584 return false;
585 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800586 }
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530587
588 //For 8x26 with panel width>1k, if RGB layer needs HFLIP fail mdp comp
589 // may not need it if Gfx pre-rotation can handle all flips & rotations
590 if(qdutils::MDPVersion::getInstance().is8x26() &&
591 (ctx->dpyAttr[mDpy].xres > 1024) &&
592 (layer->transform & HWC_TRANSFORM_FLIP_H) &&
593 (!isYuvBuffer(hnd)))
594 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800595 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700596
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700597 if(ctx->mAD->isDoable()) {
598 return false;
599 }
600
Saurabh Shahaa236822013-04-24 18:07:26 -0700601 //If all above hard conditions are met we can do full or partial MDP comp.
602 bool ret = false;
603 if(fullMDPComp(ctx, list)) {
604 ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700605 } else if(partialMDPComp(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700606 ret = true;
607 }
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530608
Saurabh Shahaa236822013-04-24 18:07:26 -0700609 return ret;
610}
611
612bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700613 //Will benefit presentation / secondary-only layer.
614 if((mDpy > HWC_DISPLAY_PRIMARY) &&
615 (list->numHwLayers - 1) > MAX_SEC_LAYERS) {
616 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
617 return false;
618 }
619
620 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
621 for(int i = 0; i < numAppLayers; i++) {
622 hwc_layer_1_t* layer = &list->hwLayers[i];
623 if(not isSupportedForMDPComp(ctx, layer)) {
624 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",__FUNCTION__);
625 return false;
626 }
Yang Xu9c1eb2b2013-11-26 01:28:13 +0800627
628 //For 8x26, if there is only one layer which needs scale for secondary
629 //while no scale for primary display, DMA pipe is occupied by primary.
630 //If need to fall back to GLES composition, virtual display lacks DMA
631 //pipe and error is reported.
632 if(qdutils::MDPVersion::getInstance().is8x26() &&
633 mDpy >= HWC_DISPLAY_EXTERNAL &&
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530634 qhwc::needsScaling(layer))
Yang Xu9c1eb2b2013-11-26 01:28:13 +0800635 return false;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700636 }
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800637
Saurabh Shahaa236822013-04-24 18:07:26 -0700638 mCurrentFrame.fbCount = 0;
639 mCurrentFrame.fbZ = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700640 memcpy(&mCurrentFrame.isFBComposed, &mCurrentFrame.drop,
641 sizeof(mCurrentFrame.isFBComposed));
642 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount -
643 mCurrentFrame.dropCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700644
radhakrishnac9a67412013-09-25 17:40:42 +0530645 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800646 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530647 }
648
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800649 if(!postHeuristicsHandling(ctx, list)) {
650 ALOGD_IF(isDebug(), "post heuristic handling failed");
651 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700652 return false;
653 }
654
Saurabh Shahaa236822013-04-24 18:07:26 -0700655 return true;
656}
657
658bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
659{
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700660 if(!sEnableMixedMode) {
661 //Mixed mode is disabled. No need to even try caching.
662 return false;
663 }
664
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700665 bool ret = false;
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800666 if(list->flags & HWC_GEOMETRY_CHANGED) { //Try load based first
667 ret = loadBasedCompPreferGPU(ctx, list) or
668 loadBasedCompPreferMDP(ctx, list) or
669 cacheBasedComp(ctx, list);
670 } else {
671 ret = cacheBasedComp(ctx, list) or
672 loadBasedCompPreferGPU(ctx, list) or
Saurabh Shahb772ae32013-11-18 15:40:02 -0800673 loadBasedCompPreferMDP(ctx, list);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700674 }
675
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700676 return ret;
677}
678
679bool MDPComp::cacheBasedComp(hwc_context_t *ctx,
680 hwc_display_contents_1_t* list) {
681 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700682 mCurrentFrame.reset(numAppLayers);
683 updateLayerCache(ctx, list);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700684
685 //If an MDP marked layer is unsupported cannot do partial MDP Comp
686 for(int i = 0; i < numAppLayers; i++) {
687 if(!mCurrentFrame.isFBComposed[i]) {
688 hwc_layer_1_t* layer = &list->hwLayers[i];
689 if(not isSupportedForMDPComp(ctx, layer)) {
690 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",
691 __FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800692 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700693 return false;
694 }
695 }
696 }
697
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700698 updateYUV(ctx, list, false /*secure only*/);
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530699 bool ret = markLayersForCaching(ctx, list); //sets up fbZ also
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700700 if(!ret) {
701 ALOGD_IF(isDebug(),"%s: batching failed, dpy %d",__FUNCTION__, mDpy);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800702 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700703 return false;
704 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700705
706 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700707
radhakrishnac9a67412013-09-25 17:40:42 +0530708 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800709 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530710 }
711
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700712 //Will benefit cases where a video has non-updating background.
713 if((mDpy > HWC_DISPLAY_PRIMARY) and
714 (mdpCount > MAX_SEC_LAYERS)) {
715 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800716 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700717 return false;
718 }
719
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800720 if(!postHeuristicsHandling(ctx, list)) {
721 ALOGD_IF(isDebug(), "post heuristic handling failed");
722 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700723 return false;
724 }
725
Saurabh Shahaa236822013-04-24 18:07:26 -0700726 return true;
727}
728
Saurabh Shahb772ae32013-11-18 15:40:02 -0800729bool MDPComp::loadBasedCompPreferGPU(hwc_context_t *ctx,
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700730 hwc_display_contents_1_t* list) {
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800731 if(not isLoadBasedCompDoable(ctx, list)) {
732 return false;
733 }
734
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700735 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
736 mCurrentFrame.reset(numAppLayers);
737
Saurabh Shahb772ae32013-11-18 15:40:02 -0800738 int stagesForMDP = min(sMaxPipesPerMixer, ctx->mOverlay->availablePipes(
739 mDpy, Overlay::MIXER_DEFAULT));
740 //If MDP has X possible stages, it can take X layers.
741 const int batchSize = numAppLayers - (stagesForMDP - 1); //1 for FB
742
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700743 if(batchSize <= 0) {
744 ALOGD_IF(isDebug(), "%s: Not attempting", __FUNCTION__);
745 return false;
746 }
747
748 int minBatchStart = -1;
749 size_t minBatchPixelCount = SIZE_MAX;
750
751 for(int i = 0; i <= numAppLayers - batchSize; i++) {
752 uint32_t batchPixelCount = 0;
753 for(int j = i; j < i + batchSize; j++) {
754 hwc_layer_1_t* layer = &list->hwLayers[j];
Arun Kumar K.R91090c72013-10-28 19:40:18 -0700755 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700756 batchPixelCount += (crop.right - crop.left) *
757 (crop.bottom - crop.top);
758 }
759
760 if(batchPixelCount < minBatchPixelCount) {
761 minBatchPixelCount = batchPixelCount;
762 minBatchStart = i;
763 }
764 }
765
766 if(minBatchStart < 0) {
767 ALOGD_IF(isDebug(), "%s: No batch found batchSize %d numAppLayers %d",
768 __FUNCTION__, batchSize, numAppLayers);
769 return false;
770 }
771
772 for(int i = 0; i < numAppLayers; i++) {
773 if(i < minBatchStart || i >= minBatchStart + batchSize) {
774 hwc_layer_1_t* layer = &list->hwLayers[i];
775 if(not isSupportedForMDPComp(ctx, layer)) {
776 ALOGD_IF(isDebug(), "%s: MDP unsupported layer found at %d",
777 __FUNCTION__, i);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800778 reset(ctx);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700779 return false;
780 }
781 mCurrentFrame.isFBComposed[i] = false;
782 }
783 }
784
785 mCurrentFrame.fbZ = minBatchStart;
786 mCurrentFrame.fbCount = batchSize;
787 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - batchSize;
788
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800789 ALOGD_IF(isDebug(), "%s: fbZ %d batchSize %d",
790 __FUNCTION__, mCurrentFrame.fbZ, batchSize);
791
radhakrishnac9a67412013-09-25 17:40:42 +0530792 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800793 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530794 }
795
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800796 if(!postHeuristicsHandling(ctx, list)) {
797 ALOGD_IF(isDebug(), "post heuristic handling failed");
798 reset(ctx);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700799 return false;
800 }
801
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700802 return true;
803}
804
Saurabh Shahb772ae32013-11-18 15:40:02 -0800805bool MDPComp::loadBasedCompPreferMDP(hwc_context_t *ctx,
806 hwc_display_contents_1_t* list) {
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800807 if(not isLoadBasedCompDoable(ctx, list)) {
808 return false;
809 }
810
Saurabh Shahb772ae32013-11-18 15:40:02 -0800811 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800812 mCurrentFrame.reset(numAppLayers);
813
Saurabh Shahb772ae32013-11-18 15:40:02 -0800814 //Full screen is from ib perspective, not actual full screen
815 const int bpp = 4;
816 double panelRefRate =
817 1000000000.0 / ctx->dpyAttr[mDpy].vsync_period;
818
819 double bwLeft = sMaxBw - sBwClaimed;
820
821 const int fullScreenLayers = bwLeft * 1000000000 / (ctx->dpyAttr[mDpy].xres
822 * ctx->dpyAttr[mDpy].yres * bpp * panelRefRate);
823
824 const int fbBatchSize = numAppLayers - (fullScreenLayers - 1);
825 //If batch size is not at least 2, we aren't really preferring MDP, since
826 //only 1 layer going to GPU could actually translate into an entire FB
827 //needed to be fetched by MDP, thus needing more b/w rather than less.
828 if(fbBatchSize < 2 || fbBatchSize > numAppLayers) {
829 ALOGD_IF(isDebug(), "%s: Not attempting", __FUNCTION__);
830 return false;
831 }
832
833 //Top-most layers constitute FB batch
834 const int fbBatchStart = numAppLayers - fbBatchSize;
835
836 //Bottom-most layers constitute MDP batch
837 for(int i = 0; i < fbBatchStart; i++) {
838 hwc_layer_1_t* layer = &list->hwLayers[i];
839 if(not isSupportedForMDPComp(ctx, layer)) {
840 ALOGD_IF(isDebug(), "%s: MDP unsupported layer found at %d",
841 __FUNCTION__, i);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800842 reset(ctx);
Saurabh Shahb772ae32013-11-18 15:40:02 -0800843 return false;
844 }
845 mCurrentFrame.isFBComposed[i] = false;
846 }
847
848 mCurrentFrame.fbZ = fbBatchStart;
849 mCurrentFrame.fbCount = fbBatchSize;
850 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - fbBatchSize;
851
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800852 ALOGD_IF(isDebug(), "%s: FB Z %d, num app layers %d, MDP Batch Size %d",
853 __FUNCTION__, mCurrentFrame.fbZ, numAppLayers,
854 numAppLayers - fbBatchSize);
855
radhakrishnac9a67412013-09-25 17:40:42 +0530856 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800857 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530858 }
859
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800860 if(!postHeuristicsHandling(ctx, list)) {
861 ALOGD_IF(isDebug(), "post heuristic handling failed");
862 reset(ctx);
Saurabh Shahb772ae32013-11-18 15:40:02 -0800863 return false;
864 }
865
Saurabh Shahb772ae32013-11-18 15:40:02 -0800866 return true;
867}
868
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700869bool MDPComp::isLoadBasedCompDoable(hwc_context_t *ctx,
870 hwc_display_contents_1_t* list) {
Prabhanjan Kandula3dbbd882013-12-11 14:43:46 +0530871 if(mDpy or isSecurePresent(ctx, mDpy) or
872 isYuvPresent(ctx, mDpy)) {
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700873 return false;
874 }
875 return true;
876}
877
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800878bool MDPComp::tryVideoOnly(hwc_context_t *ctx,
879 hwc_display_contents_1_t* list) {
880 const bool secureOnly = true;
881 return videoOnlyComp(ctx, list, not secureOnly) or
882 videoOnlyComp(ctx, list, secureOnly);
883}
884
885bool MDPComp::videoOnlyComp(hwc_context_t *ctx,
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700886 hwc_display_contents_1_t* list, bool secureOnly) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700887 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700888
Saurabh Shahaa236822013-04-24 18:07:26 -0700889 mCurrentFrame.reset(numAppLayers);
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700890 updateYUV(ctx, list, secureOnly);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700891 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700892
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800893 if(!isYuvPresent(ctx, mDpy) or (mdpCount == 0)) {
894 reset(ctx);
Saurabh Shahaa236822013-04-24 18:07:26 -0700895 return false;
896 }
897
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -0800898 /* Bail out if we are processing only secured video layers
899 * and we dont have any */
900 if(!isSecurePresent(ctx, mDpy) && secureOnly){
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800901 reset(ctx);
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -0800902 return false;
903 }
904
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800905 if(mCurrentFrame.fbCount)
906 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
Saurabh Shah4fdde762013-04-30 18:47:33 -0700907
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800908 if(sEnable4k2kYUVSplit){
909 adjustForSourceSplit(ctx, list);
910 }
911
912 if(!postHeuristicsHandling(ctx, list)) {
913 ALOGD_IF(isDebug(), "post heuristic handling failed");
914 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700915 return false;
916 }
917
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800918 return true;
919}
920
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800921/* Checks for conditions where YUV layers cannot be bypassed */
922bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -0700923 if(isSkipLayer(layer)) {
Saurabh Shahe2474082013-05-15 16:32:13 -0700924 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800925 return false;
926 }
927
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700928 if(layer->transform & HWC_TRANSFORM_ROT_90 && !canUseRotator(ctx,mDpy)) {
929 ALOGD_IF(isDebug(), "%s: no free DMA pipe",__FUNCTION__);
930 return false;
931 }
932
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800933 if(isSecuring(ctx, layer)) {
934 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
935 return false;
936 }
937
Saurabh Shah4fdde762013-04-30 18:47:33 -0700938 if(!isValidDimension(ctx, layer)) {
939 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
940 __FUNCTION__);
941 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800942 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700943
Naseer Ahmeddc61a972013-07-10 17:50:54 -0400944 if(layer->planeAlpha < 0xFF) {
945 ALOGD_IF(isDebug(), "%s: Cannot handle YUV layer with plane alpha\
946 in video only mode",
947 __FUNCTION__);
948 return false;
949 }
950
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800951 return true;
952}
953
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530954/* starts at fromIndex and check for each layer to find
955 * if it it has overlapping with any Updating layer above it in zorder
956 * till the end of the batch. returns true if it finds any intersection */
957bool MDPComp::canPushBatchToTop(const hwc_display_contents_1_t* list,
958 int fromIndex, int toIndex) {
959 for(int i = fromIndex; i < toIndex; i++) {
960 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
961 if(intersectingUpdatingLayers(list, i+1, toIndex, i)) {
962 return false;
963 }
964 }
965 }
966 return true;
967}
968
969/* Checks if given layer at targetLayerIndex has any
970 * intersection with all the updating layers in beween
971 * fromIndex and toIndex. Returns true if it finds intersectiion */
972bool MDPComp::intersectingUpdatingLayers(const hwc_display_contents_1_t* list,
973 int fromIndex, int toIndex, int targetLayerIndex) {
974 for(int i = fromIndex; i <= toIndex; i++) {
975 if(!mCurrentFrame.isFBComposed[i]) {
976 if(areLayersIntersecting(&list->hwLayers[i],
977 &list->hwLayers[targetLayerIndex])) {
978 return true;
979 }
980 }
981 }
982 return false;
983}
984
985int MDPComp::getBatch(hwc_display_contents_1_t* list,
986 int& maxBatchStart, int& maxBatchEnd,
987 int& maxBatchCount) {
988 int i = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530989 int fbZOrder =-1;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -0800990 int droppedLayerCt = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530991 while (i < mCurrentFrame.layerCount) {
992 int batchCount = 0;
993 int batchStart = i;
994 int batchEnd = i;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -0800995 /* Adjust batch Z order with the dropped layers so far */
996 int fbZ = batchStart - droppedLayerCt;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530997 int firstZReverseIndex = -1;
Prabhanjan Kandula0ed2cc92013-12-06 12:39:04 +0530998 int updatingLayersAbove = 0;//Updating layer count in middle of batch
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530999 while(i < mCurrentFrame.layerCount) {
1000 if(!mCurrentFrame.isFBComposed[i]) {
1001 if(!batchCount) {
1002 i++;
1003 break;
1004 }
1005 updatingLayersAbove++;
1006 i++;
1007 continue;
1008 } else {
1009 if(mCurrentFrame.drop[i]) {
1010 i++;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -08001011 droppedLayerCt++;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301012 continue;
1013 } else if(updatingLayersAbove <= 0) {
1014 batchCount++;
1015 batchEnd = i;
1016 i++;
1017 continue;
1018 } else { //Layer is FBComposed, not a drop & updatingLayer > 0
1019
1020 // We have a valid updating layer already. If layer-i not
1021 // have overlapping with all updating layers in between
1022 // batch-start and i, then we can add layer i to batch.
1023 if(!intersectingUpdatingLayers(list, batchStart, i-1, i)) {
1024 batchCount++;
1025 batchEnd = i;
1026 i++;
1027 continue;
1028 } else if(canPushBatchToTop(list, batchStart, i)) {
1029 //If All the non-updating layers with in this batch
1030 //does not have intersection with the updating layers
1031 //above in z-order, then we can safely move the batch to
1032 //higher z-order. Increment fbZ as it is moving up.
1033 if( firstZReverseIndex < 0) {
1034 firstZReverseIndex = i;
1035 }
1036 batchCount++;
1037 batchEnd = i;
1038 fbZ += updatingLayersAbove;
1039 i++;
1040 updatingLayersAbove = 0;
1041 continue;
1042 } else {
1043 //both failed.start the loop again from here.
1044 if(firstZReverseIndex >= 0) {
1045 i = firstZReverseIndex;
1046 }
1047 break;
1048 }
1049 }
1050 }
1051 }
1052 if(batchCount > maxBatchCount) {
1053 maxBatchCount = batchCount;
1054 maxBatchStart = batchStart;
1055 maxBatchEnd = batchEnd;
1056 fbZOrder = fbZ;
1057 }
1058 }
1059 return fbZOrder;
1060}
1061
1062bool MDPComp::markLayersForCaching(hwc_context_t* ctx,
1063 hwc_display_contents_1_t* list) {
1064 /* Idea is to keep as many non-updating(cached) layers in FB and
1065 * send rest of them through MDP. This is done in 2 steps.
1066 * 1. Find the maximum contiguous batch of non-updating layers.
1067 * 2. See if we can improve this batch size for caching by adding
1068 * opaque layers around the batch, if they don't have
1069 * any overlapping with the updating layers in between.
1070 * NEVER mark an updating layer for caching.
1071 * But cached ones can be marked for MDP */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001072
1073 int maxBatchStart = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001074 int maxBatchEnd = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001075 int maxBatchCount = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301076 int fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001077
1078 /* All or Nothing is cached. No batching needed */
Saurabh Shahaa236822013-04-24 18:07:26 -07001079 if(!mCurrentFrame.fbCount) {
1080 mCurrentFrame.fbZ = -1;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001081 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -07001082 }
1083 if(!mCurrentFrame.mdpCount) {
1084 mCurrentFrame.fbZ = 0;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001085 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -07001086 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001087
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301088 fbZ = getBatch(list, maxBatchStart, maxBatchEnd, maxBatchCount);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001089
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301090 /* reset rest of the layers lying inside ROI for MDP comp */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001091 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001092 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001093 if((i < maxBatchStart || i > maxBatchEnd) &&
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301094 mCurrentFrame.isFBComposed[i]){
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001095 if(!mCurrentFrame.drop[i]){
1096 //If an unsupported layer is being attempted to
1097 //be pulled out we should fail
1098 if(not isSupportedForMDPComp(ctx, layer)) {
1099 return false;
1100 }
1101 mCurrentFrame.isFBComposed[i] = false;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001102 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001103 }
1104 }
1105
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301106 // update the frame data
1107 mCurrentFrame.fbZ = fbZ;
1108 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001109 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001110 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001111
1112 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301113 mCurrentFrame.fbCount);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001114
1115 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001116}
Saurabh Shah85234ec2013-04-12 17:09:00 -07001117
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001118void MDPComp::updateLayerCache(hwc_context_t* ctx,
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001119 hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001120 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001121 int fbCount = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001122
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001123 for(int i = 0; i < numAppLayers; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001124 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001125 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001126 if(!mCurrentFrame.drop[i])
1127 fbCount++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001128 mCurrentFrame.isFBComposed[i] = true;
1129 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -07001130 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001131 }
1132 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001133
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001134 mCurrentFrame.fbCount = fbCount;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001135 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount
1136 - mCurrentFrame.dropCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001137
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001138 ALOGD_IF(isDebug(),"%s: MDP count: %d FB count %d drop count: %d"
1139 ,__FUNCTION__, mCurrentFrame.mdpCount, mCurrentFrame.fbCount,
1140 mCurrentFrame.dropCount);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001141}
1142
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001143void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list,
1144 bool secureOnly) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001145 int nYuvCount = ctx->listStats[mDpy].yuvCount;
1146 for(int index = 0;index < nYuvCount; index++){
1147 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
1148 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
1149
1150 if(!isYUVDoable(ctx, layer)) {
1151 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
1152 mCurrentFrame.isFBComposed[nYuvIndex] = true;
1153 mCurrentFrame.fbCount++;
1154 }
1155 } else {
1156 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001157 private_handle_t *hnd = (private_handle_t *)layer->handle;
1158 if(!secureOnly || isSecureBuffer(hnd)) {
1159 mCurrentFrame.isFBComposed[nYuvIndex] = false;
1160 mCurrentFrame.fbCount--;
1161 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001162 }
1163 }
1164 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001165
1166 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001167 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
1168 ALOGD_IF(isDebug(),"%s: fb count: %d",__FUNCTION__,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001169 mCurrentFrame.fbCount);
1170}
1171
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001172bool MDPComp::postHeuristicsHandling(hwc_context_t *ctx,
1173 hwc_display_contents_1_t* list) {
1174
1175 //Capability checks
1176 if(!resourceCheck(ctx, list)) {
1177 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
1178 return false;
1179 }
1180
1181 //Limitations checks
1182 if(!hwLimitationsCheck(ctx, list)) {
1183 ALOGD_IF(isDebug(), "%s: HW limitations",__FUNCTION__);
1184 return false;
1185 }
1186
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001187 //Configure framebuffer first if applicable
1188 if(mCurrentFrame.fbZ >= 0) {
1189 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, mCurrentFrame.fbZ)) {
1190 ALOGD_IF(isDebug(), "%s configure framebuffer failed",
1191 __FUNCTION__);
1192 return false;
1193 }
1194 }
1195
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001196 mCurrentFrame.map();
1197
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001198 if(!allocLayerPipes(ctx, list)) {
1199 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -07001200 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001201 }
1202
1203 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001204 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001205 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001206 int mdpIndex = mCurrentFrame.layerToMDP[index];
1207 hwc_layer_1_t* layer = &list->hwLayers[index];
1208
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301209 //Leave fbZ for framebuffer. CACHE/GLES layers go here.
1210 if(mdpNextZOrder == mCurrentFrame.fbZ) {
1211 mdpNextZOrder++;
1212 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001213 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1214 cur_pipe->zOrder = mdpNextZOrder++;
1215
radhakrishnac9a67412013-09-25 17:40:42 +05301216 private_handle_t *hnd = (private_handle_t *)layer->handle;
1217 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1218 if(configure4k2kYuv(ctx, layer,
1219 mCurrentFrame.mdpToLayer[mdpIndex])
1220 != 0 ){
1221 ALOGD_IF(isDebug(), "%s: Failed to configure split pipes \
1222 for layer %d",__FUNCTION__, index);
1223 return false;
1224 }
1225 else{
1226 mdpNextZOrder++;
1227 }
1228 continue;
1229 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001230 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
1231 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
radhakrishnac9a67412013-09-25 17:40:42 +05301232 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -07001233 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001234 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001235 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001236 }
1237
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001238 setRedraw(ctx, list);
Saurabh Shahaa236822013-04-24 18:07:26 -07001239 return true;
1240}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001241
Saurabh Shah173f4242013-11-20 09:50:12 -08001242bool MDPComp::resourceCheck(hwc_context_t *ctx,
1243 hwc_display_contents_1_t *list) {
1244 const bool fbUsed = mCurrentFrame.fbCount;
1245 if(mCurrentFrame.mdpCount > sMaxPipesPerMixer - fbUsed) {
1246 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
1247 return false;
1248 }
1249
1250 if(!arePipesAvailable(ctx, list)) {
1251 return false;
1252 }
1253
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001254 double size = calcMDPBytesRead(ctx, list);
Saurabh Shah173f4242013-11-20 09:50:12 -08001255 if(!bandwidthCheck(ctx, size)) {
1256 ALOGD_IF(isDebug(), "%s: Exceeds bandwidth",__FUNCTION__);
1257 return false;
1258 }
1259
1260 return true;
1261}
1262
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001263double MDPComp::calcMDPBytesRead(hwc_context_t *ctx,
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001264 hwc_display_contents_1_t* list) {
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001265 double size = 0;
1266 const double GIG = 1000000000.0;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001267
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001268 //Skip for targets where no device tree value for bw is supplied
1269 if(sMaxBw <= 0.0) {
1270 return 0.0;
1271 }
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001272
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001273 for (uint32_t i = 0; i < list->numHwLayers - 1; i++) {
1274 if(!mCurrentFrame.isFBComposed[i]) {
1275 hwc_layer_1_t* layer = &list->hwLayers[i];
1276 private_handle_t *hnd = (private_handle_t *)layer->handle;
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001277 if (hnd) {
Saurabh Shah62e1d732013-09-17 10:44:05 -07001278 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah90789162013-09-16 10:29:20 -07001279 hwc_rect_t dst = layer->displayFrame;
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001280 float bpp = ((float)hnd->size) / (hnd->width * hnd->height);
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001281 size += (bpp * (crop.right - crop.left) *
1282 (crop.bottom - crop.top) *
1283 ctx->dpyAttr[mDpy].yres / (dst.bottom - dst.top)) /
1284 GIG;
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001285 }
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001286 }
1287 }
1288
1289 if(mCurrentFrame.fbCount) {
1290 hwc_layer_1_t* layer = &list->hwLayers[list->numHwLayers - 1];
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001291 int tempw, temph;
1292 size += (getBufferSizeAndDimensions(
1293 layer->displayFrame.right - layer->displayFrame.left,
1294 layer->displayFrame.bottom - layer->displayFrame.top,
1295 HAL_PIXEL_FORMAT_RGBA_8888,
1296 tempw, temph)) / GIG;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001297 }
1298
1299 return size;
1300}
1301
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001302bool MDPComp::bandwidthCheck(hwc_context_t *ctx, const double& size) {
1303 //Skip for targets where no device tree value for bw is supplied
1304 if(sMaxBw <= 0.0) {
1305 return true;
1306 }
1307
1308 double panelRefRate =
1309 1000000000.0 / ctx->dpyAttr[mDpy].vsync_period;
1310 if((size * panelRefRate) > (sMaxBw - sBwClaimed)) {
1311 return false;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001312 }
1313 return true;
1314}
1315
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301316bool MDPComp::hwLimitationsCheck(hwc_context_t* ctx,
1317 hwc_display_contents_1_t* list) {
1318
1319 //A-family hw limitation:
1320 //If a layer need alpha scaling, MDP can not support.
1321 if(ctx->mMDP.version < qdutils::MDSS_V5) {
1322 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1323 if(!mCurrentFrame.isFBComposed[i] &&
1324 isAlphaScaled( &list->hwLayers[i])) {
1325 ALOGD_IF(isDebug(), "%s:frame needs alphaScaling",__FUNCTION__);
1326 return false;
1327 }
1328 }
1329 }
1330
1331 // On 8x26 & 8974 hw, we have a limitation of downscaling+blending.
1332 //If multiple layers requires downscaling and also they are overlapping
1333 //fall back to GPU since MDSS can not handle it.
1334 if(qdutils::MDPVersion::getInstance().is8x74v2() ||
1335 qdutils::MDPVersion::getInstance().is8x26()) {
1336 for(int i = 0; i < mCurrentFrame.layerCount-1; ++i) {
1337 hwc_layer_1_t* botLayer = &list->hwLayers[i];
1338 if(!mCurrentFrame.isFBComposed[i] &&
1339 isDownscaleRequired(botLayer)) {
1340 //if layer-i is marked for MDP and needs downscaling
1341 //check if any MDP layer on top of i & overlaps with layer-i
1342 for(int j = i+1; j < mCurrentFrame.layerCount; ++j) {
1343 hwc_layer_1_t* topLayer = &list->hwLayers[j];
1344 if(!mCurrentFrame.isFBComposed[j] &&
1345 isDownscaleRequired(topLayer)) {
1346 hwc_rect_t r = getIntersection(botLayer->displayFrame,
1347 topLayer->displayFrame);
1348 if(isValidRect(r))
1349 return false;
1350 }
1351 }
1352 }
1353 }
1354 }
1355 return true;
1356}
1357
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001358int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001359 int ret = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -07001360 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001361 MDPVersion& mdpVersion = qdutils::MDPVersion::getInstance();
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -07001362
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001363 //number of app layers exceeds MAX_NUM_APP_LAYERS fall back to GPU
1364 //do not cache the information for next draw cycle.
1365 if(numLayers > MAX_NUM_APP_LAYERS) {
1366 ALOGI("%s: Number of App layers exceeded the limit ",
1367 __FUNCTION__);
1368 mCachedFrame.reset();
1369 return -1;
1370 }
1371
Saurabh Shahb39f8152013-08-22 10:21:44 -07001372 //reset old data
1373 mCurrentFrame.reset(numLayers);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001374 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1375 mCurrentFrame.dropCount = 0;
Prabhanjan Kandula088bd892013-07-02 23:47:13 +05301376
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -07001377 // Detect the start of animation and fall back to GPU only once to cache
1378 // all the layers in FB and display FB content untill animation completes.
1379 if(ctx->listStats[mDpy].isDisplayAnimating) {
1380 mCurrentFrame.needsRedraw = false;
1381 if(ctx->mAnimationState[mDpy] == ANIMATION_STOPPED) {
1382 mCurrentFrame.needsRedraw = true;
1383 ctx->mAnimationState[mDpy] = ANIMATION_STARTED;
1384 }
1385 setMDPCompLayerFlags(ctx, list);
1386 mCachedFrame.updateCounts(mCurrentFrame);
1387 ret = -1;
1388 return ret;
1389 } else {
1390 ctx->mAnimationState[mDpy] = ANIMATION_STOPPED;
1391 }
1392
Saurabh Shahb39f8152013-08-22 10:21:44 -07001393 //Hard conditions, if not met, cannot do MDP comp
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001394 if(isFrameDoable(ctx)) {
1395 generateROI(ctx, list);
Saurabh Shahb39f8152013-08-22 10:21:44 -07001396
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001397 //Convert from kbps to gbps
1398 sMaxBw = mdpVersion.getHighBw() / 1000000.0;
1399 if (ctx->mExtDisplay->isConnected() ||
1400 ctx->mMDP.panel != MIPI_CMD_PANEL) {
1401 sMaxBw = mdpVersion.getLowBw() / 1000000.0;
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001402 }
1403
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001404 if(tryFullFrame(ctx, list) || tryVideoOnly(ctx, list)) {
1405 setMDPCompLayerFlags(ctx, list);
1406 } else {
1407 reset(ctx);
1408 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1409 mCurrentFrame.dropCount = 0;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001410 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001411 }
1412 } else {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001413 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
1414 __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001415 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001416 }
Saurabh Shahb39f8152013-08-22 10:21:44 -07001417
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001418 if(isDebug()) {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001419 ALOGD("GEOMETRY change: %d",
1420 (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001421 android::String8 sDump("");
1422 dump(sDump);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001423 ALOGD("%s",sDump.string());
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001424 }
1425
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001426 mCachedFrame.cacheAll(list);
1427 mCachedFrame.updateCounts(mCurrentFrame);
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001428 double panelRefRate =
1429 1000000000.0 / ctx->dpyAttr[mDpy].vsync_period;
1430 sBwClaimed += calcMDPBytesRead(ctx, list) * panelRefRate;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001431 return ret;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001432}
1433
radhakrishnac9a67412013-09-25 17:40:42 +05301434bool MDPComp::allocSplitVGPipesfor4k2k(hwc_context_t *ctx,
1435 hwc_display_contents_1_t* list, int index) {
1436
1437 bool bRet = true;
1438 hwc_layer_1_t* layer = &list->hwLayers[index];
1439 private_handle_t *hnd = (private_handle_t *)layer->handle;
1440 int mdpIndex = mCurrentFrame.layerToMDP[index];
1441 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
1442 info.pipeInfo = new MdpYUVPipeInfo;
1443 info.rot = NULL;
1444 MdpYUVPipeInfo& pipe_info = *(MdpYUVPipeInfo*)info.pipeInfo;
1445 ePipeType type = MDPCOMP_OV_VG;
1446
1447 pipe_info.lIndex = ovutils::OV_INVALID;
1448 pipe_info.rIndex = ovutils::OV_INVALID;
1449
1450 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
1451 if(pipe_info.lIndex == ovutils::OV_INVALID){
1452 bRet = false;
1453 ALOGD_IF(isDebug(),"%s: allocating first VG pipe failed",
1454 __FUNCTION__);
1455 }
1456 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
1457 if(pipe_info.rIndex == ovutils::OV_INVALID){
1458 bRet = false;
1459 ALOGD_IF(isDebug(),"%s: allocating second VG pipe failed",
1460 __FUNCTION__);
1461 }
1462 return bRet;
1463}
Saurabh Shah88e4d272013-09-03 13:31:29 -07001464//=============MDPCompNonSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001465
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001466void MDPCompNonSplit::adjustForSourceSplit(hwc_context_t *ctx,
radhakrishnac9a67412013-09-25 17:40:42 +05301467 hwc_display_contents_1_t* list){
1468 //As we split 4kx2k yuv layer and program to 2 VG pipes
1469 //(if available) increase mdpcount accordingly
1470 mCurrentFrame.mdpCount += ctx->listStats[mDpy].yuv4k2kCount;
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001471
1472 //If 4k2k Yuv layer split is possible, and if
1473 //fbz is above 4k2k layer, increment fb zorder by 1
1474 //as we split 4k2k layer and increment zorder for right half
1475 //of the layer
1476 if(mCurrentFrame.fbZ >= 0) {
1477 int n4k2kYuvCount = ctx->listStats[mDpy].yuv4k2kCount;
1478 for(int index = 0; index < n4k2kYuvCount; index++){
1479 int n4k2kYuvIndex =
1480 ctx->listStats[mDpy].yuv4k2kIndices[index];
1481 if(mCurrentFrame.fbZ > n4k2kYuvIndex){
1482 mCurrentFrame.fbZ += 1;
1483 }
1484 }
1485 }
radhakrishnac9a67412013-09-25 17:40:42 +05301486}
1487
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001488/*
1489 * Configures pipe(s) for MDP composition
1490 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001491int MDPCompNonSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001492 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001493 MdpPipeInfoNonSplit& mdp_info =
1494 *(static_cast<MdpPipeInfoNonSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001495 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
1496 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1497 eIsFg isFg = IS_FG_OFF;
1498 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001499
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001500 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
1501 __FUNCTION__, layer, zOrder, dest);
1502
Saurabh Shah88e4d272013-09-03 13:31:29 -07001503 return configureNonSplit(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001504 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001505}
1506
Saurabh Shah88e4d272013-09-03 13:31:29 -07001507bool MDPCompNonSplit::arePipesAvailable(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001508 hwc_display_contents_1_t* list) {
1509 overlay::Overlay& ov = *ctx->mOverlay;
1510 int numPipesNeeded = mCurrentFrame.mdpCount;
1511 int availPipes = ov.availablePipes(mDpy, Overlay::MIXER_DEFAULT);
1512
1513 //Reserve pipe for FB
1514 if(mCurrentFrame.fbCount)
1515 availPipes -= 1;
1516
1517 if(numPipesNeeded > availPipes) {
1518 ALOGD_IF(isDebug(), "%s: Insufficient pipes, dpy %d needed %d, avail %d",
1519 __FUNCTION__, mDpy, numPipesNeeded, availPipes);
1520 return false;
1521 }
1522
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001523 if(not areVGPipesAvailable(ctx, list)) {
1524 return false;
1525 }
1526
1527 return true;
1528}
1529
1530bool MDPCompNonSplit::areVGPipesAvailable(hwc_context_t *ctx,
1531 hwc_display_contents_1_t* list) {
1532 overlay::Overlay& ov = *ctx->mOverlay;
1533 int pipesNeeded = 0;
1534 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1535 if(!mCurrentFrame.isFBComposed[i]) {
1536 hwc_layer_1_t* layer = &list->hwLayers[i];
1537 hwc_rect_t dst = layer->displayFrame;
1538 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301539 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1540 pipesNeeded = pipesNeeded + 2;
1541 }
1542 else if(isYuvBuffer(hnd)) {
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001543 pipesNeeded++;
1544 }
1545 }
1546 }
1547
1548 int availableVGPipes = ov.availablePipes(mDpy, ovutils::OV_MDP_PIPE_VG);
1549 if(pipesNeeded > availableVGPipes) {
1550 ALOGD_IF(isDebug(), "%s: Insufficient VG pipes for video layers"
1551 "dpy %d needed %d, avail %d",
1552 __FUNCTION__, mDpy, pipesNeeded, availableVGPipes);
1553 return false;
1554 }
1555
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001556 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001557}
1558
Saurabh Shah88e4d272013-09-03 13:31:29 -07001559bool MDPCompNonSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001560 hwc_display_contents_1_t* list) {
1561 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001562
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001563 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001564
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001565 hwc_layer_1_t* layer = &list->hwLayers[index];
1566 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301567 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1568 if(allocSplitVGPipesfor4k2k(ctx, list, index)){
1569 continue;
1570 }
1571 }
1572
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001573 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001574 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001575 info.pipeInfo = new MdpPipeInfoNonSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08001576 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001577 MdpPipeInfoNonSplit& pipe_info = *(MdpPipeInfoNonSplit*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001578 ePipeType type = MDPCOMP_OV_ANY;
1579
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001580 if(isYuvBuffer(hnd)) {
1581 type = MDPCOMP_OV_VG;
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301582 } else if(!qhwc::needsScaling(layer)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001583 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
1584 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001585 type = MDPCOMP_OV_DMA;
1586 }
1587
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001588 pipe_info.index = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001589 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001590 ALOGD_IF(isDebug(), "%s: Unable to get pipe type = %d",
1591 __FUNCTION__, (int) type);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001592 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001593 }
1594 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001595 return true;
1596}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001597
radhakrishnac9a67412013-09-25 17:40:42 +05301598int MDPCompNonSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1599 PipeLayerPair& PipeLayerPair) {
1600 MdpYUVPipeInfo& mdp_info =
1601 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1602 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1603 eIsFg isFg = IS_FG_OFF;
1604 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1605 eDest lDest = mdp_info.lIndex;
1606 eDest rDest = mdp_info.rIndex;
1607
1608 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1609 lDest, rDest, &PipeLayerPair.rot);
1610}
1611
Saurabh Shah88e4d272013-09-03 13:31:29 -07001612bool MDPCompNonSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001613
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001614 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001615 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1616 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -08001617 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001618
1619 if(!ctx || !list) {
1620 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001621 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001622 }
1623
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301624 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1625 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1626 return true;
1627 }
1628
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001629 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001630 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Saurabh Shahb2117fe2014-01-23 18:39:01 -08001631 idleInvalidator->handleUpdateEvent();
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001632
1633 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001634 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001635
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001636 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1637 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001638 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001639 if(mCurrentFrame.isFBComposed[i]) continue;
1640
Naseer Ahmed5b6708a2012-08-02 13:46:08 -07001641 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001642 private_handle_t *hnd = (private_handle_t *)layer->handle;
1643 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001644 if (!(layer->flags & HWC_COLOR_FILL)) {
1645 ALOGE("%s handle null", __FUNCTION__);
1646 return false;
1647 }
1648 // No PLAY for Color layer
1649 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1650 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001651 }
1652
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001653 int mdpIndex = mCurrentFrame.layerToMDP[i];
1654
radhakrishnac9a67412013-09-25 17:40:42 +05301655 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1656 {
1657 MdpYUVPipeInfo& pipe_info =
1658 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1659 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1660 ovutils::eDest indexL = pipe_info.lIndex;
1661 ovutils::eDest indexR = pipe_info.rIndex;
1662 int fd = hnd->fd;
1663 uint32_t offset = hnd->offset;
1664 if(rot) {
1665 rot->queueBuffer(fd, offset);
1666 fd = rot->getDstMemId();
1667 offset = rot->getDstOffset();
1668 }
1669 if(indexL != ovutils::OV_INVALID) {
1670 ovutils::eDest destL = (ovutils::eDest)indexL;
1671 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1672 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1673 if (!ov.queueBuffer(fd, offset, destL)) {
1674 ALOGE("%s: queueBuffer failed for display:%d",
1675 __FUNCTION__, mDpy);
1676 return false;
1677 }
1678 }
1679
1680 if(indexR != ovutils::OV_INVALID) {
1681 ovutils::eDest destR = (ovutils::eDest)indexR;
1682 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1683 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1684 if (!ov.queueBuffer(fd, offset, destR)) {
1685 ALOGE("%s: queueBuffer failed for display:%d",
1686 __FUNCTION__, mDpy);
1687 return false;
1688 }
1689 }
1690 }
1691 else{
1692 MdpPipeInfoNonSplit& pipe_info =
Saurabh Shah88e4d272013-09-03 13:31:29 -07001693 *(MdpPipeInfoNonSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
radhakrishnac9a67412013-09-25 17:40:42 +05301694 ovutils::eDest dest = pipe_info.index;
1695 if(dest == ovutils::OV_INVALID) {
1696 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001697 return false;
radhakrishnac9a67412013-09-25 17:40:42 +05301698 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001699
radhakrishnac9a67412013-09-25 17:40:42 +05301700 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1701 continue;
1702 }
1703
1704 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1705 using pipe: %d", __FUNCTION__, layer,
1706 hnd, dest );
1707
1708 int fd = hnd->fd;
1709 uint32_t offset = hnd->offset;
1710
1711 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1712 if(rot) {
1713 if(!rot->queueBuffer(fd, offset))
1714 return false;
1715 fd = rot->getDstMemId();
1716 offset = rot->getDstOffset();
1717 }
1718
1719 if (!ov.queueBuffer(fd, offset, dest)) {
1720 ALOGE("%s: queueBuffer failed for display:%d ",
1721 __FUNCTION__, mDpy);
1722 return false;
1723 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001724 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001725
1726 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001727 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001728 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001729}
1730
Saurabh Shah88e4d272013-09-03 13:31:29 -07001731//=============MDPCompSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001732
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001733void MDPCompSplit::adjustForSourceSplit(hwc_context_t *ctx,
radhakrishnac9a67412013-09-25 17:40:42 +05301734 hwc_display_contents_1_t* list){
1735 //if 4kx2k yuv layer is totally present in either in left half
1736 //or right half then try splitting the yuv layer to avoid decimation
1737 int n4k2kYuvCount = ctx->listStats[mDpy].yuv4k2kCount;
1738 const int lSplit = getLeftSplit(ctx, mDpy);
1739 for(int index = 0; index < n4k2kYuvCount; index++){
1740 int n4k2kYuvIndex = ctx->listStats[mDpy].yuv4k2kIndices[index];
1741 hwc_layer_1_t* layer = &list->hwLayers[n4k2kYuvIndex];
1742 hwc_rect_t dst = layer->displayFrame;
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001743 if((dst.left > lSplit) || (dst.right < lSplit)) {
radhakrishnac9a67412013-09-25 17:40:42 +05301744 mCurrentFrame.mdpCount += 1;
1745 }
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001746 if(mCurrentFrame.fbZ > n4k2kYuvIndex){
1747 mCurrentFrame.fbZ += 1;
1748 }
radhakrishnac9a67412013-09-25 17:40:42 +05301749 }
1750}
1751
Saurabh Shah88e4d272013-09-03 13:31:29 -07001752int MDPCompSplit::pipesNeeded(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001753 hwc_display_contents_1_t* list,
1754 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001755 int pipesNeeded = 0;
Saurabh Shah67a38c32013-06-10 16:23:15 -07001756 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001757
1758 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001759
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001760 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1761 if(!mCurrentFrame.isFBComposed[i]) {
1762 hwc_layer_1_t* layer = &list->hwLayers[i];
1763 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001764 if(mixer == Overlay::MIXER_LEFT && dst.left < lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001765 pipesNeeded++;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001766 } else if(mixer == Overlay::MIXER_RIGHT && dst.right > lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001767 pipesNeeded++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001768 }
1769 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001770 }
1771 return pipesNeeded;
1772}
1773
Saurabh Shah88e4d272013-09-03 13:31:29 -07001774bool MDPCompSplit::arePipesAvailable(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001775 hwc_display_contents_1_t* list) {
1776 overlay::Overlay& ov = *ctx->mOverlay;
Saurabh Shah082468e2013-09-12 10:05:32 -07001777 int totalPipesNeeded = 0;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001778
1779 for(int i = 0; i < Overlay::MIXER_MAX; i++) {
1780 int numPipesNeeded = pipesNeeded(ctx, list, i);
1781 int availPipes = ov.availablePipes(mDpy, i);
1782
1783 //Reserve pipe(s)for FB
1784 if(mCurrentFrame.fbCount)
Saurabh Shah082468e2013-09-12 10:05:32 -07001785 numPipesNeeded += 1;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001786
Saurabh Shah082468e2013-09-12 10:05:32 -07001787 totalPipesNeeded += numPipesNeeded;
1788
1789 //Per mixer check.
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001790 if(numPipesNeeded > availPipes) {
1791 ALOGD_IF(isDebug(), "%s: Insufficient pipes for "
1792 "dpy %d mixer %d needed %d, avail %d",
1793 __FUNCTION__, mDpy, i, numPipesNeeded, availPipes);
1794 return false;
1795 }
1796 }
Saurabh Shah082468e2013-09-12 10:05:32 -07001797
1798 //Per display check, since unused pipes can get counted twice.
1799 int totalPipesAvailable = ov.availablePipes(mDpy);
1800 if(totalPipesNeeded > totalPipesAvailable) {
1801 ALOGD_IF(isDebug(), "%s: Insufficient pipes for "
1802 "dpy %d needed %d, avail %d",
1803 __FUNCTION__, mDpy, totalPipesNeeded, totalPipesAvailable);
1804 return false;
1805 }
1806
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001807 if(not areVGPipesAvailable(ctx, list)) {
1808 return false;
1809 }
1810
1811 return true;
1812}
1813
1814bool MDPCompSplit::areVGPipesAvailable(hwc_context_t *ctx,
1815 hwc_display_contents_1_t* list) {
1816 overlay::Overlay& ov = *ctx->mOverlay;
1817 int pipesNeeded = 0;
1818 const int lSplit = getLeftSplit(ctx, mDpy);
1819 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1820 if(!mCurrentFrame.isFBComposed[i]) {
1821 hwc_layer_1_t* layer = &list->hwLayers[i];
1822 hwc_rect_t dst = layer->displayFrame;
1823 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301824 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1825 if((dst.left > lSplit)||(dst.right < lSplit)){
1826 pipesNeeded = pipesNeeded + 2;
1827 continue;
1828 }
1829 }
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001830 if(isYuvBuffer(hnd)) {
1831 if(dst.left < lSplit) {
1832 pipesNeeded++;
1833 }
1834 if(dst.right > lSplit) {
1835 pipesNeeded++;
1836 }
1837 }
1838 }
1839 }
1840
1841 int availableVGPipes = ov.availablePipes(mDpy, ovutils::OV_MDP_PIPE_VG);
1842 if(pipesNeeded > availableVGPipes) {
1843 ALOGD_IF(isDebug(), "%s: Insufficient VG pipes for video layers"
1844 "dpy %d needed %d, avail %d",
1845 __FUNCTION__, mDpy, pipesNeeded, availableVGPipes);
1846 return false;
1847 }
1848
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001849 return true;
1850}
1851
Saurabh Shah88e4d272013-09-03 13:31:29 -07001852bool MDPCompSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
1853 MdpPipeInfoSplit& pipe_info,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001854 ePipeType type) {
1855 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001856 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001857
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001858 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001859 pipe_info.lIndex = ovutils::OV_INVALID;
1860 pipe_info.rIndex = ovutils::OV_INVALID;
1861
1862 if (dst.left < lSplit) {
1863 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_LEFT);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001864 if(pipe_info.lIndex == ovutils::OV_INVALID)
1865 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001866 }
1867
1868 if(dst.right > lSplit) {
1869 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_RIGHT);
1870 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001871 return false;
1872 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001873
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001874 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001875}
1876
Saurabh Shah88e4d272013-09-03 13:31:29 -07001877bool MDPCompSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001878 hwc_display_contents_1_t* list) {
1879 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001880
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001881 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001882
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001883 hwc_layer_1_t* layer = &list->hwLayers[index];
1884 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301885 hwc_rect_t dst = layer->displayFrame;
1886 const int lSplit = getLeftSplit(ctx, mDpy);
1887 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1888 if((dst.left > lSplit)||(dst.right < lSplit)){
1889 if(allocSplitVGPipesfor4k2k(ctx, list, index)){
1890 continue;
1891 }
1892 }
1893 }
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001894 int mdpIndex = mCurrentFrame.layerToMDP[index];
1895 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001896 info.pipeInfo = new MdpPipeInfoSplit;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001897 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001898 MdpPipeInfoSplit& pipe_info = *(MdpPipeInfoSplit*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001899 ePipeType type = MDPCOMP_OV_ANY;
1900
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001901 if(isYuvBuffer(hnd)) {
1902 type = MDPCOMP_OV_VG;
Sushil Chauhan15a2ea62013-09-04 18:28:36 -07001903 } else if(!qhwc::needsScalingWithSplit(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001904 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001905 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001906 type = MDPCOMP_OV_DMA;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001907 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001908
1909 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001910 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type = %d",
1911 __FUNCTION__, (int) type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001912 return false;
1913 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001914 }
1915 return true;
1916}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001917
radhakrishnac9a67412013-09-25 17:40:42 +05301918int MDPCompSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1919 PipeLayerPair& PipeLayerPair) {
1920 const int lSplit = getLeftSplit(ctx, mDpy);
1921 hwc_rect_t dst = layer->displayFrame;
1922 if((dst.left > lSplit)||(dst.right < lSplit)){
1923 MdpYUVPipeInfo& mdp_info =
1924 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1925 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1926 eIsFg isFg = IS_FG_OFF;
1927 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1928 eDest lDest = mdp_info.lIndex;
1929 eDest rDest = mdp_info.rIndex;
1930
1931 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1932 lDest, rDest, &PipeLayerPair.rot);
1933 }
1934 else{
1935 return configure(ctx, layer, PipeLayerPair);
1936 }
1937}
1938
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001939/*
1940 * Configures pipe(s) for MDP composition
1941 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001942int MDPCompSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001943 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001944 MdpPipeInfoSplit& mdp_info =
1945 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001946 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1947 eIsFg isFg = IS_FG_OFF;
1948 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1949 eDest lDest = mdp_info.lIndex;
1950 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001951
1952 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1953 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1954
Saurabh Shah88e4d272013-09-03 13:31:29 -07001955 return configureSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001956 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001957}
1958
Saurabh Shah88e4d272013-09-03 13:31:29 -07001959bool MDPCompSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001960
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001961 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001962 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1963 return true;
1964 }
1965
1966 if(!ctx || !list) {
1967 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001968 return false;
1969 }
1970
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301971 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1972 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1973 return true;
1974 }
1975
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001976 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001977 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Saurabh Shahb2117fe2014-01-23 18:39:01 -08001978 idleInvalidator->handleUpdateEvent();
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001979
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001980 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001981 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001982
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001983 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1984 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001985 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001986 if(mCurrentFrame.isFBComposed[i]) continue;
1987
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001988 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001989 private_handle_t *hnd = (private_handle_t *)layer->handle;
1990 if(!hnd) {
1991 ALOGE("%s handle null", __FUNCTION__);
1992 return false;
1993 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001994
1995 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1996 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001997 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001998
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001999 int mdpIndex = mCurrentFrame.layerToMDP[i];
2000
radhakrishnac9a67412013-09-25 17:40:42 +05302001 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
2002 {
2003 MdpYUVPipeInfo& pipe_info =
2004 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
2005 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
2006 ovutils::eDest indexL = pipe_info.lIndex;
2007 ovutils::eDest indexR = pipe_info.rIndex;
2008 int fd = hnd->fd;
2009 uint32_t offset = hnd->offset;
2010 if(rot) {
2011 rot->queueBuffer(fd, offset);
2012 fd = rot->getDstMemId();
2013 offset = rot->getDstOffset();
2014 }
2015 if(indexL != ovutils::OV_INVALID) {
2016 ovutils::eDest destL = (ovutils::eDest)indexL;
2017 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
2018 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
2019 if (!ov.queueBuffer(fd, offset, destL)) {
2020 ALOGE("%s: queueBuffer failed for display:%d",
2021 __FUNCTION__, mDpy);
2022 return false;
2023 }
2024 }
Saurabh Shahacf10202013-02-26 10:15:15 -08002025
radhakrishnac9a67412013-09-25 17:40:42 +05302026 if(indexR != ovutils::OV_INVALID) {
2027 ovutils::eDest destR = (ovutils::eDest)indexR;
2028 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
2029 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
2030 if (!ov.queueBuffer(fd, offset, destR)) {
2031 ALOGE("%s: queueBuffer failed for display:%d",
2032 __FUNCTION__, mDpy);
2033 return false;
2034 }
Saurabh Shaha9da08f2013-07-03 13:27:53 -07002035 }
2036 }
radhakrishnac9a67412013-09-25 17:40:42 +05302037 else{
2038 MdpPipeInfoSplit& pipe_info =
2039 *(MdpPipeInfoSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
2040 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07002041
radhakrishnac9a67412013-09-25 17:40:42 +05302042 ovutils::eDest indexL = pipe_info.lIndex;
2043 ovutils::eDest indexR = pipe_info.rIndex;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002044
radhakrishnac9a67412013-09-25 17:40:42 +05302045 int fd = hnd->fd;
2046 int offset = hnd->offset;
2047
2048 if(ctx->mAD->isModeOn()) {
2049 if(ctx->mAD->draw(ctx, fd, offset)) {
2050 fd = ctx->mAD->getDstFd(ctx);
2051 offset = ctx->mAD->getDstOffset(ctx);
2052 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002053 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002054
radhakrishnac9a67412013-09-25 17:40:42 +05302055 if(rot) {
2056 rot->queueBuffer(fd, offset);
2057 fd = rot->getDstMemId();
2058 offset = rot->getDstOffset();
2059 }
2060
2061 //************* play left mixer **********
2062 if(indexL != ovutils::OV_INVALID) {
2063 ovutils::eDest destL = (ovutils::eDest)indexL;
2064 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
2065 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
2066 if (!ov.queueBuffer(fd, offset, destL)) {
2067 ALOGE("%s: queueBuffer failed for left mixer",
2068 __FUNCTION__);
2069 return false;
2070 }
2071 }
2072
2073 //************* play right mixer **********
2074 if(indexR != ovutils::OV_INVALID) {
2075 ovutils::eDest destR = (ovutils::eDest)indexR;
2076 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
2077 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
2078 if (!ov.queueBuffer(fd, offset, destR)) {
2079 ALOGE("%s: queueBuffer failed for right mixer",
2080 __FUNCTION__);
2081 return false;
2082 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002083 }
2084 }
Saurabh Shahacf10202013-02-26 10:15:15 -08002085
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002086 layerProp[i].mFlags &= ~HWC_MDPCOMP;
2087 }
Saurabh Shahacf10202013-02-26 10:15:15 -08002088
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002089 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002090}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002091}; //namespace
2092