blob: 06fba61d36cf974b98e42fbe4cc0d3eabbf90e56 [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>
Tatenda Chipeperekwa12f41c92014-09-17 12:55:01 -070022#include "hdmi.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>
Sushil Chauhan4259d872014-05-13 18:17:12 -070029#include "hwc_copybit.h"
Saurabh Shahacf10202013-02-26 10:15:15 -080030
Steve Kondik5164dda2015-11-01 02:51:41 -080031#include <utils/Vector.h>
32
Saurabh Shah85234ec2013-04-12 17:09:00 -070033using namespace overlay;
Saurabh Shahbd2d0832013-04-04 14:33:08 -070034using namespace qdutils;
Saurabh Shahacf10202013-02-26 10:15:15 -080035using namespace overlay::utils;
36namespace ovutils = overlay::utils;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070037
Naseer Ahmed7c958d42012-07-31 18:57:03 -070038namespace qhwc {
39
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080040//==============MDPComp========================================================
41
Naseer Ahmed7c958d42012-07-31 18:57:03 -070042IdleInvalidator *MDPComp::idleInvalidator = NULL;
43bool MDPComp::sIdleFallBack = false;
44bool MDPComp::sDebugLogs = false;
Naseer Ahmed54821fe2012-11-28 18:44:38 -050045bool MDPComp::sEnabled = false;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -070046bool MDPComp::sEnableMixedMode = true;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -070047bool MDPComp::sEnablePartialFrameUpdate = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080048int MDPComp::sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
radhakrishnac9a67412013-09-25 17:40:42 +053049bool MDPComp::sEnable4k2kYUVSplit = false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070050
Saurabh Shah88e4d272013-09-03 13:31:29 -070051MDPComp* MDPComp::getObject(hwc_context_t *ctx, const int& dpy) {
52 if(isDisplaySplit(ctx, dpy)) {
53 return new MDPCompSplit(dpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080054 }
Saurabh Shah88e4d272013-09-03 13:31:29 -070055 return new MDPCompNonSplit(dpy);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080056}
57
Saurabh Shah49c6ec82015-05-21 18:56:58 -070058MDPComp::MDPComp(int dpy) : mDpy(dpy), mModeOn(false), mPrevModeOn(false) {
59};
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080060
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080061void MDPComp::dump(android::String8& buf)
62{
Jeykumar Sankaran3c6bb042013-08-15 14:01:04 -070063 if(mCurrentFrame.layerCount > MAX_NUM_APP_LAYERS)
64 return;
65
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080066 dumpsys_log(buf,"HWC Map for Dpy: %s \n",
Jeykumar Sankaran27dee262013-08-01 17:09:54 -070067 (mDpy == 0) ? "\"PRIMARY\"" :
68 (mDpy == 1) ? "\"EXTERNAL\"" : "\"VIRTUAL\"");
Saurabh Shahe9bc60f2013-08-29 12:58:06 -070069 dumpsys_log(buf,"CURR_FRAME: layerCount:%2d mdpCount:%2d "
70 "fbCount:%2d \n", mCurrentFrame.layerCount,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080071 mCurrentFrame.mdpCount, mCurrentFrame.fbCount);
72 dumpsys_log(buf,"needsFBRedraw:%3s pipesUsed:%2d MaxPipesPerMixer: %d \n",
73 (mCurrentFrame.needsRedraw? "YES" : "NO"),
74 mCurrentFrame.mdpCount, sMaxPipesPerMixer);
75 dumpsys_log(buf," --------------------------------------------- \n");
76 dumpsys_log(buf," listIdx | cached? | mdpIndex | comptype | Z \n");
77 dumpsys_log(buf," --------------------------------------------- \n");
78 for(int index = 0; index < mCurrentFrame.layerCount; index++ )
79 dumpsys_log(buf," %7d | %7s | %8d | %9s | %2d \n",
80 index,
81 (mCurrentFrame.isFBComposed[index] ? "YES" : "NO"),
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -070082 mCurrentFrame.layerToMDP[index],
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080083 (mCurrentFrame.isFBComposed[index] ?
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -070084 (mCurrentFrame.drop[index] ? "DROP" :
85 (mCurrentFrame.needsRedraw ? "GLES" : "CACHE")) : "MDP"),
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080086 (mCurrentFrame.isFBComposed[index] ? mCurrentFrame.fbZ :
87 mCurrentFrame.mdpToLayer[mCurrentFrame.layerToMDP[index]].pipeInfo->zOrder));
88 dumpsys_log(buf,"\n");
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080089}
90
91bool MDPComp::init(hwc_context_t *ctx) {
92
93 if(!ctx) {
94 ALOGE("%s: Invalid hwc context!!",__FUNCTION__);
95 return false;
96 }
97
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080098 char property[PROPERTY_VALUE_MAX];
99
100 sEnabled = false;
101 if((property_get("persist.hwc.mdpcomp.enable", property, NULL) > 0) &&
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800102 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
103 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800104 sEnabled = true;
105 }
106
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700107 sEnableMixedMode = true;
108 if((property_get("debug.mdpcomp.mixedmode.disable", property, NULL) > 0) &&
109 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
110 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
111 sEnableMixedMode = false;
112 }
113
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800114 if(property_get("debug.mdpcomp.logs", property, NULL) > 0) {
115 if(atoi(property) != 0)
116 sDebugLogs = true;
117 }
118
Prabhanjan Kandula30696ee2014-04-21 12:12:38 +0530119 // We read from drivers if panel supports partial updating
120 // and we enable partial update computations if supported.
121 // Keeping this property to disable partial update for
122 // debugging by setting below property to 0 & only 0.
123 property_get("persist.hwc.partialupdate", property, "-1");
124 if((atoi(property) != 0) &&
125 qdutils::MDPVersion::getInstance().isPartialUpdateEnabled()) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700126 sEnablePartialFrameUpdate = true;
127 }
128 ALOGE_IF(isDebug(), "%s: Partial Update applicable?: %d",__FUNCTION__,
129 sEnablePartialFrameUpdate);
130
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800131 sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
Saurabh Shah85234ec2013-04-12 17:09:00 -0700132 if(property_get("debug.mdpcomp.maxpermixer", property, "-1") > 0) {
133 int val = atoi(property);
134 if(val >= 0)
135 sMaxPipesPerMixer = min(val, MAX_PIPES_PER_MIXER);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800136 }
137
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400138 if(ctx->mMDP.panel != MIPI_CMD_PANEL) {
139 // Idle invalidation is not necessary on command mode panels
140 long idle_timeout = DEFAULT_IDLE_TIME;
141 if(property_get("debug.mdpcomp.idletime", property, NULL) > 0) {
142 if(atoi(property) != 0)
143 idle_timeout = atoi(property);
144 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800145
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400146 //create Idle Invalidator only when not disabled through property
147 if(idle_timeout != -1)
148 idleInvalidator = IdleInvalidator::getInstance();
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800149
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400150 if(idleInvalidator == NULL) {
151 ALOGE("%s: failed to instantiate idleInvalidator object",
152 __FUNCTION__);
153 } else {
154 idleInvalidator->init(timeout_handler, ctx, idle_timeout);
155 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800156 }
radhakrishnac9a67412013-09-25 17:40:42 +0530157
158 if((property_get("debug.mdpcomp.4k2kSplit", property, "0") > 0) &&
159 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
160 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
161 sEnable4k2kYUVSplit = true;
162 }
Sushil Chauhan4259d872014-05-13 18:17:12 -0700163
164 if ((property_get("persist.hwc.ptor.enable", property, NULL) > 0) &&
165 ((!strncasecmp(property, "true", PROPERTY_VALUE_MAX )) ||
166 (!strncmp(property, "1", PROPERTY_VALUE_MAX )))) {
167 ctx->mCopyBit[HWC_DISPLAY_PRIMARY] = new CopyBit(ctx,
168 HWC_DISPLAY_PRIMARY);
169 }
170
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700171 return true;
172}
173
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800174void MDPComp::reset(hwc_context_t *ctx) {
175 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700176 mCurrentFrame.reset(numLayers);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800177 ctx->mOverlay->clear(mDpy);
178 ctx->mLayerRotMap[mDpy]->clear();
Dileep Kumar Reddif4051ae2014-12-31 18:01:19 +0530179 ctx->listStats[mDpy].roi.x = 0;
180 ctx->listStats[mDpy].roi.y = 0;
181 ctx->listStats[mDpy].roi.w = (int)ctx->dpyAttr[mDpy].xres;
182 ctx->listStats[mDpy].roi.h = (int)ctx->dpyAttr[mDpy].yres;
183 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
184 mCurrentFrame.dropCount = 0;
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700185}
186
Raj Kamal5166b312014-06-06 13:45:20 +0530187void MDPComp::reset() {
Raj Kamal46dc44f2015-03-16 21:59:25 +0530188 mPrevModeOn = mModeOn;
Raj Kamal5166b312014-06-06 13:45:20 +0530189 mModeOn = false;
190}
191
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700192void MDPComp::timeout_handler(void *udata) {
193 struct hwc_context_t* ctx = (struct hwc_context_t*)(udata);
Raj Kamal46dc44f2015-03-16 21:59:25 +0530194 bool handleTimeout = false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700195
196 if(!ctx) {
197 ALOGE("%s: received empty data in timer callback", __FUNCTION__);
198 return;
199 }
Raj Kamal46dc44f2015-03-16 21:59:25 +0530200
Ramkumar Radhakrishnand8595ae2014-02-06 21:31:29 -0800201 Locker::Autolock _l(ctx->mDrawLock);
Raj Kamal46dc44f2015-03-16 21:59:25 +0530202
203 /* Handle timeout event only if the previous composition
204 on any display is MDP or MIXED*/
205 for(int i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
206 if(ctx->mMDPComp[i])
207 handleTimeout =
208 ctx->mMDPComp[i]->isMDPComp() || handleTimeout;
209 }
210
211 if(!handleTimeout) {
Ramkumar Radhakrishnand8595ae2014-02-06 21:31:29 -0800212 ALOGD_IF(isDebug(), "%s:Do not handle this timeout", __FUNCTION__);
213 return;
214 }
Jesse Hall3be78d92012-08-21 15:12:23 -0700215 if(!ctx->proc) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700216 ALOGE("%s: HWC proc not registered", __FUNCTION__);
217 return;
218 }
219 sIdleFallBack = true;
220 /* Trigger SF to redraw the current frame */
Jesse Hall3be78d92012-08-21 15:12:23 -0700221 ctx->proc->invalidate(ctx->proc);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700222}
223
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800224void MDPComp::setMDPCompLayerFlags(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800225 hwc_display_contents_1_t* list) {
226 LayerProp *layerProp = ctx->layerProp[mDpy];
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800227
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800228 for(int index = 0; index < ctx->listStats[mDpy].numAppLayers; index++) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800229 hwc_layer_1_t* layer = &(list->hwLayers[index]);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800230 if(!mCurrentFrame.isFBComposed[index]) {
231 layerProp[index].mFlags |= HWC_MDPCOMP;
232 layer->compositionType = HWC_OVERLAY;
233 layer->hints |= HWC_HINT_CLEAR_FB;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800234 } else {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700235 /* Drop the layer when its already present in FB OR when it lies
236 * outside frame's ROI */
237 if(!mCurrentFrame.needsRedraw || mCurrentFrame.drop[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800238 layer->compositionType = HWC_OVERLAY;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700239 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800240 }
241 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700242}
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500243
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800244void MDPComp::setRedraw(hwc_context_t *ctx,
245 hwc_display_contents_1_t* list) {
246 mCurrentFrame.needsRedraw = false;
247 if(!mCachedFrame.isSameFrame(mCurrentFrame, list) ||
248 (list->flags & HWC_GEOMETRY_CHANGED) ||
249 isSkipPresent(ctx, mDpy)) {
250 mCurrentFrame.needsRedraw = true;
251 }
252}
253
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800254MDPComp::FrameInfo::FrameInfo() {
Saurabh Shah8d09ba32014-08-14 10:11:36 -0700255 memset(&mdpToLayer, 0, sizeof(mdpToLayer));
Saurabh Shahaa236822013-04-24 18:07:26 -0700256 reset(0);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800257}
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800258
Saurabh Shahaa236822013-04-24 18:07:26 -0700259void MDPComp::FrameInfo::reset(const int& numLayers) {
Saurabh Shah8d09ba32014-08-14 10:11:36 -0700260 for(int i = 0; i < MAX_PIPES_PER_MIXER; i++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800261 if(mdpToLayer[i].pipeInfo) {
262 delete mdpToLayer[i].pipeInfo;
263 mdpToLayer[i].pipeInfo = NULL;
264 //We dont own the rotator
265 mdpToLayer[i].rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800266 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800267 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800268
269 memset(&mdpToLayer, 0, sizeof(mdpToLayer));
270 memset(&layerToMDP, -1, sizeof(layerToMDP));
Saurabh Shahaa236822013-04-24 18:07:26 -0700271 memset(&isFBComposed, 1, sizeof(isFBComposed));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800272
Saurabh Shahaa236822013-04-24 18:07:26 -0700273 layerCount = numLayers;
274 fbCount = numLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800275 mdpCount = 0;
Saurabh Shah2f3895f2013-05-02 10:13:31 -0700276 needsRedraw = true;
Saurabh Shahce188452014-02-05 10:17:43 -0800277 fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800278}
279
Saurabh Shahaa236822013-04-24 18:07:26 -0700280void MDPComp::FrameInfo::map() {
281 // populate layer and MDP maps
282 int mdpIdx = 0;
283 for(int idx = 0; idx < layerCount; idx++) {
284 if(!isFBComposed[idx]) {
285 mdpToLayer[mdpIdx].listIndex = idx;
286 layerToMDP[idx] = mdpIdx++;
287 }
288 }
289}
290
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800291MDPComp::LayerCache::LayerCache() {
292 reset();
293}
294
295void MDPComp::LayerCache::reset() {
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530296 memset(&isFBComposed, true, sizeof(isFBComposed));
297 memset(&drop, false, sizeof(drop));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800298 layerCount = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -0700299}
300
Saurabh Shahaa236822013-04-24 18:07:26 -0700301void MDPComp::LayerCache::updateCounts(const FrameInfo& curFrame) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700302 layerCount = curFrame.layerCount;
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530303 memcpy(&isFBComposed, &curFrame.isFBComposed, sizeof(isFBComposed));
304 memcpy(&drop, &curFrame.drop, sizeof(drop));
305}
306
Jeykumar Sankaran988d3682013-11-15 11:57:16 -0800307bool MDPComp::LayerCache::isSameFrame(const FrameInfo& curFrame,
308 hwc_display_contents_1_t* list) {
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530309 if(layerCount != curFrame.layerCount)
310 return false;
311 for(int i = 0; i < curFrame.layerCount; i++) {
312 if((curFrame.isFBComposed[i] != isFBComposed[i]) ||
313 (curFrame.drop[i] != drop[i])) {
314 return false;
315 }
Arun Kumar K.Rdff18b82015-07-27 16:00:02 +0530316 hwc_layer_1_t const* layer = &list->hwLayers[i];
317 if(curFrame.isFBComposed[i] && layerUpdating(layer)) {
Jeykumar Sankaran988d3682013-11-15 11:57:16 -0800318 return false;
319 }
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530320 }
321 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800322}
323
Raj Kamal46dc44f2015-03-16 21:59:25 +0530324bool MDPComp::LayerCache::isSameFrame(hwc_context_t *ctx, int dpy,
325 hwc_display_contents_1_t* list) {
326
327 if(layerCount != ctx->listStats[dpy].numAppLayers)
328 return false;
329
330 if((list->flags & HWC_GEOMETRY_CHANGED) ||
331 isSkipPresent(ctx, dpy)) {
332 return false;
333 }
334
335 for(int i = 0; i < layerCount; i++) {
Arun Kumar K.Rdff18b82015-07-27 16:00:02 +0530336 hwc_layer_1_t const* layer = &list->hwLayers[i];
337 if(layerUpdating(layer))
Raj Kamal46dc44f2015-03-16 21:59:25 +0530338 return false;
339 }
340
341 return true;
342}
343
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700344bool MDPComp::isSupportedForMDPComp(hwc_context_t *ctx, hwc_layer_1_t* layer) {
345 private_handle_t *hnd = (private_handle_t *)layer->handle;
346 if((not isYuvBuffer(hnd) and has90Transform(layer)) or
Raj Kamal81cab692014-10-28 15:31:35 +0530347 (not isValidDimension(ctx,layer)) ||
348 isSkipLayer(layer)) {
349 //More conditions here, sRGB+Blend etc
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700350 return false;
351 }
352 return true;
353}
354
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530355bool MDPComp::isValidDimension(hwc_context_t *ctx, hwc_layer_1_t *layer) {
Saurabh Shah4fdde762013-04-30 18:47:33 -0700356 const int dpy = HWC_DISPLAY_PRIMARY;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800357 private_handle_t *hnd = (private_handle_t *)layer->handle;
358
359 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -0700360 if (layer->flags & HWC_COLOR_FILL) {
361 // Color layer
362 return true;
363 }
Steve Kondikc44491f2015-04-14 23:31:16 -0700364 ALOGD_IF(isDebug(), "%s: layer handle is NULL", __FUNCTION__);
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800365 return false;
366 }
367
Naseer Ahmede850a802013-09-06 13:12:52 -0400368 //XXX: Investigate doing this with pixel phase on MDSS
Naseer Ahmede77f8082013-10-10 13:42:48 -0400369 if(!isSecureBuffer(hnd) && isNonIntegralSourceCrop(layer->sourceCropf))
Naseer Ahmede850a802013-09-06 13:12:52 -0400370 return false;
371
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800372 int hw_w = ctx->dpyAttr[mDpy].xres;
373 int hw_h = ctx->dpyAttr[mDpy].yres;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800374
Saurabh Shah62e1d732013-09-17 10:44:05 -0700375 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700376 hwc_rect_t dst = layer->displayFrame;
Saurabh Shah4fdde762013-04-30 18:47:33 -0700377 int crop_w = crop.right - crop.left;
378 int crop_h = crop.bottom - crop.top;
379 int dst_w = dst.right - dst.left;
380 int dst_h = dst.bottom - dst.top;
381 float w_dscale = ceilf((float)crop_w / (float)dst_w);
382 float h_dscale = ceilf((float)crop_h / (float)dst_h);
383
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800384 /* Workaround for MDP HW limitation in DSI command mode panels where
385 * FPS will not go beyond 30 if buffers on RGB pipes are of width or height
386 * less than 5 pixels
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530387 * There also is a HW limilation in MDP, minimum block size is 2x2
388 * Fallback to GPU if height is less than 2.
389 */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800390 if((crop_w < 5)||(crop_h < 5))
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800391 return false;
392
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800393 if((w_dscale > 1.0f) || (h_dscale > 1.0f)) {
394 const uint32_t downscale =
Saurabh Shah4fdde762013-04-30 18:47:33 -0700395 qdutils::MDPVersion::getInstance().getMaxMDPDownscale();
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800396 if(ctx->mMDP.version >= qdutils::MDSS_V5) {
397 /* Workaround for downscales larger than 4x.
398 * Will be removed once decimator block is enabled for MDSS
399 */
400 if(!qdutils::MDPVersion::getInstance().supportsDecimation()) {
401 if(crop_w > MAX_DISPLAY_DIM || w_dscale > downscale ||
402 h_dscale > downscale)
403 return false;
404 } else {
405 if(w_dscale > 64 || h_dscale > 64)
406 return false;
407 }
408 } else { //A-family
409 if(w_dscale > downscale || h_dscale > downscale)
Saurabh Shah4fdde762013-04-30 18:47:33 -0700410 return false;
411 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700412 }
413
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800414 return true;
415}
416
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700417ovutils::eDest MDPComp::getMdpPipe(hwc_context_t *ctx, ePipeType type,
418 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800419 overlay::Overlay& ov = *ctx->mOverlay;
420 ovutils::eDest mdp_pipe = ovutils::OV_INVALID;
421
422 switch(type) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800423 case MDPCOMP_OV_DMA:
Baldev Sahu5cbb5462014-11-12 15:35:13 +0530424 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_DMA, mDpy, mixer,
425 Overlay::FORMAT_RGB);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800426 if(mdp_pipe != ovutils::OV_INVALID) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800427 return mdp_pipe;
428 }
429 case MDPCOMP_OV_ANY:
430 case MDPCOMP_OV_RGB:
Baldev Sahu5cbb5462014-11-12 15:35:13 +0530431 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy, mixer,
432 Overlay::FORMAT_RGB);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800433 if(mdp_pipe != ovutils::OV_INVALID) {
434 return mdp_pipe;
435 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800436
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800437 if(type == MDPCOMP_OV_RGB) {
438 //Requested only for RGB pipe
439 break;
440 }
441 case MDPCOMP_OV_VG:
Baldev Sahu5cbb5462014-11-12 15:35:13 +0530442 return ov.nextPipe(ovutils::OV_MDP_PIPE_VG, mDpy, mixer,
443 Overlay::FORMAT_YUV);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800444 default:
445 ALOGE("%s: Invalid pipe type",__FUNCTION__);
446 return ovutils::OV_INVALID;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800447 };
448 return ovutils::OV_INVALID;
449}
450
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800451bool MDPComp::isFrameDoable(hwc_context_t *ctx) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700452 bool ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700453 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800454
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800455 if(!isEnabled()) {
456 ALOGD_IF(isDebug(),"%s: MDP Comp. not enabled.", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700457 ret = false;
Saurabh Shahd4e65852013-06-17 11:33:53 -0700458 } else if(qdutils::MDPVersion::getInstance().is8x26() &&
Tatenda Chipeperekwa75a41812014-04-01 12:54:13 -0700459 ctx->mVideoTransFlag &&
460 isSecondaryConnected(ctx)) {
Saurabh Shahd4e65852013-06-17 11:33:53 -0700461 //1 Padding round to shift pipes across mixers
462 ALOGD_IF(isDebug(),"%s: MDP Comp. video transition padding round",
463 __FUNCTION__);
464 ret = false;
Raj Kamal2a18d6d2015-03-17 20:53:14 +0530465 } else if(qdutils::MDPVersion::getInstance().is8x26() &&
466 !mDpy && isSecondaryAnimating(ctx) &&
467 (isYuvPresent(ctx,HWC_DISPLAY_EXTERNAL) ||
468 isYuvPresent(ctx,HWC_DISPLAY_VIRTUAL))) {
469 ALOGD_IF(isDebug(),"%s: Display animation in progress",
470 __FUNCTION__);
471 ret = false;
Ramkumar Radhakrishnan0f952612013-12-30 23:11:27 -0800472 } else if(isSecondaryConfiguring(ctx)) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800473 ALOGD_IF( isDebug(),"%s: External Display connection is pending",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800474 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700475 ret = false;
Saurabh Shahaa236822013-04-24 18:07:26 -0700476 } else if(ctx->isPaddingRound) {
Raj Kamalfc5b9222014-02-07 16:15:17 +0530477 ALOGD_IF(isDebug(), "%s: padding round invoked for dpy %d",
478 __FUNCTION__,mDpy);
Saurabh Shahaa236822013-04-24 18:07:26 -0700479 ret = false;
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700480 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700481 return ret;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800482}
483
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800484/*
485 * 1) Identify layers that are not visible in the updating ROI and drop them
486 * from composition.
487 * 2) If we have a scaling layers which needs cropping against generated ROI.
488 * Reset ROI to full resolution.
489 */
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700490bool MDPComp::validateAndApplyROI(hwc_context_t *ctx,
491 hwc_display_contents_1_t* list, hwc_rect_t roi) {
492 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
493
494 if(!isValidRect(roi))
495 return false;
496
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800497 hwc_rect_t visibleRect = roi;
498
499 for(int i = numAppLayers - 1; i >= 0; i--){
500
501 if(!isValidRect(visibleRect)) {
502 mCurrentFrame.drop[i] = true;
503 mCurrentFrame.dropCount++;
Jeykumar Sankaran65bc8022014-01-21 17:26:12 -0800504 continue;
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800505 }
506
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700507 const hwc_layer_1_t* layer = &list->hwLayers[i];
508
509 hwc_rect_t dstRect = layer->displayFrame;
Arun Kumar K.R91090c72013-10-28 19:40:18 -0700510 hwc_rect_t srcRect = integerizeSourceCrop(layer->sourceCropf);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700511 int transform = layer->transform;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700512
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800513 hwc_rect_t res = getIntersection(visibleRect, dstRect);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700514
515 int res_w = res.right - res.left;
516 int res_h = res.bottom - res.top;
517 int dst_w = dstRect.right - dstRect.left;
518 int dst_h = dstRect.bottom - dstRect.top;
519
520 if(!isValidRect(res)) {
521 mCurrentFrame.drop[i] = true;
522 mCurrentFrame.dropCount++;
523 }else {
524 /* Reset frame ROI when any layer which needs scaling also needs ROI
525 * cropping */
Jeykumar Sankaran65bc8022014-01-21 17:26:12 -0800526 if((res_w != dst_w || res_h != dst_h) && needsScaling (layer)) {
Arpita Banerjeed8965982013-11-08 17:27:33 -0800527 ALOGI("%s: Resetting ROI due to scaling", __FUNCTION__);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700528 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
529 mCurrentFrame.dropCount = 0;
530 return false;
531 }
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800532
Jeykumar Sankaran65bc8022014-01-21 17:26:12 -0800533 /* deduct any opaque region from visibleRect */
radhakrishna31858932014-11-03 13:19:27 +0530534 if (layer->blending == HWC_BLENDING_NONE &&
535 layer->planeAlpha == 0xFF)
Jeykumar Sankaran65bc8022014-01-21 17:26:12 -0800536 visibleRect = deductRect(visibleRect, res);
537 }
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700538 }
539 return true;
540}
541
Jeykumar Sankaran4d76a382014-02-26 18:26:58 -0800542bool MDPComp::canDoPartialUpdate(hwc_context_t *ctx,
543 hwc_display_contents_1_t* list){
544 if(!qdutils::MDPVersion::getInstance().isPartialUpdateEnabled() || mDpy ||
545 isSkipPresent(ctx, mDpy) || (list->flags & HWC_GEOMETRY_CHANGED)||
546 isDisplaySplit(ctx, mDpy)) {
547 return false;
548 }
Jeykumar Sankaranb582a0e2014-07-02 12:23:09 -0700549
550 if(ctx->listStats[mDpy].secureUI)
551 return false;
552
Jeykumar Sankaran4d76a382014-02-26 18:26:58 -0800553 return true;
554}
555
Arun Kumar K.Rdff18b82015-07-27 16:00:02 +0530556/* Calculate ROI for the frame by accounting all the layer's dispalyFrame which
557 * are updating. If DirtyRegion is applicable, calculate it by accounting all
558 * the changing layer's dirtyRegion. */
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700559void MDPComp::generateROI(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
560 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
561
Jeykumar Sankaran4d76a382014-02-26 18:26:58 -0800562 if(!canDoPartialUpdate(ctx, list))
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700563 return;
564
565 struct hwc_rect roi = (struct hwc_rect){0, 0, 0, 0};
Arun Kumar K.Rdff18b82015-07-27 16:00:02 +0530566 hwc_rect fullFrame = (struct hwc_rect) {0, 0,(int)ctx->dpyAttr[mDpy].xres,
567 (int)ctx->dpyAttr[mDpy].yres};
568
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700569 for(int index = 0; index < numAppLayers; index++ ) {
Jeykumar Sankaran4d76a382014-02-26 18:26:58 -0800570 hwc_layer_1_t* layer = &list->hwLayers[index];
Arun Kumar K.Rdff18b82015-07-27 16:00:02 +0530571 if (layerUpdating(layer) ||
Jeykumar Sankaran78893422014-05-07 16:23:14 -0700572 isYuvBuffer((private_handle_t *)layer->handle)) {
Arun Kumar K.Rdff18b82015-07-27 16:00:02 +0530573 hwc_rect_t updatingRect = layer->displayFrame;
574 if(!needsScaling(layer) && !layer->transform &&
575 (!isYuvBuffer((private_handle_t *)layer->handle)))
Jeykumar Sankaran78893422014-05-07 16:23:14 -0700576 {
Arun Kumar K.Rdff18b82015-07-27 16:00:02 +0530577 updatingRect = calculateDirtyRect(layer, fullFrame);
Jeykumar Sankaran78893422014-05-07 16:23:14 -0700578 }
Arun Kumar K.Rdff18b82015-07-27 16:00:02 +0530579
Jeykumar Sankaran4d76a382014-02-26 18:26:58 -0800580 roi = getUnion(roi, updatingRect);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700581 }
582 }
583
Jeykumar Sankaran4d76a382014-02-26 18:26:58 -0800584 // Align ROI coordinates to panel restrictions
585 roi = sanitizeROI(roi, fullFrame);
586
587 if(!validateAndApplyROI(ctx, list, roi))
588 roi = fullFrame;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700589
590 ctx->listStats[mDpy].roi.x = roi.left;
591 ctx->listStats[mDpy].roi.y = roi.top;
592 ctx->listStats[mDpy].roi.w = roi.right - roi.left;
593 ctx->listStats[mDpy].roi.h = roi.bottom - roi.top;
594
595 ALOGD_IF(isDebug(),"%s: generated ROI: [%d, %d, %d, %d]", __FUNCTION__,
596 roi.left, roi.top, roi.right, roi.bottom);
597}
598
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800599/* Checks for conditions where all the layers marked for MDP comp cannot be
600 * bypassed. On such conditions we try to bypass atleast YUV layers */
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800601bool MDPComp::tryFullFrame(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800602 hwc_display_contents_1_t* list){
603
Saurabh Shahaa236822013-04-24 18:07:26 -0700604 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800605
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -0700606 if(sIdleFallBack && !ctx->listStats[mDpy].secureUI) {
Saurabh Shah2d998a92013-05-14 17:55:58 -0700607 ALOGD_IF(isDebug(), "%s: Idle fallback dpy %d",__FUNCTION__, mDpy);
608 return false;
609 }
610
Raj Kamal2a18d6d2015-03-17 20:53:14 +0530611 if(!mDpy && isSecondaryAnimating(ctx) &&
612 (isYuvPresent(ctx,HWC_DISPLAY_EXTERNAL) ||
613 isYuvPresent(ctx,HWC_DISPLAY_VIRTUAL)) ) {
614 ALOGD_IF(isDebug(),"%s: Display animation in progress",
615 __FUNCTION__);
616 return false;
617 }
618
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800619 // check for action safe flag and downscale mode which requires scaling.
620 if(ctx->dpyAttr[mDpy].mActionSafePresent
621 || ctx->dpyAttr[mDpy].mDownScaleMode) {
622 ALOGD_IF(isDebug(), "%s: Scaling needed for this frame",__FUNCTION__);
623 return false;
624 }
625
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800626 for(int i = 0; i < numAppLayers; ++i) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800627 hwc_layer_1_t* layer = &list->hwLayers[i];
628 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800629
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700630 if(isYuvBuffer(hnd) && has90Transform(layer)) {
631 if(!canUseRotator(ctx, mDpy)) {
632 ALOGD_IF(isDebug(), "%s: Can't use rotator for dpy %d",
633 __FUNCTION__, mDpy);
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700634 return false;
635 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800636 }
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530637
638 //For 8x26 with panel width>1k, if RGB layer needs HFLIP fail mdp comp
639 // may not need it if Gfx pre-rotation can handle all flips & rotations
Sushil Chauhand8ef93f2014-03-20 11:08:41 -0700640 int transform = (layer->flags & HWC_COLOR_FILL) ? 0 : layer->transform;
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530641 if(qdutils::MDPVersion::getInstance().is8x26() &&
642 (ctx->dpyAttr[mDpy].xres > 1024) &&
Sushil Chauhand8ef93f2014-03-20 11:08:41 -0700643 (transform & HWC_TRANSFORM_FLIP_H) &&
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530644 (!isYuvBuffer(hnd)))
645 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800646 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700647
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700648 if(ctx->mAD->isDoable()) {
649 return false;
650 }
651
Saurabh Shahaa236822013-04-24 18:07:26 -0700652 //If all above hard conditions are met we can do full or partial MDP comp.
653 bool ret = false;
654 if(fullMDPComp(ctx, list)) {
655 ret = true;
Sushil Chauhan4259d872014-05-13 18:17:12 -0700656 } else if(fullMDPCompWithPTOR(ctx, list)) {
657 ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700658 } else if(partialMDPComp(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700659 ret = true;
660 }
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530661
Saurabh Shahaa236822013-04-24 18:07:26 -0700662 return ret;
663}
664
665bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700666 //Will benefit presentation / secondary-only layer.
667 if((mDpy > HWC_DISPLAY_PRIMARY) &&
668 (list->numHwLayers - 1) > MAX_SEC_LAYERS) {
669 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
670 return false;
671 }
672
673 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
674 for(int i = 0; i < numAppLayers; i++) {
675 hwc_layer_1_t* layer = &list->hwLayers[i];
676 if(not isSupportedForMDPComp(ctx, layer)) {
677 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",__FUNCTION__);
678 return false;
679 }
680 }
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800681
Saurabh Shahaa236822013-04-24 18:07:26 -0700682 mCurrentFrame.fbCount = 0;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700683 memcpy(&mCurrentFrame.isFBComposed, &mCurrentFrame.drop,
684 sizeof(mCurrentFrame.isFBComposed));
685 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount -
686 mCurrentFrame.dropCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700687
radhakrishnac9a67412013-09-25 17:40:42 +0530688 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800689 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530690 }
691
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800692 if(!postHeuristicsHandling(ctx, list)) {
693 ALOGD_IF(isDebug(), "post heuristic handling failed");
694 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700695 return false;
696 }
697
Saurabh Shahaa236822013-04-24 18:07:26 -0700698 return true;
699}
700
Sushil Chauhan4259d872014-05-13 18:17:12 -0700701/* Full MDP Composition with Peripheral Tiny Overlap Removal.
702 * MDP bandwidth limitations can be avoided, if the overlap region
703 * covered by the smallest layer at a higher z-order, gets composed
704 * by Copybit on a render buffer, which can be queued to MDP.
705 */
706bool MDPComp::fullMDPCompWithPTOR(hwc_context_t *ctx,
707 hwc_display_contents_1_t* list) {
708
709 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
710 const int stagesForMDP = min(sMaxPipesPerMixer,
711 ctx->mOverlay->availablePipes(mDpy, Overlay::MIXER_DEFAULT));
712
713 // Hard checks where we cannot use this mode
Justin Philipb1906f72014-10-30 14:14:19 +0530714 if (mDpy || !ctx->mCopyBit[mDpy] || !ctx->mIsPTOREnabled) {
Sushil Chauhan4259d872014-05-13 18:17:12 -0700715 ALOGD_IF(isDebug(), "%s: Feature not supported!", __FUNCTION__);
716 return false;
717 }
718
719 // Frame level checks
720 if ((numAppLayers > stagesForMDP) || isSkipPresent(ctx, mDpy) ||
721 isYuvPresent(ctx, mDpy) || mCurrentFrame.dropCount ||
722 isSecurePresent(ctx, mDpy)) {
723 ALOGD_IF(isDebug(), "%s: Frame not supported!", __FUNCTION__);
724 return false;
725 }
Arun Kumar K.Rbad65ab2014-06-03 11:54:10 -0700726 // MDP comp checks
727 for(int i = 0; i < numAppLayers; i++) {
Sushil Chauhan4259d872014-05-13 18:17:12 -0700728 hwc_layer_1_t* layer = &list->hwLayers[i];
Arun Kumar K.Rbad65ab2014-06-03 11:54:10 -0700729 if(not isSupportedForMDPComp(ctx, layer)) {
730 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",__FUNCTION__);
731 return false;
Sushil Chauhan4259d872014-05-13 18:17:12 -0700732 }
733 }
734
Sushil Chauhan4259d872014-05-13 18:17:12 -0700735 /* We cannot use this composition mode, if:
736 1. A below layer needs scaling.
737 2. Overlap is not peripheral to display.
738 3. Overlap or a below layer has 90 degree transform.
Arun Kumar K.Rbad65ab2014-06-03 11:54:10 -0700739 4. Overlap area > (1/3 * FrameBuffer) area, based on Perf inputs.
Sushil Chauhan4259d872014-05-13 18:17:12 -0700740 */
741
Arun Kumar K.Rbad65ab2014-06-03 11:54:10 -0700742 int minLayerIndex[MAX_PTOR_LAYERS] = { -1, -1};
743 hwc_rect_t overlapRect[MAX_PTOR_LAYERS];
744 memset(overlapRect, 0, sizeof(overlapRect));
745 int layerPixelCount, minPixelCount = 0;
746 int numPTORLayersFound = 0;
747 for (int i = numAppLayers-1; (i >= 0 &&
748 numPTORLayersFound < MAX_PTOR_LAYERS); i--) {
Sushil Chauhan4259d872014-05-13 18:17:12 -0700749 hwc_layer_1_t* layer = &list->hwLayers[i];
Arun Kumar K.Rbad65ab2014-06-03 11:54:10 -0700750 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Sushil Chauhan4259d872014-05-13 18:17:12 -0700751 hwc_rect_t dispFrame = layer->displayFrame;
Arun Kumar K.Rbad65ab2014-06-03 11:54:10 -0700752 layerPixelCount = (crop.right - crop.left) * (crop.bottom - crop.top);
753 // PTOR layer should be peripheral and cannot have transform
754 if (!isPeripheral(dispFrame, ctx->mViewFrame[mDpy]) ||
755 has90Transform(layer)) {
756 continue;
757 }
758 if((3 * (layerPixelCount + minPixelCount)) >
759 ((int)ctx->dpyAttr[mDpy].xres * (int)ctx->dpyAttr[mDpy].yres)) {
760 // Overlap area > (1/3 * FrameBuffer) area, based on Perf inputs.
761 continue;
762 }
Sushil Chauhane1474bf2014-07-25 12:20:23 -0700763 bool found = false;
Arun Kumar K.Rbad65ab2014-06-03 11:54:10 -0700764 for (int j = i-1; j >= 0; j--) {
765 // Check if the layers below this layer qualifies for PTOR comp
766 hwc_layer_1_t* layer = &list->hwLayers[j];
767 hwc_rect_t disFrame = layer->displayFrame;
Sushil Chauhane1474bf2014-07-25 12:20:23 -0700768 // Layer below PTOR is intersecting and has 90 degree transform or
Arun Kumar K.Rbad65ab2014-06-03 11:54:10 -0700769 // needs scaling cannot be supported.
Sushil Chauhane1474bf2014-07-25 12:20:23 -0700770 if (isValidRect(getIntersection(dispFrame, disFrame))) {
771 if (has90Transform(layer) || needsScaling(layer)) {
772 found = false;
773 break;
774 }
775 found = true;
Arun Kumar K.Rbad65ab2014-06-03 11:54:10 -0700776 }
777 }
778 // Store the minLayer Index
779 if(found) {
780 minLayerIndex[numPTORLayersFound] = i;
781 overlapRect[numPTORLayersFound] = list->hwLayers[i].displayFrame;
782 minPixelCount += layerPixelCount;
783 numPTORLayersFound++;
Sushil Chauhan4259d872014-05-13 18:17:12 -0700784 }
785 }
786
Arun Kumar K.Rbad65ab2014-06-03 11:54:10 -0700787 // No overlap layers
788 if (!numPTORLayersFound)
789 return false;
Sushil Chauhan4259d872014-05-13 18:17:12 -0700790
Arun Kumar K.Rbad65ab2014-06-03 11:54:10 -0700791 // Store the displayFrame and the sourceCrops of the layers
792 hwc_rect_t displayFrame[numAppLayers];
793 hwc_rect_t sourceCrop[numAppLayers];
794 for(int i = 0; i < numAppLayers; i++) {
Sushil Chauhan4259d872014-05-13 18:17:12 -0700795 hwc_layer_1_t* layer = &list->hwLayers[i];
796 displayFrame[i] = layer->displayFrame;
797 sourceCrop[i] = integerizeSourceCrop(layer->sourceCropf);
Arun Kumar K.Rbad65ab2014-06-03 11:54:10 -0700798 }
Sushil Chauhan4259d872014-05-13 18:17:12 -0700799
Prabhanjan Kandulabb1f6be2014-09-04 21:50:35 +0530800 /**
801 * It's possible that 2 PTOR layers might have overlapping.
802 * In such case, remove the intersection(again if peripheral)
803 * from the lower PTOR layer to avoid overlapping.
804 * If intersection is not on peripheral then compromise
805 * by reducing number of PTOR layers.
806 **/
807 hwc_rect_t commonRect = getIntersection(overlapRect[0], overlapRect[1]);
808 if(isValidRect(commonRect)) {
809 overlapRect[1] = deductRect(overlapRect[1], commonRect);
810 list->hwLayers[minLayerIndex[1]].displayFrame = overlapRect[1];
811 }
812
813 ctx->mPtorInfo.count = numPTORLayersFound;
814 for(int i = 0; i < MAX_PTOR_LAYERS; i++) {
815 ctx->mPtorInfo.layerIndex[i] = minLayerIndex[i];
816 }
817
818 if (!ctx->mCopyBit[mDpy]->prepareOverlap(ctx, list)) {
819 // reset PTOR
820 ctx->mPtorInfo.count = 0;
821 if(isValidRect(commonRect)) {
822 // If PTORs are intersecting restore displayframe of PTOR[1]
823 // before returning, as we have modified it above.
824 list->hwLayers[minLayerIndex[1]].displayFrame =
825 displayFrame[minLayerIndex[1]];
826 }
827 return false;
828 }
Sushil Chauhane1474bf2014-07-25 12:20:23 -0700829 private_handle_t *renderBuf = ctx->mCopyBit[mDpy]->getCurrentRenderBuffer();
Steve Kondik5164dda2015-11-01 02:51:41 -0800830 Vector<Whf> layerWhf; // To store w,h,f of PTOR layers
Sushil Chauhane1474bf2014-07-25 12:20:23 -0700831
Xu Yang645cb1f2014-07-30 21:57:21 +0800832 // Store the blending mode, planeAlpha, and transform of PTOR layers
833 int32_t blending[numPTORLayersFound];
834 uint8_t planeAlpha[numPTORLayersFound];
835 uint32_t transform[numPTORLayersFound];
836
Arun Kumar K.Rbad65ab2014-06-03 11:54:10 -0700837 for(int j = 0; j < numPTORLayersFound; j++) {
838 int index = ctx->mPtorInfo.layerIndex[j];
Sushil Chauhane1474bf2014-07-25 12:20:23 -0700839
840 // Update src crop of PTOR layer
841 hwc_layer_1_t* layer = &list->hwLayers[index];
842 layer->sourceCropf.left = (float)ctx->mPtorInfo.displayFrame[j].left;
843 layer->sourceCropf.top = (float)ctx->mPtorInfo.displayFrame[j].top;
844 layer->sourceCropf.right = (float)ctx->mPtorInfo.displayFrame[j].right;
845 layer->sourceCropf.bottom =(float)ctx->mPtorInfo.displayFrame[j].bottom;
846
847 // Store & update w, h, format of PTOR layer
848 private_handle_t *hnd = (private_handle_t *)layer->handle;
849 Whf whf(hnd->width, hnd->height, hnd->format, hnd->size);
Steve Kondik5164dda2015-11-01 02:51:41 -0800850 layerWhf.insertAt(whf, j);
Sushil Chauhane1474bf2014-07-25 12:20:23 -0700851 hnd->width = renderBuf->width;
852 hnd->height = renderBuf->height;
853 hnd->format = renderBuf->format;
854
Xu Yang645cb1f2014-07-30 21:57:21 +0800855 // Store & update blending mode, planeAlpha and transform of PTOR layer
856 blending[j] = layer->blending;
857 planeAlpha[j] = layer->planeAlpha;
858 transform[j] = layer->transform;
859 layer->blending = HWC_BLENDING_NONE;
860 layer->planeAlpha = 0xFF;
861 layer->transform = 0;
862
Arun Kumar K.Rbad65ab2014-06-03 11:54:10 -0700863 // Remove overlap from crop & displayFrame of below layers
864 for (int i = 0; i < index && index !=-1; i++) {
Sushil Chauhane1474bf2014-07-25 12:20:23 -0700865 layer = &list->hwLayers[i];
Arun Kumar K.Rbad65ab2014-06-03 11:54:10 -0700866 if(!isValidRect(getIntersection(layer->displayFrame,
867 overlapRect[j]))) {
868 continue;
869 }
870 // Update layer attributes
871 hwc_rect_t srcCrop = integerizeSourceCrop(layer->sourceCropf);
872 hwc_rect_t destRect = deductRect(layer->displayFrame,
Dileep Kumar Reddicc32af02014-11-11 16:03:03 +0530873 getIntersection(layer->displayFrame, overlapRect[j]));
Arun Kumar K.Rbad65ab2014-06-03 11:54:10 -0700874 qhwc::calculate_crop_rects(srcCrop, layer->displayFrame, destRect,
875 layer->transform);
876 layer->sourceCropf.left = (float)srcCrop.left;
877 layer->sourceCropf.top = (float)srcCrop.top;
878 layer->sourceCropf.right = (float)srcCrop.right;
879 layer->sourceCropf.bottom = (float)srcCrop.bottom;
880 }
Sushil Chauhan4259d872014-05-13 18:17:12 -0700881 }
882
883 mCurrentFrame.mdpCount = numAppLayers;
884 mCurrentFrame.fbCount = 0;
885 mCurrentFrame.fbZ = -1;
886
Dileep Kumar Reddicc32af02014-11-11 16:03:03 +0530887 for (int j = 0; j < numAppLayers; j++) {
888 if(isValidRect(list->hwLayers[j].displayFrame)) {
889 mCurrentFrame.isFBComposed[j] = false;
890 } else {
891 mCurrentFrame.mdpCount--;
892 mCurrentFrame.drop[j] = true;
893 }
894 }
Sushil Chauhan4259d872014-05-13 18:17:12 -0700895
896 bool result = postHeuristicsHandling(ctx, list);
897
898 // Restore layer attributes
Arun Kumar K.Rbad65ab2014-06-03 11:54:10 -0700899 for(int i = 0; i < numAppLayers; i++) {
Sushil Chauhan4259d872014-05-13 18:17:12 -0700900 hwc_layer_1_t* layer = &list->hwLayers[i];
901 layer->displayFrame = displayFrame[i];
902 layer->sourceCropf.left = (float)sourceCrop[i].left;
903 layer->sourceCropf.top = (float)sourceCrop[i].top;
904 layer->sourceCropf.right = (float)sourceCrop[i].right;
905 layer->sourceCropf.bottom = (float)sourceCrop[i].bottom;
906 }
907
Xu Yang645cb1f2014-07-30 21:57:21 +0800908 // Restore w,h,f, blending attributes, and transform of PTOR layers
Sushil Chauhane1474bf2014-07-25 12:20:23 -0700909 for (int i = 0; i < numPTORLayersFound; i++) {
910 int idx = ctx->mPtorInfo.layerIndex[i];
Xu Yang645cb1f2014-07-30 21:57:21 +0800911 hwc_layer_1_t* layer = &list->hwLayers[idx];
Sushil Chauhane1474bf2014-07-25 12:20:23 -0700912 private_handle_t *hnd = (private_handle_t *)list->hwLayers[idx].handle;
Steve Kondik5164dda2015-11-01 02:51:41 -0800913 Whf whf = layerWhf.itemAt(i);
914 hnd->width = whf.w;
915 hnd->height = whf.h;
916 hnd->format = whf.format;
Xu Yang645cb1f2014-07-30 21:57:21 +0800917 layer->blending = blending[i];
918 layer->planeAlpha = planeAlpha[i];
919 layer->transform = transform[i];
Sushil Chauhane1474bf2014-07-25 12:20:23 -0700920 }
921
Sushil Chauhan4259d872014-05-13 18:17:12 -0700922 if (!result) {
Arun Kumar K.Rbad65ab2014-06-03 11:54:10 -0700923 // reset PTOR
924 ctx->mPtorInfo.count = 0;
Sushil Chauhan4259d872014-05-13 18:17:12 -0700925 reset(ctx);
Arun Kumar K.Rbad65ab2014-06-03 11:54:10 -0700926 } else {
927 ALOGD_IF(isDebug(), "%s: PTOR Indexes: %d and %d", __FUNCTION__,
928 ctx->mPtorInfo.layerIndex[0], ctx->mPtorInfo.layerIndex[1]);
Sushil Chauhan4259d872014-05-13 18:17:12 -0700929 }
930
Arun Kumar K.Rbad65ab2014-06-03 11:54:10 -0700931 ALOGD_IF(isDebug(), "%s: Postheuristics %s!", __FUNCTION__,
932 (result ? "successful" : "failed"));
Sushil Chauhan4259d872014-05-13 18:17:12 -0700933 return result;
934}
935
Saurabh Shahaa236822013-04-24 18:07:26 -0700936bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
937{
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700938 if(!sEnableMixedMode) {
939 //Mixed mode is disabled. No need to even try caching.
940 return false;
941 }
942
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700943 bool ret = false;
Raj Kamal81cab692014-10-28 15:31:35 +0530944 if(isSkipPresent(ctx, mDpy) or list->flags & HWC_GEOMETRY_CHANGED) {
945 //Try load based first
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800946 ret = loadBasedComp(ctx, list) or
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800947 cacheBasedComp(ctx, list);
948 } else {
949 ret = cacheBasedComp(ctx, list) or
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800950 loadBasedComp(ctx, list);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700951 }
952
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700953 return ret;
954}
955
956bool MDPComp::cacheBasedComp(hwc_context_t *ctx,
957 hwc_display_contents_1_t* list) {
958 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700959 mCurrentFrame.reset(numAppLayers);
Arun Kumar K.R1d4bbd22014-08-20 17:14:26 -0700960 updateLayerCache(ctx, list, mCurrentFrame);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700961
962 //If an MDP marked layer is unsupported cannot do partial MDP Comp
963 for(int i = 0; i < numAppLayers; i++) {
964 if(!mCurrentFrame.isFBComposed[i]) {
965 hwc_layer_1_t* layer = &list->hwLayers[i];
966 if(not isSupportedForMDPComp(ctx, layer)) {
967 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",
968 __FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800969 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700970 return false;
971 }
972 }
973 }
974
Arun Kumar K.R1d4bbd22014-08-20 17:14:26 -0700975 updateYUV(ctx, list, false /*secure only*/, mCurrentFrame);
976
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530977 bool ret = markLayersForCaching(ctx, list); //sets up fbZ also
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700978 if(!ret) {
979 ALOGD_IF(isDebug(),"%s: batching failed, dpy %d",__FUNCTION__, mDpy);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800980 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700981 return false;
982 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700983
984 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700985
radhakrishnac9a67412013-09-25 17:40:42 +0530986 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800987 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530988 }
989
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700990 //Will benefit cases where a video has non-updating background.
991 if((mDpy > HWC_DISPLAY_PRIMARY) and
992 (mdpCount > MAX_SEC_LAYERS)) {
993 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800994 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700995 return false;
996 }
997
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800998 if(!postHeuristicsHandling(ctx, list)) {
999 ALOGD_IF(isDebug(), "post heuristic handling failed");
1000 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001001 return false;
1002 }
1003
Saurabh Shahaa236822013-04-24 18:07:26 -07001004 return true;
1005}
1006
Saurabh Shah6e8ab772014-02-20 16:18:45 -08001007bool MDPComp::loadBasedComp(hwc_context_t *ctx,
Saurabh Shahb772ae32013-11-18 15:40:02 -08001008 hwc_display_contents_1_t* list) {
Saurabh Shahf2de00f2013-12-11 17:52:53 -08001009 if(not isLoadBasedCompDoable(ctx, list)) {
1010 return false;
1011 }
1012
Saurabh Shahb772ae32013-11-18 15:40:02 -08001013 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shah6e8ab772014-02-20 16:18:45 -08001014 const int numNonDroppedLayers = numAppLayers - mCurrentFrame.dropCount;
1015 const int stagesForMDP = min(sMaxPipesPerMixer,
1016 ctx->mOverlay->availablePipes(mDpy, Overlay::MIXER_DEFAULT));
Saurabh Shahf2de00f2013-12-11 17:52:53 -08001017
Saurabh Shah6e8ab772014-02-20 16:18:45 -08001018 int mdpBatchSize = stagesForMDP - 1; //1 stage for FB
1019 int fbBatchSize = numNonDroppedLayers - mdpBatchSize;
1020 int lastMDPSupportedIndex = numAppLayers;
1021 int dropCount = 0;
Saurabh Shahb772ae32013-11-18 15:40:02 -08001022
Saurabh Shah6e8ab772014-02-20 16:18:45 -08001023 //Find the minimum MDP batch size
1024 for(int i = 0; i < numAppLayers;i++) {
1025 if(mCurrentFrame.drop[i]) {
1026 dropCount++;
Jeykumar Sankaran6279bc32014-01-23 21:59:58 -08001027 continue;
Saurabh Shah6e8ab772014-02-20 16:18:45 -08001028 }
1029 hwc_layer_1_t* layer = &list->hwLayers[i];
1030 if(not isSupportedForMDPComp(ctx, layer)) {
1031 lastMDPSupportedIndex = i;
1032 mdpBatchSize = min(i - dropCount, stagesForMDP - 1);
1033 fbBatchSize = numNonDroppedLayers - mdpBatchSize;
Jeykumar Sankaran6279bc32014-01-23 21:59:58 -08001034 break;
Saurabh Shahb772ae32013-11-18 15:40:02 -08001035 }
Saurabh Shahb772ae32013-11-18 15:40:02 -08001036 }
1037
Saurabh Shah6e8ab772014-02-20 16:18:45 -08001038 ALOGD_IF(isDebug(), "%s:Before optimizing fbBatch, mdpbatch %d, fbbatch %d "
1039 "dropped %d", __FUNCTION__, mdpBatchSize, fbBatchSize,
1040 mCurrentFrame.dropCount);
1041
1042 //Start at a point where the fb batch should at least have 2 layers, for
1043 //this mode to be justified.
1044 while(fbBatchSize < 2) {
1045 ++fbBatchSize;
1046 --mdpBatchSize;
Jeykumar Sankaran6279bc32014-01-23 21:59:58 -08001047 }
Saurabh Shahb772ae32013-11-18 15:40:02 -08001048
Saurabh Shah6e8ab772014-02-20 16:18:45 -08001049 //If there are no layers for MDP, this mode doesnt make sense.
1050 if(mdpBatchSize < 1) {
1051 ALOGD_IF(isDebug(), "%s: No MDP layers after optimizing for fbBatch",
1052 __FUNCTION__);
Saurabh Shahb772ae32013-11-18 15:40:02 -08001053 return false;
1054 }
1055
Saurabh Shah6e8ab772014-02-20 16:18:45 -08001056 mCurrentFrame.reset(numAppLayers);
1057
1058 //Try with successively smaller mdp batch sizes until we succeed or reach 1
1059 while(mdpBatchSize > 0) {
1060 //Mark layers for MDP comp
1061 int mdpBatchLeft = mdpBatchSize;
1062 for(int i = 0; i < lastMDPSupportedIndex and mdpBatchLeft; i++) {
1063 if(mCurrentFrame.drop[i]) {
1064 continue;
1065 }
1066 mCurrentFrame.isFBComposed[i] = false;
1067 --mdpBatchLeft;
1068 }
1069
1070 mCurrentFrame.fbZ = mdpBatchSize;
1071 mCurrentFrame.fbCount = fbBatchSize;
1072 mCurrentFrame.mdpCount = mdpBatchSize;
1073
1074 ALOGD_IF(isDebug(), "%s:Trying with: mdpbatch %d fbbatch %d dropped %d",
1075 __FUNCTION__, mdpBatchSize, fbBatchSize,
1076 mCurrentFrame.dropCount);
1077
1078 if(postHeuristicsHandling(ctx, list)) {
1079 ALOGD_IF(isDebug(), "%s: Postheuristics handling succeeded",
1080 __FUNCTION__);
1081 return true;
1082 }
1083
1084 reset(ctx);
1085 --mdpBatchSize;
1086 ++fbBatchSize;
1087 }
1088
1089 return false;
Saurabh Shahb772ae32013-11-18 15:40:02 -08001090}
1091
Saurabh Shah8028e3b2013-10-15 12:27:59 -07001092bool MDPComp::isLoadBasedCompDoable(hwc_context_t *ctx,
Steve Kondik5164dda2015-11-01 02:51:41 -08001093 hwc_display_contents_1_t* /*list*/) {
Jeykumar Sankaranfaada4f2015-05-14 11:54:58 -07001094 if(mDpy or isSecurePresent(ctx, mDpy)) {
Saurabh Shah8028e3b2013-10-15 12:27:59 -07001095 return false;
1096 }
1097 return true;
1098}
1099
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001100bool MDPComp::tryVideoOnly(hwc_context_t *ctx,
1101 hwc_display_contents_1_t* list) {
1102 const bool secureOnly = true;
1103 return videoOnlyComp(ctx, list, not secureOnly) or
1104 videoOnlyComp(ctx, list, secureOnly);
1105}
1106
1107bool MDPComp::videoOnlyComp(hwc_context_t *ctx,
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001108 hwc_display_contents_1_t* list, bool secureOnly) {
Saurabh Shahaa236822013-04-24 18:07:26 -07001109 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001110
Saurabh Shahaa236822013-04-24 18:07:26 -07001111 mCurrentFrame.reset(numAppLayers);
Arun Kumar K.R1d4bbd22014-08-20 17:14:26 -07001112 updateYUV(ctx, list, secureOnly, mCurrentFrame);
Saurabh Shah4fdde762013-04-30 18:47:33 -07001113 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001114
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001115 if(!isYuvPresent(ctx, mDpy) or (mdpCount == 0)) {
1116 reset(ctx);
Saurabh Shahaa236822013-04-24 18:07:26 -07001117 return false;
1118 }
1119
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -08001120 /* Bail out if we are processing only secured video layers
1121 * and we dont have any */
1122 if(!isSecurePresent(ctx, mDpy) && secureOnly){
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001123 reset(ctx);
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -08001124 return false;
1125 }
1126
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001127 if(mCurrentFrame.fbCount)
1128 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
Saurabh Shah4fdde762013-04-30 18:47:33 -07001129
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001130 if(sEnable4k2kYUVSplit){
1131 adjustForSourceSplit(ctx, list);
1132 }
1133
1134 if(!postHeuristicsHandling(ctx, list)) {
1135 ALOGD_IF(isDebug(), "post heuristic handling failed");
Justin Philipc9907322015-01-06 11:55:12 +05301136 if(errno == ENOBUFS) {
1137 ALOGD_IF(isDebug(), "SMP Allocation failed");
1138 //On SMP allocation failure in video only comp add padding round
1139 ctx->isPaddingRound = true;
1140 }
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001141 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001142 return false;
1143 }
1144
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001145 return true;
1146}
1147
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001148/* Checks for conditions where YUV layers cannot be bypassed */
1149bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -07001150 if(isSkipLayer(layer)) {
Saurabh Shahe2474082013-05-15 16:32:13 -07001151 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001152 return false;
1153 }
1154
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -07001155 if(layer->transform & HWC_TRANSFORM_ROT_90 && !canUseRotator(ctx,mDpy)) {
1156 ALOGD_IF(isDebug(), "%s: no free DMA pipe",__FUNCTION__);
1157 return false;
1158 }
1159
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001160 if(isSecuring(ctx, layer)) {
1161 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
1162 return false;
1163 }
1164
Saurabh Shah4fdde762013-04-30 18:47:33 -07001165 if(!isValidDimension(ctx, layer)) {
1166 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
1167 __FUNCTION__);
1168 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001169 }
Saurabh Shah4fdde762013-04-30 18:47:33 -07001170
Naseer Ahmeddc61a972013-07-10 17:50:54 -04001171 if(layer->planeAlpha < 0xFF) {
1172 ALOGD_IF(isDebug(), "%s: Cannot handle YUV layer with plane alpha\
1173 in video only mode",
1174 __FUNCTION__);
1175 return false;
1176 }
1177
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001178 return true;
1179}
1180
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301181/* starts at fromIndex and check for each layer to find
1182 * if it it has overlapping with any Updating layer above it in zorder
1183 * till the end of the batch. returns true if it finds any intersection */
1184bool MDPComp::canPushBatchToTop(const hwc_display_contents_1_t* list,
1185 int fromIndex, int toIndex) {
1186 for(int i = fromIndex; i < toIndex; i++) {
1187 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
1188 if(intersectingUpdatingLayers(list, i+1, toIndex, i)) {
1189 return false;
1190 }
1191 }
1192 }
1193 return true;
1194}
1195
1196/* Checks if given layer at targetLayerIndex has any
1197 * intersection with all the updating layers in beween
1198 * fromIndex and toIndex. Returns true if it finds intersectiion */
1199bool MDPComp::intersectingUpdatingLayers(const hwc_display_contents_1_t* list,
1200 int fromIndex, int toIndex, int targetLayerIndex) {
1201 for(int i = fromIndex; i <= toIndex; i++) {
1202 if(!mCurrentFrame.isFBComposed[i]) {
1203 if(areLayersIntersecting(&list->hwLayers[i],
1204 &list->hwLayers[targetLayerIndex])) {
1205 return true;
1206 }
1207 }
1208 }
1209 return false;
1210}
1211
1212int MDPComp::getBatch(hwc_display_contents_1_t* list,
1213 int& maxBatchStart, int& maxBatchEnd,
1214 int& maxBatchCount) {
1215 int i = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301216 int fbZOrder =-1;
Jeykumar Sankaran5a495da2014-01-20 12:25:32 -08001217 int droppedLayerCt = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301218 while (i < mCurrentFrame.layerCount) {
1219 int batchCount = 0;
1220 int batchStart = i;
1221 int batchEnd = i;
Jeykumar Sankaran5a495da2014-01-20 12:25:32 -08001222 /* Adjust batch Z order with the dropped layers so far */
1223 int fbZ = batchStart - droppedLayerCt;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301224 int firstZReverseIndex = -1;
Prabhanjan Kandula0ed2cc92013-12-06 12:39:04 +05301225 int updatingLayersAbove = 0;//Updating layer count in middle of batch
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301226 while(i < mCurrentFrame.layerCount) {
1227 if(!mCurrentFrame.isFBComposed[i]) {
1228 if(!batchCount) {
1229 i++;
1230 break;
1231 }
1232 updatingLayersAbove++;
1233 i++;
1234 continue;
1235 } else {
1236 if(mCurrentFrame.drop[i]) {
1237 i++;
Jeykumar Sankaran5a495da2014-01-20 12:25:32 -08001238 droppedLayerCt++;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301239 continue;
1240 } else if(updatingLayersAbove <= 0) {
1241 batchCount++;
1242 batchEnd = i;
1243 i++;
1244 continue;
1245 } else { //Layer is FBComposed, not a drop & updatingLayer > 0
1246
1247 // We have a valid updating layer already. If layer-i not
1248 // have overlapping with all updating layers in between
1249 // batch-start and i, then we can add layer i to batch.
1250 if(!intersectingUpdatingLayers(list, batchStart, i-1, i)) {
1251 batchCount++;
1252 batchEnd = i;
1253 i++;
1254 continue;
1255 } else if(canPushBatchToTop(list, batchStart, i)) {
1256 //If All the non-updating layers with in this batch
1257 //does not have intersection with the updating layers
1258 //above in z-order, then we can safely move the batch to
1259 //higher z-order. Increment fbZ as it is moving up.
1260 if( firstZReverseIndex < 0) {
1261 firstZReverseIndex = i;
1262 }
1263 batchCount++;
1264 batchEnd = i;
1265 fbZ += updatingLayersAbove;
1266 i++;
1267 updatingLayersAbove = 0;
1268 continue;
1269 } else {
1270 //both failed.start the loop again from here.
1271 if(firstZReverseIndex >= 0) {
1272 i = firstZReverseIndex;
1273 }
1274 break;
1275 }
1276 }
1277 }
1278 }
1279 if(batchCount > maxBatchCount) {
1280 maxBatchCount = batchCount;
1281 maxBatchStart = batchStart;
1282 maxBatchEnd = batchEnd;
1283 fbZOrder = fbZ;
1284 }
1285 }
1286 return fbZOrder;
1287}
1288
1289bool MDPComp::markLayersForCaching(hwc_context_t* ctx,
1290 hwc_display_contents_1_t* list) {
1291 /* Idea is to keep as many non-updating(cached) layers in FB and
1292 * send rest of them through MDP. This is done in 2 steps.
1293 * 1. Find the maximum contiguous batch of non-updating layers.
1294 * 2. See if we can improve this batch size for caching by adding
1295 * opaque layers around the batch, if they don't have
1296 * any overlapping with the updating layers in between.
1297 * NEVER mark an updating layer for caching.
1298 * But cached ones can be marked for MDP */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001299
1300 int maxBatchStart = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001301 int maxBatchEnd = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001302 int maxBatchCount = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301303 int fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001304
Saurabh Shahce188452014-02-05 10:17:43 -08001305 /* Nothing is cached. No batching needed */
1306 if(mCurrentFrame.fbCount == 0) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001307 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -07001308 }
Saurabh Shahce188452014-02-05 10:17:43 -08001309
1310 /* No MDP comp layers, try to use other comp modes */
1311 if(mCurrentFrame.mdpCount == 0) {
1312 return false;
Saurabh Shahaa236822013-04-24 18:07:26 -07001313 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001314
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301315 fbZ = getBatch(list, maxBatchStart, maxBatchEnd, maxBatchCount);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001316
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301317 /* reset rest of the layers lying inside ROI for MDP comp */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001318 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001319 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001320 if((i < maxBatchStart || i > maxBatchEnd) &&
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301321 mCurrentFrame.isFBComposed[i]){
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001322 if(!mCurrentFrame.drop[i]){
1323 //If an unsupported layer is being attempted to
1324 //be pulled out we should fail
1325 if(not isSupportedForMDPComp(ctx, layer)) {
1326 return false;
1327 }
1328 mCurrentFrame.isFBComposed[i] = false;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001329 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001330 }
1331 }
1332
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301333 // update the frame data
1334 mCurrentFrame.fbZ = fbZ;
1335 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001336 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001337 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001338
1339 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301340 mCurrentFrame.fbCount);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001341
1342 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001343}
Saurabh Shah85234ec2013-04-12 17:09:00 -07001344
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001345void MDPComp::updateLayerCache(hwc_context_t* ctx,
Arun Kumar K.R1d4bbd22014-08-20 17:14:26 -07001346 hwc_display_contents_1_t* list, FrameInfo& frame) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001347 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001348 int fbCount = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001349
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001350 for(int i = 0; i < numAppLayers; i++) {
Arun Kumar K.Rdff18b82015-07-27 16:00:02 +05301351 hwc_layer_1_t * layer = &list->hwLayers[i];
1352 if (!layerUpdating(layer)) {
Arun Kumar K.R1d4bbd22014-08-20 17:14:26 -07001353 if(!frame.drop[i])
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001354 fbCount++;
Arun Kumar K.R1d4bbd22014-08-20 17:14:26 -07001355 frame.isFBComposed[i] = true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001356 } else {
Arun Kumar K.R1d4bbd22014-08-20 17:14:26 -07001357 frame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001358 }
1359 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001360
Arun Kumar K.R1d4bbd22014-08-20 17:14:26 -07001361 frame.fbCount = fbCount;
1362 frame.mdpCount = frame.layerCount - frame.fbCount
1363 - frame.dropCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001364
Arun Kumar K.R1d4bbd22014-08-20 17:14:26 -07001365 ALOGD_IF(isDebug(),"%s: MDP count: %d FB count %d drop count: %d",
1366 __FUNCTION__, frame.mdpCount, frame.fbCount, frame.dropCount);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001367}
1368
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001369void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list,
Arun Kumar K.R1d4bbd22014-08-20 17:14:26 -07001370 bool secureOnly, FrameInfo& frame) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001371 int nYuvCount = ctx->listStats[mDpy].yuvCount;
1372 for(int index = 0;index < nYuvCount; index++){
1373 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
1374 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
1375
1376 if(!isYUVDoable(ctx, layer)) {
Arun Kumar K.R1d4bbd22014-08-20 17:14:26 -07001377 if(!frame.isFBComposed[nYuvIndex]) {
1378 frame.isFBComposed[nYuvIndex] = true;
1379 frame.fbCount++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001380 }
1381 } else {
Arun Kumar K.R1d4bbd22014-08-20 17:14:26 -07001382 if(frame.isFBComposed[nYuvIndex]) {
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001383 private_handle_t *hnd = (private_handle_t *)layer->handle;
1384 if(!secureOnly || isSecureBuffer(hnd)) {
Arun Kumar K.R1d4bbd22014-08-20 17:14:26 -07001385 frame.isFBComposed[nYuvIndex] = false;
1386 frame.fbCount--;
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001387 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001388 }
1389 }
1390 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001391
Arun Kumar K.R1d4bbd22014-08-20 17:14:26 -07001392 frame.mdpCount = frame.layerCount - frame.fbCount - frame.dropCount;
1393 ALOGD_IF(isDebug(),"%s: fb count: %d",__FUNCTION__, frame.fbCount);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001394}
1395
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001396bool MDPComp::postHeuristicsHandling(hwc_context_t *ctx,
1397 hwc_display_contents_1_t* list) {
1398
1399 //Capability checks
1400 if(!resourceCheck(ctx, list)) {
1401 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
1402 return false;
1403 }
1404
1405 //Limitations checks
1406 if(!hwLimitationsCheck(ctx, list)) {
1407 ALOGD_IF(isDebug(), "%s: HW limitations",__FUNCTION__);
1408 return false;
1409 }
1410
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001411 //Configure framebuffer first if applicable
1412 if(mCurrentFrame.fbZ >= 0) {
1413 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, mCurrentFrame.fbZ)) {
1414 ALOGD_IF(isDebug(), "%s configure framebuffer failed",
1415 __FUNCTION__);
1416 return false;
1417 }
1418 }
1419
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001420 mCurrentFrame.map();
1421
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001422 if(!allocLayerPipes(ctx, list)) {
1423 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -07001424 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001425 }
1426
1427 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001428 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001429 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001430 int mdpIndex = mCurrentFrame.layerToMDP[index];
1431 hwc_layer_1_t* layer = &list->hwLayers[index];
1432
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301433 //Leave fbZ for framebuffer. CACHE/GLES layers go here.
1434 if(mdpNextZOrder == mCurrentFrame.fbZ) {
1435 mdpNextZOrder++;
1436 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001437 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1438 cur_pipe->zOrder = mdpNextZOrder++;
1439
radhakrishnac9a67412013-09-25 17:40:42 +05301440 private_handle_t *hnd = (private_handle_t *)layer->handle;
1441 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1442 if(configure4k2kYuv(ctx, layer,
1443 mCurrentFrame.mdpToLayer[mdpIndex])
1444 != 0 ){
1445 ALOGD_IF(isDebug(), "%s: Failed to configure split pipes \
1446 for layer %d",__FUNCTION__, index);
1447 return false;
1448 }
1449 else{
1450 mdpNextZOrder++;
1451 }
1452 continue;
1453 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001454 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
1455 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
radhakrishnac9a67412013-09-25 17:40:42 +05301456 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -07001457 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001458 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001459 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001460 }
1461
Saurabh Shah450ac972013-12-16 18:18:39 -08001462 if(!ctx->mOverlay->validateAndSet(mDpy, ctx->dpyAttr[mDpy].fd)) {
1463 ALOGD_IF(isDebug(), "%s: Failed to validate and set overlay for dpy %d"
1464 ,__FUNCTION__, mDpy);
1465 return false;
1466 }
1467
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001468 setRedraw(ctx, list);
Saurabh Shahaa236822013-04-24 18:07:26 -07001469 return true;
1470}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001471
Steve Kondik5164dda2015-11-01 02:51:41 -08001472bool MDPComp::resourceCheck(hwc_context_t * /*ctx*/,
1473 hwc_display_contents_1_t * /*list*/) {
Saurabh Shah173f4242013-11-20 09:50:12 -08001474 const bool fbUsed = mCurrentFrame.fbCount;
1475 if(mCurrentFrame.mdpCount > sMaxPipesPerMixer - fbUsed) {
1476 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
1477 return false;
1478 }
Saurabh Shah173f4242013-11-20 09:50:12 -08001479 return true;
1480}
1481
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301482bool MDPComp::hwLimitationsCheck(hwc_context_t* ctx,
1483 hwc_display_contents_1_t* list) {
1484
1485 //A-family hw limitation:
1486 //If a layer need alpha scaling, MDP can not support.
1487 if(ctx->mMDP.version < qdutils::MDSS_V5) {
1488 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1489 if(!mCurrentFrame.isFBComposed[i] &&
1490 isAlphaScaled( &list->hwLayers[i])) {
1491 ALOGD_IF(isDebug(), "%s:frame needs alphaScaling",__FUNCTION__);
1492 return false;
1493 }
1494 }
1495 }
1496
1497 // On 8x26 & 8974 hw, we have a limitation of downscaling+blending.
1498 //If multiple layers requires downscaling and also they are overlapping
1499 //fall back to GPU since MDSS can not handle it.
1500 if(qdutils::MDPVersion::getInstance().is8x74v2() ||
1501 qdutils::MDPVersion::getInstance().is8x26()) {
1502 for(int i = 0; i < mCurrentFrame.layerCount-1; ++i) {
1503 hwc_layer_1_t* botLayer = &list->hwLayers[i];
1504 if(!mCurrentFrame.isFBComposed[i] &&
1505 isDownscaleRequired(botLayer)) {
1506 //if layer-i is marked for MDP and needs downscaling
1507 //check if any MDP layer on top of i & overlaps with layer-i
1508 for(int j = i+1; j < mCurrentFrame.layerCount; ++j) {
1509 hwc_layer_1_t* topLayer = &list->hwLayers[j];
1510 if(!mCurrentFrame.isFBComposed[j] &&
1511 isDownscaleRequired(topLayer)) {
1512 hwc_rect_t r = getIntersection(botLayer->displayFrame,
1513 topLayer->displayFrame);
1514 if(isValidRect(r))
1515 return false;
1516 }
1517 }
1518 }
1519 }
1520 }
1521 return true;
1522}
1523
Praveena Pachipulusuab89fcf2014-11-25 18:47:54 +05301524void MDPComp::setDynRefreshRate(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
1525 //For primary display, set the dynamic refreshrate
1526 if(!mDpy && qdutils::MDPVersion::getInstance().isDynFpsSupported() &&
1527 ctx->mUseMetaDataRefreshRate) {
1528 FrameInfo frame;
1529 frame.reset(mCurrentFrame.layerCount);
1530 memset(&frame.drop, 0, sizeof(frame.drop));
1531 frame.dropCount = 0;
1532 ALOGD_IF(isDebug(), "%s: Update Cache and YUVInfo for Dyn Refresh Rate",
1533 __FUNCTION__);
1534 updateLayerCache(ctx, list, frame);
1535 updateYUV(ctx, list, false /*secure only*/, frame);
1536 uint32_t refreshRate = ctx->dpyAttr[mDpy].refreshRate;
1537 MDPVersion& mdpHw = MDPVersion::getInstance();
1538 if(sIdleFallBack) {
1539 //Set minimum panel refresh rate during idle timeout
1540 refreshRate = mdpHw.getMinFpsSupported();
1541 } else if((ctx->listStats[mDpy].yuvCount == frame.mdpCount) ||
1542 (frame.layerCount == 1)) {
1543 //Set the new fresh rate, if there is only one updating YUV layer
1544 //or there is one single RGB layer with this request
1545 refreshRate = ctx->listStats[mDpy].refreshRateRequest;
1546 }
1547 setRefreshRate(ctx, mDpy, refreshRate);
1548 }
1549}
1550
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001551int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001552 int ret = 0;
Raj Kamal5166b312014-06-06 13:45:20 +05301553
1554 if(!ctx || !list) {
1555 ALOGE("%s: Invalid context or list",__FUNCTION__);
1556 mCachedFrame.reset();
1557 return -1;
1558 }
1559
Saurabh Shahaa236822013-04-24 18:07:26 -07001560 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001561 MDPVersion& mdpVersion = qdutils::MDPVersion::getInstance();
Arun Kumar K.Rbad65ab2014-06-03 11:54:10 -07001562
1563 // reset PTOR
1564 if(!mDpy)
1565 memset(&(ctx->mPtorInfo), 0, sizeof(ctx->mPtorInfo));
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001566
Saurabh Shahb39f8152013-08-22 10:21:44 -07001567 //reset old data
1568 mCurrentFrame.reset(numLayers);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001569 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1570 mCurrentFrame.dropCount = 0;
Prabhanjan Kandula088bd892013-07-02 23:47:13 +05301571
Praveena Pachipulusuab89fcf2014-11-25 18:47:54 +05301572 //Do not cache the information for next draw cycle.
1573 if(numLayers > MAX_NUM_APP_LAYERS or (!numLayers)) {
1574 ALOGI("%s: Unsupported layer count for mdp composition",
1575 __FUNCTION__);
1576 mCachedFrame.reset();
1577#ifdef DYNAMIC_FPS
1578 setDynRefreshRate(ctx, list);
1579#endif
1580 return -1;
1581 }
1582
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -07001583 // Detect the start of animation and fall back to GPU only once to cache
1584 // all the layers in FB and display FB content untill animation completes.
1585 if(ctx->listStats[mDpy].isDisplayAnimating) {
1586 mCurrentFrame.needsRedraw = false;
1587 if(ctx->mAnimationState[mDpy] == ANIMATION_STOPPED) {
1588 mCurrentFrame.needsRedraw = true;
1589 ctx->mAnimationState[mDpy] = ANIMATION_STARTED;
1590 }
1591 setMDPCompLayerFlags(ctx, list);
1592 mCachedFrame.updateCounts(mCurrentFrame);
Praveena Pachipulusuab89fcf2014-11-25 18:47:54 +05301593#ifdef DYNAMIC_FPS
1594 setDynRefreshRate(ctx, list);
1595#endif
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -07001596 ret = -1;
1597 return ret;
1598 } else {
1599 ctx->mAnimationState[mDpy] = ANIMATION_STOPPED;
1600 }
1601
Raj Kamal46dc44f2015-03-16 21:59:25 +05301602 if(!mDpy and !isSecondaryConnected(ctx) and !mPrevModeOn and
1603 mCachedFrame.isSameFrame(ctx,mDpy,list)) {
1604 ALOGD_IF(isDebug(),"%s: Avoid new composition",__FUNCTION__);
1605 mCurrentFrame.needsRedraw = false;
1606 setMDPCompLayerFlags(ctx, list);
1607 mCachedFrame.updateCounts(mCurrentFrame);
1608 return -1;
1609
1610 }
1611
Saurabh Shahb39f8152013-08-22 10:21:44 -07001612 //Hard conditions, if not met, cannot do MDP comp
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001613 if(isFrameDoable(ctx)) {
1614 generateROI(ctx, list);
Saurabh Shahb39f8152013-08-22 10:21:44 -07001615
Raj Kamal5166b312014-06-06 13:45:20 +05301616 mModeOn = tryFullFrame(ctx, list) || tryVideoOnly(ctx, list);
1617 if(mModeOn) {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001618 setMDPCompLayerFlags(ctx, list);
1619 } else {
1620 reset(ctx);
1621 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1622 mCurrentFrame.dropCount = 0;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001623 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001624 }
1625 } else {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001626 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
1627 __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001628 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001629 }
Saurabh Shahb39f8152013-08-22 10:21:44 -07001630
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001631 if(isDebug()) {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001632 ALOGD("GEOMETRY change: %d",
1633 (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001634 android::String8 sDump("");
1635 dump(sDump);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001636 ALOGD("%s",sDump.string());
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001637 }
1638
Arun Kumar K.R1d4bbd22014-08-20 17:14:26 -07001639#ifdef DYNAMIC_FPS
Praveena Pachipulusuab89fcf2014-11-25 18:47:54 +05301640 setDynRefreshRate(ctx, list);
Arun Kumar K.R1d4bbd22014-08-20 17:14:26 -07001641#endif
1642
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001643 mCachedFrame.updateCounts(mCurrentFrame);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001644 return ret;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001645}
1646
radhakrishnac9a67412013-09-25 17:40:42 +05301647bool MDPComp::allocSplitVGPipesfor4k2k(hwc_context_t *ctx,
1648 hwc_display_contents_1_t* list, int index) {
1649
1650 bool bRet = true;
1651 hwc_layer_1_t* layer = &list->hwLayers[index];
1652 private_handle_t *hnd = (private_handle_t *)layer->handle;
1653 int mdpIndex = mCurrentFrame.layerToMDP[index];
1654 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
1655 info.pipeInfo = new MdpYUVPipeInfo;
1656 info.rot = NULL;
1657 MdpYUVPipeInfo& pipe_info = *(MdpYUVPipeInfo*)info.pipeInfo;
1658 ePipeType type = MDPCOMP_OV_VG;
1659
1660 pipe_info.lIndex = ovutils::OV_INVALID;
1661 pipe_info.rIndex = ovutils::OV_INVALID;
1662
1663 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
1664 if(pipe_info.lIndex == ovutils::OV_INVALID){
1665 bRet = false;
1666 ALOGD_IF(isDebug(),"%s: allocating first VG pipe failed",
1667 __FUNCTION__);
1668 }
1669 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
1670 if(pipe_info.rIndex == ovutils::OV_INVALID){
1671 bRet = false;
1672 ALOGD_IF(isDebug(),"%s: allocating second VG pipe failed",
1673 __FUNCTION__);
1674 }
1675 return bRet;
1676}
Sushil Chauhan4259d872014-05-13 18:17:12 -07001677
1678int MDPComp::drawOverlap(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
1679 int fd = -1;
Arun Kumar K.Rbad65ab2014-06-03 11:54:10 -07001680 if (ctx->mPtorInfo.isActive()) {
1681 fd = ctx->mCopyBit[mDpy]->drawOverlap(ctx, list);
Sushil Chauhan4259d872014-05-13 18:17:12 -07001682 if (fd < 0) {
1683 ALOGD_IF(isDebug(),"%s: failed", __FUNCTION__);
Sushil Chauhan4259d872014-05-13 18:17:12 -07001684 }
1685 }
1686 return fd;
1687}
1688
Saurabh Shah88e4d272013-09-03 13:31:29 -07001689//=============MDPCompNonSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001690
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001691void MDPCompNonSplit::adjustForSourceSplit(hwc_context_t *ctx,
radhakrishnac9a67412013-09-25 17:40:42 +05301692 hwc_display_contents_1_t* list){
1693 //As we split 4kx2k yuv layer and program to 2 VG pipes
1694 //(if available) increase mdpcount accordingly
1695 mCurrentFrame.mdpCount += ctx->listStats[mDpy].yuv4k2kCount;
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001696
1697 //If 4k2k Yuv layer split is possible, and if
1698 //fbz is above 4k2k layer, increment fb zorder by 1
1699 //as we split 4k2k layer and increment zorder for right half
1700 //of the layer
1701 if(mCurrentFrame.fbZ >= 0) {
Dileep Kumar Reddi2268dd72014-05-22 22:24:53 +05301702 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
1703 index++) {
1704 if(!mCurrentFrame.isFBComposed[index]) {
1705 if(mdpNextZOrder == mCurrentFrame.fbZ) {
1706 mdpNextZOrder++;
1707 }
1708 mdpNextZOrder++;
1709 hwc_layer_1_t* layer = &list->hwLayers[index];
1710 private_handle_t *hnd = (private_handle_t *)layer->handle;
1711 if(is4kx2kYuvBuffer(hnd)) {
1712 if(mdpNextZOrder <= mCurrentFrame.fbZ)
1713 mCurrentFrame.fbZ += 1;
1714 mdpNextZOrder++;
1715 //As we split 4kx2k yuv layer and program to 2 VG pipes
1716 //(if available) increase mdpcount by 1.
1717 mCurrentFrame.mdpCount++;
1718 }
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001719 }
1720 }
1721 }
radhakrishnac9a67412013-09-25 17:40:42 +05301722}
1723
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001724/*
1725 * Configures pipe(s) for MDP composition
1726 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001727int MDPCompNonSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001728 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001729 MdpPipeInfoNonSplit& mdp_info =
1730 *(static_cast<MdpPipeInfoNonSplit*>(PipeLayerPair.pipeInfo));
Justin Philip23200512014-08-12 13:42:21 +05301731 eMdpFlags mdpFlags = ovutils::OV_MDP_FLAGS_NONE;
Saurabh Shahacf10202013-02-26 10:15:15 -08001732 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1733 eIsFg isFg = IS_FG_OFF;
1734 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001735
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001736 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
1737 __FUNCTION__, layer, zOrder, dest);
1738
Saurabh Shah88e4d272013-09-03 13:31:29 -07001739 return configureNonSplit(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001740 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001741}
1742
Saurabh Shah88e4d272013-09-03 13:31:29 -07001743bool MDPCompNonSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001744 hwc_display_contents_1_t* list) {
1745 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001746
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001747 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001748
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001749 hwc_layer_1_t* layer = &list->hwLayers[index];
1750 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301751 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1752 if(allocSplitVGPipesfor4k2k(ctx, list, index)){
1753 continue;
1754 }
1755 }
1756
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001757 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001758 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001759 info.pipeInfo = new MdpPipeInfoNonSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08001760 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001761 MdpPipeInfoNonSplit& pipe_info = *(MdpPipeInfoNonSplit*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001762 ePipeType type = MDPCOMP_OV_ANY;
1763
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001764 if(isYuvBuffer(hnd)) {
1765 type = MDPCOMP_OV_VG;
Prabhanjan Kandula5b8913e2014-01-22 23:01:45 +05301766 } else if(qdutils::MDPVersion::getInstance().is8x26() &&
1767 (ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres > 1024)) {
1768 if(qhwc::needsScaling(layer))
1769 type = MDPCOMP_OV_RGB;
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301770 } else if(!qhwc::needsScaling(layer)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001771 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
1772 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001773 type = MDPCOMP_OV_DMA;
1774 }
1775
Xu Yang5c2b3af2014-04-08 13:56:47 +08001776 // for 8x26, never allow primary display occupy DMA pipe
1777 // when external display is connected
1778 if(qdutils::MDPVersion::getInstance().is8x26()
1779 && ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isActive
1780 && ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected
1781 && !ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isPause
1782 && mDpy == HWC_DISPLAY_PRIMARY
1783 && type == MDPCOMP_OV_DMA) {
1784 type = MDPCOMP_OV_RGB;
1785 }
1786
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001787 pipe_info.index = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001788 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001789 ALOGD_IF(isDebug(), "%s: Unable to get pipe type = %d",
1790 __FUNCTION__, (int) type);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001791 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001792 }
1793 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001794 return true;
1795}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001796
radhakrishnac9a67412013-09-25 17:40:42 +05301797int MDPCompNonSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1798 PipeLayerPair& PipeLayerPair) {
1799 MdpYUVPipeInfo& mdp_info =
1800 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1801 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1802 eIsFg isFg = IS_FG_OFF;
Justin Philip23200512014-08-12 13:42:21 +05301803 eMdpFlags mdpFlagsL = ovutils::OV_MDP_FLAGS_NONE;
radhakrishnac9a67412013-09-25 17:40:42 +05301804 eDest lDest = mdp_info.lIndex;
1805 eDest rDest = mdp_info.rIndex;
1806
1807 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1808 lDest, rDest, &PipeLayerPair.rot);
1809}
1810
Saurabh Shah88e4d272013-09-03 13:31:29 -07001811bool MDPCompNonSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001812
Raj Kamal5166b312014-06-06 13:45:20 +05301813 if(!isEnabled() or !mModeOn) {
1814 ALOGD_IF(isDebug(),"%s: MDP Comp not enabled/configured", __FUNCTION__);
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301815 return true;
1816 }
1817
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001818 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001819 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001820
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001821 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1822 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001823 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001824 if(mCurrentFrame.isFBComposed[i]) continue;
1825
Naseer Ahmed5b6708a2012-08-02 13:46:08 -07001826 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001827 private_handle_t *hnd = (private_handle_t *)layer->handle;
1828 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001829 if (!(layer->flags & HWC_COLOR_FILL)) {
1830 ALOGE("%s handle null", __FUNCTION__);
1831 return false;
1832 }
1833 // No PLAY for Color layer
1834 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1835 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001836 }
1837
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001838 int mdpIndex = mCurrentFrame.layerToMDP[i];
1839
radhakrishnac9a67412013-09-25 17:40:42 +05301840 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1841 {
1842 MdpYUVPipeInfo& pipe_info =
1843 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1844 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1845 ovutils::eDest indexL = pipe_info.lIndex;
1846 ovutils::eDest indexR = pipe_info.rIndex;
1847 int fd = hnd->fd;
1848 uint32_t offset = hnd->offset;
1849 if(rot) {
1850 rot->queueBuffer(fd, offset);
1851 fd = rot->getDstMemId();
1852 offset = rot->getDstOffset();
1853 }
1854 if(indexL != ovutils::OV_INVALID) {
1855 ovutils::eDest destL = (ovutils::eDest)indexL;
1856 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1857 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1858 if (!ov.queueBuffer(fd, offset, destL)) {
1859 ALOGE("%s: queueBuffer failed for display:%d",
1860 __FUNCTION__, mDpy);
1861 return false;
1862 }
1863 }
1864
1865 if(indexR != ovutils::OV_INVALID) {
1866 ovutils::eDest destR = (ovutils::eDest)indexR;
1867 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1868 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1869 if (!ov.queueBuffer(fd, offset, destR)) {
1870 ALOGE("%s: queueBuffer failed for display:%d",
1871 __FUNCTION__, mDpy);
1872 return false;
1873 }
1874 }
1875 }
1876 else{
1877 MdpPipeInfoNonSplit& pipe_info =
Saurabh Shah88e4d272013-09-03 13:31:29 -07001878 *(MdpPipeInfoNonSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
radhakrishnac9a67412013-09-25 17:40:42 +05301879 ovutils::eDest dest = pipe_info.index;
1880 if(dest == ovutils::OV_INVALID) {
1881 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001882 return false;
radhakrishnac9a67412013-09-25 17:40:42 +05301883 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001884
radhakrishnac9a67412013-09-25 17:40:42 +05301885 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1886 continue;
1887 }
1888
Arun Kumar K.Rbad65ab2014-06-03 11:54:10 -07001889 int fd = hnd->fd;
1890 uint32_t offset = (uint32_t)hnd->offset;
1891 int index = ctx->mPtorInfo.getPTORArrayIndex(i);
1892 if (!mDpy && (index != -1)) {
Sushil Chauhan4259d872014-05-13 18:17:12 -07001893 hnd = ctx->mCopyBit[mDpy]->getCurrentRenderBuffer();
Arun Kumar K.Rbad65ab2014-06-03 11:54:10 -07001894 fd = hnd->fd;
Sushil Chauhane1474bf2014-07-25 12:20:23 -07001895 offset = 0;
Sushil Chauhan4259d872014-05-13 18:17:12 -07001896 }
1897
radhakrishnac9a67412013-09-25 17:40:42 +05301898 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1899 using pipe: %d", __FUNCTION__, layer,
1900 hnd, dest );
1901
radhakrishnac9a67412013-09-25 17:40:42 +05301902 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1903 if(rot) {
1904 if(!rot->queueBuffer(fd, offset))
1905 return false;
1906 fd = rot->getDstMemId();
1907 offset = rot->getDstOffset();
1908 }
1909
1910 if (!ov.queueBuffer(fd, offset, dest)) {
1911 ALOGE("%s: queueBuffer failed for display:%d ",
1912 __FUNCTION__, mDpy);
1913 return false;
1914 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001915 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001916
1917 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001918 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001919 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001920}
1921
Saurabh Shah88e4d272013-09-03 13:31:29 -07001922//=============MDPCompSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001923
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001924void MDPCompSplit::adjustForSourceSplit(hwc_context_t *ctx,
radhakrishnac9a67412013-09-25 17:40:42 +05301925 hwc_display_contents_1_t* list){
1926 //if 4kx2k yuv layer is totally present in either in left half
1927 //or right half then try splitting the yuv layer to avoid decimation
radhakrishnac9a67412013-09-25 17:40:42 +05301928 const int lSplit = getLeftSplit(ctx, mDpy);
Dileep Kumar Reddi2268dd72014-05-22 22:24:53 +05301929 if(mCurrentFrame.fbZ >= 0) {
1930 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
1931 index++) {
1932 if(!mCurrentFrame.isFBComposed[index]) {
1933 if(mdpNextZOrder == mCurrentFrame.fbZ) {
1934 mdpNextZOrder++;
1935 }
1936 mdpNextZOrder++;
1937 hwc_layer_1_t* layer = &list->hwLayers[index];
1938 private_handle_t *hnd = (private_handle_t *)layer->handle;
1939 if(is4kx2kYuvBuffer(hnd)) {
1940 hwc_rect_t dst = layer->displayFrame;
1941 if((dst.left > lSplit) || (dst.right < lSplit)) {
1942 mCurrentFrame.mdpCount += 1;
1943 }
1944 if(mdpNextZOrder <= mCurrentFrame.fbZ)
1945 mCurrentFrame.fbZ += 1;
1946 mdpNextZOrder++;
1947 }
1948 }
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001949 }
radhakrishnac9a67412013-09-25 17:40:42 +05301950 }
1951}
1952
Saurabh Shah88e4d272013-09-03 13:31:29 -07001953bool MDPCompSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
1954 MdpPipeInfoSplit& pipe_info,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001955 ePipeType type) {
1956 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001957 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001958
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001959 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001960 pipe_info.lIndex = ovutils::OV_INVALID;
1961 pipe_info.rIndex = ovutils::OV_INVALID;
1962
1963 if (dst.left < lSplit) {
1964 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_LEFT);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001965 if(pipe_info.lIndex == ovutils::OV_INVALID)
1966 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001967 }
1968
1969 if(dst.right > lSplit) {
1970 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_RIGHT);
1971 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001972 return false;
1973 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001974
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001975 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001976}
1977
Saurabh Shah88e4d272013-09-03 13:31:29 -07001978bool MDPCompSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001979 hwc_display_contents_1_t* list) {
1980 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001981
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001982 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001983
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001984 hwc_layer_1_t* layer = &list->hwLayers[index];
1985 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301986 hwc_rect_t dst = layer->displayFrame;
1987 const int lSplit = getLeftSplit(ctx, mDpy);
1988 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1989 if((dst.left > lSplit)||(dst.right < lSplit)){
1990 if(allocSplitVGPipesfor4k2k(ctx, list, index)){
1991 continue;
1992 }
1993 }
1994 }
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001995 int mdpIndex = mCurrentFrame.layerToMDP[index];
1996 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001997 info.pipeInfo = new MdpPipeInfoSplit;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001998 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001999 MdpPipeInfoSplit& pipe_info = *(MdpPipeInfoSplit*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002000 ePipeType type = MDPCOMP_OV_ANY;
2001
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07002002 if(isYuvBuffer(hnd)) {
2003 type = MDPCOMP_OV_VG;
Sushil Chauhan15a2ea62013-09-04 18:28:36 -07002004 } else if(!qhwc::needsScalingWithSplit(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07002005 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07002006 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002007 type = MDPCOMP_OV_DMA;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07002008 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002009
2010 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07002011 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type = %d",
2012 __FUNCTION__, (int) type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002013 return false;
2014 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002015 }
2016 return true;
2017}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07002018
radhakrishnac9a67412013-09-25 17:40:42 +05302019int MDPCompSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
2020 PipeLayerPair& PipeLayerPair) {
2021 const int lSplit = getLeftSplit(ctx, mDpy);
2022 hwc_rect_t dst = layer->displayFrame;
2023 if((dst.left > lSplit)||(dst.right < lSplit)){
2024 MdpYUVPipeInfo& mdp_info =
2025 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
2026 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
2027 eIsFg isFg = IS_FG_OFF;
Justin Philip23200512014-08-12 13:42:21 +05302028 eMdpFlags mdpFlagsL = ovutils::OV_MDP_FLAGS_NONE;
radhakrishnac9a67412013-09-25 17:40:42 +05302029 eDest lDest = mdp_info.lIndex;
2030 eDest rDest = mdp_info.rIndex;
2031
2032 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
2033 lDest, rDest, &PipeLayerPair.rot);
2034 }
2035 else{
2036 return configure(ctx, layer, PipeLayerPair);
2037 }
2038}
2039
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002040/*
2041 * Configures pipe(s) for MDP composition
2042 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07002043int MDPCompSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07002044 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07002045 MdpPipeInfoSplit& mdp_info =
2046 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08002047 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
2048 eIsFg isFg = IS_FG_OFF;
Justin Philip23200512014-08-12 13:42:21 +05302049 eMdpFlags mdpFlagsL = ovutils::OV_MDP_FLAGS_NONE;
Saurabh Shahacf10202013-02-26 10:15:15 -08002050 eDest lDest = mdp_info.lIndex;
2051 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08002052
2053 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
2054 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
2055
Saurabh Shah88e4d272013-09-03 13:31:29 -07002056 return configureSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08002057 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002058}
2059
Saurabh Shah88e4d272013-09-03 13:31:29 -07002060bool MDPCompSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002061
Raj Kamal5166b312014-06-06 13:45:20 +05302062 if(!isEnabled() or !mModeOn) {
2063 ALOGD_IF(isDebug(),"%s: MDP Comp not enabled/configured", __FUNCTION__);
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05302064 return true;
2065 }
2066
Naseer Ahmed54821fe2012-11-28 18:44:38 -05002067 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08002068 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002069
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08002070 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
2071 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002072 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08002073 if(mCurrentFrame.isFBComposed[i]) continue;
2074
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002075 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08002076 private_handle_t *hnd = (private_handle_t *)layer->handle;
2077 if(!hnd) {
2078 ALOGE("%s handle null", __FUNCTION__);
2079 return false;
2080 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002081
2082 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
2083 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002084 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002085
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08002086 int mdpIndex = mCurrentFrame.layerToMDP[i];
2087
radhakrishnac9a67412013-09-25 17:40:42 +05302088 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
2089 {
2090 MdpYUVPipeInfo& pipe_info =
2091 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
2092 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
2093 ovutils::eDest indexL = pipe_info.lIndex;
2094 ovutils::eDest indexR = pipe_info.rIndex;
2095 int fd = hnd->fd;
2096 uint32_t offset = hnd->offset;
2097 if(rot) {
2098 rot->queueBuffer(fd, offset);
2099 fd = rot->getDstMemId();
2100 offset = rot->getDstOffset();
2101 }
2102 if(indexL != ovutils::OV_INVALID) {
2103 ovutils::eDest destL = (ovutils::eDest)indexL;
2104 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
2105 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
2106 if (!ov.queueBuffer(fd, offset, destL)) {
2107 ALOGE("%s: queueBuffer failed for display:%d",
2108 __FUNCTION__, mDpy);
2109 return false;
2110 }
2111 }
Saurabh Shahacf10202013-02-26 10:15:15 -08002112
radhakrishnac9a67412013-09-25 17:40:42 +05302113 if(indexR != ovutils::OV_INVALID) {
2114 ovutils::eDest destR = (ovutils::eDest)indexR;
2115 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
2116 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
2117 if (!ov.queueBuffer(fd, offset, destR)) {
2118 ALOGE("%s: queueBuffer failed for display:%d",
2119 __FUNCTION__, mDpy);
2120 return false;
2121 }
Saurabh Shaha9da08f2013-07-03 13:27:53 -07002122 }
2123 }
radhakrishnac9a67412013-09-25 17:40:42 +05302124 else{
2125 MdpPipeInfoSplit& pipe_info =
2126 *(MdpPipeInfoSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
2127 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07002128
radhakrishnac9a67412013-09-25 17:40:42 +05302129 ovutils::eDest indexL = pipe_info.lIndex;
2130 ovutils::eDest indexR = pipe_info.rIndex;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002131
radhakrishnac9a67412013-09-25 17:40:42 +05302132 int fd = hnd->fd;
Arun Kumar K.Rbad65ab2014-06-03 11:54:10 -07002133 uint32_t offset = (uint32_t)hnd->offset;
2134 int index = ctx->mPtorInfo.getPTORArrayIndex(i);
2135 if (!mDpy && (index != -1)) {
2136 hnd = ctx->mCopyBit[mDpy]->getCurrentRenderBuffer();
2137 fd = hnd->fd;
Sushil Chauhane1474bf2014-07-25 12:20:23 -07002138 offset = 0;
Arun Kumar K.Rbad65ab2014-06-03 11:54:10 -07002139 }
radhakrishnac9a67412013-09-25 17:40:42 +05302140
Tatenda Chipeperekwa2f8cd2b2014-04-14 10:36:06 -07002141 if(ctx->mAD->draw(ctx, fd, offset)) {
2142 fd = ctx->mAD->getDstFd(ctx);
2143 offset = ctx->mAD->getDstOffset(ctx);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002144 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002145
radhakrishnac9a67412013-09-25 17:40:42 +05302146 if(rot) {
2147 rot->queueBuffer(fd, offset);
2148 fd = rot->getDstMemId();
2149 offset = rot->getDstOffset();
2150 }
2151
2152 //************* play left mixer **********
2153 if(indexL != ovutils::OV_INVALID) {
2154 ovutils::eDest destL = (ovutils::eDest)indexL;
2155 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
2156 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
2157 if (!ov.queueBuffer(fd, offset, destL)) {
2158 ALOGE("%s: queueBuffer failed for left mixer",
2159 __FUNCTION__);
2160 return false;
2161 }
2162 }
2163
2164 //************* play right mixer **********
2165 if(indexR != ovutils::OV_INVALID) {
2166 ovutils::eDest destR = (ovutils::eDest)indexR;
2167 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
2168 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
2169 if (!ov.queueBuffer(fd, offset, destR)) {
2170 ALOGE("%s: queueBuffer failed for right mixer",
2171 __FUNCTION__);
2172 return false;
2173 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002174 }
2175 }
Saurabh Shahacf10202013-02-26 10:15:15 -08002176
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002177 layerProp[i].mFlags &= ~HWC_MDPCOMP;
2178 }
Saurabh Shahacf10202013-02-26 10:15:15 -08002179
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002180 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002181}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002182}; //namespace
2183