blob: 8f2a6e80b1fc2d16b8b25b76912e217c03e5897c [file] [log] [blame]
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001/*
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08002 * Copyright (C) 2012-2014, The Linux Foundation. All rights reserved.
Naseer Ahmed7c958d42012-07-31 18:57:03 -07003 * Not a Contribution, Apache license notifications and license are retained
4 * for attribution purposes only.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
Saurabh Shah4fdde762013-04-30 18:47:33 -070019#include <math.h>
Naseer Ahmed7c958d42012-07-31 18:57:03 -070020#include "hwc_mdpcomp.h"
Naseer Ahmed54821fe2012-11-28 18:44:38 -050021#include <sys/ioctl.h>
Saurabh Shah56f610d2012-08-07 15:27:06 -070022#include "external.h"
Jeykumar Sankaran27dee262013-08-01 17:09:54 -070023#include "virtual.h"
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -080024#include "qdMetaData.h"
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -080025#include "mdp_version.h"
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -070026#include "hwc_fbupdate.h"
Saurabh Shaha9da08f2013-07-03 13:27:53 -070027#include "hwc_ad.h"
Saurabh Shahacf10202013-02-26 10:15:15 -080028#include <overlayRotator.h>
29
Saurabh Shah85234ec2013-04-12 17:09:00 -070030using namespace overlay;
Saurabh Shahbd2d0832013-04-04 14:33:08 -070031using namespace qdutils;
Saurabh Shahacf10202013-02-26 10:15:15 -080032using namespace overlay::utils;
33namespace ovutils = overlay::utils;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070034
Naseer Ahmed7c958d42012-07-31 18:57:03 -070035namespace qhwc {
36
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080037//==============MDPComp========================================================
38
Naseer Ahmed7c958d42012-07-31 18:57:03 -070039IdleInvalidator *MDPComp::idleInvalidator = NULL;
40bool MDPComp::sIdleFallBack = false;
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -080041bool MDPComp::sHandleTimeout = false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070042bool MDPComp::sDebugLogs = false;
Naseer Ahmed54821fe2012-11-28 18:44:38 -050043bool MDPComp::sEnabled = false;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -070044bool MDPComp::sEnableMixedMode = true;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -070045bool MDPComp::sEnablePartialFrameUpdate = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080046int MDPComp::sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
radhakrishnac9a67412013-09-25 17:40:42 +053047bool MDPComp::sEnable4k2kYUVSplit = false;
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) {
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -070050
Saurabh Shah88e4d272013-09-03 13:31:29 -070051 if(isDisplaySplit(ctx, dpy)) {
Saurabh Shahab47c692014-02-12 18:45:57 -080052 if(qdutils::MDPVersion::getInstance().isSrcSplit()) {
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -070053 sSrcSplitEnabled = true;
Saurabh Shahab47c692014-02-12 18:45:57 -080054 return new MDPCompSrcSplit(dpy);
55 }
Saurabh Shah88e4d272013-09-03 13:31:29 -070056 return new MDPCompSplit(dpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080057 }
Saurabh Shah88e4d272013-09-03 13:31:29 -070058 return new MDPCompNonSplit(dpy);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080059}
60
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080061MDPComp::MDPComp(int dpy):mDpy(dpy){};
62
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080063void MDPComp::dump(android::String8& buf)
64{
Jeykumar Sankaran3c6bb042013-08-15 14:01:04 -070065 if(mCurrentFrame.layerCount > MAX_NUM_APP_LAYERS)
66 return;
67
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080068 dumpsys_log(buf,"HWC Map for Dpy: %s \n",
Jeykumar Sankaran27dee262013-08-01 17:09:54 -070069 (mDpy == 0) ? "\"PRIMARY\"" :
70 (mDpy == 1) ? "\"EXTERNAL\"" : "\"VIRTUAL\"");
Saurabh Shahe9bc60f2013-08-29 12:58:06 -070071 dumpsys_log(buf,"CURR_FRAME: layerCount:%2d mdpCount:%2d "
72 "fbCount:%2d \n", mCurrentFrame.layerCount,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080073 mCurrentFrame.mdpCount, mCurrentFrame.fbCount);
74 dumpsys_log(buf,"needsFBRedraw:%3s pipesUsed:%2d MaxPipesPerMixer: %d \n",
75 (mCurrentFrame.needsRedraw? "YES" : "NO"),
76 mCurrentFrame.mdpCount, sMaxPipesPerMixer);
77 dumpsys_log(buf," --------------------------------------------- \n");
78 dumpsys_log(buf," listIdx | cached? | mdpIndex | comptype | Z \n");
79 dumpsys_log(buf," --------------------------------------------- \n");
80 for(int index = 0; index < mCurrentFrame.layerCount; index++ )
81 dumpsys_log(buf," %7d | %7s | %8d | %9s | %2d \n",
82 index,
83 (mCurrentFrame.isFBComposed[index] ? "YES" : "NO"),
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -070084 mCurrentFrame.layerToMDP[index],
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080085 (mCurrentFrame.isFBComposed[index] ?
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -070086 (mCurrentFrame.drop[index] ? "DROP" :
87 (mCurrentFrame.needsRedraw ? "GLES" : "CACHE")) : "MDP"),
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080088 (mCurrentFrame.isFBComposed[index] ? mCurrentFrame.fbZ :
89 mCurrentFrame.mdpToLayer[mCurrentFrame.layerToMDP[index]].pipeInfo->zOrder));
90 dumpsys_log(buf,"\n");
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080091}
92
93bool MDPComp::init(hwc_context_t *ctx) {
94
95 if(!ctx) {
96 ALOGE("%s: Invalid hwc context!!",__FUNCTION__);
97 return false;
98 }
99
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800100 char property[PROPERTY_VALUE_MAX];
101
102 sEnabled = false;
103 if((property_get("persist.hwc.mdpcomp.enable", property, NULL) > 0) &&
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800104 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
105 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800106 sEnabled = true;
107 }
108
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700109 sEnableMixedMode = true;
110 if((property_get("debug.mdpcomp.mixedmode.disable", property, NULL) > 0) &&
111 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
112 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
113 sEnableMixedMode = false;
114 }
115
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800116 if(property_get("debug.mdpcomp.logs", property, NULL) > 0) {
117 if(atoi(property) != 0)
118 sDebugLogs = true;
119 }
120
Jeykumar Sankaran7d6c4c02014-02-19 12:40:57 -0800121 if(property_get("persist.hwc.partialupdate", property, NULL) > 0) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700122 if((atoi(property) != 0) && ctx->mMDP.panel == MIPI_CMD_PANEL &&
123 qdutils::MDPVersion::getInstance().is8x74v2())
124 sEnablePartialFrameUpdate = true;
125 }
126 ALOGE_IF(isDebug(), "%s: Partial Update applicable?: %d",__FUNCTION__,
127 sEnablePartialFrameUpdate);
128
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800129 sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
Saurabh Shah85234ec2013-04-12 17:09:00 -0700130 if(property_get("debug.mdpcomp.maxpermixer", property, "-1") > 0) {
131 int val = atoi(property);
132 if(val >= 0)
133 sMaxPipesPerMixer = min(val, MAX_PIPES_PER_MIXER);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800134 }
135
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400136 if(ctx->mMDP.panel != MIPI_CMD_PANEL) {
137 // Idle invalidation is not necessary on command mode panels
138 long idle_timeout = DEFAULT_IDLE_TIME;
139 if(property_get("debug.mdpcomp.idletime", property, NULL) > 0) {
140 if(atoi(property) != 0)
141 idle_timeout = atoi(property);
142 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800143
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400144 //create Idle Invalidator only when not disabled through property
145 if(idle_timeout != -1)
146 idleInvalidator = IdleInvalidator::getInstance();
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800147
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400148 if(idleInvalidator == NULL) {
149 ALOGE("%s: failed to instantiate idleInvalidator object",
150 __FUNCTION__);
151 } else {
152 idleInvalidator->init(timeout_handler, ctx, idle_timeout);
153 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800154 }
radhakrishnac9a67412013-09-25 17:40:42 +0530155
156 if((property_get("debug.mdpcomp.4k2kSplit", property, "0") > 0) &&
157 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
158 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
159 sEnable4k2kYUVSplit = true;
160 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700161 return true;
162}
163
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800164void MDPComp::reset(hwc_context_t *ctx) {
165 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700166 mCurrentFrame.reset(numLayers);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800167 ctx->mOverlay->clear(mDpy);
168 ctx->mLayerRotMap[mDpy]->clear();
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700169}
170
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700171void MDPComp::timeout_handler(void *udata) {
172 struct hwc_context_t* ctx = (struct hwc_context_t*)(udata);
173
174 if(!ctx) {
175 ALOGE("%s: received empty data in timer callback", __FUNCTION__);
176 return;
177 }
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -0800178 Locker::Autolock _l(ctx->mDrawLock);
179 // Handle timeout event only if the previous composition is MDP or MIXED.
180 if(!sHandleTimeout) {
181 ALOGD_IF(isDebug(), "%s:Do not handle this timeout", __FUNCTION__);
182 return;
183 }
Jesse Hall3be78d92012-08-21 15:12:23 -0700184 if(!ctx->proc) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700185 ALOGE("%s: HWC proc not registered", __FUNCTION__);
186 return;
187 }
188 sIdleFallBack = true;
189 /* Trigger SF to redraw the current frame */
Jesse Hall3be78d92012-08-21 15:12:23 -0700190 ctx->proc->invalidate(ctx->proc);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700191}
192
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800193void MDPComp::setMDPCompLayerFlags(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800194 hwc_display_contents_1_t* list) {
195 LayerProp *layerProp = ctx->layerProp[mDpy];
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800196
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800197 for(int index = 0; index < ctx->listStats[mDpy].numAppLayers; index++) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800198 hwc_layer_1_t* layer = &(list->hwLayers[index]);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800199 if(!mCurrentFrame.isFBComposed[index]) {
200 layerProp[index].mFlags |= HWC_MDPCOMP;
201 layer->compositionType = HWC_OVERLAY;
202 layer->hints |= HWC_HINT_CLEAR_FB;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800203 } else {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700204 /* Drop the layer when its already present in FB OR when it lies
205 * outside frame's ROI */
206 if(!mCurrentFrame.needsRedraw || mCurrentFrame.drop[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800207 layer->compositionType = HWC_OVERLAY;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700208 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800209 }
210 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700211}
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500212
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800213void MDPComp::setRedraw(hwc_context_t *ctx,
214 hwc_display_contents_1_t* list) {
215 mCurrentFrame.needsRedraw = false;
216 if(!mCachedFrame.isSameFrame(mCurrentFrame, list) ||
217 (list->flags & HWC_GEOMETRY_CHANGED) ||
218 isSkipPresent(ctx, mDpy)) {
219 mCurrentFrame.needsRedraw = true;
220 }
221}
222
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800223MDPComp::FrameInfo::FrameInfo() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700224 reset(0);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800225}
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800226
Saurabh Shahaa236822013-04-24 18:07:26 -0700227void MDPComp::FrameInfo::reset(const int& numLayers) {
228 for(int i = 0 ; i < MAX_PIPES_PER_MIXER && numLayers; i++ ) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800229 if(mdpToLayer[i].pipeInfo) {
230 delete mdpToLayer[i].pipeInfo;
231 mdpToLayer[i].pipeInfo = NULL;
232 //We dont own the rotator
233 mdpToLayer[i].rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800234 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800235 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800236
237 memset(&mdpToLayer, 0, sizeof(mdpToLayer));
238 memset(&layerToMDP, -1, sizeof(layerToMDP));
Saurabh Shahaa236822013-04-24 18:07:26 -0700239 memset(&isFBComposed, 1, sizeof(isFBComposed));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800240
Saurabh Shahaa236822013-04-24 18:07:26 -0700241 layerCount = numLayers;
242 fbCount = numLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800243 mdpCount = 0;
Saurabh Shah2f3895f2013-05-02 10:13:31 -0700244 needsRedraw = true;
Saurabh Shahd53bc5f2014-02-05 10:17:43 -0800245 fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800246}
247
Saurabh Shahaa236822013-04-24 18:07:26 -0700248void MDPComp::FrameInfo::map() {
249 // populate layer and MDP maps
250 int mdpIdx = 0;
251 for(int idx = 0; idx < layerCount; idx++) {
252 if(!isFBComposed[idx]) {
253 mdpToLayer[mdpIdx].listIndex = idx;
254 layerToMDP[idx] = mdpIdx++;
255 }
256 }
257}
258
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800259MDPComp::LayerCache::LayerCache() {
260 reset();
261}
262
263void MDPComp::LayerCache::reset() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700264 memset(&hnd, 0, sizeof(hnd));
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530265 memset(&isFBComposed, true, sizeof(isFBComposed));
266 memset(&drop, false, sizeof(drop));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800267 layerCount = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -0700268}
269
270void MDPComp::LayerCache::cacheAll(hwc_display_contents_1_t* list) {
271 const int numAppLayers = list->numHwLayers - 1;
272 for(int i = 0; i < numAppLayers; i++) {
273 hnd[i] = list->hwLayers[i].handle;
274 }
275}
276
277void MDPComp::LayerCache::updateCounts(const FrameInfo& curFrame) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700278 layerCount = curFrame.layerCount;
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530279 memcpy(&isFBComposed, &curFrame.isFBComposed, sizeof(isFBComposed));
280 memcpy(&drop, &curFrame.drop, sizeof(drop));
281}
282
Jeykumar Sankaran988d3682013-11-15 11:57:16 -0800283bool MDPComp::LayerCache::isSameFrame(const FrameInfo& curFrame,
284 hwc_display_contents_1_t* list) {
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530285 if(layerCount != curFrame.layerCount)
286 return false;
287 for(int i = 0; i < curFrame.layerCount; i++) {
288 if((curFrame.isFBComposed[i] != isFBComposed[i]) ||
289 (curFrame.drop[i] != drop[i])) {
290 return false;
291 }
Jeykumar Sankaran988d3682013-11-15 11:57:16 -0800292 if(curFrame.isFBComposed[i] &&
293 (hnd[i] != list->hwLayers[i].handle)){
294 return false;
295 }
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530296 }
297 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800298}
299
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700300bool MDPComp::isSupportedForMDPComp(hwc_context_t *ctx, hwc_layer_1_t* layer) {
301 private_handle_t *hnd = (private_handle_t *)layer->handle;
302 if((not isYuvBuffer(hnd) and has90Transform(layer)) or
303 (not isValidDimension(ctx,layer))
304 //More conditions here, SKIP, sRGB+Blend etc
305 ) {
306 return false;
307 }
308 return true;
309}
310
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530311bool MDPComp::isValidDimension(hwc_context_t *ctx, hwc_layer_1_t *layer) {
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800312 private_handle_t *hnd = (private_handle_t *)layer->handle;
313
314 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -0700315 if (layer->flags & HWC_COLOR_FILL) {
316 // Color layer
317 return true;
318 }
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800319 ALOGE("%s: layer handle is NULL", __FUNCTION__);
320 return false;
321 }
322
Naseer Ahmede850a802013-09-06 13:12:52 -0400323 //XXX: Investigate doing this with pixel phase on MDSS
Naseer Ahmede77f8082013-10-10 13:42:48 -0400324 if(!isSecureBuffer(hnd) && isNonIntegralSourceCrop(layer->sourceCropf))
Naseer Ahmede850a802013-09-06 13:12:52 -0400325 return false;
326
Saurabh Shah62e1d732013-09-17 10:44:05 -0700327 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700328 hwc_rect_t dst = layer->displayFrame;
Saurabh Shah4fdde762013-04-30 18:47:33 -0700329 int crop_w = crop.right - crop.left;
330 int crop_h = crop.bottom - crop.top;
331 int dst_w = dst.right - dst.left;
332 int dst_h = dst.bottom - dst.top;
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800333 float w_scale = ((float)crop_w / (float)dst_w);
334 float h_scale = ((float)crop_h / (float)dst_h);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700335
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800336 /* Workaround for MDP HW limitation in DSI command mode panels where
337 * FPS will not go beyond 30 if buffers on RGB pipes are of width or height
338 * less than 5 pixels
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530339 * There also is a HW limilation in MDP, minimum block size is 2x2
340 * Fallback to GPU if height is less than 2.
341 */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800342 if((crop_w < 5)||(crop_h < 5))
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800343 return false;
344
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800345 if((w_scale > 1.0f) || (h_scale > 1.0f)) {
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700346 const uint32_t maxMDPDownscale =
Saurabh Shah4fdde762013-04-30 18:47:33 -0700347 qdutils::MDPVersion::getInstance().getMaxMDPDownscale();
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800348 const float w_dscale = w_scale;
349 const float h_dscale = h_scale;
350
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800351 if(ctx->mMDP.version >= qdutils::MDSS_V5) {
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700352
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800353 if(!qdutils::MDPVersion::getInstance().supportsDecimation()) {
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700354 /* On targets that doesnt support Decimation (eg.,8x26)
355 * maximum downscale support is overlay pipe downscale.
356 */
357 if(crop_w > MAX_DISPLAY_DIM || w_dscale > maxMDPDownscale ||
358 h_dscale > maxMDPDownscale)
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800359 return false;
360 } else {
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700361 // Decimation on macrotile format layers is not supported.
362 if(isTileRendered(hnd)) {
363 /* MDP can read maximum MAX_DISPLAY_DIM width.
364 * Bail out if
365 * 1. Src crop > MAX_DISPLAY_DIM on nonsplit MDPComp
366 * 2. exceeds maximum downscale limit
367 */
368 if(((crop_w > MAX_DISPLAY_DIM) && !sSrcSplitEnabled) ||
369 w_dscale > maxMDPDownscale ||
370 h_dscale > maxMDPDownscale) {
371 return false;
372 }
373 } else if(w_dscale > 64 || h_dscale > 64)
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800374 return false;
375 }
376 } else { //A-family
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700377 if(w_dscale > maxMDPDownscale || h_dscale > maxMDPDownscale)
Saurabh Shah4fdde762013-04-30 18:47:33 -0700378 return false;
379 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700380 }
381
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800382 if((w_scale < 1.0f) || (h_scale < 1.0f)) {
383 const uint32_t upscale =
384 qdutils::MDPVersion::getInstance().getMaxMDPUpscale();
385 const float w_uscale = 1.0f / w_scale;
386 const float h_uscale = 1.0f / h_scale;
387
388 if(w_uscale > upscale || h_uscale > upscale)
389 return false;
390 }
391
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800392 return true;
393}
394
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700395ovutils::eDest MDPComp::getMdpPipe(hwc_context_t *ctx, ePipeType type,
396 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800397 overlay::Overlay& ov = *ctx->mOverlay;
398 ovutils::eDest mdp_pipe = ovutils::OV_INVALID;
399
400 switch(type) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800401 case MDPCOMP_OV_DMA:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700402 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_DMA, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800403 if(mdp_pipe != ovutils::OV_INVALID) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800404 return mdp_pipe;
405 }
406 case MDPCOMP_OV_ANY:
407 case MDPCOMP_OV_RGB:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700408 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800409 if(mdp_pipe != ovutils::OV_INVALID) {
410 return mdp_pipe;
411 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800412
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800413 if(type == MDPCOMP_OV_RGB) {
414 //Requested only for RGB pipe
415 break;
416 }
417 case MDPCOMP_OV_VG:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700418 return ov.nextPipe(ovutils::OV_MDP_PIPE_VG, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800419 default:
420 ALOGE("%s: Invalid pipe type",__FUNCTION__);
421 return ovutils::OV_INVALID;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800422 };
423 return ovutils::OV_INVALID;
424}
425
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800426bool MDPComp::isFrameDoable(hwc_context_t *ctx) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700427 bool ret = true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800428
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800429 if(!isEnabled()) {
430 ALOGD_IF(isDebug(),"%s: MDP Comp. not enabled.", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700431 ret = false;
Saurabh Shahd4e65852013-06-17 11:33:53 -0700432 } else if(qdutils::MDPVersion::getInstance().is8x26() &&
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -0800433 ctx->mVideoTransFlag &&
434 isSecondaryConnected(ctx)) {
Saurabh Shahd4e65852013-06-17 11:33:53 -0700435 //1 Padding round to shift pipes across mixers
436 ALOGD_IF(isDebug(),"%s: MDP Comp. video transition padding round",
437 __FUNCTION__);
438 ret = false;
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -0800439 } else if(isSecondaryConfiguring(ctx)) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800440 ALOGD_IF( isDebug(),"%s: External Display connection is pending",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800441 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700442 ret = false;
Saurabh Shahaa236822013-04-24 18:07:26 -0700443 } else if(ctx->isPaddingRound) {
Raj Kamal9ed3d6b2014-02-07 16:15:17 +0530444 ALOGD_IF(isDebug(), "%s: padding round invoked for dpy %d",
445 __FUNCTION__,mDpy);
Saurabh Shahaa236822013-04-24 18:07:26 -0700446 ret = false;
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700447 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700448 return ret;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800449}
450
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800451/*
452 * 1) Identify layers that are not visible in the updating ROI and drop them
453 * from composition.
454 * 2) If we have a scaling layers which needs cropping against generated ROI.
455 * Reset ROI to full resolution.
456 */
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700457bool MDPComp::validateAndApplyROI(hwc_context_t *ctx,
458 hwc_display_contents_1_t* list, hwc_rect_t roi) {
459 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
460
461 if(!isValidRect(roi))
462 return false;
463
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800464 hwc_rect_t visibleRect = roi;
465
466 for(int i = numAppLayers - 1; i >= 0; i--){
467
468 if(!isValidRect(visibleRect)) {
469 mCurrentFrame.drop[i] = true;
470 mCurrentFrame.dropCount++;
Jeykumar Sankaran0b961452014-01-21 17:26:12 -0800471 continue;
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800472 }
473
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700474 const hwc_layer_1_t* layer = &list->hwLayers[i];
475
476 hwc_rect_t dstRect = layer->displayFrame;
Arun Kumar K.R91090c72013-10-28 19:40:18 -0700477 hwc_rect_t srcRect = integerizeSourceCrop(layer->sourceCropf);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700478
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800479 hwc_rect_t res = getIntersection(visibleRect, dstRect);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700480
481 int res_w = res.right - res.left;
482 int res_h = res.bottom - res.top;
483 int dst_w = dstRect.right - dstRect.left;
484 int dst_h = dstRect.bottom - dstRect.top;
485
486 if(!isValidRect(res)) {
487 mCurrentFrame.drop[i] = true;
488 mCurrentFrame.dropCount++;
489 }else {
490 /* Reset frame ROI when any layer which needs scaling also needs ROI
491 * cropping */
Jeykumar Sankaran0b961452014-01-21 17:26:12 -0800492 if((res_w != dst_w || res_h != dst_h) && needsScaling (layer)) {
Arpita Banerjeed8965982013-11-08 17:27:33 -0800493 ALOGI("%s: Resetting ROI due to scaling", __FUNCTION__);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700494 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
495 mCurrentFrame.dropCount = 0;
496 return false;
497 }
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800498
Jeykumar Sankaran0b961452014-01-21 17:26:12 -0800499 /* deduct any opaque region from visibleRect */
500 if (layer->blending == HWC_BLENDING_NONE)
501 visibleRect = deductRect(visibleRect, res);
502 }
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700503 }
504 return true;
505}
506
507void MDPComp::generateROI(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
508 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
509
510 if(!sEnablePartialFrameUpdate) {
511 return;
512 }
513
514 if(mDpy || isDisplaySplit(ctx, mDpy)){
515 ALOGE_IF(isDebug(), "%s: ROI not supported for"
516 "the (1) external / virtual display's (2) dual DSI displays",
517 __FUNCTION__);
518 return;
519 }
520
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800521 if(isSkipPresent(ctx, mDpy))
522 return;
523
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700524 if(list->flags & HWC_GEOMETRY_CHANGED)
525 return;
526
527 struct hwc_rect roi = (struct hwc_rect){0, 0, 0, 0};
528 for(int index = 0; index < numAppLayers; index++ ) {
529 if ((mCachedFrame.hnd[index] != list->hwLayers[index].handle) ||
530 isYuvBuffer((private_handle_t *)list->hwLayers[index].handle)) {
531 hwc_rect_t dstRect = list->hwLayers[index].displayFrame;
Arun Kumar K.R91090c72013-10-28 19:40:18 -0700532 hwc_rect_t srcRect = integerizeSourceCrop(
533 list->hwLayers[index].sourceCropf);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700534
535 /* Intersect against display boundaries */
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700536 roi = getUnion(roi, dstRect);
537 }
538 }
539
540 if(!validateAndApplyROI(ctx, list, roi)){
541 roi = (struct hwc_rect) {0, 0,
542 (int)ctx->dpyAttr[mDpy].xres, (int)ctx->dpyAttr[mDpy].yres};
543 }
544
545 ctx->listStats[mDpy].roi.x = roi.left;
546 ctx->listStats[mDpy].roi.y = roi.top;
547 ctx->listStats[mDpy].roi.w = roi.right - roi.left;
548 ctx->listStats[mDpy].roi.h = roi.bottom - roi.top;
549
550 ALOGD_IF(isDebug(),"%s: generated ROI: [%d, %d, %d, %d]", __FUNCTION__,
551 roi.left, roi.top, roi.right, roi.bottom);
552}
553
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800554/* Checks for conditions where all the layers marked for MDP comp cannot be
555 * bypassed. On such conditions we try to bypass atleast YUV layers */
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800556bool MDPComp::tryFullFrame(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800557 hwc_display_contents_1_t* list){
558
Saurabh Shahaa236822013-04-24 18:07:26 -0700559 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Arun Kumar K.R2e2871c2014-01-10 12:47:06 -0800560 int priDispW = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800561
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -0700562 if(sIdleFallBack && !ctx->listStats[mDpy].secureUI) {
Saurabh Shah2d998a92013-05-14 17:55:58 -0700563 ALOGD_IF(isDebug(), "%s: Idle fallback dpy %d",__FUNCTION__, mDpy);
564 return false;
565 }
566
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800567 if(isSkipPresent(ctx, mDpy)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700568 ALOGD_IF(isDebug(),"%s: SKIP present: %d",
569 __FUNCTION__,
570 isSkipPresent(ctx, mDpy));
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800571 return false;
572 }
573
Arun Kumar K.R2e2871c2014-01-10 12:47:06 -0800574 if(mDpy > HWC_DISPLAY_PRIMARY && (priDispW > MAX_DISPLAY_DIM) &&
575 (ctx->dpyAttr[mDpy].xres < MAX_DISPLAY_DIM)) {
576 // Disable MDP comp on Secondary when the primary is highres panel and
577 // the secondary is a normal 1080p, because, MDP comp on secondary under
578 // in such usecase, decimation gets used for downscale and there will be
579 // a quality mismatch when there will be a fallback to GPU comp
580 ALOGD_IF(isDebug(), "%s: Disable MDP Compositon for Secondary Disp",
581 __FUNCTION__);
582 return false;
583 }
584
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800585 // check for action safe flag and downscale mode which requires scaling.
586 if(ctx->dpyAttr[mDpy].mActionSafePresent
587 || ctx->dpyAttr[mDpy].mDownScaleMode) {
588 ALOGD_IF(isDebug(), "%s: Scaling needed for this frame",__FUNCTION__);
589 return false;
590 }
591
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800592 for(int i = 0; i < numAppLayers; ++i) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800593 hwc_layer_1_t* layer = &list->hwLayers[i];
594 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800595
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700596 if(isYuvBuffer(hnd) && has90Transform(layer)) {
597 if(!canUseRotator(ctx, mDpy)) {
598 ALOGD_IF(isDebug(), "%s: Can't use rotator for dpy %d",
599 __FUNCTION__, mDpy);
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700600 return false;
601 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800602 }
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530603
604 //For 8x26 with panel width>1k, if RGB layer needs HFLIP fail mdp comp
605 // may not need it if Gfx pre-rotation can handle all flips & rotations
Sushil Chauhanfda00fc2014-03-20 11:08:41 -0700606 int transform = (layer->flags & HWC_COLOR_FILL) ? 0 : layer->transform;
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530607 if(qdutils::MDPVersion::getInstance().is8x26() &&
608 (ctx->dpyAttr[mDpy].xres > 1024) &&
Sushil Chauhanfda00fc2014-03-20 11:08:41 -0700609 (transform & HWC_TRANSFORM_FLIP_H) &&
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530610 (!isYuvBuffer(hnd)))
611 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800612 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700613
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700614 if(ctx->mAD->isDoable()) {
615 return false;
616 }
617
Saurabh Shahaa236822013-04-24 18:07:26 -0700618 //If all above hard conditions are met we can do full or partial MDP comp.
619 bool ret = false;
620 if(fullMDPComp(ctx, list)) {
621 ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700622 } else if(partialMDPComp(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700623 ret = true;
624 }
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530625
Saurabh Shahaa236822013-04-24 18:07:26 -0700626 return ret;
627}
628
629bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700630 //Will benefit presentation / secondary-only layer.
631 if((mDpy > HWC_DISPLAY_PRIMARY) &&
632 (list->numHwLayers - 1) > MAX_SEC_LAYERS) {
633 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
634 return false;
635 }
636
637 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
638 for(int i = 0; i < numAppLayers; i++) {
639 hwc_layer_1_t* layer = &list->hwLayers[i];
640 if(not isSupportedForMDPComp(ctx, layer)) {
641 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",__FUNCTION__);
642 return false;
643 }
Yang Xu9c1eb2b2013-11-26 01:28:13 +0800644
645 //For 8x26, if there is only one layer which needs scale for secondary
646 //while no scale for primary display, DMA pipe is occupied by primary.
647 //If need to fall back to GLES composition, virtual display lacks DMA
648 //pipe and error is reported.
649 if(qdutils::MDPVersion::getInstance().is8x26() &&
650 mDpy >= HWC_DISPLAY_EXTERNAL &&
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530651 qhwc::needsScaling(layer))
Yang Xu9c1eb2b2013-11-26 01:28:13 +0800652 return false;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700653 }
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800654
Saurabh Shahaa236822013-04-24 18:07:26 -0700655 mCurrentFrame.fbCount = 0;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700656 memcpy(&mCurrentFrame.isFBComposed, &mCurrentFrame.drop,
657 sizeof(mCurrentFrame.isFBComposed));
658 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount -
659 mCurrentFrame.dropCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700660
radhakrishnac9a67412013-09-25 17:40:42 +0530661 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800662 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530663 }
664
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800665 if(!postHeuristicsHandling(ctx, list)) {
666 ALOGD_IF(isDebug(), "post heuristic handling failed");
667 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700668 return false;
669 }
670
Saurabh Shahaa236822013-04-24 18:07:26 -0700671 return true;
672}
673
674bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
675{
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700676 if(!sEnableMixedMode) {
677 //Mixed mode is disabled. No need to even try caching.
678 return false;
679 }
680
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700681 bool ret = false;
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800682 if(list->flags & HWC_GEOMETRY_CHANGED) { //Try load based first
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800683 ret = loadBasedComp(ctx, list) or
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800684 cacheBasedComp(ctx, list);
685 } else {
686 ret = cacheBasedComp(ctx, list) or
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800687 loadBasedComp(ctx, list);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700688 }
689
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700690 return ret;
691}
692
693bool MDPComp::cacheBasedComp(hwc_context_t *ctx,
694 hwc_display_contents_1_t* list) {
695 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700696 mCurrentFrame.reset(numAppLayers);
697 updateLayerCache(ctx, list);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700698
699 //If an MDP marked layer is unsupported cannot do partial MDP Comp
700 for(int i = 0; i < numAppLayers; i++) {
701 if(!mCurrentFrame.isFBComposed[i]) {
702 hwc_layer_1_t* layer = &list->hwLayers[i];
703 if(not isSupportedForMDPComp(ctx, layer)) {
704 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",
705 __FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800706 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700707 return false;
708 }
709 }
710 }
711
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700712 updateYUV(ctx, list, false /*secure only*/);
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530713 bool ret = markLayersForCaching(ctx, list); //sets up fbZ also
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700714 if(!ret) {
715 ALOGD_IF(isDebug(),"%s: batching failed, dpy %d",__FUNCTION__, mDpy);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800716 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700717 return false;
718 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700719
720 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700721
radhakrishnac9a67412013-09-25 17:40:42 +0530722 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800723 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530724 }
725
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700726 //Will benefit cases where a video has non-updating background.
727 if((mDpy > HWC_DISPLAY_PRIMARY) and
728 (mdpCount > MAX_SEC_LAYERS)) {
729 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800730 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700731 return false;
732 }
733
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800734 if(!postHeuristicsHandling(ctx, list)) {
735 ALOGD_IF(isDebug(), "post heuristic handling failed");
736 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700737 return false;
738 }
739
Saurabh Shahaa236822013-04-24 18:07:26 -0700740 return true;
741}
742
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800743bool MDPComp::loadBasedComp(hwc_context_t *ctx,
Saurabh Shahb772ae32013-11-18 15:40:02 -0800744 hwc_display_contents_1_t* list) {
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -0800745 if(not isLoadBasedCompDoable(ctx)) {
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800746 return false;
747 }
748
Saurabh Shahb772ae32013-11-18 15:40:02 -0800749 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800750 const int numNonDroppedLayers = numAppLayers - mCurrentFrame.dropCount;
751 const int stagesForMDP = min(sMaxPipesPerMixer,
752 ctx->mOverlay->availablePipes(mDpy, Overlay::MIXER_DEFAULT));
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800753
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800754 int mdpBatchSize = stagesForMDP - 1; //1 stage for FB
755 int fbBatchSize = numNonDroppedLayers - mdpBatchSize;
756 int lastMDPSupportedIndex = numAppLayers;
757 int dropCount = 0;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800758
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800759 //Find the minimum MDP batch size
760 for(int i = 0; i < numAppLayers;i++) {
761 if(mCurrentFrame.drop[i]) {
762 dropCount++;
Jeykumar Sankaran846e2792014-01-23 21:59:58 -0800763 continue;
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800764 }
765 hwc_layer_1_t* layer = &list->hwLayers[i];
766 if(not isSupportedForMDPComp(ctx, layer)) {
767 lastMDPSupportedIndex = i;
768 mdpBatchSize = min(i - dropCount, stagesForMDP - 1);
769 fbBatchSize = numNonDroppedLayers - mdpBatchSize;
Jeykumar Sankaran846e2792014-01-23 21:59:58 -0800770 break;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800771 }
Saurabh Shahb772ae32013-11-18 15:40:02 -0800772 }
773
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800774 ALOGD_IF(isDebug(), "%s:Before optimizing fbBatch, mdpbatch %d, fbbatch %d "
775 "dropped %d", __FUNCTION__, mdpBatchSize, fbBatchSize,
776 mCurrentFrame.dropCount);
777
778 //Start at a point where the fb batch should at least have 2 layers, for
779 //this mode to be justified.
780 while(fbBatchSize < 2) {
781 ++fbBatchSize;
782 --mdpBatchSize;
Jeykumar Sankaran846e2792014-01-23 21:59:58 -0800783 }
Saurabh Shahb772ae32013-11-18 15:40:02 -0800784
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800785 //If there are no layers for MDP, this mode doesnt make sense.
786 if(mdpBatchSize < 1) {
787 ALOGD_IF(isDebug(), "%s: No MDP layers after optimizing for fbBatch",
788 __FUNCTION__);
Saurabh Shahb772ae32013-11-18 15:40:02 -0800789 return false;
790 }
791
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800792 mCurrentFrame.reset(numAppLayers);
793
794 //Try with successively smaller mdp batch sizes until we succeed or reach 1
795 while(mdpBatchSize > 0) {
796 //Mark layers for MDP comp
797 int mdpBatchLeft = mdpBatchSize;
798 for(int i = 0; i < lastMDPSupportedIndex and mdpBatchLeft; i++) {
799 if(mCurrentFrame.drop[i]) {
800 continue;
801 }
802 mCurrentFrame.isFBComposed[i] = false;
803 --mdpBatchLeft;
804 }
805
806 mCurrentFrame.fbZ = mdpBatchSize;
807 mCurrentFrame.fbCount = fbBatchSize;
808 mCurrentFrame.mdpCount = mdpBatchSize;
809
810 ALOGD_IF(isDebug(), "%s:Trying with: mdpbatch %d fbbatch %d dropped %d",
811 __FUNCTION__, mdpBatchSize, fbBatchSize,
812 mCurrentFrame.dropCount);
813
814 if(postHeuristicsHandling(ctx, list)) {
815 ALOGD_IF(isDebug(), "%s: Postheuristics handling succeeded",
816 __FUNCTION__);
817 return true;
818 }
819
820 reset(ctx);
821 --mdpBatchSize;
822 ++fbBatchSize;
823 }
824
825 return false;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800826}
827
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -0800828bool MDPComp::isLoadBasedCompDoable(hwc_context_t *ctx) {
Prabhanjan Kandula3dbbd882013-12-11 14:43:46 +0530829 if(mDpy or isSecurePresent(ctx, mDpy) or
830 isYuvPresent(ctx, mDpy)) {
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700831 return false;
832 }
833 return true;
834}
835
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800836bool MDPComp::tryVideoOnly(hwc_context_t *ctx,
837 hwc_display_contents_1_t* list) {
838 const bool secureOnly = true;
839 return videoOnlyComp(ctx, list, not secureOnly) or
840 videoOnlyComp(ctx, list, secureOnly);
841}
842
843bool MDPComp::videoOnlyComp(hwc_context_t *ctx,
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700844 hwc_display_contents_1_t* list, bool secureOnly) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700845 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700846
Saurabh Shahaa236822013-04-24 18:07:26 -0700847 mCurrentFrame.reset(numAppLayers);
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700848 updateYUV(ctx, list, secureOnly);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700849 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700850
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800851 if(!isYuvPresent(ctx, mDpy) or (mdpCount == 0)) {
852 reset(ctx);
Saurabh Shahaa236822013-04-24 18:07:26 -0700853 return false;
854 }
855
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -0800856 /* Bail out if we are processing only secured video layers
857 * and we dont have any */
858 if(!isSecurePresent(ctx, mDpy) && secureOnly){
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800859 reset(ctx);
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -0800860 return false;
861 }
862
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800863 if(mCurrentFrame.fbCount)
864 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
Saurabh Shah4fdde762013-04-30 18:47:33 -0700865
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800866 if(sEnable4k2kYUVSplit){
867 adjustForSourceSplit(ctx, list);
868 }
869
870 if(!postHeuristicsHandling(ctx, list)) {
871 ALOGD_IF(isDebug(), "post heuristic handling failed");
872 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700873 return false;
874 }
875
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800876 return true;
877}
878
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800879/* Checks for conditions where YUV layers cannot be bypassed */
880bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -0700881 if(isSkipLayer(layer)) {
Saurabh Shahe2474082013-05-15 16:32:13 -0700882 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800883 return false;
884 }
885
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700886 if(layer->transform & HWC_TRANSFORM_ROT_90 && !canUseRotator(ctx,mDpy)) {
887 ALOGD_IF(isDebug(), "%s: no free DMA pipe",__FUNCTION__);
888 return false;
889 }
890
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800891 if(isSecuring(ctx, layer)) {
892 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
893 return false;
894 }
895
Saurabh Shah4fdde762013-04-30 18:47:33 -0700896 if(!isValidDimension(ctx, layer)) {
897 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
898 __FUNCTION__);
899 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800900 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700901
Naseer Ahmeddc61a972013-07-10 17:50:54 -0400902 if(layer->planeAlpha < 0xFF) {
903 ALOGD_IF(isDebug(), "%s: Cannot handle YUV layer with plane alpha\
904 in video only mode",
905 __FUNCTION__);
906 return false;
907 }
908
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800909 return true;
910}
911
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530912/* starts at fromIndex and check for each layer to find
913 * if it it has overlapping with any Updating layer above it in zorder
914 * till the end of the batch. returns true if it finds any intersection */
915bool MDPComp::canPushBatchToTop(const hwc_display_contents_1_t* list,
916 int fromIndex, int toIndex) {
917 for(int i = fromIndex; i < toIndex; i++) {
918 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
919 if(intersectingUpdatingLayers(list, i+1, toIndex, i)) {
920 return false;
921 }
922 }
923 }
924 return true;
925}
926
927/* Checks if given layer at targetLayerIndex has any
928 * intersection with all the updating layers in beween
929 * fromIndex and toIndex. Returns true if it finds intersectiion */
930bool MDPComp::intersectingUpdatingLayers(const hwc_display_contents_1_t* list,
931 int fromIndex, int toIndex, int targetLayerIndex) {
932 for(int i = fromIndex; i <= toIndex; i++) {
933 if(!mCurrentFrame.isFBComposed[i]) {
934 if(areLayersIntersecting(&list->hwLayers[i],
935 &list->hwLayers[targetLayerIndex])) {
936 return true;
937 }
938 }
939 }
940 return false;
941}
942
943int MDPComp::getBatch(hwc_display_contents_1_t* list,
944 int& maxBatchStart, int& maxBatchEnd,
945 int& maxBatchCount) {
946 int i = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530947 int fbZOrder =-1;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -0800948 int droppedLayerCt = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530949 while (i < mCurrentFrame.layerCount) {
950 int batchCount = 0;
951 int batchStart = i;
952 int batchEnd = i;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -0800953 /* Adjust batch Z order with the dropped layers so far */
954 int fbZ = batchStart - droppedLayerCt;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530955 int firstZReverseIndex = -1;
Prabhanjan Kandula0ed2cc92013-12-06 12:39:04 +0530956 int updatingLayersAbove = 0;//Updating layer count in middle of batch
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530957 while(i < mCurrentFrame.layerCount) {
958 if(!mCurrentFrame.isFBComposed[i]) {
959 if(!batchCount) {
960 i++;
961 break;
962 }
963 updatingLayersAbove++;
964 i++;
965 continue;
966 } else {
967 if(mCurrentFrame.drop[i]) {
968 i++;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -0800969 droppedLayerCt++;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530970 continue;
971 } else if(updatingLayersAbove <= 0) {
972 batchCount++;
973 batchEnd = i;
974 i++;
975 continue;
976 } else { //Layer is FBComposed, not a drop & updatingLayer > 0
977
978 // We have a valid updating layer already. If layer-i not
979 // have overlapping with all updating layers in between
980 // batch-start and i, then we can add layer i to batch.
981 if(!intersectingUpdatingLayers(list, batchStart, i-1, i)) {
982 batchCount++;
983 batchEnd = i;
984 i++;
985 continue;
986 } else if(canPushBatchToTop(list, batchStart, i)) {
987 //If All the non-updating layers with in this batch
988 //does not have intersection with the updating layers
989 //above in z-order, then we can safely move the batch to
990 //higher z-order. Increment fbZ as it is moving up.
991 if( firstZReverseIndex < 0) {
992 firstZReverseIndex = i;
993 }
994 batchCount++;
995 batchEnd = i;
996 fbZ += updatingLayersAbove;
997 i++;
998 updatingLayersAbove = 0;
999 continue;
1000 } else {
1001 //both failed.start the loop again from here.
1002 if(firstZReverseIndex >= 0) {
1003 i = firstZReverseIndex;
1004 }
1005 break;
1006 }
1007 }
1008 }
1009 }
1010 if(batchCount > maxBatchCount) {
1011 maxBatchCount = batchCount;
1012 maxBatchStart = batchStart;
1013 maxBatchEnd = batchEnd;
1014 fbZOrder = fbZ;
1015 }
1016 }
1017 return fbZOrder;
1018}
1019
1020bool MDPComp::markLayersForCaching(hwc_context_t* ctx,
1021 hwc_display_contents_1_t* list) {
1022 /* Idea is to keep as many non-updating(cached) layers in FB and
1023 * send rest of them through MDP. This is done in 2 steps.
1024 * 1. Find the maximum contiguous batch of non-updating layers.
1025 * 2. See if we can improve this batch size for caching by adding
1026 * opaque layers around the batch, if they don't have
1027 * any overlapping with the updating layers in between.
1028 * NEVER mark an updating layer for caching.
1029 * But cached ones can be marked for MDP */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001030
1031 int maxBatchStart = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001032 int maxBatchEnd = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001033 int maxBatchCount = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301034 int fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001035
Saurabh Shahd53bc5f2014-02-05 10:17:43 -08001036 /* Nothing is cached. No batching needed */
1037 if(mCurrentFrame.fbCount == 0) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001038 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -07001039 }
Saurabh Shahd53bc5f2014-02-05 10:17:43 -08001040
1041 /* No MDP comp layers, try to use other comp modes */
1042 if(mCurrentFrame.mdpCount == 0) {
1043 return false;
Saurabh Shahaa236822013-04-24 18:07:26 -07001044 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001045
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301046 fbZ = getBatch(list, maxBatchStart, maxBatchEnd, maxBatchCount);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001047
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301048 /* reset rest of the layers lying inside ROI for MDP comp */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001049 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001050 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001051 if((i < maxBatchStart || i > maxBatchEnd) &&
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301052 mCurrentFrame.isFBComposed[i]){
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001053 if(!mCurrentFrame.drop[i]){
1054 //If an unsupported layer is being attempted to
1055 //be pulled out we should fail
1056 if(not isSupportedForMDPComp(ctx, layer)) {
1057 return false;
1058 }
1059 mCurrentFrame.isFBComposed[i] = false;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001060 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001061 }
1062 }
1063
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301064 // update the frame data
1065 mCurrentFrame.fbZ = fbZ;
1066 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001067 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001068 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001069
1070 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301071 mCurrentFrame.fbCount);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001072
1073 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001074}
Saurabh Shah85234ec2013-04-12 17:09:00 -07001075
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001076void MDPComp::updateLayerCache(hwc_context_t* ctx,
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001077 hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001078 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001079 int fbCount = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001080
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001081 for(int i = 0; i < numAppLayers; i++) {
1082 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001083 if(!mCurrentFrame.drop[i])
1084 fbCount++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001085 mCurrentFrame.isFBComposed[i] = true;
1086 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -07001087 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001088 }
1089 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001090
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001091 mCurrentFrame.fbCount = fbCount;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001092 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount
1093 - mCurrentFrame.dropCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001094
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001095 ALOGD_IF(isDebug(),"%s: MDP count: %d FB count %d drop count: %d"
1096 ,__FUNCTION__, mCurrentFrame.mdpCount, mCurrentFrame.fbCount,
1097 mCurrentFrame.dropCount);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001098}
1099
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001100void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list,
1101 bool secureOnly) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001102 int nYuvCount = ctx->listStats[mDpy].yuvCount;
1103 for(int index = 0;index < nYuvCount; index++){
1104 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
1105 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
1106
1107 if(!isYUVDoable(ctx, layer)) {
1108 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
1109 mCurrentFrame.isFBComposed[nYuvIndex] = true;
1110 mCurrentFrame.fbCount++;
1111 }
1112 } else {
1113 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001114 private_handle_t *hnd = (private_handle_t *)layer->handle;
1115 if(!secureOnly || isSecureBuffer(hnd)) {
1116 mCurrentFrame.isFBComposed[nYuvIndex] = false;
1117 mCurrentFrame.fbCount--;
1118 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001119 }
1120 }
1121 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001122
1123 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001124 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
1125 ALOGD_IF(isDebug(),"%s: fb count: %d",__FUNCTION__,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001126 mCurrentFrame.fbCount);
1127}
1128
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001129hwc_rect_t MDPComp::getUpdatingFBRect(hwc_context_t *ctx,
1130 hwc_display_contents_1_t* list){
1131 hwc_rect_t fbRect = (struct hwc_rect){0, 0, 0, 0};
1132 hwc_layer_1_t *fbLayer = &list->hwLayers[mCurrentFrame.layerCount];
1133
1134 /* Update only the region of FB needed for composition */
1135 for(int i = 0; i < mCurrentFrame.layerCount; i++ ) {
1136 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
1137 hwc_layer_1_t* layer = &list->hwLayers[i];
1138 hwc_rect_t dst = layer->displayFrame;
1139 fbRect = getUnion(fbRect, dst);
1140 }
1141 }
1142 return fbRect;
1143}
1144
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001145bool MDPComp::postHeuristicsHandling(hwc_context_t *ctx,
1146 hwc_display_contents_1_t* list) {
1147
1148 //Capability checks
1149 if(!resourceCheck(ctx, list)) {
1150 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
1151 return false;
1152 }
1153
1154 //Limitations checks
1155 if(!hwLimitationsCheck(ctx, list)) {
1156 ALOGD_IF(isDebug(), "%s: HW limitations",__FUNCTION__);
1157 return false;
1158 }
1159
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001160 //Configure framebuffer first if applicable
1161 if(mCurrentFrame.fbZ >= 0) {
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001162 hwc_rect_t fbRect = getUpdatingFBRect(ctx, list);
1163 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, fbRect, mCurrentFrame.fbZ))
1164 {
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001165 ALOGD_IF(isDebug(), "%s configure framebuffer failed",
1166 __FUNCTION__);
1167 return false;
1168 }
1169 }
1170
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001171 mCurrentFrame.map();
1172
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001173 if(!allocLayerPipes(ctx, list)) {
1174 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -07001175 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001176 }
1177
1178 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001179 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001180 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001181 int mdpIndex = mCurrentFrame.layerToMDP[index];
1182 hwc_layer_1_t* layer = &list->hwLayers[index];
1183
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301184 //Leave fbZ for framebuffer. CACHE/GLES layers go here.
1185 if(mdpNextZOrder == mCurrentFrame.fbZ) {
1186 mdpNextZOrder++;
1187 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001188 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1189 cur_pipe->zOrder = mdpNextZOrder++;
1190
radhakrishnac9a67412013-09-25 17:40:42 +05301191 private_handle_t *hnd = (private_handle_t *)layer->handle;
1192 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1193 if(configure4k2kYuv(ctx, layer,
1194 mCurrentFrame.mdpToLayer[mdpIndex])
1195 != 0 ){
1196 ALOGD_IF(isDebug(), "%s: Failed to configure split pipes \
1197 for layer %d",__FUNCTION__, index);
1198 return false;
1199 }
1200 else{
1201 mdpNextZOrder++;
1202 }
1203 continue;
1204 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001205 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
1206 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
radhakrishnac9a67412013-09-25 17:40:42 +05301207 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -07001208 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001209 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001210 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001211 }
1212
Saurabh Shaha36be922013-12-16 18:18:39 -08001213 if(!ctx->mOverlay->validateAndSet(mDpy, ctx->dpyAttr[mDpy].fd)) {
1214 ALOGD_IF(isDebug(), "%s: Failed to validate and set overlay for dpy %d"
1215 ,__FUNCTION__, mDpy);
1216 return false;
1217 }
1218
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001219 setRedraw(ctx, list);
Saurabh Shahaa236822013-04-24 18:07:26 -07001220 return true;
1221}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001222
Saurabh Shah173f4242013-11-20 09:50:12 -08001223bool MDPComp::resourceCheck(hwc_context_t *ctx,
1224 hwc_display_contents_1_t *list) {
1225 const bool fbUsed = mCurrentFrame.fbCount;
1226 if(mCurrentFrame.mdpCount > sMaxPipesPerMixer - fbUsed) {
1227 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
1228 return false;
1229 }
Saurabh Shah173f4242013-11-20 09:50:12 -08001230 return true;
1231}
1232
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301233bool MDPComp::hwLimitationsCheck(hwc_context_t* ctx,
1234 hwc_display_contents_1_t* list) {
1235
1236 //A-family hw limitation:
1237 //If a layer need alpha scaling, MDP can not support.
1238 if(ctx->mMDP.version < qdutils::MDSS_V5) {
1239 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1240 if(!mCurrentFrame.isFBComposed[i] &&
1241 isAlphaScaled( &list->hwLayers[i])) {
1242 ALOGD_IF(isDebug(), "%s:frame needs alphaScaling",__FUNCTION__);
1243 return false;
1244 }
1245 }
1246 }
1247
1248 // On 8x26 & 8974 hw, we have a limitation of downscaling+blending.
1249 //If multiple layers requires downscaling and also they are overlapping
1250 //fall back to GPU since MDSS can not handle it.
1251 if(qdutils::MDPVersion::getInstance().is8x74v2() ||
1252 qdutils::MDPVersion::getInstance().is8x26()) {
1253 for(int i = 0; i < mCurrentFrame.layerCount-1; ++i) {
1254 hwc_layer_1_t* botLayer = &list->hwLayers[i];
1255 if(!mCurrentFrame.isFBComposed[i] &&
1256 isDownscaleRequired(botLayer)) {
1257 //if layer-i is marked for MDP and needs downscaling
1258 //check if any MDP layer on top of i & overlaps with layer-i
1259 for(int j = i+1; j < mCurrentFrame.layerCount; ++j) {
1260 hwc_layer_1_t* topLayer = &list->hwLayers[j];
1261 if(!mCurrentFrame.isFBComposed[j] &&
1262 isDownscaleRequired(topLayer)) {
1263 hwc_rect_t r = getIntersection(botLayer->displayFrame,
1264 topLayer->displayFrame);
1265 if(isValidRect(r))
1266 return false;
1267 }
1268 }
1269 }
1270 }
1271 }
1272 return true;
1273}
1274
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001275int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001276 int ret = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -07001277 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001278 MDPVersion& mdpVersion = qdutils::MDPVersion::getInstance();
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -07001279
Raj Kamal9ed3d6b2014-02-07 16:15:17 +05301280 //Do not cache the information for next draw cycle.
1281 if(numLayers > MAX_NUM_APP_LAYERS or (!numLayers)) {
1282 ALOGI("%s: Unsupported layer count for mdp composition",
1283 __FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001284 mCachedFrame.reset();
1285 return -1;
1286 }
1287
Saurabh Shahb39f8152013-08-22 10:21:44 -07001288 //reset old data
1289 mCurrentFrame.reset(numLayers);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001290 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1291 mCurrentFrame.dropCount = 0;
Prabhanjan Kandula088bd892013-07-02 23:47:13 +05301292
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -07001293 // Detect the start of animation and fall back to GPU only once to cache
1294 // all the layers in FB and display FB content untill animation completes.
1295 if(ctx->listStats[mDpy].isDisplayAnimating) {
1296 mCurrentFrame.needsRedraw = false;
1297 if(ctx->mAnimationState[mDpy] == ANIMATION_STOPPED) {
1298 mCurrentFrame.needsRedraw = true;
1299 ctx->mAnimationState[mDpy] = ANIMATION_STARTED;
1300 }
1301 setMDPCompLayerFlags(ctx, list);
1302 mCachedFrame.updateCounts(mCurrentFrame);
1303 ret = -1;
1304 return ret;
1305 } else {
1306 ctx->mAnimationState[mDpy] = ANIMATION_STOPPED;
1307 }
1308
Saurabh Shahb39f8152013-08-22 10:21:44 -07001309 //Hard conditions, if not met, cannot do MDP comp
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001310 if(isFrameDoable(ctx)) {
1311 generateROI(ctx, list);
Saurabh Shahb39f8152013-08-22 10:21:44 -07001312
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001313 if(tryFullFrame(ctx, list) || tryVideoOnly(ctx, list)) {
1314 setMDPCompLayerFlags(ctx, list);
1315 } else {
1316 reset(ctx);
1317 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1318 mCurrentFrame.dropCount = 0;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001319 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001320 }
1321 } else {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001322 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
1323 __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001324 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001325 }
Saurabh Shahb39f8152013-08-22 10:21:44 -07001326
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001327 if(isDebug()) {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001328 ALOGD("GEOMETRY change: %d",
1329 (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001330 android::String8 sDump("");
1331 dump(sDump);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001332 ALOGD("%s",sDump.string());
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001333 }
1334
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001335 mCachedFrame.cacheAll(list);
1336 mCachedFrame.updateCounts(mCurrentFrame);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001337 return ret;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001338}
1339
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001340bool MDPComp::allocSplitVGPipesfor4k2k(hwc_context_t *ctx, int index) {
radhakrishnac9a67412013-09-25 17:40:42 +05301341
1342 bool bRet = true;
radhakrishnac9a67412013-09-25 17:40:42 +05301343 int mdpIndex = mCurrentFrame.layerToMDP[index];
1344 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
1345 info.pipeInfo = new MdpYUVPipeInfo;
1346 info.rot = NULL;
1347 MdpYUVPipeInfo& pipe_info = *(MdpYUVPipeInfo*)info.pipeInfo;
1348 ePipeType type = MDPCOMP_OV_VG;
1349
1350 pipe_info.lIndex = ovutils::OV_INVALID;
1351 pipe_info.rIndex = ovutils::OV_INVALID;
1352
1353 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
1354 if(pipe_info.lIndex == ovutils::OV_INVALID){
1355 bRet = false;
1356 ALOGD_IF(isDebug(),"%s: allocating first VG pipe failed",
1357 __FUNCTION__);
1358 }
1359 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
1360 if(pipe_info.rIndex == ovutils::OV_INVALID){
1361 bRet = false;
1362 ALOGD_IF(isDebug(),"%s: allocating second VG pipe failed",
1363 __FUNCTION__);
1364 }
1365 return bRet;
1366}
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001367//=============MDPCompNonSplit==================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001368
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001369void MDPCompNonSplit::adjustForSourceSplit(hwc_context_t *ctx,
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001370 hwc_display_contents_1_t*) {
radhakrishnac9a67412013-09-25 17:40:42 +05301371 //As we split 4kx2k yuv layer and program to 2 VG pipes
1372 //(if available) increase mdpcount accordingly
1373 mCurrentFrame.mdpCount += ctx->listStats[mDpy].yuv4k2kCount;
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001374
1375 //If 4k2k Yuv layer split is possible, and if
1376 //fbz is above 4k2k layer, increment fb zorder by 1
1377 //as we split 4k2k layer and increment zorder for right half
1378 //of the layer
1379 if(mCurrentFrame.fbZ >= 0) {
1380 int n4k2kYuvCount = ctx->listStats[mDpy].yuv4k2kCount;
1381 for(int index = 0; index < n4k2kYuvCount; index++){
1382 int n4k2kYuvIndex =
1383 ctx->listStats[mDpy].yuv4k2kIndices[index];
1384 if(mCurrentFrame.fbZ > n4k2kYuvIndex){
1385 mCurrentFrame.fbZ += 1;
1386 }
1387 }
1388 }
radhakrishnac9a67412013-09-25 17:40:42 +05301389}
1390
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001391/*
1392 * Configures pipe(s) for MDP composition
1393 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001394int MDPCompNonSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001395 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001396 MdpPipeInfoNonSplit& mdp_info =
1397 *(static_cast<MdpPipeInfoNonSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001398 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
1399 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1400 eIsFg isFg = IS_FG_OFF;
1401 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001402
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001403 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
1404 __FUNCTION__, layer, zOrder, dest);
1405
Saurabh Shah88e4d272013-09-03 13:31:29 -07001406 return configureNonSplit(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001407 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001408}
1409
Saurabh Shah88e4d272013-09-03 13:31:29 -07001410bool MDPCompNonSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001411 hwc_display_contents_1_t* list) {
1412 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001413
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001414 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001415
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001416 hwc_layer_1_t* layer = &list->hwLayers[index];
1417 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301418 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001419 if(allocSplitVGPipesfor4k2k(ctx, index)){
radhakrishnac9a67412013-09-25 17:40:42 +05301420 continue;
1421 }
1422 }
1423
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001424 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001425 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001426 info.pipeInfo = new MdpPipeInfoNonSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08001427 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001428 MdpPipeInfoNonSplit& pipe_info = *(MdpPipeInfoNonSplit*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001429 ePipeType type = MDPCOMP_OV_ANY;
1430
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001431 if(isYuvBuffer(hnd)) {
1432 type = MDPCOMP_OV_VG;
Prabhanjan Kandula47191dc2014-01-22 23:01:45 +05301433 } else if(qdutils::MDPVersion::getInstance().is8x26() &&
1434 (ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres > 1024)) {
1435 if(qhwc::needsScaling(layer))
1436 type = MDPCOMP_OV_RGB;
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301437 } else if(!qhwc::needsScaling(layer)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001438 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
1439 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001440 type = MDPCOMP_OV_DMA;
1441 }
1442
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001443 pipe_info.index = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001444 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001445 ALOGD_IF(isDebug(), "%s: Unable to get pipe type = %d",
1446 __FUNCTION__, (int) type);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001447 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001448 }
1449 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001450 return true;
1451}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001452
radhakrishnac9a67412013-09-25 17:40:42 +05301453int MDPCompNonSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1454 PipeLayerPair& PipeLayerPair) {
1455 MdpYUVPipeInfo& mdp_info =
1456 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1457 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1458 eIsFg isFg = IS_FG_OFF;
1459 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1460 eDest lDest = mdp_info.lIndex;
1461 eDest rDest = mdp_info.rIndex;
1462
1463 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1464 lDest, rDest, &PipeLayerPair.rot);
1465}
1466
Saurabh Shah88e4d272013-09-03 13:31:29 -07001467bool MDPCompNonSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001468
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001469 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001470 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1471 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -08001472 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001473
1474 if(!ctx || !list) {
1475 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001476 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001477 }
1478
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301479 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1480 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1481 return true;
1482 }
1483
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -08001484 // Set the Handle timeout to true for MDP or MIXED composition.
1485 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount) {
1486 sHandleTimeout = true;
1487 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001488
1489 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001490 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001491
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001492 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1493 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001494 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001495 if(mCurrentFrame.isFBComposed[i]) continue;
1496
Naseer Ahmed5b6708a2012-08-02 13:46:08 -07001497 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001498 private_handle_t *hnd = (private_handle_t *)layer->handle;
1499 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001500 if (!(layer->flags & HWC_COLOR_FILL)) {
1501 ALOGE("%s handle null", __FUNCTION__);
1502 return false;
1503 }
1504 // No PLAY for Color layer
1505 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1506 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001507 }
1508
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001509 int mdpIndex = mCurrentFrame.layerToMDP[i];
1510
radhakrishnac9a67412013-09-25 17:40:42 +05301511 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1512 {
1513 MdpYUVPipeInfo& pipe_info =
1514 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1515 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1516 ovutils::eDest indexL = pipe_info.lIndex;
1517 ovutils::eDest indexR = pipe_info.rIndex;
1518 int fd = hnd->fd;
1519 uint32_t offset = hnd->offset;
1520 if(rot) {
1521 rot->queueBuffer(fd, offset);
1522 fd = rot->getDstMemId();
1523 offset = rot->getDstOffset();
1524 }
1525 if(indexL != ovutils::OV_INVALID) {
1526 ovutils::eDest destL = (ovutils::eDest)indexL;
1527 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1528 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1529 if (!ov.queueBuffer(fd, offset, destL)) {
1530 ALOGE("%s: queueBuffer failed for display:%d",
1531 __FUNCTION__, mDpy);
1532 return false;
1533 }
1534 }
1535
1536 if(indexR != ovutils::OV_INVALID) {
1537 ovutils::eDest destR = (ovutils::eDest)indexR;
1538 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1539 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1540 if (!ov.queueBuffer(fd, offset, destR)) {
1541 ALOGE("%s: queueBuffer failed for display:%d",
1542 __FUNCTION__, mDpy);
1543 return false;
1544 }
1545 }
1546 }
1547 else{
1548 MdpPipeInfoNonSplit& pipe_info =
Saurabh Shah88e4d272013-09-03 13:31:29 -07001549 *(MdpPipeInfoNonSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
radhakrishnac9a67412013-09-25 17:40:42 +05301550 ovutils::eDest dest = pipe_info.index;
1551 if(dest == ovutils::OV_INVALID) {
1552 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001553 return false;
radhakrishnac9a67412013-09-25 17:40:42 +05301554 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001555
radhakrishnac9a67412013-09-25 17:40:42 +05301556 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1557 continue;
1558 }
1559
1560 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1561 using pipe: %d", __FUNCTION__, layer,
1562 hnd, dest );
1563
1564 int fd = hnd->fd;
1565 uint32_t offset = hnd->offset;
1566
1567 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1568 if(rot) {
1569 if(!rot->queueBuffer(fd, offset))
1570 return false;
1571 fd = rot->getDstMemId();
1572 offset = rot->getDstOffset();
1573 }
1574
1575 if (!ov.queueBuffer(fd, offset, dest)) {
1576 ALOGE("%s: queueBuffer failed for display:%d ",
1577 __FUNCTION__, mDpy);
1578 return false;
1579 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001580 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001581
1582 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001583 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001584 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001585}
1586
Saurabh Shah88e4d272013-09-03 13:31:29 -07001587//=============MDPCompSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001588
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001589void MDPCompSplit::adjustForSourceSplit(hwc_context_t *ctx,
radhakrishnac9a67412013-09-25 17:40:42 +05301590 hwc_display_contents_1_t* list){
1591 //if 4kx2k yuv layer is totally present in either in left half
1592 //or right half then try splitting the yuv layer to avoid decimation
1593 int n4k2kYuvCount = ctx->listStats[mDpy].yuv4k2kCount;
1594 const int lSplit = getLeftSplit(ctx, mDpy);
1595 for(int index = 0; index < n4k2kYuvCount; index++){
1596 int n4k2kYuvIndex = ctx->listStats[mDpy].yuv4k2kIndices[index];
1597 hwc_layer_1_t* layer = &list->hwLayers[n4k2kYuvIndex];
1598 hwc_rect_t dst = layer->displayFrame;
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001599 if((dst.left > lSplit) || (dst.right < lSplit)) {
radhakrishnac9a67412013-09-25 17:40:42 +05301600 mCurrentFrame.mdpCount += 1;
1601 }
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001602 if(mCurrentFrame.fbZ > n4k2kYuvIndex){
1603 mCurrentFrame.fbZ += 1;
1604 }
radhakrishnac9a67412013-09-25 17:40:42 +05301605 }
1606}
1607
Saurabh Shah88e4d272013-09-03 13:31:29 -07001608bool MDPCompSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
1609 MdpPipeInfoSplit& pipe_info,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001610 ePipeType type) {
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001611 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001612
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001613 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001614 pipe_info.lIndex = ovutils::OV_INVALID;
1615 pipe_info.rIndex = ovutils::OV_INVALID;
1616
1617 if (dst.left < lSplit) {
1618 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_LEFT);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001619 if(pipe_info.lIndex == ovutils::OV_INVALID)
1620 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001621 }
1622
1623 if(dst.right > lSplit) {
1624 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_RIGHT);
1625 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001626 return false;
1627 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001628
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001629 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001630}
1631
Saurabh Shah88e4d272013-09-03 13:31:29 -07001632bool MDPCompSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001633 hwc_display_contents_1_t* list) {
1634 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001635
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001636 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001637
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001638 hwc_layer_1_t* layer = &list->hwLayers[index];
1639 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301640 hwc_rect_t dst = layer->displayFrame;
1641 const int lSplit = getLeftSplit(ctx, mDpy);
1642 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1643 if((dst.left > lSplit)||(dst.right < lSplit)){
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001644 if(allocSplitVGPipesfor4k2k(ctx, index)){
radhakrishnac9a67412013-09-25 17:40:42 +05301645 continue;
1646 }
1647 }
1648 }
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001649 int mdpIndex = mCurrentFrame.layerToMDP[index];
1650 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001651 info.pipeInfo = new MdpPipeInfoSplit;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001652 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001653 MdpPipeInfoSplit& pipe_info = *(MdpPipeInfoSplit*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001654 ePipeType type = MDPCOMP_OV_ANY;
1655
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001656 if(isYuvBuffer(hnd)) {
1657 type = MDPCOMP_OV_VG;
Sushil Chauhan15a2ea62013-09-04 18:28:36 -07001658 } else if(!qhwc::needsScalingWithSplit(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001659 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001660 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001661 type = MDPCOMP_OV_DMA;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001662 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001663
1664 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001665 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type = %d",
1666 __FUNCTION__, (int) type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001667 return false;
1668 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001669 }
1670 return true;
1671}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001672
radhakrishnac9a67412013-09-25 17:40:42 +05301673int MDPCompSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1674 PipeLayerPair& PipeLayerPair) {
1675 const int lSplit = getLeftSplit(ctx, mDpy);
1676 hwc_rect_t dst = layer->displayFrame;
1677 if((dst.left > lSplit)||(dst.right < lSplit)){
1678 MdpYUVPipeInfo& mdp_info =
1679 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1680 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1681 eIsFg isFg = IS_FG_OFF;
1682 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1683 eDest lDest = mdp_info.lIndex;
1684 eDest rDest = mdp_info.rIndex;
1685
1686 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1687 lDest, rDest, &PipeLayerPair.rot);
1688 }
1689 else{
1690 return configure(ctx, layer, PipeLayerPair);
1691 }
1692}
1693
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001694/*
1695 * Configures pipe(s) for MDP composition
1696 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001697int MDPCompSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001698 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001699 MdpPipeInfoSplit& mdp_info =
1700 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001701 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1702 eIsFg isFg = IS_FG_OFF;
1703 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1704 eDest lDest = mdp_info.lIndex;
1705 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001706
1707 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1708 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1709
Saurabh Shah88e4d272013-09-03 13:31:29 -07001710 return configureSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001711 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001712}
1713
Saurabh Shah88e4d272013-09-03 13:31:29 -07001714bool MDPCompSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001715
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001716 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001717 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1718 return true;
1719 }
1720
1721 if(!ctx || !list) {
1722 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001723 return false;
1724 }
1725
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301726 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1727 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1728 return true;
1729 }
1730
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -08001731 // Set the Handle timeout to true for MDP or MIXED composition.
1732 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount) {
1733 sHandleTimeout = true;
1734 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001735
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001736 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001737 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001738
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001739 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1740 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001741 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001742 if(mCurrentFrame.isFBComposed[i]) continue;
1743
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001744 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001745 private_handle_t *hnd = (private_handle_t *)layer->handle;
1746 if(!hnd) {
1747 ALOGE("%s handle null", __FUNCTION__);
1748 return false;
1749 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001750
1751 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1752 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001753 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001754
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001755 int mdpIndex = mCurrentFrame.layerToMDP[i];
1756
radhakrishnac9a67412013-09-25 17:40:42 +05301757 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1758 {
1759 MdpYUVPipeInfo& pipe_info =
1760 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1761 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1762 ovutils::eDest indexL = pipe_info.lIndex;
1763 ovutils::eDest indexR = pipe_info.rIndex;
1764 int fd = hnd->fd;
1765 uint32_t offset = hnd->offset;
1766 if(rot) {
1767 rot->queueBuffer(fd, offset);
1768 fd = rot->getDstMemId();
1769 offset = rot->getDstOffset();
1770 }
1771 if(indexL != ovutils::OV_INVALID) {
1772 ovutils::eDest destL = (ovutils::eDest)indexL;
1773 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1774 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1775 if (!ov.queueBuffer(fd, offset, destL)) {
1776 ALOGE("%s: queueBuffer failed for display:%d",
1777 __FUNCTION__, mDpy);
1778 return false;
1779 }
1780 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001781
radhakrishnac9a67412013-09-25 17:40:42 +05301782 if(indexR != ovutils::OV_INVALID) {
1783 ovutils::eDest destR = (ovutils::eDest)indexR;
1784 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1785 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1786 if (!ov.queueBuffer(fd, offset, destR)) {
1787 ALOGE("%s: queueBuffer failed for display:%d",
1788 __FUNCTION__, mDpy);
1789 return false;
1790 }
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001791 }
1792 }
radhakrishnac9a67412013-09-25 17:40:42 +05301793 else{
1794 MdpPipeInfoSplit& pipe_info =
1795 *(MdpPipeInfoSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1796 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001797
radhakrishnac9a67412013-09-25 17:40:42 +05301798 ovutils::eDest indexL = pipe_info.lIndex;
1799 ovutils::eDest indexR = pipe_info.rIndex;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001800
radhakrishnac9a67412013-09-25 17:40:42 +05301801 int fd = hnd->fd;
1802 int offset = hnd->offset;
1803
1804 if(ctx->mAD->isModeOn()) {
1805 if(ctx->mAD->draw(ctx, fd, offset)) {
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001806 fd = ctx->mAD->getDstFd();
1807 offset = ctx->mAD->getDstOffset();
radhakrishnac9a67412013-09-25 17:40:42 +05301808 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001809 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001810
radhakrishnac9a67412013-09-25 17:40:42 +05301811 if(rot) {
1812 rot->queueBuffer(fd, offset);
1813 fd = rot->getDstMemId();
1814 offset = rot->getDstOffset();
1815 }
1816
1817 //************* play left mixer **********
1818 if(indexL != ovutils::OV_INVALID) {
1819 ovutils::eDest destL = (ovutils::eDest)indexL;
1820 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1821 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1822 if (!ov.queueBuffer(fd, offset, destL)) {
1823 ALOGE("%s: queueBuffer failed for left mixer",
1824 __FUNCTION__);
1825 return false;
1826 }
1827 }
1828
1829 //************* play right mixer **********
1830 if(indexR != ovutils::OV_INVALID) {
1831 ovutils::eDest destR = (ovutils::eDest)indexR;
1832 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1833 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1834 if (!ov.queueBuffer(fd, offset, destR)) {
1835 ALOGE("%s: queueBuffer failed for right mixer",
1836 __FUNCTION__);
1837 return false;
1838 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001839 }
1840 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001841
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001842 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1843 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001844
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001845 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001846}
Saurabh Shahab47c692014-02-12 18:45:57 -08001847
1848//================MDPCompSrcSplit==============================================
1849bool MDPCompSrcSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
1850 MdpPipeInfoSplit& pipe_info, ePipeType /*type*/) {
1851 private_handle_t *hnd = (private_handle_t *)layer->handle;
1852 hwc_rect_t dst = layer->displayFrame;
1853 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
1854 pipe_info.lIndex = ovutils::OV_INVALID;
1855 pipe_info.rIndex = ovutils::OV_INVALID;
1856
1857 //If 2 pipes are staged on a single stage of a mixer, then the left pipe
1858 //should have a higher priority than the right one. Pipe priorities are
1859 //starting with VG0, VG1 ... , RGB0 ..., DMA1
1860 //TODO Currently we acquire VG pipes for left side and RGB/DMA for right to
1861 //make sure pipe priorities are satisfied. A better way is to have priority
1862 //as part of overlay object and acquire any 2 pipes. Assign the higher
1863 //priority one to left side and lower to right side.
1864
1865 //1 pipe by default for a layer
1866 pipe_info.lIndex = getMdpPipe(ctx, MDPCOMP_OV_VG, Overlay::MIXER_DEFAULT);
1867 if(pipe_info.lIndex == ovutils::OV_INVALID) {
1868 if(isYuvBuffer(hnd)) {
1869 return false;
1870 }
1871 pipe_info.lIndex = getMdpPipe(ctx, MDPCOMP_OV_ANY,
1872 Overlay::MIXER_DEFAULT);
1873 if(pipe_info.lIndex == ovutils::OV_INVALID) {
1874 return false;
1875 }
1876 }
1877
1878 //If layer's crop width or dest width > 2048, use 2 pipes
1879 if((dst.right - dst.left) > qdutils::MAX_DISPLAY_DIM or
1880 (crop.right - crop.left) > qdutils::MAX_DISPLAY_DIM) {
1881 ePipeType rightType = isYuvBuffer(hnd) ?
1882 MDPCOMP_OV_VG : MDPCOMP_OV_ANY;
1883 pipe_info.rIndex = getMdpPipe(ctx, rightType, Overlay::MIXER_DEFAULT);
1884 if(pipe_info.rIndex == ovutils::OV_INVALID) {
1885 return false;
1886 }
1887 }
1888
1889 return true;
1890}
1891
1892bool MDPCompSrcSplit::allocLayerPipes(hwc_context_t *ctx,
1893 hwc_display_contents_1_t* list) {
1894 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
1895 if(mCurrentFrame.isFBComposed[index]) continue;
1896 hwc_layer_1_t* layer = &list->hwLayers[index];
1897 int mdpIndex = mCurrentFrame.layerToMDP[index];
1898 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
1899 info.pipeInfo = new MdpPipeInfoSplit;
1900 info.rot = NULL;
1901 MdpPipeInfoSplit& pipe_info = *(MdpPipeInfoSplit*)info.pipeInfo;
1902
1903 ePipeType type = MDPCOMP_OV_ANY;
1904 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
1905 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type = %d",
1906 __FUNCTION__, (int) type);
1907 return false;
1908 }
1909 }
1910 return true;
1911}
1912
1913int MDPCompSrcSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
1914 PipeLayerPair& PipeLayerPair) {
1915 private_handle_t *hnd = (private_handle_t *)layer->handle;
1916 if(!hnd) {
1917 ALOGE("%s: layer handle is NULL", __FUNCTION__);
1918 return -1;
1919 }
1920 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
1921 MdpPipeInfoSplit& mdp_info =
1922 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
1923 Rotator **rot = &PipeLayerPair.rot;
1924 eZorder z = static_cast<eZorder>(mdp_info.zOrder);
1925 eIsFg isFg = IS_FG_OFF;
1926 eDest lDest = mdp_info.lIndex;
1927 eDest rDest = mdp_info.rIndex;
1928 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
1929 hwc_rect_t dst = layer->displayFrame;
1930 int transform = layer->transform;
1931 eTransform orient = static_cast<eTransform>(transform);
1932 const int downscale = 0;
1933 int rotFlags = ROT_FLAGS_NONE;
1934 uint32_t format = ovutils::getMdpFormat(hnd->format, isTileRendered(hnd));
1935 Whf whf(getWidth(hnd), getHeight(hnd), format, hnd->size);
1936
1937 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1938 "dest_pipeR: %d",__FUNCTION__, layer, z, lDest, rDest);
1939
1940 // Handle R/B swap
1941 if (layer->flags & HWC_FORMAT_RB_SWAP) {
1942 if (hnd->format == HAL_PIXEL_FORMAT_RGBA_8888)
1943 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRA_8888);
1944 else if (hnd->format == HAL_PIXEL_FORMAT_RGBX_8888)
1945 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRX_8888);
1946 }
1947
1948 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1949 setMdpFlags(layer, mdpFlagsL, 0, transform);
1950 eMdpFlags mdpFlagsR = mdpFlagsL;
1951
1952 if(lDest != OV_INVALID && rDest != OV_INVALID) {
1953 //Enable overfetch
1954 setMdpFlags(mdpFlagsL, OV_MDSS_MDP_DUAL_PIPE);
1955 }
1956
1957 if(isYuvBuffer(hnd) && (transform & HWC_TRANSFORM_ROT_90)) {
1958 (*rot) = ctx->mRotMgr->getNext();
1959 if((*rot) == NULL) return -1;
1960 //Configure rotator for pre-rotation
1961 if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale) < 0) {
1962 ALOGE("%s: configRotator failed!", __FUNCTION__);
1963 return -1;
1964 }
1965 ctx->mLayerRotMap[mDpy]->add(layer, *rot);
1966 whf.format = (*rot)->getDstFormat();
1967 updateSource(orient, whf, crop);
1968 rotFlags |= ROT_PREROTATED;
1969 }
1970
1971 //If 2 pipes being used, divide layer into half, crop and dst
1972 hwc_rect_t cropL = crop;
1973 hwc_rect_t cropR = crop;
1974 hwc_rect_t dstL = dst;
1975 hwc_rect_t dstR = dst;
1976 if(lDest != OV_INVALID && rDest != OV_INVALID) {
1977 cropL.right = (crop.right + crop.left) / 2;
1978 cropR.left = cropL.right;
1979 sanitizeSourceCrop(cropL, cropR, hnd);
1980
1981 //Swap crops on H flip since 2 pipes are being used
1982 if((orient & OVERLAY_TRANSFORM_FLIP_H) && (*rot) == NULL) {
1983 hwc_rect_t tmp = cropL;
1984 cropL = cropR;
1985 cropR = tmp;
1986 }
1987
1988 dstL.right = (dst.right + dst.left) / 2;
1989 dstR.left = dstL.right;
1990 }
1991
1992 //For the mdp, since either we are pre-rotating or MDP does flips
1993 orient = OVERLAY_TRANSFORM_0;
1994 transform = 0;
1995
1996 //configure left pipe
1997 if(lDest != OV_INVALID) {
1998 PipeArgs pargL(mdpFlagsL, whf, z, isFg,
1999 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2000 (ovutils::eBlending) getBlending(layer->blending));
2001
2002 if(configMdp(ctx->mOverlay, pargL, orient,
2003 cropL, dstL, metadata, lDest) < 0) {
2004 ALOGE("%s: commit failed for left mixer config", __FUNCTION__);
2005 return -1;
2006 }
2007 }
2008
2009 //configure right pipe
2010 if(rDest != OV_INVALID) {
2011 PipeArgs pargR(mdpFlagsR, whf, z, isFg,
2012 static_cast<eRotFlags>(rotFlags),
2013 layer->planeAlpha,
2014 (ovutils::eBlending) getBlending(layer->blending));
2015 if(configMdp(ctx->mOverlay, pargR, orient,
2016 cropR, dstR, metadata, rDest) < 0) {
2017 ALOGE("%s: commit failed for right mixer config", __FUNCTION__);
2018 return -1;
2019 }
2020 }
2021
2022 return 0;
2023}
2024
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002025}; //namespace
2026