blob: 4520230aa54a224a0c84efa8162fc922dfe6cc53 [file] [log] [blame]
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001/*
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08002 * Copyright (C) 2012-2014, The Linux Foundation. All rights reserved.
Naseer Ahmed7c958d42012-07-31 18:57:03 -07003 * Not a Contribution, Apache license notifications and license are retained
4 * for attribution purposes only.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
Saurabh Shah4fdde762013-04-30 18:47:33 -070019#include <math.h>
Naseer Ahmed7c958d42012-07-31 18:57:03 -070020#include "hwc_mdpcomp.h"
Naseer Ahmed54821fe2012-11-28 18:44:38 -050021#include <sys/ioctl.h>
Saurabh Shah56f610d2012-08-07 15:27:06 -070022#include "external.h"
Jeykumar Sankaran27dee262013-08-01 17:09:54 -070023#include "virtual.h"
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -080024#include "qdMetaData.h"
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -080025#include "mdp_version.h"
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -070026#include "hwc_fbupdate.h"
Saurabh Shaha9da08f2013-07-03 13:27:53 -070027#include "hwc_ad.h"
Saurabh Shahacf10202013-02-26 10:15:15 -080028#include <overlayRotator.h>
29
Saurabh Shah85234ec2013-04-12 17:09:00 -070030using namespace overlay;
Saurabh Shahbd2d0832013-04-04 14:33:08 -070031using namespace qdutils;
Saurabh Shahacf10202013-02-26 10:15:15 -080032using namespace overlay::utils;
33namespace ovutils = overlay::utils;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070034
Naseer Ahmed7c958d42012-07-31 18:57:03 -070035namespace qhwc {
36
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080037//==============MDPComp========================================================
38
Naseer Ahmed7c958d42012-07-31 18:57:03 -070039IdleInvalidator *MDPComp::idleInvalidator = NULL;
40bool MDPComp::sIdleFallBack = false;
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -080041bool MDPComp::sHandleTimeout = false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070042bool MDPComp::sDebugLogs = false;
Naseer Ahmed54821fe2012-11-28 18:44:38 -050043bool MDPComp::sEnabled = false;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -070044bool MDPComp::sEnableMixedMode = true;
Jeykumar Sankaran0ad97c42014-03-09 23:00:53 -070045int MDPComp::sSimulationFlags = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080046int MDPComp::sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
radhakrishnac9a67412013-09-25 17:40:42 +053047bool MDPComp::sEnable4k2kYUVSplit = false;
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -070048bool MDPComp::sSrcSplitEnabled = false;
Saurabh Shah88e4d272013-09-03 13:31:29 -070049MDPComp* MDPComp::getObject(hwc_context_t *ctx, const int& dpy) {
Saurabh Shah60e8bde2014-04-30 14:46:03 -070050 if(qdutils::MDPVersion::getInstance().isSrcSplit()) {
51 sSrcSplitEnabled = true;
52 return new MDPCompSrcSplit(dpy);
53 } else if(isDisplaySplit(ctx, dpy)) {
Saurabh Shah88e4d272013-09-03 13:31:29 -070054 return new MDPCompSplit(dpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080055 }
Saurabh Shah88e4d272013-09-03 13:31:29 -070056 return new MDPCompNonSplit(dpy);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080057}
58
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080059MDPComp::MDPComp(int dpy):mDpy(dpy){};
60
Jeykumar Sankaran6850ac62014-05-27 10:07:26 -070061void MDPComp::dump(android::String8& buf, hwc_context_t *ctx)
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080062{
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);
Jeykumar Sankaran6850ac62014-05-27 10:07:26 -070075 if(isDisplaySplit(ctx, mDpy)) {
76 dumpsys_log(buf, "Programmed ROI's: Left: [%d, %d, %d, %d] "
77 "Right: [%d, %d, %d, %d] \n",
78 ctx->listStats[mDpy].lRoi.left, ctx->listStats[mDpy].lRoi.top,
79 ctx->listStats[mDpy].lRoi.right,
80 ctx->listStats[mDpy].lRoi.bottom,
81 ctx->listStats[mDpy].rRoi.left,ctx->listStats[mDpy].rRoi.top,
82 ctx->listStats[mDpy].rRoi.right,
83 ctx->listStats[mDpy].rRoi.bottom);
84 } else {
85 dumpsys_log(buf, "Programmed ROI: [%d, %d, %d, %d] \n",
86 ctx->listStats[mDpy].lRoi.left,ctx->listStats[mDpy].lRoi.top,
87 ctx->listStats[mDpy].lRoi.right,
88 ctx->listStats[mDpy].lRoi.bottom);
89 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080090 dumpsys_log(buf," --------------------------------------------- \n");
91 dumpsys_log(buf," listIdx | cached? | mdpIndex | comptype | Z \n");
92 dumpsys_log(buf," --------------------------------------------- \n");
93 for(int index = 0; index < mCurrentFrame.layerCount; index++ )
94 dumpsys_log(buf," %7d | %7s | %8d | %9s | %2d \n",
95 index,
96 (mCurrentFrame.isFBComposed[index] ? "YES" : "NO"),
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -070097 mCurrentFrame.layerToMDP[index],
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080098 (mCurrentFrame.isFBComposed[index] ?
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -070099 (mCurrentFrame.drop[index] ? "DROP" :
100 (mCurrentFrame.needsRedraw ? "GLES" : "CACHE")) : "MDP"),
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800101 (mCurrentFrame.isFBComposed[index] ? mCurrentFrame.fbZ :
102 mCurrentFrame.mdpToLayer[mCurrentFrame.layerToMDP[index]].pipeInfo->zOrder));
103 dumpsys_log(buf,"\n");
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800104}
105
106bool MDPComp::init(hwc_context_t *ctx) {
107
108 if(!ctx) {
109 ALOGE("%s: Invalid hwc context!!",__FUNCTION__);
110 return false;
111 }
112
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800113 char property[PROPERTY_VALUE_MAX];
114
115 sEnabled = false;
116 if((property_get("persist.hwc.mdpcomp.enable", property, NULL) > 0) &&
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800117 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
118 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800119 sEnabled = true;
120 }
121
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700122 sEnableMixedMode = true;
123 if((property_get("debug.mdpcomp.mixedmode.disable", property, NULL) > 0) &&
124 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
125 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
126 sEnableMixedMode = false;
127 }
128
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800129 if(property_get("debug.mdpcomp.logs", property, NULL) > 0) {
130 if(atoi(property) != 0)
131 sDebugLogs = true;
132 }
133
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800134 sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
Saurabh Shah85234ec2013-04-12 17:09:00 -0700135 if(property_get("debug.mdpcomp.maxpermixer", property, "-1") > 0) {
136 int val = atoi(property);
137 if(val >= 0)
138 sMaxPipesPerMixer = min(val, MAX_PIPES_PER_MIXER);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800139 }
140
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400141 if(ctx->mMDP.panel != MIPI_CMD_PANEL) {
142 // Idle invalidation is not necessary on command mode panels
143 long idle_timeout = DEFAULT_IDLE_TIME;
144 if(property_get("debug.mdpcomp.idletime", property, NULL) > 0) {
145 if(atoi(property) != 0)
146 idle_timeout = atoi(property);
147 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800148
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400149 //create Idle Invalidator only when not disabled through property
150 if(idle_timeout != -1)
151 idleInvalidator = IdleInvalidator::getInstance();
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800152
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400153 if(idleInvalidator == NULL) {
154 ALOGE("%s: failed to instantiate idleInvalidator object",
155 __FUNCTION__);
156 } else {
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530157 idleInvalidator->init(timeout_handler, ctx,
158 (unsigned int)idle_timeout);
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400159 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800160 }
radhakrishnac9a67412013-09-25 17:40:42 +0530161
162 if((property_get("debug.mdpcomp.4k2kSplit", property, "0") > 0) &&
163 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
164 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
165 sEnable4k2kYUVSplit = true;
166 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700167 return true;
168}
169
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800170void MDPComp::reset(hwc_context_t *ctx) {
171 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700172 mCurrentFrame.reset(numLayers);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800173 ctx->mOverlay->clear(mDpy);
174 ctx->mLayerRotMap[mDpy]->clear();
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700175}
176
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700177void MDPComp::timeout_handler(void *udata) {
178 struct hwc_context_t* ctx = (struct hwc_context_t*)(udata);
179
180 if(!ctx) {
181 ALOGE("%s: received empty data in timer callback", __FUNCTION__);
182 return;
183 }
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -0800184 Locker::Autolock _l(ctx->mDrawLock);
185 // Handle timeout event only if the previous composition is MDP or MIXED.
186 if(!sHandleTimeout) {
187 ALOGD_IF(isDebug(), "%s:Do not handle this timeout", __FUNCTION__);
188 return;
189 }
Jesse Hall3be78d92012-08-21 15:12:23 -0700190 if(!ctx->proc) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700191 ALOGE("%s: HWC proc not registered", __FUNCTION__);
192 return;
193 }
194 sIdleFallBack = true;
195 /* Trigger SF to redraw the current frame */
Jesse Hall3be78d92012-08-21 15:12:23 -0700196 ctx->proc->invalidate(ctx->proc);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700197}
198
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800199void MDPComp::setMDPCompLayerFlags(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800200 hwc_display_contents_1_t* list) {
201 LayerProp *layerProp = ctx->layerProp[mDpy];
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800202
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800203 for(int index = 0; index < ctx->listStats[mDpy].numAppLayers; index++) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800204 hwc_layer_1_t* layer = &(list->hwLayers[index]);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800205 if(!mCurrentFrame.isFBComposed[index]) {
206 layerProp[index].mFlags |= HWC_MDPCOMP;
207 layer->compositionType = HWC_OVERLAY;
208 layer->hints |= HWC_HINT_CLEAR_FB;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800209 } else {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700210 /* Drop the layer when its already present in FB OR when it lies
211 * outside frame's ROI */
212 if(!mCurrentFrame.needsRedraw || mCurrentFrame.drop[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800213 layer->compositionType = HWC_OVERLAY;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700214 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800215 }
216 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700217}
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500218
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800219void MDPComp::setRedraw(hwc_context_t *ctx,
220 hwc_display_contents_1_t* list) {
221 mCurrentFrame.needsRedraw = false;
222 if(!mCachedFrame.isSameFrame(mCurrentFrame, list) ||
223 (list->flags & HWC_GEOMETRY_CHANGED) ||
224 isSkipPresent(ctx, mDpy)) {
225 mCurrentFrame.needsRedraw = true;
226 }
227}
228
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800229MDPComp::FrameInfo::FrameInfo() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700230 reset(0);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800231}
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800232
Saurabh Shahaa236822013-04-24 18:07:26 -0700233void MDPComp::FrameInfo::reset(const int& numLayers) {
234 for(int i = 0 ; i < MAX_PIPES_PER_MIXER && numLayers; i++ ) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800235 if(mdpToLayer[i].pipeInfo) {
236 delete mdpToLayer[i].pipeInfo;
237 mdpToLayer[i].pipeInfo = NULL;
238 //We dont own the rotator
239 mdpToLayer[i].rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800240 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800241 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800242
243 memset(&mdpToLayer, 0, sizeof(mdpToLayer));
244 memset(&layerToMDP, -1, sizeof(layerToMDP));
Saurabh Shahaa236822013-04-24 18:07:26 -0700245 memset(&isFBComposed, 1, sizeof(isFBComposed));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800246
Saurabh Shahaa236822013-04-24 18:07:26 -0700247 layerCount = numLayers;
248 fbCount = numLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800249 mdpCount = 0;
Saurabh Shah2f3895f2013-05-02 10:13:31 -0700250 needsRedraw = true;
Saurabh Shahd53bc5f2014-02-05 10:17:43 -0800251 fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800252}
253
Saurabh Shahaa236822013-04-24 18:07:26 -0700254void MDPComp::FrameInfo::map() {
255 // populate layer and MDP maps
256 int mdpIdx = 0;
257 for(int idx = 0; idx < layerCount; idx++) {
258 if(!isFBComposed[idx]) {
259 mdpToLayer[mdpIdx].listIndex = idx;
260 layerToMDP[idx] = mdpIdx++;
261 }
262 }
263}
264
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800265MDPComp::LayerCache::LayerCache() {
266 reset();
267}
268
269void MDPComp::LayerCache::reset() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700270 memset(&hnd, 0, sizeof(hnd));
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530271 memset(&isFBComposed, true, sizeof(isFBComposed));
272 memset(&drop, false, sizeof(drop));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800273 layerCount = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -0700274}
275
276void MDPComp::LayerCache::cacheAll(hwc_display_contents_1_t* list) {
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530277 const int numAppLayers = (int)list->numHwLayers - 1;
Saurabh Shahaa236822013-04-24 18:07:26 -0700278 for(int i = 0; i < numAppLayers; i++) {
279 hnd[i] = list->hwLayers[i].handle;
280 }
281}
282
283void MDPComp::LayerCache::updateCounts(const FrameInfo& curFrame) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700284 layerCount = curFrame.layerCount;
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530285 memcpy(&isFBComposed, &curFrame.isFBComposed, sizeof(isFBComposed));
286 memcpy(&drop, &curFrame.drop, sizeof(drop));
287}
288
Jeykumar Sankaran988d3682013-11-15 11:57:16 -0800289bool MDPComp::LayerCache::isSameFrame(const FrameInfo& curFrame,
290 hwc_display_contents_1_t* list) {
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530291 if(layerCount != curFrame.layerCount)
292 return false;
293 for(int i = 0; i < curFrame.layerCount; i++) {
294 if((curFrame.isFBComposed[i] != isFBComposed[i]) ||
295 (curFrame.drop[i] != drop[i])) {
296 return false;
297 }
Jeykumar Sankaran988d3682013-11-15 11:57:16 -0800298 if(curFrame.isFBComposed[i] &&
299 (hnd[i] != list->hwLayers[i].handle)){
300 return false;
301 }
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530302 }
303 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800304}
305
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700306bool MDPComp::isSupportedForMDPComp(hwc_context_t *ctx, hwc_layer_1_t* layer) {
307 private_handle_t *hnd = (private_handle_t *)layer->handle;
308 if((not isYuvBuffer(hnd) and has90Transform(layer)) or
309 (not isValidDimension(ctx,layer))
310 //More conditions here, SKIP, sRGB+Blend etc
311 ) {
312 return false;
313 }
314 return true;
315}
316
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530317bool MDPComp::isValidDimension(hwc_context_t *ctx, hwc_layer_1_t *layer) {
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800318 private_handle_t *hnd = (private_handle_t *)layer->handle;
319
320 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -0700321 if (layer->flags & HWC_COLOR_FILL) {
322 // Color layer
323 return true;
324 }
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800325 ALOGE("%s: layer handle is NULL", __FUNCTION__);
326 return false;
327 }
328
Naseer Ahmede850a802013-09-06 13:12:52 -0400329 //XXX: Investigate doing this with pixel phase on MDSS
Naseer Ahmede77f8082013-10-10 13:42:48 -0400330 if(!isSecureBuffer(hnd) && isNonIntegralSourceCrop(layer->sourceCropf))
Naseer Ahmede850a802013-09-06 13:12:52 -0400331 return false;
332
Saurabh Shah62e1d732013-09-17 10:44:05 -0700333 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700334 hwc_rect_t dst = layer->displayFrame;
Saurabh Shah4fdde762013-04-30 18:47:33 -0700335 int crop_w = crop.right - crop.left;
336 int crop_h = crop.bottom - crop.top;
337 int dst_w = dst.right - dst.left;
338 int dst_h = dst.bottom - dst.top;
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800339 float w_scale = ((float)crop_w / (float)dst_w);
340 float h_scale = ((float)crop_h / (float)dst_h);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700341
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800342 /* Workaround for MDP HW limitation in DSI command mode panels where
343 * FPS will not go beyond 30 if buffers on RGB pipes are of width or height
344 * less than 5 pixels
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530345 * There also is a HW limilation in MDP, minimum block size is 2x2
346 * Fallback to GPU if height is less than 2.
347 */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800348 if((crop_w < 5)||(crop_h < 5))
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800349 return false;
350
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800351 if((w_scale > 1.0f) || (h_scale > 1.0f)) {
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700352 const uint32_t maxMDPDownscale =
Saurabh Shah4fdde762013-04-30 18:47:33 -0700353 qdutils::MDPVersion::getInstance().getMaxMDPDownscale();
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800354 const float w_dscale = w_scale;
355 const float h_dscale = h_scale;
356
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800357 if(ctx->mMDP.version >= qdutils::MDSS_V5) {
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700358
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800359 if(!qdutils::MDPVersion::getInstance().supportsDecimation()) {
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700360 /* On targets that doesnt support Decimation (eg.,8x26)
361 * maximum downscale support is overlay pipe downscale.
362 */
363 if(crop_w > MAX_DISPLAY_DIM || w_dscale > maxMDPDownscale ||
364 h_dscale > maxMDPDownscale)
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800365 return false;
366 } else {
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700367 // Decimation on macrotile format layers is not supported.
368 if(isTileRendered(hnd)) {
369 /* MDP can read maximum MAX_DISPLAY_DIM width.
370 * Bail out if
371 * 1. Src crop > MAX_DISPLAY_DIM on nonsplit MDPComp
372 * 2. exceeds maximum downscale limit
373 */
374 if(((crop_w > MAX_DISPLAY_DIM) && !sSrcSplitEnabled) ||
375 w_dscale > maxMDPDownscale ||
376 h_dscale > maxMDPDownscale) {
377 return false;
378 }
379 } else if(w_dscale > 64 || h_dscale > 64)
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800380 return false;
381 }
382 } else { //A-family
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700383 if(w_dscale > maxMDPDownscale || h_dscale > maxMDPDownscale)
Saurabh Shah4fdde762013-04-30 18:47:33 -0700384 return false;
385 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700386 }
387
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800388 if((w_scale < 1.0f) || (h_scale < 1.0f)) {
389 const uint32_t upscale =
390 qdutils::MDPVersion::getInstance().getMaxMDPUpscale();
391 const float w_uscale = 1.0f / w_scale;
392 const float h_uscale = 1.0f / h_scale;
393
394 if(w_uscale > upscale || h_uscale > upscale)
395 return false;
396 }
397
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800398 return true;
399}
400
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800401bool MDPComp::isFrameDoable(hwc_context_t *ctx) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700402 bool ret = true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800403
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800404 if(!isEnabled()) {
405 ALOGD_IF(isDebug(),"%s: MDP Comp. not enabled.", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700406 ret = false;
Raj Kamal068f4572014-04-14 16:14:06 +0530407 } else if((qdutils::MDPVersion::getInstance().is8x26() ||
Prabhanjan Kandula958ffa92014-05-12 14:56:56 +0530408 qdutils::MDPVersion::getInstance().is8x16() ||
409 qdutils::MDPVersion::getInstance().is8x39()) &&
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -0800410 ctx->mVideoTransFlag &&
411 isSecondaryConnected(ctx)) {
Saurabh Shahd4e65852013-06-17 11:33:53 -0700412 //1 Padding round to shift pipes across mixers
413 ALOGD_IF(isDebug(),"%s: MDP Comp. video transition padding round",
414 __FUNCTION__);
415 ret = false;
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -0800416 } else if(isSecondaryConfiguring(ctx)) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800417 ALOGD_IF( isDebug(),"%s: External Display connection is pending",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800418 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700419 ret = false;
Saurabh Shahaa236822013-04-24 18:07:26 -0700420 } else if(ctx->isPaddingRound) {
Raj Kamal9ed3d6b2014-02-07 16:15:17 +0530421 ALOGD_IF(isDebug(), "%s: padding round invoked for dpy %d",
422 __FUNCTION__,mDpy);
Saurabh Shahaa236822013-04-24 18:07:26 -0700423 ret = false;
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700424 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700425 return ret;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800426}
427
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800428void MDPCompNonSplit::trimAgainstROI(hwc_context_t *ctx, hwc_rect_t& fbRect) {
429 hwc_rect_t roi = ctx->listStats[mDpy].lRoi;
430 fbRect = getIntersection(fbRect, roi);
431}
432
433/* 1) Identify layers that are not visible or lying outside the updating ROI and
434 * drop them from composition.
435 * 2) If we have a scaling layer which needs cropping against generated
436 * ROI, reset ROI to full resolution. */
437bool MDPCompNonSplit::validateAndApplyROI(hwc_context_t *ctx,
438 hwc_display_contents_1_t* list) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700439 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800440 hwc_rect_t visibleRect = ctx->listStats[mDpy].lRoi;
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800441
442 for(int i = numAppLayers - 1; i >= 0; i--){
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800443 if(!isValidRect(visibleRect)) {
444 mCurrentFrame.drop[i] = true;
445 mCurrentFrame.dropCount++;
Jeykumar Sankaran0b961452014-01-21 17:26:12 -0800446 continue;
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800447 }
448
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700449 const hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700450 hwc_rect_t dstRect = layer->displayFrame;
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800451 hwc_rect_t res = getIntersection(visibleRect, dstRect);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700452
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700453 if(!isValidRect(res)) {
454 mCurrentFrame.drop[i] = true;
455 mCurrentFrame.dropCount++;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800456 } else {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700457 /* Reset frame ROI when any layer which needs scaling also needs ROI
458 * cropping */
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800459 if(!isSameRect(res, dstRect) && needsScaling (layer)) {
Arpita Banerjeed8965982013-11-08 17:27:33 -0800460 ALOGI("%s: Resetting ROI due to scaling", __FUNCTION__);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700461 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
462 mCurrentFrame.dropCount = 0;
463 return false;
464 }
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800465
Jeykumar Sankaran0b961452014-01-21 17:26:12 -0800466 /* deduct any opaque region from visibleRect */
467 if (layer->blending == HWC_BLENDING_NONE)
468 visibleRect = deductRect(visibleRect, res);
469 }
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700470 }
471 return true;
472}
473
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800474/* Calculate ROI for the frame by accounting all the layer's dispalyFrame which
475 * are updating. If DirtyRegion is applicable, calculate it by accounting all
476 * the changing layer's dirtyRegion. */
477void MDPCompNonSplit::generateROI(hwc_context_t *ctx,
478 hwc_display_contents_1_t* list) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700479 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800480 if(!canPartialUpdate(ctx, list))
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700481 return;
482
483 struct hwc_rect roi = (struct hwc_rect){0, 0, 0, 0};
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800484 hwc_rect fullFrame = (struct hwc_rect) {0, 0,(int)ctx->dpyAttr[mDpy].xres,
485 (int)ctx->dpyAttr[mDpy].yres};
486
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700487 for(int index = 0; index < numAppLayers; index++ ) {
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800488 hwc_layer_1_t* layer = &list->hwLayers[index];
489 if ((mCachedFrame.hnd[index] != layer->handle) ||
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800490 isYuvBuffer((private_handle_t *)layer->handle)) {
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800491 hwc_rect_t updatingRect = layer->displayFrame;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800492
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800493#ifdef QCOM_BSP
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800494 if(!needsScaling(layer) && !layer->transform)
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800495 updatingRect = layer->dirtyRect;
496#endif
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800497
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800498 roi = getUnion(roi, updatingRect);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700499 }
500 }
501
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800502 /* No layer is updating. Still SF wants a refresh.*/
503 if(!isValidRect(roi))
504 return;
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800505
506 // Align ROI coordinates to panel restrictions
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800507 roi = getSanitizeROI(roi, fullFrame);
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800508
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800509 ctx->listStats[mDpy].lRoi = roi;
510 if(!validateAndApplyROI(ctx, list))
511 resetROI(ctx, mDpy);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700512
513 ALOGD_IF(isDebug(),"%s: generated ROI: [%d, %d, %d, %d]", __FUNCTION__,
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800514 ctx->listStats[mDpy].lRoi.left, ctx->listStats[mDpy].lRoi.top,
515 ctx->listStats[mDpy].lRoi.right, ctx->listStats[mDpy].lRoi.bottom);
516}
517
518void MDPCompSplit::trimAgainstROI(hwc_context_t *ctx, hwc_rect_t& fbRect) {
519 hwc_rect l_roi = ctx->listStats[mDpy].lRoi;
520 hwc_rect r_roi = ctx->listStats[mDpy].rRoi;
521
522 hwc_rect_t l_fbRect = getIntersection(fbRect, l_roi);
523 hwc_rect_t r_fbRect = getIntersection(fbRect, r_roi);
524 fbRect = getUnion(l_fbRect, r_fbRect);
525}
526/* 1) Identify layers that are not visible or lying outside BOTH the updating
527 * ROI's and drop them from composition. If a layer is spanning across both
528 * the halves of the screen but needed by only ROI, the non-contributing
529 * half will not be programmed for MDP.
530 * 2) If we have a scaling layer which needs cropping against generated
531 * ROI, reset ROI to full resolution. */
532bool MDPCompSplit::validateAndApplyROI(hwc_context_t *ctx,
533 hwc_display_contents_1_t* list) {
534
535 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
536
537 hwc_rect_t visibleRectL = ctx->listStats[mDpy].lRoi;
538 hwc_rect_t visibleRectR = ctx->listStats[mDpy].rRoi;
539
540 for(int i = numAppLayers - 1; i >= 0; i--){
541 if(!isValidRect(visibleRectL) && !isValidRect(visibleRectR))
542 {
543 mCurrentFrame.drop[i] = true;
544 mCurrentFrame.dropCount++;
545 continue;
546 }
547
548 const hwc_layer_1_t* layer = &list->hwLayers[i];
549 hwc_rect_t dstRect = layer->displayFrame;
550
551 hwc_rect_t l_res = getIntersection(visibleRectL, dstRect);
552 hwc_rect_t r_res = getIntersection(visibleRectR, dstRect);
553 hwc_rect_t res = getUnion(l_res, r_res);
554
555 if(!isValidRect(l_res) && !isValidRect(r_res)) {
556 mCurrentFrame.drop[i] = true;
557 mCurrentFrame.dropCount++;
558 } else {
559 /* Reset frame ROI when any layer which needs scaling also needs ROI
560 * cropping */
561 if(!isSameRect(res, dstRect) && needsScaling (layer)) {
562 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
563 mCurrentFrame.dropCount = 0;
564 return false;
565 }
566
567 if (layer->blending == HWC_BLENDING_NONE) {
568 visibleRectL = deductRect(visibleRectL, l_res);
569 visibleRectR = deductRect(visibleRectR, r_res);
570 }
571 }
572 }
573 return true;
574}
575/* Calculate ROI for the frame by accounting all the layer's dispalyFrame which
576 * are updating. If DirtyRegion is applicable, calculate it by accounting all
577 * the changing layer's dirtyRegion. */
578void MDPCompSplit::generateROI(hwc_context_t *ctx,
579 hwc_display_contents_1_t* list) {
580 if(!canPartialUpdate(ctx, list))
581 return;
582
583 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
584 int lSplit = getLeftSplit(ctx, mDpy);
585
586 int hw_h = (int)ctx->dpyAttr[mDpy].yres;
587 int hw_w = (int)ctx->dpyAttr[mDpy].xres;
588
589 struct hwc_rect l_frame = (struct hwc_rect){0, 0, lSplit, hw_h};
590 struct hwc_rect r_frame = (struct hwc_rect){lSplit, 0, hw_w, hw_h};
591
592 struct hwc_rect l_roi = (struct hwc_rect){0, 0, 0, 0};
593 struct hwc_rect r_roi = (struct hwc_rect){0, 0, 0, 0};
594
595 for(int index = 0; index < numAppLayers; index++ ) {
596 hwc_layer_1_t* layer = &list->hwLayers[index];
597 if ((mCachedFrame.hnd[index] != layer->handle) ||
598 isYuvBuffer((private_handle_t *)layer->handle)) {
Jeykumar Sankaran71e597c2014-05-07 16:23:14 -0700599 hwc_rect_t dst = layer->displayFrame;
600 hwc_rect_t updatingRect = dst;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800601
602#ifdef QCOM_BSP
603 if(!needsScaling(layer) && !layer->transform)
Jeykumar Sankaran71e597c2014-05-07 16:23:14 -0700604 {
605 hwc_rect_t src = integerizeSourceCrop(layer->sourceCropf);
606 int x_off = dst.left - src.left;
607 int y_off = dst.top - src.top;
608 updatingRect = moveRect(layer->dirtyRect, x_off, y_off);
609 }
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800610#endif
611
612 hwc_rect_t l_dst = getIntersection(l_frame, updatingRect);
613 if(isValidRect(l_dst))
614 l_roi = getUnion(l_roi, l_dst);
615
616 hwc_rect_t r_dst = getIntersection(r_frame, updatingRect);
617 if(isValidRect(r_dst))
618 r_roi = getUnion(r_roi, r_dst);
619 }
620 }
621
Jeykumar Sankarana40a9342014-04-25 09:37:10 -0700622 /* For panels that cannot accept commands in both the interfaces, we cannot
623 * send two ROI's (for each half). We merge them into single ROI and split
624 * them across lSplit for MDP mixer use. The ROI's will be merged again
625 * finally before udpating the panel in the driver. */
626 if(qdutils::MDPVersion::getInstance().needsROIMerge()) {
627 hwc_rect_t temp_roi = getUnion(l_roi, r_roi);
628 l_roi = getIntersection(temp_roi, l_frame);
629 r_roi = getIntersection(temp_roi, r_frame);
630 }
631
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800632 /* No layer is updating. Still SF wants a refresh. */
633 if(!isValidRect(l_roi) && !isValidRect(r_roi))
634 return;
635
636 l_roi = getSanitizeROI(l_roi, l_frame);
637 r_roi = getSanitizeROI(r_roi, r_frame);
638
639 ctx->listStats[mDpy].lRoi = l_roi;
640 ctx->listStats[mDpy].rRoi = r_roi;
641
642 if(!validateAndApplyROI(ctx, list))
643 resetROI(ctx, mDpy);
644
645 ALOGD_IF(isDebug(),"%s: generated L_ROI: [%d, %d, %d, %d]"
646 "R_ROI: [%d, %d, %d, %d]", __FUNCTION__,
647 ctx->listStats[mDpy].lRoi.left, ctx->listStats[mDpy].lRoi.top,
648 ctx->listStats[mDpy].lRoi.right, ctx->listStats[mDpy].lRoi.bottom,
649 ctx->listStats[mDpy].rRoi.left, ctx->listStats[mDpy].rRoi.top,
650 ctx->listStats[mDpy].rRoi.right, ctx->listStats[mDpy].rRoi.bottom);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700651}
652
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800653/* Checks for conditions where all the layers marked for MDP comp cannot be
654 * bypassed. On such conditions we try to bypass atleast YUV layers */
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800655bool MDPComp::tryFullFrame(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800656 hwc_display_contents_1_t* list){
657
Saurabh Shahaa236822013-04-24 18:07:26 -0700658 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Arun Kumar K.R2e2871c2014-01-10 12:47:06 -0800659 int priDispW = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800660
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -0700661 if(sIdleFallBack && !ctx->listStats[mDpy].secureUI) {
Saurabh Shah2d998a92013-05-14 17:55:58 -0700662 ALOGD_IF(isDebug(), "%s: Idle fallback dpy %d",__FUNCTION__, mDpy);
663 return false;
664 }
665
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800666 if(isSkipPresent(ctx, mDpy)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700667 ALOGD_IF(isDebug(),"%s: SKIP present: %d",
668 __FUNCTION__,
669 isSkipPresent(ctx, mDpy));
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800670 return false;
671 }
672
Arun Kumar K.R2e2871c2014-01-10 12:47:06 -0800673 if(mDpy > HWC_DISPLAY_PRIMARY && (priDispW > MAX_DISPLAY_DIM) &&
674 (ctx->dpyAttr[mDpy].xres < MAX_DISPLAY_DIM)) {
675 // Disable MDP comp on Secondary when the primary is highres panel and
676 // the secondary is a normal 1080p, because, MDP comp on secondary under
677 // in such usecase, decimation gets used for downscale and there will be
678 // a quality mismatch when there will be a fallback to GPU comp
679 ALOGD_IF(isDebug(), "%s: Disable MDP Compositon for Secondary Disp",
680 __FUNCTION__);
681 return false;
682 }
683
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800684 // check for action safe flag and downscale mode which requires scaling.
685 if(ctx->dpyAttr[mDpy].mActionSafePresent
686 || ctx->dpyAttr[mDpy].mDownScaleMode) {
687 ALOGD_IF(isDebug(), "%s: Scaling needed for this frame",__FUNCTION__);
688 return false;
689 }
690
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800691 for(int i = 0; i < numAppLayers; ++i) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800692 hwc_layer_1_t* layer = &list->hwLayers[i];
693 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800694
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700695 if(isYuvBuffer(hnd) && has90Transform(layer)) {
696 if(!canUseRotator(ctx, mDpy)) {
697 ALOGD_IF(isDebug(), "%s: Can't use rotator for dpy %d",
698 __FUNCTION__, mDpy);
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700699 return false;
700 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800701 }
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530702
703 //For 8x26 with panel width>1k, if RGB layer needs HFLIP fail mdp comp
704 // may not need it if Gfx pre-rotation can handle all flips & rotations
Sushil Chauhanfda00fc2014-03-20 11:08:41 -0700705 int transform = (layer->flags & HWC_COLOR_FILL) ? 0 : layer->transform;
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530706 if(qdutils::MDPVersion::getInstance().is8x26() &&
707 (ctx->dpyAttr[mDpy].xres > 1024) &&
Sushil Chauhanfda00fc2014-03-20 11:08:41 -0700708 (transform & HWC_TRANSFORM_FLIP_H) &&
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530709 (!isYuvBuffer(hnd)))
710 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800711 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700712
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700713 if(ctx->mAD->isDoable()) {
714 return false;
715 }
716
Saurabh Shahaa236822013-04-24 18:07:26 -0700717 //If all above hard conditions are met we can do full or partial MDP comp.
718 bool ret = false;
719 if(fullMDPComp(ctx, list)) {
720 ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700721 } else if(partialMDPComp(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700722 ret = true;
723 }
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530724
Saurabh Shahaa236822013-04-24 18:07:26 -0700725 return ret;
726}
727
728bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaran0ad97c42014-03-09 23:00:53 -0700729
730 if(sSimulationFlags & MDPCOMP_AVOID_FULL_MDP)
731 return false;
732
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700733 //Will benefit presentation / secondary-only layer.
734 if((mDpy > HWC_DISPLAY_PRIMARY) &&
735 (list->numHwLayers - 1) > MAX_SEC_LAYERS) {
736 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
737 return false;
738 }
739
740 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
741 for(int i = 0; i < numAppLayers; i++) {
742 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran880da832014-04-18 10:22:35 -0700743 if(not mCurrentFrame.drop[i] and
744 not isSupportedForMDPComp(ctx, layer)) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700745 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",__FUNCTION__);
746 return false;
747 }
748 }
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800749
Saurabh Shahaa236822013-04-24 18:07:26 -0700750 mCurrentFrame.fbCount = 0;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700751 memcpy(&mCurrentFrame.isFBComposed, &mCurrentFrame.drop,
752 sizeof(mCurrentFrame.isFBComposed));
753 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount -
754 mCurrentFrame.dropCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700755
radhakrishnac9a67412013-09-25 17:40:42 +0530756 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800757 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530758 }
759
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800760 if(!postHeuristicsHandling(ctx, list)) {
761 ALOGD_IF(isDebug(), "post heuristic handling failed");
762 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700763 return false;
764 }
Jeykumar Sankaran0ad97c42014-03-09 23:00:53 -0700765 ALOGD_IF(sSimulationFlags,"%s: FULL_MDP_COMP SUCCEEDED",
766 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700767 return true;
768}
769
770bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
771{
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700772 if(!sEnableMixedMode) {
773 //Mixed mode is disabled. No need to even try caching.
774 return false;
775 }
776
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700777 bool ret = false;
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800778 if(list->flags & HWC_GEOMETRY_CHANGED) { //Try load based first
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800779 ret = loadBasedComp(ctx, list) or
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800780 cacheBasedComp(ctx, list);
781 } else {
782 ret = cacheBasedComp(ctx, list) or
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800783 loadBasedComp(ctx, list);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700784 }
785
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700786 return ret;
787}
788
789bool MDPComp::cacheBasedComp(hwc_context_t *ctx,
790 hwc_display_contents_1_t* list) {
Jeykumar Sankaran0ad97c42014-03-09 23:00:53 -0700791 if(sSimulationFlags & MDPCOMP_AVOID_CACHE_MDP)
792 return false;
793
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700794 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700795 mCurrentFrame.reset(numAppLayers);
796 updateLayerCache(ctx, list);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700797
798 //If an MDP marked layer is unsupported cannot do partial MDP Comp
799 for(int i = 0; i < numAppLayers; i++) {
800 if(!mCurrentFrame.isFBComposed[i]) {
801 hwc_layer_1_t* layer = &list->hwLayers[i];
802 if(not isSupportedForMDPComp(ctx, layer)) {
803 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",
804 __FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800805 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700806 return false;
807 }
808 }
809 }
810
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700811 updateYUV(ctx, list, false /*secure only*/);
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530812 bool ret = markLayersForCaching(ctx, list); //sets up fbZ also
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700813 if(!ret) {
814 ALOGD_IF(isDebug(),"%s: batching failed, dpy %d",__FUNCTION__, mDpy);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800815 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700816 return false;
817 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700818
819 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700820
radhakrishnac9a67412013-09-25 17:40:42 +0530821 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800822 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530823 }
824
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700825 //Will benefit cases where a video has non-updating background.
826 if((mDpy > HWC_DISPLAY_PRIMARY) and
827 (mdpCount > MAX_SEC_LAYERS)) {
828 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800829 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700830 return false;
831 }
832
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800833 if(!postHeuristicsHandling(ctx, list)) {
834 ALOGD_IF(isDebug(), "post heuristic handling failed");
835 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700836 return false;
837 }
Jeykumar Sankaran0ad97c42014-03-09 23:00:53 -0700838 ALOGD_IF(sSimulationFlags,"%s: CACHE_MDP_COMP SUCCEEDED",
839 __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700840
Saurabh Shahaa236822013-04-24 18:07:26 -0700841 return true;
842}
843
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800844bool MDPComp::loadBasedComp(hwc_context_t *ctx,
Saurabh Shahb772ae32013-11-18 15:40:02 -0800845 hwc_display_contents_1_t* list) {
Jeykumar Sankaran0ad97c42014-03-09 23:00:53 -0700846 if(sSimulationFlags & MDPCOMP_AVOID_LOAD_MDP)
847 return false;
848
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -0800849 if(not isLoadBasedCompDoable(ctx)) {
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800850 return false;
851 }
852
Saurabh Shahb772ae32013-11-18 15:40:02 -0800853 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800854 const int numNonDroppedLayers = numAppLayers - mCurrentFrame.dropCount;
855 const int stagesForMDP = min(sMaxPipesPerMixer,
856 ctx->mOverlay->availablePipes(mDpy, Overlay::MIXER_DEFAULT));
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800857
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800858 int mdpBatchSize = stagesForMDP - 1; //1 stage for FB
859 int fbBatchSize = numNonDroppedLayers - mdpBatchSize;
860 int lastMDPSupportedIndex = numAppLayers;
861 int dropCount = 0;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800862
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800863 //Find the minimum MDP batch size
864 for(int i = 0; i < numAppLayers;i++) {
865 if(mCurrentFrame.drop[i]) {
866 dropCount++;
Jeykumar Sankaran846e2792014-01-23 21:59:58 -0800867 continue;
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800868 }
869 hwc_layer_1_t* layer = &list->hwLayers[i];
870 if(not isSupportedForMDPComp(ctx, layer)) {
871 lastMDPSupportedIndex = i;
872 mdpBatchSize = min(i - dropCount, stagesForMDP - 1);
873 fbBatchSize = numNonDroppedLayers - mdpBatchSize;
Jeykumar Sankaran846e2792014-01-23 21:59:58 -0800874 break;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800875 }
Saurabh Shahb772ae32013-11-18 15:40:02 -0800876 }
877
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800878 ALOGD_IF(isDebug(), "%s:Before optimizing fbBatch, mdpbatch %d, fbbatch %d "
879 "dropped %d", __FUNCTION__, mdpBatchSize, fbBatchSize,
880 mCurrentFrame.dropCount);
881
882 //Start at a point where the fb batch should at least have 2 layers, for
883 //this mode to be justified.
884 while(fbBatchSize < 2) {
885 ++fbBatchSize;
886 --mdpBatchSize;
Jeykumar Sankaran846e2792014-01-23 21:59:58 -0800887 }
Saurabh Shahb772ae32013-11-18 15:40:02 -0800888
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800889 //If there are no layers for MDP, this mode doesnt make sense.
890 if(mdpBatchSize < 1) {
891 ALOGD_IF(isDebug(), "%s: No MDP layers after optimizing for fbBatch",
892 __FUNCTION__);
Saurabh Shahb772ae32013-11-18 15:40:02 -0800893 return false;
894 }
895
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800896 mCurrentFrame.reset(numAppLayers);
897
898 //Try with successively smaller mdp batch sizes until we succeed or reach 1
899 while(mdpBatchSize > 0) {
900 //Mark layers for MDP comp
901 int mdpBatchLeft = mdpBatchSize;
902 for(int i = 0; i < lastMDPSupportedIndex and mdpBatchLeft; i++) {
903 if(mCurrentFrame.drop[i]) {
904 continue;
905 }
906 mCurrentFrame.isFBComposed[i] = false;
907 --mdpBatchLeft;
908 }
909
910 mCurrentFrame.fbZ = mdpBatchSize;
911 mCurrentFrame.fbCount = fbBatchSize;
912 mCurrentFrame.mdpCount = mdpBatchSize;
913
914 ALOGD_IF(isDebug(), "%s:Trying with: mdpbatch %d fbbatch %d dropped %d",
915 __FUNCTION__, mdpBatchSize, fbBatchSize,
916 mCurrentFrame.dropCount);
917
918 if(postHeuristicsHandling(ctx, list)) {
919 ALOGD_IF(isDebug(), "%s: Postheuristics handling succeeded",
Jeykumar Sankaran0ad97c42014-03-09 23:00:53 -0700920 __FUNCTION__);
921 ALOGD_IF(sSimulationFlags,"%s: LOAD_MDP_COMP SUCCEEDED",
922 __FUNCTION__);
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800923 return true;
924 }
925
926 reset(ctx);
927 --mdpBatchSize;
928 ++fbBatchSize;
929 }
930
931 return false;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800932}
933
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -0800934bool MDPComp::isLoadBasedCompDoable(hwc_context_t *ctx) {
Prabhanjan Kandula3dbbd882013-12-11 14:43:46 +0530935 if(mDpy or isSecurePresent(ctx, mDpy) or
936 isYuvPresent(ctx, mDpy)) {
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700937 return false;
938 }
939 return true;
940}
941
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800942bool MDPComp::canPartialUpdate(hwc_context_t *ctx,
943 hwc_display_contents_1_t* list){
944 if(!qdutils::MDPVersion::getInstance().isPartialUpdateEnabled() ||
945 isSkipPresent(ctx, mDpy) || (list->flags & HWC_GEOMETRY_CHANGED) ||
946 mDpy ) {
947 return false;
948 }
949 return true;
950}
951
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800952bool MDPComp::tryVideoOnly(hwc_context_t *ctx,
953 hwc_display_contents_1_t* list) {
954 const bool secureOnly = true;
955 return videoOnlyComp(ctx, list, not secureOnly) or
956 videoOnlyComp(ctx, list, secureOnly);
957}
958
959bool MDPComp::videoOnlyComp(hwc_context_t *ctx,
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700960 hwc_display_contents_1_t* list, bool secureOnly) {
Jeykumar Sankaran0ad97c42014-03-09 23:00:53 -0700961 if(sSimulationFlags & MDPCOMP_AVOID_VIDEO_ONLY)
962 return false;
Saurabh Shahaa236822013-04-24 18:07:26 -0700963 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700964
Saurabh Shahaa236822013-04-24 18:07:26 -0700965 mCurrentFrame.reset(numAppLayers);
Jeykumar Sankaraneb3a5e22014-04-08 16:07:55 -0700966 mCurrentFrame.fbCount -= mCurrentFrame.dropCount;
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700967 updateYUV(ctx, list, secureOnly);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700968 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700969
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800970 if(!isYuvPresent(ctx, mDpy) or (mdpCount == 0)) {
971 reset(ctx);
Saurabh Shahaa236822013-04-24 18:07:26 -0700972 return false;
973 }
974
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -0800975 /* Bail out if we are processing only secured video layers
976 * and we dont have any */
977 if(!isSecurePresent(ctx, mDpy) && secureOnly){
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800978 reset(ctx);
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -0800979 return false;
980 }
981
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800982 if(mCurrentFrame.fbCount)
983 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
Saurabh Shah4fdde762013-04-30 18:47:33 -0700984
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800985 if(sEnable4k2kYUVSplit){
986 adjustForSourceSplit(ctx, list);
987 }
988
989 if(!postHeuristicsHandling(ctx, list)) {
990 ALOGD_IF(isDebug(), "post heuristic handling failed");
991 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700992 return false;
993 }
994
Jeykumar Sankaran0ad97c42014-03-09 23:00:53 -0700995 ALOGD_IF(sSimulationFlags,"%s: VIDEO_ONLY_COMP SUCCEEDED",
996 __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800997 return true;
998}
999
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001000/* Checks for conditions where YUV layers cannot be bypassed */
1001bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -07001002 if(isSkipLayer(layer)) {
Saurabh Shahe2474082013-05-15 16:32:13 -07001003 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001004 return false;
1005 }
1006
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -07001007 if(layer->transform & HWC_TRANSFORM_ROT_90 && !canUseRotator(ctx,mDpy)) {
1008 ALOGD_IF(isDebug(), "%s: no free DMA pipe",__FUNCTION__);
1009 return false;
1010 }
1011
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001012 if(isSecuring(ctx, layer)) {
1013 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
1014 return false;
1015 }
1016
Saurabh Shah4fdde762013-04-30 18:47:33 -07001017 if(!isValidDimension(ctx, layer)) {
1018 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
1019 __FUNCTION__);
1020 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001021 }
Saurabh Shah4fdde762013-04-30 18:47:33 -07001022
Naseer Ahmeddc61a972013-07-10 17:50:54 -04001023 if(layer->planeAlpha < 0xFF) {
1024 ALOGD_IF(isDebug(), "%s: Cannot handle YUV layer with plane alpha\
1025 in video only mode",
1026 __FUNCTION__);
1027 return false;
1028 }
1029
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001030 return true;
1031}
1032
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301033/* starts at fromIndex and check for each layer to find
1034 * if it it has overlapping with any Updating layer above it in zorder
1035 * till the end of the batch. returns true if it finds any intersection */
1036bool MDPComp::canPushBatchToTop(const hwc_display_contents_1_t* list,
1037 int fromIndex, int toIndex) {
1038 for(int i = fromIndex; i < toIndex; i++) {
1039 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
1040 if(intersectingUpdatingLayers(list, i+1, toIndex, i)) {
1041 return false;
1042 }
1043 }
1044 }
1045 return true;
1046}
1047
1048/* Checks if given layer at targetLayerIndex has any
1049 * intersection with all the updating layers in beween
1050 * fromIndex and toIndex. Returns true if it finds intersectiion */
1051bool MDPComp::intersectingUpdatingLayers(const hwc_display_contents_1_t* list,
1052 int fromIndex, int toIndex, int targetLayerIndex) {
1053 for(int i = fromIndex; i <= toIndex; i++) {
1054 if(!mCurrentFrame.isFBComposed[i]) {
1055 if(areLayersIntersecting(&list->hwLayers[i],
1056 &list->hwLayers[targetLayerIndex])) {
1057 return true;
1058 }
1059 }
1060 }
1061 return false;
1062}
1063
1064int MDPComp::getBatch(hwc_display_contents_1_t* list,
1065 int& maxBatchStart, int& maxBatchEnd,
1066 int& maxBatchCount) {
1067 int i = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301068 int fbZOrder =-1;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -08001069 int droppedLayerCt = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301070 while (i < mCurrentFrame.layerCount) {
1071 int batchCount = 0;
1072 int batchStart = i;
1073 int batchEnd = i;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -08001074 /* Adjust batch Z order with the dropped layers so far */
1075 int fbZ = batchStart - droppedLayerCt;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301076 int firstZReverseIndex = -1;
Prabhanjan Kandula0ed2cc92013-12-06 12:39:04 +05301077 int updatingLayersAbove = 0;//Updating layer count in middle of batch
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301078 while(i < mCurrentFrame.layerCount) {
1079 if(!mCurrentFrame.isFBComposed[i]) {
1080 if(!batchCount) {
1081 i++;
1082 break;
1083 }
1084 updatingLayersAbove++;
1085 i++;
1086 continue;
1087 } else {
1088 if(mCurrentFrame.drop[i]) {
1089 i++;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -08001090 droppedLayerCt++;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301091 continue;
1092 } else if(updatingLayersAbove <= 0) {
1093 batchCount++;
1094 batchEnd = i;
1095 i++;
1096 continue;
1097 } else { //Layer is FBComposed, not a drop & updatingLayer > 0
1098
1099 // We have a valid updating layer already. If layer-i not
1100 // have overlapping with all updating layers in between
1101 // batch-start and i, then we can add layer i to batch.
1102 if(!intersectingUpdatingLayers(list, batchStart, i-1, i)) {
1103 batchCount++;
1104 batchEnd = i;
1105 i++;
1106 continue;
1107 } else if(canPushBatchToTop(list, batchStart, i)) {
1108 //If All the non-updating layers with in this batch
1109 //does not have intersection with the updating layers
1110 //above in z-order, then we can safely move the batch to
1111 //higher z-order. Increment fbZ as it is moving up.
1112 if( firstZReverseIndex < 0) {
1113 firstZReverseIndex = i;
1114 }
1115 batchCount++;
1116 batchEnd = i;
1117 fbZ += updatingLayersAbove;
1118 i++;
1119 updatingLayersAbove = 0;
1120 continue;
1121 } else {
1122 //both failed.start the loop again from here.
1123 if(firstZReverseIndex >= 0) {
1124 i = firstZReverseIndex;
1125 }
1126 break;
1127 }
1128 }
1129 }
1130 }
1131 if(batchCount > maxBatchCount) {
1132 maxBatchCount = batchCount;
1133 maxBatchStart = batchStart;
1134 maxBatchEnd = batchEnd;
1135 fbZOrder = fbZ;
1136 }
1137 }
1138 return fbZOrder;
1139}
1140
1141bool MDPComp::markLayersForCaching(hwc_context_t* ctx,
1142 hwc_display_contents_1_t* list) {
1143 /* Idea is to keep as many non-updating(cached) layers in FB and
1144 * send rest of them through MDP. This is done in 2 steps.
1145 * 1. Find the maximum contiguous batch of non-updating layers.
1146 * 2. See if we can improve this batch size for caching by adding
1147 * opaque layers around the batch, if they don't have
1148 * any overlapping with the updating layers in between.
1149 * NEVER mark an updating layer for caching.
1150 * But cached ones can be marked for MDP */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001151
1152 int maxBatchStart = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001153 int maxBatchEnd = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001154 int maxBatchCount = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301155 int fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001156
Saurabh Shahd53bc5f2014-02-05 10:17:43 -08001157 /* Nothing is cached. No batching needed */
1158 if(mCurrentFrame.fbCount == 0) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001159 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -07001160 }
Saurabh Shahd53bc5f2014-02-05 10:17:43 -08001161
1162 /* No MDP comp layers, try to use other comp modes */
1163 if(mCurrentFrame.mdpCount == 0) {
1164 return false;
Saurabh Shahaa236822013-04-24 18:07:26 -07001165 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001166
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301167 fbZ = getBatch(list, maxBatchStart, maxBatchEnd, maxBatchCount);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001168
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301169 /* reset rest of the layers lying inside ROI for MDP comp */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001170 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001171 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001172 if((i < maxBatchStart || i > maxBatchEnd) &&
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301173 mCurrentFrame.isFBComposed[i]){
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001174 if(!mCurrentFrame.drop[i]){
1175 //If an unsupported layer is being attempted to
1176 //be pulled out we should fail
1177 if(not isSupportedForMDPComp(ctx, layer)) {
1178 return false;
1179 }
1180 mCurrentFrame.isFBComposed[i] = false;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001181 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001182 }
1183 }
1184
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301185 // update the frame data
1186 mCurrentFrame.fbZ = fbZ;
1187 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001188 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001189 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001190
1191 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301192 mCurrentFrame.fbCount);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001193
1194 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001195}
Saurabh Shah85234ec2013-04-12 17:09:00 -07001196
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001197void MDPComp::updateLayerCache(hwc_context_t* ctx,
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001198 hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001199 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001200 int fbCount = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001201
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001202 for(int i = 0; i < numAppLayers; i++) {
1203 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001204 if(!mCurrentFrame.drop[i])
1205 fbCount++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001206 mCurrentFrame.isFBComposed[i] = true;
1207 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -07001208 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001209 }
1210 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001211
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001212 mCurrentFrame.fbCount = fbCount;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001213 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount
1214 - mCurrentFrame.dropCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001215
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001216 ALOGD_IF(isDebug(),"%s: MDP count: %d FB count %d drop count: %d"
1217 ,__FUNCTION__, mCurrentFrame.mdpCount, mCurrentFrame.fbCount,
1218 mCurrentFrame.dropCount);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001219}
1220
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001221void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list,
1222 bool secureOnly) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001223 int nYuvCount = ctx->listStats[mDpy].yuvCount;
1224 for(int index = 0;index < nYuvCount; index++){
1225 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
1226 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
1227
1228 if(!isYUVDoable(ctx, layer)) {
1229 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
1230 mCurrentFrame.isFBComposed[nYuvIndex] = true;
1231 mCurrentFrame.fbCount++;
1232 }
1233 } else {
1234 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001235 private_handle_t *hnd = (private_handle_t *)layer->handle;
1236 if(!secureOnly || isSecureBuffer(hnd)) {
1237 mCurrentFrame.isFBComposed[nYuvIndex] = false;
1238 mCurrentFrame.fbCount--;
1239 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001240 }
1241 }
1242 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001243
1244 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001245 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
1246 ALOGD_IF(isDebug(),"%s: fb count: %d",__FUNCTION__,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001247 mCurrentFrame.fbCount);
1248}
1249
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001250hwc_rect_t MDPComp::getUpdatingFBRect(hwc_context_t *ctx,
1251 hwc_display_contents_1_t* list){
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001252 hwc_rect_t fbRect = (struct hwc_rect){0, 0, 0, 0};
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001253
1254 /* Update only the region of FB needed for composition */
1255 for(int i = 0; i < mCurrentFrame.layerCount; i++ ) {
1256 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
1257 hwc_layer_1_t* layer = &list->hwLayers[i];
1258 hwc_rect_t dst = layer->displayFrame;
1259 fbRect = getUnion(fbRect, dst);
1260 }
1261 }
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001262 trimAgainstROI(ctx, fbRect);
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001263 return fbRect;
1264}
1265
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001266bool MDPComp::postHeuristicsHandling(hwc_context_t *ctx,
1267 hwc_display_contents_1_t* list) {
1268
1269 //Capability checks
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301270 if(!resourceCheck()) {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001271 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
1272 return false;
1273 }
1274
1275 //Limitations checks
1276 if(!hwLimitationsCheck(ctx, list)) {
1277 ALOGD_IF(isDebug(), "%s: HW limitations",__FUNCTION__);
1278 return false;
1279 }
1280
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001281 //Configure framebuffer first if applicable
1282 if(mCurrentFrame.fbZ >= 0) {
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001283 hwc_rect_t fbRect = getUpdatingFBRect(ctx, list);
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001284 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, fbRect, mCurrentFrame.fbZ))
1285 {
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001286 ALOGD_IF(isDebug(), "%s configure framebuffer failed",
1287 __FUNCTION__);
1288 return false;
1289 }
1290 }
1291
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001292 mCurrentFrame.map();
1293
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001294 if(!allocLayerPipes(ctx, list)) {
1295 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -07001296 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001297 }
1298
1299 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001300 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001301 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001302 int mdpIndex = mCurrentFrame.layerToMDP[index];
1303 hwc_layer_1_t* layer = &list->hwLayers[index];
1304
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301305 //Leave fbZ for framebuffer. CACHE/GLES layers go here.
1306 if(mdpNextZOrder == mCurrentFrame.fbZ) {
1307 mdpNextZOrder++;
1308 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001309 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1310 cur_pipe->zOrder = mdpNextZOrder++;
1311
radhakrishnac9a67412013-09-25 17:40:42 +05301312 private_handle_t *hnd = (private_handle_t *)layer->handle;
1313 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1314 if(configure4k2kYuv(ctx, layer,
1315 mCurrentFrame.mdpToLayer[mdpIndex])
1316 != 0 ){
1317 ALOGD_IF(isDebug(), "%s: Failed to configure split pipes \
1318 for layer %d",__FUNCTION__, index);
1319 return false;
1320 }
1321 else{
1322 mdpNextZOrder++;
1323 }
1324 continue;
1325 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001326 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
1327 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
radhakrishnac9a67412013-09-25 17:40:42 +05301328 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -07001329 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001330 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001331 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001332 }
1333
Saurabh Shaha36be922013-12-16 18:18:39 -08001334 if(!ctx->mOverlay->validateAndSet(mDpy, ctx->dpyAttr[mDpy].fd)) {
1335 ALOGD_IF(isDebug(), "%s: Failed to validate and set overlay for dpy %d"
1336 ,__FUNCTION__, mDpy);
1337 return false;
1338 }
1339
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001340 setRedraw(ctx, list);
Saurabh Shahaa236822013-04-24 18:07:26 -07001341 return true;
1342}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001343
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301344bool MDPComp::resourceCheck() {
Saurabh Shah173f4242013-11-20 09:50:12 -08001345 const bool fbUsed = mCurrentFrame.fbCount;
1346 if(mCurrentFrame.mdpCount > sMaxPipesPerMixer - fbUsed) {
1347 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
1348 return false;
1349 }
Saurabh Shah173f4242013-11-20 09:50:12 -08001350 return true;
1351}
1352
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301353bool MDPComp::hwLimitationsCheck(hwc_context_t* ctx,
1354 hwc_display_contents_1_t* list) {
1355
1356 //A-family hw limitation:
1357 //If a layer need alpha scaling, MDP can not support.
1358 if(ctx->mMDP.version < qdutils::MDSS_V5) {
1359 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1360 if(!mCurrentFrame.isFBComposed[i] &&
1361 isAlphaScaled( &list->hwLayers[i])) {
1362 ALOGD_IF(isDebug(), "%s:frame needs alphaScaling",__FUNCTION__);
1363 return false;
1364 }
1365 }
1366 }
1367
1368 // On 8x26 & 8974 hw, we have a limitation of downscaling+blending.
1369 //If multiple layers requires downscaling and also they are overlapping
1370 //fall back to GPU since MDSS can not handle it.
1371 if(qdutils::MDPVersion::getInstance().is8x74v2() ||
1372 qdutils::MDPVersion::getInstance().is8x26()) {
1373 for(int i = 0; i < mCurrentFrame.layerCount-1; ++i) {
1374 hwc_layer_1_t* botLayer = &list->hwLayers[i];
1375 if(!mCurrentFrame.isFBComposed[i] &&
1376 isDownscaleRequired(botLayer)) {
1377 //if layer-i is marked for MDP and needs downscaling
1378 //check if any MDP layer on top of i & overlaps with layer-i
1379 for(int j = i+1; j < mCurrentFrame.layerCount; ++j) {
1380 hwc_layer_1_t* topLayer = &list->hwLayers[j];
1381 if(!mCurrentFrame.isFBComposed[j] &&
1382 isDownscaleRequired(topLayer)) {
1383 hwc_rect_t r = getIntersection(botLayer->displayFrame,
1384 topLayer->displayFrame);
1385 if(isValidRect(r))
1386 return false;
1387 }
1388 }
1389 }
1390 }
1391 }
1392 return true;
1393}
1394
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001395int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001396 int ret = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -07001397 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran0ad97c42014-03-09 23:00:53 -07001398 char property[PROPERTY_VALUE_MAX];
1399
1400 if(property_get("debug.hwc.simulate", property, NULL) > 0) {
1401 int currentFlags = atoi(property);
1402 if(currentFlags != sSimulationFlags) {
1403 sSimulationFlags = currentFlags;
1404 ALOGE("%s: Simulation Flag read: 0x%x (%d)", __FUNCTION__,
1405 sSimulationFlags, sSimulationFlags);
1406 }
1407 }
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -07001408
Raj Kamal9ed3d6b2014-02-07 16:15:17 +05301409 //Do not cache the information for next draw cycle.
1410 if(numLayers > MAX_NUM_APP_LAYERS or (!numLayers)) {
1411 ALOGI("%s: Unsupported layer count for mdp composition",
1412 __FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001413 mCachedFrame.reset();
1414 return -1;
1415 }
1416
Saurabh Shahb39f8152013-08-22 10:21:44 -07001417 //reset old data
1418 mCurrentFrame.reset(numLayers);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001419 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1420 mCurrentFrame.dropCount = 0;
Prabhanjan Kandula088bd892013-07-02 23:47:13 +05301421
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -07001422 // Detect the start of animation and fall back to GPU only once to cache
1423 // all the layers in FB and display FB content untill animation completes.
1424 if(ctx->listStats[mDpy].isDisplayAnimating) {
1425 mCurrentFrame.needsRedraw = false;
1426 if(ctx->mAnimationState[mDpy] == ANIMATION_STOPPED) {
1427 mCurrentFrame.needsRedraw = true;
1428 ctx->mAnimationState[mDpy] = ANIMATION_STARTED;
1429 }
1430 setMDPCompLayerFlags(ctx, list);
1431 mCachedFrame.updateCounts(mCurrentFrame);
1432 ret = -1;
1433 return ret;
1434 } else {
1435 ctx->mAnimationState[mDpy] = ANIMATION_STOPPED;
1436 }
1437
Saurabh Shahb39f8152013-08-22 10:21:44 -07001438 //Hard conditions, if not met, cannot do MDP comp
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001439 if(isFrameDoable(ctx)) {
1440 generateROI(ctx, list);
Saurabh Shahb39f8152013-08-22 10:21:44 -07001441
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001442 if(tryFullFrame(ctx, list) || tryVideoOnly(ctx, list)) {
1443 setMDPCompLayerFlags(ctx, list);
1444 } else {
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001445 resetROI(ctx, mDpy);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001446 reset(ctx);
1447 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1448 mCurrentFrame.dropCount = 0;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001449 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001450 }
1451 } else {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001452 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
1453 __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001454 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001455 }
Saurabh Shahb39f8152013-08-22 10:21:44 -07001456
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001457 if(isDebug()) {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001458 ALOGD("GEOMETRY change: %d",
1459 (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001460 android::String8 sDump("");
Jeykumar Sankaran6850ac62014-05-27 10:07:26 -07001461 dump(sDump, ctx);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001462 ALOGD("%s",sDump.string());
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001463 }
1464
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001465 mCachedFrame.cacheAll(list);
1466 mCachedFrame.updateCounts(mCurrentFrame);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001467 return ret;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001468}
1469
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001470bool MDPComp::allocSplitVGPipesfor4k2k(hwc_context_t *ctx, int index) {
radhakrishnac9a67412013-09-25 17:40:42 +05301471
1472 bool bRet = true;
radhakrishnac9a67412013-09-25 17:40:42 +05301473 int mdpIndex = mCurrentFrame.layerToMDP[index];
1474 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
1475 info.pipeInfo = new MdpYUVPipeInfo;
1476 info.rot = NULL;
1477 MdpYUVPipeInfo& pipe_info = *(MdpYUVPipeInfo*)info.pipeInfo;
radhakrishnac9a67412013-09-25 17:40:42 +05301478
1479 pipe_info.lIndex = ovutils::OV_INVALID;
1480 pipe_info.rIndex = ovutils::OV_INVALID;
1481
Saurabh Shahc62f3982014-03-05 14:28:26 -08001482 Overlay::PipeSpecs pipeSpecs;
1483 pipeSpecs.formatClass = Overlay::FORMAT_YUV;
1484 pipeSpecs.needsScaling = true;
1485 pipeSpecs.dpy = mDpy;
1486 pipeSpecs.fb = false;
1487
1488 pipe_info.lIndex = ctx->mOverlay->getPipe(pipeSpecs);
radhakrishnac9a67412013-09-25 17:40:42 +05301489 if(pipe_info.lIndex == ovutils::OV_INVALID){
1490 bRet = false;
1491 ALOGD_IF(isDebug(),"%s: allocating first VG pipe failed",
1492 __FUNCTION__);
1493 }
Saurabh Shahc62f3982014-03-05 14:28:26 -08001494 pipe_info.rIndex = ctx->mOverlay->getPipe(pipeSpecs);
radhakrishnac9a67412013-09-25 17:40:42 +05301495 if(pipe_info.rIndex == ovutils::OV_INVALID){
1496 bRet = false;
1497 ALOGD_IF(isDebug(),"%s: allocating second VG pipe failed",
1498 __FUNCTION__);
1499 }
1500 return bRet;
1501}
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001502//=============MDPCompNonSplit==================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001503
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001504void MDPCompNonSplit::adjustForSourceSplit(hwc_context_t *ctx,
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001505 hwc_display_contents_1_t*) {
radhakrishnac9a67412013-09-25 17:40:42 +05301506 //As we split 4kx2k yuv layer and program to 2 VG pipes
1507 //(if available) increase mdpcount accordingly
1508 mCurrentFrame.mdpCount += ctx->listStats[mDpy].yuv4k2kCount;
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001509
1510 //If 4k2k Yuv layer split is possible, and if
1511 //fbz is above 4k2k layer, increment fb zorder by 1
1512 //as we split 4k2k layer and increment zorder for right half
1513 //of the layer
1514 if(mCurrentFrame.fbZ >= 0) {
1515 int n4k2kYuvCount = ctx->listStats[mDpy].yuv4k2kCount;
1516 for(int index = 0; index < n4k2kYuvCount; index++){
1517 int n4k2kYuvIndex =
1518 ctx->listStats[mDpy].yuv4k2kIndices[index];
Dileep Kumar Reddi4cff9282014-04-01 12:57:08 +05301519 if(mCurrentFrame.fbZ >= n4k2kYuvIndex){
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001520 mCurrentFrame.fbZ += 1;
1521 }
1522 }
1523 }
radhakrishnac9a67412013-09-25 17:40:42 +05301524}
1525
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001526/*
1527 * Configures pipe(s) for MDP composition
1528 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001529int MDPCompNonSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001530 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001531 MdpPipeInfoNonSplit& mdp_info =
1532 *(static_cast<MdpPipeInfoNonSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001533 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
1534 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1535 eIsFg isFg = IS_FG_OFF;
1536 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001537
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001538 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
1539 __FUNCTION__, layer, zOrder, dest);
1540
Saurabh Shah88e4d272013-09-03 13:31:29 -07001541 return configureNonSplit(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001542 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001543}
1544
Saurabh Shah88e4d272013-09-03 13:31:29 -07001545bool MDPCompNonSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001546 hwc_display_contents_1_t* list) {
1547 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001548
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001549 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001550
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001551 hwc_layer_1_t* layer = &list->hwLayers[index];
1552 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301553 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001554 if(allocSplitVGPipesfor4k2k(ctx, index)){
radhakrishnac9a67412013-09-25 17:40:42 +05301555 continue;
1556 }
1557 }
1558
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001559 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001560 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001561 info.pipeInfo = new MdpPipeInfoNonSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08001562 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001563 MdpPipeInfoNonSplit& pipe_info = *(MdpPipeInfoNonSplit*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001564
Saurabh Shahc62f3982014-03-05 14:28:26 -08001565 Overlay::PipeSpecs pipeSpecs;
1566 pipeSpecs.formatClass = isYuvBuffer(hnd) ?
1567 Overlay::FORMAT_YUV : Overlay::FORMAT_RGB;
1568 pipeSpecs.needsScaling = qhwc::needsScaling(layer) or
1569 (qdutils::MDPVersion::getInstance().is8x26() and
1570 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres > 1024);
1571 pipeSpecs.dpy = mDpy;
1572 pipeSpecs.fb = false;
Xu Yang1e686f62014-04-08 13:56:47 +08001573 pipeSpecs.numActiveDisplays = ctx->numActiveDisplays;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001574
Saurabh Shahc62f3982014-03-05 14:28:26 -08001575 pipe_info.index = ctx->mOverlay->getPipe(pipeSpecs);
1576
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001577 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001578 ALOGD_IF(isDebug(), "%s: Unable to get pipe", __FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001579 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001580 }
1581 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001582 return true;
1583}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001584
radhakrishnac9a67412013-09-25 17:40:42 +05301585int MDPCompNonSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1586 PipeLayerPair& PipeLayerPair) {
1587 MdpYUVPipeInfo& mdp_info =
1588 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1589 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1590 eIsFg isFg = IS_FG_OFF;
1591 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1592 eDest lDest = mdp_info.lIndex;
1593 eDest rDest = mdp_info.rIndex;
1594
1595 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1596 lDest, rDest, &PipeLayerPair.rot);
1597}
1598
Saurabh Shah88e4d272013-09-03 13:31:29 -07001599bool MDPCompNonSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001600
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001601 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001602 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1603 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -08001604 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001605
1606 if(!ctx || !list) {
1607 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001608 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001609 }
1610
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301611 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1612 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1613 return true;
1614 }
1615
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -08001616 // Set the Handle timeout to true for MDP or MIXED composition.
1617 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount) {
1618 sHandleTimeout = true;
1619 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001620
1621 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001622 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001623
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001624 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1625 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001626 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001627 if(mCurrentFrame.isFBComposed[i]) continue;
1628
Naseer Ahmed5b6708a2012-08-02 13:46:08 -07001629 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001630 private_handle_t *hnd = (private_handle_t *)layer->handle;
1631 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001632 if (!(layer->flags & HWC_COLOR_FILL)) {
1633 ALOGE("%s handle null", __FUNCTION__);
1634 return false;
1635 }
1636 // No PLAY for Color layer
1637 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1638 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001639 }
1640
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001641 int mdpIndex = mCurrentFrame.layerToMDP[i];
1642
radhakrishnac9a67412013-09-25 17:40:42 +05301643 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1644 {
1645 MdpYUVPipeInfo& pipe_info =
1646 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1647 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1648 ovutils::eDest indexL = pipe_info.lIndex;
1649 ovutils::eDest indexR = pipe_info.rIndex;
1650 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301651 uint32_t offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05301652 if(rot) {
1653 rot->queueBuffer(fd, offset);
1654 fd = rot->getDstMemId();
1655 offset = rot->getDstOffset();
1656 }
1657 if(indexL != ovutils::OV_INVALID) {
1658 ovutils::eDest destL = (ovutils::eDest)indexL;
1659 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1660 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1661 if (!ov.queueBuffer(fd, offset, destL)) {
1662 ALOGE("%s: queueBuffer failed for display:%d",
1663 __FUNCTION__, mDpy);
1664 return false;
1665 }
1666 }
1667
1668 if(indexR != ovutils::OV_INVALID) {
1669 ovutils::eDest destR = (ovutils::eDest)indexR;
1670 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1671 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1672 if (!ov.queueBuffer(fd, offset, destR)) {
1673 ALOGE("%s: queueBuffer failed for display:%d",
1674 __FUNCTION__, mDpy);
1675 return false;
1676 }
1677 }
1678 }
1679 else{
1680 MdpPipeInfoNonSplit& pipe_info =
Saurabh Shah88e4d272013-09-03 13:31:29 -07001681 *(MdpPipeInfoNonSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
radhakrishnac9a67412013-09-25 17:40:42 +05301682 ovutils::eDest dest = pipe_info.index;
1683 if(dest == ovutils::OV_INVALID) {
1684 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001685 return false;
radhakrishnac9a67412013-09-25 17:40:42 +05301686 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001687
radhakrishnac9a67412013-09-25 17:40:42 +05301688 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1689 continue;
1690 }
1691
1692 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1693 using pipe: %d", __FUNCTION__, layer,
1694 hnd, dest );
1695
1696 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301697 uint32_t offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05301698
1699 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1700 if(rot) {
1701 if(!rot->queueBuffer(fd, offset))
1702 return false;
1703 fd = rot->getDstMemId();
1704 offset = rot->getDstOffset();
1705 }
1706
1707 if (!ov.queueBuffer(fd, offset, dest)) {
1708 ALOGE("%s: queueBuffer failed for display:%d ",
1709 __FUNCTION__, mDpy);
1710 return false;
1711 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001712 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001713
1714 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001715 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001716 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001717}
1718
Saurabh Shah88e4d272013-09-03 13:31:29 -07001719//=============MDPCompSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001720
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001721void MDPCompSplit::adjustForSourceSplit(hwc_context_t *ctx,
radhakrishnac9a67412013-09-25 17:40:42 +05301722 hwc_display_contents_1_t* list){
1723 //if 4kx2k yuv layer is totally present in either in left half
1724 //or right half then try splitting the yuv layer to avoid decimation
1725 int n4k2kYuvCount = ctx->listStats[mDpy].yuv4k2kCount;
1726 const int lSplit = getLeftSplit(ctx, mDpy);
1727 for(int index = 0; index < n4k2kYuvCount; index++){
1728 int n4k2kYuvIndex = ctx->listStats[mDpy].yuv4k2kIndices[index];
1729 hwc_layer_1_t* layer = &list->hwLayers[n4k2kYuvIndex];
1730 hwc_rect_t dst = layer->displayFrame;
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001731 if((dst.left > lSplit) || (dst.right < lSplit)) {
radhakrishnac9a67412013-09-25 17:40:42 +05301732 mCurrentFrame.mdpCount += 1;
1733 }
Dileep Kumar Reddi4cff9282014-04-01 12:57:08 +05301734 if(mCurrentFrame.fbZ >= n4k2kYuvIndex){
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001735 mCurrentFrame.fbZ += 1;
1736 }
radhakrishnac9a67412013-09-25 17:40:42 +05301737 }
1738}
1739
Saurabh Shah88e4d272013-09-03 13:31:29 -07001740bool MDPCompSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Saurabh Shahc62f3982014-03-05 14:28:26 -08001741 MdpPipeInfoSplit& pipe_info) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001742
Saurabh Shahc62f3982014-03-05 14:28:26 -08001743 const int lSplit = getLeftSplit(ctx, mDpy);
1744 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001745 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001746 pipe_info.lIndex = ovutils::OV_INVALID;
1747 pipe_info.rIndex = ovutils::OV_INVALID;
1748
Saurabh Shahc62f3982014-03-05 14:28:26 -08001749 Overlay::PipeSpecs pipeSpecs;
1750 pipeSpecs.formatClass = isYuvBuffer(hnd) ?
1751 Overlay::FORMAT_YUV : Overlay::FORMAT_RGB;
1752 pipeSpecs.needsScaling = qhwc::needsScalingWithSplit(ctx, layer, mDpy);
1753 pipeSpecs.dpy = mDpy;
1754 pipeSpecs.mixer = Overlay::MIXER_LEFT;
1755 pipeSpecs.fb = false;
1756
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001757 // Acquire pipe only for the updating half
1758 hwc_rect_t l_roi = ctx->listStats[mDpy].lRoi;
1759 hwc_rect_t r_roi = ctx->listStats[mDpy].rRoi;
1760
1761 if (dst.left < lSplit && isValidRect(getIntersection(dst, l_roi))) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001762 pipe_info.lIndex = ctx->mOverlay->getPipe(pipeSpecs);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001763 if(pipe_info.lIndex == ovutils::OV_INVALID)
1764 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001765 }
1766
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001767 if(dst.right > lSplit && isValidRect(getIntersection(dst, r_roi))) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001768 pipeSpecs.mixer = Overlay::MIXER_RIGHT;
1769 pipe_info.rIndex = ctx->mOverlay->getPipe(pipeSpecs);
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001770 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001771 return false;
1772 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001773
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001774 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001775}
1776
Saurabh Shah88e4d272013-09-03 13:31:29 -07001777bool MDPCompSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001778 hwc_display_contents_1_t* list) {
1779 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001780
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001781 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001782
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001783 hwc_layer_1_t* layer = &list->hwLayers[index];
1784 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301785 hwc_rect_t dst = layer->displayFrame;
1786 const int lSplit = getLeftSplit(ctx, mDpy);
1787 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1788 if((dst.left > lSplit)||(dst.right < lSplit)){
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001789 if(allocSplitVGPipesfor4k2k(ctx, index)){
radhakrishnac9a67412013-09-25 17:40:42 +05301790 continue;
1791 }
1792 }
1793 }
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001794 int mdpIndex = mCurrentFrame.layerToMDP[index];
1795 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001796 info.pipeInfo = new MdpPipeInfoSplit;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001797 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001798 MdpPipeInfoSplit& pipe_info = *(MdpPipeInfoSplit*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001799
Saurabh Shahc62f3982014-03-05 14:28:26 -08001800 if(!acquireMDPPipes(ctx, layer, pipe_info)) {
1801 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type",
1802 __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001803 return false;
1804 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001805 }
1806 return true;
1807}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001808
radhakrishnac9a67412013-09-25 17:40:42 +05301809int MDPCompSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1810 PipeLayerPair& PipeLayerPair) {
1811 const int lSplit = getLeftSplit(ctx, mDpy);
1812 hwc_rect_t dst = layer->displayFrame;
1813 if((dst.left > lSplit)||(dst.right < lSplit)){
1814 MdpYUVPipeInfo& mdp_info =
1815 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1816 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1817 eIsFg isFg = IS_FG_OFF;
1818 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1819 eDest lDest = mdp_info.lIndex;
1820 eDest rDest = mdp_info.rIndex;
1821
1822 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1823 lDest, rDest, &PipeLayerPair.rot);
1824 }
1825 else{
1826 return configure(ctx, layer, PipeLayerPair);
1827 }
1828}
1829
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001830/*
1831 * Configures pipe(s) for MDP composition
1832 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001833int MDPCompSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001834 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001835 MdpPipeInfoSplit& mdp_info =
1836 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001837 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1838 eIsFg isFg = IS_FG_OFF;
1839 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1840 eDest lDest = mdp_info.lIndex;
1841 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001842
1843 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1844 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1845
Saurabh Shah88e4d272013-09-03 13:31:29 -07001846 return configureSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001847 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001848}
1849
Saurabh Shah88e4d272013-09-03 13:31:29 -07001850bool MDPCompSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001851
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001852 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001853 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1854 return true;
1855 }
1856
1857 if(!ctx || !list) {
1858 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001859 return false;
1860 }
1861
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301862 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1863 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1864 return true;
1865 }
1866
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -08001867 // Set the Handle timeout to true for MDP or MIXED composition.
1868 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount) {
1869 sHandleTimeout = true;
1870 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001871
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001872 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001873 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001874
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001875 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1876 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001877 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001878 if(mCurrentFrame.isFBComposed[i]) continue;
1879
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001880 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001881 private_handle_t *hnd = (private_handle_t *)layer->handle;
1882 if(!hnd) {
1883 ALOGE("%s handle null", __FUNCTION__);
1884 return false;
1885 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001886
1887 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1888 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001889 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001890
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001891 int mdpIndex = mCurrentFrame.layerToMDP[i];
1892
radhakrishnac9a67412013-09-25 17:40:42 +05301893 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1894 {
1895 MdpYUVPipeInfo& pipe_info =
1896 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1897 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1898 ovutils::eDest indexL = pipe_info.lIndex;
1899 ovutils::eDest indexR = pipe_info.rIndex;
1900 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301901 uint32_t offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05301902 if(rot) {
1903 rot->queueBuffer(fd, offset);
1904 fd = rot->getDstMemId();
1905 offset = rot->getDstOffset();
1906 }
1907 if(indexL != ovutils::OV_INVALID) {
1908 ovutils::eDest destL = (ovutils::eDest)indexL;
1909 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1910 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1911 if (!ov.queueBuffer(fd, offset, destL)) {
1912 ALOGE("%s: queueBuffer failed for display:%d",
1913 __FUNCTION__, mDpy);
1914 return false;
1915 }
1916 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001917
radhakrishnac9a67412013-09-25 17:40:42 +05301918 if(indexR != ovutils::OV_INVALID) {
1919 ovutils::eDest destR = (ovutils::eDest)indexR;
1920 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1921 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1922 if (!ov.queueBuffer(fd, offset, destR)) {
1923 ALOGE("%s: queueBuffer failed for display:%d",
1924 __FUNCTION__, mDpy);
1925 return false;
1926 }
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001927 }
1928 }
radhakrishnac9a67412013-09-25 17:40:42 +05301929 else{
1930 MdpPipeInfoSplit& pipe_info =
1931 *(MdpPipeInfoSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1932 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001933
radhakrishnac9a67412013-09-25 17:40:42 +05301934 ovutils::eDest indexL = pipe_info.lIndex;
1935 ovutils::eDest indexR = pipe_info.rIndex;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001936
radhakrishnac9a67412013-09-25 17:40:42 +05301937 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301938 int offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05301939
Tatenda Chipeperekwa88fe6352014-04-14 10:36:06 -07001940 if(ctx->mAD->draw(ctx, fd, offset)) {
1941 fd = ctx->mAD->getDstFd();
1942 offset = ctx->mAD->getDstOffset();
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001943 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001944
radhakrishnac9a67412013-09-25 17:40:42 +05301945 if(rot) {
1946 rot->queueBuffer(fd, offset);
1947 fd = rot->getDstMemId();
1948 offset = rot->getDstOffset();
1949 }
1950
1951 //************* play left mixer **********
1952 if(indexL != ovutils::OV_INVALID) {
1953 ovutils::eDest destL = (ovutils::eDest)indexL;
1954 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1955 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1956 if (!ov.queueBuffer(fd, offset, destL)) {
1957 ALOGE("%s: queueBuffer failed for left mixer",
1958 __FUNCTION__);
1959 return false;
1960 }
1961 }
1962
1963 //************* play right mixer **********
1964 if(indexR != ovutils::OV_INVALID) {
1965 ovutils::eDest destR = (ovutils::eDest)indexR;
1966 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1967 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1968 if (!ov.queueBuffer(fd, offset, destR)) {
1969 ALOGE("%s: queueBuffer failed for right mixer",
1970 __FUNCTION__);
1971 return false;
1972 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001973 }
1974 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001975
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001976 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1977 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001978
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001979 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001980}
Saurabh Shahab47c692014-02-12 18:45:57 -08001981
1982//================MDPCompSrcSplit==============================================
1983bool MDPCompSrcSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Saurabh Shahc62f3982014-03-05 14:28:26 -08001984 MdpPipeInfoSplit& pipe_info) {
Saurabh Shahab47c692014-02-12 18:45:57 -08001985 private_handle_t *hnd = (private_handle_t *)layer->handle;
1986 hwc_rect_t dst = layer->displayFrame;
1987 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
1988 pipe_info.lIndex = ovutils::OV_INVALID;
1989 pipe_info.rIndex = ovutils::OV_INVALID;
1990
1991 //If 2 pipes are staged on a single stage of a mixer, then the left pipe
1992 //should have a higher priority than the right one. Pipe priorities are
1993 //starting with VG0, VG1 ... , RGB0 ..., DMA1
Saurabh Shahab47c692014-02-12 18:45:57 -08001994
Saurabh Shahc62f3982014-03-05 14:28:26 -08001995 Overlay::PipeSpecs pipeSpecs;
1996 pipeSpecs.formatClass = isYuvBuffer(hnd) ?
1997 Overlay::FORMAT_YUV : Overlay::FORMAT_RGB;
1998 pipeSpecs.needsScaling = qhwc::needsScaling(layer);
1999 pipeSpecs.dpy = mDpy;
2000 pipeSpecs.fb = false;
2001
Saurabh Shahab47c692014-02-12 18:45:57 -08002002 //1 pipe by default for a layer
Saurabh Shahc62f3982014-03-05 14:28:26 -08002003 pipe_info.lIndex = ctx->mOverlay->getPipe(pipeSpecs);
Saurabh Shahab47c692014-02-12 18:45:57 -08002004 if(pipe_info.lIndex == ovutils::OV_INVALID) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08002005 return false;
Saurabh Shahab47c692014-02-12 18:45:57 -08002006 }
2007
2008 //If layer's crop width or dest width > 2048, use 2 pipes
2009 if((dst.right - dst.left) > qdutils::MAX_DISPLAY_DIM or
2010 (crop.right - crop.left) > qdutils::MAX_DISPLAY_DIM) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08002011 pipe_info.rIndex = ctx->mOverlay->getPipe(pipeSpecs);
Saurabh Shahab47c692014-02-12 18:45:57 -08002012 if(pipe_info.rIndex == ovutils::OV_INVALID) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08002013 return false;
Saurabh Shahdd8237a2014-02-28 14:29:09 -08002014 }
2015
2016 // Return values
2017 // 1 Left pipe is higher priority, do nothing.
2018 // 0 Pipes of same priority.
2019 //-1 Right pipe is of higher priority, needs swap.
2020 if(ctx->mOverlay->comparePipePriority(pipe_info.lIndex,
2021 pipe_info.rIndex) == -1) {
2022 qhwc::swap(pipe_info.lIndex, pipe_info.rIndex);
Saurabh Shahab47c692014-02-12 18:45:57 -08002023 }
2024 }
2025
2026 return true;
2027}
2028
Saurabh Shahab47c692014-02-12 18:45:57 -08002029int MDPCompSrcSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
2030 PipeLayerPair& PipeLayerPair) {
2031 private_handle_t *hnd = (private_handle_t *)layer->handle;
2032 if(!hnd) {
2033 ALOGE("%s: layer handle is NULL", __FUNCTION__);
2034 return -1;
2035 }
2036 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
2037 MdpPipeInfoSplit& mdp_info =
2038 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
2039 Rotator **rot = &PipeLayerPair.rot;
2040 eZorder z = static_cast<eZorder>(mdp_info.zOrder);
2041 eIsFg isFg = IS_FG_OFF;
2042 eDest lDest = mdp_info.lIndex;
2043 eDest rDest = mdp_info.rIndex;
2044 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
2045 hwc_rect_t dst = layer->displayFrame;
2046 int transform = layer->transform;
2047 eTransform orient = static_cast<eTransform>(transform);
2048 const int downscale = 0;
2049 int rotFlags = ROT_FLAGS_NONE;
2050 uint32_t format = ovutils::getMdpFormat(hnd->format, isTileRendered(hnd));
2051 Whf whf(getWidth(hnd), getHeight(hnd), format, hnd->size);
2052
2053 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
2054 "dest_pipeR: %d",__FUNCTION__, layer, z, lDest, rDest);
2055
2056 // Handle R/B swap
2057 if (layer->flags & HWC_FORMAT_RB_SWAP) {
2058 if (hnd->format == HAL_PIXEL_FORMAT_RGBA_8888)
2059 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRA_8888);
2060 else if (hnd->format == HAL_PIXEL_FORMAT_RGBX_8888)
2061 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRX_8888);
2062 }
2063
Saurabh Shah97e2d802014-04-14 18:03:54 -07002064 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
2065 setMdpFlags(layer, mdpFlags, 0, transform);
Saurabh Shahab47c692014-02-12 18:45:57 -08002066
2067 if(lDest != OV_INVALID && rDest != OV_INVALID) {
2068 //Enable overfetch
Saurabh Shah97e2d802014-04-14 18:03:54 -07002069 setMdpFlags(mdpFlags, OV_MDSS_MDP_DUAL_PIPE);
Saurabh Shahab47c692014-02-12 18:45:57 -08002070 }
2071
2072 if(isYuvBuffer(hnd) && (transform & HWC_TRANSFORM_ROT_90)) {
2073 (*rot) = ctx->mRotMgr->getNext();
2074 if((*rot) == NULL) return -1;
Saurabh Shah39240c92014-03-31 10:31:42 -07002075 ctx->mLayerRotMap[mDpy]->add(layer, *rot);
Saurabh Shah1bd5b6f2014-05-19 12:23:13 -07002076 //If the video is using a single pipe, enable BWC
2077 if(rDest == OV_INVALID) {
2078 BwcPM::setBwc(crop, dst, transform, mdpFlags);
2079 }
Saurabh Shahab47c692014-02-12 18:45:57 -08002080 //Configure rotator for pre-rotation
Saurabh Shah97e2d802014-04-14 18:03:54 -07002081 if(configRotator(*rot, whf, crop, mdpFlags, orient, downscale) < 0) {
Saurabh Shahab47c692014-02-12 18:45:57 -08002082 ALOGE("%s: configRotator failed!", __FUNCTION__);
2083 return -1;
2084 }
Saurabh Shahab47c692014-02-12 18:45:57 -08002085 whf.format = (*rot)->getDstFormat();
2086 updateSource(orient, whf, crop);
2087 rotFlags |= ROT_PREROTATED;
2088 }
2089
2090 //If 2 pipes being used, divide layer into half, crop and dst
2091 hwc_rect_t cropL = crop;
2092 hwc_rect_t cropR = crop;
2093 hwc_rect_t dstL = dst;
2094 hwc_rect_t dstR = dst;
2095 if(lDest != OV_INVALID && rDest != OV_INVALID) {
2096 cropL.right = (crop.right + crop.left) / 2;
2097 cropR.left = cropL.right;
2098 sanitizeSourceCrop(cropL, cropR, hnd);
2099
2100 //Swap crops on H flip since 2 pipes are being used
2101 if((orient & OVERLAY_TRANSFORM_FLIP_H) && (*rot) == NULL) {
2102 hwc_rect_t tmp = cropL;
2103 cropL = cropR;
2104 cropR = tmp;
2105 }
2106
2107 dstL.right = (dst.right + dst.left) / 2;
2108 dstR.left = dstL.right;
2109 }
2110
2111 //For the mdp, since either we are pre-rotating or MDP does flips
2112 orient = OVERLAY_TRANSFORM_0;
2113 transform = 0;
2114
2115 //configure left pipe
2116 if(lDest != OV_INVALID) {
Saurabh Shah97e2d802014-04-14 18:03:54 -07002117 PipeArgs pargL(mdpFlags, whf, z, isFg,
Saurabh Shahab47c692014-02-12 18:45:57 -08002118 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2119 (ovutils::eBlending) getBlending(layer->blending));
2120
2121 if(configMdp(ctx->mOverlay, pargL, orient,
2122 cropL, dstL, metadata, lDest) < 0) {
2123 ALOGE("%s: commit failed for left mixer config", __FUNCTION__);
2124 return -1;
2125 }
2126 }
2127
2128 //configure right pipe
2129 if(rDest != OV_INVALID) {
Saurabh Shah97e2d802014-04-14 18:03:54 -07002130 PipeArgs pargR(mdpFlags, whf, z, isFg,
Saurabh Shahab47c692014-02-12 18:45:57 -08002131 static_cast<eRotFlags>(rotFlags),
2132 layer->planeAlpha,
2133 (ovutils::eBlending) getBlending(layer->blending));
2134 if(configMdp(ctx->mOverlay, pargR, orient,
2135 cropR, dstR, metadata, rDest) < 0) {
2136 ALOGE("%s: commit failed for right mixer config", __FUNCTION__);
2137 return -1;
2138 }
2139 }
2140
2141 return 0;
2142}
2143
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002144}; //namespace
2145