blob: 581f57c570963c1f839099bead578d9ee2c25e33 [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
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800482bool MDPComp::canDoPartialUpdate(hwc_context_t *ctx,
483 hwc_display_contents_1_t* list){
484 if(!qdutils::MDPVersion::getInstance().isPartialUpdateEnabled() || mDpy ||
485 isSkipPresent(ctx, mDpy) || (list->flags & HWC_GEOMETRY_CHANGED)||
486 isDisplaySplit(ctx, mDpy)) {
487 return false;
488 }
489 return true;
490}
491
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700492void MDPComp::generateROI(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
493 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
494
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800495 if(!canDoPartialUpdate(ctx, list))
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700496 return;
497
498 struct hwc_rect roi = (struct hwc_rect){0, 0, 0, 0};
499 for(int index = 0; index < numAppLayers; index++ ) {
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800500 hwc_layer_1_t* layer = &list->hwLayers[index];
501 if ((mCachedFrame.hnd[index] != layer->handle) ||
502 isYuvBuffer((private_handle_t *)layer->handle)) {
503 hwc_rect_t updatingRect = layer->displayFrame;
504#ifdef QCOM_BSP
505 if(!needsScaling(layer))
506 updatingRect = layer->dirtyRect;
507#endif
508 roi = getUnion(roi, updatingRect);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700509 }
510 }
511
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800512 hwc_rect fullFrame = (struct hwc_rect) {0, 0,(int)ctx->dpyAttr[mDpy].xres,
513 (int)ctx->dpyAttr[mDpy].yres};
514
515 // Align ROI coordinates to panel restrictions
516 roi = sanitizeROI(roi, fullFrame);
517
518 if(!validateAndApplyROI(ctx, list, roi))
519 roi = fullFrame;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700520
521 ctx->listStats[mDpy].roi.x = roi.left;
522 ctx->listStats[mDpy].roi.y = roi.top;
523 ctx->listStats[mDpy].roi.w = roi.right - roi.left;
524 ctx->listStats[mDpy].roi.h = roi.bottom - roi.top;
525
526 ALOGD_IF(isDebug(),"%s: generated ROI: [%d, %d, %d, %d]", __FUNCTION__,
527 roi.left, roi.top, roi.right, roi.bottom);
528}
529
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800530/* Checks for conditions where all the layers marked for MDP comp cannot be
531 * bypassed. On such conditions we try to bypass atleast YUV layers */
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800532bool MDPComp::tryFullFrame(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800533 hwc_display_contents_1_t* list){
534
Saurabh Shahaa236822013-04-24 18:07:26 -0700535 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Arun Kumar K.R2e2871c2014-01-10 12:47:06 -0800536 int priDispW = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800537
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -0700538 if(sIdleFallBack && !ctx->listStats[mDpy].secureUI) {
Saurabh Shah2d998a92013-05-14 17:55:58 -0700539 ALOGD_IF(isDebug(), "%s: Idle fallback dpy %d",__FUNCTION__, mDpy);
540 return false;
541 }
542
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800543 if(isSkipPresent(ctx, mDpy)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700544 ALOGD_IF(isDebug(),"%s: SKIP present: %d",
545 __FUNCTION__,
546 isSkipPresent(ctx, mDpy));
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800547 return false;
548 }
549
Arun Kumar K.R2e2871c2014-01-10 12:47:06 -0800550 if(mDpy > HWC_DISPLAY_PRIMARY && (priDispW > MAX_DISPLAY_DIM) &&
551 (ctx->dpyAttr[mDpy].xres < MAX_DISPLAY_DIM)) {
552 // Disable MDP comp on Secondary when the primary is highres panel and
553 // the secondary is a normal 1080p, because, MDP comp on secondary under
554 // in such usecase, decimation gets used for downscale and there will be
555 // a quality mismatch when there will be a fallback to GPU comp
556 ALOGD_IF(isDebug(), "%s: Disable MDP Compositon for Secondary Disp",
557 __FUNCTION__);
558 return false;
559 }
560
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800561 // check for action safe flag and downscale mode which requires scaling.
562 if(ctx->dpyAttr[mDpy].mActionSafePresent
563 || ctx->dpyAttr[mDpy].mDownScaleMode) {
564 ALOGD_IF(isDebug(), "%s: Scaling needed for this frame",__FUNCTION__);
565 return false;
566 }
567
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800568 for(int i = 0; i < numAppLayers; ++i) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800569 hwc_layer_1_t* layer = &list->hwLayers[i];
570 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800571
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700572 if(isYuvBuffer(hnd) && has90Transform(layer)) {
573 if(!canUseRotator(ctx, mDpy)) {
574 ALOGD_IF(isDebug(), "%s: Can't use rotator for dpy %d",
575 __FUNCTION__, mDpy);
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700576 return false;
577 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800578 }
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530579
580 //For 8x26 with panel width>1k, if RGB layer needs HFLIP fail mdp comp
581 // may not need it if Gfx pre-rotation can handle all flips & rotations
Sushil Chauhanfda00fc2014-03-20 11:08:41 -0700582 int transform = (layer->flags & HWC_COLOR_FILL) ? 0 : layer->transform;
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530583 if(qdutils::MDPVersion::getInstance().is8x26() &&
584 (ctx->dpyAttr[mDpy].xres > 1024) &&
Sushil Chauhanfda00fc2014-03-20 11:08:41 -0700585 (transform & HWC_TRANSFORM_FLIP_H) &&
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530586 (!isYuvBuffer(hnd)))
587 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800588 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700589
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700590 if(ctx->mAD->isDoable()) {
591 return false;
592 }
593
Saurabh Shahaa236822013-04-24 18:07:26 -0700594 //If all above hard conditions are met we can do full or partial MDP comp.
595 bool ret = false;
596 if(fullMDPComp(ctx, list)) {
597 ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700598 } else if(partialMDPComp(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700599 ret = true;
600 }
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530601
Saurabh Shahaa236822013-04-24 18:07:26 -0700602 return ret;
603}
604
605bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700606 //Will benefit presentation / secondary-only layer.
607 if((mDpy > HWC_DISPLAY_PRIMARY) &&
608 (list->numHwLayers - 1) > MAX_SEC_LAYERS) {
609 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
610 return false;
611 }
612
613 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
614 for(int i = 0; i < numAppLayers; i++) {
615 hwc_layer_1_t* layer = &list->hwLayers[i];
616 if(not isSupportedForMDPComp(ctx, layer)) {
617 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",__FUNCTION__);
618 return false;
619 }
620 }
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800621
Saurabh Shahaa236822013-04-24 18:07:26 -0700622 mCurrentFrame.fbCount = 0;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700623 memcpy(&mCurrentFrame.isFBComposed, &mCurrentFrame.drop,
624 sizeof(mCurrentFrame.isFBComposed));
625 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount -
626 mCurrentFrame.dropCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700627
radhakrishnac9a67412013-09-25 17:40:42 +0530628 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800629 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530630 }
631
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800632 if(!postHeuristicsHandling(ctx, list)) {
633 ALOGD_IF(isDebug(), "post heuristic handling failed");
634 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700635 return false;
636 }
637
Saurabh Shahaa236822013-04-24 18:07:26 -0700638 return true;
639}
640
641bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
642{
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700643 if(!sEnableMixedMode) {
644 //Mixed mode is disabled. No need to even try caching.
645 return false;
646 }
647
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700648 bool ret = false;
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800649 if(list->flags & HWC_GEOMETRY_CHANGED) { //Try load based first
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800650 ret = loadBasedComp(ctx, list) or
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800651 cacheBasedComp(ctx, list);
652 } else {
653 ret = cacheBasedComp(ctx, list) or
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800654 loadBasedComp(ctx, list);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700655 }
656
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700657 return ret;
658}
659
660bool MDPComp::cacheBasedComp(hwc_context_t *ctx,
661 hwc_display_contents_1_t* list) {
662 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700663 mCurrentFrame.reset(numAppLayers);
664 updateLayerCache(ctx, list);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700665
666 //If an MDP marked layer is unsupported cannot do partial MDP Comp
667 for(int i = 0; i < numAppLayers; i++) {
668 if(!mCurrentFrame.isFBComposed[i]) {
669 hwc_layer_1_t* layer = &list->hwLayers[i];
670 if(not isSupportedForMDPComp(ctx, layer)) {
671 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",
672 __FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800673 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700674 return false;
675 }
676 }
677 }
678
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700679 updateYUV(ctx, list, false /*secure only*/);
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530680 bool ret = markLayersForCaching(ctx, list); //sets up fbZ also
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700681 if(!ret) {
682 ALOGD_IF(isDebug(),"%s: batching failed, dpy %d",__FUNCTION__, mDpy);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800683 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700684 return false;
685 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700686
687 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700688
radhakrishnac9a67412013-09-25 17:40:42 +0530689 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800690 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530691 }
692
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700693 //Will benefit cases where a video has non-updating background.
694 if((mDpy > HWC_DISPLAY_PRIMARY) and
695 (mdpCount > MAX_SEC_LAYERS)) {
696 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800697 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700698 return false;
699 }
700
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800701 if(!postHeuristicsHandling(ctx, list)) {
702 ALOGD_IF(isDebug(), "post heuristic handling failed");
703 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700704 return false;
705 }
706
Saurabh Shahaa236822013-04-24 18:07:26 -0700707 return true;
708}
709
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800710bool MDPComp::loadBasedComp(hwc_context_t *ctx,
Saurabh Shahb772ae32013-11-18 15:40:02 -0800711 hwc_display_contents_1_t* list) {
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -0800712 if(not isLoadBasedCompDoable(ctx)) {
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800713 return false;
714 }
715
Saurabh Shahb772ae32013-11-18 15:40:02 -0800716 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800717 const int numNonDroppedLayers = numAppLayers - mCurrentFrame.dropCount;
718 const int stagesForMDP = min(sMaxPipesPerMixer,
719 ctx->mOverlay->availablePipes(mDpy, Overlay::MIXER_DEFAULT));
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800720
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800721 int mdpBatchSize = stagesForMDP - 1; //1 stage for FB
722 int fbBatchSize = numNonDroppedLayers - mdpBatchSize;
723 int lastMDPSupportedIndex = numAppLayers;
724 int dropCount = 0;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800725
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800726 //Find the minimum MDP batch size
727 for(int i = 0; i < numAppLayers;i++) {
728 if(mCurrentFrame.drop[i]) {
729 dropCount++;
Jeykumar Sankaran846e2792014-01-23 21:59:58 -0800730 continue;
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800731 }
732 hwc_layer_1_t* layer = &list->hwLayers[i];
733 if(not isSupportedForMDPComp(ctx, layer)) {
734 lastMDPSupportedIndex = i;
735 mdpBatchSize = min(i - dropCount, stagesForMDP - 1);
736 fbBatchSize = numNonDroppedLayers - mdpBatchSize;
Jeykumar Sankaran846e2792014-01-23 21:59:58 -0800737 break;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800738 }
Saurabh Shahb772ae32013-11-18 15:40:02 -0800739 }
740
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800741 ALOGD_IF(isDebug(), "%s:Before optimizing fbBatch, mdpbatch %d, fbbatch %d "
742 "dropped %d", __FUNCTION__, mdpBatchSize, fbBatchSize,
743 mCurrentFrame.dropCount);
744
745 //Start at a point where the fb batch should at least have 2 layers, for
746 //this mode to be justified.
747 while(fbBatchSize < 2) {
748 ++fbBatchSize;
749 --mdpBatchSize;
Jeykumar Sankaran846e2792014-01-23 21:59:58 -0800750 }
Saurabh Shahb772ae32013-11-18 15:40:02 -0800751
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800752 //If there are no layers for MDP, this mode doesnt make sense.
753 if(mdpBatchSize < 1) {
754 ALOGD_IF(isDebug(), "%s: No MDP layers after optimizing for fbBatch",
755 __FUNCTION__);
Saurabh Shahb772ae32013-11-18 15:40:02 -0800756 return false;
757 }
758
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800759 mCurrentFrame.reset(numAppLayers);
760
761 //Try with successively smaller mdp batch sizes until we succeed or reach 1
762 while(mdpBatchSize > 0) {
763 //Mark layers for MDP comp
764 int mdpBatchLeft = mdpBatchSize;
765 for(int i = 0; i < lastMDPSupportedIndex and mdpBatchLeft; i++) {
766 if(mCurrentFrame.drop[i]) {
767 continue;
768 }
769 mCurrentFrame.isFBComposed[i] = false;
770 --mdpBatchLeft;
771 }
772
773 mCurrentFrame.fbZ = mdpBatchSize;
774 mCurrentFrame.fbCount = fbBatchSize;
775 mCurrentFrame.mdpCount = mdpBatchSize;
776
777 ALOGD_IF(isDebug(), "%s:Trying with: mdpbatch %d fbbatch %d dropped %d",
778 __FUNCTION__, mdpBatchSize, fbBatchSize,
779 mCurrentFrame.dropCount);
780
781 if(postHeuristicsHandling(ctx, list)) {
782 ALOGD_IF(isDebug(), "%s: Postheuristics handling succeeded",
783 __FUNCTION__);
784 return true;
785 }
786
787 reset(ctx);
788 --mdpBatchSize;
789 ++fbBatchSize;
790 }
791
792 return false;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800793}
794
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -0800795bool MDPComp::isLoadBasedCompDoable(hwc_context_t *ctx) {
Prabhanjan Kandula3dbbd882013-12-11 14:43:46 +0530796 if(mDpy or isSecurePresent(ctx, mDpy) or
797 isYuvPresent(ctx, mDpy)) {
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700798 return false;
799 }
800 return true;
801}
802
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800803bool MDPComp::tryVideoOnly(hwc_context_t *ctx,
804 hwc_display_contents_1_t* list) {
805 const bool secureOnly = true;
806 return videoOnlyComp(ctx, list, not secureOnly) or
807 videoOnlyComp(ctx, list, secureOnly);
808}
809
810bool MDPComp::videoOnlyComp(hwc_context_t *ctx,
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700811 hwc_display_contents_1_t* list, bool secureOnly) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700812 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700813
Saurabh Shahaa236822013-04-24 18:07:26 -0700814 mCurrentFrame.reset(numAppLayers);
Jeykumar Sankaraneb3a5e22014-04-08 16:07:55 -0700815 mCurrentFrame.fbCount -= mCurrentFrame.dropCount;
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700816 updateYUV(ctx, list, secureOnly);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700817 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700818
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800819 if(!isYuvPresent(ctx, mDpy) or (mdpCount == 0)) {
820 reset(ctx);
Saurabh Shahaa236822013-04-24 18:07:26 -0700821 return false;
822 }
823
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -0800824 /* Bail out if we are processing only secured video layers
825 * and we dont have any */
826 if(!isSecurePresent(ctx, mDpy) && secureOnly){
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800827 reset(ctx);
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -0800828 return false;
829 }
830
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800831 if(mCurrentFrame.fbCount)
832 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
Saurabh Shah4fdde762013-04-30 18:47:33 -0700833
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800834 if(sEnable4k2kYUVSplit){
835 adjustForSourceSplit(ctx, list);
836 }
837
838 if(!postHeuristicsHandling(ctx, list)) {
839 ALOGD_IF(isDebug(), "post heuristic handling failed");
840 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700841 return false;
842 }
843
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800844 return true;
845}
846
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800847/* Checks for conditions where YUV layers cannot be bypassed */
848bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -0700849 if(isSkipLayer(layer)) {
Saurabh Shahe2474082013-05-15 16:32:13 -0700850 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800851 return false;
852 }
853
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700854 if(layer->transform & HWC_TRANSFORM_ROT_90 && !canUseRotator(ctx,mDpy)) {
855 ALOGD_IF(isDebug(), "%s: no free DMA pipe",__FUNCTION__);
856 return false;
857 }
858
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800859 if(isSecuring(ctx, layer)) {
860 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
861 return false;
862 }
863
Saurabh Shah4fdde762013-04-30 18:47:33 -0700864 if(!isValidDimension(ctx, layer)) {
865 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
866 __FUNCTION__);
867 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800868 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700869
Naseer Ahmeddc61a972013-07-10 17:50:54 -0400870 if(layer->planeAlpha < 0xFF) {
871 ALOGD_IF(isDebug(), "%s: Cannot handle YUV layer with plane alpha\
872 in video only mode",
873 __FUNCTION__);
874 return false;
875 }
876
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800877 return true;
878}
879
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530880/* starts at fromIndex and check for each layer to find
881 * if it it has overlapping with any Updating layer above it in zorder
882 * till the end of the batch. returns true if it finds any intersection */
883bool MDPComp::canPushBatchToTop(const hwc_display_contents_1_t* list,
884 int fromIndex, int toIndex) {
885 for(int i = fromIndex; i < toIndex; i++) {
886 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
887 if(intersectingUpdatingLayers(list, i+1, toIndex, i)) {
888 return false;
889 }
890 }
891 }
892 return true;
893}
894
895/* Checks if given layer at targetLayerIndex has any
896 * intersection with all the updating layers in beween
897 * fromIndex and toIndex. Returns true if it finds intersectiion */
898bool MDPComp::intersectingUpdatingLayers(const hwc_display_contents_1_t* list,
899 int fromIndex, int toIndex, int targetLayerIndex) {
900 for(int i = fromIndex; i <= toIndex; i++) {
901 if(!mCurrentFrame.isFBComposed[i]) {
902 if(areLayersIntersecting(&list->hwLayers[i],
903 &list->hwLayers[targetLayerIndex])) {
904 return true;
905 }
906 }
907 }
908 return false;
909}
910
911int MDPComp::getBatch(hwc_display_contents_1_t* list,
912 int& maxBatchStart, int& maxBatchEnd,
913 int& maxBatchCount) {
914 int i = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530915 int fbZOrder =-1;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -0800916 int droppedLayerCt = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530917 while (i < mCurrentFrame.layerCount) {
918 int batchCount = 0;
919 int batchStart = i;
920 int batchEnd = i;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -0800921 /* Adjust batch Z order with the dropped layers so far */
922 int fbZ = batchStart - droppedLayerCt;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530923 int firstZReverseIndex = -1;
Prabhanjan Kandula0ed2cc92013-12-06 12:39:04 +0530924 int updatingLayersAbove = 0;//Updating layer count in middle of batch
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530925 while(i < mCurrentFrame.layerCount) {
926 if(!mCurrentFrame.isFBComposed[i]) {
927 if(!batchCount) {
928 i++;
929 break;
930 }
931 updatingLayersAbove++;
932 i++;
933 continue;
934 } else {
935 if(mCurrentFrame.drop[i]) {
936 i++;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -0800937 droppedLayerCt++;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530938 continue;
939 } else if(updatingLayersAbove <= 0) {
940 batchCount++;
941 batchEnd = i;
942 i++;
943 continue;
944 } else { //Layer is FBComposed, not a drop & updatingLayer > 0
945
946 // We have a valid updating layer already. If layer-i not
947 // have overlapping with all updating layers in between
948 // batch-start and i, then we can add layer i to batch.
949 if(!intersectingUpdatingLayers(list, batchStart, i-1, i)) {
950 batchCount++;
951 batchEnd = i;
952 i++;
953 continue;
954 } else if(canPushBatchToTop(list, batchStart, i)) {
955 //If All the non-updating layers with in this batch
956 //does not have intersection with the updating layers
957 //above in z-order, then we can safely move the batch to
958 //higher z-order. Increment fbZ as it is moving up.
959 if( firstZReverseIndex < 0) {
960 firstZReverseIndex = i;
961 }
962 batchCount++;
963 batchEnd = i;
964 fbZ += updatingLayersAbove;
965 i++;
966 updatingLayersAbove = 0;
967 continue;
968 } else {
969 //both failed.start the loop again from here.
970 if(firstZReverseIndex >= 0) {
971 i = firstZReverseIndex;
972 }
973 break;
974 }
975 }
976 }
977 }
978 if(batchCount > maxBatchCount) {
979 maxBatchCount = batchCount;
980 maxBatchStart = batchStart;
981 maxBatchEnd = batchEnd;
982 fbZOrder = fbZ;
983 }
984 }
985 return fbZOrder;
986}
987
988bool MDPComp::markLayersForCaching(hwc_context_t* ctx,
989 hwc_display_contents_1_t* list) {
990 /* Idea is to keep as many non-updating(cached) layers in FB and
991 * send rest of them through MDP. This is done in 2 steps.
992 * 1. Find the maximum contiguous batch of non-updating layers.
993 * 2. See if we can improve this batch size for caching by adding
994 * opaque layers around the batch, if they don't have
995 * any overlapping with the updating layers in between.
996 * NEVER mark an updating layer for caching.
997 * But cached ones can be marked for MDP */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800998
999 int maxBatchStart = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001000 int maxBatchEnd = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001001 int maxBatchCount = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301002 int fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001003
Saurabh Shahd53bc5f2014-02-05 10:17:43 -08001004 /* Nothing is cached. No batching needed */
1005 if(mCurrentFrame.fbCount == 0) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001006 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -07001007 }
Saurabh Shahd53bc5f2014-02-05 10:17:43 -08001008
1009 /* No MDP comp layers, try to use other comp modes */
1010 if(mCurrentFrame.mdpCount == 0) {
1011 return false;
Saurabh Shahaa236822013-04-24 18:07:26 -07001012 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001013
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301014 fbZ = getBatch(list, maxBatchStart, maxBatchEnd, maxBatchCount);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001015
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301016 /* reset rest of the layers lying inside ROI for MDP comp */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001017 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001018 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001019 if((i < maxBatchStart || i > maxBatchEnd) &&
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301020 mCurrentFrame.isFBComposed[i]){
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001021 if(!mCurrentFrame.drop[i]){
1022 //If an unsupported layer is being attempted to
1023 //be pulled out we should fail
1024 if(not isSupportedForMDPComp(ctx, layer)) {
1025 return false;
1026 }
1027 mCurrentFrame.isFBComposed[i] = false;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001028 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001029 }
1030 }
1031
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301032 // update the frame data
1033 mCurrentFrame.fbZ = fbZ;
1034 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001035 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001036 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001037
1038 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301039 mCurrentFrame.fbCount);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001040
1041 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001042}
Saurabh Shah85234ec2013-04-12 17:09:00 -07001043
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001044void MDPComp::updateLayerCache(hwc_context_t* ctx,
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001045 hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001046 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001047 int fbCount = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001048
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001049 for(int i = 0; i < numAppLayers; i++) {
1050 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001051 if(!mCurrentFrame.drop[i])
1052 fbCount++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001053 mCurrentFrame.isFBComposed[i] = true;
1054 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -07001055 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001056 }
1057 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001058
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001059 mCurrentFrame.fbCount = fbCount;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001060 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount
1061 - mCurrentFrame.dropCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001062
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001063 ALOGD_IF(isDebug(),"%s: MDP count: %d FB count %d drop count: %d"
1064 ,__FUNCTION__, mCurrentFrame.mdpCount, mCurrentFrame.fbCount,
1065 mCurrentFrame.dropCount);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001066}
1067
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001068void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list,
1069 bool secureOnly) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001070 int nYuvCount = ctx->listStats[mDpy].yuvCount;
1071 for(int index = 0;index < nYuvCount; index++){
1072 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
1073 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
1074
1075 if(!isYUVDoable(ctx, layer)) {
1076 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
1077 mCurrentFrame.isFBComposed[nYuvIndex] = true;
1078 mCurrentFrame.fbCount++;
1079 }
1080 } else {
1081 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001082 private_handle_t *hnd = (private_handle_t *)layer->handle;
1083 if(!secureOnly || isSecureBuffer(hnd)) {
1084 mCurrentFrame.isFBComposed[nYuvIndex] = false;
1085 mCurrentFrame.fbCount--;
1086 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001087 }
1088 }
1089 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001090
1091 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001092 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
1093 ALOGD_IF(isDebug(),"%s: fb count: %d",__FUNCTION__,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001094 mCurrentFrame.fbCount);
1095}
1096
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301097hwc_rect_t MDPComp::getUpdatingFBRect(hwc_display_contents_1_t* list){
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001098 hwc_rect_t fbRect = (struct hwc_rect){0, 0, 0, 0};
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001099
1100 /* Update only the region of FB needed for composition */
1101 for(int i = 0; i < mCurrentFrame.layerCount; i++ ) {
1102 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
1103 hwc_layer_1_t* layer = &list->hwLayers[i];
1104 hwc_rect_t dst = layer->displayFrame;
1105 fbRect = getUnion(fbRect, dst);
1106 }
1107 }
1108 return fbRect;
1109}
1110
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001111bool MDPComp::postHeuristicsHandling(hwc_context_t *ctx,
1112 hwc_display_contents_1_t* list) {
1113
1114 //Capability checks
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301115 if(!resourceCheck()) {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001116 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
1117 return false;
1118 }
1119
1120 //Limitations checks
1121 if(!hwLimitationsCheck(ctx, list)) {
1122 ALOGD_IF(isDebug(), "%s: HW limitations",__FUNCTION__);
1123 return false;
1124 }
1125
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001126 //Configure framebuffer first if applicable
1127 if(mCurrentFrame.fbZ >= 0) {
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301128 hwc_rect_t fbRect = getUpdatingFBRect(list);
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001129 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, fbRect, mCurrentFrame.fbZ))
1130 {
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001131 ALOGD_IF(isDebug(), "%s configure framebuffer failed",
1132 __FUNCTION__);
1133 return false;
1134 }
1135 }
1136
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001137 mCurrentFrame.map();
1138
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001139 if(!allocLayerPipes(ctx, list)) {
1140 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -07001141 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001142 }
1143
1144 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001145 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001146 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001147 int mdpIndex = mCurrentFrame.layerToMDP[index];
1148 hwc_layer_1_t* layer = &list->hwLayers[index];
1149
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301150 //Leave fbZ for framebuffer. CACHE/GLES layers go here.
1151 if(mdpNextZOrder == mCurrentFrame.fbZ) {
1152 mdpNextZOrder++;
1153 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001154 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1155 cur_pipe->zOrder = mdpNextZOrder++;
1156
radhakrishnac9a67412013-09-25 17:40:42 +05301157 private_handle_t *hnd = (private_handle_t *)layer->handle;
1158 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1159 if(configure4k2kYuv(ctx, layer,
1160 mCurrentFrame.mdpToLayer[mdpIndex])
1161 != 0 ){
1162 ALOGD_IF(isDebug(), "%s: Failed to configure split pipes \
1163 for layer %d",__FUNCTION__, index);
1164 return false;
1165 }
1166 else{
1167 mdpNextZOrder++;
1168 }
1169 continue;
1170 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001171 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
1172 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
radhakrishnac9a67412013-09-25 17:40:42 +05301173 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -07001174 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001175 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001176 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001177 }
1178
Saurabh Shaha36be922013-12-16 18:18:39 -08001179 if(!ctx->mOverlay->validateAndSet(mDpy, ctx->dpyAttr[mDpy].fd)) {
1180 ALOGD_IF(isDebug(), "%s: Failed to validate and set overlay for dpy %d"
1181 ,__FUNCTION__, mDpy);
1182 return false;
1183 }
1184
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001185 setRedraw(ctx, list);
Saurabh Shahaa236822013-04-24 18:07:26 -07001186 return true;
1187}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001188
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301189bool MDPComp::resourceCheck() {
Saurabh Shah173f4242013-11-20 09:50:12 -08001190 const bool fbUsed = mCurrentFrame.fbCount;
1191 if(mCurrentFrame.mdpCount > sMaxPipesPerMixer - fbUsed) {
1192 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
1193 return false;
1194 }
Saurabh Shah173f4242013-11-20 09:50:12 -08001195 return true;
1196}
1197
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301198bool MDPComp::hwLimitationsCheck(hwc_context_t* ctx,
1199 hwc_display_contents_1_t* list) {
1200
1201 //A-family hw limitation:
1202 //If a layer need alpha scaling, MDP can not support.
1203 if(ctx->mMDP.version < qdutils::MDSS_V5) {
1204 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1205 if(!mCurrentFrame.isFBComposed[i] &&
1206 isAlphaScaled( &list->hwLayers[i])) {
1207 ALOGD_IF(isDebug(), "%s:frame needs alphaScaling",__FUNCTION__);
1208 return false;
1209 }
1210 }
1211 }
1212
1213 // On 8x26 & 8974 hw, we have a limitation of downscaling+blending.
1214 //If multiple layers requires downscaling and also they are overlapping
1215 //fall back to GPU since MDSS can not handle it.
1216 if(qdutils::MDPVersion::getInstance().is8x74v2() ||
1217 qdutils::MDPVersion::getInstance().is8x26()) {
1218 for(int i = 0; i < mCurrentFrame.layerCount-1; ++i) {
1219 hwc_layer_1_t* botLayer = &list->hwLayers[i];
1220 if(!mCurrentFrame.isFBComposed[i] &&
1221 isDownscaleRequired(botLayer)) {
1222 //if layer-i is marked for MDP and needs downscaling
1223 //check if any MDP layer on top of i & overlaps with layer-i
1224 for(int j = i+1; j < mCurrentFrame.layerCount; ++j) {
1225 hwc_layer_1_t* topLayer = &list->hwLayers[j];
1226 if(!mCurrentFrame.isFBComposed[j] &&
1227 isDownscaleRequired(topLayer)) {
1228 hwc_rect_t r = getIntersection(botLayer->displayFrame,
1229 topLayer->displayFrame);
1230 if(isValidRect(r))
1231 return false;
1232 }
1233 }
1234 }
1235 }
1236 }
1237 return true;
1238}
1239
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001240int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001241 int ret = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -07001242 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -07001243
Raj Kamal9ed3d6b2014-02-07 16:15:17 +05301244 //Do not cache the information for next draw cycle.
1245 if(numLayers > MAX_NUM_APP_LAYERS or (!numLayers)) {
1246 ALOGI("%s: Unsupported layer count for mdp composition",
1247 __FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001248 mCachedFrame.reset();
1249 return -1;
1250 }
1251
Saurabh Shahb39f8152013-08-22 10:21:44 -07001252 //reset old data
1253 mCurrentFrame.reset(numLayers);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001254 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1255 mCurrentFrame.dropCount = 0;
Prabhanjan Kandula088bd892013-07-02 23:47:13 +05301256
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -07001257 // Detect the start of animation and fall back to GPU only once to cache
1258 // all the layers in FB and display FB content untill animation completes.
1259 if(ctx->listStats[mDpy].isDisplayAnimating) {
1260 mCurrentFrame.needsRedraw = false;
1261 if(ctx->mAnimationState[mDpy] == ANIMATION_STOPPED) {
1262 mCurrentFrame.needsRedraw = true;
1263 ctx->mAnimationState[mDpy] = ANIMATION_STARTED;
1264 }
1265 setMDPCompLayerFlags(ctx, list);
1266 mCachedFrame.updateCounts(mCurrentFrame);
1267 ret = -1;
1268 return ret;
1269 } else {
1270 ctx->mAnimationState[mDpy] = ANIMATION_STOPPED;
1271 }
1272
Saurabh Shahb39f8152013-08-22 10:21:44 -07001273 //Hard conditions, if not met, cannot do MDP comp
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001274 if(isFrameDoable(ctx)) {
1275 generateROI(ctx, list);
Saurabh Shahb39f8152013-08-22 10:21:44 -07001276
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001277 if(tryFullFrame(ctx, list) || tryVideoOnly(ctx, list)) {
1278 setMDPCompLayerFlags(ctx, list);
1279 } else {
1280 reset(ctx);
1281 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1282 mCurrentFrame.dropCount = 0;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001283 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001284 }
1285 } else {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001286 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
1287 __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001288 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001289 }
Saurabh Shahb39f8152013-08-22 10:21:44 -07001290
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001291 if(isDebug()) {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001292 ALOGD("GEOMETRY change: %d",
1293 (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001294 android::String8 sDump("");
1295 dump(sDump);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001296 ALOGD("%s",sDump.string());
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001297 }
1298
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001299 mCachedFrame.cacheAll(list);
1300 mCachedFrame.updateCounts(mCurrentFrame);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001301 return ret;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001302}
1303
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001304bool MDPComp::allocSplitVGPipesfor4k2k(hwc_context_t *ctx, int index) {
radhakrishnac9a67412013-09-25 17:40:42 +05301305
1306 bool bRet = true;
radhakrishnac9a67412013-09-25 17:40:42 +05301307 int mdpIndex = mCurrentFrame.layerToMDP[index];
1308 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
1309 info.pipeInfo = new MdpYUVPipeInfo;
1310 info.rot = NULL;
1311 MdpYUVPipeInfo& pipe_info = *(MdpYUVPipeInfo*)info.pipeInfo;
radhakrishnac9a67412013-09-25 17:40:42 +05301312
1313 pipe_info.lIndex = ovutils::OV_INVALID;
1314 pipe_info.rIndex = ovutils::OV_INVALID;
1315
Saurabh Shahc62f3982014-03-05 14:28:26 -08001316 Overlay::PipeSpecs pipeSpecs;
1317 pipeSpecs.formatClass = Overlay::FORMAT_YUV;
1318 pipeSpecs.needsScaling = true;
1319 pipeSpecs.dpy = mDpy;
1320 pipeSpecs.fb = false;
1321
1322 pipe_info.lIndex = ctx->mOverlay->getPipe(pipeSpecs);
radhakrishnac9a67412013-09-25 17:40:42 +05301323 if(pipe_info.lIndex == ovutils::OV_INVALID){
1324 bRet = false;
1325 ALOGD_IF(isDebug(),"%s: allocating first VG pipe failed",
1326 __FUNCTION__);
1327 }
Saurabh Shahc62f3982014-03-05 14:28:26 -08001328 pipe_info.rIndex = ctx->mOverlay->getPipe(pipeSpecs);
radhakrishnac9a67412013-09-25 17:40:42 +05301329 if(pipe_info.rIndex == ovutils::OV_INVALID){
1330 bRet = false;
1331 ALOGD_IF(isDebug(),"%s: allocating second VG pipe failed",
1332 __FUNCTION__);
1333 }
1334 return bRet;
1335}
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001336//=============MDPCompNonSplit==================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001337
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001338void MDPCompNonSplit::adjustForSourceSplit(hwc_context_t *ctx,
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001339 hwc_display_contents_1_t*) {
radhakrishnac9a67412013-09-25 17:40:42 +05301340 //As we split 4kx2k yuv layer and program to 2 VG pipes
1341 //(if available) increase mdpcount accordingly
1342 mCurrentFrame.mdpCount += ctx->listStats[mDpy].yuv4k2kCount;
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001343
1344 //If 4k2k Yuv layer split is possible, and if
1345 //fbz is above 4k2k layer, increment fb zorder by 1
1346 //as we split 4k2k layer and increment zorder for right half
1347 //of the layer
1348 if(mCurrentFrame.fbZ >= 0) {
1349 int n4k2kYuvCount = ctx->listStats[mDpy].yuv4k2kCount;
1350 for(int index = 0; index < n4k2kYuvCount; index++){
1351 int n4k2kYuvIndex =
1352 ctx->listStats[mDpy].yuv4k2kIndices[index];
Dileep Kumar Reddi4cff9282014-04-01 12:57:08 +05301353 if(mCurrentFrame.fbZ >= n4k2kYuvIndex){
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001354 mCurrentFrame.fbZ += 1;
1355 }
1356 }
1357 }
radhakrishnac9a67412013-09-25 17:40:42 +05301358}
1359
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001360/*
1361 * Configures pipe(s) for MDP composition
1362 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001363int MDPCompNonSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001364 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001365 MdpPipeInfoNonSplit& mdp_info =
1366 *(static_cast<MdpPipeInfoNonSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001367 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
1368 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1369 eIsFg isFg = IS_FG_OFF;
1370 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001371
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001372 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
1373 __FUNCTION__, layer, zOrder, dest);
1374
Saurabh Shah88e4d272013-09-03 13:31:29 -07001375 return configureNonSplit(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001376 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001377}
1378
Saurabh Shah88e4d272013-09-03 13:31:29 -07001379bool MDPCompNonSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001380 hwc_display_contents_1_t* list) {
1381 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001382
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001383 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001384
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001385 hwc_layer_1_t* layer = &list->hwLayers[index];
1386 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301387 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001388 if(allocSplitVGPipesfor4k2k(ctx, index)){
radhakrishnac9a67412013-09-25 17:40:42 +05301389 continue;
1390 }
1391 }
1392
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001393 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001394 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001395 info.pipeInfo = new MdpPipeInfoNonSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08001396 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001397 MdpPipeInfoNonSplit& pipe_info = *(MdpPipeInfoNonSplit*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001398
Saurabh Shahc62f3982014-03-05 14:28:26 -08001399 Overlay::PipeSpecs pipeSpecs;
1400 pipeSpecs.formatClass = isYuvBuffer(hnd) ?
1401 Overlay::FORMAT_YUV : Overlay::FORMAT_RGB;
1402 pipeSpecs.needsScaling = qhwc::needsScaling(layer) or
1403 (qdutils::MDPVersion::getInstance().is8x26() and
1404 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres > 1024);
1405 pipeSpecs.dpy = mDpy;
1406 pipeSpecs.fb = false;
Xu Yang1e686f62014-04-08 13:56:47 +08001407 pipeSpecs.numActiveDisplays = ctx->numActiveDisplays;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001408
Saurabh Shahc62f3982014-03-05 14:28:26 -08001409 pipe_info.index = ctx->mOverlay->getPipe(pipeSpecs);
1410
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001411 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001412 ALOGD_IF(isDebug(), "%s: Unable to get pipe", __FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001413 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001414 }
1415 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001416 return true;
1417}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001418
radhakrishnac9a67412013-09-25 17:40:42 +05301419int MDPCompNonSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1420 PipeLayerPair& PipeLayerPair) {
1421 MdpYUVPipeInfo& mdp_info =
1422 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1423 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1424 eIsFg isFg = IS_FG_OFF;
1425 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1426 eDest lDest = mdp_info.lIndex;
1427 eDest rDest = mdp_info.rIndex;
1428
1429 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1430 lDest, rDest, &PipeLayerPair.rot);
1431}
1432
Saurabh Shah88e4d272013-09-03 13:31:29 -07001433bool MDPCompNonSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001434
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001435 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001436 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1437 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -08001438 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001439
1440 if(!ctx || !list) {
1441 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001442 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001443 }
1444
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301445 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1446 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1447 return true;
1448 }
1449
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -08001450 // Set the Handle timeout to true for MDP or MIXED composition.
1451 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount) {
1452 sHandleTimeout = true;
1453 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001454
1455 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001456 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001457
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001458 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1459 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001460 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001461 if(mCurrentFrame.isFBComposed[i]) continue;
1462
Naseer Ahmed5b6708a2012-08-02 13:46:08 -07001463 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001464 private_handle_t *hnd = (private_handle_t *)layer->handle;
1465 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001466 if (!(layer->flags & HWC_COLOR_FILL)) {
1467 ALOGE("%s handle null", __FUNCTION__);
1468 return false;
1469 }
1470 // No PLAY for Color layer
1471 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1472 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001473 }
1474
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001475 int mdpIndex = mCurrentFrame.layerToMDP[i];
1476
radhakrishnac9a67412013-09-25 17:40:42 +05301477 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1478 {
1479 MdpYUVPipeInfo& pipe_info =
1480 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1481 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1482 ovutils::eDest indexL = pipe_info.lIndex;
1483 ovutils::eDest indexR = pipe_info.rIndex;
1484 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301485 uint32_t offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05301486 if(rot) {
1487 rot->queueBuffer(fd, offset);
1488 fd = rot->getDstMemId();
1489 offset = rot->getDstOffset();
1490 }
1491 if(indexL != ovutils::OV_INVALID) {
1492 ovutils::eDest destL = (ovutils::eDest)indexL;
1493 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1494 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1495 if (!ov.queueBuffer(fd, offset, destL)) {
1496 ALOGE("%s: queueBuffer failed for display:%d",
1497 __FUNCTION__, mDpy);
1498 return false;
1499 }
1500 }
1501
1502 if(indexR != ovutils::OV_INVALID) {
1503 ovutils::eDest destR = (ovutils::eDest)indexR;
1504 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1505 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1506 if (!ov.queueBuffer(fd, offset, destR)) {
1507 ALOGE("%s: queueBuffer failed for display:%d",
1508 __FUNCTION__, mDpy);
1509 return false;
1510 }
1511 }
1512 }
1513 else{
1514 MdpPipeInfoNonSplit& pipe_info =
Saurabh Shah88e4d272013-09-03 13:31:29 -07001515 *(MdpPipeInfoNonSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
radhakrishnac9a67412013-09-25 17:40:42 +05301516 ovutils::eDest dest = pipe_info.index;
1517 if(dest == ovutils::OV_INVALID) {
1518 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001519 return false;
radhakrishnac9a67412013-09-25 17:40:42 +05301520 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001521
radhakrishnac9a67412013-09-25 17:40:42 +05301522 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1523 continue;
1524 }
1525
1526 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1527 using pipe: %d", __FUNCTION__, layer,
1528 hnd, dest );
1529
1530 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301531 uint32_t offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05301532
1533 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1534 if(rot) {
1535 if(!rot->queueBuffer(fd, offset))
1536 return false;
1537 fd = rot->getDstMemId();
1538 offset = rot->getDstOffset();
1539 }
1540
1541 if (!ov.queueBuffer(fd, offset, dest)) {
1542 ALOGE("%s: queueBuffer failed for display:%d ",
1543 __FUNCTION__, mDpy);
1544 return false;
1545 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001546 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001547
1548 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001549 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001550 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001551}
1552
Saurabh Shah88e4d272013-09-03 13:31:29 -07001553//=============MDPCompSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001554
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001555void MDPCompSplit::adjustForSourceSplit(hwc_context_t *ctx,
radhakrishnac9a67412013-09-25 17:40:42 +05301556 hwc_display_contents_1_t* list){
1557 //if 4kx2k yuv layer is totally present in either in left half
1558 //or right half then try splitting the yuv layer to avoid decimation
1559 int n4k2kYuvCount = ctx->listStats[mDpy].yuv4k2kCount;
1560 const int lSplit = getLeftSplit(ctx, mDpy);
1561 for(int index = 0; index < n4k2kYuvCount; index++){
1562 int n4k2kYuvIndex = ctx->listStats[mDpy].yuv4k2kIndices[index];
1563 hwc_layer_1_t* layer = &list->hwLayers[n4k2kYuvIndex];
1564 hwc_rect_t dst = layer->displayFrame;
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001565 if((dst.left > lSplit) || (dst.right < lSplit)) {
radhakrishnac9a67412013-09-25 17:40:42 +05301566 mCurrentFrame.mdpCount += 1;
1567 }
Dileep Kumar Reddi4cff9282014-04-01 12:57:08 +05301568 if(mCurrentFrame.fbZ >= n4k2kYuvIndex){
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001569 mCurrentFrame.fbZ += 1;
1570 }
radhakrishnac9a67412013-09-25 17:40:42 +05301571 }
1572}
1573
Saurabh Shah88e4d272013-09-03 13:31:29 -07001574bool MDPCompSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Saurabh Shahc62f3982014-03-05 14:28:26 -08001575 MdpPipeInfoSplit& pipe_info) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001576
Saurabh Shahc62f3982014-03-05 14:28:26 -08001577 const int lSplit = getLeftSplit(ctx, mDpy);
1578 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001579 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001580 pipe_info.lIndex = ovutils::OV_INVALID;
1581 pipe_info.rIndex = ovutils::OV_INVALID;
1582
Saurabh Shahc62f3982014-03-05 14:28:26 -08001583 Overlay::PipeSpecs pipeSpecs;
1584 pipeSpecs.formatClass = isYuvBuffer(hnd) ?
1585 Overlay::FORMAT_YUV : Overlay::FORMAT_RGB;
1586 pipeSpecs.needsScaling = qhwc::needsScalingWithSplit(ctx, layer, mDpy);
1587 pipeSpecs.dpy = mDpy;
1588 pipeSpecs.mixer = Overlay::MIXER_LEFT;
1589 pipeSpecs.fb = false;
1590
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001591 if (dst.left < lSplit) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001592 pipe_info.lIndex = ctx->mOverlay->getPipe(pipeSpecs);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001593 if(pipe_info.lIndex == ovutils::OV_INVALID)
1594 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001595 }
1596
1597 if(dst.right > lSplit) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001598 pipeSpecs.mixer = Overlay::MIXER_RIGHT;
1599 pipe_info.rIndex = ctx->mOverlay->getPipe(pipeSpecs);
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001600 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001601 return false;
1602 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001603
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001604 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001605}
1606
Saurabh Shah88e4d272013-09-03 13:31:29 -07001607bool MDPCompSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001608 hwc_display_contents_1_t* list) {
1609 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001610
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001611 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001612
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001613 hwc_layer_1_t* layer = &list->hwLayers[index];
1614 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301615 hwc_rect_t dst = layer->displayFrame;
1616 const int lSplit = getLeftSplit(ctx, mDpy);
1617 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1618 if((dst.left > lSplit)||(dst.right < lSplit)){
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001619 if(allocSplitVGPipesfor4k2k(ctx, index)){
radhakrishnac9a67412013-09-25 17:40:42 +05301620 continue;
1621 }
1622 }
1623 }
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001624 int mdpIndex = mCurrentFrame.layerToMDP[index];
1625 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001626 info.pipeInfo = new MdpPipeInfoSplit;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001627 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001628 MdpPipeInfoSplit& pipe_info = *(MdpPipeInfoSplit*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001629
Saurabh Shahc62f3982014-03-05 14:28:26 -08001630 if(!acquireMDPPipes(ctx, layer, pipe_info)) {
1631 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type",
1632 __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001633 return false;
1634 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001635 }
1636 return true;
1637}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001638
radhakrishnac9a67412013-09-25 17:40:42 +05301639int MDPCompSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1640 PipeLayerPair& PipeLayerPair) {
1641 const int lSplit = getLeftSplit(ctx, mDpy);
1642 hwc_rect_t dst = layer->displayFrame;
1643 if((dst.left > lSplit)||(dst.right < lSplit)){
1644 MdpYUVPipeInfo& mdp_info =
1645 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1646 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1647 eIsFg isFg = IS_FG_OFF;
1648 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1649 eDest lDest = mdp_info.lIndex;
1650 eDest rDest = mdp_info.rIndex;
1651
1652 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1653 lDest, rDest, &PipeLayerPair.rot);
1654 }
1655 else{
1656 return configure(ctx, layer, PipeLayerPair);
1657 }
1658}
1659
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001660/*
1661 * Configures pipe(s) for MDP composition
1662 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001663int MDPCompSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001664 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001665 MdpPipeInfoSplit& mdp_info =
1666 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001667 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1668 eIsFg isFg = IS_FG_OFF;
1669 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1670 eDest lDest = mdp_info.lIndex;
1671 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001672
1673 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1674 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1675
Saurabh Shah88e4d272013-09-03 13:31:29 -07001676 return configureSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001677 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001678}
1679
Saurabh Shah88e4d272013-09-03 13:31:29 -07001680bool MDPCompSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001681
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001682 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001683 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1684 return true;
1685 }
1686
1687 if(!ctx || !list) {
1688 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001689 return false;
1690 }
1691
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301692 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1693 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1694 return true;
1695 }
1696
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -08001697 // Set the Handle timeout to true for MDP or MIXED composition.
1698 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount) {
1699 sHandleTimeout = true;
1700 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001701
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001702 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001703 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001704
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001705 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1706 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001707 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001708 if(mCurrentFrame.isFBComposed[i]) continue;
1709
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001710 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001711 private_handle_t *hnd = (private_handle_t *)layer->handle;
1712 if(!hnd) {
1713 ALOGE("%s handle null", __FUNCTION__);
1714 return false;
1715 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001716
1717 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1718 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001719 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001720
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001721 int mdpIndex = mCurrentFrame.layerToMDP[i];
1722
radhakrishnac9a67412013-09-25 17:40:42 +05301723 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1724 {
1725 MdpYUVPipeInfo& pipe_info =
1726 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1727 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1728 ovutils::eDest indexL = pipe_info.lIndex;
1729 ovutils::eDest indexR = pipe_info.rIndex;
1730 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301731 uint32_t offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05301732 if(rot) {
1733 rot->queueBuffer(fd, offset);
1734 fd = rot->getDstMemId();
1735 offset = rot->getDstOffset();
1736 }
1737 if(indexL != ovutils::OV_INVALID) {
1738 ovutils::eDest destL = (ovutils::eDest)indexL;
1739 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1740 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1741 if (!ov.queueBuffer(fd, offset, destL)) {
1742 ALOGE("%s: queueBuffer failed for display:%d",
1743 __FUNCTION__, mDpy);
1744 return false;
1745 }
1746 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001747
radhakrishnac9a67412013-09-25 17:40:42 +05301748 if(indexR != ovutils::OV_INVALID) {
1749 ovutils::eDest destR = (ovutils::eDest)indexR;
1750 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1751 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1752 if (!ov.queueBuffer(fd, offset, destR)) {
1753 ALOGE("%s: queueBuffer failed for display:%d",
1754 __FUNCTION__, mDpy);
1755 return false;
1756 }
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001757 }
1758 }
radhakrishnac9a67412013-09-25 17:40:42 +05301759 else{
1760 MdpPipeInfoSplit& pipe_info =
1761 *(MdpPipeInfoSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1762 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001763
radhakrishnac9a67412013-09-25 17:40:42 +05301764 ovutils::eDest indexL = pipe_info.lIndex;
1765 ovutils::eDest indexR = pipe_info.rIndex;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001766
radhakrishnac9a67412013-09-25 17:40:42 +05301767 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301768 int offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05301769
1770 if(ctx->mAD->isModeOn()) {
1771 if(ctx->mAD->draw(ctx, fd, offset)) {
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001772 fd = ctx->mAD->getDstFd();
1773 offset = ctx->mAD->getDstOffset();
radhakrishnac9a67412013-09-25 17:40:42 +05301774 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001775 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001776
radhakrishnac9a67412013-09-25 17:40:42 +05301777 if(rot) {
1778 rot->queueBuffer(fd, offset);
1779 fd = rot->getDstMemId();
1780 offset = rot->getDstOffset();
1781 }
1782
1783 //************* play left mixer **********
1784 if(indexL != ovutils::OV_INVALID) {
1785 ovutils::eDest destL = (ovutils::eDest)indexL;
1786 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1787 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1788 if (!ov.queueBuffer(fd, offset, destL)) {
1789 ALOGE("%s: queueBuffer failed for left mixer",
1790 __FUNCTION__);
1791 return false;
1792 }
1793 }
1794
1795 //************* play right mixer **********
1796 if(indexR != ovutils::OV_INVALID) {
1797 ovutils::eDest destR = (ovutils::eDest)indexR;
1798 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1799 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1800 if (!ov.queueBuffer(fd, offset, destR)) {
1801 ALOGE("%s: queueBuffer failed for right mixer",
1802 __FUNCTION__);
1803 return false;
1804 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001805 }
1806 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001807
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001808 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1809 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001810
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001811 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001812}
Saurabh Shahab47c692014-02-12 18:45:57 -08001813
1814//================MDPCompSrcSplit==============================================
1815bool MDPCompSrcSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Saurabh Shahc62f3982014-03-05 14:28:26 -08001816 MdpPipeInfoSplit& pipe_info) {
Saurabh Shahab47c692014-02-12 18:45:57 -08001817 private_handle_t *hnd = (private_handle_t *)layer->handle;
1818 hwc_rect_t dst = layer->displayFrame;
1819 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
1820 pipe_info.lIndex = ovutils::OV_INVALID;
1821 pipe_info.rIndex = ovutils::OV_INVALID;
1822
1823 //If 2 pipes are staged on a single stage of a mixer, then the left pipe
1824 //should have a higher priority than the right one. Pipe priorities are
1825 //starting with VG0, VG1 ... , RGB0 ..., DMA1
Saurabh Shahab47c692014-02-12 18:45:57 -08001826
Saurabh Shahc62f3982014-03-05 14:28:26 -08001827 Overlay::PipeSpecs pipeSpecs;
1828 pipeSpecs.formatClass = isYuvBuffer(hnd) ?
1829 Overlay::FORMAT_YUV : Overlay::FORMAT_RGB;
1830 pipeSpecs.needsScaling = qhwc::needsScaling(layer);
1831 pipeSpecs.dpy = mDpy;
1832 pipeSpecs.fb = false;
1833
Saurabh Shahab47c692014-02-12 18:45:57 -08001834 //1 pipe by default for a layer
Saurabh Shahc62f3982014-03-05 14:28:26 -08001835 pipe_info.lIndex = ctx->mOverlay->getPipe(pipeSpecs);
Saurabh Shahab47c692014-02-12 18:45:57 -08001836 if(pipe_info.lIndex == ovutils::OV_INVALID) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001837 return false;
Saurabh Shahab47c692014-02-12 18:45:57 -08001838 }
1839
1840 //If layer's crop width or dest width > 2048, use 2 pipes
1841 if((dst.right - dst.left) > qdutils::MAX_DISPLAY_DIM or
1842 (crop.right - crop.left) > qdutils::MAX_DISPLAY_DIM) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001843 pipe_info.rIndex = ctx->mOverlay->getPipe(pipeSpecs);
Saurabh Shahab47c692014-02-12 18:45:57 -08001844 if(pipe_info.rIndex == ovutils::OV_INVALID) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001845 return false;
Saurabh Shahdd8237a2014-02-28 14:29:09 -08001846 }
1847
1848 // Return values
1849 // 1 Left pipe is higher priority, do nothing.
1850 // 0 Pipes of same priority.
1851 //-1 Right pipe is of higher priority, needs swap.
1852 if(ctx->mOverlay->comparePipePriority(pipe_info.lIndex,
1853 pipe_info.rIndex) == -1) {
1854 qhwc::swap(pipe_info.lIndex, pipe_info.rIndex);
Saurabh Shahab47c692014-02-12 18:45:57 -08001855 }
1856 }
1857
1858 return true;
1859}
1860
Saurabh Shahab47c692014-02-12 18:45:57 -08001861int MDPCompSrcSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
1862 PipeLayerPair& PipeLayerPair) {
1863 private_handle_t *hnd = (private_handle_t *)layer->handle;
1864 if(!hnd) {
1865 ALOGE("%s: layer handle is NULL", __FUNCTION__);
1866 return -1;
1867 }
1868 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
1869 MdpPipeInfoSplit& mdp_info =
1870 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
1871 Rotator **rot = &PipeLayerPair.rot;
1872 eZorder z = static_cast<eZorder>(mdp_info.zOrder);
1873 eIsFg isFg = IS_FG_OFF;
1874 eDest lDest = mdp_info.lIndex;
1875 eDest rDest = mdp_info.rIndex;
1876 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
1877 hwc_rect_t dst = layer->displayFrame;
1878 int transform = layer->transform;
1879 eTransform orient = static_cast<eTransform>(transform);
1880 const int downscale = 0;
1881 int rotFlags = ROT_FLAGS_NONE;
1882 uint32_t format = ovutils::getMdpFormat(hnd->format, isTileRendered(hnd));
1883 Whf whf(getWidth(hnd), getHeight(hnd), format, hnd->size);
1884
1885 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1886 "dest_pipeR: %d",__FUNCTION__, layer, z, lDest, rDest);
1887
1888 // Handle R/B swap
1889 if (layer->flags & HWC_FORMAT_RB_SWAP) {
1890 if (hnd->format == HAL_PIXEL_FORMAT_RGBA_8888)
1891 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRA_8888);
1892 else if (hnd->format == HAL_PIXEL_FORMAT_RGBX_8888)
1893 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRX_8888);
1894 }
1895
Saurabh Shah97e2d802014-04-14 18:03:54 -07001896 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
1897 setMdpFlags(layer, mdpFlags, 0, transform);
Saurabh Shahab47c692014-02-12 18:45:57 -08001898
1899 if(lDest != OV_INVALID && rDest != OV_INVALID) {
1900 //Enable overfetch
Saurabh Shah97e2d802014-04-14 18:03:54 -07001901 setMdpFlags(mdpFlags, OV_MDSS_MDP_DUAL_PIPE);
Saurabh Shahab47c692014-02-12 18:45:57 -08001902 }
1903
1904 if(isYuvBuffer(hnd) && (transform & HWC_TRANSFORM_ROT_90)) {
1905 (*rot) = ctx->mRotMgr->getNext();
1906 if((*rot) == NULL) return -1;
Saurabh Shah39240c92014-03-31 10:31:42 -07001907 ctx->mLayerRotMap[mDpy]->add(layer, *rot);
Saurabh Shahab47c692014-02-12 18:45:57 -08001908 //Configure rotator for pre-rotation
Saurabh Shah97e2d802014-04-14 18:03:54 -07001909 if(configRotator(*rot, whf, crop, mdpFlags, orient, downscale) < 0) {
Saurabh Shahab47c692014-02-12 18:45:57 -08001910 ALOGE("%s: configRotator failed!", __FUNCTION__);
1911 return -1;
1912 }
Saurabh Shahab47c692014-02-12 18:45:57 -08001913 whf.format = (*rot)->getDstFormat();
1914 updateSource(orient, whf, crop);
1915 rotFlags |= ROT_PREROTATED;
1916 }
1917
1918 //If 2 pipes being used, divide layer into half, crop and dst
1919 hwc_rect_t cropL = crop;
1920 hwc_rect_t cropR = crop;
1921 hwc_rect_t dstL = dst;
1922 hwc_rect_t dstR = dst;
1923 if(lDest != OV_INVALID && rDest != OV_INVALID) {
1924 cropL.right = (crop.right + crop.left) / 2;
1925 cropR.left = cropL.right;
1926 sanitizeSourceCrop(cropL, cropR, hnd);
1927
1928 //Swap crops on H flip since 2 pipes are being used
1929 if((orient & OVERLAY_TRANSFORM_FLIP_H) && (*rot) == NULL) {
1930 hwc_rect_t tmp = cropL;
1931 cropL = cropR;
1932 cropR = tmp;
1933 }
1934
1935 dstL.right = (dst.right + dst.left) / 2;
1936 dstR.left = dstL.right;
1937 }
1938
1939 //For the mdp, since either we are pre-rotating or MDP does flips
1940 orient = OVERLAY_TRANSFORM_0;
1941 transform = 0;
1942
1943 //configure left pipe
1944 if(lDest != OV_INVALID) {
Saurabh Shah97e2d802014-04-14 18:03:54 -07001945 PipeArgs pargL(mdpFlags, whf, z, isFg,
Saurabh Shahab47c692014-02-12 18:45:57 -08001946 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
1947 (ovutils::eBlending) getBlending(layer->blending));
1948
1949 if(configMdp(ctx->mOverlay, pargL, orient,
1950 cropL, dstL, metadata, lDest) < 0) {
1951 ALOGE("%s: commit failed for left mixer config", __FUNCTION__);
1952 return -1;
1953 }
1954 }
1955
1956 //configure right pipe
1957 if(rDest != OV_INVALID) {
Saurabh Shah97e2d802014-04-14 18:03:54 -07001958 PipeArgs pargR(mdpFlags, whf, z, isFg,
Saurabh Shahab47c692014-02-12 18:45:57 -08001959 static_cast<eRotFlags>(rotFlags),
1960 layer->planeAlpha,
1961 (ovutils::eBlending) getBlending(layer->blending));
1962 if(configMdp(ctx->mOverlay, pargR, orient,
1963 cropR, dstR, metadata, rDest) < 0) {
1964 ALOGE("%s: commit failed for right mixer config", __FUNCTION__);
1965 return -1;
1966 }
1967 }
1968
1969 return 0;
1970}
1971
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001972}; //namespace
1973