blob: d0081479a8f2b57367d03a81cdad4d60d5752511 [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
Prabhanjan Kandula8e6f9142014-04-21 12:12:38 +0530121 // We read from drivers if panel supports partial updating
122 // and we enable partial update computations if supported.
123 // Keeping this property to disable partial update for
124 // debugging by setting below property to 0 & only 0.
125 property_get("persist.hwc.partialupdate", property, "-1");
126 if((atoi(property) != 0) &&
127 qdutils::MDPVersion::getInstance().isPartialUpdateEnabled()) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700128 sEnablePartialFrameUpdate = true;
129 }
130 ALOGE_IF(isDebug(), "%s: Partial Update applicable?: %d",__FUNCTION__,
131 sEnablePartialFrameUpdate);
132
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800133 sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
Saurabh Shah85234ec2013-04-12 17:09:00 -0700134 if(property_get("debug.mdpcomp.maxpermixer", property, "-1") > 0) {
135 int val = atoi(property);
136 if(val >= 0)
137 sMaxPipesPerMixer = min(val, MAX_PIPES_PER_MIXER);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800138 }
139
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400140 if(ctx->mMDP.panel != MIPI_CMD_PANEL) {
141 // Idle invalidation is not necessary on command mode panels
142 long idle_timeout = DEFAULT_IDLE_TIME;
143 if(property_get("debug.mdpcomp.idletime", property, NULL) > 0) {
144 if(atoi(property) != 0)
145 idle_timeout = atoi(property);
146 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800147
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400148 //create Idle Invalidator only when not disabled through property
149 if(idle_timeout != -1)
150 idleInvalidator = IdleInvalidator::getInstance();
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800151
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400152 if(idleInvalidator == NULL) {
153 ALOGE("%s: failed to instantiate idleInvalidator object",
154 __FUNCTION__);
155 } else {
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530156 idleInvalidator->init(timeout_handler, ctx,
157 (unsigned int)idle_timeout);
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400158 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800159 }
radhakrishnac9a67412013-09-25 17:40:42 +0530160
161 if((property_get("debug.mdpcomp.4k2kSplit", property, "0") > 0) &&
162 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
163 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
164 sEnable4k2kYUVSplit = true;
165 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700166 return true;
167}
168
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800169void MDPComp::reset(hwc_context_t *ctx) {
170 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700171 mCurrentFrame.reset(numLayers);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800172 ctx->mOverlay->clear(mDpy);
173 ctx->mLayerRotMap[mDpy]->clear();
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700174}
175
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700176void MDPComp::timeout_handler(void *udata) {
177 struct hwc_context_t* ctx = (struct hwc_context_t*)(udata);
178
179 if(!ctx) {
180 ALOGE("%s: received empty data in timer callback", __FUNCTION__);
181 return;
182 }
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -0800183 Locker::Autolock _l(ctx->mDrawLock);
184 // Handle timeout event only if the previous composition is MDP or MIXED.
185 if(!sHandleTimeout) {
186 ALOGD_IF(isDebug(), "%s:Do not handle this timeout", __FUNCTION__);
187 return;
188 }
Jesse Hall3be78d92012-08-21 15:12:23 -0700189 if(!ctx->proc) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700190 ALOGE("%s: HWC proc not registered", __FUNCTION__);
191 return;
192 }
193 sIdleFallBack = true;
194 /* Trigger SF to redraw the current frame */
Jesse Hall3be78d92012-08-21 15:12:23 -0700195 ctx->proc->invalidate(ctx->proc);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700196}
197
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800198void MDPComp::setMDPCompLayerFlags(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800199 hwc_display_contents_1_t* list) {
200 LayerProp *layerProp = ctx->layerProp[mDpy];
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800201
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800202 for(int index = 0; index < ctx->listStats[mDpy].numAppLayers; index++) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800203 hwc_layer_1_t* layer = &(list->hwLayers[index]);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800204 if(!mCurrentFrame.isFBComposed[index]) {
205 layerProp[index].mFlags |= HWC_MDPCOMP;
206 layer->compositionType = HWC_OVERLAY;
207 layer->hints |= HWC_HINT_CLEAR_FB;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800208 } else {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700209 /* Drop the layer when its already present in FB OR when it lies
210 * outside frame's ROI */
211 if(!mCurrentFrame.needsRedraw || mCurrentFrame.drop[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800212 layer->compositionType = HWC_OVERLAY;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700213 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800214 }
215 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700216}
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500217
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800218void MDPComp::setRedraw(hwc_context_t *ctx,
219 hwc_display_contents_1_t* list) {
220 mCurrentFrame.needsRedraw = false;
221 if(!mCachedFrame.isSameFrame(mCurrentFrame, list) ||
222 (list->flags & HWC_GEOMETRY_CHANGED) ||
223 isSkipPresent(ctx, mDpy)) {
224 mCurrentFrame.needsRedraw = true;
225 }
226}
227
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800228MDPComp::FrameInfo::FrameInfo() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700229 reset(0);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800230}
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800231
Saurabh Shahaa236822013-04-24 18:07:26 -0700232void MDPComp::FrameInfo::reset(const int& numLayers) {
233 for(int i = 0 ; i < MAX_PIPES_PER_MIXER && numLayers; i++ ) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800234 if(mdpToLayer[i].pipeInfo) {
235 delete mdpToLayer[i].pipeInfo;
236 mdpToLayer[i].pipeInfo = NULL;
237 //We dont own the rotator
238 mdpToLayer[i].rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800239 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800240 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800241
242 memset(&mdpToLayer, 0, sizeof(mdpToLayer));
243 memset(&layerToMDP, -1, sizeof(layerToMDP));
Saurabh Shahaa236822013-04-24 18:07:26 -0700244 memset(&isFBComposed, 1, sizeof(isFBComposed));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800245
Saurabh Shahaa236822013-04-24 18:07:26 -0700246 layerCount = numLayers;
247 fbCount = numLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800248 mdpCount = 0;
Saurabh Shah2f3895f2013-05-02 10:13:31 -0700249 needsRedraw = true;
Saurabh Shahd53bc5f2014-02-05 10:17:43 -0800250 fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800251}
252
Saurabh Shahaa236822013-04-24 18:07:26 -0700253void MDPComp::FrameInfo::map() {
254 // populate layer and MDP maps
255 int mdpIdx = 0;
256 for(int idx = 0; idx < layerCount; idx++) {
257 if(!isFBComposed[idx]) {
258 mdpToLayer[mdpIdx].listIndex = idx;
259 layerToMDP[idx] = mdpIdx++;
260 }
261 }
262}
263
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800264MDPComp::LayerCache::LayerCache() {
265 reset();
266}
267
268void MDPComp::LayerCache::reset() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700269 memset(&hnd, 0, sizeof(hnd));
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530270 memset(&isFBComposed, true, sizeof(isFBComposed));
271 memset(&drop, false, sizeof(drop));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800272 layerCount = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -0700273}
274
275void MDPComp::LayerCache::cacheAll(hwc_display_contents_1_t* list) {
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530276 const int numAppLayers = (int)list->numHwLayers - 1;
Saurabh Shahaa236822013-04-24 18:07:26 -0700277 for(int i = 0; i < numAppLayers; i++) {
278 hnd[i] = list->hwLayers[i].handle;
279 }
280}
281
282void MDPComp::LayerCache::updateCounts(const FrameInfo& curFrame) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700283 layerCount = curFrame.layerCount;
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530284 memcpy(&isFBComposed, &curFrame.isFBComposed, sizeof(isFBComposed));
285 memcpy(&drop, &curFrame.drop, sizeof(drop));
286}
287
Jeykumar Sankaran988d3682013-11-15 11:57:16 -0800288bool MDPComp::LayerCache::isSameFrame(const FrameInfo& curFrame,
289 hwc_display_contents_1_t* list) {
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530290 if(layerCount != curFrame.layerCount)
291 return false;
292 for(int i = 0; i < curFrame.layerCount; i++) {
293 if((curFrame.isFBComposed[i] != isFBComposed[i]) ||
294 (curFrame.drop[i] != drop[i])) {
295 return false;
296 }
Jeykumar Sankaran988d3682013-11-15 11:57:16 -0800297 if(curFrame.isFBComposed[i] &&
298 (hnd[i] != list->hwLayers[i].handle)){
299 return false;
300 }
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530301 }
302 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800303}
304
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700305bool MDPComp::isSupportedForMDPComp(hwc_context_t *ctx, hwc_layer_1_t* layer) {
306 private_handle_t *hnd = (private_handle_t *)layer->handle;
307 if((not isYuvBuffer(hnd) and has90Transform(layer)) or
308 (not isValidDimension(ctx,layer))
309 //More conditions here, SKIP, sRGB+Blend etc
310 ) {
311 return false;
312 }
313 return true;
314}
315
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530316bool MDPComp::isValidDimension(hwc_context_t *ctx, hwc_layer_1_t *layer) {
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800317 private_handle_t *hnd = (private_handle_t *)layer->handle;
318
319 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -0700320 if (layer->flags & HWC_COLOR_FILL) {
321 // Color layer
322 return true;
323 }
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800324 ALOGE("%s: layer handle is NULL", __FUNCTION__);
325 return false;
326 }
327
Naseer Ahmede850a802013-09-06 13:12:52 -0400328 //XXX: Investigate doing this with pixel phase on MDSS
Naseer Ahmede77f8082013-10-10 13:42:48 -0400329 if(!isSecureBuffer(hnd) && isNonIntegralSourceCrop(layer->sourceCropf))
Naseer Ahmede850a802013-09-06 13:12:52 -0400330 return false;
331
Saurabh Shah62e1d732013-09-17 10:44:05 -0700332 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700333 hwc_rect_t dst = layer->displayFrame;
Saurabh Shah4fdde762013-04-30 18:47:33 -0700334 int crop_w = crop.right - crop.left;
335 int crop_h = crop.bottom - crop.top;
336 int dst_w = dst.right - dst.left;
337 int dst_h = dst.bottom - dst.top;
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800338 float w_scale = ((float)crop_w / (float)dst_w);
339 float h_scale = ((float)crop_h / (float)dst_h);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700340
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800341 /* Workaround for MDP HW limitation in DSI command mode panels where
342 * FPS will not go beyond 30 if buffers on RGB pipes are of width or height
343 * less than 5 pixels
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530344 * There also is a HW limilation in MDP, minimum block size is 2x2
345 * Fallback to GPU if height is less than 2.
346 */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800347 if((crop_w < 5)||(crop_h < 5))
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800348 return false;
349
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800350 if((w_scale > 1.0f) || (h_scale > 1.0f)) {
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700351 const uint32_t maxMDPDownscale =
Saurabh Shah4fdde762013-04-30 18:47:33 -0700352 qdutils::MDPVersion::getInstance().getMaxMDPDownscale();
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800353 const float w_dscale = w_scale;
354 const float h_dscale = h_scale;
355
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800356 if(ctx->mMDP.version >= qdutils::MDSS_V5) {
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700357
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800358 if(!qdutils::MDPVersion::getInstance().supportsDecimation()) {
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700359 /* On targets that doesnt support Decimation (eg.,8x26)
360 * maximum downscale support is overlay pipe downscale.
361 */
362 if(crop_w > MAX_DISPLAY_DIM || w_dscale > maxMDPDownscale ||
363 h_dscale > maxMDPDownscale)
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800364 return false;
365 } else {
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700366 // Decimation on macrotile format layers is not supported.
367 if(isTileRendered(hnd)) {
368 /* MDP can read maximum MAX_DISPLAY_DIM width.
369 * Bail out if
370 * 1. Src crop > MAX_DISPLAY_DIM on nonsplit MDPComp
371 * 2. exceeds maximum downscale limit
372 */
373 if(((crop_w > MAX_DISPLAY_DIM) && !sSrcSplitEnabled) ||
374 w_dscale > maxMDPDownscale ||
375 h_dscale > maxMDPDownscale) {
376 return false;
377 }
378 } else if(w_dscale > 64 || h_dscale > 64)
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800379 return false;
380 }
381 } else { //A-family
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700382 if(w_dscale > maxMDPDownscale || h_dscale > maxMDPDownscale)
Saurabh Shah4fdde762013-04-30 18:47:33 -0700383 return false;
384 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700385 }
386
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800387 if((w_scale < 1.0f) || (h_scale < 1.0f)) {
388 const uint32_t upscale =
389 qdutils::MDPVersion::getInstance().getMaxMDPUpscale();
390 const float w_uscale = 1.0f / w_scale;
391 const float h_uscale = 1.0f / h_scale;
392
393 if(w_uscale > upscale || h_uscale > upscale)
394 return false;
395 }
396
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800397 return true;
398}
399
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800400bool MDPComp::isFrameDoable(hwc_context_t *ctx) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700401 bool ret = true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800402
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800403 if(!isEnabled()) {
404 ALOGD_IF(isDebug(),"%s: MDP Comp. not enabled.", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700405 ret = false;
Raj Kamal068f4572014-04-14 16:14:06 +0530406 } else if((qdutils::MDPVersion::getInstance().is8x26() ||
407 qdutils::MDPVersion::getInstance().is8x16()) &&
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -0800408 ctx->mVideoTransFlag &&
409 isSecondaryConnected(ctx)) {
Saurabh Shahd4e65852013-06-17 11:33:53 -0700410 //1 Padding round to shift pipes across mixers
411 ALOGD_IF(isDebug(),"%s: MDP Comp. video transition padding round",
412 __FUNCTION__);
413 ret = false;
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -0800414 } else if(isSecondaryConfiguring(ctx)) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800415 ALOGD_IF( isDebug(),"%s: External Display connection is pending",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800416 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700417 ret = false;
Saurabh Shahaa236822013-04-24 18:07:26 -0700418 } else if(ctx->isPaddingRound) {
Raj Kamal9ed3d6b2014-02-07 16:15:17 +0530419 ALOGD_IF(isDebug(), "%s: padding round invoked for dpy %d",
420 __FUNCTION__,mDpy);
Saurabh Shahaa236822013-04-24 18:07:26 -0700421 ret = false;
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700422 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700423 return ret;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800424}
425
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800426/*
427 * 1) Identify layers that are not visible in the updating ROI and drop them
428 * from composition.
429 * 2) If we have a scaling layers which needs cropping against generated ROI.
430 * Reset ROI to full resolution.
431 */
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700432bool MDPComp::validateAndApplyROI(hwc_context_t *ctx,
433 hwc_display_contents_1_t* list, hwc_rect_t roi) {
434 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
435
436 if(!isValidRect(roi))
437 return false;
438
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800439 hwc_rect_t visibleRect = roi;
440
441 for(int i = numAppLayers - 1; i >= 0; i--){
442
443 if(!isValidRect(visibleRect)) {
444 mCurrentFrame.drop[i] = true;
445 mCurrentFrame.dropCount++;
Jeykumar Sankaran0b961452014-01-21 17:26:12 -0800446 continue;
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800447 }
448
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700449 const hwc_layer_1_t* layer = &list->hwLayers[i];
450
451 hwc_rect_t dstRect = layer->displayFrame;
Arun Kumar K.R91090c72013-10-28 19:40:18 -0700452 hwc_rect_t srcRect = integerizeSourceCrop(layer->sourceCropf);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700453
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800454 hwc_rect_t res = getIntersection(visibleRect, dstRect);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700455
456 int res_w = res.right - res.left;
457 int res_h = res.bottom - res.top;
458 int dst_w = dstRect.right - dstRect.left;
459 int dst_h = dstRect.bottom - dstRect.top;
460
461 if(!isValidRect(res)) {
462 mCurrentFrame.drop[i] = true;
463 mCurrentFrame.dropCount++;
464 }else {
465 /* Reset frame ROI when any layer which needs scaling also needs ROI
466 * cropping */
Jeykumar Sankaran0b961452014-01-21 17:26:12 -0800467 if((res_w != dst_w || res_h != dst_h) && needsScaling (layer)) {
Arpita Banerjeed8965982013-11-08 17:27:33 -0800468 ALOGI("%s: Resetting ROI due to scaling", __FUNCTION__);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700469 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
470 mCurrentFrame.dropCount = 0;
471 return false;
472 }
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800473
Jeykumar Sankaran0b961452014-01-21 17:26:12 -0800474 /* deduct any opaque region from visibleRect */
475 if (layer->blending == HWC_BLENDING_NONE)
476 visibleRect = deductRect(visibleRect, res);
477 }
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700478 }
479 return true;
480}
481
482void MDPComp::generateROI(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
483 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
484
485 if(!sEnablePartialFrameUpdate) {
486 return;
487 }
488
489 if(mDpy || isDisplaySplit(ctx, mDpy)){
490 ALOGE_IF(isDebug(), "%s: ROI not supported for"
491 "the (1) external / virtual display's (2) dual DSI displays",
492 __FUNCTION__);
493 return;
494 }
495
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800496 if(isSkipPresent(ctx, mDpy))
497 return;
498
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700499 if(list->flags & HWC_GEOMETRY_CHANGED)
500 return;
501
502 struct hwc_rect roi = (struct hwc_rect){0, 0, 0, 0};
503 for(int index = 0; index < numAppLayers; index++ ) {
504 if ((mCachedFrame.hnd[index] != list->hwLayers[index].handle) ||
505 isYuvBuffer((private_handle_t *)list->hwLayers[index].handle)) {
506 hwc_rect_t dstRect = list->hwLayers[index].displayFrame;
Arun Kumar K.R91090c72013-10-28 19:40:18 -0700507 hwc_rect_t srcRect = integerizeSourceCrop(
508 list->hwLayers[index].sourceCropf);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700509
510 /* Intersect against display boundaries */
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700511 roi = getUnion(roi, dstRect);
512 }
513 }
514
515 if(!validateAndApplyROI(ctx, list, roi)){
516 roi = (struct hwc_rect) {0, 0,
517 (int)ctx->dpyAttr[mDpy].xres, (int)ctx->dpyAttr[mDpy].yres};
518 }
519
520 ctx->listStats[mDpy].roi.x = roi.left;
521 ctx->listStats[mDpy].roi.y = roi.top;
522 ctx->listStats[mDpy].roi.w = roi.right - roi.left;
523 ctx->listStats[mDpy].roi.h = roi.bottom - roi.top;
524
525 ALOGD_IF(isDebug(),"%s: generated ROI: [%d, %d, %d, %d]", __FUNCTION__,
526 roi.left, roi.top, roi.right, roi.bottom);
527}
528
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800529/* Checks for conditions where all the layers marked for MDP comp cannot be
530 * bypassed. On such conditions we try to bypass atleast YUV layers */
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800531bool MDPComp::tryFullFrame(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800532 hwc_display_contents_1_t* list){
533
Saurabh Shahaa236822013-04-24 18:07:26 -0700534 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Arun Kumar K.R2e2871c2014-01-10 12:47:06 -0800535 int priDispW = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800536
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -0700537 if(sIdleFallBack && !ctx->listStats[mDpy].secureUI) {
Saurabh Shah2d998a92013-05-14 17:55:58 -0700538 ALOGD_IF(isDebug(), "%s: Idle fallback dpy %d",__FUNCTION__, mDpy);
539 return false;
540 }
541
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800542 if(isSkipPresent(ctx, mDpy)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700543 ALOGD_IF(isDebug(),"%s: SKIP present: %d",
544 __FUNCTION__,
545 isSkipPresent(ctx, mDpy));
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800546 return false;
547 }
548
Arun Kumar K.R2e2871c2014-01-10 12:47:06 -0800549 if(mDpy > HWC_DISPLAY_PRIMARY && (priDispW > MAX_DISPLAY_DIM) &&
550 (ctx->dpyAttr[mDpy].xres < MAX_DISPLAY_DIM)) {
551 // Disable MDP comp on Secondary when the primary is highres panel and
552 // the secondary is a normal 1080p, because, MDP comp on secondary under
553 // in such usecase, decimation gets used for downscale and there will be
554 // a quality mismatch when there will be a fallback to GPU comp
555 ALOGD_IF(isDebug(), "%s: Disable MDP Compositon for Secondary Disp",
556 __FUNCTION__);
557 return false;
558 }
559
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800560 // check for action safe flag and downscale mode which requires scaling.
561 if(ctx->dpyAttr[mDpy].mActionSafePresent
562 || ctx->dpyAttr[mDpy].mDownScaleMode) {
563 ALOGD_IF(isDebug(), "%s: Scaling needed for this frame",__FUNCTION__);
564 return false;
565 }
566
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800567 for(int i = 0; i < numAppLayers; ++i) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800568 hwc_layer_1_t* layer = &list->hwLayers[i];
569 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800570
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700571 if(isYuvBuffer(hnd) && has90Transform(layer)) {
572 if(!canUseRotator(ctx, mDpy)) {
573 ALOGD_IF(isDebug(), "%s: Can't use rotator for dpy %d",
574 __FUNCTION__, mDpy);
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700575 return false;
576 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800577 }
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530578
579 //For 8x26 with panel width>1k, if RGB layer needs HFLIP fail mdp comp
580 // may not need it if Gfx pre-rotation can handle all flips & rotations
Sushil Chauhanfda00fc2014-03-20 11:08:41 -0700581 int transform = (layer->flags & HWC_COLOR_FILL) ? 0 : layer->transform;
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530582 if(qdutils::MDPVersion::getInstance().is8x26() &&
583 (ctx->dpyAttr[mDpy].xres > 1024) &&
Sushil Chauhanfda00fc2014-03-20 11:08:41 -0700584 (transform & HWC_TRANSFORM_FLIP_H) &&
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530585 (!isYuvBuffer(hnd)))
586 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800587 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700588
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700589 if(ctx->mAD->isDoable()) {
590 return false;
591 }
592
Saurabh Shahaa236822013-04-24 18:07:26 -0700593 //If all above hard conditions are met we can do full or partial MDP comp.
594 bool ret = false;
595 if(fullMDPComp(ctx, list)) {
596 ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700597 } else if(partialMDPComp(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700598 ret = true;
599 }
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530600
Saurabh Shahaa236822013-04-24 18:07:26 -0700601 return ret;
602}
603
604bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700605 //Will benefit presentation / secondary-only layer.
606 if((mDpy > HWC_DISPLAY_PRIMARY) &&
607 (list->numHwLayers - 1) > MAX_SEC_LAYERS) {
608 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
609 return false;
610 }
611
612 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
613 for(int i = 0; i < numAppLayers; i++) {
614 hwc_layer_1_t* layer = &list->hwLayers[i];
615 if(not isSupportedForMDPComp(ctx, layer)) {
616 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",__FUNCTION__);
617 return false;
618 }
Yang Xu9c1eb2b2013-11-26 01:28:13 +0800619
620 //For 8x26, if there is only one layer which needs scale for secondary
621 //while no scale for primary display, DMA pipe is occupied by primary.
622 //If need to fall back to GLES composition, virtual display lacks DMA
623 //pipe and error is reported.
624 if(qdutils::MDPVersion::getInstance().is8x26() &&
625 mDpy >= HWC_DISPLAY_EXTERNAL &&
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530626 qhwc::needsScaling(layer))
Yang Xu9c1eb2b2013-11-26 01:28:13 +0800627 return false;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700628 }
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800629
Saurabh Shahaa236822013-04-24 18:07:26 -0700630 mCurrentFrame.fbCount = 0;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700631 memcpy(&mCurrentFrame.isFBComposed, &mCurrentFrame.drop,
632 sizeof(mCurrentFrame.isFBComposed));
633 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount -
634 mCurrentFrame.dropCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700635
radhakrishnac9a67412013-09-25 17:40:42 +0530636 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800637 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530638 }
639
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800640 if(!postHeuristicsHandling(ctx, list)) {
641 ALOGD_IF(isDebug(), "post heuristic handling failed");
642 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700643 return false;
644 }
645
Saurabh Shahaa236822013-04-24 18:07:26 -0700646 return true;
647}
648
649bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
650{
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700651 if(!sEnableMixedMode) {
652 //Mixed mode is disabled. No need to even try caching.
653 return false;
654 }
655
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700656 bool ret = false;
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800657 if(list->flags & HWC_GEOMETRY_CHANGED) { //Try load based first
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800658 ret = loadBasedComp(ctx, list) or
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800659 cacheBasedComp(ctx, list);
660 } else {
661 ret = cacheBasedComp(ctx, list) or
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800662 loadBasedComp(ctx, list);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700663 }
664
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700665 return ret;
666}
667
668bool MDPComp::cacheBasedComp(hwc_context_t *ctx,
669 hwc_display_contents_1_t* list) {
670 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700671 mCurrentFrame.reset(numAppLayers);
672 updateLayerCache(ctx, list);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700673
674 //If an MDP marked layer is unsupported cannot do partial MDP Comp
675 for(int i = 0; i < numAppLayers; i++) {
676 if(!mCurrentFrame.isFBComposed[i]) {
677 hwc_layer_1_t* layer = &list->hwLayers[i];
678 if(not isSupportedForMDPComp(ctx, layer)) {
679 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",
680 __FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800681 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700682 return false;
683 }
684 }
685 }
686
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700687 updateYUV(ctx, list, false /*secure only*/);
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530688 bool ret = markLayersForCaching(ctx, list); //sets up fbZ also
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700689 if(!ret) {
690 ALOGD_IF(isDebug(),"%s: batching failed, dpy %d",__FUNCTION__, mDpy);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800691 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700692 return false;
693 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700694
695 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700696
radhakrishnac9a67412013-09-25 17:40:42 +0530697 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800698 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530699 }
700
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700701 //Will benefit cases where a video has non-updating background.
702 if((mDpy > HWC_DISPLAY_PRIMARY) and
703 (mdpCount > MAX_SEC_LAYERS)) {
704 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800705 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700706 return false;
707 }
708
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800709 if(!postHeuristicsHandling(ctx, list)) {
710 ALOGD_IF(isDebug(), "post heuristic handling failed");
711 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700712 return false;
713 }
714
Saurabh Shahaa236822013-04-24 18:07:26 -0700715 return true;
716}
717
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800718bool MDPComp::loadBasedComp(hwc_context_t *ctx,
Saurabh Shahb772ae32013-11-18 15:40:02 -0800719 hwc_display_contents_1_t* list) {
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -0800720 if(not isLoadBasedCompDoable(ctx)) {
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800721 return false;
722 }
723
Saurabh Shahb772ae32013-11-18 15:40:02 -0800724 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800725 const int numNonDroppedLayers = numAppLayers - mCurrentFrame.dropCount;
726 const int stagesForMDP = min(sMaxPipesPerMixer,
727 ctx->mOverlay->availablePipes(mDpy, Overlay::MIXER_DEFAULT));
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800728
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800729 int mdpBatchSize = stagesForMDP - 1; //1 stage for FB
730 int fbBatchSize = numNonDroppedLayers - mdpBatchSize;
731 int lastMDPSupportedIndex = numAppLayers;
732 int dropCount = 0;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800733
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800734 //Find the minimum MDP batch size
735 for(int i = 0; i < numAppLayers;i++) {
736 if(mCurrentFrame.drop[i]) {
737 dropCount++;
Jeykumar Sankaran846e2792014-01-23 21:59:58 -0800738 continue;
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800739 }
740 hwc_layer_1_t* layer = &list->hwLayers[i];
741 if(not isSupportedForMDPComp(ctx, layer)) {
742 lastMDPSupportedIndex = i;
743 mdpBatchSize = min(i - dropCount, stagesForMDP - 1);
744 fbBatchSize = numNonDroppedLayers - mdpBatchSize;
Jeykumar Sankaran846e2792014-01-23 21:59:58 -0800745 break;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800746 }
Saurabh Shahb772ae32013-11-18 15:40:02 -0800747 }
748
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800749 ALOGD_IF(isDebug(), "%s:Before optimizing fbBatch, mdpbatch %d, fbbatch %d "
750 "dropped %d", __FUNCTION__, mdpBatchSize, fbBatchSize,
751 mCurrentFrame.dropCount);
752
753 //Start at a point where the fb batch should at least have 2 layers, for
754 //this mode to be justified.
755 while(fbBatchSize < 2) {
756 ++fbBatchSize;
757 --mdpBatchSize;
Jeykumar Sankaran846e2792014-01-23 21:59:58 -0800758 }
Saurabh Shahb772ae32013-11-18 15:40:02 -0800759
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800760 //If there are no layers for MDP, this mode doesnt make sense.
761 if(mdpBatchSize < 1) {
762 ALOGD_IF(isDebug(), "%s: No MDP layers after optimizing for fbBatch",
763 __FUNCTION__);
Saurabh Shahb772ae32013-11-18 15:40:02 -0800764 return false;
765 }
766
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800767 mCurrentFrame.reset(numAppLayers);
768
769 //Try with successively smaller mdp batch sizes until we succeed or reach 1
770 while(mdpBatchSize > 0) {
771 //Mark layers for MDP comp
772 int mdpBatchLeft = mdpBatchSize;
773 for(int i = 0; i < lastMDPSupportedIndex and mdpBatchLeft; i++) {
774 if(mCurrentFrame.drop[i]) {
775 continue;
776 }
777 mCurrentFrame.isFBComposed[i] = false;
778 --mdpBatchLeft;
779 }
780
781 mCurrentFrame.fbZ = mdpBatchSize;
782 mCurrentFrame.fbCount = fbBatchSize;
783 mCurrentFrame.mdpCount = mdpBatchSize;
784
785 ALOGD_IF(isDebug(), "%s:Trying with: mdpbatch %d fbbatch %d dropped %d",
786 __FUNCTION__, mdpBatchSize, fbBatchSize,
787 mCurrentFrame.dropCount);
788
789 if(postHeuristicsHandling(ctx, list)) {
790 ALOGD_IF(isDebug(), "%s: Postheuristics handling succeeded",
791 __FUNCTION__);
792 return true;
793 }
794
795 reset(ctx);
796 --mdpBatchSize;
797 ++fbBatchSize;
798 }
799
800 return false;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800801}
802
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -0800803bool MDPComp::isLoadBasedCompDoable(hwc_context_t *ctx) {
Prabhanjan Kandula3dbbd882013-12-11 14:43:46 +0530804 if(mDpy or isSecurePresent(ctx, mDpy) or
805 isYuvPresent(ctx, mDpy)) {
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700806 return false;
807 }
808 return true;
809}
810
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800811bool MDPComp::tryVideoOnly(hwc_context_t *ctx,
812 hwc_display_contents_1_t* list) {
813 const bool secureOnly = true;
814 return videoOnlyComp(ctx, list, not secureOnly) or
815 videoOnlyComp(ctx, list, secureOnly);
816}
817
818bool MDPComp::videoOnlyComp(hwc_context_t *ctx,
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700819 hwc_display_contents_1_t* list, bool secureOnly) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700820 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700821
Saurabh Shahaa236822013-04-24 18:07:26 -0700822 mCurrentFrame.reset(numAppLayers);
Jeykumar Sankaraneb3a5e22014-04-08 16:07:55 -0700823 mCurrentFrame.fbCount -= mCurrentFrame.dropCount;
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700824 updateYUV(ctx, list, secureOnly);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700825 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700826
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800827 if(!isYuvPresent(ctx, mDpy) or (mdpCount == 0)) {
828 reset(ctx);
Saurabh Shahaa236822013-04-24 18:07:26 -0700829 return false;
830 }
831
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -0800832 /* Bail out if we are processing only secured video layers
833 * and we dont have any */
834 if(!isSecurePresent(ctx, mDpy) && secureOnly){
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800835 reset(ctx);
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -0800836 return false;
837 }
838
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800839 if(mCurrentFrame.fbCount)
840 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
Saurabh Shah4fdde762013-04-30 18:47:33 -0700841
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800842 if(sEnable4k2kYUVSplit){
843 adjustForSourceSplit(ctx, list);
844 }
845
846 if(!postHeuristicsHandling(ctx, list)) {
847 ALOGD_IF(isDebug(), "post heuristic handling failed");
848 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700849 return false;
850 }
851
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800852 return true;
853}
854
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800855/* Checks for conditions where YUV layers cannot be bypassed */
856bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -0700857 if(isSkipLayer(layer)) {
Saurabh Shahe2474082013-05-15 16:32:13 -0700858 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800859 return false;
860 }
861
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700862 if(layer->transform & HWC_TRANSFORM_ROT_90 && !canUseRotator(ctx,mDpy)) {
863 ALOGD_IF(isDebug(), "%s: no free DMA pipe",__FUNCTION__);
864 return false;
865 }
866
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800867 if(isSecuring(ctx, layer)) {
868 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
869 return false;
870 }
871
Saurabh Shah4fdde762013-04-30 18:47:33 -0700872 if(!isValidDimension(ctx, layer)) {
873 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
874 __FUNCTION__);
875 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800876 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700877
Naseer Ahmeddc61a972013-07-10 17:50:54 -0400878 if(layer->planeAlpha < 0xFF) {
879 ALOGD_IF(isDebug(), "%s: Cannot handle YUV layer with plane alpha\
880 in video only mode",
881 __FUNCTION__);
882 return false;
883 }
884
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800885 return true;
886}
887
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530888/* starts at fromIndex and check for each layer to find
889 * if it it has overlapping with any Updating layer above it in zorder
890 * till the end of the batch. returns true if it finds any intersection */
891bool MDPComp::canPushBatchToTop(const hwc_display_contents_1_t* list,
892 int fromIndex, int toIndex) {
893 for(int i = fromIndex; i < toIndex; i++) {
894 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
895 if(intersectingUpdatingLayers(list, i+1, toIndex, i)) {
896 return false;
897 }
898 }
899 }
900 return true;
901}
902
903/* Checks if given layer at targetLayerIndex has any
904 * intersection with all the updating layers in beween
905 * fromIndex and toIndex. Returns true if it finds intersectiion */
906bool MDPComp::intersectingUpdatingLayers(const hwc_display_contents_1_t* list,
907 int fromIndex, int toIndex, int targetLayerIndex) {
908 for(int i = fromIndex; i <= toIndex; i++) {
909 if(!mCurrentFrame.isFBComposed[i]) {
910 if(areLayersIntersecting(&list->hwLayers[i],
911 &list->hwLayers[targetLayerIndex])) {
912 return true;
913 }
914 }
915 }
916 return false;
917}
918
919int MDPComp::getBatch(hwc_display_contents_1_t* list,
920 int& maxBatchStart, int& maxBatchEnd,
921 int& maxBatchCount) {
922 int i = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530923 int fbZOrder =-1;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -0800924 int droppedLayerCt = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530925 while (i < mCurrentFrame.layerCount) {
926 int batchCount = 0;
927 int batchStart = i;
928 int batchEnd = i;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -0800929 /* Adjust batch Z order with the dropped layers so far */
930 int fbZ = batchStart - droppedLayerCt;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530931 int firstZReverseIndex = -1;
Prabhanjan Kandula0ed2cc92013-12-06 12:39:04 +0530932 int updatingLayersAbove = 0;//Updating layer count in middle of batch
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530933 while(i < mCurrentFrame.layerCount) {
934 if(!mCurrentFrame.isFBComposed[i]) {
935 if(!batchCount) {
936 i++;
937 break;
938 }
939 updatingLayersAbove++;
940 i++;
941 continue;
942 } else {
943 if(mCurrentFrame.drop[i]) {
944 i++;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -0800945 droppedLayerCt++;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530946 continue;
947 } else if(updatingLayersAbove <= 0) {
948 batchCount++;
949 batchEnd = i;
950 i++;
951 continue;
952 } else { //Layer is FBComposed, not a drop & updatingLayer > 0
953
954 // We have a valid updating layer already. If layer-i not
955 // have overlapping with all updating layers in between
956 // batch-start and i, then we can add layer i to batch.
957 if(!intersectingUpdatingLayers(list, batchStart, i-1, i)) {
958 batchCount++;
959 batchEnd = i;
960 i++;
961 continue;
962 } else if(canPushBatchToTop(list, batchStart, i)) {
963 //If All the non-updating layers with in this batch
964 //does not have intersection with the updating layers
965 //above in z-order, then we can safely move the batch to
966 //higher z-order. Increment fbZ as it is moving up.
967 if( firstZReverseIndex < 0) {
968 firstZReverseIndex = i;
969 }
970 batchCount++;
971 batchEnd = i;
972 fbZ += updatingLayersAbove;
973 i++;
974 updatingLayersAbove = 0;
975 continue;
976 } else {
977 //both failed.start the loop again from here.
978 if(firstZReverseIndex >= 0) {
979 i = firstZReverseIndex;
980 }
981 break;
982 }
983 }
984 }
985 }
986 if(batchCount > maxBatchCount) {
987 maxBatchCount = batchCount;
988 maxBatchStart = batchStart;
989 maxBatchEnd = batchEnd;
990 fbZOrder = fbZ;
991 }
992 }
993 return fbZOrder;
994}
995
996bool MDPComp::markLayersForCaching(hwc_context_t* ctx,
997 hwc_display_contents_1_t* list) {
998 /* Idea is to keep as many non-updating(cached) layers in FB and
999 * send rest of them through MDP. This is done in 2 steps.
1000 * 1. Find the maximum contiguous batch of non-updating layers.
1001 * 2. See if we can improve this batch size for caching by adding
1002 * opaque layers around the batch, if they don't have
1003 * any overlapping with the updating layers in between.
1004 * NEVER mark an updating layer for caching.
1005 * But cached ones can be marked for MDP */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001006
1007 int maxBatchStart = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001008 int maxBatchEnd = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001009 int maxBatchCount = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301010 int fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001011
Saurabh Shahd53bc5f2014-02-05 10:17:43 -08001012 /* Nothing is cached. No batching needed */
1013 if(mCurrentFrame.fbCount == 0) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001014 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -07001015 }
Saurabh Shahd53bc5f2014-02-05 10:17:43 -08001016
1017 /* No MDP comp layers, try to use other comp modes */
1018 if(mCurrentFrame.mdpCount == 0) {
1019 return false;
Saurabh Shahaa236822013-04-24 18:07:26 -07001020 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001021
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301022 fbZ = getBatch(list, maxBatchStart, maxBatchEnd, maxBatchCount);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001023
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301024 /* reset rest of the layers lying inside ROI for MDP comp */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001025 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001026 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001027 if((i < maxBatchStart || i > maxBatchEnd) &&
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301028 mCurrentFrame.isFBComposed[i]){
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001029 if(!mCurrentFrame.drop[i]){
1030 //If an unsupported layer is being attempted to
1031 //be pulled out we should fail
1032 if(not isSupportedForMDPComp(ctx, layer)) {
1033 return false;
1034 }
1035 mCurrentFrame.isFBComposed[i] = false;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001036 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001037 }
1038 }
1039
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301040 // update the frame data
1041 mCurrentFrame.fbZ = fbZ;
1042 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001043 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001044 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001045
1046 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301047 mCurrentFrame.fbCount);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001048
1049 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001050}
Saurabh Shah85234ec2013-04-12 17:09:00 -07001051
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001052void MDPComp::updateLayerCache(hwc_context_t* ctx,
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001053 hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001054 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001055 int fbCount = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001056
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001057 for(int i = 0; i < numAppLayers; i++) {
1058 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001059 if(!mCurrentFrame.drop[i])
1060 fbCount++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001061 mCurrentFrame.isFBComposed[i] = true;
1062 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -07001063 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001064 }
1065 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001066
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001067 mCurrentFrame.fbCount = fbCount;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001068 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount
1069 - mCurrentFrame.dropCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001070
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001071 ALOGD_IF(isDebug(),"%s: MDP count: %d FB count %d drop count: %d"
1072 ,__FUNCTION__, mCurrentFrame.mdpCount, mCurrentFrame.fbCount,
1073 mCurrentFrame.dropCount);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001074}
1075
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001076void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list,
1077 bool secureOnly) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001078 int nYuvCount = ctx->listStats[mDpy].yuvCount;
1079 for(int index = 0;index < nYuvCount; index++){
1080 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
1081 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
1082
1083 if(!isYUVDoable(ctx, layer)) {
1084 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
1085 mCurrentFrame.isFBComposed[nYuvIndex] = true;
1086 mCurrentFrame.fbCount++;
1087 }
1088 } else {
1089 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001090 private_handle_t *hnd = (private_handle_t *)layer->handle;
1091 if(!secureOnly || isSecureBuffer(hnd)) {
1092 mCurrentFrame.isFBComposed[nYuvIndex] = false;
1093 mCurrentFrame.fbCount--;
1094 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001095 }
1096 }
1097 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001098
1099 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001100 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
1101 ALOGD_IF(isDebug(),"%s: fb count: %d",__FUNCTION__,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001102 mCurrentFrame.fbCount);
1103}
1104
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301105hwc_rect_t MDPComp::getUpdatingFBRect(hwc_display_contents_1_t* list){
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001106 hwc_rect_t fbRect = (struct hwc_rect){0, 0, 0, 0};
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001107
1108 /* Update only the region of FB needed for composition */
1109 for(int i = 0; i < mCurrentFrame.layerCount; i++ ) {
1110 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
1111 hwc_layer_1_t* layer = &list->hwLayers[i];
1112 hwc_rect_t dst = layer->displayFrame;
1113 fbRect = getUnion(fbRect, dst);
1114 }
1115 }
1116 return fbRect;
1117}
1118
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001119bool MDPComp::postHeuristicsHandling(hwc_context_t *ctx,
1120 hwc_display_contents_1_t* list) {
1121
1122 //Capability checks
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301123 if(!resourceCheck()) {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001124 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
1125 return false;
1126 }
1127
1128 //Limitations checks
1129 if(!hwLimitationsCheck(ctx, list)) {
1130 ALOGD_IF(isDebug(), "%s: HW limitations",__FUNCTION__);
1131 return false;
1132 }
1133
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001134 //Configure framebuffer first if applicable
1135 if(mCurrentFrame.fbZ >= 0) {
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301136 hwc_rect_t fbRect = getUpdatingFBRect(list);
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001137 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, fbRect, mCurrentFrame.fbZ))
1138 {
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001139 ALOGD_IF(isDebug(), "%s configure framebuffer failed",
1140 __FUNCTION__);
1141 return false;
1142 }
1143 }
1144
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001145 mCurrentFrame.map();
1146
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001147 if(!allocLayerPipes(ctx, list)) {
1148 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -07001149 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001150 }
1151
1152 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001153 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001154 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001155 int mdpIndex = mCurrentFrame.layerToMDP[index];
1156 hwc_layer_1_t* layer = &list->hwLayers[index];
1157
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301158 //Leave fbZ for framebuffer. CACHE/GLES layers go here.
1159 if(mdpNextZOrder == mCurrentFrame.fbZ) {
1160 mdpNextZOrder++;
1161 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001162 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1163 cur_pipe->zOrder = mdpNextZOrder++;
1164
radhakrishnac9a67412013-09-25 17:40:42 +05301165 private_handle_t *hnd = (private_handle_t *)layer->handle;
1166 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1167 if(configure4k2kYuv(ctx, layer,
1168 mCurrentFrame.mdpToLayer[mdpIndex])
1169 != 0 ){
1170 ALOGD_IF(isDebug(), "%s: Failed to configure split pipes \
1171 for layer %d",__FUNCTION__, index);
1172 return false;
1173 }
1174 else{
1175 mdpNextZOrder++;
1176 }
1177 continue;
1178 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001179 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
1180 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
radhakrishnac9a67412013-09-25 17:40:42 +05301181 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -07001182 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001183 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001184 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001185 }
1186
Saurabh Shaha36be922013-12-16 18:18:39 -08001187 if(!ctx->mOverlay->validateAndSet(mDpy, ctx->dpyAttr[mDpy].fd)) {
1188 ALOGD_IF(isDebug(), "%s: Failed to validate and set overlay for dpy %d"
1189 ,__FUNCTION__, mDpy);
1190 return false;
1191 }
1192
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001193 setRedraw(ctx, list);
Saurabh Shahaa236822013-04-24 18:07:26 -07001194 return true;
1195}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001196
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301197bool MDPComp::resourceCheck() {
Saurabh Shah173f4242013-11-20 09:50:12 -08001198 const bool fbUsed = mCurrentFrame.fbCount;
1199 if(mCurrentFrame.mdpCount > sMaxPipesPerMixer - fbUsed) {
1200 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
1201 return false;
1202 }
Saurabh Shah173f4242013-11-20 09:50:12 -08001203 return true;
1204}
1205
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301206bool MDPComp::hwLimitationsCheck(hwc_context_t* ctx,
1207 hwc_display_contents_1_t* list) {
1208
1209 //A-family hw limitation:
1210 //If a layer need alpha scaling, MDP can not support.
1211 if(ctx->mMDP.version < qdutils::MDSS_V5) {
1212 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1213 if(!mCurrentFrame.isFBComposed[i] &&
1214 isAlphaScaled( &list->hwLayers[i])) {
1215 ALOGD_IF(isDebug(), "%s:frame needs alphaScaling",__FUNCTION__);
1216 return false;
1217 }
1218 }
1219 }
1220
1221 // On 8x26 & 8974 hw, we have a limitation of downscaling+blending.
1222 //If multiple layers requires downscaling and also they are overlapping
1223 //fall back to GPU since MDSS can not handle it.
1224 if(qdutils::MDPVersion::getInstance().is8x74v2() ||
1225 qdutils::MDPVersion::getInstance().is8x26()) {
1226 for(int i = 0; i < mCurrentFrame.layerCount-1; ++i) {
1227 hwc_layer_1_t* botLayer = &list->hwLayers[i];
1228 if(!mCurrentFrame.isFBComposed[i] &&
1229 isDownscaleRequired(botLayer)) {
1230 //if layer-i is marked for MDP and needs downscaling
1231 //check if any MDP layer on top of i & overlaps with layer-i
1232 for(int j = i+1; j < mCurrentFrame.layerCount; ++j) {
1233 hwc_layer_1_t* topLayer = &list->hwLayers[j];
1234 if(!mCurrentFrame.isFBComposed[j] &&
1235 isDownscaleRequired(topLayer)) {
1236 hwc_rect_t r = getIntersection(botLayer->displayFrame,
1237 topLayer->displayFrame);
1238 if(isValidRect(r))
1239 return false;
1240 }
1241 }
1242 }
1243 }
1244 }
1245 return true;
1246}
1247
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001248int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001249 int ret = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -07001250 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -07001251
Raj Kamal9ed3d6b2014-02-07 16:15:17 +05301252 //Do not cache the information for next draw cycle.
1253 if(numLayers > MAX_NUM_APP_LAYERS or (!numLayers)) {
1254 ALOGI("%s: Unsupported layer count for mdp composition",
1255 __FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001256 mCachedFrame.reset();
1257 return -1;
1258 }
1259
Saurabh Shahb39f8152013-08-22 10:21:44 -07001260 //reset old data
1261 mCurrentFrame.reset(numLayers);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001262 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1263 mCurrentFrame.dropCount = 0;
Prabhanjan Kandula088bd892013-07-02 23:47:13 +05301264
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -07001265 // Detect the start of animation and fall back to GPU only once to cache
1266 // all the layers in FB and display FB content untill animation completes.
1267 if(ctx->listStats[mDpy].isDisplayAnimating) {
1268 mCurrentFrame.needsRedraw = false;
1269 if(ctx->mAnimationState[mDpy] == ANIMATION_STOPPED) {
1270 mCurrentFrame.needsRedraw = true;
1271 ctx->mAnimationState[mDpy] = ANIMATION_STARTED;
1272 }
1273 setMDPCompLayerFlags(ctx, list);
1274 mCachedFrame.updateCounts(mCurrentFrame);
1275 ret = -1;
1276 return ret;
1277 } else {
1278 ctx->mAnimationState[mDpy] = ANIMATION_STOPPED;
1279 }
1280
Saurabh Shahb39f8152013-08-22 10:21:44 -07001281 //Hard conditions, if not met, cannot do MDP comp
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001282 if(isFrameDoable(ctx)) {
1283 generateROI(ctx, list);
Saurabh Shahb39f8152013-08-22 10:21:44 -07001284
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001285 if(tryFullFrame(ctx, list) || tryVideoOnly(ctx, list)) {
1286 setMDPCompLayerFlags(ctx, list);
1287 } else {
1288 reset(ctx);
1289 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1290 mCurrentFrame.dropCount = 0;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001291 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001292 }
1293 } else {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001294 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
1295 __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001296 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001297 }
Saurabh Shahb39f8152013-08-22 10:21:44 -07001298
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001299 if(isDebug()) {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001300 ALOGD("GEOMETRY change: %d",
1301 (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001302 android::String8 sDump("");
1303 dump(sDump);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001304 ALOGD("%s",sDump.string());
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001305 }
1306
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001307 mCachedFrame.cacheAll(list);
1308 mCachedFrame.updateCounts(mCurrentFrame);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001309 return ret;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001310}
1311
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001312bool MDPComp::allocSplitVGPipesfor4k2k(hwc_context_t *ctx, int index) {
radhakrishnac9a67412013-09-25 17:40:42 +05301313
1314 bool bRet = true;
radhakrishnac9a67412013-09-25 17:40:42 +05301315 int mdpIndex = mCurrentFrame.layerToMDP[index];
1316 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
1317 info.pipeInfo = new MdpYUVPipeInfo;
1318 info.rot = NULL;
1319 MdpYUVPipeInfo& pipe_info = *(MdpYUVPipeInfo*)info.pipeInfo;
radhakrishnac9a67412013-09-25 17:40:42 +05301320
1321 pipe_info.lIndex = ovutils::OV_INVALID;
1322 pipe_info.rIndex = ovutils::OV_INVALID;
1323
Saurabh Shahc62f3982014-03-05 14:28:26 -08001324 Overlay::PipeSpecs pipeSpecs;
1325 pipeSpecs.formatClass = Overlay::FORMAT_YUV;
1326 pipeSpecs.needsScaling = true;
1327 pipeSpecs.dpy = mDpy;
1328 pipeSpecs.fb = false;
1329
1330 pipe_info.lIndex = ctx->mOverlay->getPipe(pipeSpecs);
radhakrishnac9a67412013-09-25 17:40:42 +05301331 if(pipe_info.lIndex == ovutils::OV_INVALID){
1332 bRet = false;
1333 ALOGD_IF(isDebug(),"%s: allocating first VG pipe failed",
1334 __FUNCTION__);
1335 }
Saurabh Shahc62f3982014-03-05 14:28:26 -08001336 pipe_info.rIndex = ctx->mOverlay->getPipe(pipeSpecs);
radhakrishnac9a67412013-09-25 17:40:42 +05301337 if(pipe_info.rIndex == ovutils::OV_INVALID){
1338 bRet = false;
1339 ALOGD_IF(isDebug(),"%s: allocating second VG pipe failed",
1340 __FUNCTION__);
1341 }
1342 return bRet;
1343}
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001344//=============MDPCompNonSplit==================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001345
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001346void MDPCompNonSplit::adjustForSourceSplit(hwc_context_t *ctx,
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001347 hwc_display_contents_1_t*) {
radhakrishnac9a67412013-09-25 17:40:42 +05301348 //As we split 4kx2k yuv layer and program to 2 VG pipes
1349 //(if available) increase mdpcount accordingly
1350 mCurrentFrame.mdpCount += ctx->listStats[mDpy].yuv4k2kCount;
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001351
1352 //If 4k2k Yuv layer split is possible, and if
1353 //fbz is above 4k2k layer, increment fb zorder by 1
1354 //as we split 4k2k layer and increment zorder for right half
1355 //of the layer
1356 if(mCurrentFrame.fbZ >= 0) {
1357 int n4k2kYuvCount = ctx->listStats[mDpy].yuv4k2kCount;
1358 for(int index = 0; index < n4k2kYuvCount; index++){
1359 int n4k2kYuvIndex =
1360 ctx->listStats[mDpy].yuv4k2kIndices[index];
Dileep Kumar Reddi4cff9282014-04-01 12:57:08 +05301361 if(mCurrentFrame.fbZ >= n4k2kYuvIndex){
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001362 mCurrentFrame.fbZ += 1;
1363 }
1364 }
1365 }
radhakrishnac9a67412013-09-25 17:40:42 +05301366}
1367
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001368/*
1369 * Configures pipe(s) for MDP composition
1370 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001371int MDPCompNonSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001372 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001373 MdpPipeInfoNonSplit& mdp_info =
1374 *(static_cast<MdpPipeInfoNonSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001375 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
1376 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1377 eIsFg isFg = IS_FG_OFF;
1378 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001379
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001380 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
1381 __FUNCTION__, layer, zOrder, dest);
1382
Saurabh Shah88e4d272013-09-03 13:31:29 -07001383 return configureNonSplit(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001384 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001385}
1386
Saurabh Shah88e4d272013-09-03 13:31:29 -07001387bool MDPCompNonSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001388 hwc_display_contents_1_t* list) {
1389 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001390
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001391 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001392
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001393 hwc_layer_1_t* layer = &list->hwLayers[index];
1394 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301395 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001396 if(allocSplitVGPipesfor4k2k(ctx, index)){
radhakrishnac9a67412013-09-25 17:40:42 +05301397 continue;
1398 }
1399 }
1400
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001401 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001402 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001403 info.pipeInfo = new MdpPipeInfoNonSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08001404 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001405 MdpPipeInfoNonSplit& pipe_info = *(MdpPipeInfoNonSplit*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001406
Saurabh Shahc62f3982014-03-05 14:28:26 -08001407 Overlay::PipeSpecs pipeSpecs;
1408 pipeSpecs.formatClass = isYuvBuffer(hnd) ?
1409 Overlay::FORMAT_YUV : Overlay::FORMAT_RGB;
1410 pipeSpecs.needsScaling = qhwc::needsScaling(layer) or
1411 (qdutils::MDPVersion::getInstance().is8x26() and
1412 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres > 1024);
1413 pipeSpecs.dpy = mDpy;
1414 pipeSpecs.fb = false;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001415
Saurabh Shahc62f3982014-03-05 14:28:26 -08001416 pipe_info.index = ctx->mOverlay->getPipe(pipeSpecs);
1417
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001418 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001419 ALOGD_IF(isDebug(), "%s: Unable to get pipe", __FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001420 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001421 }
1422 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001423 return true;
1424}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001425
radhakrishnac9a67412013-09-25 17:40:42 +05301426int MDPCompNonSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1427 PipeLayerPair& PipeLayerPair) {
1428 MdpYUVPipeInfo& mdp_info =
1429 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1430 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1431 eIsFg isFg = IS_FG_OFF;
1432 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1433 eDest lDest = mdp_info.lIndex;
1434 eDest rDest = mdp_info.rIndex;
1435
1436 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1437 lDest, rDest, &PipeLayerPair.rot);
1438}
1439
Saurabh Shah88e4d272013-09-03 13:31:29 -07001440bool MDPCompNonSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001441
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001442 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001443 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1444 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -08001445 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001446
1447 if(!ctx || !list) {
1448 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001449 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001450 }
1451
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301452 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1453 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1454 return true;
1455 }
1456
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -08001457 // Set the Handle timeout to true for MDP or MIXED composition.
1458 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount) {
1459 sHandleTimeout = true;
1460 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001461
1462 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001463 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001464
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001465 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1466 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001467 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001468 if(mCurrentFrame.isFBComposed[i]) continue;
1469
Naseer Ahmed5b6708a2012-08-02 13:46:08 -07001470 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001471 private_handle_t *hnd = (private_handle_t *)layer->handle;
1472 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001473 if (!(layer->flags & HWC_COLOR_FILL)) {
1474 ALOGE("%s handle null", __FUNCTION__);
1475 return false;
1476 }
1477 // No PLAY for Color layer
1478 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1479 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001480 }
1481
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001482 int mdpIndex = mCurrentFrame.layerToMDP[i];
1483
radhakrishnac9a67412013-09-25 17:40:42 +05301484 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1485 {
1486 MdpYUVPipeInfo& pipe_info =
1487 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1488 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1489 ovutils::eDest indexL = pipe_info.lIndex;
1490 ovutils::eDest indexR = pipe_info.rIndex;
1491 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301492 uint32_t offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05301493 if(rot) {
1494 rot->queueBuffer(fd, offset);
1495 fd = rot->getDstMemId();
1496 offset = rot->getDstOffset();
1497 }
1498 if(indexL != ovutils::OV_INVALID) {
1499 ovutils::eDest destL = (ovutils::eDest)indexL;
1500 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1501 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1502 if (!ov.queueBuffer(fd, offset, destL)) {
1503 ALOGE("%s: queueBuffer failed for display:%d",
1504 __FUNCTION__, mDpy);
1505 return false;
1506 }
1507 }
1508
1509 if(indexR != ovutils::OV_INVALID) {
1510 ovutils::eDest destR = (ovutils::eDest)indexR;
1511 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1512 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1513 if (!ov.queueBuffer(fd, offset, destR)) {
1514 ALOGE("%s: queueBuffer failed for display:%d",
1515 __FUNCTION__, mDpy);
1516 return false;
1517 }
1518 }
1519 }
1520 else{
1521 MdpPipeInfoNonSplit& pipe_info =
Saurabh Shah88e4d272013-09-03 13:31:29 -07001522 *(MdpPipeInfoNonSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
radhakrishnac9a67412013-09-25 17:40:42 +05301523 ovutils::eDest dest = pipe_info.index;
1524 if(dest == ovutils::OV_INVALID) {
1525 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001526 return false;
radhakrishnac9a67412013-09-25 17:40:42 +05301527 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001528
radhakrishnac9a67412013-09-25 17:40:42 +05301529 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1530 continue;
1531 }
1532
1533 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1534 using pipe: %d", __FUNCTION__, layer,
1535 hnd, dest );
1536
1537 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301538 uint32_t offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05301539
1540 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1541 if(rot) {
1542 if(!rot->queueBuffer(fd, offset))
1543 return false;
1544 fd = rot->getDstMemId();
1545 offset = rot->getDstOffset();
1546 }
1547
1548 if (!ov.queueBuffer(fd, offset, dest)) {
1549 ALOGE("%s: queueBuffer failed for display:%d ",
1550 __FUNCTION__, mDpy);
1551 return false;
1552 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001553 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001554
1555 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001556 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001557 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001558}
1559
Saurabh Shah88e4d272013-09-03 13:31:29 -07001560//=============MDPCompSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001561
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001562void MDPCompSplit::adjustForSourceSplit(hwc_context_t *ctx,
radhakrishnac9a67412013-09-25 17:40:42 +05301563 hwc_display_contents_1_t* list){
1564 //if 4kx2k yuv layer is totally present in either in left half
1565 //or right half then try splitting the yuv layer to avoid decimation
1566 int n4k2kYuvCount = ctx->listStats[mDpy].yuv4k2kCount;
1567 const int lSplit = getLeftSplit(ctx, mDpy);
1568 for(int index = 0; index < n4k2kYuvCount; index++){
1569 int n4k2kYuvIndex = ctx->listStats[mDpy].yuv4k2kIndices[index];
1570 hwc_layer_1_t* layer = &list->hwLayers[n4k2kYuvIndex];
1571 hwc_rect_t dst = layer->displayFrame;
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001572 if((dst.left > lSplit) || (dst.right < lSplit)) {
radhakrishnac9a67412013-09-25 17:40:42 +05301573 mCurrentFrame.mdpCount += 1;
1574 }
Dileep Kumar Reddi4cff9282014-04-01 12:57:08 +05301575 if(mCurrentFrame.fbZ >= n4k2kYuvIndex){
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001576 mCurrentFrame.fbZ += 1;
1577 }
radhakrishnac9a67412013-09-25 17:40:42 +05301578 }
1579}
1580
Saurabh Shah88e4d272013-09-03 13:31:29 -07001581bool MDPCompSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Saurabh Shahc62f3982014-03-05 14:28:26 -08001582 MdpPipeInfoSplit& pipe_info) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001583
Saurabh Shahc62f3982014-03-05 14:28:26 -08001584 const int lSplit = getLeftSplit(ctx, mDpy);
1585 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001586 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001587 pipe_info.lIndex = ovutils::OV_INVALID;
1588 pipe_info.rIndex = ovutils::OV_INVALID;
1589
Saurabh Shahc62f3982014-03-05 14:28:26 -08001590 Overlay::PipeSpecs pipeSpecs;
1591 pipeSpecs.formatClass = isYuvBuffer(hnd) ?
1592 Overlay::FORMAT_YUV : Overlay::FORMAT_RGB;
1593 pipeSpecs.needsScaling = qhwc::needsScalingWithSplit(ctx, layer, mDpy);
1594 pipeSpecs.dpy = mDpy;
1595 pipeSpecs.mixer = Overlay::MIXER_LEFT;
1596 pipeSpecs.fb = false;
1597
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001598 if (dst.left < lSplit) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001599 pipe_info.lIndex = ctx->mOverlay->getPipe(pipeSpecs);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001600 if(pipe_info.lIndex == ovutils::OV_INVALID)
1601 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001602 }
1603
1604 if(dst.right > lSplit) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001605 pipeSpecs.mixer = Overlay::MIXER_RIGHT;
1606 pipe_info.rIndex = ctx->mOverlay->getPipe(pipeSpecs);
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001607 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001608 return false;
1609 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001610
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001611 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001612}
1613
Saurabh Shah88e4d272013-09-03 13:31:29 -07001614bool MDPCompSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001615 hwc_display_contents_1_t* list) {
1616 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001617
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001618 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001619
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001620 hwc_layer_1_t* layer = &list->hwLayers[index];
1621 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301622 hwc_rect_t dst = layer->displayFrame;
1623 const int lSplit = getLeftSplit(ctx, mDpy);
1624 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1625 if((dst.left > lSplit)||(dst.right < lSplit)){
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001626 if(allocSplitVGPipesfor4k2k(ctx, index)){
radhakrishnac9a67412013-09-25 17:40:42 +05301627 continue;
1628 }
1629 }
1630 }
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001631 int mdpIndex = mCurrentFrame.layerToMDP[index];
1632 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001633 info.pipeInfo = new MdpPipeInfoSplit;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001634 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001635 MdpPipeInfoSplit& pipe_info = *(MdpPipeInfoSplit*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001636
Saurabh Shahc62f3982014-03-05 14:28:26 -08001637 if(!acquireMDPPipes(ctx, layer, pipe_info)) {
1638 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type",
1639 __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001640 return false;
1641 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001642 }
1643 return true;
1644}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001645
radhakrishnac9a67412013-09-25 17:40:42 +05301646int MDPCompSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1647 PipeLayerPair& PipeLayerPair) {
1648 const int lSplit = getLeftSplit(ctx, mDpy);
1649 hwc_rect_t dst = layer->displayFrame;
1650 if((dst.left > lSplit)||(dst.right < lSplit)){
1651 MdpYUVPipeInfo& mdp_info =
1652 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1653 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1654 eIsFg isFg = IS_FG_OFF;
1655 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1656 eDest lDest = mdp_info.lIndex;
1657 eDest rDest = mdp_info.rIndex;
1658
1659 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1660 lDest, rDest, &PipeLayerPair.rot);
1661 }
1662 else{
1663 return configure(ctx, layer, PipeLayerPair);
1664 }
1665}
1666
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001667/*
1668 * Configures pipe(s) for MDP composition
1669 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001670int MDPCompSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001671 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001672 MdpPipeInfoSplit& mdp_info =
1673 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001674 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1675 eIsFg isFg = IS_FG_OFF;
1676 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1677 eDest lDest = mdp_info.lIndex;
1678 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001679
1680 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1681 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1682
Saurabh Shah88e4d272013-09-03 13:31:29 -07001683 return configureSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001684 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001685}
1686
Saurabh Shah88e4d272013-09-03 13:31:29 -07001687bool MDPCompSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001688
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001689 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001690 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1691 return true;
1692 }
1693
1694 if(!ctx || !list) {
1695 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001696 return false;
1697 }
1698
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301699 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1700 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1701 return true;
1702 }
1703
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -08001704 // Set the Handle timeout to true for MDP or MIXED composition.
1705 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount) {
1706 sHandleTimeout = true;
1707 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001708
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001709 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001710 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001711
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001712 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1713 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001714 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001715 if(mCurrentFrame.isFBComposed[i]) continue;
1716
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001717 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001718 private_handle_t *hnd = (private_handle_t *)layer->handle;
1719 if(!hnd) {
1720 ALOGE("%s handle null", __FUNCTION__);
1721 return false;
1722 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001723
1724 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1725 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001726 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001727
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001728 int mdpIndex = mCurrentFrame.layerToMDP[i];
1729
radhakrishnac9a67412013-09-25 17:40:42 +05301730 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1731 {
1732 MdpYUVPipeInfo& pipe_info =
1733 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1734 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1735 ovutils::eDest indexL = pipe_info.lIndex;
1736 ovutils::eDest indexR = pipe_info.rIndex;
1737 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301738 uint32_t offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05301739 if(rot) {
1740 rot->queueBuffer(fd, offset);
1741 fd = rot->getDstMemId();
1742 offset = rot->getDstOffset();
1743 }
1744 if(indexL != ovutils::OV_INVALID) {
1745 ovutils::eDest destL = (ovutils::eDest)indexL;
1746 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1747 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1748 if (!ov.queueBuffer(fd, offset, destL)) {
1749 ALOGE("%s: queueBuffer failed for display:%d",
1750 __FUNCTION__, mDpy);
1751 return false;
1752 }
1753 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001754
radhakrishnac9a67412013-09-25 17:40:42 +05301755 if(indexR != ovutils::OV_INVALID) {
1756 ovutils::eDest destR = (ovutils::eDest)indexR;
1757 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1758 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1759 if (!ov.queueBuffer(fd, offset, destR)) {
1760 ALOGE("%s: queueBuffer failed for display:%d",
1761 __FUNCTION__, mDpy);
1762 return false;
1763 }
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001764 }
1765 }
radhakrishnac9a67412013-09-25 17:40:42 +05301766 else{
1767 MdpPipeInfoSplit& pipe_info =
1768 *(MdpPipeInfoSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1769 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001770
radhakrishnac9a67412013-09-25 17:40:42 +05301771 ovutils::eDest indexL = pipe_info.lIndex;
1772 ovutils::eDest indexR = pipe_info.rIndex;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001773
radhakrishnac9a67412013-09-25 17:40:42 +05301774 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301775 int offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05301776
1777 if(ctx->mAD->isModeOn()) {
1778 if(ctx->mAD->draw(ctx, fd, offset)) {
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001779 fd = ctx->mAD->getDstFd();
1780 offset = ctx->mAD->getDstOffset();
radhakrishnac9a67412013-09-25 17:40:42 +05301781 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001782 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001783
radhakrishnac9a67412013-09-25 17:40:42 +05301784 if(rot) {
1785 rot->queueBuffer(fd, offset);
1786 fd = rot->getDstMemId();
1787 offset = rot->getDstOffset();
1788 }
1789
1790 //************* play left mixer **********
1791 if(indexL != ovutils::OV_INVALID) {
1792 ovutils::eDest destL = (ovutils::eDest)indexL;
1793 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1794 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1795 if (!ov.queueBuffer(fd, offset, destL)) {
1796 ALOGE("%s: queueBuffer failed for left mixer",
1797 __FUNCTION__);
1798 return false;
1799 }
1800 }
1801
1802 //************* play right mixer **********
1803 if(indexR != ovutils::OV_INVALID) {
1804 ovutils::eDest destR = (ovutils::eDest)indexR;
1805 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1806 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1807 if (!ov.queueBuffer(fd, offset, destR)) {
1808 ALOGE("%s: queueBuffer failed for right mixer",
1809 __FUNCTION__);
1810 return false;
1811 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001812 }
1813 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001814
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001815 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1816 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001817
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001818 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001819}
Saurabh Shahab47c692014-02-12 18:45:57 -08001820
1821//================MDPCompSrcSplit==============================================
1822bool MDPCompSrcSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Saurabh Shahc62f3982014-03-05 14:28:26 -08001823 MdpPipeInfoSplit& pipe_info) {
Saurabh Shahab47c692014-02-12 18:45:57 -08001824 private_handle_t *hnd = (private_handle_t *)layer->handle;
1825 hwc_rect_t dst = layer->displayFrame;
1826 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
1827 pipe_info.lIndex = ovutils::OV_INVALID;
1828 pipe_info.rIndex = ovutils::OV_INVALID;
1829
1830 //If 2 pipes are staged on a single stage of a mixer, then the left pipe
1831 //should have a higher priority than the right one. Pipe priorities are
1832 //starting with VG0, VG1 ... , RGB0 ..., DMA1
Saurabh Shahab47c692014-02-12 18:45:57 -08001833
Saurabh Shahc62f3982014-03-05 14:28:26 -08001834 Overlay::PipeSpecs pipeSpecs;
1835 pipeSpecs.formatClass = isYuvBuffer(hnd) ?
1836 Overlay::FORMAT_YUV : Overlay::FORMAT_RGB;
1837 pipeSpecs.needsScaling = qhwc::needsScaling(layer);
1838 pipeSpecs.dpy = mDpy;
1839 pipeSpecs.fb = false;
1840
Saurabh Shahab47c692014-02-12 18:45:57 -08001841 //1 pipe by default for a layer
Saurabh Shahc62f3982014-03-05 14:28:26 -08001842 pipe_info.lIndex = ctx->mOverlay->getPipe(pipeSpecs);
Saurabh Shahab47c692014-02-12 18:45:57 -08001843 if(pipe_info.lIndex == ovutils::OV_INVALID) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001844 return false;
Saurabh Shahab47c692014-02-12 18:45:57 -08001845 }
1846
1847 //If layer's crop width or dest width > 2048, use 2 pipes
1848 if((dst.right - dst.left) > qdutils::MAX_DISPLAY_DIM or
1849 (crop.right - crop.left) > qdutils::MAX_DISPLAY_DIM) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001850 pipe_info.rIndex = ctx->mOverlay->getPipe(pipeSpecs);
Saurabh Shahab47c692014-02-12 18:45:57 -08001851 if(pipe_info.rIndex == ovutils::OV_INVALID) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001852 return false;
Saurabh Shahdd8237a2014-02-28 14:29:09 -08001853 }
1854
1855 // Return values
1856 // 1 Left pipe is higher priority, do nothing.
1857 // 0 Pipes of same priority.
1858 //-1 Right pipe is of higher priority, needs swap.
1859 if(ctx->mOverlay->comparePipePriority(pipe_info.lIndex,
1860 pipe_info.rIndex) == -1) {
1861 qhwc::swap(pipe_info.lIndex, pipe_info.rIndex);
Saurabh Shahab47c692014-02-12 18:45:57 -08001862 }
1863 }
1864
1865 return true;
1866}
1867
Saurabh Shahab47c692014-02-12 18:45:57 -08001868int MDPCompSrcSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
1869 PipeLayerPair& PipeLayerPair) {
1870 private_handle_t *hnd = (private_handle_t *)layer->handle;
1871 if(!hnd) {
1872 ALOGE("%s: layer handle is NULL", __FUNCTION__);
1873 return -1;
1874 }
1875 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
1876 MdpPipeInfoSplit& mdp_info =
1877 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
1878 Rotator **rot = &PipeLayerPair.rot;
1879 eZorder z = static_cast<eZorder>(mdp_info.zOrder);
1880 eIsFg isFg = IS_FG_OFF;
1881 eDest lDest = mdp_info.lIndex;
1882 eDest rDest = mdp_info.rIndex;
1883 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
1884 hwc_rect_t dst = layer->displayFrame;
1885 int transform = layer->transform;
1886 eTransform orient = static_cast<eTransform>(transform);
1887 const int downscale = 0;
1888 int rotFlags = ROT_FLAGS_NONE;
1889 uint32_t format = ovutils::getMdpFormat(hnd->format, isTileRendered(hnd));
1890 Whf whf(getWidth(hnd), getHeight(hnd), format, hnd->size);
1891
1892 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1893 "dest_pipeR: %d",__FUNCTION__, layer, z, lDest, rDest);
1894
1895 // Handle R/B swap
1896 if (layer->flags & HWC_FORMAT_RB_SWAP) {
1897 if (hnd->format == HAL_PIXEL_FORMAT_RGBA_8888)
1898 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRA_8888);
1899 else if (hnd->format == HAL_PIXEL_FORMAT_RGBX_8888)
1900 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRX_8888);
1901 }
1902
Saurabh Shah97e2d802014-04-14 18:03:54 -07001903 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
1904 setMdpFlags(layer, mdpFlags, 0, transform);
Saurabh Shahab47c692014-02-12 18:45:57 -08001905
1906 if(lDest != OV_INVALID && rDest != OV_INVALID) {
1907 //Enable overfetch
Saurabh Shah97e2d802014-04-14 18:03:54 -07001908 setMdpFlags(mdpFlags, OV_MDSS_MDP_DUAL_PIPE);
Saurabh Shahab47c692014-02-12 18:45:57 -08001909 }
1910
1911 if(isYuvBuffer(hnd) && (transform & HWC_TRANSFORM_ROT_90)) {
1912 (*rot) = ctx->mRotMgr->getNext();
1913 if((*rot) == NULL) return -1;
Saurabh Shah39240c92014-03-31 10:31:42 -07001914 ctx->mLayerRotMap[mDpy]->add(layer, *rot);
Saurabh Shahab47c692014-02-12 18:45:57 -08001915 //Configure rotator for pre-rotation
Saurabh Shah97e2d802014-04-14 18:03:54 -07001916 if(configRotator(*rot, whf, crop, mdpFlags, orient, downscale) < 0) {
Saurabh Shahab47c692014-02-12 18:45:57 -08001917 ALOGE("%s: configRotator failed!", __FUNCTION__);
1918 return -1;
1919 }
Saurabh Shahab47c692014-02-12 18:45:57 -08001920 whf.format = (*rot)->getDstFormat();
1921 updateSource(orient, whf, crop);
1922 rotFlags |= ROT_PREROTATED;
1923 }
1924
1925 //If 2 pipes being used, divide layer into half, crop and dst
1926 hwc_rect_t cropL = crop;
1927 hwc_rect_t cropR = crop;
1928 hwc_rect_t dstL = dst;
1929 hwc_rect_t dstR = dst;
1930 if(lDest != OV_INVALID && rDest != OV_INVALID) {
1931 cropL.right = (crop.right + crop.left) / 2;
1932 cropR.left = cropL.right;
1933 sanitizeSourceCrop(cropL, cropR, hnd);
1934
1935 //Swap crops on H flip since 2 pipes are being used
1936 if((orient & OVERLAY_TRANSFORM_FLIP_H) && (*rot) == NULL) {
1937 hwc_rect_t tmp = cropL;
1938 cropL = cropR;
1939 cropR = tmp;
1940 }
1941
1942 dstL.right = (dst.right + dst.left) / 2;
1943 dstR.left = dstL.right;
1944 }
1945
1946 //For the mdp, since either we are pre-rotating or MDP does flips
1947 orient = OVERLAY_TRANSFORM_0;
1948 transform = 0;
1949
1950 //configure left pipe
1951 if(lDest != OV_INVALID) {
Saurabh Shah97e2d802014-04-14 18:03:54 -07001952 PipeArgs pargL(mdpFlags, whf, z, isFg,
Saurabh Shahab47c692014-02-12 18:45:57 -08001953 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
1954 (ovutils::eBlending) getBlending(layer->blending));
1955
1956 if(configMdp(ctx->mOverlay, pargL, orient,
1957 cropL, dstL, metadata, lDest) < 0) {
1958 ALOGE("%s: commit failed for left mixer config", __FUNCTION__);
1959 return -1;
1960 }
1961 }
1962
1963 //configure right pipe
1964 if(rDest != OV_INVALID) {
Saurabh Shah97e2d802014-04-14 18:03:54 -07001965 PipeArgs pargR(mdpFlags, whf, z, isFg,
Saurabh Shahab47c692014-02-12 18:45:57 -08001966 static_cast<eRotFlags>(rotFlags),
1967 layer->planeAlpha,
1968 (ovutils::eBlending) getBlending(layer->blending));
1969 if(configMdp(ctx->mOverlay, pargR, orient,
1970 cropR, dstR, metadata, rDest) < 0) {
1971 ALOGE("%s: commit failed for right mixer config", __FUNCTION__);
1972 return -1;
1973 }
1974 }
1975
1976 return 0;
1977}
1978
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001979}; //namespace
1980