blob: 774af7c57e91a135282a604237e5e49ce59e210d [file] [log] [blame]
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001/*
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08002 * Copyright (C) 2012-2014, The Linux Foundation. All rights reserved.
Naseer Ahmed7c958d42012-07-31 18:57:03 -07003 * Not a Contribution, Apache license notifications and license are retained
4 * for attribution purposes only.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
Saurabh Shah4fdde762013-04-30 18:47:33 -070019#include <math.h>
Naseer Ahmed7c958d42012-07-31 18:57:03 -070020#include "hwc_mdpcomp.h"
Naseer Ahmed54821fe2012-11-28 18:44:38 -050021#include <sys/ioctl.h>
Saurabh Shah56f610d2012-08-07 15:27:06 -070022#include "external.h"
Jeykumar Sankaran27dee262013-08-01 17:09:54 -070023#include "virtual.h"
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -080024#include "qdMetaData.h"
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -080025#include "mdp_version.h"
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -070026#include "hwc_fbupdate.h"
Saurabh Shaha9da08f2013-07-03 13:27:53 -070027#include "hwc_ad.h"
Saurabh Shahacf10202013-02-26 10:15:15 -080028#include <overlayRotator.h>
29
Saurabh Shah85234ec2013-04-12 17:09:00 -070030using namespace overlay;
Saurabh Shahbd2d0832013-04-04 14:33:08 -070031using namespace qdutils;
Saurabh Shahacf10202013-02-26 10:15:15 -080032using namespace overlay::utils;
33namespace ovutils = overlay::utils;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070034
Naseer Ahmed7c958d42012-07-31 18:57:03 -070035namespace qhwc {
36
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080037//==============MDPComp========================================================
38
Naseer Ahmed7c958d42012-07-31 18:57:03 -070039IdleInvalidator *MDPComp::idleInvalidator = NULL;
40bool MDPComp::sIdleFallBack = false;
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -080041bool MDPComp::sHandleTimeout = false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070042bool MDPComp::sDebugLogs = false;
Naseer Ahmed54821fe2012-11-28 18:44:38 -050043bool MDPComp::sEnabled = false;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -070044bool MDPComp::sEnableMixedMode = true;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -070045bool MDPComp::sEnablePartialFrameUpdate = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080046int MDPComp::sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
radhakrishnac9a67412013-09-25 17:40:42 +053047bool MDPComp::sEnable4k2kYUVSplit = false;
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -070048bool MDPComp::sSrcSplitEnabled = false;
Saurabh Shah88e4d272013-09-03 13:31:29 -070049MDPComp* MDPComp::getObject(hwc_context_t *ctx, const int& dpy) {
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -070050
Saurabh Shah88e4d272013-09-03 13:31:29 -070051 if(isDisplaySplit(ctx, dpy)) {
Saurabh Shahab47c692014-02-12 18:45:57 -080052 if(qdutils::MDPVersion::getInstance().isSrcSplit()) {
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -070053 sSrcSplitEnabled = true;
Saurabh Shahab47c692014-02-12 18:45:57 -080054 return new MDPCompSrcSplit(dpy);
55 }
Saurabh Shah88e4d272013-09-03 13:31:29 -070056 return new MDPCompSplit(dpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080057 }
Saurabh Shah88e4d272013-09-03 13:31:29 -070058 return new MDPCompNonSplit(dpy);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080059}
60
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080061MDPComp::MDPComp(int dpy):mDpy(dpy){};
62
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080063void MDPComp::dump(android::String8& buf)
64{
Jeykumar Sankaran3c6bb042013-08-15 14:01:04 -070065 if(mCurrentFrame.layerCount > MAX_NUM_APP_LAYERS)
66 return;
67
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080068 dumpsys_log(buf,"HWC Map for Dpy: %s \n",
Jeykumar Sankaran27dee262013-08-01 17:09:54 -070069 (mDpy == 0) ? "\"PRIMARY\"" :
70 (mDpy == 1) ? "\"EXTERNAL\"" : "\"VIRTUAL\"");
Saurabh Shahe9bc60f2013-08-29 12:58:06 -070071 dumpsys_log(buf,"CURR_FRAME: layerCount:%2d mdpCount:%2d "
72 "fbCount:%2d \n", mCurrentFrame.layerCount,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080073 mCurrentFrame.mdpCount, mCurrentFrame.fbCount);
74 dumpsys_log(buf,"needsFBRedraw:%3s pipesUsed:%2d MaxPipesPerMixer: %d \n",
75 (mCurrentFrame.needsRedraw? "YES" : "NO"),
76 mCurrentFrame.mdpCount, sMaxPipesPerMixer);
77 dumpsys_log(buf," --------------------------------------------- \n");
78 dumpsys_log(buf," listIdx | cached? | mdpIndex | comptype | Z \n");
79 dumpsys_log(buf," --------------------------------------------- \n");
80 for(int index = 0; index < mCurrentFrame.layerCount; index++ )
81 dumpsys_log(buf," %7d | %7s | %8d | %9s | %2d \n",
82 index,
83 (mCurrentFrame.isFBComposed[index] ? "YES" : "NO"),
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -070084 mCurrentFrame.layerToMDP[index],
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080085 (mCurrentFrame.isFBComposed[index] ?
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -070086 (mCurrentFrame.drop[index] ? "DROP" :
87 (mCurrentFrame.needsRedraw ? "GLES" : "CACHE")) : "MDP"),
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080088 (mCurrentFrame.isFBComposed[index] ? mCurrentFrame.fbZ :
89 mCurrentFrame.mdpToLayer[mCurrentFrame.layerToMDP[index]].pipeInfo->zOrder));
90 dumpsys_log(buf,"\n");
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080091}
92
93bool MDPComp::init(hwc_context_t *ctx) {
94
95 if(!ctx) {
96 ALOGE("%s: Invalid hwc context!!",__FUNCTION__);
97 return false;
98 }
99
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800100 char property[PROPERTY_VALUE_MAX];
101
102 sEnabled = false;
103 if((property_get("persist.hwc.mdpcomp.enable", property, NULL) > 0) &&
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800104 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
105 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800106 sEnabled = true;
107 }
108
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700109 sEnableMixedMode = true;
110 if((property_get("debug.mdpcomp.mixedmode.disable", property, NULL) > 0) &&
111 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
112 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
113 sEnableMixedMode = false;
114 }
115
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800116 if(property_get("debug.mdpcomp.logs", property, NULL) > 0) {
117 if(atoi(property) != 0)
118 sDebugLogs = true;
119 }
120
Jeykumar Sankaran7d6c4c02014-02-19 12:40:57 -0800121 if(property_get("persist.hwc.partialupdate", property, NULL) > 0) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700122 if((atoi(property) != 0) && ctx->mMDP.panel == MIPI_CMD_PANEL &&
123 qdutils::MDPVersion::getInstance().is8x74v2())
124 sEnablePartialFrameUpdate = true;
125 }
126 ALOGE_IF(isDebug(), "%s: Partial Update applicable?: %d",__FUNCTION__,
127 sEnablePartialFrameUpdate);
128
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800129 sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
Saurabh Shah85234ec2013-04-12 17:09:00 -0700130 if(property_get("debug.mdpcomp.maxpermixer", property, "-1") > 0) {
131 int val = atoi(property);
132 if(val >= 0)
133 sMaxPipesPerMixer = min(val, MAX_PIPES_PER_MIXER);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800134 }
135
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400136 if(ctx->mMDP.panel != MIPI_CMD_PANEL) {
137 // Idle invalidation is not necessary on command mode panels
138 long idle_timeout = DEFAULT_IDLE_TIME;
139 if(property_get("debug.mdpcomp.idletime", property, NULL) > 0) {
140 if(atoi(property) != 0)
141 idle_timeout = atoi(property);
142 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800143
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400144 //create Idle Invalidator only when not disabled through property
145 if(idle_timeout != -1)
146 idleInvalidator = IdleInvalidator::getInstance();
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800147
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400148 if(idleInvalidator == NULL) {
149 ALOGE("%s: failed to instantiate idleInvalidator object",
150 __FUNCTION__);
151 } else {
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530152 idleInvalidator->init(timeout_handler, ctx,
153 (unsigned int)idle_timeout);
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400154 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800155 }
radhakrishnac9a67412013-09-25 17:40:42 +0530156
157 if((property_get("debug.mdpcomp.4k2kSplit", property, "0") > 0) &&
158 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
159 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
160 sEnable4k2kYUVSplit = true;
161 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700162 return true;
163}
164
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800165void MDPComp::reset(hwc_context_t *ctx) {
166 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700167 mCurrentFrame.reset(numLayers);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800168 ctx->mOverlay->clear(mDpy);
169 ctx->mLayerRotMap[mDpy]->clear();
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700170}
171
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700172void MDPComp::timeout_handler(void *udata) {
173 struct hwc_context_t* ctx = (struct hwc_context_t*)(udata);
174
175 if(!ctx) {
176 ALOGE("%s: received empty data in timer callback", __FUNCTION__);
177 return;
178 }
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -0800179 Locker::Autolock _l(ctx->mDrawLock);
180 // Handle timeout event only if the previous composition is MDP or MIXED.
181 if(!sHandleTimeout) {
182 ALOGD_IF(isDebug(), "%s:Do not handle this timeout", __FUNCTION__);
183 return;
184 }
Jesse Hall3be78d92012-08-21 15:12:23 -0700185 if(!ctx->proc) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700186 ALOGE("%s: HWC proc not registered", __FUNCTION__);
187 return;
188 }
189 sIdleFallBack = true;
190 /* Trigger SF to redraw the current frame */
Jesse Hall3be78d92012-08-21 15:12:23 -0700191 ctx->proc->invalidate(ctx->proc);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700192}
193
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800194void MDPComp::setMDPCompLayerFlags(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800195 hwc_display_contents_1_t* list) {
196 LayerProp *layerProp = ctx->layerProp[mDpy];
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800197
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800198 for(int index = 0; index < ctx->listStats[mDpy].numAppLayers; index++) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800199 hwc_layer_1_t* layer = &(list->hwLayers[index]);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800200 if(!mCurrentFrame.isFBComposed[index]) {
201 layerProp[index].mFlags |= HWC_MDPCOMP;
202 layer->compositionType = HWC_OVERLAY;
203 layer->hints |= HWC_HINT_CLEAR_FB;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800204 } else {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700205 /* Drop the layer when its already present in FB OR when it lies
206 * outside frame's ROI */
207 if(!mCurrentFrame.needsRedraw || mCurrentFrame.drop[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800208 layer->compositionType = HWC_OVERLAY;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700209 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800210 }
211 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700212}
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500213
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800214void MDPComp::setRedraw(hwc_context_t *ctx,
215 hwc_display_contents_1_t* list) {
216 mCurrentFrame.needsRedraw = false;
217 if(!mCachedFrame.isSameFrame(mCurrentFrame, list) ||
218 (list->flags & HWC_GEOMETRY_CHANGED) ||
219 isSkipPresent(ctx, mDpy)) {
220 mCurrentFrame.needsRedraw = true;
221 }
222}
223
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800224MDPComp::FrameInfo::FrameInfo() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700225 reset(0);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800226}
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800227
Saurabh Shahaa236822013-04-24 18:07:26 -0700228void MDPComp::FrameInfo::reset(const int& numLayers) {
229 for(int i = 0 ; i < MAX_PIPES_PER_MIXER && numLayers; i++ ) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800230 if(mdpToLayer[i].pipeInfo) {
231 delete mdpToLayer[i].pipeInfo;
232 mdpToLayer[i].pipeInfo = NULL;
233 //We dont own the rotator
234 mdpToLayer[i].rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800235 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800236 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800237
238 memset(&mdpToLayer, 0, sizeof(mdpToLayer));
239 memset(&layerToMDP, -1, sizeof(layerToMDP));
Saurabh Shahaa236822013-04-24 18:07:26 -0700240 memset(&isFBComposed, 1, sizeof(isFBComposed));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800241
Saurabh Shahaa236822013-04-24 18:07:26 -0700242 layerCount = numLayers;
243 fbCount = numLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800244 mdpCount = 0;
Saurabh Shah2f3895f2013-05-02 10:13:31 -0700245 needsRedraw = true;
Saurabh Shahd53bc5f2014-02-05 10:17:43 -0800246 fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800247}
248
Saurabh Shahaa236822013-04-24 18:07:26 -0700249void MDPComp::FrameInfo::map() {
250 // populate layer and MDP maps
251 int mdpIdx = 0;
252 for(int idx = 0; idx < layerCount; idx++) {
253 if(!isFBComposed[idx]) {
254 mdpToLayer[mdpIdx].listIndex = idx;
255 layerToMDP[idx] = mdpIdx++;
256 }
257 }
258}
259
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800260MDPComp::LayerCache::LayerCache() {
261 reset();
262}
263
264void MDPComp::LayerCache::reset() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700265 memset(&hnd, 0, sizeof(hnd));
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530266 memset(&isFBComposed, true, sizeof(isFBComposed));
267 memset(&drop, false, sizeof(drop));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800268 layerCount = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -0700269}
270
271void MDPComp::LayerCache::cacheAll(hwc_display_contents_1_t* list) {
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530272 const int numAppLayers = (int)list->numHwLayers - 1;
Saurabh Shahaa236822013-04-24 18:07:26 -0700273 for(int i = 0; i < numAppLayers; i++) {
274 hnd[i] = list->hwLayers[i].handle;
275 }
276}
277
278void MDPComp::LayerCache::updateCounts(const FrameInfo& curFrame) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700279 layerCount = curFrame.layerCount;
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530280 memcpy(&isFBComposed, &curFrame.isFBComposed, sizeof(isFBComposed));
281 memcpy(&drop, &curFrame.drop, sizeof(drop));
282}
283
Jeykumar Sankaran988d3682013-11-15 11:57:16 -0800284bool MDPComp::LayerCache::isSameFrame(const FrameInfo& curFrame,
285 hwc_display_contents_1_t* list) {
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530286 if(layerCount != curFrame.layerCount)
287 return false;
288 for(int i = 0; i < curFrame.layerCount; i++) {
289 if((curFrame.isFBComposed[i] != isFBComposed[i]) ||
290 (curFrame.drop[i] != drop[i])) {
291 return false;
292 }
Jeykumar Sankaran988d3682013-11-15 11:57:16 -0800293 if(curFrame.isFBComposed[i] &&
294 (hnd[i] != list->hwLayers[i].handle)){
295 return false;
296 }
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530297 }
298 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800299}
300
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700301bool MDPComp::isSupportedForMDPComp(hwc_context_t *ctx, hwc_layer_1_t* layer) {
302 private_handle_t *hnd = (private_handle_t *)layer->handle;
303 if((not isYuvBuffer(hnd) and has90Transform(layer)) or
304 (not isValidDimension(ctx,layer))
305 //More conditions here, SKIP, sRGB+Blend etc
306 ) {
307 return false;
308 }
309 return true;
310}
311
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530312bool MDPComp::isValidDimension(hwc_context_t *ctx, hwc_layer_1_t *layer) {
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800313 private_handle_t *hnd = (private_handle_t *)layer->handle;
314
315 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -0700316 if (layer->flags & HWC_COLOR_FILL) {
317 // Color layer
318 return true;
319 }
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800320 ALOGE("%s: layer handle is NULL", __FUNCTION__);
321 return false;
322 }
323
Naseer Ahmede850a802013-09-06 13:12:52 -0400324 //XXX: Investigate doing this with pixel phase on MDSS
Naseer Ahmede77f8082013-10-10 13:42:48 -0400325 if(!isSecureBuffer(hnd) && isNonIntegralSourceCrop(layer->sourceCropf))
Naseer Ahmede850a802013-09-06 13:12:52 -0400326 return false;
327
Saurabh Shah62e1d732013-09-17 10:44:05 -0700328 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700329 hwc_rect_t dst = layer->displayFrame;
Saurabh Shah4fdde762013-04-30 18:47:33 -0700330 int crop_w = crop.right - crop.left;
331 int crop_h = crop.bottom - crop.top;
332 int dst_w = dst.right - dst.left;
333 int dst_h = dst.bottom - dst.top;
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800334 float w_scale = ((float)crop_w / (float)dst_w);
335 float h_scale = ((float)crop_h / (float)dst_h);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700336
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800337 /* Workaround for MDP HW limitation in DSI command mode panels where
338 * FPS will not go beyond 30 if buffers on RGB pipes are of width or height
339 * less than 5 pixels
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530340 * There also is a HW limilation in MDP, minimum block size is 2x2
341 * Fallback to GPU if height is less than 2.
342 */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800343 if((crop_w < 5)||(crop_h < 5))
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800344 return false;
345
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800346 if((w_scale > 1.0f) || (h_scale > 1.0f)) {
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700347 const uint32_t maxMDPDownscale =
Saurabh Shah4fdde762013-04-30 18:47:33 -0700348 qdutils::MDPVersion::getInstance().getMaxMDPDownscale();
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800349 const float w_dscale = w_scale;
350 const float h_dscale = h_scale;
351
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800352 if(ctx->mMDP.version >= qdutils::MDSS_V5) {
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700353
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800354 if(!qdutils::MDPVersion::getInstance().supportsDecimation()) {
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700355 /* On targets that doesnt support Decimation (eg.,8x26)
356 * maximum downscale support is overlay pipe downscale.
357 */
358 if(crop_w > MAX_DISPLAY_DIM || w_dscale > maxMDPDownscale ||
359 h_dscale > maxMDPDownscale)
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800360 return false;
361 } else {
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700362 // Decimation on macrotile format layers is not supported.
363 if(isTileRendered(hnd)) {
364 /* MDP can read maximum MAX_DISPLAY_DIM width.
365 * Bail out if
366 * 1. Src crop > MAX_DISPLAY_DIM on nonsplit MDPComp
367 * 2. exceeds maximum downscale limit
368 */
369 if(((crop_w > MAX_DISPLAY_DIM) && !sSrcSplitEnabled) ||
370 w_dscale > maxMDPDownscale ||
371 h_dscale > maxMDPDownscale) {
372 return false;
373 }
374 } else if(w_dscale > 64 || h_dscale > 64)
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800375 return false;
376 }
377 } else { //A-family
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700378 if(w_dscale > maxMDPDownscale || h_dscale > maxMDPDownscale)
Saurabh Shah4fdde762013-04-30 18:47:33 -0700379 return false;
380 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700381 }
382
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800383 if((w_scale < 1.0f) || (h_scale < 1.0f)) {
384 const uint32_t upscale =
385 qdutils::MDPVersion::getInstance().getMaxMDPUpscale();
386 const float w_uscale = 1.0f / w_scale;
387 const float h_uscale = 1.0f / h_scale;
388
389 if(w_uscale > upscale || h_uscale > upscale)
390 return false;
391 }
392
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800393 return true;
394}
395
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700396ovutils::eDest MDPComp::getMdpPipe(hwc_context_t *ctx, ePipeType type,
397 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800398 overlay::Overlay& ov = *ctx->mOverlay;
399 ovutils::eDest mdp_pipe = ovutils::OV_INVALID;
400
401 switch(type) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800402 case MDPCOMP_OV_DMA:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700403 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_DMA, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800404 if(mdp_pipe != ovutils::OV_INVALID) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800405 return mdp_pipe;
406 }
407 case MDPCOMP_OV_ANY:
408 case MDPCOMP_OV_RGB:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700409 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800410 if(mdp_pipe != ovutils::OV_INVALID) {
411 return mdp_pipe;
412 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800413
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800414 if(type == MDPCOMP_OV_RGB) {
415 //Requested only for RGB pipe
416 break;
417 }
418 case MDPCOMP_OV_VG:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700419 return ov.nextPipe(ovutils::OV_MDP_PIPE_VG, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800420 default:
421 ALOGE("%s: Invalid pipe type",__FUNCTION__);
422 return ovutils::OV_INVALID;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800423 };
424 return ovutils::OV_INVALID;
425}
426
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800427bool MDPComp::isFrameDoable(hwc_context_t *ctx) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700428 bool ret = true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800429
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800430 if(!isEnabled()) {
431 ALOGD_IF(isDebug(),"%s: MDP Comp. not enabled.", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700432 ret = false;
Saurabh Shahd4e65852013-06-17 11:33:53 -0700433 } else if(qdutils::MDPVersion::getInstance().is8x26() &&
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -0800434 ctx->mVideoTransFlag &&
435 isSecondaryConnected(ctx)) {
Saurabh Shahd4e65852013-06-17 11:33:53 -0700436 //1 Padding round to shift pipes across mixers
437 ALOGD_IF(isDebug(),"%s: MDP Comp. video transition padding round",
438 __FUNCTION__);
439 ret = false;
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -0800440 } else if(isSecondaryConfiguring(ctx)) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800441 ALOGD_IF( isDebug(),"%s: External Display connection is pending",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800442 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700443 ret = false;
Saurabh Shahaa236822013-04-24 18:07:26 -0700444 } else if(ctx->isPaddingRound) {
Raj Kamal9ed3d6b2014-02-07 16:15:17 +0530445 ALOGD_IF(isDebug(), "%s: padding round invoked for dpy %d",
446 __FUNCTION__,mDpy);
Saurabh Shahaa236822013-04-24 18:07:26 -0700447 ret = false;
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700448 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700449 return ret;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800450}
451
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800452/*
453 * 1) Identify layers that are not visible in the updating ROI and drop them
454 * from composition.
455 * 2) If we have a scaling layers which needs cropping against generated ROI.
456 * Reset ROI to full resolution.
457 */
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700458bool MDPComp::validateAndApplyROI(hwc_context_t *ctx,
459 hwc_display_contents_1_t* list, hwc_rect_t roi) {
460 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
461
462 if(!isValidRect(roi))
463 return false;
464
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800465 hwc_rect_t visibleRect = roi;
466
467 for(int i = numAppLayers - 1; i >= 0; i--){
468
469 if(!isValidRect(visibleRect)) {
470 mCurrentFrame.drop[i] = true;
471 mCurrentFrame.dropCount++;
Jeykumar Sankaran0b961452014-01-21 17:26:12 -0800472 continue;
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800473 }
474
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700475 const hwc_layer_1_t* layer = &list->hwLayers[i];
476
477 hwc_rect_t dstRect = layer->displayFrame;
Arun Kumar K.R91090c72013-10-28 19:40:18 -0700478 hwc_rect_t srcRect = integerizeSourceCrop(layer->sourceCropf);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700479
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800480 hwc_rect_t res = getIntersection(visibleRect, dstRect);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700481
482 int res_w = res.right - res.left;
483 int res_h = res.bottom - res.top;
484 int dst_w = dstRect.right - dstRect.left;
485 int dst_h = dstRect.bottom - dstRect.top;
486
487 if(!isValidRect(res)) {
488 mCurrentFrame.drop[i] = true;
489 mCurrentFrame.dropCount++;
490 }else {
491 /* Reset frame ROI when any layer which needs scaling also needs ROI
492 * cropping */
Jeykumar Sankaran0b961452014-01-21 17:26:12 -0800493 if((res_w != dst_w || res_h != dst_h) && needsScaling (layer)) {
Arpita Banerjeed8965982013-11-08 17:27:33 -0800494 ALOGI("%s: Resetting ROI due to scaling", __FUNCTION__);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700495 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
496 mCurrentFrame.dropCount = 0;
497 return false;
498 }
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800499
Jeykumar Sankaran0b961452014-01-21 17:26:12 -0800500 /* deduct any opaque region from visibleRect */
501 if (layer->blending == HWC_BLENDING_NONE)
502 visibleRect = deductRect(visibleRect, res);
503 }
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700504 }
505 return true;
506}
507
508void MDPComp::generateROI(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
509 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
510
511 if(!sEnablePartialFrameUpdate) {
512 return;
513 }
514
515 if(mDpy || isDisplaySplit(ctx, mDpy)){
516 ALOGE_IF(isDebug(), "%s: ROI not supported for"
517 "the (1) external / virtual display's (2) dual DSI displays",
518 __FUNCTION__);
519 return;
520 }
521
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800522 if(isSkipPresent(ctx, mDpy))
523 return;
524
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700525 if(list->flags & HWC_GEOMETRY_CHANGED)
526 return;
527
528 struct hwc_rect roi = (struct hwc_rect){0, 0, 0, 0};
529 for(int index = 0; index < numAppLayers; index++ ) {
530 if ((mCachedFrame.hnd[index] != list->hwLayers[index].handle) ||
531 isYuvBuffer((private_handle_t *)list->hwLayers[index].handle)) {
532 hwc_rect_t dstRect = list->hwLayers[index].displayFrame;
Arun Kumar K.R91090c72013-10-28 19:40:18 -0700533 hwc_rect_t srcRect = integerizeSourceCrop(
534 list->hwLayers[index].sourceCropf);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700535
536 /* Intersect against display boundaries */
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700537 roi = getUnion(roi, dstRect);
538 }
539 }
540
541 if(!validateAndApplyROI(ctx, list, roi)){
542 roi = (struct hwc_rect) {0, 0,
543 (int)ctx->dpyAttr[mDpy].xres, (int)ctx->dpyAttr[mDpy].yres};
544 }
545
546 ctx->listStats[mDpy].roi.x = roi.left;
547 ctx->listStats[mDpy].roi.y = roi.top;
548 ctx->listStats[mDpy].roi.w = roi.right - roi.left;
549 ctx->listStats[mDpy].roi.h = roi.bottom - roi.top;
550
551 ALOGD_IF(isDebug(),"%s: generated ROI: [%d, %d, %d, %d]", __FUNCTION__,
552 roi.left, roi.top, roi.right, roi.bottom);
553}
554
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800555/* Checks for conditions where all the layers marked for MDP comp cannot be
556 * bypassed. On such conditions we try to bypass atleast YUV layers */
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800557bool MDPComp::tryFullFrame(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800558 hwc_display_contents_1_t* list){
559
Saurabh Shahaa236822013-04-24 18:07:26 -0700560 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Arun Kumar K.R2e2871c2014-01-10 12:47:06 -0800561 int priDispW = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800562
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -0700563 if(sIdleFallBack && !ctx->listStats[mDpy].secureUI) {
Saurabh Shah2d998a92013-05-14 17:55:58 -0700564 ALOGD_IF(isDebug(), "%s: Idle fallback dpy %d",__FUNCTION__, mDpy);
565 return false;
566 }
567
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800568 if(isSkipPresent(ctx, mDpy)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700569 ALOGD_IF(isDebug(),"%s: SKIP present: %d",
570 __FUNCTION__,
571 isSkipPresent(ctx, mDpy));
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800572 return false;
573 }
574
Arun Kumar K.R2e2871c2014-01-10 12:47:06 -0800575 if(mDpy > HWC_DISPLAY_PRIMARY && (priDispW > MAX_DISPLAY_DIM) &&
576 (ctx->dpyAttr[mDpy].xres < MAX_DISPLAY_DIM)) {
577 // Disable MDP comp on Secondary when the primary is highres panel and
578 // the secondary is a normal 1080p, because, MDP comp on secondary under
579 // in such usecase, decimation gets used for downscale and there will be
580 // a quality mismatch when there will be a fallback to GPU comp
581 ALOGD_IF(isDebug(), "%s: Disable MDP Compositon for Secondary Disp",
582 __FUNCTION__);
583 return false;
584 }
585
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800586 // check for action safe flag and downscale mode which requires scaling.
587 if(ctx->dpyAttr[mDpy].mActionSafePresent
588 || ctx->dpyAttr[mDpy].mDownScaleMode) {
589 ALOGD_IF(isDebug(), "%s: Scaling needed for this frame",__FUNCTION__);
590 return false;
591 }
592
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800593 for(int i = 0; i < numAppLayers; ++i) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800594 hwc_layer_1_t* layer = &list->hwLayers[i];
595 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800596
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700597 if(isYuvBuffer(hnd) && has90Transform(layer)) {
598 if(!canUseRotator(ctx, mDpy)) {
599 ALOGD_IF(isDebug(), "%s: Can't use rotator for dpy %d",
600 __FUNCTION__, mDpy);
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700601 return false;
602 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800603 }
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530604
605 //For 8x26 with panel width>1k, if RGB layer needs HFLIP fail mdp comp
606 // may not need it if Gfx pre-rotation can handle all flips & rotations
Sushil Chauhanfda00fc2014-03-20 11:08:41 -0700607 int transform = (layer->flags & HWC_COLOR_FILL) ? 0 : layer->transform;
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530608 if(qdutils::MDPVersion::getInstance().is8x26() &&
609 (ctx->dpyAttr[mDpy].xres > 1024) &&
Sushil Chauhanfda00fc2014-03-20 11:08:41 -0700610 (transform & HWC_TRANSFORM_FLIP_H) &&
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530611 (!isYuvBuffer(hnd)))
612 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800613 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700614
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700615 if(ctx->mAD->isDoable()) {
616 return false;
617 }
618
Saurabh Shahaa236822013-04-24 18:07:26 -0700619 //If all above hard conditions are met we can do full or partial MDP comp.
620 bool ret = false;
621 if(fullMDPComp(ctx, list)) {
622 ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700623 } else if(partialMDPComp(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700624 ret = true;
625 }
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530626
Saurabh Shahaa236822013-04-24 18:07:26 -0700627 return ret;
628}
629
630bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700631 //Will benefit presentation / secondary-only layer.
632 if((mDpy > HWC_DISPLAY_PRIMARY) &&
633 (list->numHwLayers - 1) > MAX_SEC_LAYERS) {
634 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
635 return false;
636 }
637
638 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
639 for(int i = 0; i < numAppLayers; i++) {
640 hwc_layer_1_t* layer = &list->hwLayers[i];
641 if(not isSupportedForMDPComp(ctx, layer)) {
642 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",__FUNCTION__);
643 return false;
644 }
Yang Xu9c1eb2b2013-11-26 01:28:13 +0800645
646 //For 8x26, if there is only one layer which needs scale for secondary
647 //while no scale for primary display, DMA pipe is occupied by primary.
648 //If need to fall back to GLES composition, virtual display lacks DMA
649 //pipe and error is reported.
650 if(qdutils::MDPVersion::getInstance().is8x26() &&
651 mDpy >= HWC_DISPLAY_EXTERNAL &&
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530652 qhwc::needsScaling(layer))
Yang Xu9c1eb2b2013-11-26 01:28:13 +0800653 return false;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700654 }
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800655
Saurabh Shahaa236822013-04-24 18:07:26 -0700656 mCurrentFrame.fbCount = 0;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700657 memcpy(&mCurrentFrame.isFBComposed, &mCurrentFrame.drop,
658 sizeof(mCurrentFrame.isFBComposed));
659 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount -
660 mCurrentFrame.dropCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700661
radhakrishnac9a67412013-09-25 17:40:42 +0530662 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800663 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530664 }
665
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800666 if(!postHeuristicsHandling(ctx, list)) {
667 ALOGD_IF(isDebug(), "post heuristic handling failed");
668 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700669 return false;
670 }
671
Saurabh Shahaa236822013-04-24 18:07:26 -0700672 return true;
673}
674
675bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
676{
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700677 if(!sEnableMixedMode) {
678 //Mixed mode is disabled. No need to even try caching.
679 return false;
680 }
681
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700682 bool ret = false;
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800683 if(list->flags & HWC_GEOMETRY_CHANGED) { //Try load based first
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800684 ret = loadBasedComp(ctx, list) or
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800685 cacheBasedComp(ctx, list);
686 } else {
687 ret = cacheBasedComp(ctx, list) or
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800688 loadBasedComp(ctx, list);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700689 }
690
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700691 return ret;
692}
693
694bool MDPComp::cacheBasedComp(hwc_context_t *ctx,
695 hwc_display_contents_1_t* list) {
696 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700697 mCurrentFrame.reset(numAppLayers);
698 updateLayerCache(ctx, list);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700699
700 //If an MDP marked layer is unsupported cannot do partial MDP Comp
701 for(int i = 0; i < numAppLayers; i++) {
702 if(!mCurrentFrame.isFBComposed[i]) {
703 hwc_layer_1_t* layer = &list->hwLayers[i];
704 if(not isSupportedForMDPComp(ctx, layer)) {
705 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",
706 __FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800707 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700708 return false;
709 }
710 }
711 }
712
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700713 updateYUV(ctx, list, false /*secure only*/);
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530714 bool ret = markLayersForCaching(ctx, list); //sets up fbZ also
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700715 if(!ret) {
716 ALOGD_IF(isDebug(),"%s: batching failed, dpy %d",__FUNCTION__, mDpy);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800717 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700718 return false;
719 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700720
721 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700722
radhakrishnac9a67412013-09-25 17:40:42 +0530723 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800724 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530725 }
726
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700727 //Will benefit cases where a video has non-updating background.
728 if((mDpy > HWC_DISPLAY_PRIMARY) and
729 (mdpCount > MAX_SEC_LAYERS)) {
730 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800731 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700732 return false;
733 }
734
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800735 if(!postHeuristicsHandling(ctx, list)) {
736 ALOGD_IF(isDebug(), "post heuristic handling failed");
737 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700738 return false;
739 }
740
Saurabh Shahaa236822013-04-24 18:07:26 -0700741 return true;
742}
743
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800744bool MDPComp::loadBasedComp(hwc_context_t *ctx,
Saurabh Shahb772ae32013-11-18 15:40:02 -0800745 hwc_display_contents_1_t* list) {
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -0800746 if(not isLoadBasedCompDoable(ctx)) {
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800747 return false;
748 }
749
Saurabh Shahb772ae32013-11-18 15:40:02 -0800750 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800751 const int numNonDroppedLayers = numAppLayers - mCurrentFrame.dropCount;
752 const int stagesForMDP = min(sMaxPipesPerMixer,
753 ctx->mOverlay->availablePipes(mDpy, Overlay::MIXER_DEFAULT));
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800754
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800755 int mdpBatchSize = stagesForMDP - 1; //1 stage for FB
756 int fbBatchSize = numNonDroppedLayers - mdpBatchSize;
757 int lastMDPSupportedIndex = numAppLayers;
758 int dropCount = 0;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800759
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800760 //Find the minimum MDP batch size
761 for(int i = 0; i < numAppLayers;i++) {
762 if(mCurrentFrame.drop[i]) {
763 dropCount++;
Jeykumar Sankaran846e2792014-01-23 21:59:58 -0800764 continue;
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800765 }
766 hwc_layer_1_t* layer = &list->hwLayers[i];
767 if(not isSupportedForMDPComp(ctx, layer)) {
768 lastMDPSupportedIndex = i;
769 mdpBatchSize = min(i - dropCount, stagesForMDP - 1);
770 fbBatchSize = numNonDroppedLayers - mdpBatchSize;
Jeykumar Sankaran846e2792014-01-23 21:59:58 -0800771 break;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800772 }
Saurabh Shahb772ae32013-11-18 15:40:02 -0800773 }
774
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800775 ALOGD_IF(isDebug(), "%s:Before optimizing fbBatch, mdpbatch %d, fbbatch %d "
776 "dropped %d", __FUNCTION__, mdpBatchSize, fbBatchSize,
777 mCurrentFrame.dropCount);
778
779 //Start at a point where the fb batch should at least have 2 layers, for
780 //this mode to be justified.
781 while(fbBatchSize < 2) {
782 ++fbBatchSize;
783 --mdpBatchSize;
Jeykumar Sankaran846e2792014-01-23 21:59:58 -0800784 }
Saurabh Shahb772ae32013-11-18 15:40:02 -0800785
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800786 //If there are no layers for MDP, this mode doesnt make sense.
787 if(mdpBatchSize < 1) {
788 ALOGD_IF(isDebug(), "%s: No MDP layers after optimizing for fbBatch",
789 __FUNCTION__);
Saurabh Shahb772ae32013-11-18 15:40:02 -0800790 return false;
791 }
792
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800793 mCurrentFrame.reset(numAppLayers);
794
795 //Try with successively smaller mdp batch sizes until we succeed or reach 1
796 while(mdpBatchSize > 0) {
797 //Mark layers for MDP comp
798 int mdpBatchLeft = mdpBatchSize;
799 for(int i = 0; i < lastMDPSupportedIndex and mdpBatchLeft; i++) {
800 if(mCurrentFrame.drop[i]) {
801 continue;
802 }
803 mCurrentFrame.isFBComposed[i] = false;
804 --mdpBatchLeft;
805 }
806
807 mCurrentFrame.fbZ = mdpBatchSize;
808 mCurrentFrame.fbCount = fbBatchSize;
809 mCurrentFrame.mdpCount = mdpBatchSize;
810
811 ALOGD_IF(isDebug(), "%s:Trying with: mdpbatch %d fbbatch %d dropped %d",
812 __FUNCTION__, mdpBatchSize, fbBatchSize,
813 mCurrentFrame.dropCount);
814
815 if(postHeuristicsHandling(ctx, list)) {
816 ALOGD_IF(isDebug(), "%s: Postheuristics handling succeeded",
817 __FUNCTION__);
818 return true;
819 }
820
821 reset(ctx);
822 --mdpBatchSize;
823 ++fbBatchSize;
824 }
825
826 return false;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800827}
828
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -0800829bool MDPComp::isLoadBasedCompDoable(hwc_context_t *ctx) {
Prabhanjan Kandula3dbbd882013-12-11 14:43:46 +0530830 if(mDpy or isSecurePresent(ctx, mDpy) or
831 isYuvPresent(ctx, mDpy)) {
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700832 return false;
833 }
834 return true;
835}
836
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800837bool MDPComp::tryVideoOnly(hwc_context_t *ctx,
838 hwc_display_contents_1_t* list) {
839 const bool secureOnly = true;
840 return videoOnlyComp(ctx, list, not secureOnly) or
841 videoOnlyComp(ctx, list, secureOnly);
842}
843
844bool MDPComp::videoOnlyComp(hwc_context_t *ctx,
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700845 hwc_display_contents_1_t* list, bool secureOnly) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700846 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700847
Saurabh Shahaa236822013-04-24 18:07:26 -0700848 mCurrentFrame.reset(numAppLayers);
Jeykumar Sankaraneb3a5e22014-04-08 16:07:55 -0700849 mCurrentFrame.fbCount -= mCurrentFrame.dropCount;
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700850 updateYUV(ctx, list, secureOnly);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700851 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700852
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800853 if(!isYuvPresent(ctx, mDpy) or (mdpCount == 0)) {
854 reset(ctx);
Saurabh Shahaa236822013-04-24 18:07:26 -0700855 return false;
856 }
857
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -0800858 /* Bail out if we are processing only secured video layers
859 * and we dont have any */
860 if(!isSecurePresent(ctx, mDpy) && secureOnly){
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800861 reset(ctx);
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -0800862 return false;
863 }
864
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800865 if(mCurrentFrame.fbCount)
866 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
Saurabh Shah4fdde762013-04-30 18:47:33 -0700867
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800868 if(sEnable4k2kYUVSplit){
869 adjustForSourceSplit(ctx, list);
870 }
871
872 if(!postHeuristicsHandling(ctx, list)) {
873 ALOGD_IF(isDebug(), "post heuristic handling failed");
874 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700875 return false;
876 }
877
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800878 return true;
879}
880
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800881/* Checks for conditions where YUV layers cannot be bypassed */
882bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -0700883 if(isSkipLayer(layer)) {
Saurabh Shahe2474082013-05-15 16:32:13 -0700884 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800885 return false;
886 }
887
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700888 if(layer->transform & HWC_TRANSFORM_ROT_90 && !canUseRotator(ctx,mDpy)) {
889 ALOGD_IF(isDebug(), "%s: no free DMA pipe",__FUNCTION__);
890 return false;
891 }
892
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800893 if(isSecuring(ctx, layer)) {
894 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
895 return false;
896 }
897
Saurabh Shah4fdde762013-04-30 18:47:33 -0700898 if(!isValidDimension(ctx, layer)) {
899 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
900 __FUNCTION__);
901 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800902 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700903
Naseer Ahmeddc61a972013-07-10 17:50:54 -0400904 if(layer->planeAlpha < 0xFF) {
905 ALOGD_IF(isDebug(), "%s: Cannot handle YUV layer with plane alpha\
906 in video only mode",
907 __FUNCTION__);
908 return false;
909 }
910
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800911 return true;
912}
913
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530914/* starts at fromIndex and check for each layer to find
915 * if it it has overlapping with any Updating layer above it in zorder
916 * till the end of the batch. returns true if it finds any intersection */
917bool MDPComp::canPushBatchToTop(const hwc_display_contents_1_t* list,
918 int fromIndex, int toIndex) {
919 for(int i = fromIndex; i < toIndex; i++) {
920 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
921 if(intersectingUpdatingLayers(list, i+1, toIndex, i)) {
922 return false;
923 }
924 }
925 }
926 return true;
927}
928
929/* Checks if given layer at targetLayerIndex has any
930 * intersection with all the updating layers in beween
931 * fromIndex and toIndex. Returns true if it finds intersectiion */
932bool MDPComp::intersectingUpdatingLayers(const hwc_display_contents_1_t* list,
933 int fromIndex, int toIndex, int targetLayerIndex) {
934 for(int i = fromIndex; i <= toIndex; i++) {
935 if(!mCurrentFrame.isFBComposed[i]) {
936 if(areLayersIntersecting(&list->hwLayers[i],
937 &list->hwLayers[targetLayerIndex])) {
938 return true;
939 }
940 }
941 }
942 return false;
943}
944
945int MDPComp::getBatch(hwc_display_contents_1_t* list,
946 int& maxBatchStart, int& maxBatchEnd,
947 int& maxBatchCount) {
948 int i = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530949 int fbZOrder =-1;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -0800950 int droppedLayerCt = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530951 while (i < mCurrentFrame.layerCount) {
952 int batchCount = 0;
953 int batchStart = i;
954 int batchEnd = i;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -0800955 /* Adjust batch Z order with the dropped layers so far */
956 int fbZ = batchStart - droppedLayerCt;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530957 int firstZReverseIndex = -1;
Prabhanjan Kandula0ed2cc92013-12-06 12:39:04 +0530958 int updatingLayersAbove = 0;//Updating layer count in middle of batch
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530959 while(i < mCurrentFrame.layerCount) {
960 if(!mCurrentFrame.isFBComposed[i]) {
961 if(!batchCount) {
962 i++;
963 break;
964 }
965 updatingLayersAbove++;
966 i++;
967 continue;
968 } else {
969 if(mCurrentFrame.drop[i]) {
970 i++;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -0800971 droppedLayerCt++;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530972 continue;
973 } else if(updatingLayersAbove <= 0) {
974 batchCount++;
975 batchEnd = i;
976 i++;
977 continue;
978 } else { //Layer is FBComposed, not a drop & updatingLayer > 0
979
980 // We have a valid updating layer already. If layer-i not
981 // have overlapping with all updating layers in between
982 // batch-start and i, then we can add layer i to batch.
983 if(!intersectingUpdatingLayers(list, batchStart, i-1, i)) {
984 batchCount++;
985 batchEnd = i;
986 i++;
987 continue;
988 } else if(canPushBatchToTop(list, batchStart, i)) {
989 //If All the non-updating layers with in this batch
990 //does not have intersection with the updating layers
991 //above in z-order, then we can safely move the batch to
992 //higher z-order. Increment fbZ as it is moving up.
993 if( firstZReverseIndex < 0) {
994 firstZReverseIndex = i;
995 }
996 batchCount++;
997 batchEnd = i;
998 fbZ += updatingLayersAbove;
999 i++;
1000 updatingLayersAbove = 0;
1001 continue;
1002 } else {
1003 //both failed.start the loop again from here.
1004 if(firstZReverseIndex >= 0) {
1005 i = firstZReverseIndex;
1006 }
1007 break;
1008 }
1009 }
1010 }
1011 }
1012 if(batchCount > maxBatchCount) {
1013 maxBatchCount = batchCount;
1014 maxBatchStart = batchStart;
1015 maxBatchEnd = batchEnd;
1016 fbZOrder = fbZ;
1017 }
1018 }
1019 return fbZOrder;
1020}
1021
1022bool MDPComp::markLayersForCaching(hwc_context_t* ctx,
1023 hwc_display_contents_1_t* list) {
1024 /* Idea is to keep as many non-updating(cached) layers in FB and
1025 * send rest of them through MDP. This is done in 2 steps.
1026 * 1. Find the maximum contiguous batch of non-updating layers.
1027 * 2. See if we can improve this batch size for caching by adding
1028 * opaque layers around the batch, if they don't have
1029 * any overlapping with the updating layers in between.
1030 * NEVER mark an updating layer for caching.
1031 * But cached ones can be marked for MDP */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001032
1033 int maxBatchStart = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001034 int maxBatchEnd = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001035 int maxBatchCount = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301036 int fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001037
Saurabh Shahd53bc5f2014-02-05 10:17:43 -08001038 /* Nothing is cached. No batching needed */
1039 if(mCurrentFrame.fbCount == 0) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001040 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -07001041 }
Saurabh Shahd53bc5f2014-02-05 10:17:43 -08001042
1043 /* No MDP comp layers, try to use other comp modes */
1044 if(mCurrentFrame.mdpCount == 0) {
1045 return false;
Saurabh Shahaa236822013-04-24 18:07:26 -07001046 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001047
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301048 fbZ = getBatch(list, maxBatchStart, maxBatchEnd, maxBatchCount);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001049
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301050 /* reset rest of the layers lying inside ROI for MDP comp */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001051 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001052 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001053 if((i < maxBatchStart || i > maxBatchEnd) &&
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301054 mCurrentFrame.isFBComposed[i]){
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001055 if(!mCurrentFrame.drop[i]){
1056 //If an unsupported layer is being attempted to
1057 //be pulled out we should fail
1058 if(not isSupportedForMDPComp(ctx, layer)) {
1059 return false;
1060 }
1061 mCurrentFrame.isFBComposed[i] = false;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001062 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001063 }
1064 }
1065
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301066 // update the frame data
1067 mCurrentFrame.fbZ = fbZ;
1068 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001069 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001070 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001071
1072 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301073 mCurrentFrame.fbCount);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001074
1075 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001076}
Saurabh Shah85234ec2013-04-12 17:09:00 -07001077
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001078void MDPComp::updateLayerCache(hwc_context_t* ctx,
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001079 hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001080 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001081 int fbCount = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001082
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001083 for(int i = 0; i < numAppLayers; i++) {
1084 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001085 if(!mCurrentFrame.drop[i])
1086 fbCount++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001087 mCurrentFrame.isFBComposed[i] = true;
1088 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -07001089 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001090 }
1091 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001092
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001093 mCurrentFrame.fbCount = fbCount;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001094 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount
1095 - mCurrentFrame.dropCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001096
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001097 ALOGD_IF(isDebug(),"%s: MDP count: %d FB count %d drop count: %d"
1098 ,__FUNCTION__, mCurrentFrame.mdpCount, mCurrentFrame.fbCount,
1099 mCurrentFrame.dropCount);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001100}
1101
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001102void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list,
1103 bool secureOnly) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001104 int nYuvCount = ctx->listStats[mDpy].yuvCount;
1105 for(int index = 0;index < nYuvCount; index++){
1106 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
1107 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
1108
1109 if(!isYUVDoable(ctx, layer)) {
1110 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
1111 mCurrentFrame.isFBComposed[nYuvIndex] = true;
1112 mCurrentFrame.fbCount++;
1113 }
1114 } else {
1115 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001116 private_handle_t *hnd = (private_handle_t *)layer->handle;
1117 if(!secureOnly || isSecureBuffer(hnd)) {
1118 mCurrentFrame.isFBComposed[nYuvIndex] = false;
1119 mCurrentFrame.fbCount--;
1120 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001121 }
1122 }
1123 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001124
1125 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001126 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
1127 ALOGD_IF(isDebug(),"%s: fb count: %d",__FUNCTION__,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001128 mCurrentFrame.fbCount);
1129}
1130
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301131hwc_rect_t MDPComp::getUpdatingFBRect(hwc_display_contents_1_t* list){
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001132 hwc_rect_t fbRect = (struct hwc_rect){0, 0, 0, 0};
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001133
1134 /* Update only the region of FB needed for composition */
1135 for(int i = 0; i < mCurrentFrame.layerCount; i++ ) {
1136 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
1137 hwc_layer_1_t* layer = &list->hwLayers[i];
1138 hwc_rect_t dst = layer->displayFrame;
1139 fbRect = getUnion(fbRect, dst);
1140 }
1141 }
1142 return fbRect;
1143}
1144
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001145bool MDPComp::postHeuristicsHandling(hwc_context_t *ctx,
1146 hwc_display_contents_1_t* list) {
1147
1148 //Capability checks
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301149 if(!resourceCheck()) {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001150 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
1151 return false;
1152 }
1153
1154 //Limitations checks
1155 if(!hwLimitationsCheck(ctx, list)) {
1156 ALOGD_IF(isDebug(), "%s: HW limitations",__FUNCTION__);
1157 return false;
1158 }
1159
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001160 //Configure framebuffer first if applicable
1161 if(mCurrentFrame.fbZ >= 0) {
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301162 hwc_rect_t fbRect = getUpdatingFBRect(list);
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001163 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, fbRect, mCurrentFrame.fbZ))
1164 {
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001165 ALOGD_IF(isDebug(), "%s configure framebuffer failed",
1166 __FUNCTION__);
1167 return false;
1168 }
1169 }
1170
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001171 mCurrentFrame.map();
1172
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001173 if(!allocLayerPipes(ctx, list)) {
1174 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -07001175 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001176 }
1177
1178 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001179 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001180 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001181 int mdpIndex = mCurrentFrame.layerToMDP[index];
1182 hwc_layer_1_t* layer = &list->hwLayers[index];
1183
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301184 //Leave fbZ for framebuffer. CACHE/GLES layers go here.
1185 if(mdpNextZOrder == mCurrentFrame.fbZ) {
1186 mdpNextZOrder++;
1187 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001188 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1189 cur_pipe->zOrder = mdpNextZOrder++;
1190
radhakrishnac9a67412013-09-25 17:40:42 +05301191 private_handle_t *hnd = (private_handle_t *)layer->handle;
1192 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1193 if(configure4k2kYuv(ctx, layer,
1194 mCurrentFrame.mdpToLayer[mdpIndex])
1195 != 0 ){
1196 ALOGD_IF(isDebug(), "%s: Failed to configure split pipes \
1197 for layer %d",__FUNCTION__, index);
1198 return false;
1199 }
1200 else{
1201 mdpNextZOrder++;
1202 }
1203 continue;
1204 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001205 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
1206 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
radhakrishnac9a67412013-09-25 17:40:42 +05301207 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -07001208 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001209 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001210 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001211 }
1212
Saurabh Shaha36be922013-12-16 18:18:39 -08001213 if(!ctx->mOverlay->validateAndSet(mDpy, ctx->dpyAttr[mDpy].fd)) {
1214 ALOGD_IF(isDebug(), "%s: Failed to validate and set overlay for dpy %d"
1215 ,__FUNCTION__, mDpy);
1216 return false;
1217 }
1218
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001219 setRedraw(ctx, list);
Saurabh Shahaa236822013-04-24 18:07:26 -07001220 return true;
1221}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001222
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301223bool MDPComp::resourceCheck() {
Saurabh Shah173f4242013-11-20 09:50:12 -08001224 const bool fbUsed = mCurrentFrame.fbCount;
1225 if(mCurrentFrame.mdpCount > sMaxPipesPerMixer - fbUsed) {
1226 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
1227 return false;
1228 }
Saurabh Shah173f4242013-11-20 09:50:12 -08001229 return true;
1230}
1231
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301232bool MDPComp::hwLimitationsCheck(hwc_context_t* ctx,
1233 hwc_display_contents_1_t* list) {
1234
1235 //A-family hw limitation:
1236 //If a layer need alpha scaling, MDP can not support.
1237 if(ctx->mMDP.version < qdutils::MDSS_V5) {
1238 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1239 if(!mCurrentFrame.isFBComposed[i] &&
1240 isAlphaScaled( &list->hwLayers[i])) {
1241 ALOGD_IF(isDebug(), "%s:frame needs alphaScaling",__FUNCTION__);
1242 return false;
1243 }
1244 }
1245 }
1246
1247 // On 8x26 & 8974 hw, we have a limitation of downscaling+blending.
1248 //If multiple layers requires downscaling and also they are overlapping
1249 //fall back to GPU since MDSS can not handle it.
1250 if(qdutils::MDPVersion::getInstance().is8x74v2() ||
1251 qdutils::MDPVersion::getInstance().is8x26()) {
1252 for(int i = 0; i < mCurrentFrame.layerCount-1; ++i) {
1253 hwc_layer_1_t* botLayer = &list->hwLayers[i];
1254 if(!mCurrentFrame.isFBComposed[i] &&
1255 isDownscaleRequired(botLayer)) {
1256 //if layer-i is marked for MDP and needs downscaling
1257 //check if any MDP layer on top of i & overlaps with layer-i
1258 for(int j = i+1; j < mCurrentFrame.layerCount; ++j) {
1259 hwc_layer_1_t* topLayer = &list->hwLayers[j];
1260 if(!mCurrentFrame.isFBComposed[j] &&
1261 isDownscaleRequired(topLayer)) {
1262 hwc_rect_t r = getIntersection(botLayer->displayFrame,
1263 topLayer->displayFrame);
1264 if(isValidRect(r))
1265 return false;
1266 }
1267 }
1268 }
1269 }
1270 }
1271 return true;
1272}
1273
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001274int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001275 int ret = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -07001276 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -07001277
Raj Kamal9ed3d6b2014-02-07 16:15:17 +05301278 //Do not cache the information for next draw cycle.
1279 if(numLayers > MAX_NUM_APP_LAYERS or (!numLayers)) {
1280 ALOGI("%s: Unsupported layer count for mdp composition",
1281 __FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001282 mCachedFrame.reset();
1283 return -1;
1284 }
1285
Saurabh Shahb39f8152013-08-22 10:21:44 -07001286 //reset old data
1287 mCurrentFrame.reset(numLayers);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001288 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1289 mCurrentFrame.dropCount = 0;
Prabhanjan Kandula088bd892013-07-02 23:47:13 +05301290
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -07001291 // Detect the start of animation and fall back to GPU only once to cache
1292 // all the layers in FB and display FB content untill animation completes.
1293 if(ctx->listStats[mDpy].isDisplayAnimating) {
1294 mCurrentFrame.needsRedraw = false;
1295 if(ctx->mAnimationState[mDpy] == ANIMATION_STOPPED) {
1296 mCurrentFrame.needsRedraw = true;
1297 ctx->mAnimationState[mDpy] = ANIMATION_STARTED;
1298 }
1299 setMDPCompLayerFlags(ctx, list);
1300 mCachedFrame.updateCounts(mCurrentFrame);
1301 ret = -1;
1302 return ret;
1303 } else {
1304 ctx->mAnimationState[mDpy] = ANIMATION_STOPPED;
1305 }
1306
Saurabh Shahb39f8152013-08-22 10:21:44 -07001307 //Hard conditions, if not met, cannot do MDP comp
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001308 if(isFrameDoable(ctx)) {
1309 generateROI(ctx, list);
Saurabh Shahb39f8152013-08-22 10:21:44 -07001310
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001311 if(tryFullFrame(ctx, list) || tryVideoOnly(ctx, list)) {
1312 setMDPCompLayerFlags(ctx, list);
1313 } else {
1314 reset(ctx);
1315 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1316 mCurrentFrame.dropCount = 0;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001317 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001318 }
1319 } else {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001320 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
1321 __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001322 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001323 }
Saurabh Shahb39f8152013-08-22 10:21:44 -07001324
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001325 if(isDebug()) {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001326 ALOGD("GEOMETRY change: %d",
1327 (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001328 android::String8 sDump("");
1329 dump(sDump);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001330 ALOGD("%s",sDump.string());
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001331 }
1332
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001333 mCachedFrame.cacheAll(list);
1334 mCachedFrame.updateCounts(mCurrentFrame);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001335 return ret;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001336}
1337
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001338bool MDPComp::allocSplitVGPipesfor4k2k(hwc_context_t *ctx, int index) {
radhakrishnac9a67412013-09-25 17:40:42 +05301339
1340 bool bRet = true;
radhakrishnac9a67412013-09-25 17:40:42 +05301341 int mdpIndex = mCurrentFrame.layerToMDP[index];
1342 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
1343 info.pipeInfo = new MdpYUVPipeInfo;
1344 info.rot = NULL;
1345 MdpYUVPipeInfo& pipe_info = *(MdpYUVPipeInfo*)info.pipeInfo;
1346 ePipeType type = MDPCOMP_OV_VG;
1347
1348 pipe_info.lIndex = ovutils::OV_INVALID;
1349 pipe_info.rIndex = ovutils::OV_INVALID;
1350
1351 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
1352 if(pipe_info.lIndex == ovutils::OV_INVALID){
1353 bRet = false;
1354 ALOGD_IF(isDebug(),"%s: allocating first VG pipe failed",
1355 __FUNCTION__);
1356 }
1357 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
1358 if(pipe_info.rIndex == ovutils::OV_INVALID){
1359 bRet = false;
1360 ALOGD_IF(isDebug(),"%s: allocating second VG pipe failed",
1361 __FUNCTION__);
1362 }
1363 return bRet;
1364}
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001365//=============MDPCompNonSplit==================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001366
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001367void MDPCompNonSplit::adjustForSourceSplit(hwc_context_t *ctx,
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001368 hwc_display_contents_1_t*) {
radhakrishnac9a67412013-09-25 17:40:42 +05301369 //As we split 4kx2k yuv layer and program to 2 VG pipes
1370 //(if available) increase mdpcount accordingly
1371 mCurrentFrame.mdpCount += ctx->listStats[mDpy].yuv4k2kCount;
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001372
1373 //If 4k2k Yuv layer split is possible, and if
1374 //fbz is above 4k2k layer, increment fb zorder by 1
1375 //as we split 4k2k layer and increment zorder for right half
1376 //of the layer
1377 if(mCurrentFrame.fbZ >= 0) {
1378 int n4k2kYuvCount = ctx->listStats[mDpy].yuv4k2kCount;
1379 for(int index = 0; index < n4k2kYuvCount; index++){
1380 int n4k2kYuvIndex =
1381 ctx->listStats[mDpy].yuv4k2kIndices[index];
Dileep Kumar Reddi4cff9282014-04-01 12:57:08 +05301382 if(mCurrentFrame.fbZ >= n4k2kYuvIndex){
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001383 mCurrentFrame.fbZ += 1;
1384 }
1385 }
1386 }
radhakrishnac9a67412013-09-25 17:40:42 +05301387}
1388
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001389/*
1390 * Configures pipe(s) for MDP composition
1391 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001392int MDPCompNonSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001393 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001394 MdpPipeInfoNonSplit& mdp_info =
1395 *(static_cast<MdpPipeInfoNonSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001396 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
1397 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1398 eIsFg isFg = IS_FG_OFF;
1399 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001400
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001401 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
1402 __FUNCTION__, layer, zOrder, dest);
1403
Saurabh Shah88e4d272013-09-03 13:31:29 -07001404 return configureNonSplit(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001405 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001406}
1407
Saurabh Shah88e4d272013-09-03 13:31:29 -07001408bool MDPCompNonSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001409 hwc_display_contents_1_t* list) {
1410 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001411
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001412 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001413
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001414 hwc_layer_1_t* layer = &list->hwLayers[index];
1415 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301416 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001417 if(allocSplitVGPipesfor4k2k(ctx, index)){
radhakrishnac9a67412013-09-25 17:40:42 +05301418 continue;
1419 }
1420 }
1421
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001422 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001423 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001424 info.pipeInfo = new MdpPipeInfoNonSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08001425 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001426 MdpPipeInfoNonSplit& pipe_info = *(MdpPipeInfoNonSplit*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001427 ePipeType type = MDPCOMP_OV_ANY;
1428
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001429 if(isYuvBuffer(hnd)) {
1430 type = MDPCOMP_OV_VG;
Prabhanjan Kandula47191dc2014-01-22 23:01:45 +05301431 } else if(qdutils::MDPVersion::getInstance().is8x26() &&
1432 (ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres > 1024)) {
1433 if(qhwc::needsScaling(layer))
1434 type = MDPCOMP_OV_RGB;
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301435 } else if(!qhwc::needsScaling(layer)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001436 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
1437 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001438 type = MDPCOMP_OV_DMA;
radhakrishna2e792f92014-03-13 11:39:33 +05301439 } else if(qhwc::needsScaling(layer) &&
1440 !(ctx->listStats[mDpy].yuvCount) &&
1441 ! qdutils::MDPVersion::getInstance().isRGBScalarSupported()){
1442 type = MDPCOMP_OV_VG;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001443 }
1444
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001445 pipe_info.index = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001446 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001447 ALOGD_IF(isDebug(), "%s: Unable to get pipe type = %d",
1448 __FUNCTION__, (int) type);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001449 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001450 }
1451 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001452 return true;
1453}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001454
radhakrishnac9a67412013-09-25 17:40:42 +05301455int MDPCompNonSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1456 PipeLayerPair& PipeLayerPair) {
1457 MdpYUVPipeInfo& mdp_info =
1458 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1459 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1460 eIsFg isFg = IS_FG_OFF;
1461 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1462 eDest lDest = mdp_info.lIndex;
1463 eDest rDest = mdp_info.rIndex;
1464
1465 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1466 lDest, rDest, &PipeLayerPair.rot);
1467}
1468
Saurabh Shah88e4d272013-09-03 13:31:29 -07001469bool MDPCompNonSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001470
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001471 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001472 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1473 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -08001474 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001475
1476 if(!ctx || !list) {
1477 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001478 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001479 }
1480
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301481 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1482 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1483 return true;
1484 }
1485
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -08001486 // Set the Handle timeout to true for MDP or MIXED composition.
1487 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount) {
1488 sHandleTimeout = true;
1489 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001490
1491 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001492 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001493
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001494 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1495 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001496 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001497 if(mCurrentFrame.isFBComposed[i]) continue;
1498
Naseer Ahmed5b6708a2012-08-02 13:46:08 -07001499 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001500 private_handle_t *hnd = (private_handle_t *)layer->handle;
1501 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001502 if (!(layer->flags & HWC_COLOR_FILL)) {
1503 ALOGE("%s handle null", __FUNCTION__);
1504 return false;
1505 }
1506 // No PLAY for Color layer
1507 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1508 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001509 }
1510
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001511 int mdpIndex = mCurrentFrame.layerToMDP[i];
1512
radhakrishnac9a67412013-09-25 17:40:42 +05301513 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1514 {
1515 MdpYUVPipeInfo& pipe_info =
1516 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1517 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1518 ovutils::eDest indexL = pipe_info.lIndex;
1519 ovutils::eDest indexR = pipe_info.rIndex;
1520 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301521 uint32_t offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05301522 if(rot) {
1523 rot->queueBuffer(fd, offset);
1524 fd = rot->getDstMemId();
1525 offset = rot->getDstOffset();
1526 }
1527 if(indexL != ovutils::OV_INVALID) {
1528 ovutils::eDest destL = (ovutils::eDest)indexL;
1529 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1530 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1531 if (!ov.queueBuffer(fd, offset, destL)) {
1532 ALOGE("%s: queueBuffer failed for display:%d",
1533 __FUNCTION__, mDpy);
1534 return false;
1535 }
1536 }
1537
1538 if(indexR != ovutils::OV_INVALID) {
1539 ovutils::eDest destR = (ovutils::eDest)indexR;
1540 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1541 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1542 if (!ov.queueBuffer(fd, offset, destR)) {
1543 ALOGE("%s: queueBuffer failed for display:%d",
1544 __FUNCTION__, mDpy);
1545 return false;
1546 }
1547 }
1548 }
1549 else{
1550 MdpPipeInfoNonSplit& pipe_info =
Saurabh Shah88e4d272013-09-03 13:31:29 -07001551 *(MdpPipeInfoNonSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
radhakrishnac9a67412013-09-25 17:40:42 +05301552 ovutils::eDest dest = pipe_info.index;
1553 if(dest == ovutils::OV_INVALID) {
1554 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001555 return false;
radhakrishnac9a67412013-09-25 17:40:42 +05301556 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001557
radhakrishnac9a67412013-09-25 17:40:42 +05301558 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1559 continue;
1560 }
1561
1562 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1563 using pipe: %d", __FUNCTION__, layer,
1564 hnd, dest );
1565
1566 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301567 uint32_t offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05301568
1569 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1570 if(rot) {
1571 if(!rot->queueBuffer(fd, offset))
1572 return false;
1573 fd = rot->getDstMemId();
1574 offset = rot->getDstOffset();
1575 }
1576
1577 if (!ov.queueBuffer(fd, offset, dest)) {
1578 ALOGE("%s: queueBuffer failed for display:%d ",
1579 __FUNCTION__, mDpy);
1580 return false;
1581 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001582 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001583
1584 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001585 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001586 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001587}
1588
Saurabh Shah88e4d272013-09-03 13:31:29 -07001589//=============MDPCompSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001590
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001591void MDPCompSplit::adjustForSourceSplit(hwc_context_t *ctx,
radhakrishnac9a67412013-09-25 17:40:42 +05301592 hwc_display_contents_1_t* list){
1593 //if 4kx2k yuv layer is totally present in either in left half
1594 //or right half then try splitting the yuv layer to avoid decimation
1595 int n4k2kYuvCount = ctx->listStats[mDpy].yuv4k2kCount;
1596 const int lSplit = getLeftSplit(ctx, mDpy);
1597 for(int index = 0; index < n4k2kYuvCount; index++){
1598 int n4k2kYuvIndex = ctx->listStats[mDpy].yuv4k2kIndices[index];
1599 hwc_layer_1_t* layer = &list->hwLayers[n4k2kYuvIndex];
1600 hwc_rect_t dst = layer->displayFrame;
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001601 if((dst.left > lSplit) || (dst.right < lSplit)) {
radhakrishnac9a67412013-09-25 17:40:42 +05301602 mCurrentFrame.mdpCount += 1;
1603 }
Dileep Kumar Reddi4cff9282014-04-01 12:57:08 +05301604 if(mCurrentFrame.fbZ >= n4k2kYuvIndex){
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001605 mCurrentFrame.fbZ += 1;
1606 }
radhakrishnac9a67412013-09-25 17:40:42 +05301607 }
1608}
1609
Saurabh Shah88e4d272013-09-03 13:31:29 -07001610bool MDPCompSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
1611 MdpPipeInfoSplit& pipe_info,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001612 ePipeType type) {
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001613 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001614
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001615 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001616 pipe_info.lIndex = ovutils::OV_INVALID;
1617 pipe_info.rIndex = ovutils::OV_INVALID;
1618
1619 if (dst.left < lSplit) {
1620 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_LEFT);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001621 if(pipe_info.lIndex == ovutils::OV_INVALID)
1622 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001623 }
1624
1625 if(dst.right > lSplit) {
1626 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_RIGHT);
1627 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001628 return false;
1629 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001630
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001631 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001632}
1633
Saurabh Shah88e4d272013-09-03 13:31:29 -07001634bool MDPCompSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001635 hwc_display_contents_1_t* list) {
1636 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001637
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001638 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001639
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001640 hwc_layer_1_t* layer = &list->hwLayers[index];
1641 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301642 hwc_rect_t dst = layer->displayFrame;
1643 const int lSplit = getLeftSplit(ctx, mDpy);
1644 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1645 if((dst.left > lSplit)||(dst.right < lSplit)){
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001646 if(allocSplitVGPipesfor4k2k(ctx, index)){
radhakrishnac9a67412013-09-25 17:40:42 +05301647 continue;
1648 }
1649 }
1650 }
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001651 int mdpIndex = mCurrentFrame.layerToMDP[index];
1652 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001653 info.pipeInfo = new MdpPipeInfoSplit;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001654 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001655 MdpPipeInfoSplit& pipe_info = *(MdpPipeInfoSplit*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001656 ePipeType type = MDPCOMP_OV_ANY;
1657
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001658 if(isYuvBuffer(hnd)) {
1659 type = MDPCOMP_OV_VG;
Sushil Chauhan15a2ea62013-09-04 18:28:36 -07001660 } else if(!qhwc::needsScalingWithSplit(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001661 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001662 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001663 type = MDPCOMP_OV_DMA;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001664 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001665
1666 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001667 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type = %d",
1668 __FUNCTION__, (int) type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001669 return false;
1670 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001671 }
1672 return true;
1673}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001674
radhakrishnac9a67412013-09-25 17:40:42 +05301675int MDPCompSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1676 PipeLayerPair& PipeLayerPair) {
1677 const int lSplit = getLeftSplit(ctx, mDpy);
1678 hwc_rect_t dst = layer->displayFrame;
1679 if((dst.left > lSplit)||(dst.right < lSplit)){
1680 MdpYUVPipeInfo& mdp_info =
1681 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1682 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1683 eIsFg isFg = IS_FG_OFF;
1684 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1685 eDest lDest = mdp_info.lIndex;
1686 eDest rDest = mdp_info.rIndex;
1687
1688 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1689 lDest, rDest, &PipeLayerPair.rot);
1690 }
1691 else{
1692 return configure(ctx, layer, PipeLayerPair);
1693 }
1694}
1695
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001696/*
1697 * Configures pipe(s) for MDP composition
1698 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001699int MDPCompSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001700 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001701 MdpPipeInfoSplit& mdp_info =
1702 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001703 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1704 eIsFg isFg = IS_FG_OFF;
1705 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1706 eDest lDest = mdp_info.lIndex;
1707 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001708
1709 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1710 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1711
Saurabh Shah88e4d272013-09-03 13:31:29 -07001712 return configureSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001713 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001714}
1715
Saurabh Shah88e4d272013-09-03 13:31:29 -07001716bool MDPCompSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001717
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001718 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001719 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1720 return true;
1721 }
1722
1723 if(!ctx || !list) {
1724 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001725 return false;
1726 }
1727
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301728 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1729 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1730 return true;
1731 }
1732
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -08001733 // Set the Handle timeout to true for MDP or MIXED composition.
1734 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount) {
1735 sHandleTimeout = true;
1736 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001737
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001738 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001739 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001740
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001741 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1742 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001743 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001744 if(mCurrentFrame.isFBComposed[i]) continue;
1745
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001746 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001747 private_handle_t *hnd = (private_handle_t *)layer->handle;
1748 if(!hnd) {
1749 ALOGE("%s handle null", __FUNCTION__);
1750 return false;
1751 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001752
1753 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1754 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001755 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001756
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001757 int mdpIndex = mCurrentFrame.layerToMDP[i];
1758
radhakrishnac9a67412013-09-25 17:40:42 +05301759 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1760 {
1761 MdpYUVPipeInfo& pipe_info =
1762 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1763 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1764 ovutils::eDest indexL = pipe_info.lIndex;
1765 ovutils::eDest indexR = pipe_info.rIndex;
1766 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301767 uint32_t offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05301768 if(rot) {
1769 rot->queueBuffer(fd, offset);
1770 fd = rot->getDstMemId();
1771 offset = rot->getDstOffset();
1772 }
1773 if(indexL != ovutils::OV_INVALID) {
1774 ovutils::eDest destL = (ovutils::eDest)indexL;
1775 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1776 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1777 if (!ov.queueBuffer(fd, offset, destL)) {
1778 ALOGE("%s: queueBuffer failed for display:%d",
1779 __FUNCTION__, mDpy);
1780 return false;
1781 }
1782 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001783
radhakrishnac9a67412013-09-25 17:40:42 +05301784 if(indexR != ovutils::OV_INVALID) {
1785 ovutils::eDest destR = (ovutils::eDest)indexR;
1786 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1787 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1788 if (!ov.queueBuffer(fd, offset, destR)) {
1789 ALOGE("%s: queueBuffer failed for display:%d",
1790 __FUNCTION__, mDpy);
1791 return false;
1792 }
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001793 }
1794 }
radhakrishnac9a67412013-09-25 17:40:42 +05301795 else{
1796 MdpPipeInfoSplit& pipe_info =
1797 *(MdpPipeInfoSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1798 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001799
radhakrishnac9a67412013-09-25 17:40:42 +05301800 ovutils::eDest indexL = pipe_info.lIndex;
1801 ovutils::eDest indexR = pipe_info.rIndex;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001802
radhakrishnac9a67412013-09-25 17:40:42 +05301803 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301804 int offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05301805
1806 if(ctx->mAD->isModeOn()) {
1807 if(ctx->mAD->draw(ctx, fd, offset)) {
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001808 fd = ctx->mAD->getDstFd();
1809 offset = ctx->mAD->getDstOffset();
radhakrishnac9a67412013-09-25 17:40:42 +05301810 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001811 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001812
radhakrishnac9a67412013-09-25 17:40:42 +05301813 if(rot) {
1814 rot->queueBuffer(fd, offset);
1815 fd = rot->getDstMemId();
1816 offset = rot->getDstOffset();
1817 }
1818
1819 //************* play left mixer **********
1820 if(indexL != ovutils::OV_INVALID) {
1821 ovutils::eDest destL = (ovutils::eDest)indexL;
1822 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1823 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1824 if (!ov.queueBuffer(fd, offset, destL)) {
1825 ALOGE("%s: queueBuffer failed for left mixer",
1826 __FUNCTION__);
1827 return false;
1828 }
1829 }
1830
1831 //************* play right mixer **********
1832 if(indexR != ovutils::OV_INVALID) {
1833 ovutils::eDest destR = (ovutils::eDest)indexR;
1834 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1835 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1836 if (!ov.queueBuffer(fd, offset, destR)) {
1837 ALOGE("%s: queueBuffer failed for right mixer",
1838 __FUNCTION__);
1839 return false;
1840 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001841 }
1842 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001843
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001844 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1845 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001846
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001847 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001848}
Saurabh Shahab47c692014-02-12 18:45:57 -08001849
1850//================MDPCompSrcSplit==============================================
1851bool MDPCompSrcSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Saurabh Shahdd8237a2014-02-28 14:29:09 -08001852 MdpPipeInfoSplit& pipe_info, ePipeType type) {
Saurabh Shahab47c692014-02-12 18:45:57 -08001853 private_handle_t *hnd = (private_handle_t *)layer->handle;
1854 hwc_rect_t dst = layer->displayFrame;
1855 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
1856 pipe_info.lIndex = ovutils::OV_INVALID;
1857 pipe_info.rIndex = ovutils::OV_INVALID;
1858
1859 //If 2 pipes are staged on a single stage of a mixer, then the left pipe
1860 //should have a higher priority than the right one. Pipe priorities are
1861 //starting with VG0, VG1 ... , RGB0 ..., DMA1
Saurabh Shahab47c692014-02-12 18:45:57 -08001862
1863 //1 pipe by default for a layer
Saurabh Shahdd8237a2014-02-28 14:29:09 -08001864 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
Saurabh Shahab47c692014-02-12 18:45:57 -08001865 if(pipe_info.lIndex == ovutils::OV_INVALID) {
1866 if(isYuvBuffer(hnd)) {
1867 return false;
1868 }
1869 pipe_info.lIndex = getMdpPipe(ctx, MDPCOMP_OV_ANY,
1870 Overlay::MIXER_DEFAULT);
1871 if(pipe_info.lIndex == ovutils::OV_INVALID) {
1872 return false;
1873 }
1874 }
1875
1876 //If layer's crop width or dest width > 2048, use 2 pipes
1877 if((dst.right - dst.left) > qdutils::MAX_DISPLAY_DIM or
1878 (crop.right - crop.left) > qdutils::MAX_DISPLAY_DIM) {
Saurabh Shahdd8237a2014-02-28 14:29:09 -08001879 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
Saurabh Shahab47c692014-02-12 18:45:57 -08001880 if(pipe_info.rIndex == ovutils::OV_INVALID) {
Saurabh Shahdd8237a2014-02-28 14:29:09 -08001881 if(isYuvBuffer(hnd)) {
1882 return false;
1883 }
1884 pipe_info.rIndex = getMdpPipe(ctx, MDPCOMP_OV_ANY,
1885 Overlay::MIXER_DEFAULT);
1886 if(pipe_info.rIndex == ovutils::OV_INVALID) {
1887 return false;
1888 }
1889 }
1890
1891 // Return values
1892 // 1 Left pipe is higher priority, do nothing.
1893 // 0 Pipes of same priority.
1894 //-1 Right pipe is of higher priority, needs swap.
1895 if(ctx->mOverlay->comparePipePriority(pipe_info.lIndex,
1896 pipe_info.rIndex) == -1) {
1897 qhwc::swap(pipe_info.lIndex, pipe_info.rIndex);
Saurabh Shahab47c692014-02-12 18:45:57 -08001898 }
1899 }
1900
1901 return true;
1902}
1903
Saurabh Shahab47c692014-02-12 18:45:57 -08001904int MDPCompSrcSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
1905 PipeLayerPair& PipeLayerPair) {
1906 private_handle_t *hnd = (private_handle_t *)layer->handle;
1907 if(!hnd) {
1908 ALOGE("%s: layer handle is NULL", __FUNCTION__);
1909 return -1;
1910 }
1911 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
1912 MdpPipeInfoSplit& mdp_info =
1913 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
1914 Rotator **rot = &PipeLayerPair.rot;
1915 eZorder z = static_cast<eZorder>(mdp_info.zOrder);
1916 eIsFg isFg = IS_FG_OFF;
1917 eDest lDest = mdp_info.lIndex;
1918 eDest rDest = mdp_info.rIndex;
1919 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
1920 hwc_rect_t dst = layer->displayFrame;
1921 int transform = layer->transform;
1922 eTransform orient = static_cast<eTransform>(transform);
1923 const int downscale = 0;
1924 int rotFlags = ROT_FLAGS_NONE;
1925 uint32_t format = ovutils::getMdpFormat(hnd->format, isTileRendered(hnd));
1926 Whf whf(getWidth(hnd), getHeight(hnd), format, hnd->size);
1927
1928 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1929 "dest_pipeR: %d",__FUNCTION__, layer, z, lDest, rDest);
1930
1931 // Handle R/B swap
1932 if (layer->flags & HWC_FORMAT_RB_SWAP) {
1933 if (hnd->format == HAL_PIXEL_FORMAT_RGBA_8888)
1934 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRA_8888);
1935 else if (hnd->format == HAL_PIXEL_FORMAT_RGBX_8888)
1936 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRX_8888);
1937 }
1938
1939 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1940 setMdpFlags(layer, mdpFlagsL, 0, transform);
1941 eMdpFlags mdpFlagsR = mdpFlagsL;
1942
1943 if(lDest != OV_INVALID && rDest != OV_INVALID) {
1944 //Enable overfetch
1945 setMdpFlags(mdpFlagsL, OV_MDSS_MDP_DUAL_PIPE);
1946 }
1947
1948 if(isYuvBuffer(hnd) && (transform & HWC_TRANSFORM_ROT_90)) {
1949 (*rot) = ctx->mRotMgr->getNext();
1950 if((*rot) == NULL) return -1;
1951 //Configure rotator for pre-rotation
1952 if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale) < 0) {
1953 ALOGE("%s: configRotator failed!", __FUNCTION__);
1954 return -1;
1955 }
1956 ctx->mLayerRotMap[mDpy]->add(layer, *rot);
1957 whf.format = (*rot)->getDstFormat();
1958 updateSource(orient, whf, crop);
1959 rotFlags |= ROT_PREROTATED;
1960 }
1961
1962 //If 2 pipes being used, divide layer into half, crop and dst
1963 hwc_rect_t cropL = crop;
1964 hwc_rect_t cropR = crop;
1965 hwc_rect_t dstL = dst;
1966 hwc_rect_t dstR = dst;
1967 if(lDest != OV_INVALID && rDest != OV_INVALID) {
1968 cropL.right = (crop.right + crop.left) / 2;
1969 cropR.left = cropL.right;
1970 sanitizeSourceCrop(cropL, cropR, hnd);
1971
1972 //Swap crops on H flip since 2 pipes are being used
1973 if((orient & OVERLAY_TRANSFORM_FLIP_H) && (*rot) == NULL) {
1974 hwc_rect_t tmp = cropL;
1975 cropL = cropR;
1976 cropR = tmp;
1977 }
1978
1979 dstL.right = (dst.right + dst.left) / 2;
1980 dstR.left = dstL.right;
1981 }
1982
1983 //For the mdp, since either we are pre-rotating or MDP does flips
1984 orient = OVERLAY_TRANSFORM_0;
1985 transform = 0;
1986
1987 //configure left pipe
1988 if(lDest != OV_INVALID) {
1989 PipeArgs pargL(mdpFlagsL, whf, z, isFg,
1990 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
1991 (ovutils::eBlending) getBlending(layer->blending));
1992
1993 if(configMdp(ctx->mOverlay, pargL, orient,
1994 cropL, dstL, metadata, lDest) < 0) {
1995 ALOGE("%s: commit failed for left mixer config", __FUNCTION__);
1996 return -1;
1997 }
1998 }
1999
2000 //configure right pipe
2001 if(rDest != OV_INVALID) {
2002 PipeArgs pargR(mdpFlagsR, whf, z, isFg,
2003 static_cast<eRotFlags>(rotFlags),
2004 layer->planeAlpha,
2005 (ovutils::eBlending) getBlending(layer->blending));
2006 if(configMdp(ctx->mOverlay, pargR, orient,
2007 cropR, dstR, metadata, rDest) < 0) {
2008 ALOGE("%s: commit failed for right mixer config", __FUNCTION__);
2009 return -1;
2010 }
2011 }
2012
2013 return 0;
2014}
2015
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002016}; //namespace
2017