blob: 69d4f09850cbc6d81229e13e991455b6a268b9f6 [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
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800396bool MDPComp::isFrameDoable(hwc_context_t *ctx) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700397 bool ret = true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800398
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800399 if(!isEnabled()) {
400 ALOGD_IF(isDebug(),"%s: MDP Comp. not enabled.", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700401 ret = false;
Saurabh Shahd4e65852013-06-17 11:33:53 -0700402 } else if(qdutils::MDPVersion::getInstance().is8x26() &&
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -0800403 ctx->mVideoTransFlag &&
404 isSecondaryConnected(ctx)) {
Saurabh Shahd4e65852013-06-17 11:33:53 -0700405 //1 Padding round to shift pipes across mixers
406 ALOGD_IF(isDebug(),"%s: MDP Comp. video transition padding round",
407 __FUNCTION__);
408 ret = false;
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -0800409 } else if(isSecondaryConfiguring(ctx)) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800410 ALOGD_IF( isDebug(),"%s: External Display connection is pending",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800411 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700412 ret = false;
Saurabh Shahaa236822013-04-24 18:07:26 -0700413 } else if(ctx->isPaddingRound) {
Raj Kamal9ed3d6b2014-02-07 16:15:17 +0530414 ALOGD_IF(isDebug(), "%s: padding round invoked for dpy %d",
415 __FUNCTION__,mDpy);
Saurabh Shahaa236822013-04-24 18:07:26 -0700416 ret = false;
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700417 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700418 return ret;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800419}
420
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800421/*
422 * 1) Identify layers that are not visible in the updating ROI and drop them
423 * from composition.
424 * 2) If we have a scaling layers which needs cropping against generated ROI.
425 * Reset ROI to full resolution.
426 */
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700427bool MDPComp::validateAndApplyROI(hwc_context_t *ctx,
428 hwc_display_contents_1_t* list, hwc_rect_t roi) {
429 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
430
431 if(!isValidRect(roi))
432 return false;
433
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800434 hwc_rect_t visibleRect = roi;
435
436 for(int i = numAppLayers - 1; i >= 0; i--){
437
438 if(!isValidRect(visibleRect)) {
439 mCurrentFrame.drop[i] = true;
440 mCurrentFrame.dropCount++;
Jeykumar Sankaran0b961452014-01-21 17:26:12 -0800441 continue;
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800442 }
443
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700444 const hwc_layer_1_t* layer = &list->hwLayers[i];
445
446 hwc_rect_t dstRect = layer->displayFrame;
Arun Kumar K.R91090c72013-10-28 19:40:18 -0700447 hwc_rect_t srcRect = integerizeSourceCrop(layer->sourceCropf);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700448
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800449 hwc_rect_t res = getIntersection(visibleRect, dstRect);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700450
451 int res_w = res.right - res.left;
452 int res_h = res.bottom - res.top;
453 int dst_w = dstRect.right - dstRect.left;
454 int dst_h = dstRect.bottom - dstRect.top;
455
456 if(!isValidRect(res)) {
457 mCurrentFrame.drop[i] = true;
458 mCurrentFrame.dropCount++;
459 }else {
460 /* Reset frame ROI when any layer which needs scaling also needs ROI
461 * cropping */
Jeykumar Sankaran0b961452014-01-21 17:26:12 -0800462 if((res_w != dst_w || res_h != dst_h) && needsScaling (layer)) {
Arpita Banerjeed8965982013-11-08 17:27:33 -0800463 ALOGI("%s: Resetting ROI due to scaling", __FUNCTION__);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700464 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
465 mCurrentFrame.dropCount = 0;
466 return false;
467 }
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800468
Jeykumar Sankaran0b961452014-01-21 17:26:12 -0800469 /* deduct any opaque region from visibleRect */
470 if (layer->blending == HWC_BLENDING_NONE)
471 visibleRect = deductRect(visibleRect, res);
472 }
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700473 }
474 return true;
475}
476
477void MDPComp::generateROI(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
478 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
479
480 if(!sEnablePartialFrameUpdate) {
481 return;
482 }
483
484 if(mDpy || isDisplaySplit(ctx, mDpy)){
485 ALOGE_IF(isDebug(), "%s: ROI not supported for"
486 "the (1) external / virtual display's (2) dual DSI displays",
487 __FUNCTION__);
488 return;
489 }
490
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800491 if(isSkipPresent(ctx, mDpy))
492 return;
493
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700494 if(list->flags & HWC_GEOMETRY_CHANGED)
495 return;
496
497 struct hwc_rect roi = (struct hwc_rect){0, 0, 0, 0};
498 for(int index = 0; index < numAppLayers; index++ ) {
499 if ((mCachedFrame.hnd[index] != list->hwLayers[index].handle) ||
500 isYuvBuffer((private_handle_t *)list->hwLayers[index].handle)) {
501 hwc_rect_t dstRect = list->hwLayers[index].displayFrame;
Arun Kumar K.R91090c72013-10-28 19:40:18 -0700502 hwc_rect_t srcRect = integerizeSourceCrop(
503 list->hwLayers[index].sourceCropf);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700504
505 /* Intersect against display boundaries */
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700506 roi = getUnion(roi, dstRect);
507 }
508 }
509
510 if(!validateAndApplyROI(ctx, list, roi)){
511 roi = (struct hwc_rect) {0, 0,
512 (int)ctx->dpyAttr[mDpy].xres, (int)ctx->dpyAttr[mDpy].yres};
513 }
514
515 ctx->listStats[mDpy].roi.x = roi.left;
516 ctx->listStats[mDpy].roi.y = roi.top;
517 ctx->listStats[mDpy].roi.w = roi.right - roi.left;
518 ctx->listStats[mDpy].roi.h = roi.bottom - roi.top;
519
520 ALOGD_IF(isDebug(),"%s: generated ROI: [%d, %d, %d, %d]", __FUNCTION__,
521 roi.left, roi.top, roi.right, roi.bottom);
522}
523
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800524/* Checks for conditions where all the layers marked for MDP comp cannot be
525 * bypassed. On such conditions we try to bypass atleast YUV layers */
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800526bool MDPComp::tryFullFrame(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800527 hwc_display_contents_1_t* list){
528
Saurabh Shahaa236822013-04-24 18:07:26 -0700529 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Arun Kumar K.R2e2871c2014-01-10 12:47:06 -0800530 int priDispW = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800531
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -0700532 if(sIdleFallBack && !ctx->listStats[mDpy].secureUI) {
Saurabh Shah2d998a92013-05-14 17:55:58 -0700533 ALOGD_IF(isDebug(), "%s: Idle fallback dpy %d",__FUNCTION__, mDpy);
534 return false;
535 }
536
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800537 if(isSkipPresent(ctx, mDpy)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700538 ALOGD_IF(isDebug(),"%s: SKIP present: %d",
539 __FUNCTION__,
540 isSkipPresent(ctx, mDpy));
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800541 return false;
542 }
543
Arun Kumar K.R2e2871c2014-01-10 12:47:06 -0800544 if(mDpy > HWC_DISPLAY_PRIMARY && (priDispW > MAX_DISPLAY_DIM) &&
545 (ctx->dpyAttr[mDpy].xres < MAX_DISPLAY_DIM)) {
546 // Disable MDP comp on Secondary when the primary is highres panel and
547 // the secondary is a normal 1080p, because, MDP comp on secondary under
548 // in such usecase, decimation gets used for downscale and there will be
549 // a quality mismatch when there will be a fallback to GPU comp
550 ALOGD_IF(isDebug(), "%s: Disable MDP Compositon for Secondary Disp",
551 __FUNCTION__);
552 return false;
553 }
554
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800555 // check for action safe flag and downscale mode which requires scaling.
556 if(ctx->dpyAttr[mDpy].mActionSafePresent
557 || ctx->dpyAttr[mDpy].mDownScaleMode) {
558 ALOGD_IF(isDebug(), "%s: Scaling needed for this frame",__FUNCTION__);
559 return false;
560 }
561
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800562 for(int i = 0; i < numAppLayers; ++i) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800563 hwc_layer_1_t* layer = &list->hwLayers[i];
564 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800565
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700566 if(isYuvBuffer(hnd) && has90Transform(layer)) {
567 if(!canUseRotator(ctx, mDpy)) {
568 ALOGD_IF(isDebug(), "%s: Can't use rotator for dpy %d",
569 __FUNCTION__, mDpy);
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700570 return false;
571 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800572 }
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530573
574 //For 8x26 with panel width>1k, if RGB layer needs HFLIP fail mdp comp
575 // may not need it if Gfx pre-rotation can handle all flips & rotations
Sushil Chauhanfda00fc2014-03-20 11:08:41 -0700576 int transform = (layer->flags & HWC_COLOR_FILL) ? 0 : layer->transform;
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530577 if(qdutils::MDPVersion::getInstance().is8x26() &&
578 (ctx->dpyAttr[mDpy].xres > 1024) &&
Sushil Chauhanfda00fc2014-03-20 11:08:41 -0700579 (transform & HWC_TRANSFORM_FLIP_H) &&
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530580 (!isYuvBuffer(hnd)))
581 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800582 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700583
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700584 if(ctx->mAD->isDoable()) {
585 return false;
586 }
587
Saurabh Shahaa236822013-04-24 18:07:26 -0700588 //If all above hard conditions are met we can do full or partial MDP comp.
589 bool ret = false;
590 if(fullMDPComp(ctx, list)) {
591 ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700592 } else if(partialMDPComp(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700593 ret = true;
594 }
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530595
Saurabh Shahaa236822013-04-24 18:07:26 -0700596 return ret;
597}
598
599bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700600 //Will benefit presentation / secondary-only layer.
601 if((mDpy > HWC_DISPLAY_PRIMARY) &&
602 (list->numHwLayers - 1) > MAX_SEC_LAYERS) {
603 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
604 return false;
605 }
606
607 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
608 for(int i = 0; i < numAppLayers; i++) {
609 hwc_layer_1_t* layer = &list->hwLayers[i];
610 if(not isSupportedForMDPComp(ctx, layer)) {
611 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",__FUNCTION__);
612 return false;
613 }
614 }
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800615
Saurabh Shahaa236822013-04-24 18:07:26 -0700616 mCurrentFrame.fbCount = 0;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700617 memcpy(&mCurrentFrame.isFBComposed, &mCurrentFrame.drop,
618 sizeof(mCurrentFrame.isFBComposed));
619 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount -
620 mCurrentFrame.dropCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700621
radhakrishnac9a67412013-09-25 17:40:42 +0530622 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800623 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530624 }
625
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800626 if(!postHeuristicsHandling(ctx, list)) {
627 ALOGD_IF(isDebug(), "post heuristic handling failed");
628 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700629 return false;
630 }
631
Saurabh Shahaa236822013-04-24 18:07:26 -0700632 return true;
633}
634
635bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
636{
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700637 if(!sEnableMixedMode) {
638 //Mixed mode is disabled. No need to even try caching.
639 return false;
640 }
641
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700642 bool ret = false;
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800643 if(list->flags & HWC_GEOMETRY_CHANGED) { //Try load based first
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800644 ret = loadBasedComp(ctx, list) or
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800645 cacheBasedComp(ctx, list);
646 } else {
647 ret = cacheBasedComp(ctx, list) or
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800648 loadBasedComp(ctx, list);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700649 }
650
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700651 return ret;
652}
653
654bool MDPComp::cacheBasedComp(hwc_context_t *ctx,
655 hwc_display_contents_1_t* list) {
656 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700657 mCurrentFrame.reset(numAppLayers);
658 updateLayerCache(ctx, list);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700659
660 //If an MDP marked layer is unsupported cannot do partial MDP Comp
661 for(int i = 0; i < numAppLayers; i++) {
662 if(!mCurrentFrame.isFBComposed[i]) {
663 hwc_layer_1_t* layer = &list->hwLayers[i];
664 if(not isSupportedForMDPComp(ctx, layer)) {
665 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",
666 __FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800667 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700668 return false;
669 }
670 }
671 }
672
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700673 updateYUV(ctx, list, false /*secure only*/);
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530674 bool ret = markLayersForCaching(ctx, list); //sets up fbZ also
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700675 if(!ret) {
676 ALOGD_IF(isDebug(),"%s: batching failed, dpy %d",__FUNCTION__, mDpy);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800677 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700678 return false;
679 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700680
681 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700682
radhakrishnac9a67412013-09-25 17:40:42 +0530683 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800684 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530685 }
686
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700687 //Will benefit cases where a video has non-updating background.
688 if((mDpy > HWC_DISPLAY_PRIMARY) and
689 (mdpCount > MAX_SEC_LAYERS)) {
690 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800691 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700692 return false;
693 }
694
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800695 if(!postHeuristicsHandling(ctx, list)) {
696 ALOGD_IF(isDebug(), "post heuristic handling failed");
697 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700698 return false;
699 }
700
Saurabh Shahaa236822013-04-24 18:07:26 -0700701 return true;
702}
703
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800704bool MDPComp::loadBasedComp(hwc_context_t *ctx,
Saurabh Shahb772ae32013-11-18 15:40:02 -0800705 hwc_display_contents_1_t* list) {
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -0800706 if(not isLoadBasedCompDoable(ctx)) {
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800707 return false;
708 }
709
Saurabh Shahb772ae32013-11-18 15:40:02 -0800710 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800711 const int numNonDroppedLayers = numAppLayers - mCurrentFrame.dropCount;
712 const int stagesForMDP = min(sMaxPipesPerMixer,
713 ctx->mOverlay->availablePipes(mDpy, Overlay::MIXER_DEFAULT));
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800714
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800715 int mdpBatchSize = stagesForMDP - 1; //1 stage for FB
716 int fbBatchSize = numNonDroppedLayers - mdpBatchSize;
717 int lastMDPSupportedIndex = numAppLayers;
718 int dropCount = 0;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800719
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800720 //Find the minimum MDP batch size
721 for(int i = 0; i < numAppLayers;i++) {
722 if(mCurrentFrame.drop[i]) {
723 dropCount++;
Jeykumar Sankaran846e2792014-01-23 21:59:58 -0800724 continue;
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800725 }
726 hwc_layer_1_t* layer = &list->hwLayers[i];
727 if(not isSupportedForMDPComp(ctx, layer)) {
728 lastMDPSupportedIndex = i;
729 mdpBatchSize = min(i - dropCount, stagesForMDP - 1);
730 fbBatchSize = numNonDroppedLayers - mdpBatchSize;
Jeykumar Sankaran846e2792014-01-23 21:59:58 -0800731 break;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800732 }
Saurabh Shahb772ae32013-11-18 15:40:02 -0800733 }
734
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800735 ALOGD_IF(isDebug(), "%s:Before optimizing fbBatch, mdpbatch %d, fbbatch %d "
736 "dropped %d", __FUNCTION__, mdpBatchSize, fbBatchSize,
737 mCurrentFrame.dropCount);
738
739 //Start at a point where the fb batch should at least have 2 layers, for
740 //this mode to be justified.
741 while(fbBatchSize < 2) {
742 ++fbBatchSize;
743 --mdpBatchSize;
Jeykumar Sankaran846e2792014-01-23 21:59:58 -0800744 }
Saurabh Shahb772ae32013-11-18 15:40:02 -0800745
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800746 //If there are no layers for MDP, this mode doesnt make sense.
747 if(mdpBatchSize < 1) {
748 ALOGD_IF(isDebug(), "%s: No MDP layers after optimizing for fbBatch",
749 __FUNCTION__);
Saurabh Shahb772ae32013-11-18 15:40:02 -0800750 return false;
751 }
752
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800753 mCurrentFrame.reset(numAppLayers);
754
755 //Try with successively smaller mdp batch sizes until we succeed or reach 1
756 while(mdpBatchSize > 0) {
757 //Mark layers for MDP comp
758 int mdpBatchLeft = mdpBatchSize;
759 for(int i = 0; i < lastMDPSupportedIndex and mdpBatchLeft; i++) {
760 if(mCurrentFrame.drop[i]) {
761 continue;
762 }
763 mCurrentFrame.isFBComposed[i] = false;
764 --mdpBatchLeft;
765 }
766
767 mCurrentFrame.fbZ = mdpBatchSize;
768 mCurrentFrame.fbCount = fbBatchSize;
769 mCurrentFrame.mdpCount = mdpBatchSize;
770
771 ALOGD_IF(isDebug(), "%s:Trying with: mdpbatch %d fbbatch %d dropped %d",
772 __FUNCTION__, mdpBatchSize, fbBatchSize,
773 mCurrentFrame.dropCount);
774
775 if(postHeuristicsHandling(ctx, list)) {
776 ALOGD_IF(isDebug(), "%s: Postheuristics handling succeeded",
777 __FUNCTION__);
778 return true;
779 }
780
781 reset(ctx);
782 --mdpBatchSize;
783 ++fbBatchSize;
784 }
785
786 return false;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800787}
788
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -0800789bool MDPComp::isLoadBasedCompDoable(hwc_context_t *ctx) {
Prabhanjan Kandula3dbbd882013-12-11 14:43:46 +0530790 if(mDpy or isSecurePresent(ctx, mDpy) or
791 isYuvPresent(ctx, mDpy)) {
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700792 return false;
793 }
794 return true;
795}
796
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800797bool MDPComp::tryVideoOnly(hwc_context_t *ctx,
798 hwc_display_contents_1_t* list) {
799 const bool secureOnly = true;
800 return videoOnlyComp(ctx, list, not secureOnly) or
801 videoOnlyComp(ctx, list, secureOnly);
802}
803
804bool MDPComp::videoOnlyComp(hwc_context_t *ctx,
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700805 hwc_display_contents_1_t* list, bool secureOnly) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700806 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700807
Saurabh Shahaa236822013-04-24 18:07:26 -0700808 mCurrentFrame.reset(numAppLayers);
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700809 updateYUV(ctx, list, secureOnly);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700810 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700811
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800812 if(!isYuvPresent(ctx, mDpy) or (mdpCount == 0)) {
813 reset(ctx);
Saurabh Shahaa236822013-04-24 18:07:26 -0700814 return false;
815 }
816
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -0800817 /* Bail out if we are processing only secured video layers
818 * and we dont have any */
819 if(!isSecurePresent(ctx, mDpy) && secureOnly){
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800820 reset(ctx);
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -0800821 return false;
822 }
823
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800824 if(mCurrentFrame.fbCount)
825 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
Saurabh Shah4fdde762013-04-30 18:47:33 -0700826
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800827 if(sEnable4k2kYUVSplit){
828 adjustForSourceSplit(ctx, list);
829 }
830
831 if(!postHeuristicsHandling(ctx, list)) {
832 ALOGD_IF(isDebug(), "post heuristic handling failed");
833 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700834 return false;
835 }
836
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800837 return true;
838}
839
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800840/* Checks for conditions where YUV layers cannot be bypassed */
841bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -0700842 if(isSkipLayer(layer)) {
Saurabh Shahe2474082013-05-15 16:32:13 -0700843 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800844 return false;
845 }
846
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700847 if(layer->transform & HWC_TRANSFORM_ROT_90 && !canUseRotator(ctx,mDpy)) {
848 ALOGD_IF(isDebug(), "%s: no free DMA pipe",__FUNCTION__);
849 return false;
850 }
851
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800852 if(isSecuring(ctx, layer)) {
853 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
854 return false;
855 }
856
Saurabh Shah4fdde762013-04-30 18:47:33 -0700857 if(!isValidDimension(ctx, layer)) {
858 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
859 __FUNCTION__);
860 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800861 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700862
Naseer Ahmeddc61a972013-07-10 17:50:54 -0400863 if(layer->planeAlpha < 0xFF) {
864 ALOGD_IF(isDebug(), "%s: Cannot handle YUV layer with plane alpha\
865 in video only mode",
866 __FUNCTION__);
867 return false;
868 }
869
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800870 return true;
871}
872
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530873/* starts at fromIndex and check for each layer to find
874 * if it it has overlapping with any Updating layer above it in zorder
875 * till the end of the batch. returns true if it finds any intersection */
876bool MDPComp::canPushBatchToTop(const hwc_display_contents_1_t* list,
877 int fromIndex, int toIndex) {
878 for(int i = fromIndex; i < toIndex; i++) {
879 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
880 if(intersectingUpdatingLayers(list, i+1, toIndex, i)) {
881 return false;
882 }
883 }
884 }
885 return true;
886}
887
888/* Checks if given layer at targetLayerIndex has any
889 * intersection with all the updating layers in beween
890 * fromIndex and toIndex. Returns true if it finds intersectiion */
891bool MDPComp::intersectingUpdatingLayers(const hwc_display_contents_1_t* list,
892 int fromIndex, int toIndex, int targetLayerIndex) {
893 for(int i = fromIndex; i <= toIndex; i++) {
894 if(!mCurrentFrame.isFBComposed[i]) {
895 if(areLayersIntersecting(&list->hwLayers[i],
896 &list->hwLayers[targetLayerIndex])) {
897 return true;
898 }
899 }
900 }
901 return false;
902}
903
904int MDPComp::getBatch(hwc_display_contents_1_t* list,
905 int& maxBatchStart, int& maxBatchEnd,
906 int& maxBatchCount) {
907 int i = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530908 int fbZOrder =-1;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -0800909 int droppedLayerCt = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530910 while (i < mCurrentFrame.layerCount) {
911 int batchCount = 0;
912 int batchStart = i;
913 int batchEnd = i;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -0800914 /* Adjust batch Z order with the dropped layers so far */
915 int fbZ = batchStart - droppedLayerCt;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530916 int firstZReverseIndex = -1;
Prabhanjan Kandula0ed2cc92013-12-06 12:39:04 +0530917 int updatingLayersAbove = 0;//Updating layer count in middle of batch
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530918 while(i < mCurrentFrame.layerCount) {
919 if(!mCurrentFrame.isFBComposed[i]) {
920 if(!batchCount) {
921 i++;
922 break;
923 }
924 updatingLayersAbove++;
925 i++;
926 continue;
927 } else {
928 if(mCurrentFrame.drop[i]) {
929 i++;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -0800930 droppedLayerCt++;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530931 continue;
932 } else if(updatingLayersAbove <= 0) {
933 batchCount++;
934 batchEnd = i;
935 i++;
936 continue;
937 } else { //Layer is FBComposed, not a drop & updatingLayer > 0
938
939 // We have a valid updating layer already. If layer-i not
940 // have overlapping with all updating layers in between
941 // batch-start and i, then we can add layer i to batch.
942 if(!intersectingUpdatingLayers(list, batchStart, i-1, i)) {
943 batchCount++;
944 batchEnd = i;
945 i++;
946 continue;
947 } else if(canPushBatchToTop(list, batchStart, i)) {
948 //If All the non-updating layers with in this batch
949 //does not have intersection with the updating layers
950 //above in z-order, then we can safely move the batch to
951 //higher z-order. Increment fbZ as it is moving up.
952 if( firstZReverseIndex < 0) {
953 firstZReverseIndex = i;
954 }
955 batchCount++;
956 batchEnd = i;
957 fbZ += updatingLayersAbove;
958 i++;
959 updatingLayersAbove = 0;
960 continue;
961 } else {
962 //both failed.start the loop again from here.
963 if(firstZReverseIndex >= 0) {
964 i = firstZReverseIndex;
965 }
966 break;
967 }
968 }
969 }
970 }
971 if(batchCount > maxBatchCount) {
972 maxBatchCount = batchCount;
973 maxBatchStart = batchStart;
974 maxBatchEnd = batchEnd;
975 fbZOrder = fbZ;
976 }
977 }
978 return fbZOrder;
979}
980
981bool MDPComp::markLayersForCaching(hwc_context_t* ctx,
982 hwc_display_contents_1_t* list) {
983 /* Idea is to keep as many non-updating(cached) layers in FB and
984 * send rest of them through MDP. This is done in 2 steps.
985 * 1. Find the maximum contiguous batch of non-updating layers.
986 * 2. See if we can improve this batch size for caching by adding
987 * opaque layers around the batch, if they don't have
988 * any overlapping with the updating layers in between.
989 * NEVER mark an updating layer for caching.
990 * But cached ones can be marked for MDP */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800991
992 int maxBatchStart = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700993 int maxBatchEnd = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800994 int maxBatchCount = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530995 int fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800996
Saurabh Shahd53bc5f2014-02-05 10:17:43 -0800997 /* Nothing is cached. No batching needed */
998 if(mCurrentFrame.fbCount == 0) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700999 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -07001000 }
Saurabh Shahd53bc5f2014-02-05 10:17:43 -08001001
1002 /* No MDP comp layers, try to use other comp modes */
1003 if(mCurrentFrame.mdpCount == 0) {
1004 return false;
Saurabh Shahaa236822013-04-24 18:07:26 -07001005 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001006
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301007 fbZ = getBatch(list, maxBatchStart, maxBatchEnd, maxBatchCount);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001008
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301009 /* reset rest of the layers lying inside ROI for MDP comp */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001010 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001011 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001012 if((i < maxBatchStart || i > maxBatchEnd) &&
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301013 mCurrentFrame.isFBComposed[i]){
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001014 if(!mCurrentFrame.drop[i]){
1015 //If an unsupported layer is being attempted to
1016 //be pulled out we should fail
1017 if(not isSupportedForMDPComp(ctx, layer)) {
1018 return false;
1019 }
1020 mCurrentFrame.isFBComposed[i] = false;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001021 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001022 }
1023 }
1024
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301025 // update the frame data
1026 mCurrentFrame.fbZ = fbZ;
1027 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001028 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001029 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001030
1031 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301032 mCurrentFrame.fbCount);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001033
1034 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001035}
Saurabh Shah85234ec2013-04-12 17:09:00 -07001036
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001037void MDPComp::updateLayerCache(hwc_context_t* ctx,
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001038 hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001039 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001040 int fbCount = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001041
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001042 for(int i = 0; i < numAppLayers; i++) {
1043 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001044 if(!mCurrentFrame.drop[i])
1045 fbCount++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001046 mCurrentFrame.isFBComposed[i] = true;
1047 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -07001048 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001049 }
1050 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001051
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001052 mCurrentFrame.fbCount = fbCount;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001053 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount
1054 - mCurrentFrame.dropCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001055
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001056 ALOGD_IF(isDebug(),"%s: MDP count: %d FB count %d drop count: %d"
1057 ,__FUNCTION__, mCurrentFrame.mdpCount, mCurrentFrame.fbCount,
1058 mCurrentFrame.dropCount);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001059}
1060
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001061void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list,
1062 bool secureOnly) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001063 int nYuvCount = ctx->listStats[mDpy].yuvCount;
1064 for(int index = 0;index < nYuvCount; index++){
1065 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
1066 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
1067
1068 if(!isYUVDoable(ctx, layer)) {
1069 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
1070 mCurrentFrame.isFBComposed[nYuvIndex] = true;
1071 mCurrentFrame.fbCount++;
1072 }
1073 } else {
1074 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001075 private_handle_t *hnd = (private_handle_t *)layer->handle;
1076 if(!secureOnly || isSecureBuffer(hnd)) {
1077 mCurrentFrame.isFBComposed[nYuvIndex] = false;
1078 mCurrentFrame.fbCount--;
1079 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001080 }
1081 }
1082 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001083
1084 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001085 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
1086 ALOGD_IF(isDebug(),"%s: fb count: %d",__FUNCTION__,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001087 mCurrentFrame.fbCount);
1088}
1089
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301090hwc_rect_t MDPComp::getUpdatingFBRect(hwc_display_contents_1_t* list){
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001091 hwc_rect_t fbRect = (struct hwc_rect){0, 0, 0, 0};
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001092
1093 /* Update only the region of FB needed for composition */
1094 for(int i = 0; i < mCurrentFrame.layerCount; i++ ) {
1095 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
1096 hwc_layer_1_t* layer = &list->hwLayers[i];
1097 hwc_rect_t dst = layer->displayFrame;
1098 fbRect = getUnion(fbRect, dst);
1099 }
1100 }
1101 return fbRect;
1102}
1103
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001104bool MDPComp::postHeuristicsHandling(hwc_context_t *ctx,
1105 hwc_display_contents_1_t* list) {
1106
1107 //Capability checks
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301108 if(!resourceCheck()) {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001109 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
1110 return false;
1111 }
1112
1113 //Limitations checks
1114 if(!hwLimitationsCheck(ctx, list)) {
1115 ALOGD_IF(isDebug(), "%s: HW limitations",__FUNCTION__);
1116 return false;
1117 }
1118
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001119 //Configure framebuffer first if applicable
1120 if(mCurrentFrame.fbZ >= 0) {
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301121 hwc_rect_t fbRect = getUpdatingFBRect(list);
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001122 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, fbRect, mCurrentFrame.fbZ))
1123 {
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001124 ALOGD_IF(isDebug(), "%s configure framebuffer failed",
1125 __FUNCTION__);
1126 return false;
1127 }
1128 }
1129
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001130 mCurrentFrame.map();
1131
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001132 if(!allocLayerPipes(ctx, list)) {
1133 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -07001134 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001135 }
1136
1137 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001138 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001139 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001140 int mdpIndex = mCurrentFrame.layerToMDP[index];
1141 hwc_layer_1_t* layer = &list->hwLayers[index];
1142
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301143 //Leave fbZ for framebuffer. CACHE/GLES layers go here.
1144 if(mdpNextZOrder == mCurrentFrame.fbZ) {
1145 mdpNextZOrder++;
1146 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001147 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1148 cur_pipe->zOrder = mdpNextZOrder++;
1149
radhakrishnac9a67412013-09-25 17:40:42 +05301150 private_handle_t *hnd = (private_handle_t *)layer->handle;
1151 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1152 if(configure4k2kYuv(ctx, layer,
1153 mCurrentFrame.mdpToLayer[mdpIndex])
1154 != 0 ){
1155 ALOGD_IF(isDebug(), "%s: Failed to configure split pipes \
1156 for layer %d",__FUNCTION__, index);
1157 return false;
1158 }
1159 else{
1160 mdpNextZOrder++;
1161 }
1162 continue;
1163 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001164 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
1165 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
radhakrishnac9a67412013-09-25 17:40:42 +05301166 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -07001167 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001168 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001169 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001170 }
1171
Saurabh Shaha36be922013-12-16 18:18:39 -08001172 if(!ctx->mOverlay->validateAndSet(mDpy, ctx->dpyAttr[mDpy].fd)) {
1173 ALOGD_IF(isDebug(), "%s: Failed to validate and set overlay for dpy %d"
1174 ,__FUNCTION__, mDpy);
1175 return false;
1176 }
1177
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001178 setRedraw(ctx, list);
Saurabh Shahaa236822013-04-24 18:07:26 -07001179 return true;
1180}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001181
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301182bool MDPComp::resourceCheck() {
Saurabh Shah173f4242013-11-20 09:50:12 -08001183 const bool fbUsed = mCurrentFrame.fbCount;
1184 if(mCurrentFrame.mdpCount > sMaxPipesPerMixer - fbUsed) {
1185 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
1186 return false;
1187 }
Saurabh Shah173f4242013-11-20 09:50:12 -08001188 return true;
1189}
1190
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301191bool MDPComp::hwLimitationsCheck(hwc_context_t* ctx,
1192 hwc_display_contents_1_t* list) {
1193
1194 //A-family hw limitation:
1195 //If a layer need alpha scaling, MDP can not support.
1196 if(ctx->mMDP.version < qdutils::MDSS_V5) {
1197 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1198 if(!mCurrentFrame.isFBComposed[i] &&
1199 isAlphaScaled( &list->hwLayers[i])) {
1200 ALOGD_IF(isDebug(), "%s:frame needs alphaScaling",__FUNCTION__);
1201 return false;
1202 }
1203 }
1204 }
1205
1206 // On 8x26 & 8974 hw, we have a limitation of downscaling+blending.
1207 //If multiple layers requires downscaling and also they are overlapping
1208 //fall back to GPU since MDSS can not handle it.
1209 if(qdutils::MDPVersion::getInstance().is8x74v2() ||
1210 qdutils::MDPVersion::getInstance().is8x26()) {
1211 for(int i = 0; i < mCurrentFrame.layerCount-1; ++i) {
1212 hwc_layer_1_t* botLayer = &list->hwLayers[i];
1213 if(!mCurrentFrame.isFBComposed[i] &&
1214 isDownscaleRequired(botLayer)) {
1215 //if layer-i is marked for MDP and needs downscaling
1216 //check if any MDP layer on top of i & overlaps with layer-i
1217 for(int j = i+1; j < mCurrentFrame.layerCount; ++j) {
1218 hwc_layer_1_t* topLayer = &list->hwLayers[j];
1219 if(!mCurrentFrame.isFBComposed[j] &&
1220 isDownscaleRequired(topLayer)) {
1221 hwc_rect_t r = getIntersection(botLayer->displayFrame,
1222 topLayer->displayFrame);
1223 if(isValidRect(r))
1224 return false;
1225 }
1226 }
1227 }
1228 }
1229 }
1230 return true;
1231}
1232
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001233int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001234 int ret = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -07001235 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -07001236
Raj Kamal9ed3d6b2014-02-07 16:15:17 +05301237 //Do not cache the information for next draw cycle.
1238 if(numLayers > MAX_NUM_APP_LAYERS or (!numLayers)) {
1239 ALOGI("%s: Unsupported layer count for mdp composition",
1240 __FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001241 mCachedFrame.reset();
1242 return -1;
1243 }
1244
Saurabh Shahb39f8152013-08-22 10:21:44 -07001245 //reset old data
1246 mCurrentFrame.reset(numLayers);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001247 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1248 mCurrentFrame.dropCount = 0;
Prabhanjan Kandula088bd892013-07-02 23:47:13 +05301249
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -07001250 // Detect the start of animation and fall back to GPU only once to cache
1251 // all the layers in FB and display FB content untill animation completes.
1252 if(ctx->listStats[mDpy].isDisplayAnimating) {
1253 mCurrentFrame.needsRedraw = false;
1254 if(ctx->mAnimationState[mDpy] == ANIMATION_STOPPED) {
1255 mCurrentFrame.needsRedraw = true;
1256 ctx->mAnimationState[mDpy] = ANIMATION_STARTED;
1257 }
1258 setMDPCompLayerFlags(ctx, list);
1259 mCachedFrame.updateCounts(mCurrentFrame);
1260 ret = -1;
1261 return ret;
1262 } else {
1263 ctx->mAnimationState[mDpy] = ANIMATION_STOPPED;
1264 }
1265
Saurabh Shahb39f8152013-08-22 10:21:44 -07001266 //Hard conditions, if not met, cannot do MDP comp
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001267 if(isFrameDoable(ctx)) {
1268 generateROI(ctx, list);
Saurabh Shahb39f8152013-08-22 10:21:44 -07001269
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001270 if(tryFullFrame(ctx, list) || tryVideoOnly(ctx, list)) {
1271 setMDPCompLayerFlags(ctx, list);
1272 } else {
1273 reset(ctx);
1274 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1275 mCurrentFrame.dropCount = 0;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001276 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001277 }
1278 } else {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001279 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
1280 __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001281 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001282 }
Saurabh Shahb39f8152013-08-22 10:21:44 -07001283
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001284 if(isDebug()) {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001285 ALOGD("GEOMETRY change: %d",
1286 (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001287 android::String8 sDump("");
1288 dump(sDump);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001289 ALOGD("%s",sDump.string());
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001290 }
1291
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001292 mCachedFrame.cacheAll(list);
1293 mCachedFrame.updateCounts(mCurrentFrame);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001294 return ret;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001295}
1296
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001297bool MDPComp::allocSplitVGPipesfor4k2k(hwc_context_t *ctx, int index) {
radhakrishnac9a67412013-09-25 17:40:42 +05301298
1299 bool bRet = true;
radhakrishnac9a67412013-09-25 17:40:42 +05301300 int mdpIndex = mCurrentFrame.layerToMDP[index];
1301 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
1302 info.pipeInfo = new MdpYUVPipeInfo;
1303 info.rot = NULL;
1304 MdpYUVPipeInfo& pipe_info = *(MdpYUVPipeInfo*)info.pipeInfo;
radhakrishnac9a67412013-09-25 17:40:42 +05301305
1306 pipe_info.lIndex = ovutils::OV_INVALID;
1307 pipe_info.rIndex = ovutils::OV_INVALID;
1308
Saurabh Shahc62f3982014-03-05 14:28:26 -08001309 Overlay::PipeSpecs pipeSpecs;
1310 pipeSpecs.formatClass = Overlay::FORMAT_YUV;
1311 pipeSpecs.needsScaling = true;
1312 pipeSpecs.dpy = mDpy;
1313 pipeSpecs.fb = false;
1314
1315 pipe_info.lIndex = ctx->mOverlay->getPipe(pipeSpecs);
radhakrishnac9a67412013-09-25 17:40:42 +05301316 if(pipe_info.lIndex == ovutils::OV_INVALID){
1317 bRet = false;
1318 ALOGD_IF(isDebug(),"%s: allocating first VG pipe failed",
1319 __FUNCTION__);
1320 }
Saurabh Shahc62f3982014-03-05 14:28:26 -08001321 pipe_info.rIndex = ctx->mOverlay->getPipe(pipeSpecs);
radhakrishnac9a67412013-09-25 17:40:42 +05301322 if(pipe_info.rIndex == ovutils::OV_INVALID){
1323 bRet = false;
1324 ALOGD_IF(isDebug(),"%s: allocating second VG pipe failed",
1325 __FUNCTION__);
1326 }
1327 return bRet;
1328}
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001329//=============MDPCompNonSplit==================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001330
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001331void MDPCompNonSplit::adjustForSourceSplit(hwc_context_t *ctx,
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001332 hwc_display_contents_1_t*) {
radhakrishnac9a67412013-09-25 17:40:42 +05301333 //As we split 4kx2k yuv layer and program to 2 VG pipes
1334 //(if available) increase mdpcount accordingly
1335 mCurrentFrame.mdpCount += ctx->listStats[mDpy].yuv4k2kCount;
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001336
1337 //If 4k2k Yuv layer split is possible, and if
1338 //fbz is above 4k2k layer, increment fb zorder by 1
1339 //as we split 4k2k layer and increment zorder for right half
1340 //of the layer
1341 if(mCurrentFrame.fbZ >= 0) {
1342 int n4k2kYuvCount = ctx->listStats[mDpy].yuv4k2kCount;
1343 for(int index = 0; index < n4k2kYuvCount; index++){
1344 int n4k2kYuvIndex =
1345 ctx->listStats[mDpy].yuv4k2kIndices[index];
Dileep Kumar Reddi4cff9282014-04-01 12:57:08 +05301346 if(mCurrentFrame.fbZ >= n4k2kYuvIndex){
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001347 mCurrentFrame.fbZ += 1;
1348 }
1349 }
1350 }
radhakrishnac9a67412013-09-25 17:40:42 +05301351}
1352
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001353/*
1354 * Configures pipe(s) for MDP composition
1355 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001356int MDPCompNonSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001357 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001358 MdpPipeInfoNonSplit& mdp_info =
1359 *(static_cast<MdpPipeInfoNonSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001360 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
1361 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1362 eIsFg isFg = IS_FG_OFF;
1363 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001364
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001365 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
1366 __FUNCTION__, layer, zOrder, dest);
1367
Saurabh Shah88e4d272013-09-03 13:31:29 -07001368 return configureNonSplit(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001369 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001370}
1371
Saurabh Shah88e4d272013-09-03 13:31:29 -07001372bool MDPCompNonSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001373 hwc_display_contents_1_t* list) {
1374 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001375
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001376 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001377
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001378 hwc_layer_1_t* layer = &list->hwLayers[index];
1379 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301380 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001381 if(allocSplitVGPipesfor4k2k(ctx, index)){
radhakrishnac9a67412013-09-25 17:40:42 +05301382 continue;
1383 }
1384 }
1385
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001386 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001387 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001388 info.pipeInfo = new MdpPipeInfoNonSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08001389 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001390 MdpPipeInfoNonSplit& pipe_info = *(MdpPipeInfoNonSplit*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001391
Saurabh Shahc62f3982014-03-05 14:28:26 -08001392 Overlay::PipeSpecs pipeSpecs;
1393 pipeSpecs.formatClass = isYuvBuffer(hnd) ?
1394 Overlay::FORMAT_YUV : Overlay::FORMAT_RGB;
1395 pipeSpecs.needsScaling = qhwc::needsScaling(layer) or
1396 (qdutils::MDPVersion::getInstance().is8x26() and
1397 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres > 1024);
1398 pipeSpecs.dpy = mDpy;
1399 pipeSpecs.fb = false;
Xu Yang1e686f62014-04-08 13:56:47 +08001400 pipeSpecs.numActiveDisplays = ctx->numActiveDisplays;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001401
Saurabh Shahc62f3982014-03-05 14:28:26 -08001402 pipe_info.index = ctx->mOverlay->getPipe(pipeSpecs);
1403
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001404 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001405 ALOGD_IF(isDebug(), "%s: Unable to get pipe", __FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001406 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001407 }
1408 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001409 return true;
1410}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001411
radhakrishnac9a67412013-09-25 17:40:42 +05301412int MDPCompNonSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1413 PipeLayerPair& PipeLayerPair) {
1414 MdpYUVPipeInfo& mdp_info =
1415 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1416 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1417 eIsFg isFg = IS_FG_OFF;
1418 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1419 eDest lDest = mdp_info.lIndex;
1420 eDest rDest = mdp_info.rIndex;
1421
1422 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1423 lDest, rDest, &PipeLayerPair.rot);
1424}
1425
Saurabh Shah88e4d272013-09-03 13:31:29 -07001426bool MDPCompNonSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001427
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001428 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001429 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1430 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -08001431 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001432
1433 if(!ctx || !list) {
1434 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001435 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001436 }
1437
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301438 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1439 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1440 return true;
1441 }
1442
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -08001443 // Set the Handle timeout to true for MDP or MIXED composition.
1444 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount) {
1445 sHandleTimeout = true;
1446 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001447
1448 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001449 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001450
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001451 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1452 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001453 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001454 if(mCurrentFrame.isFBComposed[i]) continue;
1455
Naseer Ahmed5b6708a2012-08-02 13:46:08 -07001456 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001457 private_handle_t *hnd = (private_handle_t *)layer->handle;
1458 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001459 if (!(layer->flags & HWC_COLOR_FILL)) {
1460 ALOGE("%s handle null", __FUNCTION__);
1461 return false;
1462 }
1463 // No PLAY for Color layer
1464 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1465 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001466 }
1467
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001468 int mdpIndex = mCurrentFrame.layerToMDP[i];
1469
radhakrishnac9a67412013-09-25 17:40:42 +05301470 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1471 {
1472 MdpYUVPipeInfo& pipe_info =
1473 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1474 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1475 ovutils::eDest indexL = pipe_info.lIndex;
1476 ovutils::eDest indexR = pipe_info.rIndex;
1477 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301478 uint32_t offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05301479 if(rot) {
1480 rot->queueBuffer(fd, offset);
1481 fd = rot->getDstMemId();
1482 offset = rot->getDstOffset();
1483 }
1484 if(indexL != ovutils::OV_INVALID) {
1485 ovutils::eDest destL = (ovutils::eDest)indexL;
1486 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1487 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1488 if (!ov.queueBuffer(fd, offset, destL)) {
1489 ALOGE("%s: queueBuffer failed for display:%d",
1490 __FUNCTION__, mDpy);
1491 return false;
1492 }
1493 }
1494
1495 if(indexR != ovutils::OV_INVALID) {
1496 ovutils::eDest destR = (ovutils::eDest)indexR;
1497 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1498 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1499 if (!ov.queueBuffer(fd, offset, destR)) {
1500 ALOGE("%s: queueBuffer failed for display:%d",
1501 __FUNCTION__, mDpy);
1502 return false;
1503 }
1504 }
1505 }
1506 else{
1507 MdpPipeInfoNonSplit& pipe_info =
Saurabh Shah88e4d272013-09-03 13:31:29 -07001508 *(MdpPipeInfoNonSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
radhakrishnac9a67412013-09-25 17:40:42 +05301509 ovutils::eDest dest = pipe_info.index;
1510 if(dest == ovutils::OV_INVALID) {
1511 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001512 return false;
radhakrishnac9a67412013-09-25 17:40:42 +05301513 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001514
radhakrishnac9a67412013-09-25 17:40:42 +05301515 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1516 continue;
1517 }
1518
1519 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1520 using pipe: %d", __FUNCTION__, layer,
1521 hnd, dest );
1522
1523 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301524 uint32_t offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05301525
1526 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1527 if(rot) {
1528 if(!rot->queueBuffer(fd, offset))
1529 return false;
1530 fd = rot->getDstMemId();
1531 offset = rot->getDstOffset();
1532 }
1533
1534 if (!ov.queueBuffer(fd, offset, dest)) {
1535 ALOGE("%s: queueBuffer failed for display:%d ",
1536 __FUNCTION__, mDpy);
1537 return false;
1538 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001539 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001540
1541 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001542 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001543 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001544}
1545
Saurabh Shah88e4d272013-09-03 13:31:29 -07001546//=============MDPCompSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001547
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001548void MDPCompSplit::adjustForSourceSplit(hwc_context_t *ctx,
radhakrishnac9a67412013-09-25 17:40:42 +05301549 hwc_display_contents_1_t* list){
1550 //if 4kx2k yuv layer is totally present in either in left half
1551 //or right half then try splitting the yuv layer to avoid decimation
1552 int n4k2kYuvCount = ctx->listStats[mDpy].yuv4k2kCount;
1553 const int lSplit = getLeftSplit(ctx, mDpy);
1554 for(int index = 0; index < n4k2kYuvCount; index++){
1555 int n4k2kYuvIndex = ctx->listStats[mDpy].yuv4k2kIndices[index];
1556 hwc_layer_1_t* layer = &list->hwLayers[n4k2kYuvIndex];
1557 hwc_rect_t dst = layer->displayFrame;
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001558 if((dst.left > lSplit) || (dst.right < lSplit)) {
radhakrishnac9a67412013-09-25 17:40:42 +05301559 mCurrentFrame.mdpCount += 1;
1560 }
Dileep Kumar Reddi4cff9282014-04-01 12:57:08 +05301561 if(mCurrentFrame.fbZ >= n4k2kYuvIndex){
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001562 mCurrentFrame.fbZ += 1;
1563 }
radhakrishnac9a67412013-09-25 17:40:42 +05301564 }
1565}
1566
Saurabh Shah88e4d272013-09-03 13:31:29 -07001567bool MDPCompSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Saurabh Shahc62f3982014-03-05 14:28:26 -08001568 MdpPipeInfoSplit& pipe_info) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001569
Saurabh Shahc62f3982014-03-05 14:28:26 -08001570 const int lSplit = getLeftSplit(ctx, mDpy);
1571 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001572 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001573 pipe_info.lIndex = ovutils::OV_INVALID;
1574 pipe_info.rIndex = ovutils::OV_INVALID;
1575
Saurabh Shahc62f3982014-03-05 14:28:26 -08001576 Overlay::PipeSpecs pipeSpecs;
1577 pipeSpecs.formatClass = isYuvBuffer(hnd) ?
1578 Overlay::FORMAT_YUV : Overlay::FORMAT_RGB;
1579 pipeSpecs.needsScaling = qhwc::needsScalingWithSplit(ctx, layer, mDpy);
1580 pipeSpecs.dpy = mDpy;
1581 pipeSpecs.mixer = Overlay::MIXER_LEFT;
1582 pipeSpecs.fb = false;
1583
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001584 if (dst.left < lSplit) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001585 pipe_info.lIndex = ctx->mOverlay->getPipe(pipeSpecs);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001586 if(pipe_info.lIndex == ovutils::OV_INVALID)
1587 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001588 }
1589
1590 if(dst.right > lSplit) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001591 pipeSpecs.mixer = Overlay::MIXER_RIGHT;
1592 pipe_info.rIndex = ctx->mOverlay->getPipe(pipeSpecs);
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001593 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001594 return false;
1595 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001596
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001597 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001598}
1599
Saurabh Shah88e4d272013-09-03 13:31:29 -07001600bool MDPCompSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001601 hwc_display_contents_1_t* list) {
1602 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001603
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001604 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001605
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001606 hwc_layer_1_t* layer = &list->hwLayers[index];
1607 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301608 hwc_rect_t dst = layer->displayFrame;
1609 const int lSplit = getLeftSplit(ctx, mDpy);
1610 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1611 if((dst.left > lSplit)||(dst.right < lSplit)){
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001612 if(allocSplitVGPipesfor4k2k(ctx, index)){
radhakrishnac9a67412013-09-25 17:40:42 +05301613 continue;
1614 }
1615 }
1616 }
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001617 int mdpIndex = mCurrentFrame.layerToMDP[index];
1618 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001619 info.pipeInfo = new MdpPipeInfoSplit;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001620 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001621 MdpPipeInfoSplit& pipe_info = *(MdpPipeInfoSplit*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001622
Saurabh Shahc62f3982014-03-05 14:28:26 -08001623 if(!acquireMDPPipes(ctx, layer, pipe_info)) {
1624 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type",
1625 __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001626 return false;
1627 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001628 }
1629 return true;
1630}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001631
radhakrishnac9a67412013-09-25 17:40:42 +05301632int MDPCompSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1633 PipeLayerPair& PipeLayerPair) {
1634 const int lSplit = getLeftSplit(ctx, mDpy);
1635 hwc_rect_t dst = layer->displayFrame;
1636 if((dst.left > lSplit)||(dst.right < lSplit)){
1637 MdpYUVPipeInfo& mdp_info =
1638 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1639 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1640 eIsFg isFg = IS_FG_OFF;
1641 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1642 eDest lDest = mdp_info.lIndex;
1643 eDest rDest = mdp_info.rIndex;
1644
1645 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1646 lDest, rDest, &PipeLayerPair.rot);
1647 }
1648 else{
1649 return configure(ctx, layer, PipeLayerPair);
1650 }
1651}
1652
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001653/*
1654 * Configures pipe(s) for MDP composition
1655 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001656int MDPCompSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001657 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001658 MdpPipeInfoSplit& mdp_info =
1659 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001660 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1661 eIsFg isFg = IS_FG_OFF;
1662 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1663 eDest lDest = mdp_info.lIndex;
1664 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001665
1666 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1667 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1668
Saurabh Shah88e4d272013-09-03 13:31:29 -07001669 return configureSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001670 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001671}
1672
Saurabh Shah88e4d272013-09-03 13:31:29 -07001673bool MDPCompSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001674
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001675 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001676 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1677 return true;
1678 }
1679
1680 if(!ctx || !list) {
1681 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001682 return false;
1683 }
1684
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301685 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1686 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1687 return true;
1688 }
1689
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -08001690 // Set the Handle timeout to true for MDP or MIXED composition.
1691 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount) {
1692 sHandleTimeout = true;
1693 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001694
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001695 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001696 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001697
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001698 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1699 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001700 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001701 if(mCurrentFrame.isFBComposed[i]) continue;
1702
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001703 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001704 private_handle_t *hnd = (private_handle_t *)layer->handle;
1705 if(!hnd) {
1706 ALOGE("%s handle null", __FUNCTION__);
1707 return false;
1708 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001709
1710 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1711 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001712 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001713
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001714 int mdpIndex = mCurrentFrame.layerToMDP[i];
1715
radhakrishnac9a67412013-09-25 17:40:42 +05301716 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1717 {
1718 MdpYUVPipeInfo& pipe_info =
1719 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1720 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1721 ovutils::eDest indexL = pipe_info.lIndex;
1722 ovutils::eDest indexR = pipe_info.rIndex;
1723 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301724 uint32_t offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05301725 if(rot) {
1726 rot->queueBuffer(fd, offset);
1727 fd = rot->getDstMemId();
1728 offset = rot->getDstOffset();
1729 }
1730 if(indexL != ovutils::OV_INVALID) {
1731 ovutils::eDest destL = (ovutils::eDest)indexL;
1732 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1733 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1734 if (!ov.queueBuffer(fd, offset, destL)) {
1735 ALOGE("%s: queueBuffer failed for display:%d",
1736 __FUNCTION__, mDpy);
1737 return false;
1738 }
1739 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001740
radhakrishnac9a67412013-09-25 17:40:42 +05301741 if(indexR != ovutils::OV_INVALID) {
1742 ovutils::eDest destR = (ovutils::eDest)indexR;
1743 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1744 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1745 if (!ov.queueBuffer(fd, offset, destR)) {
1746 ALOGE("%s: queueBuffer failed for display:%d",
1747 __FUNCTION__, mDpy);
1748 return false;
1749 }
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001750 }
1751 }
radhakrishnac9a67412013-09-25 17:40:42 +05301752 else{
1753 MdpPipeInfoSplit& pipe_info =
1754 *(MdpPipeInfoSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1755 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001756
radhakrishnac9a67412013-09-25 17:40:42 +05301757 ovutils::eDest indexL = pipe_info.lIndex;
1758 ovutils::eDest indexR = pipe_info.rIndex;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001759
radhakrishnac9a67412013-09-25 17:40:42 +05301760 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301761 int offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05301762
1763 if(ctx->mAD->isModeOn()) {
1764 if(ctx->mAD->draw(ctx, fd, offset)) {
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001765 fd = ctx->mAD->getDstFd();
1766 offset = ctx->mAD->getDstOffset();
radhakrishnac9a67412013-09-25 17:40:42 +05301767 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001768 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001769
radhakrishnac9a67412013-09-25 17:40:42 +05301770 if(rot) {
1771 rot->queueBuffer(fd, offset);
1772 fd = rot->getDstMemId();
1773 offset = rot->getDstOffset();
1774 }
1775
1776 //************* play left mixer **********
1777 if(indexL != ovutils::OV_INVALID) {
1778 ovutils::eDest destL = (ovutils::eDest)indexL;
1779 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1780 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1781 if (!ov.queueBuffer(fd, offset, destL)) {
1782 ALOGE("%s: queueBuffer failed for left mixer",
1783 __FUNCTION__);
1784 return false;
1785 }
1786 }
1787
1788 //************* play right mixer **********
1789 if(indexR != ovutils::OV_INVALID) {
1790 ovutils::eDest destR = (ovutils::eDest)indexR;
1791 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1792 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1793 if (!ov.queueBuffer(fd, offset, destR)) {
1794 ALOGE("%s: queueBuffer failed for right mixer",
1795 __FUNCTION__);
1796 return false;
1797 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001798 }
1799 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001800
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001801 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1802 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001803
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001804 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001805}
Saurabh Shahab47c692014-02-12 18:45:57 -08001806
1807//================MDPCompSrcSplit==============================================
1808bool MDPCompSrcSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Saurabh Shahc62f3982014-03-05 14:28:26 -08001809 MdpPipeInfoSplit& pipe_info) {
Saurabh Shahab47c692014-02-12 18:45:57 -08001810 private_handle_t *hnd = (private_handle_t *)layer->handle;
1811 hwc_rect_t dst = layer->displayFrame;
1812 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
1813 pipe_info.lIndex = ovutils::OV_INVALID;
1814 pipe_info.rIndex = ovutils::OV_INVALID;
1815
1816 //If 2 pipes are staged on a single stage of a mixer, then the left pipe
1817 //should have a higher priority than the right one. Pipe priorities are
1818 //starting with VG0, VG1 ... , RGB0 ..., DMA1
Saurabh Shahab47c692014-02-12 18:45:57 -08001819
Saurabh Shahc62f3982014-03-05 14:28:26 -08001820 Overlay::PipeSpecs pipeSpecs;
1821 pipeSpecs.formatClass = isYuvBuffer(hnd) ?
1822 Overlay::FORMAT_YUV : Overlay::FORMAT_RGB;
1823 pipeSpecs.needsScaling = qhwc::needsScaling(layer);
1824 pipeSpecs.dpy = mDpy;
1825 pipeSpecs.fb = false;
1826
Saurabh Shahab47c692014-02-12 18:45:57 -08001827 //1 pipe by default for a layer
Saurabh Shahc62f3982014-03-05 14:28:26 -08001828 pipe_info.lIndex = ctx->mOverlay->getPipe(pipeSpecs);
Saurabh Shahab47c692014-02-12 18:45:57 -08001829 if(pipe_info.lIndex == ovutils::OV_INVALID) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001830 return false;
Saurabh Shahab47c692014-02-12 18:45:57 -08001831 }
1832
1833 //If layer's crop width or dest width > 2048, use 2 pipes
1834 if((dst.right - dst.left) > qdutils::MAX_DISPLAY_DIM or
1835 (crop.right - crop.left) > qdutils::MAX_DISPLAY_DIM) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001836 pipe_info.rIndex = ctx->mOverlay->getPipe(pipeSpecs);
Saurabh Shahab47c692014-02-12 18:45:57 -08001837 if(pipe_info.rIndex == ovutils::OV_INVALID) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001838 return false;
Saurabh Shahdd8237a2014-02-28 14:29:09 -08001839 }
1840
1841 // Return values
1842 // 1 Left pipe is higher priority, do nothing.
1843 // 0 Pipes of same priority.
1844 //-1 Right pipe is of higher priority, needs swap.
1845 if(ctx->mOverlay->comparePipePriority(pipe_info.lIndex,
1846 pipe_info.rIndex) == -1) {
1847 qhwc::swap(pipe_info.lIndex, pipe_info.rIndex);
Saurabh Shahab47c692014-02-12 18:45:57 -08001848 }
1849 }
1850
1851 return true;
1852}
1853
Saurabh Shahab47c692014-02-12 18:45:57 -08001854int MDPCompSrcSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
1855 PipeLayerPair& PipeLayerPair) {
1856 private_handle_t *hnd = (private_handle_t *)layer->handle;
1857 if(!hnd) {
1858 ALOGE("%s: layer handle is NULL", __FUNCTION__);
1859 return -1;
1860 }
1861 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
1862 MdpPipeInfoSplit& mdp_info =
1863 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
1864 Rotator **rot = &PipeLayerPair.rot;
1865 eZorder z = static_cast<eZorder>(mdp_info.zOrder);
1866 eIsFg isFg = IS_FG_OFF;
1867 eDest lDest = mdp_info.lIndex;
1868 eDest rDest = mdp_info.rIndex;
1869 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
1870 hwc_rect_t dst = layer->displayFrame;
1871 int transform = layer->transform;
1872 eTransform orient = static_cast<eTransform>(transform);
1873 const int downscale = 0;
1874 int rotFlags = ROT_FLAGS_NONE;
1875 uint32_t format = ovutils::getMdpFormat(hnd->format, isTileRendered(hnd));
1876 Whf whf(getWidth(hnd), getHeight(hnd), format, hnd->size);
1877
1878 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1879 "dest_pipeR: %d",__FUNCTION__, layer, z, lDest, rDest);
1880
1881 // Handle R/B swap
1882 if (layer->flags & HWC_FORMAT_RB_SWAP) {
1883 if (hnd->format == HAL_PIXEL_FORMAT_RGBA_8888)
1884 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRA_8888);
1885 else if (hnd->format == HAL_PIXEL_FORMAT_RGBX_8888)
1886 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRX_8888);
1887 }
1888
Saurabh Shah97e2d802014-04-14 18:03:54 -07001889 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
1890 setMdpFlags(layer, mdpFlags, 0, transform);
Saurabh Shahab47c692014-02-12 18:45:57 -08001891
1892 if(lDest != OV_INVALID && rDest != OV_INVALID) {
1893 //Enable overfetch
Saurabh Shah97e2d802014-04-14 18:03:54 -07001894 setMdpFlags(mdpFlags, OV_MDSS_MDP_DUAL_PIPE);
Saurabh Shahab47c692014-02-12 18:45:57 -08001895 }
1896
1897 if(isYuvBuffer(hnd) && (transform & HWC_TRANSFORM_ROT_90)) {
1898 (*rot) = ctx->mRotMgr->getNext();
1899 if((*rot) == NULL) return -1;
Saurabh Shah39240c92014-03-31 10:31:42 -07001900 ctx->mLayerRotMap[mDpy]->add(layer, *rot);
Saurabh Shahab47c692014-02-12 18:45:57 -08001901 //Configure rotator for pre-rotation
Saurabh Shah97e2d802014-04-14 18:03:54 -07001902 if(configRotator(*rot, whf, crop, mdpFlags, orient, downscale) < 0) {
Saurabh Shahab47c692014-02-12 18:45:57 -08001903 ALOGE("%s: configRotator failed!", __FUNCTION__);
1904 return -1;
1905 }
Saurabh Shahab47c692014-02-12 18:45:57 -08001906 whf.format = (*rot)->getDstFormat();
1907 updateSource(orient, whf, crop);
1908 rotFlags |= ROT_PREROTATED;
1909 }
1910
1911 //If 2 pipes being used, divide layer into half, crop and dst
1912 hwc_rect_t cropL = crop;
1913 hwc_rect_t cropR = crop;
1914 hwc_rect_t dstL = dst;
1915 hwc_rect_t dstR = dst;
1916 if(lDest != OV_INVALID && rDest != OV_INVALID) {
1917 cropL.right = (crop.right + crop.left) / 2;
1918 cropR.left = cropL.right;
1919 sanitizeSourceCrop(cropL, cropR, hnd);
1920
1921 //Swap crops on H flip since 2 pipes are being used
1922 if((orient & OVERLAY_TRANSFORM_FLIP_H) && (*rot) == NULL) {
1923 hwc_rect_t tmp = cropL;
1924 cropL = cropR;
1925 cropR = tmp;
1926 }
1927
1928 dstL.right = (dst.right + dst.left) / 2;
1929 dstR.left = dstL.right;
1930 }
1931
1932 //For the mdp, since either we are pre-rotating or MDP does flips
1933 orient = OVERLAY_TRANSFORM_0;
1934 transform = 0;
1935
1936 //configure left pipe
1937 if(lDest != OV_INVALID) {
Saurabh Shah97e2d802014-04-14 18:03:54 -07001938 PipeArgs pargL(mdpFlags, whf, z, isFg,
Saurabh Shahab47c692014-02-12 18:45:57 -08001939 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
1940 (ovutils::eBlending) getBlending(layer->blending));
1941
1942 if(configMdp(ctx->mOverlay, pargL, orient,
1943 cropL, dstL, metadata, lDest) < 0) {
1944 ALOGE("%s: commit failed for left mixer config", __FUNCTION__);
1945 return -1;
1946 }
1947 }
1948
1949 //configure right pipe
1950 if(rDest != OV_INVALID) {
Saurabh Shah97e2d802014-04-14 18:03:54 -07001951 PipeArgs pargR(mdpFlags, whf, z, isFg,
Saurabh Shahab47c692014-02-12 18:45:57 -08001952 static_cast<eRotFlags>(rotFlags),
1953 layer->planeAlpha,
1954 (ovutils::eBlending) getBlending(layer->blending));
1955 if(configMdp(ctx->mOverlay, pargR, orient,
1956 cropR, dstR, metadata, rDest) < 0) {
1957 ALOGE("%s: commit failed for right mixer config", __FUNCTION__);
1958 return -1;
1959 }
1960 }
1961
1962 return 0;
1963}
1964
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001965}; //namespace
1966