blob: 14c478da34eadaef5b5f00ef4957b3605f626a4a [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 Sankaran85977e32013-02-25 17:06:08 -080045int MDPComp::sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
radhakrishnac9a67412013-09-25 17:40:42 +053046bool MDPComp::sEnable4k2kYUVSplit = false;
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -070047bool MDPComp::sSrcSplitEnabled = false;
Saurabh Shah88e4d272013-09-03 13:31:29 -070048MDPComp* MDPComp::getObject(hwc_context_t *ctx, const int& dpy) {
Saurabh Shah60e8bde2014-04-30 14:46:03 -070049 if(qdutils::MDPVersion::getInstance().isSrcSplit()) {
50 sSrcSplitEnabled = true;
51 return new MDPCompSrcSplit(dpy);
52 } else if(isDisplaySplit(ctx, dpy)) {
Saurabh Shah88e4d272013-09-03 13:31:29 -070053 return new MDPCompSplit(dpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080054 }
Saurabh Shah88e4d272013-09-03 13:31:29 -070055 return new MDPCompNonSplit(dpy);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080056}
57
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080058MDPComp::MDPComp(int dpy):mDpy(dpy){};
59
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080060void MDPComp::dump(android::String8& buf)
61{
Jeykumar Sankaran3c6bb042013-08-15 14:01:04 -070062 if(mCurrentFrame.layerCount > MAX_NUM_APP_LAYERS)
63 return;
64
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080065 dumpsys_log(buf,"HWC Map for Dpy: %s \n",
Jeykumar Sankaran27dee262013-08-01 17:09:54 -070066 (mDpy == 0) ? "\"PRIMARY\"" :
67 (mDpy == 1) ? "\"EXTERNAL\"" : "\"VIRTUAL\"");
Saurabh Shahe9bc60f2013-08-29 12:58:06 -070068 dumpsys_log(buf,"CURR_FRAME: layerCount:%2d mdpCount:%2d "
69 "fbCount:%2d \n", mCurrentFrame.layerCount,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080070 mCurrentFrame.mdpCount, mCurrentFrame.fbCount);
71 dumpsys_log(buf,"needsFBRedraw:%3s pipesUsed:%2d MaxPipesPerMixer: %d \n",
72 (mCurrentFrame.needsRedraw? "YES" : "NO"),
73 mCurrentFrame.mdpCount, sMaxPipesPerMixer);
74 dumpsys_log(buf," --------------------------------------------- \n");
75 dumpsys_log(buf," listIdx | cached? | mdpIndex | comptype | Z \n");
76 dumpsys_log(buf," --------------------------------------------- \n");
77 for(int index = 0; index < mCurrentFrame.layerCount; index++ )
78 dumpsys_log(buf," %7d | %7s | %8d | %9s | %2d \n",
79 index,
80 (mCurrentFrame.isFBComposed[index] ? "YES" : "NO"),
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -070081 mCurrentFrame.layerToMDP[index],
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080082 (mCurrentFrame.isFBComposed[index] ?
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -070083 (mCurrentFrame.drop[index] ? "DROP" :
84 (mCurrentFrame.needsRedraw ? "GLES" : "CACHE")) : "MDP"),
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080085 (mCurrentFrame.isFBComposed[index] ? mCurrentFrame.fbZ :
86 mCurrentFrame.mdpToLayer[mCurrentFrame.layerToMDP[index]].pipeInfo->zOrder));
87 dumpsys_log(buf,"\n");
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080088}
89
90bool MDPComp::init(hwc_context_t *ctx) {
91
92 if(!ctx) {
93 ALOGE("%s: Invalid hwc context!!",__FUNCTION__);
94 return false;
95 }
96
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080097 char property[PROPERTY_VALUE_MAX];
98
99 sEnabled = false;
100 if((property_get("persist.hwc.mdpcomp.enable", property, NULL) > 0) &&
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800101 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
102 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800103 sEnabled = true;
104 }
105
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700106 sEnableMixedMode = true;
107 if((property_get("debug.mdpcomp.mixedmode.disable", property, NULL) > 0) &&
108 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
109 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
110 sEnableMixedMode = false;
111 }
112
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800113 if(property_get("debug.mdpcomp.logs", property, NULL) > 0) {
114 if(atoi(property) != 0)
115 sDebugLogs = true;
116 }
117
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800118 sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
Saurabh Shah85234ec2013-04-12 17:09:00 -0700119 if(property_get("debug.mdpcomp.maxpermixer", property, "-1") > 0) {
120 int val = atoi(property);
121 if(val >= 0)
122 sMaxPipesPerMixer = min(val, MAX_PIPES_PER_MIXER);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800123 }
124
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400125 if(ctx->mMDP.panel != MIPI_CMD_PANEL) {
126 // Idle invalidation is not necessary on command mode panels
127 long idle_timeout = DEFAULT_IDLE_TIME;
128 if(property_get("debug.mdpcomp.idletime", property, NULL) > 0) {
129 if(atoi(property) != 0)
130 idle_timeout = atoi(property);
131 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800132
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400133 //create Idle Invalidator only when not disabled through property
134 if(idle_timeout != -1)
135 idleInvalidator = IdleInvalidator::getInstance();
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800136
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400137 if(idleInvalidator == NULL) {
138 ALOGE("%s: failed to instantiate idleInvalidator object",
139 __FUNCTION__);
140 } else {
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530141 idleInvalidator->init(timeout_handler, ctx,
142 (unsigned int)idle_timeout);
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400143 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800144 }
radhakrishnac9a67412013-09-25 17:40:42 +0530145
146 if((property_get("debug.mdpcomp.4k2kSplit", property, "0") > 0) &&
147 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
148 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
149 sEnable4k2kYUVSplit = true;
150 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700151 return true;
152}
153
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800154void MDPComp::reset(hwc_context_t *ctx) {
155 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700156 mCurrentFrame.reset(numLayers);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800157 ctx->mOverlay->clear(mDpy);
158 ctx->mLayerRotMap[mDpy]->clear();
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700159}
160
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700161void MDPComp::timeout_handler(void *udata) {
162 struct hwc_context_t* ctx = (struct hwc_context_t*)(udata);
163
164 if(!ctx) {
165 ALOGE("%s: received empty data in timer callback", __FUNCTION__);
166 return;
167 }
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -0800168 Locker::Autolock _l(ctx->mDrawLock);
169 // Handle timeout event only if the previous composition is MDP or MIXED.
170 if(!sHandleTimeout) {
171 ALOGD_IF(isDebug(), "%s:Do not handle this timeout", __FUNCTION__);
172 return;
173 }
Jesse Hall3be78d92012-08-21 15:12:23 -0700174 if(!ctx->proc) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700175 ALOGE("%s: HWC proc not registered", __FUNCTION__);
176 return;
177 }
178 sIdleFallBack = true;
179 /* Trigger SF to redraw the current frame */
Jesse Hall3be78d92012-08-21 15:12:23 -0700180 ctx->proc->invalidate(ctx->proc);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700181}
182
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800183void MDPComp::setMDPCompLayerFlags(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800184 hwc_display_contents_1_t* list) {
185 LayerProp *layerProp = ctx->layerProp[mDpy];
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800186
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800187 for(int index = 0; index < ctx->listStats[mDpy].numAppLayers; index++) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800188 hwc_layer_1_t* layer = &(list->hwLayers[index]);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800189 if(!mCurrentFrame.isFBComposed[index]) {
190 layerProp[index].mFlags |= HWC_MDPCOMP;
191 layer->compositionType = HWC_OVERLAY;
192 layer->hints |= HWC_HINT_CLEAR_FB;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800193 } else {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700194 /* Drop the layer when its already present in FB OR when it lies
195 * outside frame's ROI */
196 if(!mCurrentFrame.needsRedraw || mCurrentFrame.drop[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800197 layer->compositionType = HWC_OVERLAY;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700198 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800199 }
200 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700201}
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500202
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800203void MDPComp::setRedraw(hwc_context_t *ctx,
204 hwc_display_contents_1_t* list) {
205 mCurrentFrame.needsRedraw = false;
206 if(!mCachedFrame.isSameFrame(mCurrentFrame, list) ||
207 (list->flags & HWC_GEOMETRY_CHANGED) ||
208 isSkipPresent(ctx, mDpy)) {
209 mCurrentFrame.needsRedraw = true;
210 }
211}
212
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800213MDPComp::FrameInfo::FrameInfo() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700214 reset(0);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800215}
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800216
Saurabh Shahaa236822013-04-24 18:07:26 -0700217void MDPComp::FrameInfo::reset(const int& numLayers) {
218 for(int i = 0 ; i < MAX_PIPES_PER_MIXER && numLayers; i++ ) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800219 if(mdpToLayer[i].pipeInfo) {
220 delete mdpToLayer[i].pipeInfo;
221 mdpToLayer[i].pipeInfo = NULL;
222 //We dont own the rotator
223 mdpToLayer[i].rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800224 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800225 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800226
227 memset(&mdpToLayer, 0, sizeof(mdpToLayer));
228 memset(&layerToMDP, -1, sizeof(layerToMDP));
Saurabh Shahaa236822013-04-24 18:07:26 -0700229 memset(&isFBComposed, 1, sizeof(isFBComposed));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800230
Saurabh Shahaa236822013-04-24 18:07:26 -0700231 layerCount = numLayers;
232 fbCount = numLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800233 mdpCount = 0;
Saurabh Shah2f3895f2013-05-02 10:13:31 -0700234 needsRedraw = true;
Saurabh Shahd53bc5f2014-02-05 10:17:43 -0800235 fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800236}
237
Saurabh Shahaa236822013-04-24 18:07:26 -0700238void MDPComp::FrameInfo::map() {
239 // populate layer and MDP maps
240 int mdpIdx = 0;
241 for(int idx = 0; idx < layerCount; idx++) {
242 if(!isFBComposed[idx]) {
243 mdpToLayer[mdpIdx].listIndex = idx;
244 layerToMDP[idx] = mdpIdx++;
245 }
246 }
247}
248
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800249MDPComp::LayerCache::LayerCache() {
250 reset();
251}
252
253void MDPComp::LayerCache::reset() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700254 memset(&hnd, 0, sizeof(hnd));
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530255 memset(&isFBComposed, true, sizeof(isFBComposed));
256 memset(&drop, false, sizeof(drop));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800257 layerCount = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -0700258}
259
260void MDPComp::LayerCache::cacheAll(hwc_display_contents_1_t* list) {
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530261 const int numAppLayers = (int)list->numHwLayers - 1;
Saurabh Shahaa236822013-04-24 18:07:26 -0700262 for(int i = 0; i < numAppLayers; i++) {
263 hnd[i] = list->hwLayers[i].handle;
264 }
265}
266
267void MDPComp::LayerCache::updateCounts(const FrameInfo& curFrame) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700268 layerCount = curFrame.layerCount;
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530269 memcpy(&isFBComposed, &curFrame.isFBComposed, sizeof(isFBComposed));
270 memcpy(&drop, &curFrame.drop, sizeof(drop));
271}
272
Jeykumar Sankaran988d3682013-11-15 11:57:16 -0800273bool MDPComp::LayerCache::isSameFrame(const FrameInfo& curFrame,
274 hwc_display_contents_1_t* list) {
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530275 if(layerCount != curFrame.layerCount)
276 return false;
277 for(int i = 0; i < curFrame.layerCount; i++) {
278 if((curFrame.isFBComposed[i] != isFBComposed[i]) ||
279 (curFrame.drop[i] != drop[i])) {
280 return false;
281 }
Jeykumar Sankaran988d3682013-11-15 11:57:16 -0800282 if(curFrame.isFBComposed[i] &&
283 (hnd[i] != list->hwLayers[i].handle)){
284 return false;
285 }
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530286 }
287 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800288}
289
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700290bool MDPComp::isSupportedForMDPComp(hwc_context_t *ctx, hwc_layer_1_t* layer) {
291 private_handle_t *hnd = (private_handle_t *)layer->handle;
292 if((not isYuvBuffer(hnd) and has90Transform(layer)) or
293 (not isValidDimension(ctx,layer))
294 //More conditions here, SKIP, sRGB+Blend etc
295 ) {
296 return false;
297 }
298 return true;
299}
300
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530301bool MDPComp::isValidDimension(hwc_context_t *ctx, hwc_layer_1_t *layer) {
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800302 private_handle_t *hnd = (private_handle_t *)layer->handle;
303
304 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -0700305 if (layer->flags & HWC_COLOR_FILL) {
306 // Color layer
307 return true;
308 }
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800309 ALOGE("%s: layer handle is NULL", __FUNCTION__);
310 return false;
311 }
312
Naseer Ahmede850a802013-09-06 13:12:52 -0400313 //XXX: Investigate doing this with pixel phase on MDSS
Naseer Ahmede77f8082013-10-10 13:42:48 -0400314 if(!isSecureBuffer(hnd) && isNonIntegralSourceCrop(layer->sourceCropf))
Naseer Ahmede850a802013-09-06 13:12:52 -0400315 return false;
316
Saurabh Shah62e1d732013-09-17 10:44:05 -0700317 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700318 hwc_rect_t dst = layer->displayFrame;
Saurabh Shah4fdde762013-04-30 18:47:33 -0700319 int crop_w = crop.right - crop.left;
320 int crop_h = crop.bottom - crop.top;
321 int dst_w = dst.right - dst.left;
322 int dst_h = dst.bottom - dst.top;
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800323 float w_scale = ((float)crop_w / (float)dst_w);
324 float h_scale = ((float)crop_h / (float)dst_h);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700325
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800326 /* Workaround for MDP HW limitation in DSI command mode panels where
327 * FPS will not go beyond 30 if buffers on RGB pipes are of width or height
328 * less than 5 pixels
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530329 * There also is a HW limilation in MDP, minimum block size is 2x2
330 * Fallback to GPU if height is less than 2.
331 */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800332 if((crop_w < 5)||(crop_h < 5))
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800333 return false;
334
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800335 if((w_scale > 1.0f) || (h_scale > 1.0f)) {
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700336 const uint32_t maxMDPDownscale =
Saurabh Shah4fdde762013-04-30 18:47:33 -0700337 qdutils::MDPVersion::getInstance().getMaxMDPDownscale();
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800338 const float w_dscale = w_scale;
339 const float h_dscale = h_scale;
340
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800341 if(ctx->mMDP.version >= qdutils::MDSS_V5) {
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700342
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800343 if(!qdutils::MDPVersion::getInstance().supportsDecimation()) {
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700344 /* On targets that doesnt support Decimation (eg.,8x26)
345 * maximum downscale support is overlay pipe downscale.
346 */
347 if(crop_w > MAX_DISPLAY_DIM || w_dscale > maxMDPDownscale ||
348 h_dscale > maxMDPDownscale)
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800349 return false;
350 } else {
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700351 // Decimation on macrotile format layers is not supported.
352 if(isTileRendered(hnd)) {
353 /* MDP can read maximum MAX_DISPLAY_DIM width.
354 * Bail out if
355 * 1. Src crop > MAX_DISPLAY_DIM on nonsplit MDPComp
356 * 2. exceeds maximum downscale limit
357 */
358 if(((crop_w > MAX_DISPLAY_DIM) && !sSrcSplitEnabled) ||
359 w_dscale > maxMDPDownscale ||
360 h_dscale > maxMDPDownscale) {
361 return false;
362 }
363 } else if(w_dscale > 64 || h_dscale > 64)
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800364 return false;
365 }
366 } else { //A-family
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700367 if(w_dscale > maxMDPDownscale || h_dscale > maxMDPDownscale)
Saurabh Shah4fdde762013-04-30 18:47:33 -0700368 return false;
369 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700370 }
371
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800372 if((w_scale < 1.0f) || (h_scale < 1.0f)) {
373 const uint32_t upscale =
374 qdutils::MDPVersion::getInstance().getMaxMDPUpscale();
375 const float w_uscale = 1.0f / w_scale;
376 const float h_uscale = 1.0f / h_scale;
377
378 if(w_uscale > upscale || h_uscale > upscale)
379 return false;
380 }
381
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800382 return true;
383}
384
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800385bool MDPComp::isFrameDoable(hwc_context_t *ctx) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700386 bool ret = true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800387
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800388 if(!isEnabled()) {
389 ALOGD_IF(isDebug(),"%s: MDP Comp. not enabled.", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700390 ret = false;
Raj Kamal068f4572014-04-14 16:14:06 +0530391 } else if((qdutils::MDPVersion::getInstance().is8x26() ||
392 qdutils::MDPVersion::getInstance().is8x16()) &&
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -0800393 ctx->mVideoTransFlag &&
394 isSecondaryConnected(ctx)) {
Saurabh Shahd4e65852013-06-17 11:33:53 -0700395 //1 Padding round to shift pipes across mixers
396 ALOGD_IF(isDebug(),"%s: MDP Comp. video transition padding round",
397 __FUNCTION__);
398 ret = false;
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -0800399 } else if(isSecondaryConfiguring(ctx)) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800400 ALOGD_IF( isDebug(),"%s: External Display connection is pending",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800401 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700402 ret = false;
Saurabh Shahaa236822013-04-24 18:07:26 -0700403 } else if(ctx->isPaddingRound) {
Raj Kamal9ed3d6b2014-02-07 16:15:17 +0530404 ALOGD_IF(isDebug(), "%s: padding round invoked for dpy %d",
405 __FUNCTION__,mDpy);
Saurabh Shahaa236822013-04-24 18:07:26 -0700406 ret = false;
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700407 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700408 return ret;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800409}
410
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800411void MDPCompNonSplit::trimAgainstROI(hwc_context_t *ctx, hwc_rect_t& fbRect) {
412 hwc_rect_t roi = ctx->listStats[mDpy].lRoi;
413 fbRect = getIntersection(fbRect, roi);
414}
415
416/* 1) Identify layers that are not visible or lying outside the updating ROI and
417 * drop them from composition.
418 * 2) If we have a scaling layer which needs cropping against generated
419 * ROI, reset ROI to full resolution. */
420bool MDPCompNonSplit::validateAndApplyROI(hwc_context_t *ctx,
421 hwc_display_contents_1_t* list) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700422 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800423 hwc_rect_t visibleRect = ctx->listStats[mDpy].lRoi;
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800424
425 for(int i = numAppLayers - 1; i >= 0; i--){
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800426 if(!isValidRect(visibleRect)) {
427 mCurrentFrame.drop[i] = true;
428 mCurrentFrame.dropCount++;
Jeykumar Sankaran0b961452014-01-21 17:26:12 -0800429 continue;
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800430 }
431
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700432 const hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700433 hwc_rect_t dstRect = layer->displayFrame;
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800434 hwc_rect_t res = getIntersection(visibleRect, dstRect);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700435
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700436 if(!isValidRect(res)) {
437 mCurrentFrame.drop[i] = true;
438 mCurrentFrame.dropCount++;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800439 } else {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700440 /* Reset frame ROI when any layer which needs scaling also needs ROI
441 * cropping */
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800442 if(!isSameRect(res, dstRect) && needsScaling (layer)) {
Arpita Banerjeed8965982013-11-08 17:27:33 -0800443 ALOGI("%s: Resetting ROI due to scaling", __FUNCTION__);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700444 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
445 mCurrentFrame.dropCount = 0;
446 return false;
447 }
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800448
Jeykumar Sankaran0b961452014-01-21 17:26:12 -0800449 /* deduct any opaque region from visibleRect */
450 if (layer->blending == HWC_BLENDING_NONE)
451 visibleRect = deductRect(visibleRect, res);
452 }
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700453 }
454 return true;
455}
456
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800457/* Calculate ROI for the frame by accounting all the layer's dispalyFrame which
458 * are updating. If DirtyRegion is applicable, calculate it by accounting all
459 * the changing layer's dirtyRegion. */
460void MDPCompNonSplit::generateROI(hwc_context_t *ctx,
461 hwc_display_contents_1_t* list) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700462 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800463 if(!canPartialUpdate(ctx, list))
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700464 return;
465
466 struct hwc_rect roi = (struct hwc_rect){0, 0, 0, 0};
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800467 hwc_rect fullFrame = (struct hwc_rect) {0, 0,(int)ctx->dpyAttr[mDpy].xres,
468 (int)ctx->dpyAttr[mDpy].yres};
469
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700470 for(int index = 0; index < numAppLayers; index++ ) {
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800471 hwc_layer_1_t* layer = &list->hwLayers[index];
472 if ((mCachedFrame.hnd[index] != layer->handle) ||
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800473 isYuvBuffer((private_handle_t *)layer->handle)) {
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800474 hwc_rect_t updatingRect = layer->displayFrame;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800475
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800476#ifdef QCOM_BSP
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800477 if(!needsScaling(layer) && !layer->transform)
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800478 updatingRect = layer->dirtyRect;
479#endif
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800480
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800481 roi = getUnion(roi, updatingRect);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700482 }
483 }
484
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800485 /* No layer is updating. Still SF wants a refresh.*/
486 if(!isValidRect(roi))
487 return;
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800488
489 // Align ROI coordinates to panel restrictions
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800490 roi = getSanitizeROI(roi, fullFrame);
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800491
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800492 ctx->listStats[mDpy].lRoi = roi;
493 if(!validateAndApplyROI(ctx, list))
494 resetROI(ctx, mDpy);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700495
496 ALOGD_IF(isDebug(),"%s: generated ROI: [%d, %d, %d, %d]", __FUNCTION__,
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800497 ctx->listStats[mDpy].lRoi.left, ctx->listStats[mDpy].lRoi.top,
498 ctx->listStats[mDpy].lRoi.right, ctx->listStats[mDpy].lRoi.bottom);
499}
500
501void MDPCompSplit::trimAgainstROI(hwc_context_t *ctx, hwc_rect_t& fbRect) {
502 hwc_rect l_roi = ctx->listStats[mDpy].lRoi;
503 hwc_rect r_roi = ctx->listStats[mDpy].rRoi;
504
505 hwc_rect_t l_fbRect = getIntersection(fbRect, l_roi);
506 hwc_rect_t r_fbRect = getIntersection(fbRect, r_roi);
507 fbRect = getUnion(l_fbRect, r_fbRect);
508}
509/* 1) Identify layers that are not visible or lying outside BOTH the updating
510 * ROI's and drop them from composition. If a layer is spanning across both
511 * the halves of the screen but needed by only ROI, the non-contributing
512 * half will not be programmed for MDP.
513 * 2) If we have a scaling layer which needs cropping against generated
514 * ROI, reset ROI to full resolution. */
515bool MDPCompSplit::validateAndApplyROI(hwc_context_t *ctx,
516 hwc_display_contents_1_t* list) {
517
518 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
519
520 hwc_rect_t visibleRectL = ctx->listStats[mDpy].lRoi;
521 hwc_rect_t visibleRectR = ctx->listStats[mDpy].rRoi;
522
523 for(int i = numAppLayers - 1; i >= 0; i--){
524 if(!isValidRect(visibleRectL) && !isValidRect(visibleRectR))
525 {
526 mCurrentFrame.drop[i] = true;
527 mCurrentFrame.dropCount++;
528 continue;
529 }
530
531 const hwc_layer_1_t* layer = &list->hwLayers[i];
532 hwc_rect_t dstRect = layer->displayFrame;
533
534 hwc_rect_t l_res = getIntersection(visibleRectL, dstRect);
535 hwc_rect_t r_res = getIntersection(visibleRectR, dstRect);
536 hwc_rect_t res = getUnion(l_res, r_res);
537
538 if(!isValidRect(l_res) && !isValidRect(r_res)) {
539 mCurrentFrame.drop[i] = true;
540 mCurrentFrame.dropCount++;
541 } else {
542 /* Reset frame ROI when any layer which needs scaling also needs ROI
543 * cropping */
544 if(!isSameRect(res, dstRect) && needsScaling (layer)) {
545 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
546 mCurrentFrame.dropCount = 0;
547 return false;
548 }
549
550 if (layer->blending == HWC_BLENDING_NONE) {
551 visibleRectL = deductRect(visibleRectL, l_res);
552 visibleRectR = deductRect(visibleRectR, r_res);
553 }
554 }
555 }
556 return true;
557}
558/* Calculate ROI for the frame by accounting all the layer's dispalyFrame which
559 * are updating. If DirtyRegion is applicable, calculate it by accounting all
560 * the changing layer's dirtyRegion. */
561void MDPCompSplit::generateROI(hwc_context_t *ctx,
562 hwc_display_contents_1_t* list) {
563 if(!canPartialUpdate(ctx, list))
564 return;
565
566 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
567 int lSplit = getLeftSplit(ctx, mDpy);
568
569 int hw_h = (int)ctx->dpyAttr[mDpy].yres;
570 int hw_w = (int)ctx->dpyAttr[mDpy].xres;
571
572 struct hwc_rect l_frame = (struct hwc_rect){0, 0, lSplit, hw_h};
573 struct hwc_rect r_frame = (struct hwc_rect){lSplit, 0, hw_w, hw_h};
574
575 struct hwc_rect l_roi = (struct hwc_rect){0, 0, 0, 0};
576 struct hwc_rect r_roi = (struct hwc_rect){0, 0, 0, 0};
577
578 for(int index = 0; index < numAppLayers; index++ ) {
579 hwc_layer_1_t* layer = &list->hwLayers[index];
580 if ((mCachedFrame.hnd[index] != layer->handle) ||
581 isYuvBuffer((private_handle_t *)layer->handle)) {
Jeykumar Sankaran71e597c2014-05-07 16:23:14 -0700582 hwc_rect_t dst = layer->displayFrame;
583 hwc_rect_t updatingRect = dst;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800584
585#ifdef QCOM_BSP
586 if(!needsScaling(layer) && !layer->transform)
Jeykumar Sankaran71e597c2014-05-07 16:23:14 -0700587 {
588 hwc_rect_t src = integerizeSourceCrop(layer->sourceCropf);
589 int x_off = dst.left - src.left;
590 int y_off = dst.top - src.top;
591 updatingRect = moveRect(layer->dirtyRect, x_off, y_off);
592 }
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800593#endif
594
595 hwc_rect_t l_dst = getIntersection(l_frame, updatingRect);
596 if(isValidRect(l_dst))
597 l_roi = getUnion(l_roi, l_dst);
598
599 hwc_rect_t r_dst = getIntersection(r_frame, updatingRect);
600 if(isValidRect(r_dst))
601 r_roi = getUnion(r_roi, r_dst);
602 }
603 }
604
Jeykumar Sankarana40a9342014-04-25 09:37:10 -0700605 /* For panels that cannot accept commands in both the interfaces, we cannot
606 * send two ROI's (for each half). We merge them into single ROI and split
607 * them across lSplit for MDP mixer use. The ROI's will be merged again
608 * finally before udpating the panel in the driver. */
609 if(qdutils::MDPVersion::getInstance().needsROIMerge()) {
610 hwc_rect_t temp_roi = getUnion(l_roi, r_roi);
611 l_roi = getIntersection(temp_roi, l_frame);
612 r_roi = getIntersection(temp_roi, r_frame);
613 }
614
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800615 /* No layer is updating. Still SF wants a refresh. */
616 if(!isValidRect(l_roi) && !isValidRect(r_roi))
617 return;
618
619 l_roi = getSanitizeROI(l_roi, l_frame);
620 r_roi = getSanitizeROI(r_roi, r_frame);
621
622 ctx->listStats[mDpy].lRoi = l_roi;
623 ctx->listStats[mDpy].rRoi = r_roi;
624
625 if(!validateAndApplyROI(ctx, list))
626 resetROI(ctx, mDpy);
627
628 ALOGD_IF(isDebug(),"%s: generated L_ROI: [%d, %d, %d, %d]"
629 "R_ROI: [%d, %d, %d, %d]", __FUNCTION__,
630 ctx->listStats[mDpy].lRoi.left, ctx->listStats[mDpy].lRoi.top,
631 ctx->listStats[mDpy].lRoi.right, ctx->listStats[mDpy].lRoi.bottom,
632 ctx->listStats[mDpy].rRoi.left, ctx->listStats[mDpy].rRoi.top,
633 ctx->listStats[mDpy].rRoi.right, ctx->listStats[mDpy].rRoi.bottom);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700634}
635
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800636/* Checks for conditions where all the layers marked for MDP comp cannot be
637 * bypassed. On such conditions we try to bypass atleast YUV layers */
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800638bool MDPComp::tryFullFrame(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800639 hwc_display_contents_1_t* list){
640
Saurabh Shahaa236822013-04-24 18:07:26 -0700641 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Arun Kumar K.R2e2871c2014-01-10 12:47:06 -0800642 int priDispW = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800643
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -0700644 if(sIdleFallBack && !ctx->listStats[mDpy].secureUI) {
Saurabh Shah2d998a92013-05-14 17:55:58 -0700645 ALOGD_IF(isDebug(), "%s: Idle fallback dpy %d",__FUNCTION__, mDpy);
646 return false;
647 }
648
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800649 if(isSkipPresent(ctx, mDpy)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700650 ALOGD_IF(isDebug(),"%s: SKIP present: %d",
651 __FUNCTION__,
652 isSkipPresent(ctx, mDpy));
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800653 return false;
654 }
655
Arun Kumar K.R2e2871c2014-01-10 12:47:06 -0800656 if(mDpy > HWC_DISPLAY_PRIMARY && (priDispW > MAX_DISPLAY_DIM) &&
657 (ctx->dpyAttr[mDpy].xres < MAX_DISPLAY_DIM)) {
658 // Disable MDP comp on Secondary when the primary is highres panel and
659 // the secondary is a normal 1080p, because, MDP comp on secondary under
660 // in such usecase, decimation gets used for downscale and there will be
661 // a quality mismatch when there will be a fallback to GPU comp
662 ALOGD_IF(isDebug(), "%s: Disable MDP Compositon for Secondary Disp",
663 __FUNCTION__);
664 return false;
665 }
666
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800667 // check for action safe flag and downscale mode which requires scaling.
668 if(ctx->dpyAttr[mDpy].mActionSafePresent
669 || ctx->dpyAttr[mDpy].mDownScaleMode) {
670 ALOGD_IF(isDebug(), "%s: Scaling needed for this frame",__FUNCTION__);
671 return false;
672 }
673
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800674 for(int i = 0; i < numAppLayers; ++i) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800675 hwc_layer_1_t* layer = &list->hwLayers[i];
676 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800677
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700678 if(isYuvBuffer(hnd) && has90Transform(layer)) {
679 if(!canUseRotator(ctx, mDpy)) {
680 ALOGD_IF(isDebug(), "%s: Can't use rotator for dpy %d",
681 __FUNCTION__, mDpy);
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700682 return false;
683 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800684 }
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530685
686 //For 8x26 with panel width>1k, if RGB layer needs HFLIP fail mdp comp
687 // may not need it if Gfx pre-rotation can handle all flips & rotations
Sushil Chauhanfda00fc2014-03-20 11:08:41 -0700688 int transform = (layer->flags & HWC_COLOR_FILL) ? 0 : layer->transform;
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530689 if(qdutils::MDPVersion::getInstance().is8x26() &&
690 (ctx->dpyAttr[mDpy].xres > 1024) &&
Sushil Chauhanfda00fc2014-03-20 11:08:41 -0700691 (transform & HWC_TRANSFORM_FLIP_H) &&
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530692 (!isYuvBuffer(hnd)))
693 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800694 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700695
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700696 if(ctx->mAD->isDoable()) {
697 return false;
698 }
699
Saurabh Shahaa236822013-04-24 18:07:26 -0700700 //If all above hard conditions are met we can do full or partial MDP comp.
701 bool ret = false;
702 if(fullMDPComp(ctx, list)) {
703 ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700704 } else if(partialMDPComp(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700705 ret = true;
706 }
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530707
Saurabh Shahaa236822013-04-24 18:07:26 -0700708 return ret;
709}
710
711bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700712 //Will benefit presentation / secondary-only layer.
713 if((mDpy > HWC_DISPLAY_PRIMARY) &&
714 (list->numHwLayers - 1) > MAX_SEC_LAYERS) {
715 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
716 return false;
717 }
718
719 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
720 for(int i = 0; i < numAppLayers; i++) {
721 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran880da832014-04-18 10:22:35 -0700722 if(not mCurrentFrame.drop[i] and
723 not isSupportedForMDPComp(ctx, layer)) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700724 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",__FUNCTION__);
725 return false;
726 }
727 }
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800728
Saurabh Shahaa236822013-04-24 18:07:26 -0700729 mCurrentFrame.fbCount = 0;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700730 memcpy(&mCurrentFrame.isFBComposed, &mCurrentFrame.drop,
731 sizeof(mCurrentFrame.isFBComposed));
732 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount -
733 mCurrentFrame.dropCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700734
radhakrishnac9a67412013-09-25 17:40:42 +0530735 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800736 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530737 }
738
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800739 if(!postHeuristicsHandling(ctx, list)) {
740 ALOGD_IF(isDebug(), "post heuristic handling failed");
741 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700742 return false;
743 }
744
Saurabh Shahaa236822013-04-24 18:07:26 -0700745 return true;
746}
747
748bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
749{
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700750 if(!sEnableMixedMode) {
751 //Mixed mode is disabled. No need to even try caching.
752 return false;
753 }
754
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700755 bool ret = false;
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800756 if(list->flags & HWC_GEOMETRY_CHANGED) { //Try load based first
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800757 ret = loadBasedComp(ctx, list) or
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800758 cacheBasedComp(ctx, list);
759 } else {
760 ret = cacheBasedComp(ctx, list) or
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800761 loadBasedComp(ctx, list);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700762 }
763
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700764 return ret;
765}
766
767bool MDPComp::cacheBasedComp(hwc_context_t *ctx,
768 hwc_display_contents_1_t* list) {
769 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700770 mCurrentFrame.reset(numAppLayers);
771 updateLayerCache(ctx, list);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700772
773 //If an MDP marked layer is unsupported cannot do partial MDP Comp
774 for(int i = 0; i < numAppLayers; i++) {
775 if(!mCurrentFrame.isFBComposed[i]) {
776 hwc_layer_1_t* layer = &list->hwLayers[i];
777 if(not isSupportedForMDPComp(ctx, layer)) {
778 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",
779 __FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800780 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700781 return false;
782 }
783 }
784 }
785
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700786 updateYUV(ctx, list, false /*secure only*/);
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530787 bool ret = markLayersForCaching(ctx, list); //sets up fbZ also
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700788 if(!ret) {
789 ALOGD_IF(isDebug(),"%s: batching failed, dpy %d",__FUNCTION__, mDpy);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800790 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700791 return false;
792 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700793
794 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700795
radhakrishnac9a67412013-09-25 17:40:42 +0530796 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800797 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530798 }
799
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700800 //Will benefit cases where a video has non-updating background.
801 if((mDpy > HWC_DISPLAY_PRIMARY) and
802 (mdpCount > MAX_SEC_LAYERS)) {
803 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800804 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700805 return false;
806 }
807
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800808 if(!postHeuristicsHandling(ctx, list)) {
809 ALOGD_IF(isDebug(), "post heuristic handling failed");
810 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700811 return false;
812 }
813
Saurabh Shahaa236822013-04-24 18:07:26 -0700814 return true;
815}
816
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800817bool MDPComp::loadBasedComp(hwc_context_t *ctx,
Saurabh Shahb772ae32013-11-18 15:40:02 -0800818 hwc_display_contents_1_t* list) {
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -0800819 if(not isLoadBasedCompDoable(ctx)) {
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800820 return false;
821 }
822
Saurabh Shahb772ae32013-11-18 15:40:02 -0800823 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800824 const int numNonDroppedLayers = numAppLayers - mCurrentFrame.dropCount;
825 const int stagesForMDP = min(sMaxPipesPerMixer,
826 ctx->mOverlay->availablePipes(mDpy, Overlay::MIXER_DEFAULT));
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800827
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800828 int mdpBatchSize = stagesForMDP - 1; //1 stage for FB
829 int fbBatchSize = numNonDroppedLayers - mdpBatchSize;
830 int lastMDPSupportedIndex = numAppLayers;
831 int dropCount = 0;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800832
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800833 //Find the minimum MDP batch size
834 for(int i = 0; i < numAppLayers;i++) {
835 if(mCurrentFrame.drop[i]) {
836 dropCount++;
Jeykumar Sankaran846e2792014-01-23 21:59:58 -0800837 continue;
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800838 }
839 hwc_layer_1_t* layer = &list->hwLayers[i];
840 if(not isSupportedForMDPComp(ctx, layer)) {
841 lastMDPSupportedIndex = i;
842 mdpBatchSize = min(i - dropCount, stagesForMDP - 1);
843 fbBatchSize = numNonDroppedLayers - mdpBatchSize;
Jeykumar Sankaran846e2792014-01-23 21:59:58 -0800844 break;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800845 }
Saurabh Shahb772ae32013-11-18 15:40:02 -0800846 }
847
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800848 ALOGD_IF(isDebug(), "%s:Before optimizing fbBatch, mdpbatch %d, fbbatch %d "
849 "dropped %d", __FUNCTION__, mdpBatchSize, fbBatchSize,
850 mCurrentFrame.dropCount);
851
852 //Start at a point where the fb batch should at least have 2 layers, for
853 //this mode to be justified.
854 while(fbBatchSize < 2) {
855 ++fbBatchSize;
856 --mdpBatchSize;
Jeykumar Sankaran846e2792014-01-23 21:59:58 -0800857 }
Saurabh Shahb772ae32013-11-18 15:40:02 -0800858
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800859 //If there are no layers for MDP, this mode doesnt make sense.
860 if(mdpBatchSize < 1) {
861 ALOGD_IF(isDebug(), "%s: No MDP layers after optimizing for fbBatch",
862 __FUNCTION__);
Saurabh Shahb772ae32013-11-18 15:40:02 -0800863 return false;
864 }
865
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800866 mCurrentFrame.reset(numAppLayers);
867
868 //Try with successively smaller mdp batch sizes until we succeed or reach 1
869 while(mdpBatchSize > 0) {
870 //Mark layers for MDP comp
871 int mdpBatchLeft = mdpBatchSize;
872 for(int i = 0; i < lastMDPSupportedIndex and mdpBatchLeft; i++) {
873 if(mCurrentFrame.drop[i]) {
874 continue;
875 }
876 mCurrentFrame.isFBComposed[i] = false;
877 --mdpBatchLeft;
878 }
879
880 mCurrentFrame.fbZ = mdpBatchSize;
881 mCurrentFrame.fbCount = fbBatchSize;
882 mCurrentFrame.mdpCount = mdpBatchSize;
883
884 ALOGD_IF(isDebug(), "%s:Trying with: mdpbatch %d fbbatch %d dropped %d",
885 __FUNCTION__, mdpBatchSize, fbBatchSize,
886 mCurrentFrame.dropCount);
887
888 if(postHeuristicsHandling(ctx, list)) {
889 ALOGD_IF(isDebug(), "%s: Postheuristics handling succeeded",
890 __FUNCTION__);
891 return true;
892 }
893
894 reset(ctx);
895 --mdpBatchSize;
896 ++fbBatchSize;
897 }
898
899 return false;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800900}
901
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -0800902bool MDPComp::isLoadBasedCompDoable(hwc_context_t *ctx) {
Prabhanjan Kandula3dbbd882013-12-11 14:43:46 +0530903 if(mDpy or isSecurePresent(ctx, mDpy) or
904 isYuvPresent(ctx, mDpy)) {
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700905 return false;
906 }
907 return true;
908}
909
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800910bool MDPComp::canPartialUpdate(hwc_context_t *ctx,
911 hwc_display_contents_1_t* list){
912 if(!qdutils::MDPVersion::getInstance().isPartialUpdateEnabled() ||
913 isSkipPresent(ctx, mDpy) || (list->flags & HWC_GEOMETRY_CHANGED) ||
914 mDpy ) {
915 return false;
916 }
917 return true;
918}
919
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800920bool MDPComp::tryVideoOnly(hwc_context_t *ctx,
921 hwc_display_contents_1_t* list) {
922 const bool secureOnly = true;
923 return videoOnlyComp(ctx, list, not secureOnly) or
924 videoOnlyComp(ctx, list, secureOnly);
925}
926
927bool MDPComp::videoOnlyComp(hwc_context_t *ctx,
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700928 hwc_display_contents_1_t* list, bool secureOnly) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700929 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700930
Saurabh Shahaa236822013-04-24 18:07:26 -0700931 mCurrentFrame.reset(numAppLayers);
Jeykumar Sankaraneb3a5e22014-04-08 16:07:55 -0700932 mCurrentFrame.fbCount -= mCurrentFrame.dropCount;
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700933 updateYUV(ctx, list, secureOnly);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700934 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700935
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800936 if(!isYuvPresent(ctx, mDpy) or (mdpCount == 0)) {
937 reset(ctx);
Saurabh Shahaa236822013-04-24 18:07:26 -0700938 return false;
939 }
940
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -0800941 /* Bail out if we are processing only secured video layers
942 * and we dont have any */
943 if(!isSecurePresent(ctx, mDpy) && secureOnly){
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800944 reset(ctx);
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -0800945 return false;
946 }
947
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800948 if(mCurrentFrame.fbCount)
949 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
Saurabh Shah4fdde762013-04-30 18:47:33 -0700950
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800951 if(sEnable4k2kYUVSplit){
952 adjustForSourceSplit(ctx, list);
953 }
954
955 if(!postHeuristicsHandling(ctx, list)) {
956 ALOGD_IF(isDebug(), "post heuristic handling failed");
957 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700958 return false;
959 }
960
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800961 return true;
962}
963
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800964/* Checks for conditions where YUV layers cannot be bypassed */
965bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -0700966 if(isSkipLayer(layer)) {
Saurabh Shahe2474082013-05-15 16:32:13 -0700967 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800968 return false;
969 }
970
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700971 if(layer->transform & HWC_TRANSFORM_ROT_90 && !canUseRotator(ctx,mDpy)) {
972 ALOGD_IF(isDebug(), "%s: no free DMA pipe",__FUNCTION__);
973 return false;
974 }
975
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800976 if(isSecuring(ctx, layer)) {
977 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
978 return false;
979 }
980
Saurabh Shah4fdde762013-04-30 18:47:33 -0700981 if(!isValidDimension(ctx, layer)) {
982 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
983 __FUNCTION__);
984 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800985 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700986
Naseer Ahmeddc61a972013-07-10 17:50:54 -0400987 if(layer->planeAlpha < 0xFF) {
988 ALOGD_IF(isDebug(), "%s: Cannot handle YUV layer with plane alpha\
989 in video only mode",
990 __FUNCTION__);
991 return false;
992 }
993
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800994 return true;
995}
996
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530997/* starts at fromIndex and check for each layer to find
998 * if it it has overlapping with any Updating layer above it in zorder
999 * till the end of the batch. returns true if it finds any intersection */
1000bool MDPComp::canPushBatchToTop(const hwc_display_contents_1_t* list,
1001 int fromIndex, int toIndex) {
1002 for(int i = fromIndex; i < toIndex; i++) {
1003 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
1004 if(intersectingUpdatingLayers(list, i+1, toIndex, i)) {
1005 return false;
1006 }
1007 }
1008 }
1009 return true;
1010}
1011
1012/* Checks if given layer at targetLayerIndex has any
1013 * intersection with all the updating layers in beween
1014 * fromIndex and toIndex. Returns true if it finds intersectiion */
1015bool MDPComp::intersectingUpdatingLayers(const hwc_display_contents_1_t* list,
1016 int fromIndex, int toIndex, int targetLayerIndex) {
1017 for(int i = fromIndex; i <= toIndex; i++) {
1018 if(!mCurrentFrame.isFBComposed[i]) {
1019 if(areLayersIntersecting(&list->hwLayers[i],
1020 &list->hwLayers[targetLayerIndex])) {
1021 return true;
1022 }
1023 }
1024 }
1025 return false;
1026}
1027
1028int MDPComp::getBatch(hwc_display_contents_1_t* list,
1029 int& maxBatchStart, int& maxBatchEnd,
1030 int& maxBatchCount) {
1031 int i = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301032 int fbZOrder =-1;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -08001033 int droppedLayerCt = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301034 while (i < mCurrentFrame.layerCount) {
1035 int batchCount = 0;
1036 int batchStart = i;
1037 int batchEnd = i;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -08001038 /* Adjust batch Z order with the dropped layers so far */
1039 int fbZ = batchStart - droppedLayerCt;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301040 int firstZReverseIndex = -1;
Prabhanjan Kandula0ed2cc92013-12-06 12:39:04 +05301041 int updatingLayersAbove = 0;//Updating layer count in middle of batch
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301042 while(i < mCurrentFrame.layerCount) {
1043 if(!mCurrentFrame.isFBComposed[i]) {
1044 if(!batchCount) {
1045 i++;
1046 break;
1047 }
1048 updatingLayersAbove++;
1049 i++;
1050 continue;
1051 } else {
1052 if(mCurrentFrame.drop[i]) {
1053 i++;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -08001054 droppedLayerCt++;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301055 continue;
1056 } else if(updatingLayersAbove <= 0) {
1057 batchCount++;
1058 batchEnd = i;
1059 i++;
1060 continue;
1061 } else { //Layer is FBComposed, not a drop & updatingLayer > 0
1062
1063 // We have a valid updating layer already. If layer-i not
1064 // have overlapping with all updating layers in between
1065 // batch-start and i, then we can add layer i to batch.
1066 if(!intersectingUpdatingLayers(list, batchStart, i-1, i)) {
1067 batchCount++;
1068 batchEnd = i;
1069 i++;
1070 continue;
1071 } else if(canPushBatchToTop(list, batchStart, i)) {
1072 //If All the non-updating layers with in this batch
1073 //does not have intersection with the updating layers
1074 //above in z-order, then we can safely move the batch to
1075 //higher z-order. Increment fbZ as it is moving up.
1076 if( firstZReverseIndex < 0) {
1077 firstZReverseIndex = i;
1078 }
1079 batchCount++;
1080 batchEnd = i;
1081 fbZ += updatingLayersAbove;
1082 i++;
1083 updatingLayersAbove = 0;
1084 continue;
1085 } else {
1086 //both failed.start the loop again from here.
1087 if(firstZReverseIndex >= 0) {
1088 i = firstZReverseIndex;
1089 }
1090 break;
1091 }
1092 }
1093 }
1094 }
1095 if(batchCount > maxBatchCount) {
1096 maxBatchCount = batchCount;
1097 maxBatchStart = batchStart;
1098 maxBatchEnd = batchEnd;
1099 fbZOrder = fbZ;
1100 }
1101 }
1102 return fbZOrder;
1103}
1104
1105bool MDPComp::markLayersForCaching(hwc_context_t* ctx,
1106 hwc_display_contents_1_t* list) {
1107 /* Idea is to keep as many non-updating(cached) layers in FB and
1108 * send rest of them through MDP. This is done in 2 steps.
1109 * 1. Find the maximum contiguous batch of non-updating layers.
1110 * 2. See if we can improve this batch size for caching by adding
1111 * opaque layers around the batch, if they don't have
1112 * any overlapping with the updating layers in between.
1113 * NEVER mark an updating layer for caching.
1114 * But cached ones can be marked for MDP */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001115
1116 int maxBatchStart = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001117 int maxBatchEnd = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001118 int maxBatchCount = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301119 int fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001120
Saurabh Shahd53bc5f2014-02-05 10:17:43 -08001121 /* Nothing is cached. No batching needed */
1122 if(mCurrentFrame.fbCount == 0) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001123 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -07001124 }
Saurabh Shahd53bc5f2014-02-05 10:17:43 -08001125
1126 /* No MDP comp layers, try to use other comp modes */
1127 if(mCurrentFrame.mdpCount == 0) {
1128 return false;
Saurabh Shahaa236822013-04-24 18:07:26 -07001129 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001130
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301131 fbZ = getBatch(list, maxBatchStart, maxBatchEnd, maxBatchCount);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001132
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301133 /* reset rest of the layers lying inside ROI for MDP comp */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001134 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001135 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001136 if((i < maxBatchStart || i > maxBatchEnd) &&
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301137 mCurrentFrame.isFBComposed[i]){
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001138 if(!mCurrentFrame.drop[i]){
1139 //If an unsupported layer is being attempted to
1140 //be pulled out we should fail
1141 if(not isSupportedForMDPComp(ctx, layer)) {
1142 return false;
1143 }
1144 mCurrentFrame.isFBComposed[i] = false;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001145 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001146 }
1147 }
1148
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301149 // update the frame data
1150 mCurrentFrame.fbZ = fbZ;
1151 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001152 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001153 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001154
1155 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301156 mCurrentFrame.fbCount);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001157
1158 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001159}
Saurabh Shah85234ec2013-04-12 17:09:00 -07001160
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001161void MDPComp::updateLayerCache(hwc_context_t* ctx,
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001162 hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001163 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001164 int fbCount = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001165
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001166 for(int i = 0; i < numAppLayers; i++) {
1167 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001168 if(!mCurrentFrame.drop[i])
1169 fbCount++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001170 mCurrentFrame.isFBComposed[i] = true;
1171 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -07001172 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001173 }
1174 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001175
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001176 mCurrentFrame.fbCount = fbCount;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001177 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount
1178 - mCurrentFrame.dropCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001179
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001180 ALOGD_IF(isDebug(),"%s: MDP count: %d FB count %d drop count: %d"
1181 ,__FUNCTION__, mCurrentFrame.mdpCount, mCurrentFrame.fbCount,
1182 mCurrentFrame.dropCount);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001183}
1184
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001185void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list,
1186 bool secureOnly) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001187 int nYuvCount = ctx->listStats[mDpy].yuvCount;
1188 for(int index = 0;index < nYuvCount; index++){
1189 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
1190 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
1191
1192 if(!isYUVDoable(ctx, layer)) {
1193 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
1194 mCurrentFrame.isFBComposed[nYuvIndex] = true;
1195 mCurrentFrame.fbCount++;
1196 }
1197 } else {
1198 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001199 private_handle_t *hnd = (private_handle_t *)layer->handle;
1200 if(!secureOnly || isSecureBuffer(hnd)) {
1201 mCurrentFrame.isFBComposed[nYuvIndex] = false;
1202 mCurrentFrame.fbCount--;
1203 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001204 }
1205 }
1206 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001207
1208 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001209 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
1210 ALOGD_IF(isDebug(),"%s: fb count: %d",__FUNCTION__,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001211 mCurrentFrame.fbCount);
1212}
1213
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001214hwc_rect_t MDPComp::getUpdatingFBRect(hwc_context_t *ctx,
1215 hwc_display_contents_1_t* list){
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001216 hwc_rect_t fbRect = (struct hwc_rect){0, 0, 0, 0};
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001217
1218 /* Update only the region of FB needed for composition */
1219 for(int i = 0; i < mCurrentFrame.layerCount; i++ ) {
1220 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
1221 hwc_layer_1_t* layer = &list->hwLayers[i];
1222 hwc_rect_t dst = layer->displayFrame;
1223 fbRect = getUnion(fbRect, dst);
1224 }
1225 }
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001226 trimAgainstROI(ctx, fbRect);
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001227 return fbRect;
1228}
1229
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001230bool MDPComp::postHeuristicsHandling(hwc_context_t *ctx,
1231 hwc_display_contents_1_t* list) {
1232
1233 //Capability checks
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301234 if(!resourceCheck()) {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001235 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
1236 return false;
1237 }
1238
1239 //Limitations checks
1240 if(!hwLimitationsCheck(ctx, list)) {
1241 ALOGD_IF(isDebug(), "%s: HW limitations",__FUNCTION__);
1242 return false;
1243 }
1244
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001245 //Configure framebuffer first if applicable
1246 if(mCurrentFrame.fbZ >= 0) {
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001247 hwc_rect_t fbRect = getUpdatingFBRect(ctx, list);
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001248 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, fbRect, mCurrentFrame.fbZ))
1249 {
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001250 ALOGD_IF(isDebug(), "%s configure framebuffer failed",
1251 __FUNCTION__);
1252 return false;
1253 }
1254 }
1255
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001256 mCurrentFrame.map();
1257
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001258 if(!allocLayerPipes(ctx, list)) {
1259 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -07001260 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001261 }
1262
1263 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001264 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001265 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001266 int mdpIndex = mCurrentFrame.layerToMDP[index];
1267 hwc_layer_1_t* layer = &list->hwLayers[index];
1268
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301269 //Leave fbZ for framebuffer. CACHE/GLES layers go here.
1270 if(mdpNextZOrder == mCurrentFrame.fbZ) {
1271 mdpNextZOrder++;
1272 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001273 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1274 cur_pipe->zOrder = mdpNextZOrder++;
1275
radhakrishnac9a67412013-09-25 17:40:42 +05301276 private_handle_t *hnd = (private_handle_t *)layer->handle;
1277 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1278 if(configure4k2kYuv(ctx, layer,
1279 mCurrentFrame.mdpToLayer[mdpIndex])
1280 != 0 ){
1281 ALOGD_IF(isDebug(), "%s: Failed to configure split pipes \
1282 for layer %d",__FUNCTION__, index);
1283 return false;
1284 }
1285 else{
1286 mdpNextZOrder++;
1287 }
1288 continue;
1289 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001290 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
1291 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
radhakrishnac9a67412013-09-25 17:40:42 +05301292 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -07001293 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001294 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001295 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001296 }
1297
Saurabh Shaha36be922013-12-16 18:18:39 -08001298 if(!ctx->mOverlay->validateAndSet(mDpy, ctx->dpyAttr[mDpy].fd)) {
1299 ALOGD_IF(isDebug(), "%s: Failed to validate and set overlay for dpy %d"
1300 ,__FUNCTION__, mDpy);
1301 return false;
1302 }
1303
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001304 setRedraw(ctx, list);
Saurabh Shahaa236822013-04-24 18:07:26 -07001305 return true;
1306}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001307
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301308bool MDPComp::resourceCheck() {
Saurabh Shah173f4242013-11-20 09:50:12 -08001309 const bool fbUsed = mCurrentFrame.fbCount;
1310 if(mCurrentFrame.mdpCount > sMaxPipesPerMixer - fbUsed) {
1311 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
1312 return false;
1313 }
Saurabh Shah173f4242013-11-20 09:50:12 -08001314 return true;
1315}
1316
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301317bool MDPComp::hwLimitationsCheck(hwc_context_t* ctx,
1318 hwc_display_contents_1_t* list) {
1319
1320 //A-family hw limitation:
1321 //If a layer need alpha scaling, MDP can not support.
1322 if(ctx->mMDP.version < qdutils::MDSS_V5) {
1323 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1324 if(!mCurrentFrame.isFBComposed[i] &&
1325 isAlphaScaled( &list->hwLayers[i])) {
1326 ALOGD_IF(isDebug(), "%s:frame needs alphaScaling",__FUNCTION__);
1327 return false;
1328 }
1329 }
1330 }
1331
1332 // On 8x26 & 8974 hw, we have a limitation of downscaling+blending.
1333 //If multiple layers requires downscaling and also they are overlapping
1334 //fall back to GPU since MDSS can not handle it.
1335 if(qdutils::MDPVersion::getInstance().is8x74v2() ||
1336 qdutils::MDPVersion::getInstance().is8x26()) {
1337 for(int i = 0; i < mCurrentFrame.layerCount-1; ++i) {
1338 hwc_layer_1_t* botLayer = &list->hwLayers[i];
1339 if(!mCurrentFrame.isFBComposed[i] &&
1340 isDownscaleRequired(botLayer)) {
1341 //if layer-i is marked for MDP and needs downscaling
1342 //check if any MDP layer on top of i & overlaps with layer-i
1343 for(int j = i+1; j < mCurrentFrame.layerCount; ++j) {
1344 hwc_layer_1_t* topLayer = &list->hwLayers[j];
1345 if(!mCurrentFrame.isFBComposed[j] &&
1346 isDownscaleRequired(topLayer)) {
1347 hwc_rect_t r = getIntersection(botLayer->displayFrame,
1348 topLayer->displayFrame);
1349 if(isValidRect(r))
1350 return false;
1351 }
1352 }
1353 }
1354 }
1355 }
1356 return true;
1357}
1358
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001359int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001360 int ret = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -07001361 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -07001362
Raj Kamal9ed3d6b2014-02-07 16:15:17 +05301363 //Do not cache the information for next draw cycle.
1364 if(numLayers > MAX_NUM_APP_LAYERS or (!numLayers)) {
1365 ALOGI("%s: Unsupported layer count for mdp composition",
1366 __FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001367 mCachedFrame.reset();
1368 return -1;
1369 }
1370
Saurabh Shahb39f8152013-08-22 10:21:44 -07001371 //reset old data
1372 mCurrentFrame.reset(numLayers);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001373 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1374 mCurrentFrame.dropCount = 0;
Prabhanjan Kandula088bd892013-07-02 23:47:13 +05301375
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -07001376 // Detect the start of animation and fall back to GPU only once to cache
1377 // all the layers in FB and display FB content untill animation completes.
1378 if(ctx->listStats[mDpy].isDisplayAnimating) {
1379 mCurrentFrame.needsRedraw = false;
1380 if(ctx->mAnimationState[mDpy] == ANIMATION_STOPPED) {
1381 mCurrentFrame.needsRedraw = true;
1382 ctx->mAnimationState[mDpy] = ANIMATION_STARTED;
1383 }
1384 setMDPCompLayerFlags(ctx, list);
1385 mCachedFrame.updateCounts(mCurrentFrame);
1386 ret = -1;
1387 return ret;
1388 } else {
1389 ctx->mAnimationState[mDpy] = ANIMATION_STOPPED;
1390 }
1391
Saurabh Shahb39f8152013-08-22 10:21:44 -07001392 //Hard conditions, if not met, cannot do MDP comp
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001393 if(isFrameDoable(ctx)) {
1394 generateROI(ctx, list);
Saurabh Shahb39f8152013-08-22 10:21:44 -07001395
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001396 if(tryFullFrame(ctx, list) || tryVideoOnly(ctx, list)) {
1397 setMDPCompLayerFlags(ctx, list);
1398 } else {
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001399 resetROI(ctx, mDpy);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001400 reset(ctx);
1401 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1402 mCurrentFrame.dropCount = 0;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001403 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001404 }
1405 } else {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001406 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
1407 __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001408 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001409 }
Saurabh Shahb39f8152013-08-22 10:21:44 -07001410
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001411 if(isDebug()) {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001412 ALOGD("GEOMETRY change: %d",
1413 (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001414 android::String8 sDump("");
1415 dump(sDump);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001416 ALOGD("%s",sDump.string());
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001417 }
1418
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001419 mCachedFrame.cacheAll(list);
1420 mCachedFrame.updateCounts(mCurrentFrame);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001421 return ret;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001422}
1423
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001424bool MDPComp::allocSplitVGPipesfor4k2k(hwc_context_t *ctx, int index) {
radhakrishnac9a67412013-09-25 17:40:42 +05301425
1426 bool bRet = true;
radhakrishnac9a67412013-09-25 17:40:42 +05301427 int mdpIndex = mCurrentFrame.layerToMDP[index];
1428 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
1429 info.pipeInfo = new MdpYUVPipeInfo;
1430 info.rot = NULL;
1431 MdpYUVPipeInfo& pipe_info = *(MdpYUVPipeInfo*)info.pipeInfo;
radhakrishnac9a67412013-09-25 17:40:42 +05301432
1433 pipe_info.lIndex = ovutils::OV_INVALID;
1434 pipe_info.rIndex = ovutils::OV_INVALID;
1435
Saurabh Shahc62f3982014-03-05 14:28:26 -08001436 Overlay::PipeSpecs pipeSpecs;
1437 pipeSpecs.formatClass = Overlay::FORMAT_YUV;
1438 pipeSpecs.needsScaling = true;
1439 pipeSpecs.dpy = mDpy;
1440 pipeSpecs.fb = false;
1441
1442 pipe_info.lIndex = ctx->mOverlay->getPipe(pipeSpecs);
radhakrishnac9a67412013-09-25 17:40:42 +05301443 if(pipe_info.lIndex == ovutils::OV_INVALID){
1444 bRet = false;
1445 ALOGD_IF(isDebug(),"%s: allocating first VG pipe failed",
1446 __FUNCTION__);
1447 }
Saurabh Shahc62f3982014-03-05 14:28:26 -08001448 pipe_info.rIndex = ctx->mOverlay->getPipe(pipeSpecs);
radhakrishnac9a67412013-09-25 17:40:42 +05301449 if(pipe_info.rIndex == ovutils::OV_INVALID){
1450 bRet = false;
1451 ALOGD_IF(isDebug(),"%s: allocating second VG pipe failed",
1452 __FUNCTION__);
1453 }
1454 return bRet;
1455}
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001456//=============MDPCompNonSplit==================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001457
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001458void MDPCompNonSplit::adjustForSourceSplit(hwc_context_t *ctx,
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001459 hwc_display_contents_1_t*) {
radhakrishnac9a67412013-09-25 17:40:42 +05301460 //As we split 4kx2k yuv layer and program to 2 VG pipes
1461 //(if available) increase mdpcount accordingly
1462 mCurrentFrame.mdpCount += ctx->listStats[mDpy].yuv4k2kCount;
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001463
1464 //If 4k2k Yuv layer split is possible, and if
1465 //fbz is above 4k2k layer, increment fb zorder by 1
1466 //as we split 4k2k layer and increment zorder for right half
1467 //of the layer
1468 if(mCurrentFrame.fbZ >= 0) {
1469 int n4k2kYuvCount = ctx->listStats[mDpy].yuv4k2kCount;
1470 for(int index = 0; index < n4k2kYuvCount; index++){
1471 int n4k2kYuvIndex =
1472 ctx->listStats[mDpy].yuv4k2kIndices[index];
Dileep Kumar Reddi4cff9282014-04-01 12:57:08 +05301473 if(mCurrentFrame.fbZ >= n4k2kYuvIndex){
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001474 mCurrentFrame.fbZ += 1;
1475 }
1476 }
1477 }
radhakrishnac9a67412013-09-25 17:40:42 +05301478}
1479
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001480/*
1481 * Configures pipe(s) for MDP composition
1482 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001483int MDPCompNonSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001484 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001485 MdpPipeInfoNonSplit& mdp_info =
1486 *(static_cast<MdpPipeInfoNonSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001487 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
1488 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1489 eIsFg isFg = IS_FG_OFF;
1490 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001491
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001492 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
1493 __FUNCTION__, layer, zOrder, dest);
1494
Saurabh Shah88e4d272013-09-03 13:31:29 -07001495 return configureNonSplit(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001496 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001497}
1498
Saurabh Shah88e4d272013-09-03 13:31:29 -07001499bool MDPCompNonSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001500 hwc_display_contents_1_t* list) {
1501 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001502
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001503 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001504
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001505 hwc_layer_1_t* layer = &list->hwLayers[index];
1506 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301507 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001508 if(allocSplitVGPipesfor4k2k(ctx, index)){
radhakrishnac9a67412013-09-25 17:40:42 +05301509 continue;
1510 }
1511 }
1512
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001513 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001514 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001515 info.pipeInfo = new MdpPipeInfoNonSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08001516 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001517 MdpPipeInfoNonSplit& pipe_info = *(MdpPipeInfoNonSplit*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001518
Saurabh Shahc62f3982014-03-05 14:28:26 -08001519 Overlay::PipeSpecs pipeSpecs;
1520 pipeSpecs.formatClass = isYuvBuffer(hnd) ?
1521 Overlay::FORMAT_YUV : Overlay::FORMAT_RGB;
1522 pipeSpecs.needsScaling = qhwc::needsScaling(layer) or
1523 (qdutils::MDPVersion::getInstance().is8x26() and
1524 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres > 1024);
1525 pipeSpecs.dpy = mDpy;
1526 pipeSpecs.fb = false;
Xu Yang1e686f62014-04-08 13:56:47 +08001527 pipeSpecs.numActiveDisplays = ctx->numActiveDisplays;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001528
Saurabh Shahc62f3982014-03-05 14:28:26 -08001529 pipe_info.index = ctx->mOverlay->getPipe(pipeSpecs);
1530
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001531 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001532 ALOGD_IF(isDebug(), "%s: Unable to get pipe", __FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001533 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001534 }
1535 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001536 return true;
1537}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001538
radhakrishnac9a67412013-09-25 17:40:42 +05301539int MDPCompNonSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1540 PipeLayerPair& PipeLayerPair) {
1541 MdpYUVPipeInfo& mdp_info =
1542 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1543 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1544 eIsFg isFg = IS_FG_OFF;
1545 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1546 eDest lDest = mdp_info.lIndex;
1547 eDest rDest = mdp_info.rIndex;
1548
1549 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1550 lDest, rDest, &PipeLayerPair.rot);
1551}
1552
Saurabh Shah88e4d272013-09-03 13:31:29 -07001553bool MDPCompNonSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001554
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001555 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001556 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1557 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -08001558 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001559
1560 if(!ctx || !list) {
1561 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001562 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001563 }
1564
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301565 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1566 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1567 return true;
1568 }
1569
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -08001570 // Set the Handle timeout to true for MDP or MIXED composition.
1571 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount) {
1572 sHandleTimeout = true;
1573 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001574
1575 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001576 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001577
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001578 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1579 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001580 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001581 if(mCurrentFrame.isFBComposed[i]) continue;
1582
Naseer Ahmed5b6708a2012-08-02 13:46:08 -07001583 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001584 private_handle_t *hnd = (private_handle_t *)layer->handle;
1585 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001586 if (!(layer->flags & HWC_COLOR_FILL)) {
1587 ALOGE("%s handle null", __FUNCTION__);
1588 return false;
1589 }
1590 // No PLAY for Color layer
1591 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1592 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001593 }
1594
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001595 int mdpIndex = mCurrentFrame.layerToMDP[i];
1596
radhakrishnac9a67412013-09-25 17:40:42 +05301597 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1598 {
1599 MdpYUVPipeInfo& pipe_info =
1600 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1601 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1602 ovutils::eDest indexL = pipe_info.lIndex;
1603 ovutils::eDest indexR = pipe_info.rIndex;
1604 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301605 uint32_t offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05301606 if(rot) {
1607 rot->queueBuffer(fd, offset);
1608 fd = rot->getDstMemId();
1609 offset = rot->getDstOffset();
1610 }
1611 if(indexL != ovutils::OV_INVALID) {
1612 ovutils::eDest destL = (ovutils::eDest)indexL;
1613 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1614 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1615 if (!ov.queueBuffer(fd, offset, destL)) {
1616 ALOGE("%s: queueBuffer failed for display:%d",
1617 __FUNCTION__, mDpy);
1618 return false;
1619 }
1620 }
1621
1622 if(indexR != ovutils::OV_INVALID) {
1623 ovutils::eDest destR = (ovutils::eDest)indexR;
1624 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1625 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1626 if (!ov.queueBuffer(fd, offset, destR)) {
1627 ALOGE("%s: queueBuffer failed for display:%d",
1628 __FUNCTION__, mDpy);
1629 return false;
1630 }
1631 }
1632 }
1633 else{
1634 MdpPipeInfoNonSplit& pipe_info =
Saurabh Shah88e4d272013-09-03 13:31:29 -07001635 *(MdpPipeInfoNonSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
radhakrishnac9a67412013-09-25 17:40:42 +05301636 ovutils::eDest dest = pipe_info.index;
1637 if(dest == ovutils::OV_INVALID) {
1638 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001639 return false;
radhakrishnac9a67412013-09-25 17:40:42 +05301640 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001641
radhakrishnac9a67412013-09-25 17:40:42 +05301642 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1643 continue;
1644 }
1645
1646 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1647 using pipe: %d", __FUNCTION__, layer,
1648 hnd, dest );
1649
1650 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301651 uint32_t offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05301652
1653 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1654 if(rot) {
1655 if(!rot->queueBuffer(fd, offset))
1656 return false;
1657 fd = rot->getDstMemId();
1658 offset = rot->getDstOffset();
1659 }
1660
1661 if (!ov.queueBuffer(fd, offset, dest)) {
1662 ALOGE("%s: queueBuffer failed for display:%d ",
1663 __FUNCTION__, mDpy);
1664 return false;
1665 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001666 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001667
1668 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001669 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001670 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001671}
1672
Saurabh Shah88e4d272013-09-03 13:31:29 -07001673//=============MDPCompSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001674
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001675void MDPCompSplit::adjustForSourceSplit(hwc_context_t *ctx,
radhakrishnac9a67412013-09-25 17:40:42 +05301676 hwc_display_contents_1_t* list){
1677 //if 4kx2k yuv layer is totally present in either in left half
1678 //or right half then try splitting the yuv layer to avoid decimation
1679 int n4k2kYuvCount = ctx->listStats[mDpy].yuv4k2kCount;
1680 const int lSplit = getLeftSplit(ctx, mDpy);
1681 for(int index = 0; index < n4k2kYuvCount; index++){
1682 int n4k2kYuvIndex = ctx->listStats[mDpy].yuv4k2kIndices[index];
1683 hwc_layer_1_t* layer = &list->hwLayers[n4k2kYuvIndex];
1684 hwc_rect_t dst = layer->displayFrame;
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001685 if((dst.left > lSplit) || (dst.right < lSplit)) {
radhakrishnac9a67412013-09-25 17:40:42 +05301686 mCurrentFrame.mdpCount += 1;
1687 }
Dileep Kumar Reddi4cff9282014-04-01 12:57:08 +05301688 if(mCurrentFrame.fbZ >= n4k2kYuvIndex){
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001689 mCurrentFrame.fbZ += 1;
1690 }
radhakrishnac9a67412013-09-25 17:40:42 +05301691 }
1692}
1693
Saurabh Shah88e4d272013-09-03 13:31:29 -07001694bool MDPCompSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Saurabh Shahc62f3982014-03-05 14:28:26 -08001695 MdpPipeInfoSplit& pipe_info) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001696
Saurabh Shahc62f3982014-03-05 14:28:26 -08001697 const int lSplit = getLeftSplit(ctx, mDpy);
1698 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001699 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001700 pipe_info.lIndex = ovutils::OV_INVALID;
1701 pipe_info.rIndex = ovutils::OV_INVALID;
1702
Saurabh Shahc62f3982014-03-05 14:28:26 -08001703 Overlay::PipeSpecs pipeSpecs;
1704 pipeSpecs.formatClass = isYuvBuffer(hnd) ?
1705 Overlay::FORMAT_YUV : Overlay::FORMAT_RGB;
1706 pipeSpecs.needsScaling = qhwc::needsScalingWithSplit(ctx, layer, mDpy);
1707 pipeSpecs.dpy = mDpy;
1708 pipeSpecs.mixer = Overlay::MIXER_LEFT;
1709 pipeSpecs.fb = false;
1710
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001711 // Acquire pipe only for the updating half
1712 hwc_rect_t l_roi = ctx->listStats[mDpy].lRoi;
1713 hwc_rect_t r_roi = ctx->listStats[mDpy].rRoi;
1714
1715 if (dst.left < lSplit && isValidRect(getIntersection(dst, l_roi))) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001716 pipe_info.lIndex = ctx->mOverlay->getPipe(pipeSpecs);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001717 if(pipe_info.lIndex == ovutils::OV_INVALID)
1718 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001719 }
1720
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001721 if(dst.right > lSplit && isValidRect(getIntersection(dst, r_roi))) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001722 pipeSpecs.mixer = Overlay::MIXER_RIGHT;
1723 pipe_info.rIndex = ctx->mOverlay->getPipe(pipeSpecs);
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001724 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001725 return false;
1726 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001727
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001728 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001729}
1730
Saurabh Shah88e4d272013-09-03 13:31:29 -07001731bool MDPCompSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001732 hwc_display_contents_1_t* list) {
1733 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001734
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001735 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001736
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001737 hwc_layer_1_t* layer = &list->hwLayers[index];
1738 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301739 hwc_rect_t dst = layer->displayFrame;
1740 const int lSplit = getLeftSplit(ctx, mDpy);
1741 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1742 if((dst.left > lSplit)||(dst.right < lSplit)){
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001743 if(allocSplitVGPipesfor4k2k(ctx, index)){
radhakrishnac9a67412013-09-25 17:40:42 +05301744 continue;
1745 }
1746 }
1747 }
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001748 int mdpIndex = mCurrentFrame.layerToMDP[index];
1749 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001750 info.pipeInfo = new MdpPipeInfoSplit;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001751 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001752 MdpPipeInfoSplit& pipe_info = *(MdpPipeInfoSplit*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001753
Saurabh Shahc62f3982014-03-05 14:28:26 -08001754 if(!acquireMDPPipes(ctx, layer, pipe_info)) {
1755 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type",
1756 __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001757 return false;
1758 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001759 }
1760 return true;
1761}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001762
radhakrishnac9a67412013-09-25 17:40:42 +05301763int MDPCompSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1764 PipeLayerPair& PipeLayerPair) {
1765 const int lSplit = getLeftSplit(ctx, mDpy);
1766 hwc_rect_t dst = layer->displayFrame;
1767 if((dst.left > lSplit)||(dst.right < lSplit)){
1768 MdpYUVPipeInfo& mdp_info =
1769 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1770 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1771 eIsFg isFg = IS_FG_OFF;
1772 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1773 eDest lDest = mdp_info.lIndex;
1774 eDest rDest = mdp_info.rIndex;
1775
1776 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1777 lDest, rDest, &PipeLayerPair.rot);
1778 }
1779 else{
1780 return configure(ctx, layer, PipeLayerPair);
1781 }
1782}
1783
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001784/*
1785 * Configures pipe(s) for MDP composition
1786 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001787int MDPCompSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001788 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001789 MdpPipeInfoSplit& mdp_info =
1790 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001791 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1792 eIsFg isFg = IS_FG_OFF;
1793 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1794 eDest lDest = mdp_info.lIndex;
1795 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001796
1797 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1798 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1799
Saurabh Shah88e4d272013-09-03 13:31:29 -07001800 return configureSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001801 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001802}
1803
Saurabh Shah88e4d272013-09-03 13:31:29 -07001804bool MDPCompSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001805
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001806 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001807 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1808 return true;
1809 }
1810
1811 if(!ctx || !list) {
1812 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001813 return false;
1814 }
1815
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301816 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1817 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1818 return true;
1819 }
1820
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -08001821 // Set the Handle timeout to true for MDP or MIXED composition.
1822 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount) {
1823 sHandleTimeout = true;
1824 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001825
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001826 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001827 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001828
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001829 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1830 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001831 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001832 if(mCurrentFrame.isFBComposed[i]) continue;
1833
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001834 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001835 private_handle_t *hnd = (private_handle_t *)layer->handle;
1836 if(!hnd) {
1837 ALOGE("%s handle null", __FUNCTION__);
1838 return false;
1839 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001840
1841 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1842 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001843 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001844
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001845 int mdpIndex = mCurrentFrame.layerToMDP[i];
1846
radhakrishnac9a67412013-09-25 17:40:42 +05301847 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1848 {
1849 MdpYUVPipeInfo& pipe_info =
1850 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1851 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1852 ovutils::eDest indexL = pipe_info.lIndex;
1853 ovutils::eDest indexR = pipe_info.rIndex;
1854 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301855 uint32_t offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05301856 if(rot) {
1857 rot->queueBuffer(fd, offset);
1858 fd = rot->getDstMemId();
1859 offset = rot->getDstOffset();
1860 }
1861 if(indexL != ovutils::OV_INVALID) {
1862 ovutils::eDest destL = (ovutils::eDest)indexL;
1863 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1864 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1865 if (!ov.queueBuffer(fd, offset, destL)) {
1866 ALOGE("%s: queueBuffer failed for display:%d",
1867 __FUNCTION__, mDpy);
1868 return false;
1869 }
1870 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001871
radhakrishnac9a67412013-09-25 17:40:42 +05301872 if(indexR != ovutils::OV_INVALID) {
1873 ovutils::eDest destR = (ovutils::eDest)indexR;
1874 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1875 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1876 if (!ov.queueBuffer(fd, offset, destR)) {
1877 ALOGE("%s: queueBuffer failed for display:%d",
1878 __FUNCTION__, mDpy);
1879 return false;
1880 }
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001881 }
1882 }
radhakrishnac9a67412013-09-25 17:40:42 +05301883 else{
1884 MdpPipeInfoSplit& pipe_info =
1885 *(MdpPipeInfoSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1886 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001887
radhakrishnac9a67412013-09-25 17:40:42 +05301888 ovutils::eDest indexL = pipe_info.lIndex;
1889 ovutils::eDest indexR = pipe_info.rIndex;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001890
radhakrishnac9a67412013-09-25 17:40:42 +05301891 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301892 int offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05301893
1894 if(ctx->mAD->isModeOn()) {
1895 if(ctx->mAD->draw(ctx, fd, offset)) {
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001896 fd = ctx->mAD->getDstFd();
1897 offset = ctx->mAD->getDstOffset();
radhakrishnac9a67412013-09-25 17:40:42 +05301898 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001899 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001900
radhakrishnac9a67412013-09-25 17:40:42 +05301901 if(rot) {
1902 rot->queueBuffer(fd, offset);
1903 fd = rot->getDstMemId();
1904 offset = rot->getDstOffset();
1905 }
1906
1907 //************* play left mixer **********
1908 if(indexL != ovutils::OV_INVALID) {
1909 ovutils::eDest destL = (ovutils::eDest)indexL;
1910 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1911 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1912 if (!ov.queueBuffer(fd, offset, destL)) {
1913 ALOGE("%s: queueBuffer failed for left mixer",
1914 __FUNCTION__);
1915 return false;
1916 }
1917 }
1918
1919 //************* play right mixer **********
1920 if(indexR != ovutils::OV_INVALID) {
1921 ovutils::eDest destR = (ovutils::eDest)indexR;
1922 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1923 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1924 if (!ov.queueBuffer(fd, offset, destR)) {
1925 ALOGE("%s: queueBuffer failed for right mixer",
1926 __FUNCTION__);
1927 return false;
1928 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001929 }
1930 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001931
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001932 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1933 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001934
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001935 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001936}
Saurabh Shahab47c692014-02-12 18:45:57 -08001937
1938//================MDPCompSrcSplit==============================================
1939bool MDPCompSrcSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Saurabh Shahc62f3982014-03-05 14:28:26 -08001940 MdpPipeInfoSplit& pipe_info) {
Saurabh Shahab47c692014-02-12 18:45:57 -08001941 private_handle_t *hnd = (private_handle_t *)layer->handle;
1942 hwc_rect_t dst = layer->displayFrame;
1943 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
1944 pipe_info.lIndex = ovutils::OV_INVALID;
1945 pipe_info.rIndex = ovutils::OV_INVALID;
1946
1947 //If 2 pipes are staged on a single stage of a mixer, then the left pipe
1948 //should have a higher priority than the right one. Pipe priorities are
1949 //starting with VG0, VG1 ... , RGB0 ..., DMA1
Saurabh Shahab47c692014-02-12 18:45:57 -08001950
Saurabh Shahc62f3982014-03-05 14:28:26 -08001951 Overlay::PipeSpecs pipeSpecs;
1952 pipeSpecs.formatClass = isYuvBuffer(hnd) ?
1953 Overlay::FORMAT_YUV : Overlay::FORMAT_RGB;
1954 pipeSpecs.needsScaling = qhwc::needsScaling(layer);
1955 pipeSpecs.dpy = mDpy;
1956 pipeSpecs.fb = false;
1957
Saurabh Shahab47c692014-02-12 18:45:57 -08001958 //1 pipe by default for a layer
Saurabh Shahc62f3982014-03-05 14:28:26 -08001959 pipe_info.lIndex = ctx->mOverlay->getPipe(pipeSpecs);
Saurabh Shahab47c692014-02-12 18:45:57 -08001960 if(pipe_info.lIndex == ovutils::OV_INVALID) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001961 return false;
Saurabh Shahab47c692014-02-12 18:45:57 -08001962 }
1963
1964 //If layer's crop width or dest width > 2048, use 2 pipes
1965 if((dst.right - dst.left) > qdutils::MAX_DISPLAY_DIM or
1966 (crop.right - crop.left) > qdutils::MAX_DISPLAY_DIM) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001967 pipe_info.rIndex = ctx->mOverlay->getPipe(pipeSpecs);
Saurabh Shahab47c692014-02-12 18:45:57 -08001968 if(pipe_info.rIndex == ovutils::OV_INVALID) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001969 return false;
Saurabh Shahdd8237a2014-02-28 14:29:09 -08001970 }
1971
1972 // Return values
1973 // 1 Left pipe is higher priority, do nothing.
1974 // 0 Pipes of same priority.
1975 //-1 Right pipe is of higher priority, needs swap.
1976 if(ctx->mOverlay->comparePipePriority(pipe_info.lIndex,
1977 pipe_info.rIndex) == -1) {
1978 qhwc::swap(pipe_info.lIndex, pipe_info.rIndex);
Saurabh Shahab47c692014-02-12 18:45:57 -08001979 }
1980 }
1981
1982 return true;
1983}
1984
Saurabh Shahab47c692014-02-12 18:45:57 -08001985int MDPCompSrcSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
1986 PipeLayerPair& PipeLayerPair) {
1987 private_handle_t *hnd = (private_handle_t *)layer->handle;
1988 if(!hnd) {
1989 ALOGE("%s: layer handle is NULL", __FUNCTION__);
1990 return -1;
1991 }
1992 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
1993 MdpPipeInfoSplit& mdp_info =
1994 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
1995 Rotator **rot = &PipeLayerPair.rot;
1996 eZorder z = static_cast<eZorder>(mdp_info.zOrder);
1997 eIsFg isFg = IS_FG_OFF;
1998 eDest lDest = mdp_info.lIndex;
1999 eDest rDest = mdp_info.rIndex;
2000 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
2001 hwc_rect_t dst = layer->displayFrame;
2002 int transform = layer->transform;
2003 eTransform orient = static_cast<eTransform>(transform);
2004 const int downscale = 0;
2005 int rotFlags = ROT_FLAGS_NONE;
2006 uint32_t format = ovutils::getMdpFormat(hnd->format, isTileRendered(hnd));
2007 Whf whf(getWidth(hnd), getHeight(hnd), format, hnd->size);
2008
2009 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
2010 "dest_pipeR: %d",__FUNCTION__, layer, z, lDest, rDest);
2011
2012 // Handle R/B swap
2013 if (layer->flags & HWC_FORMAT_RB_SWAP) {
2014 if (hnd->format == HAL_PIXEL_FORMAT_RGBA_8888)
2015 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRA_8888);
2016 else if (hnd->format == HAL_PIXEL_FORMAT_RGBX_8888)
2017 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRX_8888);
2018 }
2019
Saurabh Shah97e2d802014-04-14 18:03:54 -07002020 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
2021 setMdpFlags(layer, mdpFlags, 0, transform);
Saurabh Shahab47c692014-02-12 18:45:57 -08002022
2023 if(lDest != OV_INVALID && rDest != OV_INVALID) {
2024 //Enable overfetch
Saurabh Shah97e2d802014-04-14 18:03:54 -07002025 setMdpFlags(mdpFlags, OV_MDSS_MDP_DUAL_PIPE);
Saurabh Shahab47c692014-02-12 18:45:57 -08002026 }
2027
2028 if(isYuvBuffer(hnd) && (transform & HWC_TRANSFORM_ROT_90)) {
2029 (*rot) = ctx->mRotMgr->getNext();
2030 if((*rot) == NULL) return -1;
Saurabh Shah39240c92014-03-31 10:31:42 -07002031 ctx->mLayerRotMap[mDpy]->add(layer, *rot);
Saurabh Shahab47c692014-02-12 18:45:57 -08002032 //Configure rotator for pre-rotation
Saurabh Shah97e2d802014-04-14 18:03:54 -07002033 if(configRotator(*rot, whf, crop, mdpFlags, orient, downscale) < 0) {
Saurabh Shahab47c692014-02-12 18:45:57 -08002034 ALOGE("%s: configRotator failed!", __FUNCTION__);
2035 return -1;
2036 }
Saurabh Shahab47c692014-02-12 18:45:57 -08002037 whf.format = (*rot)->getDstFormat();
2038 updateSource(orient, whf, crop);
2039 rotFlags |= ROT_PREROTATED;
2040 }
2041
2042 //If 2 pipes being used, divide layer into half, crop and dst
2043 hwc_rect_t cropL = crop;
2044 hwc_rect_t cropR = crop;
2045 hwc_rect_t dstL = dst;
2046 hwc_rect_t dstR = dst;
2047 if(lDest != OV_INVALID && rDest != OV_INVALID) {
2048 cropL.right = (crop.right + crop.left) / 2;
2049 cropR.left = cropL.right;
2050 sanitizeSourceCrop(cropL, cropR, hnd);
2051
2052 //Swap crops on H flip since 2 pipes are being used
2053 if((orient & OVERLAY_TRANSFORM_FLIP_H) && (*rot) == NULL) {
2054 hwc_rect_t tmp = cropL;
2055 cropL = cropR;
2056 cropR = tmp;
2057 }
2058
2059 dstL.right = (dst.right + dst.left) / 2;
2060 dstR.left = dstL.right;
2061 }
2062
2063 //For the mdp, since either we are pre-rotating or MDP does flips
2064 orient = OVERLAY_TRANSFORM_0;
2065 transform = 0;
2066
2067 //configure left pipe
2068 if(lDest != OV_INVALID) {
Saurabh Shah97e2d802014-04-14 18:03:54 -07002069 PipeArgs pargL(mdpFlags, whf, z, isFg,
Saurabh Shahab47c692014-02-12 18:45:57 -08002070 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2071 (ovutils::eBlending) getBlending(layer->blending));
2072
2073 if(configMdp(ctx->mOverlay, pargL, orient,
2074 cropL, dstL, metadata, lDest) < 0) {
2075 ALOGE("%s: commit failed for left mixer config", __FUNCTION__);
2076 return -1;
2077 }
2078 }
2079
2080 //configure right pipe
2081 if(rDest != OV_INVALID) {
Saurabh Shah97e2d802014-04-14 18:03:54 -07002082 PipeArgs pargR(mdpFlags, whf, z, isFg,
Saurabh Shahab47c692014-02-12 18:45:57 -08002083 static_cast<eRotFlags>(rotFlags),
2084 layer->planeAlpha,
2085 (ovutils::eBlending) getBlending(layer->blending));
2086 if(configMdp(ctx->mOverlay, pargR, orient,
2087 cropR, dstR, metadata, rDest) < 0) {
2088 ALOGE("%s: commit failed for right mixer config", __FUNCTION__);
2089 return -1;
2090 }
2091 }
2092
2093 return 0;
2094}
2095
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002096}; //namespace
2097