blob: 06e0b1261e649ef19434e2e209971adce278d084 [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
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080061void MDPComp::dump(android::String8& buf)
62{
Jeykumar Sankaran3c6bb042013-08-15 14:01:04 -070063 if(mCurrentFrame.layerCount > MAX_NUM_APP_LAYERS)
64 return;
65
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080066 dumpsys_log(buf,"HWC Map for Dpy: %s \n",
Jeykumar Sankaran27dee262013-08-01 17:09:54 -070067 (mDpy == 0) ? "\"PRIMARY\"" :
68 (mDpy == 1) ? "\"EXTERNAL\"" : "\"VIRTUAL\"");
Saurabh Shahe9bc60f2013-08-29 12:58:06 -070069 dumpsys_log(buf,"CURR_FRAME: layerCount:%2d mdpCount:%2d "
70 "fbCount:%2d \n", mCurrentFrame.layerCount,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080071 mCurrentFrame.mdpCount, mCurrentFrame.fbCount);
72 dumpsys_log(buf,"needsFBRedraw:%3s pipesUsed:%2d MaxPipesPerMixer: %d \n",
73 (mCurrentFrame.needsRedraw? "YES" : "NO"),
74 mCurrentFrame.mdpCount, sMaxPipesPerMixer);
75 dumpsys_log(buf," --------------------------------------------- \n");
76 dumpsys_log(buf," listIdx | cached? | mdpIndex | comptype | Z \n");
77 dumpsys_log(buf," --------------------------------------------- \n");
78 for(int index = 0; index < mCurrentFrame.layerCount; index++ )
79 dumpsys_log(buf," %7d | %7s | %8d | %9s | %2d \n",
80 index,
81 (mCurrentFrame.isFBComposed[index] ? "YES" : "NO"),
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -070082 mCurrentFrame.layerToMDP[index],
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080083 (mCurrentFrame.isFBComposed[index] ?
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -070084 (mCurrentFrame.drop[index] ? "DROP" :
85 (mCurrentFrame.needsRedraw ? "GLES" : "CACHE")) : "MDP"),
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080086 (mCurrentFrame.isFBComposed[index] ? mCurrentFrame.fbZ :
87 mCurrentFrame.mdpToLayer[mCurrentFrame.layerToMDP[index]].pipeInfo->zOrder));
88 dumpsys_log(buf,"\n");
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080089}
90
91bool MDPComp::init(hwc_context_t *ctx) {
92
93 if(!ctx) {
94 ALOGE("%s: Invalid hwc context!!",__FUNCTION__);
95 return false;
96 }
97
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080098 char property[PROPERTY_VALUE_MAX];
99
100 sEnabled = false;
101 if((property_get("persist.hwc.mdpcomp.enable", property, NULL) > 0) &&
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800102 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
103 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800104 sEnabled = true;
105 }
106
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700107 sEnableMixedMode = true;
108 if((property_get("debug.mdpcomp.mixedmode.disable", property, NULL) > 0) &&
109 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
110 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
111 sEnableMixedMode = false;
112 }
113
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800114 if(property_get("debug.mdpcomp.logs", property, NULL) > 0) {
115 if(atoi(property) != 0)
116 sDebugLogs = true;
117 }
118
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800119 sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
Saurabh Shah85234ec2013-04-12 17:09:00 -0700120 if(property_get("debug.mdpcomp.maxpermixer", property, "-1") > 0) {
121 int val = atoi(property);
122 if(val >= 0)
123 sMaxPipesPerMixer = min(val, MAX_PIPES_PER_MIXER);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800124 }
125
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400126 if(ctx->mMDP.panel != MIPI_CMD_PANEL) {
127 // Idle invalidation is not necessary on command mode panels
128 long idle_timeout = DEFAULT_IDLE_TIME;
129 if(property_get("debug.mdpcomp.idletime", property, NULL) > 0) {
130 if(atoi(property) != 0)
131 idle_timeout = atoi(property);
132 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800133
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400134 //create Idle Invalidator only when not disabled through property
135 if(idle_timeout != -1)
136 idleInvalidator = IdleInvalidator::getInstance();
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800137
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400138 if(idleInvalidator == NULL) {
139 ALOGE("%s: failed to instantiate idleInvalidator object",
140 __FUNCTION__);
141 } else {
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530142 idleInvalidator->init(timeout_handler, ctx,
143 (unsigned int)idle_timeout);
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400144 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800145 }
radhakrishnac9a67412013-09-25 17:40:42 +0530146
147 if((property_get("debug.mdpcomp.4k2kSplit", property, "0") > 0) &&
148 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
149 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
150 sEnable4k2kYUVSplit = true;
151 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700152 return true;
153}
154
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800155void MDPComp::reset(hwc_context_t *ctx) {
156 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700157 mCurrentFrame.reset(numLayers);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800158 ctx->mOverlay->clear(mDpy);
159 ctx->mLayerRotMap[mDpy]->clear();
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700160}
161
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700162void MDPComp::timeout_handler(void *udata) {
163 struct hwc_context_t* ctx = (struct hwc_context_t*)(udata);
164
165 if(!ctx) {
166 ALOGE("%s: received empty data in timer callback", __FUNCTION__);
167 return;
168 }
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -0800169 Locker::Autolock _l(ctx->mDrawLock);
170 // Handle timeout event only if the previous composition is MDP or MIXED.
171 if(!sHandleTimeout) {
172 ALOGD_IF(isDebug(), "%s:Do not handle this timeout", __FUNCTION__);
173 return;
174 }
Jesse Hall3be78d92012-08-21 15:12:23 -0700175 if(!ctx->proc) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700176 ALOGE("%s: HWC proc not registered", __FUNCTION__);
177 return;
178 }
179 sIdleFallBack = true;
180 /* Trigger SF to redraw the current frame */
Jesse Hall3be78d92012-08-21 15:12:23 -0700181 ctx->proc->invalidate(ctx->proc);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700182}
183
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800184void MDPComp::setMDPCompLayerFlags(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800185 hwc_display_contents_1_t* list) {
186 LayerProp *layerProp = ctx->layerProp[mDpy];
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800187
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800188 for(int index = 0; index < ctx->listStats[mDpy].numAppLayers; index++) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800189 hwc_layer_1_t* layer = &(list->hwLayers[index]);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800190 if(!mCurrentFrame.isFBComposed[index]) {
191 layerProp[index].mFlags |= HWC_MDPCOMP;
192 layer->compositionType = HWC_OVERLAY;
193 layer->hints |= HWC_HINT_CLEAR_FB;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800194 } else {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700195 /* Drop the layer when its already present in FB OR when it lies
196 * outside frame's ROI */
197 if(!mCurrentFrame.needsRedraw || mCurrentFrame.drop[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800198 layer->compositionType = HWC_OVERLAY;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700199 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800200 }
201 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700202}
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500203
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800204void MDPComp::setRedraw(hwc_context_t *ctx,
205 hwc_display_contents_1_t* list) {
206 mCurrentFrame.needsRedraw = false;
207 if(!mCachedFrame.isSameFrame(mCurrentFrame, list) ||
208 (list->flags & HWC_GEOMETRY_CHANGED) ||
209 isSkipPresent(ctx, mDpy)) {
210 mCurrentFrame.needsRedraw = true;
211 }
212}
213
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800214MDPComp::FrameInfo::FrameInfo() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700215 reset(0);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800216}
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800217
Saurabh Shahaa236822013-04-24 18:07:26 -0700218void MDPComp::FrameInfo::reset(const int& numLayers) {
219 for(int i = 0 ; i < MAX_PIPES_PER_MIXER && numLayers; i++ ) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800220 if(mdpToLayer[i].pipeInfo) {
221 delete mdpToLayer[i].pipeInfo;
222 mdpToLayer[i].pipeInfo = NULL;
223 //We dont own the rotator
224 mdpToLayer[i].rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800225 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800226 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800227
228 memset(&mdpToLayer, 0, sizeof(mdpToLayer));
229 memset(&layerToMDP, -1, sizeof(layerToMDP));
Saurabh Shahaa236822013-04-24 18:07:26 -0700230 memset(&isFBComposed, 1, sizeof(isFBComposed));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800231
Saurabh Shahaa236822013-04-24 18:07:26 -0700232 layerCount = numLayers;
233 fbCount = numLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800234 mdpCount = 0;
Saurabh Shah2f3895f2013-05-02 10:13:31 -0700235 needsRedraw = true;
Saurabh Shahd53bc5f2014-02-05 10:17:43 -0800236 fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800237}
238
Saurabh Shahaa236822013-04-24 18:07:26 -0700239void MDPComp::FrameInfo::map() {
240 // populate layer and MDP maps
241 int mdpIdx = 0;
242 for(int idx = 0; idx < layerCount; idx++) {
243 if(!isFBComposed[idx]) {
244 mdpToLayer[mdpIdx].listIndex = idx;
245 layerToMDP[idx] = mdpIdx++;
246 }
247 }
248}
249
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800250MDPComp::LayerCache::LayerCache() {
251 reset();
252}
253
254void MDPComp::LayerCache::reset() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700255 memset(&hnd, 0, sizeof(hnd));
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530256 memset(&isFBComposed, true, sizeof(isFBComposed));
257 memset(&drop, false, sizeof(drop));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800258 layerCount = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -0700259}
260
261void MDPComp::LayerCache::cacheAll(hwc_display_contents_1_t* list) {
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530262 const int numAppLayers = (int)list->numHwLayers - 1;
Saurabh Shahaa236822013-04-24 18:07:26 -0700263 for(int i = 0; i < numAppLayers; i++) {
264 hnd[i] = list->hwLayers[i].handle;
265 }
266}
267
268void MDPComp::LayerCache::updateCounts(const FrameInfo& curFrame) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700269 layerCount = curFrame.layerCount;
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530270 memcpy(&isFBComposed, &curFrame.isFBComposed, sizeof(isFBComposed));
271 memcpy(&drop, &curFrame.drop, sizeof(drop));
272}
273
Jeykumar Sankaran988d3682013-11-15 11:57:16 -0800274bool MDPComp::LayerCache::isSameFrame(const FrameInfo& curFrame,
275 hwc_display_contents_1_t* list) {
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530276 if(layerCount != curFrame.layerCount)
277 return false;
278 for(int i = 0; i < curFrame.layerCount; i++) {
279 if((curFrame.isFBComposed[i] != isFBComposed[i]) ||
280 (curFrame.drop[i] != drop[i])) {
281 return false;
282 }
Jeykumar Sankaran988d3682013-11-15 11:57:16 -0800283 if(curFrame.isFBComposed[i] &&
284 (hnd[i] != list->hwLayers[i].handle)){
285 return false;
286 }
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530287 }
288 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800289}
290
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700291bool MDPComp::isSupportedForMDPComp(hwc_context_t *ctx, hwc_layer_1_t* layer) {
292 private_handle_t *hnd = (private_handle_t *)layer->handle;
293 if((not isYuvBuffer(hnd) and has90Transform(layer)) or
294 (not isValidDimension(ctx,layer))
295 //More conditions here, SKIP, sRGB+Blend etc
296 ) {
297 return false;
298 }
299 return true;
300}
301
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530302bool MDPComp::isValidDimension(hwc_context_t *ctx, hwc_layer_1_t *layer) {
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800303 private_handle_t *hnd = (private_handle_t *)layer->handle;
304
305 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -0700306 if (layer->flags & HWC_COLOR_FILL) {
307 // Color layer
308 return true;
309 }
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800310 ALOGE("%s: layer handle is NULL", __FUNCTION__);
311 return false;
312 }
313
Naseer Ahmede850a802013-09-06 13:12:52 -0400314 //XXX: Investigate doing this with pixel phase on MDSS
Naseer Ahmede77f8082013-10-10 13:42:48 -0400315 if(!isSecureBuffer(hnd) && isNonIntegralSourceCrop(layer->sourceCropf))
Naseer Ahmede850a802013-09-06 13:12:52 -0400316 return false;
317
Saurabh Shah62e1d732013-09-17 10:44:05 -0700318 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700319 hwc_rect_t dst = layer->displayFrame;
Saurabh Shah4fdde762013-04-30 18:47:33 -0700320 int crop_w = crop.right - crop.left;
321 int crop_h = crop.bottom - crop.top;
322 int dst_w = dst.right - dst.left;
323 int dst_h = dst.bottom - dst.top;
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800324 float w_scale = ((float)crop_w / (float)dst_w);
325 float h_scale = ((float)crop_h / (float)dst_h);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700326
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800327 /* Workaround for MDP HW limitation in DSI command mode panels where
328 * FPS will not go beyond 30 if buffers on RGB pipes are of width or height
329 * less than 5 pixels
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530330 * There also is a HW limilation in MDP, minimum block size is 2x2
331 * Fallback to GPU if height is less than 2.
332 */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800333 if((crop_w < 5)||(crop_h < 5))
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800334 return false;
335
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800336 if((w_scale > 1.0f) || (h_scale > 1.0f)) {
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700337 const uint32_t maxMDPDownscale =
Saurabh Shah4fdde762013-04-30 18:47:33 -0700338 qdutils::MDPVersion::getInstance().getMaxMDPDownscale();
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800339 const float w_dscale = w_scale;
340 const float h_dscale = h_scale;
341
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800342 if(ctx->mMDP.version >= qdutils::MDSS_V5) {
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700343
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800344 if(!qdutils::MDPVersion::getInstance().supportsDecimation()) {
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700345 /* On targets that doesnt support Decimation (eg.,8x26)
346 * maximum downscale support is overlay pipe downscale.
347 */
348 if(crop_w > MAX_DISPLAY_DIM || w_dscale > maxMDPDownscale ||
349 h_dscale > maxMDPDownscale)
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800350 return false;
351 } else {
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700352 // Decimation on macrotile format layers is not supported.
353 if(isTileRendered(hnd)) {
354 /* MDP can read maximum MAX_DISPLAY_DIM width.
355 * Bail out if
356 * 1. Src crop > MAX_DISPLAY_DIM on nonsplit MDPComp
357 * 2. exceeds maximum downscale limit
358 */
359 if(((crop_w > MAX_DISPLAY_DIM) && !sSrcSplitEnabled) ||
360 w_dscale > maxMDPDownscale ||
361 h_dscale > maxMDPDownscale) {
362 return false;
363 }
364 } else if(w_dscale > 64 || h_dscale > 64)
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800365 return false;
366 }
367 } else { //A-family
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700368 if(w_dscale > maxMDPDownscale || h_dscale > maxMDPDownscale)
Saurabh Shah4fdde762013-04-30 18:47:33 -0700369 return false;
370 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700371 }
372
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800373 if((w_scale < 1.0f) || (h_scale < 1.0f)) {
374 const uint32_t upscale =
375 qdutils::MDPVersion::getInstance().getMaxMDPUpscale();
376 const float w_uscale = 1.0f / w_scale;
377 const float h_uscale = 1.0f / h_scale;
378
379 if(w_uscale > upscale || h_uscale > upscale)
380 return false;
381 }
382
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800383 return true;
384}
385
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800386bool MDPComp::isFrameDoable(hwc_context_t *ctx) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700387 bool ret = true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800388
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800389 if(!isEnabled()) {
390 ALOGD_IF(isDebug(),"%s: MDP Comp. not enabled.", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700391 ret = false;
Raj Kamal068f4572014-04-14 16:14:06 +0530392 } else if((qdutils::MDPVersion::getInstance().is8x26() ||
Prabhanjan Kandula958ffa92014-05-12 14:56:56 +0530393 qdutils::MDPVersion::getInstance().is8x16() ||
394 qdutils::MDPVersion::getInstance().is8x39()) &&
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -0800395 ctx->mVideoTransFlag &&
396 isSecondaryConnected(ctx)) {
Saurabh Shahd4e65852013-06-17 11:33:53 -0700397 //1 Padding round to shift pipes across mixers
398 ALOGD_IF(isDebug(),"%s: MDP Comp. video transition padding round",
399 __FUNCTION__);
400 ret = false;
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -0800401 } else if(isSecondaryConfiguring(ctx)) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800402 ALOGD_IF( isDebug(),"%s: External Display connection is pending",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800403 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700404 ret = false;
Saurabh Shahaa236822013-04-24 18:07:26 -0700405 } else if(ctx->isPaddingRound) {
Raj Kamal9ed3d6b2014-02-07 16:15:17 +0530406 ALOGD_IF(isDebug(), "%s: padding round invoked for dpy %d",
407 __FUNCTION__,mDpy);
Saurabh Shahaa236822013-04-24 18:07:26 -0700408 ret = false;
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700409 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700410 return ret;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800411}
412
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800413void MDPCompNonSplit::trimAgainstROI(hwc_context_t *ctx, hwc_rect_t& fbRect) {
414 hwc_rect_t roi = ctx->listStats[mDpy].lRoi;
415 fbRect = getIntersection(fbRect, roi);
416}
417
418/* 1) Identify layers that are not visible or lying outside the updating ROI and
419 * drop them from composition.
420 * 2) If we have a scaling layer which needs cropping against generated
421 * ROI, reset ROI to full resolution. */
422bool MDPCompNonSplit::validateAndApplyROI(hwc_context_t *ctx,
423 hwc_display_contents_1_t* list) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700424 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800425 hwc_rect_t visibleRect = ctx->listStats[mDpy].lRoi;
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800426
427 for(int i = numAppLayers - 1; i >= 0; i--){
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800428 if(!isValidRect(visibleRect)) {
429 mCurrentFrame.drop[i] = true;
430 mCurrentFrame.dropCount++;
Jeykumar Sankaran0b961452014-01-21 17:26:12 -0800431 continue;
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800432 }
433
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700434 const hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700435 hwc_rect_t dstRect = layer->displayFrame;
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800436 hwc_rect_t res = getIntersection(visibleRect, dstRect);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700437
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700438 if(!isValidRect(res)) {
439 mCurrentFrame.drop[i] = true;
440 mCurrentFrame.dropCount++;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800441 } else {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700442 /* Reset frame ROI when any layer which needs scaling also needs ROI
443 * cropping */
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800444 if(!isSameRect(res, dstRect) && needsScaling (layer)) {
Arpita Banerjeed8965982013-11-08 17:27:33 -0800445 ALOGI("%s: Resetting ROI due to scaling", __FUNCTION__);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700446 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
447 mCurrentFrame.dropCount = 0;
448 return false;
449 }
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800450
Jeykumar Sankaran0b961452014-01-21 17:26:12 -0800451 /* deduct any opaque region from visibleRect */
452 if (layer->blending == HWC_BLENDING_NONE)
453 visibleRect = deductRect(visibleRect, res);
454 }
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700455 }
456 return true;
457}
458
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800459/* Calculate ROI for the frame by accounting all the layer's dispalyFrame which
460 * are updating. If DirtyRegion is applicable, calculate it by accounting all
461 * the changing layer's dirtyRegion. */
462void MDPCompNonSplit::generateROI(hwc_context_t *ctx,
463 hwc_display_contents_1_t* list) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700464 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800465 if(!canPartialUpdate(ctx, list))
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700466 return;
467
468 struct hwc_rect roi = (struct hwc_rect){0, 0, 0, 0};
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800469 hwc_rect fullFrame = (struct hwc_rect) {0, 0,(int)ctx->dpyAttr[mDpy].xres,
470 (int)ctx->dpyAttr[mDpy].yres};
471
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700472 for(int index = 0; index < numAppLayers; index++ ) {
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800473 hwc_layer_1_t* layer = &list->hwLayers[index];
474 if ((mCachedFrame.hnd[index] != layer->handle) ||
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800475 isYuvBuffer((private_handle_t *)layer->handle)) {
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800476 hwc_rect_t updatingRect = layer->displayFrame;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800477
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800478#ifdef QCOM_BSP
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800479 if(!needsScaling(layer) && !layer->transform)
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800480 updatingRect = layer->dirtyRect;
481#endif
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800482
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800483 roi = getUnion(roi, updatingRect);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700484 }
485 }
486
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800487 /* No layer is updating. Still SF wants a refresh.*/
488 if(!isValidRect(roi))
489 return;
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800490
491 // Align ROI coordinates to panel restrictions
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800492 roi = getSanitizeROI(roi, fullFrame);
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800493
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800494 ctx->listStats[mDpy].lRoi = roi;
495 if(!validateAndApplyROI(ctx, list))
496 resetROI(ctx, mDpy);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700497
498 ALOGD_IF(isDebug(),"%s: generated ROI: [%d, %d, %d, %d]", __FUNCTION__,
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800499 ctx->listStats[mDpy].lRoi.left, ctx->listStats[mDpy].lRoi.top,
500 ctx->listStats[mDpy].lRoi.right, ctx->listStats[mDpy].lRoi.bottom);
501}
502
503void MDPCompSplit::trimAgainstROI(hwc_context_t *ctx, hwc_rect_t& fbRect) {
504 hwc_rect l_roi = ctx->listStats[mDpy].lRoi;
505 hwc_rect r_roi = ctx->listStats[mDpy].rRoi;
506
507 hwc_rect_t l_fbRect = getIntersection(fbRect, l_roi);
508 hwc_rect_t r_fbRect = getIntersection(fbRect, r_roi);
509 fbRect = getUnion(l_fbRect, r_fbRect);
510}
511/* 1) Identify layers that are not visible or lying outside BOTH the updating
512 * ROI's and drop them from composition. If a layer is spanning across both
513 * the halves of the screen but needed by only ROI, the non-contributing
514 * half will not be programmed for MDP.
515 * 2) If we have a scaling layer which needs cropping against generated
516 * ROI, reset ROI to full resolution. */
517bool MDPCompSplit::validateAndApplyROI(hwc_context_t *ctx,
518 hwc_display_contents_1_t* list) {
519
520 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
521
522 hwc_rect_t visibleRectL = ctx->listStats[mDpy].lRoi;
523 hwc_rect_t visibleRectR = ctx->listStats[mDpy].rRoi;
524
525 for(int i = numAppLayers - 1; i >= 0; i--){
526 if(!isValidRect(visibleRectL) && !isValidRect(visibleRectR))
527 {
528 mCurrentFrame.drop[i] = true;
529 mCurrentFrame.dropCount++;
530 continue;
531 }
532
533 const hwc_layer_1_t* layer = &list->hwLayers[i];
534 hwc_rect_t dstRect = layer->displayFrame;
535
536 hwc_rect_t l_res = getIntersection(visibleRectL, dstRect);
537 hwc_rect_t r_res = getIntersection(visibleRectR, dstRect);
538 hwc_rect_t res = getUnion(l_res, r_res);
539
540 if(!isValidRect(l_res) && !isValidRect(r_res)) {
541 mCurrentFrame.drop[i] = true;
542 mCurrentFrame.dropCount++;
543 } else {
544 /* Reset frame ROI when any layer which needs scaling also needs ROI
545 * cropping */
546 if(!isSameRect(res, dstRect) && needsScaling (layer)) {
547 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
548 mCurrentFrame.dropCount = 0;
549 return false;
550 }
551
552 if (layer->blending == HWC_BLENDING_NONE) {
553 visibleRectL = deductRect(visibleRectL, l_res);
554 visibleRectR = deductRect(visibleRectR, r_res);
555 }
556 }
557 }
558 return true;
559}
560/* Calculate ROI for the frame by accounting all the layer's dispalyFrame which
561 * are updating. If DirtyRegion is applicable, calculate it by accounting all
562 * the changing layer's dirtyRegion. */
563void MDPCompSplit::generateROI(hwc_context_t *ctx,
564 hwc_display_contents_1_t* list) {
565 if(!canPartialUpdate(ctx, list))
566 return;
567
568 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
569 int lSplit = getLeftSplit(ctx, mDpy);
570
571 int hw_h = (int)ctx->dpyAttr[mDpy].yres;
572 int hw_w = (int)ctx->dpyAttr[mDpy].xres;
573
574 struct hwc_rect l_frame = (struct hwc_rect){0, 0, lSplit, hw_h};
575 struct hwc_rect r_frame = (struct hwc_rect){lSplit, 0, hw_w, hw_h};
576
577 struct hwc_rect l_roi = (struct hwc_rect){0, 0, 0, 0};
578 struct hwc_rect r_roi = (struct hwc_rect){0, 0, 0, 0};
579
580 for(int index = 0; index < numAppLayers; index++ ) {
581 hwc_layer_1_t* layer = &list->hwLayers[index];
582 if ((mCachedFrame.hnd[index] != layer->handle) ||
583 isYuvBuffer((private_handle_t *)layer->handle)) {
Jeykumar Sankaran71e597c2014-05-07 16:23:14 -0700584 hwc_rect_t dst = layer->displayFrame;
585 hwc_rect_t updatingRect = dst;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800586
587#ifdef QCOM_BSP
588 if(!needsScaling(layer) && !layer->transform)
Jeykumar Sankaran71e597c2014-05-07 16:23:14 -0700589 {
590 hwc_rect_t src = integerizeSourceCrop(layer->sourceCropf);
591 int x_off = dst.left - src.left;
592 int y_off = dst.top - src.top;
593 updatingRect = moveRect(layer->dirtyRect, x_off, y_off);
594 }
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800595#endif
596
597 hwc_rect_t l_dst = getIntersection(l_frame, updatingRect);
598 if(isValidRect(l_dst))
599 l_roi = getUnion(l_roi, l_dst);
600
601 hwc_rect_t r_dst = getIntersection(r_frame, updatingRect);
602 if(isValidRect(r_dst))
603 r_roi = getUnion(r_roi, r_dst);
604 }
605 }
606
Jeykumar Sankarana40a9342014-04-25 09:37:10 -0700607 /* For panels that cannot accept commands in both the interfaces, we cannot
608 * send two ROI's (for each half). We merge them into single ROI and split
609 * them across lSplit for MDP mixer use. The ROI's will be merged again
610 * finally before udpating the panel in the driver. */
611 if(qdutils::MDPVersion::getInstance().needsROIMerge()) {
612 hwc_rect_t temp_roi = getUnion(l_roi, r_roi);
613 l_roi = getIntersection(temp_roi, l_frame);
614 r_roi = getIntersection(temp_roi, r_frame);
615 }
616
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800617 /* No layer is updating. Still SF wants a refresh. */
618 if(!isValidRect(l_roi) && !isValidRect(r_roi))
619 return;
620
621 l_roi = getSanitizeROI(l_roi, l_frame);
622 r_roi = getSanitizeROI(r_roi, r_frame);
623
624 ctx->listStats[mDpy].lRoi = l_roi;
625 ctx->listStats[mDpy].rRoi = r_roi;
626
627 if(!validateAndApplyROI(ctx, list))
628 resetROI(ctx, mDpy);
629
630 ALOGD_IF(isDebug(),"%s: generated L_ROI: [%d, %d, %d, %d]"
631 "R_ROI: [%d, %d, %d, %d]", __FUNCTION__,
632 ctx->listStats[mDpy].lRoi.left, ctx->listStats[mDpy].lRoi.top,
633 ctx->listStats[mDpy].lRoi.right, ctx->listStats[mDpy].lRoi.bottom,
634 ctx->listStats[mDpy].rRoi.left, ctx->listStats[mDpy].rRoi.top,
635 ctx->listStats[mDpy].rRoi.right, ctx->listStats[mDpy].rRoi.bottom);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700636}
637
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800638/* Checks for conditions where all the layers marked for MDP comp cannot be
639 * bypassed. On such conditions we try to bypass atleast YUV layers */
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800640bool MDPComp::tryFullFrame(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800641 hwc_display_contents_1_t* list){
642
Saurabh Shahaa236822013-04-24 18:07:26 -0700643 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Arun Kumar K.R2e2871c2014-01-10 12:47:06 -0800644 int priDispW = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800645
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -0700646 if(sIdleFallBack && !ctx->listStats[mDpy].secureUI) {
Saurabh Shah2d998a92013-05-14 17:55:58 -0700647 ALOGD_IF(isDebug(), "%s: Idle fallback dpy %d",__FUNCTION__, mDpy);
648 return false;
649 }
650
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800651 if(isSkipPresent(ctx, mDpy)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700652 ALOGD_IF(isDebug(),"%s: SKIP present: %d",
653 __FUNCTION__,
654 isSkipPresent(ctx, mDpy));
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800655 return false;
656 }
657
Arun Kumar K.R2e2871c2014-01-10 12:47:06 -0800658 if(mDpy > HWC_DISPLAY_PRIMARY && (priDispW > MAX_DISPLAY_DIM) &&
659 (ctx->dpyAttr[mDpy].xres < MAX_DISPLAY_DIM)) {
660 // Disable MDP comp on Secondary when the primary is highres panel and
661 // the secondary is a normal 1080p, because, MDP comp on secondary under
662 // in such usecase, decimation gets used for downscale and there will be
663 // a quality mismatch when there will be a fallback to GPU comp
664 ALOGD_IF(isDebug(), "%s: Disable MDP Compositon for Secondary Disp",
665 __FUNCTION__);
666 return false;
667 }
668
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800669 // check for action safe flag and downscale mode which requires scaling.
670 if(ctx->dpyAttr[mDpy].mActionSafePresent
671 || ctx->dpyAttr[mDpy].mDownScaleMode) {
672 ALOGD_IF(isDebug(), "%s: Scaling needed for this frame",__FUNCTION__);
673 return false;
674 }
675
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800676 for(int i = 0; i < numAppLayers; ++i) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800677 hwc_layer_1_t* layer = &list->hwLayers[i];
678 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800679
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700680 if(isYuvBuffer(hnd) && has90Transform(layer)) {
681 if(!canUseRotator(ctx, mDpy)) {
682 ALOGD_IF(isDebug(), "%s: Can't use rotator for dpy %d",
683 __FUNCTION__, mDpy);
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700684 return false;
685 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800686 }
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530687
688 //For 8x26 with panel width>1k, if RGB layer needs HFLIP fail mdp comp
689 // may not need it if Gfx pre-rotation can handle all flips & rotations
Sushil Chauhanfda00fc2014-03-20 11:08:41 -0700690 int transform = (layer->flags & HWC_COLOR_FILL) ? 0 : layer->transform;
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530691 if(qdutils::MDPVersion::getInstance().is8x26() &&
692 (ctx->dpyAttr[mDpy].xres > 1024) &&
Sushil Chauhanfda00fc2014-03-20 11:08:41 -0700693 (transform & HWC_TRANSFORM_FLIP_H) &&
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530694 (!isYuvBuffer(hnd)))
695 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800696 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700697
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700698 if(ctx->mAD->isDoable()) {
699 return false;
700 }
701
Saurabh Shahaa236822013-04-24 18:07:26 -0700702 //If all above hard conditions are met we can do full or partial MDP comp.
703 bool ret = false;
704 if(fullMDPComp(ctx, list)) {
705 ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700706 } else if(partialMDPComp(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700707 ret = true;
708 }
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530709
Saurabh Shahaa236822013-04-24 18:07:26 -0700710 return ret;
711}
712
713bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaran0ad97c42014-03-09 23:00:53 -0700714
715 if(sSimulationFlags & MDPCOMP_AVOID_FULL_MDP)
716 return false;
717
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700718 //Will benefit presentation / secondary-only layer.
719 if((mDpy > HWC_DISPLAY_PRIMARY) &&
720 (list->numHwLayers - 1) > MAX_SEC_LAYERS) {
721 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
722 return false;
723 }
724
725 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
726 for(int i = 0; i < numAppLayers; i++) {
727 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran880da832014-04-18 10:22:35 -0700728 if(not mCurrentFrame.drop[i] and
729 not isSupportedForMDPComp(ctx, layer)) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700730 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",__FUNCTION__);
731 return false;
732 }
733 }
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800734
Saurabh Shahaa236822013-04-24 18:07:26 -0700735 mCurrentFrame.fbCount = 0;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700736 memcpy(&mCurrentFrame.isFBComposed, &mCurrentFrame.drop,
737 sizeof(mCurrentFrame.isFBComposed));
738 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount -
739 mCurrentFrame.dropCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700740
radhakrishnac9a67412013-09-25 17:40:42 +0530741 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800742 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530743 }
744
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800745 if(!postHeuristicsHandling(ctx, list)) {
746 ALOGD_IF(isDebug(), "post heuristic handling failed");
747 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700748 return false;
749 }
Jeykumar Sankaran0ad97c42014-03-09 23:00:53 -0700750 ALOGD_IF(sSimulationFlags,"%s: FULL_MDP_COMP SUCCEEDED",
751 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700752 return true;
753}
754
755bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
756{
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700757 if(!sEnableMixedMode) {
758 //Mixed mode is disabled. No need to even try caching.
759 return false;
760 }
761
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700762 bool ret = false;
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800763 if(list->flags & HWC_GEOMETRY_CHANGED) { //Try load based first
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800764 ret = loadBasedComp(ctx, list) or
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800765 cacheBasedComp(ctx, list);
766 } else {
767 ret = cacheBasedComp(ctx, list) or
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800768 loadBasedComp(ctx, list);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700769 }
770
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700771 return ret;
772}
773
774bool MDPComp::cacheBasedComp(hwc_context_t *ctx,
775 hwc_display_contents_1_t* list) {
Jeykumar Sankaran0ad97c42014-03-09 23:00:53 -0700776 if(sSimulationFlags & MDPCOMP_AVOID_CACHE_MDP)
777 return false;
778
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700779 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700780 mCurrentFrame.reset(numAppLayers);
781 updateLayerCache(ctx, list);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700782
783 //If an MDP marked layer is unsupported cannot do partial MDP Comp
784 for(int i = 0; i < numAppLayers; i++) {
785 if(!mCurrentFrame.isFBComposed[i]) {
786 hwc_layer_1_t* layer = &list->hwLayers[i];
787 if(not isSupportedForMDPComp(ctx, layer)) {
788 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",
789 __FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800790 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700791 return false;
792 }
793 }
794 }
795
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700796 updateYUV(ctx, list, false /*secure only*/);
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530797 bool ret = markLayersForCaching(ctx, list); //sets up fbZ also
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700798 if(!ret) {
799 ALOGD_IF(isDebug(),"%s: batching failed, dpy %d",__FUNCTION__, mDpy);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800800 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700801 return false;
802 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700803
804 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700805
radhakrishnac9a67412013-09-25 17:40:42 +0530806 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800807 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530808 }
809
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700810 //Will benefit cases where a video has non-updating background.
811 if((mDpy > HWC_DISPLAY_PRIMARY) and
812 (mdpCount > MAX_SEC_LAYERS)) {
813 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800814 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700815 return false;
816 }
817
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800818 if(!postHeuristicsHandling(ctx, list)) {
819 ALOGD_IF(isDebug(), "post heuristic handling failed");
820 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700821 return false;
822 }
Jeykumar Sankaran0ad97c42014-03-09 23:00:53 -0700823 ALOGD_IF(sSimulationFlags,"%s: CACHE_MDP_COMP SUCCEEDED",
824 __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700825
Saurabh Shahaa236822013-04-24 18:07:26 -0700826 return true;
827}
828
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800829bool MDPComp::loadBasedComp(hwc_context_t *ctx,
Saurabh Shahb772ae32013-11-18 15:40:02 -0800830 hwc_display_contents_1_t* list) {
Jeykumar Sankaran0ad97c42014-03-09 23:00:53 -0700831 if(sSimulationFlags & MDPCOMP_AVOID_LOAD_MDP)
832 return false;
833
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -0800834 if(not isLoadBasedCompDoable(ctx)) {
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800835 return false;
836 }
837
Saurabh Shahb772ae32013-11-18 15:40:02 -0800838 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800839 const int numNonDroppedLayers = numAppLayers - mCurrentFrame.dropCount;
840 const int stagesForMDP = min(sMaxPipesPerMixer,
841 ctx->mOverlay->availablePipes(mDpy, Overlay::MIXER_DEFAULT));
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800842
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800843 int mdpBatchSize = stagesForMDP - 1; //1 stage for FB
844 int fbBatchSize = numNonDroppedLayers - mdpBatchSize;
845 int lastMDPSupportedIndex = numAppLayers;
846 int dropCount = 0;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800847
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800848 //Find the minimum MDP batch size
849 for(int i = 0; i < numAppLayers;i++) {
850 if(mCurrentFrame.drop[i]) {
851 dropCount++;
Jeykumar Sankaran846e2792014-01-23 21:59:58 -0800852 continue;
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800853 }
854 hwc_layer_1_t* layer = &list->hwLayers[i];
855 if(not isSupportedForMDPComp(ctx, layer)) {
856 lastMDPSupportedIndex = i;
857 mdpBatchSize = min(i - dropCount, stagesForMDP - 1);
858 fbBatchSize = numNonDroppedLayers - mdpBatchSize;
Jeykumar Sankaran846e2792014-01-23 21:59:58 -0800859 break;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800860 }
Saurabh Shahb772ae32013-11-18 15:40:02 -0800861 }
862
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800863 ALOGD_IF(isDebug(), "%s:Before optimizing fbBatch, mdpbatch %d, fbbatch %d "
864 "dropped %d", __FUNCTION__, mdpBatchSize, fbBatchSize,
865 mCurrentFrame.dropCount);
866
867 //Start at a point where the fb batch should at least have 2 layers, for
868 //this mode to be justified.
869 while(fbBatchSize < 2) {
870 ++fbBatchSize;
871 --mdpBatchSize;
Jeykumar Sankaran846e2792014-01-23 21:59:58 -0800872 }
Saurabh Shahb772ae32013-11-18 15:40:02 -0800873
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800874 //If there are no layers for MDP, this mode doesnt make sense.
875 if(mdpBatchSize < 1) {
876 ALOGD_IF(isDebug(), "%s: No MDP layers after optimizing for fbBatch",
877 __FUNCTION__);
Saurabh Shahb772ae32013-11-18 15:40:02 -0800878 return false;
879 }
880
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800881 mCurrentFrame.reset(numAppLayers);
882
883 //Try with successively smaller mdp batch sizes until we succeed or reach 1
884 while(mdpBatchSize > 0) {
885 //Mark layers for MDP comp
886 int mdpBatchLeft = mdpBatchSize;
887 for(int i = 0; i < lastMDPSupportedIndex and mdpBatchLeft; i++) {
888 if(mCurrentFrame.drop[i]) {
889 continue;
890 }
891 mCurrentFrame.isFBComposed[i] = false;
892 --mdpBatchLeft;
893 }
894
895 mCurrentFrame.fbZ = mdpBatchSize;
896 mCurrentFrame.fbCount = fbBatchSize;
897 mCurrentFrame.mdpCount = mdpBatchSize;
898
899 ALOGD_IF(isDebug(), "%s:Trying with: mdpbatch %d fbbatch %d dropped %d",
900 __FUNCTION__, mdpBatchSize, fbBatchSize,
901 mCurrentFrame.dropCount);
902
903 if(postHeuristicsHandling(ctx, list)) {
904 ALOGD_IF(isDebug(), "%s: Postheuristics handling succeeded",
Jeykumar Sankaran0ad97c42014-03-09 23:00:53 -0700905 __FUNCTION__);
906 ALOGD_IF(sSimulationFlags,"%s: LOAD_MDP_COMP SUCCEEDED",
907 __FUNCTION__);
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800908 return true;
909 }
910
911 reset(ctx);
912 --mdpBatchSize;
913 ++fbBatchSize;
914 }
915
916 return false;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800917}
918
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -0800919bool MDPComp::isLoadBasedCompDoable(hwc_context_t *ctx) {
Prabhanjan Kandula3dbbd882013-12-11 14:43:46 +0530920 if(mDpy or isSecurePresent(ctx, mDpy) or
921 isYuvPresent(ctx, mDpy)) {
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700922 return false;
923 }
924 return true;
925}
926
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800927bool MDPComp::canPartialUpdate(hwc_context_t *ctx,
928 hwc_display_contents_1_t* list){
929 if(!qdutils::MDPVersion::getInstance().isPartialUpdateEnabled() ||
930 isSkipPresent(ctx, mDpy) || (list->flags & HWC_GEOMETRY_CHANGED) ||
931 mDpy ) {
932 return false;
933 }
934 return true;
935}
936
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800937bool MDPComp::tryVideoOnly(hwc_context_t *ctx,
938 hwc_display_contents_1_t* list) {
939 const bool secureOnly = true;
940 return videoOnlyComp(ctx, list, not secureOnly) or
941 videoOnlyComp(ctx, list, secureOnly);
942}
943
944bool MDPComp::videoOnlyComp(hwc_context_t *ctx,
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700945 hwc_display_contents_1_t* list, bool secureOnly) {
Jeykumar Sankaran0ad97c42014-03-09 23:00:53 -0700946 if(sSimulationFlags & MDPCOMP_AVOID_VIDEO_ONLY)
947 return false;
Saurabh Shahaa236822013-04-24 18:07:26 -0700948 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700949
Saurabh Shahaa236822013-04-24 18:07:26 -0700950 mCurrentFrame.reset(numAppLayers);
Jeykumar Sankaraneb3a5e22014-04-08 16:07:55 -0700951 mCurrentFrame.fbCount -= mCurrentFrame.dropCount;
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700952 updateYUV(ctx, list, secureOnly);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700953 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700954
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800955 if(!isYuvPresent(ctx, mDpy) or (mdpCount == 0)) {
956 reset(ctx);
Saurabh Shahaa236822013-04-24 18:07:26 -0700957 return false;
958 }
959
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -0800960 /* Bail out if we are processing only secured video layers
961 * and we dont have any */
962 if(!isSecurePresent(ctx, mDpy) && secureOnly){
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800963 reset(ctx);
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -0800964 return false;
965 }
966
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800967 if(mCurrentFrame.fbCount)
968 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
Saurabh Shah4fdde762013-04-30 18:47:33 -0700969
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800970 if(sEnable4k2kYUVSplit){
971 adjustForSourceSplit(ctx, list);
972 }
973
974 if(!postHeuristicsHandling(ctx, list)) {
975 ALOGD_IF(isDebug(), "post heuristic handling failed");
976 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700977 return false;
978 }
979
Jeykumar Sankaran0ad97c42014-03-09 23:00:53 -0700980 ALOGD_IF(sSimulationFlags,"%s: VIDEO_ONLY_COMP SUCCEEDED",
981 __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800982 return true;
983}
984
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800985/* Checks for conditions where YUV layers cannot be bypassed */
986bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -0700987 if(isSkipLayer(layer)) {
Saurabh Shahe2474082013-05-15 16:32:13 -0700988 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800989 return false;
990 }
991
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700992 if(layer->transform & HWC_TRANSFORM_ROT_90 && !canUseRotator(ctx,mDpy)) {
993 ALOGD_IF(isDebug(), "%s: no free DMA pipe",__FUNCTION__);
994 return false;
995 }
996
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800997 if(isSecuring(ctx, layer)) {
998 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
999 return false;
1000 }
1001
Saurabh Shah4fdde762013-04-30 18:47:33 -07001002 if(!isValidDimension(ctx, layer)) {
1003 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
1004 __FUNCTION__);
1005 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001006 }
Saurabh Shah4fdde762013-04-30 18:47:33 -07001007
Naseer Ahmeddc61a972013-07-10 17:50:54 -04001008 if(layer->planeAlpha < 0xFF) {
1009 ALOGD_IF(isDebug(), "%s: Cannot handle YUV layer with plane alpha\
1010 in video only mode",
1011 __FUNCTION__);
1012 return false;
1013 }
1014
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001015 return true;
1016}
1017
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301018/* starts at fromIndex and check for each layer to find
1019 * if it it has overlapping with any Updating layer above it in zorder
1020 * till the end of the batch. returns true if it finds any intersection */
1021bool MDPComp::canPushBatchToTop(const hwc_display_contents_1_t* list,
1022 int fromIndex, int toIndex) {
1023 for(int i = fromIndex; i < toIndex; i++) {
1024 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
1025 if(intersectingUpdatingLayers(list, i+1, toIndex, i)) {
1026 return false;
1027 }
1028 }
1029 }
1030 return true;
1031}
1032
1033/* Checks if given layer at targetLayerIndex has any
1034 * intersection with all the updating layers in beween
1035 * fromIndex and toIndex. Returns true if it finds intersectiion */
1036bool MDPComp::intersectingUpdatingLayers(const hwc_display_contents_1_t* list,
1037 int fromIndex, int toIndex, int targetLayerIndex) {
1038 for(int i = fromIndex; i <= toIndex; i++) {
1039 if(!mCurrentFrame.isFBComposed[i]) {
1040 if(areLayersIntersecting(&list->hwLayers[i],
1041 &list->hwLayers[targetLayerIndex])) {
1042 return true;
1043 }
1044 }
1045 }
1046 return false;
1047}
1048
1049int MDPComp::getBatch(hwc_display_contents_1_t* list,
1050 int& maxBatchStart, int& maxBatchEnd,
1051 int& maxBatchCount) {
1052 int i = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301053 int fbZOrder =-1;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -08001054 int droppedLayerCt = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301055 while (i < mCurrentFrame.layerCount) {
1056 int batchCount = 0;
1057 int batchStart = i;
1058 int batchEnd = i;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -08001059 /* Adjust batch Z order with the dropped layers so far */
1060 int fbZ = batchStart - droppedLayerCt;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301061 int firstZReverseIndex = -1;
Prabhanjan Kandula0ed2cc92013-12-06 12:39:04 +05301062 int updatingLayersAbove = 0;//Updating layer count in middle of batch
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301063 while(i < mCurrentFrame.layerCount) {
1064 if(!mCurrentFrame.isFBComposed[i]) {
1065 if(!batchCount) {
1066 i++;
1067 break;
1068 }
1069 updatingLayersAbove++;
1070 i++;
1071 continue;
1072 } else {
1073 if(mCurrentFrame.drop[i]) {
1074 i++;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -08001075 droppedLayerCt++;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301076 continue;
1077 } else if(updatingLayersAbove <= 0) {
1078 batchCount++;
1079 batchEnd = i;
1080 i++;
1081 continue;
1082 } else { //Layer is FBComposed, not a drop & updatingLayer > 0
1083
1084 // We have a valid updating layer already. If layer-i not
1085 // have overlapping with all updating layers in between
1086 // batch-start and i, then we can add layer i to batch.
1087 if(!intersectingUpdatingLayers(list, batchStart, i-1, i)) {
1088 batchCount++;
1089 batchEnd = i;
1090 i++;
1091 continue;
1092 } else if(canPushBatchToTop(list, batchStart, i)) {
1093 //If All the non-updating layers with in this batch
1094 //does not have intersection with the updating layers
1095 //above in z-order, then we can safely move the batch to
1096 //higher z-order. Increment fbZ as it is moving up.
1097 if( firstZReverseIndex < 0) {
1098 firstZReverseIndex = i;
1099 }
1100 batchCount++;
1101 batchEnd = i;
1102 fbZ += updatingLayersAbove;
1103 i++;
1104 updatingLayersAbove = 0;
1105 continue;
1106 } else {
1107 //both failed.start the loop again from here.
1108 if(firstZReverseIndex >= 0) {
1109 i = firstZReverseIndex;
1110 }
1111 break;
1112 }
1113 }
1114 }
1115 }
1116 if(batchCount > maxBatchCount) {
1117 maxBatchCount = batchCount;
1118 maxBatchStart = batchStart;
1119 maxBatchEnd = batchEnd;
1120 fbZOrder = fbZ;
1121 }
1122 }
1123 return fbZOrder;
1124}
1125
1126bool MDPComp::markLayersForCaching(hwc_context_t* ctx,
1127 hwc_display_contents_1_t* list) {
1128 /* Idea is to keep as many non-updating(cached) layers in FB and
1129 * send rest of them through MDP. This is done in 2 steps.
1130 * 1. Find the maximum contiguous batch of non-updating layers.
1131 * 2. See if we can improve this batch size for caching by adding
1132 * opaque layers around the batch, if they don't have
1133 * any overlapping with the updating layers in between.
1134 * NEVER mark an updating layer for caching.
1135 * But cached ones can be marked for MDP */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001136
1137 int maxBatchStart = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001138 int maxBatchEnd = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001139 int maxBatchCount = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301140 int fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001141
Saurabh Shahd53bc5f2014-02-05 10:17:43 -08001142 /* Nothing is cached. No batching needed */
1143 if(mCurrentFrame.fbCount == 0) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001144 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -07001145 }
Saurabh Shahd53bc5f2014-02-05 10:17:43 -08001146
1147 /* No MDP comp layers, try to use other comp modes */
1148 if(mCurrentFrame.mdpCount == 0) {
1149 return false;
Saurabh Shahaa236822013-04-24 18:07:26 -07001150 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001151
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301152 fbZ = getBatch(list, maxBatchStart, maxBatchEnd, maxBatchCount);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001153
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301154 /* reset rest of the layers lying inside ROI for MDP comp */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001155 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001156 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001157 if((i < maxBatchStart || i > maxBatchEnd) &&
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301158 mCurrentFrame.isFBComposed[i]){
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001159 if(!mCurrentFrame.drop[i]){
1160 //If an unsupported layer is being attempted to
1161 //be pulled out we should fail
1162 if(not isSupportedForMDPComp(ctx, layer)) {
1163 return false;
1164 }
1165 mCurrentFrame.isFBComposed[i] = false;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001166 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001167 }
1168 }
1169
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301170 // update the frame data
1171 mCurrentFrame.fbZ = fbZ;
1172 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001173 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001174 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001175
1176 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301177 mCurrentFrame.fbCount);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001178
1179 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001180}
Saurabh Shah85234ec2013-04-12 17:09:00 -07001181
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001182void MDPComp::updateLayerCache(hwc_context_t* ctx,
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001183 hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001184 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001185 int fbCount = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001186
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001187 for(int i = 0; i < numAppLayers; i++) {
1188 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001189 if(!mCurrentFrame.drop[i])
1190 fbCount++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001191 mCurrentFrame.isFBComposed[i] = true;
1192 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -07001193 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001194 }
1195 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001196
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001197 mCurrentFrame.fbCount = fbCount;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001198 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount
1199 - mCurrentFrame.dropCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001200
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001201 ALOGD_IF(isDebug(),"%s: MDP count: %d FB count %d drop count: %d"
1202 ,__FUNCTION__, mCurrentFrame.mdpCount, mCurrentFrame.fbCount,
1203 mCurrentFrame.dropCount);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001204}
1205
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001206void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list,
1207 bool secureOnly) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001208 int nYuvCount = ctx->listStats[mDpy].yuvCount;
1209 for(int index = 0;index < nYuvCount; index++){
1210 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
1211 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
1212
1213 if(!isYUVDoable(ctx, layer)) {
1214 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
1215 mCurrentFrame.isFBComposed[nYuvIndex] = true;
1216 mCurrentFrame.fbCount++;
1217 }
1218 } else {
1219 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001220 private_handle_t *hnd = (private_handle_t *)layer->handle;
1221 if(!secureOnly || isSecureBuffer(hnd)) {
1222 mCurrentFrame.isFBComposed[nYuvIndex] = false;
1223 mCurrentFrame.fbCount--;
1224 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001225 }
1226 }
1227 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001228
1229 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001230 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
1231 ALOGD_IF(isDebug(),"%s: fb count: %d",__FUNCTION__,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001232 mCurrentFrame.fbCount);
1233}
1234
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001235hwc_rect_t MDPComp::getUpdatingFBRect(hwc_context_t *ctx,
1236 hwc_display_contents_1_t* list){
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001237 hwc_rect_t fbRect = (struct hwc_rect){0, 0, 0, 0};
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001238
1239 /* Update only the region of FB needed for composition */
1240 for(int i = 0; i < mCurrentFrame.layerCount; i++ ) {
1241 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
1242 hwc_layer_1_t* layer = &list->hwLayers[i];
1243 hwc_rect_t dst = layer->displayFrame;
1244 fbRect = getUnion(fbRect, dst);
1245 }
1246 }
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001247 trimAgainstROI(ctx, fbRect);
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001248 return fbRect;
1249}
1250
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001251bool MDPComp::postHeuristicsHandling(hwc_context_t *ctx,
1252 hwc_display_contents_1_t* list) {
1253
1254 //Capability checks
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301255 if(!resourceCheck()) {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001256 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
1257 return false;
1258 }
1259
1260 //Limitations checks
1261 if(!hwLimitationsCheck(ctx, list)) {
1262 ALOGD_IF(isDebug(), "%s: HW limitations",__FUNCTION__);
1263 return false;
1264 }
1265
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001266 //Configure framebuffer first if applicable
1267 if(mCurrentFrame.fbZ >= 0) {
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001268 hwc_rect_t fbRect = getUpdatingFBRect(ctx, list);
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001269 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, fbRect, mCurrentFrame.fbZ))
1270 {
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001271 ALOGD_IF(isDebug(), "%s configure framebuffer failed",
1272 __FUNCTION__);
1273 return false;
1274 }
1275 }
1276
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001277 mCurrentFrame.map();
1278
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001279 if(!allocLayerPipes(ctx, list)) {
1280 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -07001281 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001282 }
1283
1284 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001285 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001286 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001287 int mdpIndex = mCurrentFrame.layerToMDP[index];
1288 hwc_layer_1_t* layer = &list->hwLayers[index];
1289
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301290 //Leave fbZ for framebuffer. CACHE/GLES layers go here.
1291 if(mdpNextZOrder == mCurrentFrame.fbZ) {
1292 mdpNextZOrder++;
1293 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001294 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1295 cur_pipe->zOrder = mdpNextZOrder++;
1296
radhakrishnac9a67412013-09-25 17:40:42 +05301297 private_handle_t *hnd = (private_handle_t *)layer->handle;
1298 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1299 if(configure4k2kYuv(ctx, layer,
1300 mCurrentFrame.mdpToLayer[mdpIndex])
1301 != 0 ){
1302 ALOGD_IF(isDebug(), "%s: Failed to configure split pipes \
1303 for layer %d",__FUNCTION__, index);
1304 return false;
1305 }
1306 else{
1307 mdpNextZOrder++;
1308 }
1309 continue;
1310 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001311 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
1312 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
radhakrishnac9a67412013-09-25 17:40:42 +05301313 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -07001314 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001315 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001316 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001317 }
1318
Saurabh Shaha36be922013-12-16 18:18:39 -08001319 if(!ctx->mOverlay->validateAndSet(mDpy, ctx->dpyAttr[mDpy].fd)) {
1320 ALOGD_IF(isDebug(), "%s: Failed to validate and set overlay for dpy %d"
1321 ,__FUNCTION__, mDpy);
1322 return false;
1323 }
1324
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001325 setRedraw(ctx, list);
Saurabh Shahaa236822013-04-24 18:07:26 -07001326 return true;
1327}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001328
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301329bool MDPComp::resourceCheck() {
Saurabh Shah173f4242013-11-20 09:50:12 -08001330 const bool fbUsed = mCurrentFrame.fbCount;
1331 if(mCurrentFrame.mdpCount > sMaxPipesPerMixer - fbUsed) {
1332 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
1333 return false;
1334 }
Saurabh Shah173f4242013-11-20 09:50:12 -08001335 return true;
1336}
1337
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301338bool MDPComp::hwLimitationsCheck(hwc_context_t* ctx,
1339 hwc_display_contents_1_t* list) {
1340
1341 //A-family hw limitation:
1342 //If a layer need alpha scaling, MDP can not support.
1343 if(ctx->mMDP.version < qdutils::MDSS_V5) {
1344 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1345 if(!mCurrentFrame.isFBComposed[i] &&
1346 isAlphaScaled( &list->hwLayers[i])) {
1347 ALOGD_IF(isDebug(), "%s:frame needs alphaScaling",__FUNCTION__);
1348 return false;
1349 }
1350 }
1351 }
1352
1353 // On 8x26 & 8974 hw, we have a limitation of downscaling+blending.
1354 //If multiple layers requires downscaling and also they are overlapping
1355 //fall back to GPU since MDSS can not handle it.
1356 if(qdutils::MDPVersion::getInstance().is8x74v2() ||
1357 qdutils::MDPVersion::getInstance().is8x26()) {
1358 for(int i = 0; i < mCurrentFrame.layerCount-1; ++i) {
1359 hwc_layer_1_t* botLayer = &list->hwLayers[i];
1360 if(!mCurrentFrame.isFBComposed[i] &&
1361 isDownscaleRequired(botLayer)) {
1362 //if layer-i is marked for MDP and needs downscaling
1363 //check if any MDP layer on top of i & overlaps with layer-i
1364 for(int j = i+1; j < mCurrentFrame.layerCount; ++j) {
1365 hwc_layer_1_t* topLayer = &list->hwLayers[j];
1366 if(!mCurrentFrame.isFBComposed[j] &&
1367 isDownscaleRequired(topLayer)) {
1368 hwc_rect_t r = getIntersection(botLayer->displayFrame,
1369 topLayer->displayFrame);
1370 if(isValidRect(r))
1371 return false;
1372 }
1373 }
1374 }
1375 }
1376 }
1377 return true;
1378}
1379
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001380int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001381 int ret = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -07001382 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran0ad97c42014-03-09 23:00:53 -07001383 char property[PROPERTY_VALUE_MAX];
1384
1385 if(property_get("debug.hwc.simulate", property, NULL) > 0) {
1386 int currentFlags = atoi(property);
1387 if(currentFlags != sSimulationFlags) {
1388 sSimulationFlags = currentFlags;
1389 ALOGE("%s: Simulation Flag read: 0x%x (%d)", __FUNCTION__,
1390 sSimulationFlags, sSimulationFlags);
1391 }
1392 }
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -07001393
Raj Kamal9ed3d6b2014-02-07 16:15:17 +05301394 //Do not cache the information for next draw cycle.
1395 if(numLayers > MAX_NUM_APP_LAYERS or (!numLayers)) {
1396 ALOGI("%s: Unsupported layer count for mdp composition",
1397 __FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001398 mCachedFrame.reset();
1399 return -1;
1400 }
1401
Saurabh Shahb39f8152013-08-22 10:21:44 -07001402 //reset old data
1403 mCurrentFrame.reset(numLayers);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001404 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1405 mCurrentFrame.dropCount = 0;
Prabhanjan Kandula088bd892013-07-02 23:47:13 +05301406
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -07001407 // Detect the start of animation and fall back to GPU only once to cache
1408 // all the layers in FB and display FB content untill animation completes.
1409 if(ctx->listStats[mDpy].isDisplayAnimating) {
1410 mCurrentFrame.needsRedraw = false;
1411 if(ctx->mAnimationState[mDpy] == ANIMATION_STOPPED) {
1412 mCurrentFrame.needsRedraw = true;
1413 ctx->mAnimationState[mDpy] = ANIMATION_STARTED;
1414 }
1415 setMDPCompLayerFlags(ctx, list);
1416 mCachedFrame.updateCounts(mCurrentFrame);
1417 ret = -1;
1418 return ret;
1419 } else {
1420 ctx->mAnimationState[mDpy] = ANIMATION_STOPPED;
1421 }
1422
Saurabh Shahb39f8152013-08-22 10:21:44 -07001423 //Hard conditions, if not met, cannot do MDP comp
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001424 if(isFrameDoable(ctx)) {
1425 generateROI(ctx, list);
Saurabh Shahb39f8152013-08-22 10:21:44 -07001426
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001427 if(tryFullFrame(ctx, list) || tryVideoOnly(ctx, list)) {
1428 setMDPCompLayerFlags(ctx, list);
1429 } else {
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001430 resetROI(ctx, mDpy);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001431 reset(ctx);
1432 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1433 mCurrentFrame.dropCount = 0;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001434 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001435 }
1436 } else {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001437 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
1438 __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001439 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001440 }
Saurabh Shahb39f8152013-08-22 10:21:44 -07001441
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001442 if(isDebug()) {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001443 ALOGD("GEOMETRY change: %d",
1444 (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001445 android::String8 sDump("");
1446 dump(sDump);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001447 ALOGD("%s",sDump.string());
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001448 }
1449
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001450 mCachedFrame.cacheAll(list);
1451 mCachedFrame.updateCounts(mCurrentFrame);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001452 return ret;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001453}
1454
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001455bool MDPComp::allocSplitVGPipesfor4k2k(hwc_context_t *ctx, int index) {
radhakrishnac9a67412013-09-25 17:40:42 +05301456
1457 bool bRet = true;
radhakrishnac9a67412013-09-25 17:40:42 +05301458 int mdpIndex = mCurrentFrame.layerToMDP[index];
1459 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
1460 info.pipeInfo = new MdpYUVPipeInfo;
1461 info.rot = NULL;
1462 MdpYUVPipeInfo& pipe_info = *(MdpYUVPipeInfo*)info.pipeInfo;
radhakrishnac9a67412013-09-25 17:40:42 +05301463
1464 pipe_info.lIndex = ovutils::OV_INVALID;
1465 pipe_info.rIndex = ovutils::OV_INVALID;
1466
Saurabh Shahc62f3982014-03-05 14:28:26 -08001467 Overlay::PipeSpecs pipeSpecs;
1468 pipeSpecs.formatClass = Overlay::FORMAT_YUV;
1469 pipeSpecs.needsScaling = true;
1470 pipeSpecs.dpy = mDpy;
1471 pipeSpecs.fb = false;
1472
1473 pipe_info.lIndex = ctx->mOverlay->getPipe(pipeSpecs);
radhakrishnac9a67412013-09-25 17:40:42 +05301474 if(pipe_info.lIndex == ovutils::OV_INVALID){
1475 bRet = false;
1476 ALOGD_IF(isDebug(),"%s: allocating first VG pipe failed",
1477 __FUNCTION__);
1478 }
Saurabh Shahc62f3982014-03-05 14:28:26 -08001479 pipe_info.rIndex = ctx->mOverlay->getPipe(pipeSpecs);
radhakrishnac9a67412013-09-25 17:40:42 +05301480 if(pipe_info.rIndex == ovutils::OV_INVALID){
1481 bRet = false;
1482 ALOGD_IF(isDebug(),"%s: allocating second VG pipe failed",
1483 __FUNCTION__);
1484 }
1485 return bRet;
1486}
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001487//=============MDPCompNonSplit==================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001488
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001489void MDPCompNonSplit::adjustForSourceSplit(hwc_context_t *ctx,
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001490 hwc_display_contents_1_t*) {
radhakrishnac9a67412013-09-25 17:40:42 +05301491 //As we split 4kx2k yuv layer and program to 2 VG pipes
1492 //(if available) increase mdpcount accordingly
1493 mCurrentFrame.mdpCount += ctx->listStats[mDpy].yuv4k2kCount;
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001494
1495 //If 4k2k Yuv layer split is possible, and if
1496 //fbz is above 4k2k layer, increment fb zorder by 1
1497 //as we split 4k2k layer and increment zorder for right half
1498 //of the layer
1499 if(mCurrentFrame.fbZ >= 0) {
1500 int n4k2kYuvCount = ctx->listStats[mDpy].yuv4k2kCount;
1501 for(int index = 0; index < n4k2kYuvCount; index++){
1502 int n4k2kYuvIndex =
1503 ctx->listStats[mDpy].yuv4k2kIndices[index];
Dileep Kumar Reddi4cff9282014-04-01 12:57:08 +05301504 if(mCurrentFrame.fbZ >= n4k2kYuvIndex){
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001505 mCurrentFrame.fbZ += 1;
1506 }
1507 }
1508 }
radhakrishnac9a67412013-09-25 17:40:42 +05301509}
1510
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001511/*
1512 * Configures pipe(s) for MDP composition
1513 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001514int MDPCompNonSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001515 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001516 MdpPipeInfoNonSplit& mdp_info =
1517 *(static_cast<MdpPipeInfoNonSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001518 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
1519 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1520 eIsFg isFg = IS_FG_OFF;
1521 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001522
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001523 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
1524 __FUNCTION__, layer, zOrder, dest);
1525
Saurabh Shah88e4d272013-09-03 13:31:29 -07001526 return configureNonSplit(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001527 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001528}
1529
Saurabh Shah88e4d272013-09-03 13:31:29 -07001530bool MDPCompNonSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001531 hwc_display_contents_1_t* list) {
1532 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001533
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001534 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001535
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001536 hwc_layer_1_t* layer = &list->hwLayers[index];
1537 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301538 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001539 if(allocSplitVGPipesfor4k2k(ctx, index)){
radhakrishnac9a67412013-09-25 17:40:42 +05301540 continue;
1541 }
1542 }
1543
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001544 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001545 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001546 info.pipeInfo = new MdpPipeInfoNonSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08001547 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001548 MdpPipeInfoNonSplit& pipe_info = *(MdpPipeInfoNonSplit*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001549
Saurabh Shahc62f3982014-03-05 14:28:26 -08001550 Overlay::PipeSpecs pipeSpecs;
1551 pipeSpecs.formatClass = isYuvBuffer(hnd) ?
1552 Overlay::FORMAT_YUV : Overlay::FORMAT_RGB;
1553 pipeSpecs.needsScaling = qhwc::needsScaling(layer) or
1554 (qdutils::MDPVersion::getInstance().is8x26() and
1555 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres > 1024);
1556 pipeSpecs.dpy = mDpy;
1557 pipeSpecs.fb = false;
Xu Yang1e686f62014-04-08 13:56:47 +08001558 pipeSpecs.numActiveDisplays = ctx->numActiveDisplays;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001559
Saurabh Shahc62f3982014-03-05 14:28:26 -08001560 pipe_info.index = ctx->mOverlay->getPipe(pipeSpecs);
1561
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001562 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001563 ALOGD_IF(isDebug(), "%s: Unable to get pipe", __FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001564 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001565 }
1566 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001567 return true;
1568}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001569
radhakrishnac9a67412013-09-25 17:40:42 +05301570int MDPCompNonSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1571 PipeLayerPair& PipeLayerPair) {
1572 MdpYUVPipeInfo& mdp_info =
1573 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1574 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1575 eIsFg isFg = IS_FG_OFF;
1576 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1577 eDest lDest = mdp_info.lIndex;
1578 eDest rDest = mdp_info.rIndex;
1579
1580 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1581 lDest, rDest, &PipeLayerPair.rot);
1582}
1583
Saurabh Shah88e4d272013-09-03 13:31:29 -07001584bool MDPCompNonSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001585
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001586 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001587 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1588 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -08001589 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001590
1591 if(!ctx || !list) {
1592 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001593 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001594 }
1595
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301596 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1597 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1598 return true;
1599 }
1600
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -08001601 // Set the Handle timeout to true for MDP or MIXED composition.
1602 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount) {
1603 sHandleTimeout = true;
1604 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001605
1606 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001607 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001608
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001609 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1610 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001611 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001612 if(mCurrentFrame.isFBComposed[i]) continue;
1613
Naseer Ahmed5b6708a2012-08-02 13:46:08 -07001614 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001615 private_handle_t *hnd = (private_handle_t *)layer->handle;
1616 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001617 if (!(layer->flags & HWC_COLOR_FILL)) {
1618 ALOGE("%s handle null", __FUNCTION__);
1619 return false;
1620 }
1621 // No PLAY for Color layer
1622 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1623 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001624 }
1625
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001626 int mdpIndex = mCurrentFrame.layerToMDP[i];
1627
radhakrishnac9a67412013-09-25 17:40:42 +05301628 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1629 {
1630 MdpYUVPipeInfo& pipe_info =
1631 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1632 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1633 ovutils::eDest indexL = pipe_info.lIndex;
1634 ovutils::eDest indexR = pipe_info.rIndex;
1635 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301636 uint32_t offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05301637 if(rot) {
1638 rot->queueBuffer(fd, offset);
1639 fd = rot->getDstMemId();
1640 offset = rot->getDstOffset();
1641 }
1642 if(indexL != ovutils::OV_INVALID) {
1643 ovutils::eDest destL = (ovutils::eDest)indexL;
1644 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1645 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1646 if (!ov.queueBuffer(fd, offset, destL)) {
1647 ALOGE("%s: queueBuffer failed for display:%d",
1648 __FUNCTION__, mDpy);
1649 return false;
1650 }
1651 }
1652
1653 if(indexR != ovutils::OV_INVALID) {
1654 ovutils::eDest destR = (ovutils::eDest)indexR;
1655 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1656 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1657 if (!ov.queueBuffer(fd, offset, destR)) {
1658 ALOGE("%s: queueBuffer failed for display:%d",
1659 __FUNCTION__, mDpy);
1660 return false;
1661 }
1662 }
1663 }
1664 else{
1665 MdpPipeInfoNonSplit& pipe_info =
Saurabh Shah88e4d272013-09-03 13:31:29 -07001666 *(MdpPipeInfoNonSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
radhakrishnac9a67412013-09-25 17:40:42 +05301667 ovutils::eDest dest = pipe_info.index;
1668 if(dest == ovutils::OV_INVALID) {
1669 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001670 return false;
radhakrishnac9a67412013-09-25 17:40:42 +05301671 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001672
radhakrishnac9a67412013-09-25 17:40:42 +05301673 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1674 continue;
1675 }
1676
1677 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1678 using pipe: %d", __FUNCTION__, layer,
1679 hnd, dest );
1680
1681 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301682 uint32_t offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05301683
1684 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1685 if(rot) {
1686 if(!rot->queueBuffer(fd, offset))
1687 return false;
1688 fd = rot->getDstMemId();
1689 offset = rot->getDstOffset();
1690 }
1691
1692 if (!ov.queueBuffer(fd, offset, dest)) {
1693 ALOGE("%s: queueBuffer failed for display:%d ",
1694 __FUNCTION__, mDpy);
1695 return false;
1696 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001697 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001698
1699 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001700 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001701 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001702}
1703
Saurabh Shah88e4d272013-09-03 13:31:29 -07001704//=============MDPCompSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001705
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001706void MDPCompSplit::adjustForSourceSplit(hwc_context_t *ctx,
radhakrishnac9a67412013-09-25 17:40:42 +05301707 hwc_display_contents_1_t* list){
1708 //if 4kx2k yuv layer is totally present in either in left half
1709 //or right half then try splitting the yuv layer to avoid decimation
1710 int n4k2kYuvCount = ctx->listStats[mDpy].yuv4k2kCount;
1711 const int lSplit = getLeftSplit(ctx, mDpy);
1712 for(int index = 0; index < n4k2kYuvCount; index++){
1713 int n4k2kYuvIndex = ctx->listStats[mDpy].yuv4k2kIndices[index];
1714 hwc_layer_1_t* layer = &list->hwLayers[n4k2kYuvIndex];
1715 hwc_rect_t dst = layer->displayFrame;
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001716 if((dst.left > lSplit) || (dst.right < lSplit)) {
radhakrishnac9a67412013-09-25 17:40:42 +05301717 mCurrentFrame.mdpCount += 1;
1718 }
Dileep Kumar Reddi4cff9282014-04-01 12:57:08 +05301719 if(mCurrentFrame.fbZ >= n4k2kYuvIndex){
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001720 mCurrentFrame.fbZ += 1;
1721 }
radhakrishnac9a67412013-09-25 17:40:42 +05301722 }
1723}
1724
Saurabh Shah88e4d272013-09-03 13:31:29 -07001725bool MDPCompSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Saurabh Shahc62f3982014-03-05 14:28:26 -08001726 MdpPipeInfoSplit& pipe_info) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001727
Saurabh Shahc62f3982014-03-05 14:28:26 -08001728 const int lSplit = getLeftSplit(ctx, mDpy);
1729 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001730 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001731 pipe_info.lIndex = ovutils::OV_INVALID;
1732 pipe_info.rIndex = ovutils::OV_INVALID;
1733
Saurabh Shahc62f3982014-03-05 14:28:26 -08001734 Overlay::PipeSpecs pipeSpecs;
1735 pipeSpecs.formatClass = isYuvBuffer(hnd) ?
1736 Overlay::FORMAT_YUV : Overlay::FORMAT_RGB;
1737 pipeSpecs.needsScaling = qhwc::needsScalingWithSplit(ctx, layer, mDpy);
1738 pipeSpecs.dpy = mDpy;
1739 pipeSpecs.mixer = Overlay::MIXER_LEFT;
1740 pipeSpecs.fb = false;
1741
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001742 // Acquire pipe only for the updating half
1743 hwc_rect_t l_roi = ctx->listStats[mDpy].lRoi;
1744 hwc_rect_t r_roi = ctx->listStats[mDpy].rRoi;
1745
1746 if (dst.left < lSplit && isValidRect(getIntersection(dst, l_roi))) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001747 pipe_info.lIndex = ctx->mOverlay->getPipe(pipeSpecs);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001748 if(pipe_info.lIndex == ovutils::OV_INVALID)
1749 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001750 }
1751
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001752 if(dst.right > lSplit && isValidRect(getIntersection(dst, r_roi))) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001753 pipeSpecs.mixer = Overlay::MIXER_RIGHT;
1754 pipe_info.rIndex = ctx->mOverlay->getPipe(pipeSpecs);
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001755 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001756 return false;
1757 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001758
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001759 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001760}
1761
Saurabh Shah88e4d272013-09-03 13:31:29 -07001762bool MDPCompSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001763 hwc_display_contents_1_t* list) {
1764 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001765
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001766 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001767
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001768 hwc_layer_1_t* layer = &list->hwLayers[index];
1769 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301770 hwc_rect_t dst = layer->displayFrame;
1771 const int lSplit = getLeftSplit(ctx, mDpy);
1772 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1773 if((dst.left > lSplit)||(dst.right < lSplit)){
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001774 if(allocSplitVGPipesfor4k2k(ctx, index)){
radhakrishnac9a67412013-09-25 17:40:42 +05301775 continue;
1776 }
1777 }
1778 }
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001779 int mdpIndex = mCurrentFrame.layerToMDP[index];
1780 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001781 info.pipeInfo = new MdpPipeInfoSplit;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001782 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001783 MdpPipeInfoSplit& pipe_info = *(MdpPipeInfoSplit*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001784
Saurabh Shahc62f3982014-03-05 14:28:26 -08001785 if(!acquireMDPPipes(ctx, layer, pipe_info)) {
1786 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type",
1787 __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001788 return false;
1789 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001790 }
1791 return true;
1792}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001793
radhakrishnac9a67412013-09-25 17:40:42 +05301794int MDPCompSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1795 PipeLayerPair& PipeLayerPair) {
1796 const int lSplit = getLeftSplit(ctx, mDpy);
1797 hwc_rect_t dst = layer->displayFrame;
1798 if((dst.left > lSplit)||(dst.right < lSplit)){
1799 MdpYUVPipeInfo& mdp_info =
1800 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1801 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1802 eIsFg isFg = IS_FG_OFF;
1803 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1804 eDest lDest = mdp_info.lIndex;
1805 eDest rDest = mdp_info.rIndex;
1806
1807 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1808 lDest, rDest, &PipeLayerPair.rot);
1809 }
1810 else{
1811 return configure(ctx, layer, PipeLayerPair);
1812 }
1813}
1814
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001815/*
1816 * Configures pipe(s) for MDP composition
1817 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001818int MDPCompSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001819 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001820 MdpPipeInfoSplit& mdp_info =
1821 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001822 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1823 eIsFg isFg = IS_FG_OFF;
1824 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1825 eDest lDest = mdp_info.lIndex;
1826 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001827
1828 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1829 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1830
Saurabh Shah88e4d272013-09-03 13:31:29 -07001831 return configureSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001832 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001833}
1834
Saurabh Shah88e4d272013-09-03 13:31:29 -07001835bool MDPCompSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001836
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001837 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001838 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1839 return true;
1840 }
1841
1842 if(!ctx || !list) {
1843 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001844 return false;
1845 }
1846
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301847 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1848 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1849 return true;
1850 }
1851
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -08001852 // Set the Handle timeout to true for MDP or MIXED composition.
1853 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount) {
1854 sHandleTimeout = true;
1855 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001856
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001857 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001858 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001859
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001860 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1861 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001862 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001863 if(mCurrentFrame.isFBComposed[i]) continue;
1864
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001865 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001866 private_handle_t *hnd = (private_handle_t *)layer->handle;
1867 if(!hnd) {
1868 ALOGE("%s handle null", __FUNCTION__);
1869 return false;
1870 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001871
1872 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1873 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001874 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001875
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001876 int mdpIndex = mCurrentFrame.layerToMDP[i];
1877
radhakrishnac9a67412013-09-25 17:40:42 +05301878 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1879 {
1880 MdpYUVPipeInfo& pipe_info =
1881 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1882 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1883 ovutils::eDest indexL = pipe_info.lIndex;
1884 ovutils::eDest indexR = pipe_info.rIndex;
1885 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301886 uint32_t offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05301887 if(rot) {
1888 rot->queueBuffer(fd, offset);
1889 fd = rot->getDstMemId();
1890 offset = rot->getDstOffset();
1891 }
1892 if(indexL != ovutils::OV_INVALID) {
1893 ovutils::eDest destL = (ovutils::eDest)indexL;
1894 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1895 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1896 if (!ov.queueBuffer(fd, offset, destL)) {
1897 ALOGE("%s: queueBuffer failed for display:%d",
1898 __FUNCTION__, mDpy);
1899 return false;
1900 }
1901 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001902
radhakrishnac9a67412013-09-25 17:40:42 +05301903 if(indexR != ovutils::OV_INVALID) {
1904 ovutils::eDest destR = (ovutils::eDest)indexR;
1905 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1906 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1907 if (!ov.queueBuffer(fd, offset, destR)) {
1908 ALOGE("%s: queueBuffer failed for display:%d",
1909 __FUNCTION__, mDpy);
1910 return false;
1911 }
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001912 }
1913 }
radhakrishnac9a67412013-09-25 17:40:42 +05301914 else{
1915 MdpPipeInfoSplit& pipe_info =
1916 *(MdpPipeInfoSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1917 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001918
radhakrishnac9a67412013-09-25 17:40:42 +05301919 ovutils::eDest indexL = pipe_info.lIndex;
1920 ovutils::eDest indexR = pipe_info.rIndex;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001921
radhakrishnac9a67412013-09-25 17:40:42 +05301922 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301923 int offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05301924
Tatenda Chipeperekwa88fe6352014-04-14 10:36:06 -07001925 if(ctx->mAD->draw(ctx, fd, offset)) {
1926 fd = ctx->mAD->getDstFd();
1927 offset = ctx->mAD->getDstOffset();
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001928 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001929
radhakrishnac9a67412013-09-25 17:40:42 +05301930 if(rot) {
1931 rot->queueBuffer(fd, offset);
1932 fd = rot->getDstMemId();
1933 offset = rot->getDstOffset();
1934 }
1935
1936 //************* play left mixer **********
1937 if(indexL != ovutils::OV_INVALID) {
1938 ovutils::eDest destL = (ovutils::eDest)indexL;
1939 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1940 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1941 if (!ov.queueBuffer(fd, offset, destL)) {
1942 ALOGE("%s: queueBuffer failed for left mixer",
1943 __FUNCTION__);
1944 return false;
1945 }
1946 }
1947
1948 //************* play right mixer **********
1949 if(indexR != ovutils::OV_INVALID) {
1950 ovutils::eDest destR = (ovutils::eDest)indexR;
1951 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1952 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1953 if (!ov.queueBuffer(fd, offset, destR)) {
1954 ALOGE("%s: queueBuffer failed for right mixer",
1955 __FUNCTION__);
1956 return false;
1957 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001958 }
1959 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001960
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001961 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1962 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001963
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001964 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001965}
Saurabh Shahab47c692014-02-12 18:45:57 -08001966
1967//================MDPCompSrcSplit==============================================
1968bool MDPCompSrcSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Saurabh Shahc62f3982014-03-05 14:28:26 -08001969 MdpPipeInfoSplit& pipe_info) {
Saurabh Shahab47c692014-02-12 18:45:57 -08001970 private_handle_t *hnd = (private_handle_t *)layer->handle;
1971 hwc_rect_t dst = layer->displayFrame;
1972 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
1973 pipe_info.lIndex = ovutils::OV_INVALID;
1974 pipe_info.rIndex = ovutils::OV_INVALID;
1975
1976 //If 2 pipes are staged on a single stage of a mixer, then the left pipe
1977 //should have a higher priority than the right one. Pipe priorities are
1978 //starting with VG0, VG1 ... , RGB0 ..., DMA1
Saurabh Shahab47c692014-02-12 18:45:57 -08001979
Saurabh Shahc62f3982014-03-05 14:28:26 -08001980 Overlay::PipeSpecs pipeSpecs;
1981 pipeSpecs.formatClass = isYuvBuffer(hnd) ?
1982 Overlay::FORMAT_YUV : Overlay::FORMAT_RGB;
1983 pipeSpecs.needsScaling = qhwc::needsScaling(layer);
1984 pipeSpecs.dpy = mDpy;
1985 pipeSpecs.fb = false;
1986
Saurabh Shahab47c692014-02-12 18:45:57 -08001987 //1 pipe by default for a layer
Saurabh Shahc62f3982014-03-05 14:28:26 -08001988 pipe_info.lIndex = ctx->mOverlay->getPipe(pipeSpecs);
Saurabh Shahab47c692014-02-12 18:45:57 -08001989 if(pipe_info.lIndex == ovutils::OV_INVALID) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001990 return false;
Saurabh Shahab47c692014-02-12 18:45:57 -08001991 }
1992
1993 //If layer's crop width or dest width > 2048, use 2 pipes
1994 if((dst.right - dst.left) > qdutils::MAX_DISPLAY_DIM or
1995 (crop.right - crop.left) > qdutils::MAX_DISPLAY_DIM) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001996 pipe_info.rIndex = ctx->mOverlay->getPipe(pipeSpecs);
Saurabh Shahab47c692014-02-12 18:45:57 -08001997 if(pipe_info.rIndex == ovutils::OV_INVALID) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001998 return false;
Saurabh Shahdd8237a2014-02-28 14:29:09 -08001999 }
2000
2001 // Return values
2002 // 1 Left pipe is higher priority, do nothing.
2003 // 0 Pipes of same priority.
2004 //-1 Right pipe is of higher priority, needs swap.
2005 if(ctx->mOverlay->comparePipePriority(pipe_info.lIndex,
2006 pipe_info.rIndex) == -1) {
2007 qhwc::swap(pipe_info.lIndex, pipe_info.rIndex);
Saurabh Shahab47c692014-02-12 18:45:57 -08002008 }
2009 }
2010
2011 return true;
2012}
2013
Saurabh Shahab47c692014-02-12 18:45:57 -08002014int MDPCompSrcSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
2015 PipeLayerPair& PipeLayerPair) {
2016 private_handle_t *hnd = (private_handle_t *)layer->handle;
2017 if(!hnd) {
2018 ALOGE("%s: layer handle is NULL", __FUNCTION__);
2019 return -1;
2020 }
2021 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
2022 MdpPipeInfoSplit& mdp_info =
2023 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
2024 Rotator **rot = &PipeLayerPair.rot;
2025 eZorder z = static_cast<eZorder>(mdp_info.zOrder);
2026 eIsFg isFg = IS_FG_OFF;
2027 eDest lDest = mdp_info.lIndex;
2028 eDest rDest = mdp_info.rIndex;
2029 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
2030 hwc_rect_t dst = layer->displayFrame;
2031 int transform = layer->transform;
2032 eTransform orient = static_cast<eTransform>(transform);
2033 const int downscale = 0;
2034 int rotFlags = ROT_FLAGS_NONE;
2035 uint32_t format = ovutils::getMdpFormat(hnd->format, isTileRendered(hnd));
2036 Whf whf(getWidth(hnd), getHeight(hnd), format, hnd->size);
2037
2038 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
2039 "dest_pipeR: %d",__FUNCTION__, layer, z, lDest, rDest);
2040
2041 // Handle R/B swap
2042 if (layer->flags & HWC_FORMAT_RB_SWAP) {
2043 if (hnd->format == HAL_PIXEL_FORMAT_RGBA_8888)
2044 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRA_8888);
2045 else if (hnd->format == HAL_PIXEL_FORMAT_RGBX_8888)
2046 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRX_8888);
2047 }
2048
Saurabh Shah97e2d802014-04-14 18:03:54 -07002049 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
2050 setMdpFlags(layer, mdpFlags, 0, transform);
Saurabh Shahab47c692014-02-12 18:45:57 -08002051
2052 if(lDest != OV_INVALID && rDest != OV_INVALID) {
2053 //Enable overfetch
Saurabh Shah97e2d802014-04-14 18:03:54 -07002054 setMdpFlags(mdpFlags, OV_MDSS_MDP_DUAL_PIPE);
Saurabh Shahab47c692014-02-12 18:45:57 -08002055 }
2056
2057 if(isYuvBuffer(hnd) && (transform & HWC_TRANSFORM_ROT_90)) {
2058 (*rot) = ctx->mRotMgr->getNext();
2059 if((*rot) == NULL) return -1;
Saurabh Shah39240c92014-03-31 10:31:42 -07002060 ctx->mLayerRotMap[mDpy]->add(layer, *rot);
Saurabh Shah1bd5b6f2014-05-19 12:23:13 -07002061 //If the video is using a single pipe, enable BWC
2062 if(rDest == OV_INVALID) {
2063 BwcPM::setBwc(crop, dst, transform, mdpFlags);
2064 }
Saurabh Shahab47c692014-02-12 18:45:57 -08002065 //Configure rotator for pre-rotation
Saurabh Shah97e2d802014-04-14 18:03:54 -07002066 if(configRotator(*rot, whf, crop, mdpFlags, orient, downscale) < 0) {
Saurabh Shahab47c692014-02-12 18:45:57 -08002067 ALOGE("%s: configRotator failed!", __FUNCTION__);
2068 return -1;
2069 }
Saurabh Shahab47c692014-02-12 18:45:57 -08002070 whf.format = (*rot)->getDstFormat();
2071 updateSource(orient, whf, crop);
2072 rotFlags |= ROT_PREROTATED;
2073 }
2074
2075 //If 2 pipes being used, divide layer into half, crop and dst
2076 hwc_rect_t cropL = crop;
2077 hwc_rect_t cropR = crop;
2078 hwc_rect_t dstL = dst;
2079 hwc_rect_t dstR = dst;
2080 if(lDest != OV_INVALID && rDest != OV_INVALID) {
2081 cropL.right = (crop.right + crop.left) / 2;
2082 cropR.left = cropL.right;
2083 sanitizeSourceCrop(cropL, cropR, hnd);
2084
2085 //Swap crops on H flip since 2 pipes are being used
2086 if((orient & OVERLAY_TRANSFORM_FLIP_H) && (*rot) == NULL) {
2087 hwc_rect_t tmp = cropL;
2088 cropL = cropR;
2089 cropR = tmp;
2090 }
2091
2092 dstL.right = (dst.right + dst.left) / 2;
2093 dstR.left = dstL.right;
2094 }
2095
2096 //For the mdp, since either we are pre-rotating or MDP does flips
2097 orient = OVERLAY_TRANSFORM_0;
2098 transform = 0;
2099
2100 //configure left pipe
2101 if(lDest != OV_INVALID) {
Saurabh Shah97e2d802014-04-14 18:03:54 -07002102 PipeArgs pargL(mdpFlags, whf, z, isFg,
Saurabh Shahab47c692014-02-12 18:45:57 -08002103 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2104 (ovutils::eBlending) getBlending(layer->blending));
2105
2106 if(configMdp(ctx->mOverlay, pargL, orient,
2107 cropL, dstL, metadata, lDest) < 0) {
2108 ALOGE("%s: commit failed for left mixer config", __FUNCTION__);
2109 return -1;
2110 }
2111 }
2112
2113 //configure right pipe
2114 if(rDest != OV_INVALID) {
Saurabh Shah97e2d802014-04-14 18:03:54 -07002115 PipeArgs pargR(mdpFlags, whf, z, isFg,
Saurabh Shahab47c692014-02-12 18:45:57 -08002116 static_cast<eRotFlags>(rotFlags),
2117 layer->planeAlpha,
2118 (ovutils::eBlending) getBlending(layer->blending));
2119 if(configMdp(ctx->mOverlay, pargR, orient,
2120 cropR, dstR, metadata, rDest) < 0) {
2121 ALOGE("%s: commit failed for right mixer config", __FUNCTION__);
2122 return -1;
2123 }
2124 }
2125
2126 return 0;
2127}
2128
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002129}; //namespace
2130