blob: 2356c9ce044f51ad347ad77ba7d227160b1fa553 [file] [log] [blame]
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001/*
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08002 * Copyright (C) 2012-2014, 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;
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -080041bool MDPComp::sHandleTimeout = false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070042bool MDPComp::sDebugLogs = false;
Naseer Ahmed54821fe2012-11-28 18:44:38 -050043bool MDPComp::sEnabled = false;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -070044bool MDPComp::sEnableMixedMode = true;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -070045bool MDPComp::sEnablePartialFrameUpdate = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080046int MDPComp::sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
radhakrishnac9a67412013-09-25 17:40:42 +053047bool MDPComp::sEnable4k2kYUVSplit = false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070048
Saurabh Shah88e4d272013-09-03 13:31:29 -070049MDPComp* MDPComp::getObject(hwc_context_t *ctx, const int& dpy) {
50 if(isDisplaySplit(ctx, dpy)) {
51 return new MDPCompSplit(dpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080052 }
Saurabh Shah88e4d272013-09-03 13:31:29 -070053 return new MDPCompNonSplit(dpy);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080054}
55
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080056MDPComp::MDPComp(int dpy):mDpy(dpy){};
57
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080058void MDPComp::dump(android::String8& buf)
59{
Jeykumar Sankaran3c6bb042013-08-15 14:01:04 -070060 if(mCurrentFrame.layerCount > MAX_NUM_APP_LAYERS)
61 return;
62
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080063 dumpsys_log(buf,"HWC Map for Dpy: %s \n",
Jeykumar Sankaran27dee262013-08-01 17:09:54 -070064 (mDpy == 0) ? "\"PRIMARY\"" :
65 (mDpy == 1) ? "\"EXTERNAL\"" : "\"VIRTUAL\"");
Saurabh Shahe9bc60f2013-08-29 12:58:06 -070066 dumpsys_log(buf,"CURR_FRAME: layerCount:%2d mdpCount:%2d "
67 "fbCount:%2d \n", mCurrentFrame.layerCount,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080068 mCurrentFrame.mdpCount, mCurrentFrame.fbCount);
69 dumpsys_log(buf,"needsFBRedraw:%3s pipesUsed:%2d MaxPipesPerMixer: %d \n",
70 (mCurrentFrame.needsRedraw? "YES" : "NO"),
71 mCurrentFrame.mdpCount, sMaxPipesPerMixer);
72 dumpsys_log(buf," --------------------------------------------- \n");
73 dumpsys_log(buf," listIdx | cached? | mdpIndex | comptype | Z \n");
74 dumpsys_log(buf," --------------------------------------------- \n");
75 for(int index = 0; index < mCurrentFrame.layerCount; index++ )
76 dumpsys_log(buf," %7d | %7s | %8d | %9s | %2d \n",
77 index,
78 (mCurrentFrame.isFBComposed[index] ? "YES" : "NO"),
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -070079 mCurrentFrame.layerToMDP[index],
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080080 (mCurrentFrame.isFBComposed[index] ?
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -070081 (mCurrentFrame.drop[index] ? "DROP" :
82 (mCurrentFrame.needsRedraw ? "GLES" : "CACHE")) : "MDP"),
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080083 (mCurrentFrame.isFBComposed[index] ? mCurrentFrame.fbZ :
84 mCurrentFrame.mdpToLayer[mCurrentFrame.layerToMDP[index]].pipeInfo->zOrder));
85 dumpsys_log(buf,"\n");
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080086}
87
88bool MDPComp::init(hwc_context_t *ctx) {
89
90 if(!ctx) {
91 ALOGE("%s: Invalid hwc context!!",__FUNCTION__);
92 return false;
93 }
94
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080095 char property[PROPERTY_VALUE_MAX];
96
97 sEnabled = false;
98 if((property_get("persist.hwc.mdpcomp.enable", property, NULL) > 0) &&
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080099 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
100 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800101 sEnabled = true;
102 }
103
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700104 sEnableMixedMode = true;
105 if((property_get("debug.mdpcomp.mixedmode.disable", property, NULL) > 0) &&
106 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
107 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
108 sEnableMixedMode = false;
109 }
110
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800111 if(property_get("debug.mdpcomp.logs", property, NULL) > 0) {
112 if(atoi(property) != 0)
113 sDebugLogs = true;
114 }
115
Jeykumar Sankaran7d6c4c02014-02-19 12:40:57 -0800116 if(property_get("persist.hwc.partialupdate", property, NULL) > 0) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700117 if((atoi(property) != 0) && ctx->mMDP.panel == MIPI_CMD_PANEL &&
118 qdutils::MDPVersion::getInstance().is8x74v2())
119 sEnablePartialFrameUpdate = true;
120 }
121 ALOGE_IF(isDebug(), "%s: Partial Update applicable?: %d",__FUNCTION__,
122 sEnablePartialFrameUpdate);
123
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800124 sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
Saurabh Shah85234ec2013-04-12 17:09:00 -0700125 if(property_get("debug.mdpcomp.maxpermixer", property, "-1") > 0) {
126 int val = atoi(property);
127 if(val >= 0)
128 sMaxPipesPerMixer = min(val, MAX_PIPES_PER_MIXER);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800129 }
130
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400131 if(ctx->mMDP.panel != MIPI_CMD_PANEL) {
132 // Idle invalidation is not necessary on command mode panels
133 long idle_timeout = DEFAULT_IDLE_TIME;
134 if(property_get("debug.mdpcomp.idletime", property, NULL) > 0) {
135 if(atoi(property) != 0)
136 idle_timeout = atoi(property);
137 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800138
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400139 //create Idle Invalidator only when not disabled through property
140 if(idle_timeout != -1)
141 idleInvalidator = IdleInvalidator::getInstance();
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800142
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400143 if(idleInvalidator == NULL) {
144 ALOGE("%s: failed to instantiate idleInvalidator object",
145 __FUNCTION__);
146 } else {
147 idleInvalidator->init(timeout_handler, ctx, idle_timeout);
148 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800149 }
radhakrishnac9a67412013-09-25 17:40:42 +0530150
151 if((property_get("debug.mdpcomp.4k2kSplit", property, "0") > 0) &&
152 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
153 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
154 sEnable4k2kYUVSplit = true;
155 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700156 return true;
157}
158
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800159void MDPComp::reset(hwc_context_t *ctx) {
160 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700161 mCurrentFrame.reset(numLayers);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800162 ctx->mOverlay->clear(mDpy);
163 ctx->mLayerRotMap[mDpy]->clear();
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700164}
165
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700166void MDPComp::timeout_handler(void *udata) {
167 struct hwc_context_t* ctx = (struct hwc_context_t*)(udata);
168
169 if(!ctx) {
170 ALOGE("%s: received empty data in timer callback", __FUNCTION__);
171 return;
172 }
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -0800173 Locker::Autolock _l(ctx->mDrawLock);
174 // Handle timeout event only if the previous composition is MDP or MIXED.
175 if(!sHandleTimeout) {
176 ALOGD_IF(isDebug(), "%s:Do not handle this timeout", __FUNCTION__);
177 return;
178 }
Jesse Hall3be78d92012-08-21 15:12:23 -0700179 if(!ctx->proc) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700180 ALOGE("%s: HWC proc not registered", __FUNCTION__);
181 return;
182 }
183 sIdleFallBack = true;
184 /* Trigger SF to redraw the current frame */
Jesse Hall3be78d92012-08-21 15:12:23 -0700185 ctx->proc->invalidate(ctx->proc);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700186}
187
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800188void MDPComp::setMDPCompLayerFlags(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800189 hwc_display_contents_1_t* list) {
190 LayerProp *layerProp = ctx->layerProp[mDpy];
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800191
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800192 for(int index = 0; index < ctx->listStats[mDpy].numAppLayers; index++) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800193 hwc_layer_1_t* layer = &(list->hwLayers[index]);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800194 if(!mCurrentFrame.isFBComposed[index]) {
195 layerProp[index].mFlags |= HWC_MDPCOMP;
196 layer->compositionType = HWC_OVERLAY;
197 layer->hints |= HWC_HINT_CLEAR_FB;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800198 } else {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700199 /* Drop the layer when its already present in FB OR when it lies
200 * outside frame's ROI */
201 if(!mCurrentFrame.needsRedraw || mCurrentFrame.drop[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800202 layer->compositionType = HWC_OVERLAY;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700203 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800204 }
205 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700206}
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500207
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800208void MDPComp::setRedraw(hwc_context_t *ctx,
209 hwc_display_contents_1_t* list) {
210 mCurrentFrame.needsRedraw = false;
211 if(!mCachedFrame.isSameFrame(mCurrentFrame, list) ||
212 (list->flags & HWC_GEOMETRY_CHANGED) ||
213 isSkipPresent(ctx, mDpy)) {
214 mCurrentFrame.needsRedraw = true;
215 }
216}
217
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800218MDPComp::FrameInfo::FrameInfo() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700219 reset(0);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800220}
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800221
Saurabh Shahaa236822013-04-24 18:07:26 -0700222void MDPComp::FrameInfo::reset(const int& numLayers) {
223 for(int i = 0 ; i < MAX_PIPES_PER_MIXER && numLayers; i++ ) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800224 if(mdpToLayer[i].pipeInfo) {
225 delete mdpToLayer[i].pipeInfo;
226 mdpToLayer[i].pipeInfo = NULL;
227 //We dont own the rotator
228 mdpToLayer[i].rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800229 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800230 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800231
232 memset(&mdpToLayer, 0, sizeof(mdpToLayer));
233 memset(&layerToMDP, -1, sizeof(layerToMDP));
Saurabh Shahaa236822013-04-24 18:07:26 -0700234 memset(&isFBComposed, 1, sizeof(isFBComposed));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800235
Saurabh Shahaa236822013-04-24 18:07:26 -0700236 layerCount = numLayers;
237 fbCount = numLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800238 mdpCount = 0;
Saurabh Shah2f3895f2013-05-02 10:13:31 -0700239 needsRedraw = true;
Saurabh Shahd53bc5f2014-02-05 10:17:43 -0800240 fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800241}
242
Saurabh Shahaa236822013-04-24 18:07:26 -0700243void MDPComp::FrameInfo::map() {
244 // populate layer and MDP maps
245 int mdpIdx = 0;
246 for(int idx = 0; idx < layerCount; idx++) {
247 if(!isFBComposed[idx]) {
248 mdpToLayer[mdpIdx].listIndex = idx;
249 layerToMDP[idx] = mdpIdx++;
250 }
251 }
252}
253
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800254MDPComp::LayerCache::LayerCache() {
255 reset();
256}
257
258void MDPComp::LayerCache::reset() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700259 memset(&hnd, 0, sizeof(hnd));
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530260 memset(&isFBComposed, true, sizeof(isFBComposed));
261 memset(&drop, false, sizeof(drop));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800262 layerCount = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -0700263}
264
265void MDPComp::LayerCache::cacheAll(hwc_display_contents_1_t* list) {
266 const int numAppLayers = list->numHwLayers - 1;
267 for(int i = 0; i < numAppLayers; i++) {
268 hnd[i] = list->hwLayers[i].handle;
269 }
270}
271
272void MDPComp::LayerCache::updateCounts(const FrameInfo& curFrame) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700273 layerCount = curFrame.layerCount;
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530274 memcpy(&isFBComposed, &curFrame.isFBComposed, sizeof(isFBComposed));
275 memcpy(&drop, &curFrame.drop, sizeof(drop));
276}
277
Jeykumar Sankaran988d3682013-11-15 11:57:16 -0800278bool MDPComp::LayerCache::isSameFrame(const FrameInfo& curFrame,
279 hwc_display_contents_1_t* list) {
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530280 if(layerCount != curFrame.layerCount)
281 return false;
282 for(int i = 0; i < curFrame.layerCount; i++) {
283 if((curFrame.isFBComposed[i] != isFBComposed[i]) ||
284 (curFrame.drop[i] != drop[i])) {
285 return false;
286 }
Jeykumar Sankaran988d3682013-11-15 11:57:16 -0800287 if(curFrame.isFBComposed[i] &&
288 (hnd[i] != list->hwLayers[i].handle)){
289 return false;
290 }
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530291 }
292 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800293}
294
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700295bool MDPComp::isSupportedForMDPComp(hwc_context_t *ctx, hwc_layer_1_t* layer) {
296 private_handle_t *hnd = (private_handle_t *)layer->handle;
297 if((not isYuvBuffer(hnd) and has90Transform(layer)) or
298 (not isValidDimension(ctx,layer))
299 //More conditions here, SKIP, sRGB+Blend etc
300 ) {
301 return false;
302 }
303 return true;
304}
305
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530306bool MDPComp::isValidDimension(hwc_context_t *ctx, hwc_layer_1_t *layer) {
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800307 private_handle_t *hnd = (private_handle_t *)layer->handle;
308
309 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -0700310 if (layer->flags & HWC_COLOR_FILL) {
311 // Color layer
312 return true;
313 }
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800314 ALOGE("%s: layer handle is NULL", __FUNCTION__);
315 return false;
316 }
317
Naseer Ahmede850a802013-09-06 13:12:52 -0400318 //XXX: Investigate doing this with pixel phase on MDSS
Naseer Ahmede77f8082013-10-10 13:42:48 -0400319 if(!isSecureBuffer(hnd) && isNonIntegralSourceCrop(layer->sourceCropf))
Naseer Ahmede850a802013-09-06 13:12:52 -0400320 return false;
321
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 Sankaranb551ce42013-01-10 16:26:48 -0800410
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800411 if(!isEnabled()) {
412 ALOGD_IF(isDebug(),"%s: MDP Comp. not enabled.", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700413 ret = false;
Saurabh Shahd4e65852013-06-17 11:33:53 -0700414 } else if(qdutils::MDPVersion::getInstance().is8x26() &&
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -0800415 ctx->mVideoTransFlag &&
416 isSecondaryConnected(ctx)) {
Saurabh Shahd4e65852013-06-17 11:33:53 -0700417 //1 Padding round to shift pipes across mixers
418 ALOGD_IF(isDebug(),"%s: MDP Comp. video transition padding round",
419 __FUNCTION__);
420 ret = false;
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -0800421 } else if(isSecondaryConfiguring(ctx)) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800422 ALOGD_IF( isDebug(),"%s: External Display connection is pending",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800423 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700424 ret = false;
Saurabh Shahaa236822013-04-24 18:07:26 -0700425 } else if(ctx->isPaddingRound) {
Raj Kamal9ed3d6b2014-02-07 16:15:17 +0530426 ALOGD_IF(isDebug(), "%s: padding round invoked for dpy %d",
427 __FUNCTION__,mDpy);
Saurabh Shahaa236822013-04-24 18:07:26 -0700428 ret = false;
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700429 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700430 return ret;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800431}
432
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800433/*
434 * 1) Identify layers that are not visible in the updating ROI and drop them
435 * from composition.
436 * 2) If we have a scaling layers which needs cropping against generated ROI.
437 * Reset ROI to full resolution.
438 */
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700439bool MDPComp::validateAndApplyROI(hwc_context_t *ctx,
440 hwc_display_contents_1_t* list, hwc_rect_t roi) {
441 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
442
443 if(!isValidRect(roi))
444 return false;
445
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800446 hwc_rect_t visibleRect = roi;
447
448 for(int i = numAppLayers - 1; i >= 0; i--){
449
450 if(!isValidRect(visibleRect)) {
451 mCurrentFrame.drop[i] = true;
452 mCurrentFrame.dropCount++;
Jeykumar Sankaran0b961452014-01-21 17:26:12 -0800453 continue;
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800454 }
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
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800461 hwc_rect_t res = getIntersection(visibleRect, dstRect);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700462
463 int res_w = res.right - res.left;
464 int res_h = res.bottom - res.top;
465 int dst_w = dstRect.right - dstRect.left;
466 int dst_h = dstRect.bottom - dstRect.top;
467
468 if(!isValidRect(res)) {
469 mCurrentFrame.drop[i] = true;
470 mCurrentFrame.dropCount++;
471 }else {
472 /* Reset frame ROI when any layer which needs scaling also needs ROI
473 * cropping */
Jeykumar Sankaran0b961452014-01-21 17:26:12 -0800474 if((res_w != dst_w || res_h != dst_h) && needsScaling (layer)) {
Arpita Banerjeed8965982013-11-08 17:27:33 -0800475 ALOGI("%s: Resetting ROI due to scaling", __FUNCTION__);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700476 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
477 mCurrentFrame.dropCount = 0;
478 return false;
479 }
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800480
Jeykumar Sankaran0b961452014-01-21 17:26:12 -0800481 /* deduct any opaque region from visibleRect */
482 if (layer->blending == HWC_BLENDING_NONE)
483 visibleRect = deductRect(visibleRect, res);
484 }
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700485 }
486 return true;
487}
488
489void MDPComp::generateROI(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
490 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
491
492 if(!sEnablePartialFrameUpdate) {
493 return;
494 }
495
496 if(mDpy || isDisplaySplit(ctx, mDpy)){
497 ALOGE_IF(isDebug(), "%s: ROI not supported for"
498 "the (1) external / virtual display's (2) dual DSI displays",
499 __FUNCTION__);
500 return;
501 }
502
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800503 if(isSkipPresent(ctx, mDpy))
504 return;
505
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700506 if(list->flags & HWC_GEOMETRY_CHANGED)
507 return;
508
509 struct hwc_rect roi = (struct hwc_rect){0, 0, 0, 0};
510 for(int index = 0; index < numAppLayers; index++ ) {
511 if ((mCachedFrame.hnd[index] != list->hwLayers[index].handle) ||
512 isYuvBuffer((private_handle_t *)list->hwLayers[index].handle)) {
513 hwc_rect_t dstRect = list->hwLayers[index].displayFrame;
Arun Kumar K.R91090c72013-10-28 19:40:18 -0700514 hwc_rect_t srcRect = integerizeSourceCrop(
515 list->hwLayers[index].sourceCropf);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700516
517 /* Intersect against display boundaries */
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700518 roi = getUnion(roi, dstRect);
519 }
520 }
521
522 if(!validateAndApplyROI(ctx, list, roi)){
523 roi = (struct hwc_rect) {0, 0,
524 (int)ctx->dpyAttr[mDpy].xres, (int)ctx->dpyAttr[mDpy].yres};
525 }
526
527 ctx->listStats[mDpy].roi.x = roi.left;
528 ctx->listStats[mDpy].roi.y = roi.top;
529 ctx->listStats[mDpy].roi.w = roi.right - roi.left;
530 ctx->listStats[mDpy].roi.h = roi.bottom - roi.top;
531
532 ALOGD_IF(isDebug(),"%s: generated ROI: [%d, %d, %d, %d]", __FUNCTION__,
533 roi.left, roi.top, roi.right, roi.bottom);
534}
535
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800536/* Checks for conditions where all the layers marked for MDP comp cannot be
537 * bypassed. On such conditions we try to bypass atleast YUV layers */
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800538bool MDPComp::tryFullFrame(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800539 hwc_display_contents_1_t* list){
540
Saurabh Shahaa236822013-04-24 18:07:26 -0700541 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Arun Kumar K.R2e2871c2014-01-10 12:47:06 -0800542 int priDispW = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800543
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -0700544 if(sIdleFallBack && !ctx->listStats[mDpy].secureUI) {
Saurabh Shah2d998a92013-05-14 17:55:58 -0700545 ALOGD_IF(isDebug(), "%s: Idle fallback dpy %d",__FUNCTION__, mDpy);
546 return false;
547 }
548
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800549 if(isSkipPresent(ctx, mDpy)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700550 ALOGD_IF(isDebug(),"%s: SKIP present: %d",
551 __FUNCTION__,
552 isSkipPresent(ctx, mDpy));
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800553 return false;
554 }
555
Arun Kumar K.R2e2871c2014-01-10 12:47:06 -0800556 if(mDpy > HWC_DISPLAY_PRIMARY && (priDispW > MAX_DISPLAY_DIM) &&
557 (ctx->dpyAttr[mDpy].xres < MAX_DISPLAY_DIM)) {
558 // Disable MDP comp on Secondary when the primary is highres panel and
559 // the secondary is a normal 1080p, because, MDP comp on secondary under
560 // in such usecase, decimation gets used for downscale and there will be
561 // a quality mismatch when there will be a fallback to GPU comp
562 ALOGD_IF(isDebug(), "%s: Disable MDP Compositon for Secondary Disp",
563 __FUNCTION__);
564 return false;
565 }
566
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800567 // check for action safe flag and downscale mode which requires scaling.
568 if(ctx->dpyAttr[mDpy].mActionSafePresent
569 || ctx->dpyAttr[mDpy].mDownScaleMode) {
570 ALOGD_IF(isDebug(), "%s: Scaling needed for this frame",__FUNCTION__);
571 return false;
572 }
573
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800574 for(int i = 0; i < numAppLayers; ++i) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800575 hwc_layer_1_t* layer = &list->hwLayers[i];
576 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800577
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700578 if(isYuvBuffer(hnd) && has90Transform(layer)) {
579 if(!canUseRotator(ctx, mDpy)) {
580 ALOGD_IF(isDebug(), "%s: Can't use rotator for dpy %d",
581 __FUNCTION__, mDpy);
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700582 return false;
583 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800584 }
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530585
586 //For 8x26 with panel width>1k, if RGB layer needs HFLIP fail mdp comp
587 // may not need it if Gfx pre-rotation can handle all flips & rotations
588 if(qdutils::MDPVersion::getInstance().is8x26() &&
589 (ctx->dpyAttr[mDpy].xres > 1024) &&
590 (layer->transform & HWC_TRANSFORM_FLIP_H) &&
591 (!isYuvBuffer(hnd)))
592 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800593 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700594
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700595 if(ctx->mAD->isDoable()) {
596 return false;
597 }
598
Saurabh Shahaa236822013-04-24 18:07:26 -0700599 //If all above hard conditions are met we can do full or partial MDP comp.
600 bool ret = false;
601 if(fullMDPComp(ctx, list)) {
602 ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700603 } else if(partialMDPComp(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700604 ret = true;
605 }
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530606
Saurabh Shahaa236822013-04-24 18:07:26 -0700607 return ret;
608}
609
610bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700611 //Will benefit presentation / secondary-only layer.
612 if((mDpy > HWC_DISPLAY_PRIMARY) &&
613 (list->numHwLayers - 1) > MAX_SEC_LAYERS) {
614 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
615 return false;
616 }
617
618 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
619 for(int i = 0; i < numAppLayers; i++) {
620 hwc_layer_1_t* layer = &list->hwLayers[i];
621 if(not isSupportedForMDPComp(ctx, layer)) {
622 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",__FUNCTION__);
623 return false;
624 }
Yang Xu9c1eb2b2013-11-26 01:28:13 +0800625
626 //For 8x26, if there is only one layer which needs scale for secondary
627 //while no scale for primary display, DMA pipe is occupied by primary.
628 //If need to fall back to GLES composition, virtual display lacks DMA
629 //pipe and error is reported.
630 if(qdutils::MDPVersion::getInstance().is8x26() &&
631 mDpy >= HWC_DISPLAY_EXTERNAL &&
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530632 qhwc::needsScaling(layer))
Yang Xu9c1eb2b2013-11-26 01:28:13 +0800633 return false;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700634 }
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800635
Saurabh Shahaa236822013-04-24 18:07:26 -0700636 mCurrentFrame.fbCount = 0;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700637 memcpy(&mCurrentFrame.isFBComposed, &mCurrentFrame.drop,
638 sizeof(mCurrentFrame.isFBComposed));
639 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount -
640 mCurrentFrame.dropCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700641
radhakrishnac9a67412013-09-25 17:40:42 +0530642 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800643 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530644 }
645
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800646 if(!postHeuristicsHandling(ctx, list)) {
647 ALOGD_IF(isDebug(), "post heuristic handling failed");
648 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700649 return false;
650 }
651
Saurabh Shahaa236822013-04-24 18:07:26 -0700652 return true;
653}
654
655bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
656{
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700657 if(!sEnableMixedMode) {
658 //Mixed mode is disabled. No need to even try caching.
659 return false;
660 }
661
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700662 bool ret = false;
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800663 if(list->flags & HWC_GEOMETRY_CHANGED) { //Try load based first
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800664 ret = loadBasedComp(ctx, list) or
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800665 cacheBasedComp(ctx, list);
666 } else {
667 ret = cacheBasedComp(ctx, list) or
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800668 loadBasedComp(ctx, list);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700669 }
670
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700671 return ret;
672}
673
674bool MDPComp::cacheBasedComp(hwc_context_t *ctx,
675 hwc_display_contents_1_t* list) {
676 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700677 mCurrentFrame.reset(numAppLayers);
678 updateLayerCache(ctx, list);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700679
680 //If an MDP marked layer is unsupported cannot do partial MDP Comp
681 for(int i = 0; i < numAppLayers; i++) {
682 if(!mCurrentFrame.isFBComposed[i]) {
683 hwc_layer_1_t* layer = &list->hwLayers[i];
684 if(not isSupportedForMDPComp(ctx, layer)) {
685 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",
686 __FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800687 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700688 return false;
689 }
690 }
691 }
692
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700693 updateYUV(ctx, list, false /*secure only*/);
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530694 bool ret = markLayersForCaching(ctx, list); //sets up fbZ also
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700695 if(!ret) {
696 ALOGD_IF(isDebug(),"%s: batching failed, dpy %d",__FUNCTION__, mDpy);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800697 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700698 return false;
699 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700700
701 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700702
radhakrishnac9a67412013-09-25 17:40:42 +0530703 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800704 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530705 }
706
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700707 //Will benefit cases where a video has non-updating background.
708 if((mDpy > HWC_DISPLAY_PRIMARY) and
709 (mdpCount > MAX_SEC_LAYERS)) {
710 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800711 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700712 return false;
713 }
714
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800715 if(!postHeuristicsHandling(ctx, list)) {
716 ALOGD_IF(isDebug(), "post heuristic handling failed");
717 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700718 return false;
719 }
720
Saurabh Shahaa236822013-04-24 18:07:26 -0700721 return true;
722}
723
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800724bool MDPComp::loadBasedComp(hwc_context_t *ctx,
Saurabh Shahb772ae32013-11-18 15:40:02 -0800725 hwc_display_contents_1_t* list) {
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -0800726 if(not isLoadBasedCompDoable(ctx)) {
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800727 return false;
728 }
729
Saurabh Shahb772ae32013-11-18 15:40:02 -0800730 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800731 const int numNonDroppedLayers = numAppLayers - mCurrentFrame.dropCount;
732 const int stagesForMDP = min(sMaxPipesPerMixer,
733 ctx->mOverlay->availablePipes(mDpy, Overlay::MIXER_DEFAULT));
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800734
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800735 int mdpBatchSize = stagesForMDP - 1; //1 stage for FB
736 int fbBatchSize = numNonDroppedLayers - mdpBatchSize;
737 int lastMDPSupportedIndex = numAppLayers;
738 int dropCount = 0;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800739
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800740 //Find the minimum MDP batch size
741 for(int i = 0; i < numAppLayers;i++) {
742 if(mCurrentFrame.drop[i]) {
743 dropCount++;
Jeykumar Sankaran846e2792014-01-23 21:59:58 -0800744 continue;
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800745 }
746 hwc_layer_1_t* layer = &list->hwLayers[i];
747 if(not isSupportedForMDPComp(ctx, layer)) {
748 lastMDPSupportedIndex = i;
749 mdpBatchSize = min(i - dropCount, stagesForMDP - 1);
750 fbBatchSize = numNonDroppedLayers - mdpBatchSize;
Jeykumar Sankaran846e2792014-01-23 21:59:58 -0800751 break;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800752 }
Saurabh Shahb772ae32013-11-18 15:40:02 -0800753 }
754
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800755 ALOGD_IF(isDebug(), "%s:Before optimizing fbBatch, mdpbatch %d, fbbatch %d "
756 "dropped %d", __FUNCTION__, mdpBatchSize, fbBatchSize,
757 mCurrentFrame.dropCount);
758
759 //Start at a point where the fb batch should at least have 2 layers, for
760 //this mode to be justified.
761 while(fbBatchSize < 2) {
762 ++fbBatchSize;
763 --mdpBatchSize;
Jeykumar Sankaran846e2792014-01-23 21:59:58 -0800764 }
Saurabh Shahb772ae32013-11-18 15:40:02 -0800765
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800766 //If there are no layers for MDP, this mode doesnt make sense.
767 if(mdpBatchSize < 1) {
768 ALOGD_IF(isDebug(), "%s: No MDP layers after optimizing for fbBatch",
769 __FUNCTION__);
Saurabh Shahb772ae32013-11-18 15:40:02 -0800770 return false;
771 }
772
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800773 mCurrentFrame.reset(numAppLayers);
774
775 //Try with successively smaller mdp batch sizes until we succeed or reach 1
776 while(mdpBatchSize > 0) {
777 //Mark layers for MDP comp
778 int mdpBatchLeft = mdpBatchSize;
779 for(int i = 0; i < lastMDPSupportedIndex and mdpBatchLeft; i++) {
780 if(mCurrentFrame.drop[i]) {
781 continue;
782 }
783 mCurrentFrame.isFBComposed[i] = false;
784 --mdpBatchLeft;
785 }
786
787 mCurrentFrame.fbZ = mdpBatchSize;
788 mCurrentFrame.fbCount = fbBatchSize;
789 mCurrentFrame.mdpCount = mdpBatchSize;
790
791 ALOGD_IF(isDebug(), "%s:Trying with: mdpbatch %d fbbatch %d dropped %d",
792 __FUNCTION__, mdpBatchSize, fbBatchSize,
793 mCurrentFrame.dropCount);
794
795 if(postHeuristicsHandling(ctx, list)) {
796 ALOGD_IF(isDebug(), "%s: Postheuristics handling succeeded",
797 __FUNCTION__);
798 return true;
799 }
800
801 reset(ctx);
802 --mdpBatchSize;
803 ++fbBatchSize;
804 }
805
806 return false;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800807}
808
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -0800809bool MDPComp::isLoadBasedCompDoable(hwc_context_t *ctx) {
Prabhanjan Kandula3dbbd882013-12-11 14:43:46 +0530810 if(mDpy or isSecurePresent(ctx, mDpy) or
811 isYuvPresent(ctx, mDpy)) {
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700812 return false;
813 }
814 return true;
815}
816
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800817bool MDPComp::tryVideoOnly(hwc_context_t *ctx,
818 hwc_display_contents_1_t* list) {
819 const bool secureOnly = true;
820 return videoOnlyComp(ctx, list, not secureOnly) or
821 videoOnlyComp(ctx, list, secureOnly);
822}
823
824bool MDPComp::videoOnlyComp(hwc_context_t *ctx,
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700825 hwc_display_contents_1_t* list, bool secureOnly) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700826 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700827
Saurabh Shahaa236822013-04-24 18:07:26 -0700828 mCurrentFrame.reset(numAppLayers);
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700829 updateYUV(ctx, list, secureOnly);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700830 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700831
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800832 if(!isYuvPresent(ctx, mDpy) or (mdpCount == 0)) {
833 reset(ctx);
Saurabh Shahaa236822013-04-24 18:07:26 -0700834 return false;
835 }
836
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -0800837 /* Bail out if we are processing only secured video layers
838 * and we dont have any */
839 if(!isSecurePresent(ctx, mDpy) && secureOnly){
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800840 reset(ctx);
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -0800841 return false;
842 }
843
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800844 if(mCurrentFrame.fbCount)
845 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
Saurabh Shah4fdde762013-04-30 18:47:33 -0700846
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800847 if(sEnable4k2kYUVSplit){
848 adjustForSourceSplit(ctx, list);
849 }
850
851 if(!postHeuristicsHandling(ctx, list)) {
852 ALOGD_IF(isDebug(), "post heuristic handling failed");
853 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700854 return false;
855 }
856
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800857 return true;
858}
859
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800860/* Checks for conditions where YUV layers cannot be bypassed */
861bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -0700862 if(isSkipLayer(layer)) {
Saurabh Shahe2474082013-05-15 16:32:13 -0700863 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800864 return false;
865 }
866
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700867 if(layer->transform & HWC_TRANSFORM_ROT_90 && !canUseRotator(ctx,mDpy)) {
868 ALOGD_IF(isDebug(), "%s: no free DMA pipe",__FUNCTION__);
869 return false;
870 }
871
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800872 if(isSecuring(ctx, layer)) {
873 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
874 return false;
875 }
876
Saurabh Shah4fdde762013-04-30 18:47:33 -0700877 if(!isValidDimension(ctx, layer)) {
878 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
879 __FUNCTION__);
880 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800881 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700882
Naseer Ahmeddc61a972013-07-10 17:50:54 -0400883 if(layer->planeAlpha < 0xFF) {
884 ALOGD_IF(isDebug(), "%s: Cannot handle YUV layer with plane alpha\
885 in video only mode",
886 __FUNCTION__);
887 return false;
888 }
889
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800890 return true;
891}
892
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530893/* starts at fromIndex and check for each layer to find
894 * if it it has overlapping with any Updating layer above it in zorder
895 * till the end of the batch. returns true if it finds any intersection */
896bool MDPComp::canPushBatchToTop(const hwc_display_contents_1_t* list,
897 int fromIndex, int toIndex) {
898 for(int i = fromIndex; i < toIndex; i++) {
899 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
900 if(intersectingUpdatingLayers(list, i+1, toIndex, i)) {
901 return false;
902 }
903 }
904 }
905 return true;
906}
907
908/* Checks if given layer at targetLayerIndex has any
909 * intersection with all the updating layers in beween
910 * fromIndex and toIndex. Returns true if it finds intersectiion */
911bool MDPComp::intersectingUpdatingLayers(const hwc_display_contents_1_t* list,
912 int fromIndex, int toIndex, int targetLayerIndex) {
913 for(int i = fromIndex; i <= toIndex; i++) {
914 if(!mCurrentFrame.isFBComposed[i]) {
915 if(areLayersIntersecting(&list->hwLayers[i],
916 &list->hwLayers[targetLayerIndex])) {
917 return true;
918 }
919 }
920 }
921 return false;
922}
923
924int MDPComp::getBatch(hwc_display_contents_1_t* list,
925 int& maxBatchStart, int& maxBatchEnd,
926 int& maxBatchCount) {
927 int i = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530928 int fbZOrder =-1;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -0800929 int droppedLayerCt = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530930 while (i < mCurrentFrame.layerCount) {
931 int batchCount = 0;
932 int batchStart = i;
933 int batchEnd = i;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -0800934 /* Adjust batch Z order with the dropped layers so far */
935 int fbZ = batchStart - droppedLayerCt;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530936 int firstZReverseIndex = -1;
Prabhanjan Kandula0ed2cc92013-12-06 12:39:04 +0530937 int updatingLayersAbove = 0;//Updating layer count in middle of batch
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530938 while(i < mCurrentFrame.layerCount) {
939 if(!mCurrentFrame.isFBComposed[i]) {
940 if(!batchCount) {
941 i++;
942 break;
943 }
944 updatingLayersAbove++;
945 i++;
946 continue;
947 } else {
948 if(mCurrentFrame.drop[i]) {
949 i++;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -0800950 droppedLayerCt++;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530951 continue;
952 } else if(updatingLayersAbove <= 0) {
953 batchCount++;
954 batchEnd = i;
955 i++;
956 continue;
957 } else { //Layer is FBComposed, not a drop & updatingLayer > 0
958
959 // We have a valid updating layer already. If layer-i not
960 // have overlapping with all updating layers in between
961 // batch-start and i, then we can add layer i to batch.
962 if(!intersectingUpdatingLayers(list, batchStart, i-1, i)) {
963 batchCount++;
964 batchEnd = i;
965 i++;
966 continue;
967 } else if(canPushBatchToTop(list, batchStart, i)) {
968 //If All the non-updating layers with in this batch
969 //does not have intersection with the updating layers
970 //above in z-order, then we can safely move the batch to
971 //higher z-order. Increment fbZ as it is moving up.
972 if( firstZReverseIndex < 0) {
973 firstZReverseIndex = i;
974 }
975 batchCount++;
976 batchEnd = i;
977 fbZ += updatingLayersAbove;
978 i++;
979 updatingLayersAbove = 0;
980 continue;
981 } else {
982 //both failed.start the loop again from here.
983 if(firstZReverseIndex >= 0) {
984 i = firstZReverseIndex;
985 }
986 break;
987 }
988 }
989 }
990 }
991 if(batchCount > maxBatchCount) {
992 maxBatchCount = batchCount;
993 maxBatchStart = batchStart;
994 maxBatchEnd = batchEnd;
995 fbZOrder = fbZ;
996 }
997 }
998 return fbZOrder;
999}
1000
1001bool MDPComp::markLayersForCaching(hwc_context_t* ctx,
1002 hwc_display_contents_1_t* list) {
1003 /* Idea is to keep as many non-updating(cached) layers in FB and
1004 * send rest of them through MDP. This is done in 2 steps.
1005 * 1. Find the maximum contiguous batch of non-updating layers.
1006 * 2. See if we can improve this batch size for caching by adding
1007 * opaque layers around the batch, if they don't have
1008 * any overlapping with the updating layers in between.
1009 * NEVER mark an updating layer for caching.
1010 * But cached ones can be marked for MDP */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001011
1012 int maxBatchStart = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001013 int maxBatchEnd = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001014 int maxBatchCount = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301015 int fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001016
Saurabh Shahd53bc5f2014-02-05 10:17:43 -08001017 /* Nothing is cached. No batching needed */
1018 if(mCurrentFrame.fbCount == 0) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001019 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -07001020 }
Saurabh Shahd53bc5f2014-02-05 10:17:43 -08001021
1022 /* No MDP comp layers, try to use other comp modes */
1023 if(mCurrentFrame.mdpCount == 0) {
1024 return false;
Saurabh Shahaa236822013-04-24 18:07:26 -07001025 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001026
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301027 fbZ = getBatch(list, maxBatchStart, maxBatchEnd, maxBatchCount);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001028
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301029 /* reset rest of the layers lying inside ROI for MDP comp */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001030 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001031 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001032 if((i < maxBatchStart || i > maxBatchEnd) &&
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301033 mCurrentFrame.isFBComposed[i]){
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001034 if(!mCurrentFrame.drop[i]){
1035 //If an unsupported layer is being attempted to
1036 //be pulled out we should fail
1037 if(not isSupportedForMDPComp(ctx, layer)) {
1038 return false;
1039 }
1040 mCurrentFrame.isFBComposed[i] = false;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001041 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001042 }
1043 }
1044
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301045 // update the frame data
1046 mCurrentFrame.fbZ = fbZ;
1047 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001048 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001049 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001050
1051 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301052 mCurrentFrame.fbCount);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001053
1054 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001055}
Saurabh Shah85234ec2013-04-12 17:09:00 -07001056
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001057void MDPComp::updateLayerCache(hwc_context_t* ctx,
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001058 hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001059 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001060 int fbCount = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001061
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001062 for(int i = 0; i < numAppLayers; i++) {
1063 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001064 if(!mCurrentFrame.drop[i])
1065 fbCount++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001066 mCurrentFrame.isFBComposed[i] = true;
1067 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -07001068 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001069 }
1070 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001071
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001072 mCurrentFrame.fbCount = fbCount;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001073 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount
1074 - mCurrentFrame.dropCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001075
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001076 ALOGD_IF(isDebug(),"%s: MDP count: %d FB count %d drop count: %d"
1077 ,__FUNCTION__, mCurrentFrame.mdpCount, mCurrentFrame.fbCount,
1078 mCurrentFrame.dropCount);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001079}
1080
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001081void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list,
1082 bool secureOnly) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001083 int nYuvCount = ctx->listStats[mDpy].yuvCount;
1084 for(int index = 0;index < nYuvCount; index++){
1085 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
1086 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
1087
1088 if(!isYUVDoable(ctx, layer)) {
1089 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
1090 mCurrentFrame.isFBComposed[nYuvIndex] = true;
1091 mCurrentFrame.fbCount++;
1092 }
1093 } else {
1094 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001095 private_handle_t *hnd = (private_handle_t *)layer->handle;
1096 if(!secureOnly || isSecureBuffer(hnd)) {
1097 mCurrentFrame.isFBComposed[nYuvIndex] = false;
1098 mCurrentFrame.fbCount--;
1099 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001100 }
1101 }
1102 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001103
1104 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001105 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
1106 ALOGD_IF(isDebug(),"%s: fb count: %d",__FUNCTION__,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001107 mCurrentFrame.fbCount);
1108}
1109
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001110hwc_rect_t MDPComp::getUpdatingFBRect(hwc_context_t *ctx,
1111 hwc_display_contents_1_t* list){
1112 hwc_rect_t fbRect = (struct hwc_rect){0, 0, 0, 0};
1113 hwc_layer_1_t *fbLayer = &list->hwLayers[mCurrentFrame.layerCount];
1114
1115 /* Update only the region of FB needed for composition */
1116 for(int i = 0; i < mCurrentFrame.layerCount; i++ ) {
1117 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
1118 hwc_layer_1_t* layer = &list->hwLayers[i];
1119 hwc_rect_t dst = layer->displayFrame;
1120 fbRect = getUnion(fbRect, dst);
1121 }
1122 }
1123 return fbRect;
1124}
1125
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001126bool MDPComp::postHeuristicsHandling(hwc_context_t *ctx,
1127 hwc_display_contents_1_t* list) {
1128
1129 //Capability checks
1130 if(!resourceCheck(ctx, list)) {
1131 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
1132 return false;
1133 }
1134
1135 //Limitations checks
1136 if(!hwLimitationsCheck(ctx, list)) {
1137 ALOGD_IF(isDebug(), "%s: HW limitations",__FUNCTION__);
1138 return false;
1139 }
1140
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001141 //Configure framebuffer first if applicable
1142 if(mCurrentFrame.fbZ >= 0) {
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001143 hwc_rect_t fbRect = getUpdatingFBRect(ctx, list);
1144 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, fbRect, mCurrentFrame.fbZ))
1145 {
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001146 ALOGD_IF(isDebug(), "%s configure framebuffer failed",
1147 __FUNCTION__);
1148 return false;
1149 }
1150 }
1151
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001152 mCurrentFrame.map();
1153
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001154 if(!allocLayerPipes(ctx, list)) {
1155 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -07001156 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001157 }
1158
1159 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001160 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001161 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001162 int mdpIndex = mCurrentFrame.layerToMDP[index];
1163 hwc_layer_1_t* layer = &list->hwLayers[index];
1164
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301165 //Leave fbZ for framebuffer. CACHE/GLES layers go here.
1166 if(mdpNextZOrder == mCurrentFrame.fbZ) {
1167 mdpNextZOrder++;
1168 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001169 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1170 cur_pipe->zOrder = mdpNextZOrder++;
1171
radhakrishnac9a67412013-09-25 17:40:42 +05301172 private_handle_t *hnd = (private_handle_t *)layer->handle;
1173 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1174 if(configure4k2kYuv(ctx, layer,
1175 mCurrentFrame.mdpToLayer[mdpIndex])
1176 != 0 ){
1177 ALOGD_IF(isDebug(), "%s: Failed to configure split pipes \
1178 for layer %d",__FUNCTION__, index);
1179 return false;
1180 }
1181 else{
1182 mdpNextZOrder++;
1183 }
1184 continue;
1185 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001186 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
1187 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
radhakrishnac9a67412013-09-25 17:40:42 +05301188 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -07001189 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001190 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001191 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001192 }
1193
Saurabh Shaha36be922013-12-16 18:18:39 -08001194 if(!ctx->mOverlay->validateAndSet(mDpy, ctx->dpyAttr[mDpy].fd)) {
1195 ALOGD_IF(isDebug(), "%s: Failed to validate and set overlay for dpy %d"
1196 ,__FUNCTION__, mDpy);
1197 return false;
1198 }
1199
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001200 setRedraw(ctx, list);
Saurabh Shahaa236822013-04-24 18:07:26 -07001201 return true;
1202}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001203
Saurabh Shah173f4242013-11-20 09:50:12 -08001204bool MDPComp::resourceCheck(hwc_context_t *ctx,
1205 hwc_display_contents_1_t *list) {
1206 const bool fbUsed = mCurrentFrame.fbCount;
1207 if(mCurrentFrame.mdpCount > sMaxPipesPerMixer - fbUsed) {
1208 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
1209 return false;
1210 }
Saurabh Shah173f4242013-11-20 09:50:12 -08001211 return true;
1212}
1213
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301214bool MDPComp::hwLimitationsCheck(hwc_context_t* ctx,
1215 hwc_display_contents_1_t* list) {
1216
1217 //A-family hw limitation:
1218 //If a layer need alpha scaling, MDP can not support.
1219 if(ctx->mMDP.version < qdutils::MDSS_V5) {
1220 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1221 if(!mCurrentFrame.isFBComposed[i] &&
1222 isAlphaScaled( &list->hwLayers[i])) {
1223 ALOGD_IF(isDebug(), "%s:frame needs alphaScaling",__FUNCTION__);
1224 return false;
1225 }
1226 }
1227 }
1228
1229 // On 8x26 & 8974 hw, we have a limitation of downscaling+blending.
1230 //If multiple layers requires downscaling and also they are overlapping
1231 //fall back to GPU since MDSS can not handle it.
1232 if(qdutils::MDPVersion::getInstance().is8x74v2() ||
1233 qdutils::MDPVersion::getInstance().is8x26()) {
1234 for(int i = 0; i < mCurrentFrame.layerCount-1; ++i) {
1235 hwc_layer_1_t* botLayer = &list->hwLayers[i];
1236 if(!mCurrentFrame.isFBComposed[i] &&
1237 isDownscaleRequired(botLayer)) {
1238 //if layer-i is marked for MDP and needs downscaling
1239 //check if any MDP layer on top of i & overlaps with layer-i
1240 for(int j = i+1; j < mCurrentFrame.layerCount; ++j) {
1241 hwc_layer_1_t* topLayer = &list->hwLayers[j];
1242 if(!mCurrentFrame.isFBComposed[j] &&
1243 isDownscaleRequired(topLayer)) {
1244 hwc_rect_t r = getIntersection(botLayer->displayFrame,
1245 topLayer->displayFrame);
1246 if(isValidRect(r))
1247 return false;
1248 }
1249 }
1250 }
1251 }
1252 }
1253 return true;
1254}
1255
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001256int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001257 int ret = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -07001258 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001259 MDPVersion& mdpVersion = qdutils::MDPVersion::getInstance();
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -07001260
Raj Kamal9ed3d6b2014-02-07 16:15:17 +05301261 //Do not cache the information for next draw cycle.
1262 if(numLayers > MAX_NUM_APP_LAYERS or (!numLayers)) {
1263 ALOGI("%s: Unsupported layer count for mdp composition",
1264 __FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001265 mCachedFrame.reset();
1266 return -1;
1267 }
1268
Saurabh Shahb39f8152013-08-22 10:21:44 -07001269 //reset old data
1270 mCurrentFrame.reset(numLayers);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001271 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1272 mCurrentFrame.dropCount = 0;
Prabhanjan Kandula088bd892013-07-02 23:47:13 +05301273
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -07001274 // Detect the start of animation and fall back to GPU only once to cache
1275 // all the layers in FB and display FB content untill animation completes.
1276 if(ctx->listStats[mDpy].isDisplayAnimating) {
1277 mCurrentFrame.needsRedraw = false;
1278 if(ctx->mAnimationState[mDpy] == ANIMATION_STOPPED) {
1279 mCurrentFrame.needsRedraw = true;
1280 ctx->mAnimationState[mDpy] = ANIMATION_STARTED;
1281 }
1282 setMDPCompLayerFlags(ctx, list);
1283 mCachedFrame.updateCounts(mCurrentFrame);
1284 ret = -1;
1285 return ret;
1286 } else {
1287 ctx->mAnimationState[mDpy] = ANIMATION_STOPPED;
1288 }
1289
Saurabh Shahb39f8152013-08-22 10:21:44 -07001290 //Hard conditions, if not met, cannot do MDP comp
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001291 if(isFrameDoable(ctx)) {
1292 generateROI(ctx, list);
Saurabh Shahb39f8152013-08-22 10:21:44 -07001293
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001294 if(tryFullFrame(ctx, list) || tryVideoOnly(ctx, list)) {
1295 setMDPCompLayerFlags(ctx, list);
1296 } else {
1297 reset(ctx);
1298 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1299 mCurrentFrame.dropCount = 0;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001300 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001301 }
1302 } else {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001303 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
1304 __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001305 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001306 }
Saurabh Shahb39f8152013-08-22 10:21:44 -07001307
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001308 if(isDebug()) {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001309 ALOGD("GEOMETRY change: %d",
1310 (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001311 android::String8 sDump("");
1312 dump(sDump);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001313 ALOGD("%s",sDump.string());
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001314 }
1315
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001316 mCachedFrame.cacheAll(list);
1317 mCachedFrame.updateCounts(mCurrentFrame);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001318 return ret;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001319}
1320
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001321bool MDPComp::allocSplitVGPipesfor4k2k(hwc_context_t *ctx, int index) {
radhakrishnac9a67412013-09-25 17:40:42 +05301322
1323 bool bRet = true;
radhakrishnac9a67412013-09-25 17:40:42 +05301324 int mdpIndex = mCurrentFrame.layerToMDP[index];
1325 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
1326 info.pipeInfo = new MdpYUVPipeInfo;
1327 info.rot = NULL;
1328 MdpYUVPipeInfo& pipe_info = *(MdpYUVPipeInfo*)info.pipeInfo;
1329 ePipeType type = MDPCOMP_OV_VG;
1330
1331 pipe_info.lIndex = ovutils::OV_INVALID;
1332 pipe_info.rIndex = ovutils::OV_INVALID;
1333
1334 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
1335 if(pipe_info.lIndex == ovutils::OV_INVALID){
1336 bRet = false;
1337 ALOGD_IF(isDebug(),"%s: allocating first VG pipe failed",
1338 __FUNCTION__);
1339 }
1340 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
1341 if(pipe_info.rIndex == ovutils::OV_INVALID){
1342 bRet = false;
1343 ALOGD_IF(isDebug(),"%s: allocating second VG pipe failed",
1344 __FUNCTION__);
1345 }
1346 return bRet;
1347}
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001348//=============MDPCompNonSplit==================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001349
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001350void MDPCompNonSplit::adjustForSourceSplit(hwc_context_t *ctx,
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001351 hwc_display_contents_1_t*) {
radhakrishnac9a67412013-09-25 17:40:42 +05301352 //As we split 4kx2k yuv layer and program to 2 VG pipes
1353 //(if available) increase mdpcount accordingly
1354 mCurrentFrame.mdpCount += ctx->listStats[mDpy].yuv4k2kCount;
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001355
1356 //If 4k2k Yuv layer split is possible, and if
1357 //fbz is above 4k2k layer, increment fb zorder by 1
1358 //as we split 4k2k layer and increment zorder for right half
1359 //of the layer
1360 if(mCurrentFrame.fbZ >= 0) {
1361 int n4k2kYuvCount = ctx->listStats[mDpy].yuv4k2kCount;
1362 for(int index = 0; index < n4k2kYuvCount; index++){
1363 int n4k2kYuvIndex =
1364 ctx->listStats[mDpy].yuv4k2kIndices[index];
1365 if(mCurrentFrame.fbZ > n4k2kYuvIndex){
1366 mCurrentFrame.fbZ += 1;
1367 }
1368 }
1369 }
radhakrishnac9a67412013-09-25 17:40:42 +05301370}
1371
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001372/*
1373 * Configures pipe(s) for MDP composition
1374 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001375int MDPCompNonSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001376 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001377 MdpPipeInfoNonSplit& mdp_info =
1378 *(static_cast<MdpPipeInfoNonSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001379 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
1380 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1381 eIsFg isFg = IS_FG_OFF;
1382 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001383
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001384 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
1385 __FUNCTION__, layer, zOrder, dest);
1386
Saurabh Shah88e4d272013-09-03 13:31:29 -07001387 return configureNonSplit(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001388 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001389}
1390
Saurabh Shah88e4d272013-09-03 13:31:29 -07001391bool MDPCompNonSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001392 hwc_display_contents_1_t* list) {
1393 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001394
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001395 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001396
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001397 hwc_layer_1_t* layer = &list->hwLayers[index];
1398 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301399 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001400 if(allocSplitVGPipesfor4k2k(ctx, index)){
radhakrishnac9a67412013-09-25 17:40:42 +05301401 continue;
1402 }
1403 }
1404
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001405 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001406 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001407 info.pipeInfo = new MdpPipeInfoNonSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08001408 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001409 MdpPipeInfoNonSplit& pipe_info = *(MdpPipeInfoNonSplit*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001410 ePipeType type = MDPCOMP_OV_ANY;
1411
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001412 if(isYuvBuffer(hnd)) {
1413 type = MDPCOMP_OV_VG;
Prabhanjan Kandula47191dc2014-01-22 23:01:45 +05301414 } else if(qdutils::MDPVersion::getInstance().is8x26() &&
1415 (ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres > 1024)) {
1416 if(qhwc::needsScaling(layer))
1417 type = MDPCOMP_OV_RGB;
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301418 } else if(!qhwc::needsScaling(layer)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001419 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
1420 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001421 type = MDPCOMP_OV_DMA;
1422 }
1423
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001424 pipe_info.index = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001425 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001426 ALOGD_IF(isDebug(), "%s: Unable to get pipe type = %d",
1427 __FUNCTION__, (int) type);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001428 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001429 }
1430 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001431 return true;
1432}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001433
radhakrishnac9a67412013-09-25 17:40:42 +05301434int MDPCompNonSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1435 PipeLayerPair& PipeLayerPair) {
1436 MdpYUVPipeInfo& mdp_info =
1437 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1438 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1439 eIsFg isFg = IS_FG_OFF;
1440 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1441 eDest lDest = mdp_info.lIndex;
1442 eDest rDest = mdp_info.rIndex;
1443
1444 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1445 lDest, rDest, &PipeLayerPair.rot);
1446}
1447
Saurabh Shah88e4d272013-09-03 13:31:29 -07001448bool MDPCompNonSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001449
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001450 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001451 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1452 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -08001453 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001454
1455 if(!ctx || !list) {
1456 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001457 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001458 }
1459
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301460 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1461 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1462 return true;
1463 }
1464
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -08001465 // Set the Handle timeout to true for MDP or MIXED composition.
1466 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount) {
1467 sHandleTimeout = true;
1468 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001469
1470 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001471 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001472
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001473 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1474 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001475 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001476 if(mCurrentFrame.isFBComposed[i]) continue;
1477
Naseer Ahmed5b6708a2012-08-02 13:46:08 -07001478 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001479 private_handle_t *hnd = (private_handle_t *)layer->handle;
1480 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001481 if (!(layer->flags & HWC_COLOR_FILL)) {
1482 ALOGE("%s handle null", __FUNCTION__);
1483 return false;
1484 }
1485 // No PLAY for Color layer
1486 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1487 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001488 }
1489
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001490 int mdpIndex = mCurrentFrame.layerToMDP[i];
1491
radhakrishnac9a67412013-09-25 17:40:42 +05301492 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1493 {
1494 MdpYUVPipeInfo& pipe_info =
1495 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1496 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1497 ovutils::eDest indexL = pipe_info.lIndex;
1498 ovutils::eDest indexR = pipe_info.rIndex;
1499 int fd = hnd->fd;
1500 uint32_t offset = hnd->offset;
1501 if(rot) {
1502 rot->queueBuffer(fd, offset);
1503 fd = rot->getDstMemId();
1504 offset = rot->getDstOffset();
1505 }
1506 if(indexL != ovutils::OV_INVALID) {
1507 ovutils::eDest destL = (ovutils::eDest)indexL;
1508 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1509 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1510 if (!ov.queueBuffer(fd, offset, destL)) {
1511 ALOGE("%s: queueBuffer failed for display:%d",
1512 __FUNCTION__, mDpy);
1513 return false;
1514 }
1515 }
1516
1517 if(indexR != ovutils::OV_INVALID) {
1518 ovutils::eDest destR = (ovutils::eDest)indexR;
1519 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1520 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1521 if (!ov.queueBuffer(fd, offset, destR)) {
1522 ALOGE("%s: queueBuffer failed for display:%d",
1523 __FUNCTION__, mDpy);
1524 return false;
1525 }
1526 }
1527 }
1528 else{
1529 MdpPipeInfoNonSplit& pipe_info =
Saurabh Shah88e4d272013-09-03 13:31:29 -07001530 *(MdpPipeInfoNonSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
radhakrishnac9a67412013-09-25 17:40:42 +05301531 ovutils::eDest dest = pipe_info.index;
1532 if(dest == ovutils::OV_INVALID) {
1533 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001534 return false;
radhakrishnac9a67412013-09-25 17:40:42 +05301535 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001536
radhakrishnac9a67412013-09-25 17:40:42 +05301537 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1538 continue;
1539 }
1540
1541 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1542 using pipe: %d", __FUNCTION__, layer,
1543 hnd, dest );
1544
1545 int fd = hnd->fd;
1546 uint32_t offset = hnd->offset;
1547
1548 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1549 if(rot) {
1550 if(!rot->queueBuffer(fd, offset))
1551 return false;
1552 fd = rot->getDstMemId();
1553 offset = rot->getDstOffset();
1554 }
1555
1556 if (!ov.queueBuffer(fd, offset, dest)) {
1557 ALOGE("%s: queueBuffer failed for display:%d ",
1558 __FUNCTION__, mDpy);
1559 return false;
1560 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001561 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001562
1563 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001564 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001565 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001566}
1567
Saurabh Shah88e4d272013-09-03 13:31:29 -07001568//=============MDPCompSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001569
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001570void MDPCompSplit::adjustForSourceSplit(hwc_context_t *ctx,
radhakrishnac9a67412013-09-25 17:40:42 +05301571 hwc_display_contents_1_t* list){
1572 //if 4kx2k yuv layer is totally present in either in left half
1573 //or right half then try splitting the yuv layer to avoid decimation
1574 int n4k2kYuvCount = ctx->listStats[mDpy].yuv4k2kCount;
1575 const int lSplit = getLeftSplit(ctx, mDpy);
1576 for(int index = 0; index < n4k2kYuvCount; index++){
1577 int n4k2kYuvIndex = ctx->listStats[mDpy].yuv4k2kIndices[index];
1578 hwc_layer_1_t* layer = &list->hwLayers[n4k2kYuvIndex];
1579 hwc_rect_t dst = layer->displayFrame;
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001580 if((dst.left > lSplit) || (dst.right < lSplit)) {
radhakrishnac9a67412013-09-25 17:40:42 +05301581 mCurrentFrame.mdpCount += 1;
1582 }
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001583 if(mCurrentFrame.fbZ > n4k2kYuvIndex){
1584 mCurrentFrame.fbZ += 1;
1585 }
radhakrishnac9a67412013-09-25 17:40:42 +05301586 }
1587}
1588
Saurabh Shah88e4d272013-09-03 13:31:29 -07001589bool MDPCompSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
1590 MdpPipeInfoSplit& pipe_info,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001591 ePipeType type) {
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001592 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001593
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001594 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001595 pipe_info.lIndex = ovutils::OV_INVALID;
1596 pipe_info.rIndex = ovutils::OV_INVALID;
1597
1598 if (dst.left < lSplit) {
1599 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_LEFT);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001600 if(pipe_info.lIndex == ovutils::OV_INVALID)
1601 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001602 }
1603
1604 if(dst.right > lSplit) {
1605 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_RIGHT);
1606 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001607 return false;
1608 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001609
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001610 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001611}
1612
Saurabh Shah88e4d272013-09-03 13:31:29 -07001613bool MDPCompSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001614 hwc_display_contents_1_t* list) {
1615 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001616
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001617 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001618
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001619 hwc_layer_1_t* layer = &list->hwLayers[index];
1620 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301621 hwc_rect_t dst = layer->displayFrame;
1622 const int lSplit = getLeftSplit(ctx, mDpy);
1623 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1624 if((dst.left > lSplit)||(dst.right < lSplit)){
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001625 if(allocSplitVGPipesfor4k2k(ctx, index)){
radhakrishnac9a67412013-09-25 17:40:42 +05301626 continue;
1627 }
1628 }
1629 }
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001630 int mdpIndex = mCurrentFrame.layerToMDP[index];
1631 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001632 info.pipeInfo = new MdpPipeInfoSplit;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001633 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001634 MdpPipeInfoSplit& pipe_info = *(MdpPipeInfoSplit*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001635 ePipeType type = MDPCOMP_OV_ANY;
1636
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001637 if(isYuvBuffer(hnd)) {
1638 type = MDPCOMP_OV_VG;
Sushil Chauhan15a2ea62013-09-04 18:28:36 -07001639 } else if(!qhwc::needsScalingWithSplit(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001640 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001641 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001642 type = MDPCOMP_OV_DMA;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001643 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001644
1645 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001646 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type = %d",
1647 __FUNCTION__, (int) type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001648 return false;
1649 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001650 }
1651 return true;
1652}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001653
radhakrishnac9a67412013-09-25 17:40:42 +05301654int MDPCompSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1655 PipeLayerPair& PipeLayerPair) {
1656 const int lSplit = getLeftSplit(ctx, mDpy);
1657 hwc_rect_t dst = layer->displayFrame;
1658 if((dst.left > lSplit)||(dst.right < lSplit)){
1659 MdpYUVPipeInfo& mdp_info =
1660 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1661 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1662 eIsFg isFg = IS_FG_OFF;
1663 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1664 eDest lDest = mdp_info.lIndex;
1665 eDest rDest = mdp_info.rIndex;
1666
1667 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1668 lDest, rDest, &PipeLayerPair.rot);
1669 }
1670 else{
1671 return configure(ctx, layer, PipeLayerPair);
1672 }
1673}
1674
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001675/*
1676 * Configures pipe(s) for MDP composition
1677 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001678int MDPCompSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001679 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001680 MdpPipeInfoSplit& mdp_info =
1681 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001682 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1683 eIsFg isFg = IS_FG_OFF;
1684 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1685 eDest lDest = mdp_info.lIndex;
1686 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001687
1688 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1689 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1690
Saurabh Shah88e4d272013-09-03 13:31:29 -07001691 return configureSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001692 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001693}
1694
Saurabh Shah88e4d272013-09-03 13:31:29 -07001695bool MDPCompSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001696
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001697 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001698 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1699 return true;
1700 }
1701
1702 if(!ctx || !list) {
1703 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001704 return false;
1705 }
1706
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301707 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1708 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1709 return true;
1710 }
1711
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -08001712 // Set the Handle timeout to true for MDP or MIXED composition.
1713 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount) {
1714 sHandleTimeout = true;
1715 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001716
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001717 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001718 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001719
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001720 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1721 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001722 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001723 if(mCurrentFrame.isFBComposed[i]) continue;
1724
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001725 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001726 private_handle_t *hnd = (private_handle_t *)layer->handle;
1727 if(!hnd) {
1728 ALOGE("%s handle null", __FUNCTION__);
1729 return false;
1730 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001731
1732 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1733 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001734 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001735
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001736 int mdpIndex = mCurrentFrame.layerToMDP[i];
1737
radhakrishnac9a67412013-09-25 17:40:42 +05301738 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1739 {
1740 MdpYUVPipeInfo& pipe_info =
1741 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1742 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1743 ovutils::eDest indexL = pipe_info.lIndex;
1744 ovutils::eDest indexR = pipe_info.rIndex;
1745 int fd = hnd->fd;
1746 uint32_t offset = hnd->offset;
1747 if(rot) {
1748 rot->queueBuffer(fd, offset);
1749 fd = rot->getDstMemId();
1750 offset = rot->getDstOffset();
1751 }
1752 if(indexL != ovutils::OV_INVALID) {
1753 ovutils::eDest destL = (ovutils::eDest)indexL;
1754 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1755 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1756 if (!ov.queueBuffer(fd, offset, destL)) {
1757 ALOGE("%s: queueBuffer failed for display:%d",
1758 __FUNCTION__, mDpy);
1759 return false;
1760 }
1761 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001762
radhakrishnac9a67412013-09-25 17:40:42 +05301763 if(indexR != ovutils::OV_INVALID) {
1764 ovutils::eDest destR = (ovutils::eDest)indexR;
1765 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1766 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1767 if (!ov.queueBuffer(fd, offset, destR)) {
1768 ALOGE("%s: queueBuffer failed for display:%d",
1769 __FUNCTION__, mDpy);
1770 return false;
1771 }
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001772 }
1773 }
radhakrishnac9a67412013-09-25 17:40:42 +05301774 else{
1775 MdpPipeInfoSplit& pipe_info =
1776 *(MdpPipeInfoSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1777 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001778
radhakrishnac9a67412013-09-25 17:40:42 +05301779 ovutils::eDest indexL = pipe_info.lIndex;
1780 ovutils::eDest indexR = pipe_info.rIndex;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001781
radhakrishnac9a67412013-09-25 17:40:42 +05301782 int fd = hnd->fd;
1783 int offset = hnd->offset;
1784
1785 if(ctx->mAD->isModeOn()) {
1786 if(ctx->mAD->draw(ctx, fd, offset)) {
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001787 fd = ctx->mAD->getDstFd();
1788 offset = ctx->mAD->getDstOffset();
radhakrishnac9a67412013-09-25 17:40:42 +05301789 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001790 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001791
radhakrishnac9a67412013-09-25 17:40:42 +05301792 if(rot) {
1793 rot->queueBuffer(fd, offset);
1794 fd = rot->getDstMemId();
1795 offset = rot->getDstOffset();
1796 }
1797
1798 //************* play left mixer **********
1799 if(indexL != ovutils::OV_INVALID) {
1800 ovutils::eDest destL = (ovutils::eDest)indexL;
1801 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1802 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1803 if (!ov.queueBuffer(fd, offset, destL)) {
1804 ALOGE("%s: queueBuffer failed for left mixer",
1805 __FUNCTION__);
1806 return false;
1807 }
1808 }
1809
1810 //************* play right mixer **********
1811 if(indexR != ovutils::OV_INVALID) {
1812 ovutils::eDest destR = (ovutils::eDest)indexR;
1813 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1814 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1815 if (!ov.queueBuffer(fd, offset, destR)) {
1816 ALOGE("%s: queueBuffer failed for right mixer",
1817 __FUNCTION__);
1818 return false;
1819 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001820 }
1821 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001822
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001823 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1824 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001825
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001826 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001827}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001828}; //namespace
1829