blob: e72d0eaac691873a62c0a64f785de18e51bddb52 [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)) {
582 hwc_rect_t updatingRect = layer->displayFrame;
583
584#ifdef QCOM_BSP
585 if(!needsScaling(layer) && !layer->transform)
586 updatingRect = layer->dirtyRect;
587#endif
588
589 hwc_rect_t l_dst = getIntersection(l_frame, updatingRect);
590 if(isValidRect(l_dst))
591 l_roi = getUnion(l_roi, l_dst);
592
593 hwc_rect_t r_dst = getIntersection(r_frame, updatingRect);
594 if(isValidRect(r_dst))
595 r_roi = getUnion(r_roi, r_dst);
596 }
597 }
598
Jeykumar Sankarana40a9342014-04-25 09:37:10 -0700599 /* For panels that cannot accept commands in both the interfaces, we cannot
600 * send two ROI's (for each half). We merge them into single ROI and split
601 * them across lSplit for MDP mixer use. The ROI's will be merged again
602 * finally before udpating the panel in the driver. */
603 if(qdutils::MDPVersion::getInstance().needsROIMerge()) {
604 hwc_rect_t temp_roi = getUnion(l_roi, r_roi);
605 l_roi = getIntersection(temp_roi, l_frame);
606 r_roi = getIntersection(temp_roi, r_frame);
607 }
608
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800609 /* No layer is updating. Still SF wants a refresh. */
610 if(!isValidRect(l_roi) && !isValidRect(r_roi))
611 return;
612
613 l_roi = getSanitizeROI(l_roi, l_frame);
614 r_roi = getSanitizeROI(r_roi, r_frame);
615
616 ctx->listStats[mDpy].lRoi = l_roi;
617 ctx->listStats[mDpy].rRoi = r_roi;
618
619 if(!validateAndApplyROI(ctx, list))
620 resetROI(ctx, mDpy);
621
622 ALOGD_IF(isDebug(),"%s: generated L_ROI: [%d, %d, %d, %d]"
623 "R_ROI: [%d, %d, %d, %d]", __FUNCTION__,
624 ctx->listStats[mDpy].lRoi.left, ctx->listStats[mDpy].lRoi.top,
625 ctx->listStats[mDpy].lRoi.right, ctx->listStats[mDpy].lRoi.bottom,
626 ctx->listStats[mDpy].rRoi.left, ctx->listStats[mDpy].rRoi.top,
627 ctx->listStats[mDpy].rRoi.right, ctx->listStats[mDpy].rRoi.bottom);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700628}
629
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800630/* Checks for conditions where all the layers marked for MDP comp cannot be
631 * bypassed. On such conditions we try to bypass atleast YUV layers */
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800632bool MDPComp::tryFullFrame(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800633 hwc_display_contents_1_t* list){
634
Saurabh Shahaa236822013-04-24 18:07:26 -0700635 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Arun Kumar K.R2e2871c2014-01-10 12:47:06 -0800636 int priDispW = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800637
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -0700638 if(sIdleFallBack && !ctx->listStats[mDpy].secureUI) {
Saurabh Shah2d998a92013-05-14 17:55:58 -0700639 ALOGD_IF(isDebug(), "%s: Idle fallback dpy %d",__FUNCTION__, mDpy);
640 return false;
641 }
642
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800643 if(isSkipPresent(ctx, mDpy)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700644 ALOGD_IF(isDebug(),"%s: SKIP present: %d",
645 __FUNCTION__,
646 isSkipPresent(ctx, mDpy));
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800647 return false;
648 }
649
Arun Kumar K.R2e2871c2014-01-10 12:47:06 -0800650 if(mDpy > HWC_DISPLAY_PRIMARY && (priDispW > MAX_DISPLAY_DIM) &&
651 (ctx->dpyAttr[mDpy].xres < MAX_DISPLAY_DIM)) {
652 // Disable MDP comp on Secondary when the primary is highres panel and
653 // the secondary is a normal 1080p, because, MDP comp on secondary under
654 // in such usecase, decimation gets used for downscale and there will be
655 // a quality mismatch when there will be a fallback to GPU comp
656 ALOGD_IF(isDebug(), "%s: Disable MDP Compositon for Secondary Disp",
657 __FUNCTION__);
658 return false;
659 }
660
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800661 // check for action safe flag and downscale mode which requires scaling.
662 if(ctx->dpyAttr[mDpy].mActionSafePresent
663 || ctx->dpyAttr[mDpy].mDownScaleMode) {
664 ALOGD_IF(isDebug(), "%s: Scaling needed for this frame",__FUNCTION__);
665 return false;
666 }
667
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800668 for(int i = 0; i < numAppLayers; ++i) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800669 hwc_layer_1_t* layer = &list->hwLayers[i];
670 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800671
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700672 if(isYuvBuffer(hnd) && has90Transform(layer)) {
673 if(!canUseRotator(ctx, mDpy)) {
674 ALOGD_IF(isDebug(), "%s: Can't use rotator for dpy %d",
675 __FUNCTION__, mDpy);
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700676 return false;
677 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800678 }
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530679
680 //For 8x26 with panel width>1k, if RGB layer needs HFLIP fail mdp comp
681 // may not need it if Gfx pre-rotation can handle all flips & rotations
Sushil Chauhanfda00fc2014-03-20 11:08:41 -0700682 int transform = (layer->flags & HWC_COLOR_FILL) ? 0 : layer->transform;
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530683 if(qdutils::MDPVersion::getInstance().is8x26() &&
684 (ctx->dpyAttr[mDpy].xres > 1024) &&
Sushil Chauhanfda00fc2014-03-20 11:08:41 -0700685 (transform & HWC_TRANSFORM_FLIP_H) &&
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530686 (!isYuvBuffer(hnd)))
687 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800688 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700689
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700690 if(ctx->mAD->isDoable()) {
691 return false;
692 }
693
Saurabh Shahaa236822013-04-24 18:07:26 -0700694 //If all above hard conditions are met we can do full or partial MDP comp.
695 bool ret = false;
696 if(fullMDPComp(ctx, list)) {
697 ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700698 } else if(partialMDPComp(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700699 ret = true;
700 }
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530701
Saurabh Shahaa236822013-04-24 18:07:26 -0700702 return ret;
703}
704
705bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700706 //Will benefit presentation / secondary-only layer.
707 if((mDpy > HWC_DISPLAY_PRIMARY) &&
708 (list->numHwLayers - 1) > MAX_SEC_LAYERS) {
709 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
710 return false;
711 }
712
713 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
714 for(int i = 0; i < numAppLayers; i++) {
715 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran880da832014-04-18 10:22:35 -0700716 if(not mCurrentFrame.drop[i] and
717 not isSupportedForMDPComp(ctx, layer)) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700718 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",__FUNCTION__);
719 return false;
720 }
721 }
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800722
Saurabh Shahaa236822013-04-24 18:07:26 -0700723 mCurrentFrame.fbCount = 0;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700724 memcpy(&mCurrentFrame.isFBComposed, &mCurrentFrame.drop,
725 sizeof(mCurrentFrame.isFBComposed));
726 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount -
727 mCurrentFrame.dropCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700728
radhakrishnac9a67412013-09-25 17:40:42 +0530729 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800730 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530731 }
732
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800733 if(!postHeuristicsHandling(ctx, list)) {
734 ALOGD_IF(isDebug(), "post heuristic handling failed");
735 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700736 return false;
737 }
738
Saurabh Shahaa236822013-04-24 18:07:26 -0700739 return true;
740}
741
742bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
743{
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700744 if(!sEnableMixedMode) {
745 //Mixed mode is disabled. No need to even try caching.
746 return false;
747 }
748
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700749 bool ret = false;
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800750 if(list->flags & HWC_GEOMETRY_CHANGED) { //Try load based first
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800751 ret = loadBasedComp(ctx, list) or
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800752 cacheBasedComp(ctx, list);
753 } else {
754 ret = cacheBasedComp(ctx, list) or
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800755 loadBasedComp(ctx, list);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700756 }
757
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700758 return ret;
759}
760
761bool MDPComp::cacheBasedComp(hwc_context_t *ctx,
762 hwc_display_contents_1_t* list) {
763 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700764 mCurrentFrame.reset(numAppLayers);
765 updateLayerCache(ctx, list);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700766
767 //If an MDP marked layer is unsupported cannot do partial MDP Comp
768 for(int i = 0; i < numAppLayers; i++) {
769 if(!mCurrentFrame.isFBComposed[i]) {
770 hwc_layer_1_t* layer = &list->hwLayers[i];
771 if(not isSupportedForMDPComp(ctx, layer)) {
772 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",
773 __FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800774 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700775 return false;
776 }
777 }
778 }
779
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700780 updateYUV(ctx, list, false /*secure only*/);
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530781 bool ret = markLayersForCaching(ctx, list); //sets up fbZ also
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700782 if(!ret) {
783 ALOGD_IF(isDebug(),"%s: batching failed, dpy %d",__FUNCTION__, mDpy);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800784 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700785 return false;
786 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700787
788 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700789
radhakrishnac9a67412013-09-25 17:40:42 +0530790 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800791 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530792 }
793
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700794 //Will benefit cases where a video has non-updating background.
795 if((mDpy > HWC_DISPLAY_PRIMARY) and
796 (mdpCount > MAX_SEC_LAYERS)) {
797 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800798 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700799 return false;
800 }
801
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800802 if(!postHeuristicsHandling(ctx, list)) {
803 ALOGD_IF(isDebug(), "post heuristic handling failed");
804 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700805 return false;
806 }
807
Saurabh Shahaa236822013-04-24 18:07:26 -0700808 return true;
809}
810
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800811bool MDPComp::loadBasedComp(hwc_context_t *ctx,
Saurabh Shahb772ae32013-11-18 15:40:02 -0800812 hwc_display_contents_1_t* list) {
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -0800813 if(not isLoadBasedCompDoable(ctx)) {
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800814 return false;
815 }
816
Saurabh Shahb772ae32013-11-18 15:40:02 -0800817 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800818 const int numNonDroppedLayers = numAppLayers - mCurrentFrame.dropCount;
819 const int stagesForMDP = min(sMaxPipesPerMixer,
820 ctx->mOverlay->availablePipes(mDpy, Overlay::MIXER_DEFAULT));
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800821
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800822 int mdpBatchSize = stagesForMDP - 1; //1 stage for FB
823 int fbBatchSize = numNonDroppedLayers - mdpBatchSize;
824 int lastMDPSupportedIndex = numAppLayers;
825 int dropCount = 0;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800826
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800827 //Find the minimum MDP batch size
828 for(int i = 0; i < numAppLayers;i++) {
829 if(mCurrentFrame.drop[i]) {
830 dropCount++;
Jeykumar Sankaran846e2792014-01-23 21:59:58 -0800831 continue;
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800832 }
833 hwc_layer_1_t* layer = &list->hwLayers[i];
834 if(not isSupportedForMDPComp(ctx, layer)) {
835 lastMDPSupportedIndex = i;
836 mdpBatchSize = min(i - dropCount, stagesForMDP - 1);
837 fbBatchSize = numNonDroppedLayers - mdpBatchSize;
Jeykumar Sankaran846e2792014-01-23 21:59:58 -0800838 break;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800839 }
Saurabh Shahb772ae32013-11-18 15:40:02 -0800840 }
841
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800842 ALOGD_IF(isDebug(), "%s:Before optimizing fbBatch, mdpbatch %d, fbbatch %d "
843 "dropped %d", __FUNCTION__, mdpBatchSize, fbBatchSize,
844 mCurrentFrame.dropCount);
845
846 //Start at a point where the fb batch should at least have 2 layers, for
847 //this mode to be justified.
848 while(fbBatchSize < 2) {
849 ++fbBatchSize;
850 --mdpBatchSize;
Jeykumar Sankaran846e2792014-01-23 21:59:58 -0800851 }
Saurabh Shahb772ae32013-11-18 15:40:02 -0800852
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800853 //If there are no layers for MDP, this mode doesnt make sense.
854 if(mdpBatchSize < 1) {
855 ALOGD_IF(isDebug(), "%s: No MDP layers after optimizing for fbBatch",
856 __FUNCTION__);
Saurabh Shahb772ae32013-11-18 15:40:02 -0800857 return false;
858 }
859
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800860 mCurrentFrame.reset(numAppLayers);
861
862 //Try with successively smaller mdp batch sizes until we succeed or reach 1
863 while(mdpBatchSize > 0) {
864 //Mark layers for MDP comp
865 int mdpBatchLeft = mdpBatchSize;
866 for(int i = 0; i < lastMDPSupportedIndex and mdpBatchLeft; i++) {
867 if(mCurrentFrame.drop[i]) {
868 continue;
869 }
870 mCurrentFrame.isFBComposed[i] = false;
871 --mdpBatchLeft;
872 }
873
874 mCurrentFrame.fbZ = mdpBatchSize;
875 mCurrentFrame.fbCount = fbBatchSize;
876 mCurrentFrame.mdpCount = mdpBatchSize;
877
878 ALOGD_IF(isDebug(), "%s:Trying with: mdpbatch %d fbbatch %d dropped %d",
879 __FUNCTION__, mdpBatchSize, fbBatchSize,
880 mCurrentFrame.dropCount);
881
882 if(postHeuristicsHandling(ctx, list)) {
883 ALOGD_IF(isDebug(), "%s: Postheuristics handling succeeded",
884 __FUNCTION__);
885 return true;
886 }
887
888 reset(ctx);
889 --mdpBatchSize;
890 ++fbBatchSize;
891 }
892
893 return false;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800894}
895
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -0800896bool MDPComp::isLoadBasedCompDoable(hwc_context_t *ctx) {
Prabhanjan Kandula3dbbd882013-12-11 14:43:46 +0530897 if(mDpy or isSecurePresent(ctx, mDpy) or
898 isYuvPresent(ctx, mDpy)) {
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700899 return false;
900 }
901 return true;
902}
903
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800904bool MDPComp::canPartialUpdate(hwc_context_t *ctx,
905 hwc_display_contents_1_t* list){
906 if(!qdutils::MDPVersion::getInstance().isPartialUpdateEnabled() ||
907 isSkipPresent(ctx, mDpy) || (list->flags & HWC_GEOMETRY_CHANGED) ||
908 mDpy ) {
909 return false;
910 }
911 return true;
912}
913
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800914bool MDPComp::tryVideoOnly(hwc_context_t *ctx,
915 hwc_display_contents_1_t* list) {
916 const bool secureOnly = true;
917 return videoOnlyComp(ctx, list, not secureOnly) or
918 videoOnlyComp(ctx, list, secureOnly);
919}
920
921bool MDPComp::videoOnlyComp(hwc_context_t *ctx,
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700922 hwc_display_contents_1_t* list, bool secureOnly) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700923 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700924
Saurabh Shahaa236822013-04-24 18:07:26 -0700925 mCurrentFrame.reset(numAppLayers);
Jeykumar Sankaraneb3a5e22014-04-08 16:07:55 -0700926 mCurrentFrame.fbCount -= mCurrentFrame.dropCount;
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700927 updateYUV(ctx, list, secureOnly);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700928 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700929
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800930 if(!isYuvPresent(ctx, mDpy) or (mdpCount == 0)) {
931 reset(ctx);
Saurabh Shahaa236822013-04-24 18:07:26 -0700932 return false;
933 }
934
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -0800935 /* Bail out if we are processing only secured video layers
936 * and we dont have any */
937 if(!isSecurePresent(ctx, mDpy) && secureOnly){
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800938 reset(ctx);
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -0800939 return false;
940 }
941
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800942 if(mCurrentFrame.fbCount)
943 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
Saurabh Shah4fdde762013-04-30 18:47:33 -0700944
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800945 if(sEnable4k2kYUVSplit){
946 adjustForSourceSplit(ctx, list);
947 }
948
949 if(!postHeuristicsHandling(ctx, list)) {
950 ALOGD_IF(isDebug(), "post heuristic handling failed");
951 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700952 return false;
953 }
954
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800955 return true;
956}
957
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800958/* Checks for conditions where YUV layers cannot be bypassed */
959bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -0700960 if(isSkipLayer(layer)) {
Saurabh Shahe2474082013-05-15 16:32:13 -0700961 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800962 return false;
963 }
964
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700965 if(layer->transform & HWC_TRANSFORM_ROT_90 && !canUseRotator(ctx,mDpy)) {
966 ALOGD_IF(isDebug(), "%s: no free DMA pipe",__FUNCTION__);
967 return false;
968 }
969
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800970 if(isSecuring(ctx, layer)) {
971 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
972 return false;
973 }
974
Saurabh Shah4fdde762013-04-30 18:47:33 -0700975 if(!isValidDimension(ctx, layer)) {
976 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
977 __FUNCTION__);
978 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800979 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700980
Naseer Ahmeddc61a972013-07-10 17:50:54 -0400981 if(layer->planeAlpha < 0xFF) {
982 ALOGD_IF(isDebug(), "%s: Cannot handle YUV layer with plane alpha\
983 in video only mode",
984 __FUNCTION__);
985 return false;
986 }
987
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800988 return true;
989}
990
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530991/* starts at fromIndex and check for each layer to find
992 * if it it has overlapping with any Updating layer above it in zorder
993 * till the end of the batch. returns true if it finds any intersection */
994bool MDPComp::canPushBatchToTop(const hwc_display_contents_1_t* list,
995 int fromIndex, int toIndex) {
996 for(int i = fromIndex; i < toIndex; i++) {
997 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
998 if(intersectingUpdatingLayers(list, i+1, toIndex, i)) {
999 return false;
1000 }
1001 }
1002 }
1003 return true;
1004}
1005
1006/* Checks if given layer at targetLayerIndex has any
1007 * intersection with all the updating layers in beween
1008 * fromIndex and toIndex. Returns true if it finds intersectiion */
1009bool MDPComp::intersectingUpdatingLayers(const hwc_display_contents_1_t* list,
1010 int fromIndex, int toIndex, int targetLayerIndex) {
1011 for(int i = fromIndex; i <= toIndex; i++) {
1012 if(!mCurrentFrame.isFBComposed[i]) {
1013 if(areLayersIntersecting(&list->hwLayers[i],
1014 &list->hwLayers[targetLayerIndex])) {
1015 return true;
1016 }
1017 }
1018 }
1019 return false;
1020}
1021
1022int MDPComp::getBatch(hwc_display_contents_1_t* list,
1023 int& maxBatchStart, int& maxBatchEnd,
1024 int& maxBatchCount) {
1025 int i = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301026 int fbZOrder =-1;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -08001027 int droppedLayerCt = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301028 while (i < mCurrentFrame.layerCount) {
1029 int batchCount = 0;
1030 int batchStart = i;
1031 int batchEnd = i;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -08001032 /* Adjust batch Z order with the dropped layers so far */
1033 int fbZ = batchStart - droppedLayerCt;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301034 int firstZReverseIndex = -1;
Prabhanjan Kandula0ed2cc92013-12-06 12:39:04 +05301035 int updatingLayersAbove = 0;//Updating layer count in middle of batch
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301036 while(i < mCurrentFrame.layerCount) {
1037 if(!mCurrentFrame.isFBComposed[i]) {
1038 if(!batchCount) {
1039 i++;
1040 break;
1041 }
1042 updatingLayersAbove++;
1043 i++;
1044 continue;
1045 } else {
1046 if(mCurrentFrame.drop[i]) {
1047 i++;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -08001048 droppedLayerCt++;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301049 continue;
1050 } else if(updatingLayersAbove <= 0) {
1051 batchCount++;
1052 batchEnd = i;
1053 i++;
1054 continue;
1055 } else { //Layer is FBComposed, not a drop & updatingLayer > 0
1056
1057 // We have a valid updating layer already. If layer-i not
1058 // have overlapping with all updating layers in between
1059 // batch-start and i, then we can add layer i to batch.
1060 if(!intersectingUpdatingLayers(list, batchStart, i-1, i)) {
1061 batchCount++;
1062 batchEnd = i;
1063 i++;
1064 continue;
1065 } else if(canPushBatchToTop(list, batchStart, i)) {
1066 //If All the non-updating layers with in this batch
1067 //does not have intersection with the updating layers
1068 //above in z-order, then we can safely move the batch to
1069 //higher z-order. Increment fbZ as it is moving up.
1070 if( firstZReverseIndex < 0) {
1071 firstZReverseIndex = i;
1072 }
1073 batchCount++;
1074 batchEnd = i;
1075 fbZ += updatingLayersAbove;
1076 i++;
1077 updatingLayersAbove = 0;
1078 continue;
1079 } else {
1080 //both failed.start the loop again from here.
1081 if(firstZReverseIndex >= 0) {
1082 i = firstZReverseIndex;
1083 }
1084 break;
1085 }
1086 }
1087 }
1088 }
1089 if(batchCount > maxBatchCount) {
1090 maxBatchCount = batchCount;
1091 maxBatchStart = batchStart;
1092 maxBatchEnd = batchEnd;
1093 fbZOrder = fbZ;
1094 }
1095 }
1096 return fbZOrder;
1097}
1098
1099bool MDPComp::markLayersForCaching(hwc_context_t* ctx,
1100 hwc_display_contents_1_t* list) {
1101 /* Idea is to keep as many non-updating(cached) layers in FB and
1102 * send rest of them through MDP. This is done in 2 steps.
1103 * 1. Find the maximum contiguous batch of non-updating layers.
1104 * 2. See if we can improve this batch size for caching by adding
1105 * opaque layers around the batch, if they don't have
1106 * any overlapping with the updating layers in between.
1107 * NEVER mark an updating layer for caching.
1108 * But cached ones can be marked for MDP */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001109
1110 int maxBatchStart = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001111 int maxBatchEnd = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001112 int maxBatchCount = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301113 int fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001114
Saurabh Shahd53bc5f2014-02-05 10:17:43 -08001115 /* Nothing is cached. No batching needed */
1116 if(mCurrentFrame.fbCount == 0) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001117 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -07001118 }
Saurabh Shahd53bc5f2014-02-05 10:17:43 -08001119
1120 /* No MDP comp layers, try to use other comp modes */
1121 if(mCurrentFrame.mdpCount == 0) {
1122 return false;
Saurabh Shahaa236822013-04-24 18:07:26 -07001123 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001124
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301125 fbZ = getBatch(list, maxBatchStart, maxBatchEnd, maxBatchCount);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001126
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301127 /* reset rest of the layers lying inside ROI for MDP comp */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001128 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001129 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001130 if((i < maxBatchStart || i > maxBatchEnd) &&
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301131 mCurrentFrame.isFBComposed[i]){
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001132 if(!mCurrentFrame.drop[i]){
1133 //If an unsupported layer is being attempted to
1134 //be pulled out we should fail
1135 if(not isSupportedForMDPComp(ctx, layer)) {
1136 return false;
1137 }
1138 mCurrentFrame.isFBComposed[i] = false;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001139 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001140 }
1141 }
1142
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301143 // update the frame data
1144 mCurrentFrame.fbZ = fbZ;
1145 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001146 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001147 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001148
1149 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301150 mCurrentFrame.fbCount);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001151
1152 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001153}
Saurabh Shah85234ec2013-04-12 17:09:00 -07001154
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001155void MDPComp::updateLayerCache(hwc_context_t* ctx,
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001156 hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001157 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001158 int fbCount = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001159
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001160 for(int i = 0; i < numAppLayers; i++) {
1161 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001162 if(!mCurrentFrame.drop[i])
1163 fbCount++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001164 mCurrentFrame.isFBComposed[i] = true;
1165 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -07001166 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001167 }
1168 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001169
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001170 mCurrentFrame.fbCount = fbCount;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001171 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount
1172 - mCurrentFrame.dropCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001173
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001174 ALOGD_IF(isDebug(),"%s: MDP count: %d FB count %d drop count: %d"
1175 ,__FUNCTION__, mCurrentFrame.mdpCount, mCurrentFrame.fbCount,
1176 mCurrentFrame.dropCount);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001177}
1178
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001179void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list,
1180 bool secureOnly) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001181 int nYuvCount = ctx->listStats[mDpy].yuvCount;
1182 for(int index = 0;index < nYuvCount; index++){
1183 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
1184 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
1185
1186 if(!isYUVDoable(ctx, layer)) {
1187 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
1188 mCurrentFrame.isFBComposed[nYuvIndex] = true;
1189 mCurrentFrame.fbCount++;
1190 }
1191 } else {
1192 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001193 private_handle_t *hnd = (private_handle_t *)layer->handle;
1194 if(!secureOnly || isSecureBuffer(hnd)) {
1195 mCurrentFrame.isFBComposed[nYuvIndex] = false;
1196 mCurrentFrame.fbCount--;
1197 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001198 }
1199 }
1200 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001201
1202 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001203 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
1204 ALOGD_IF(isDebug(),"%s: fb count: %d",__FUNCTION__,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001205 mCurrentFrame.fbCount);
1206}
1207
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001208hwc_rect_t MDPComp::getUpdatingFBRect(hwc_context_t *ctx,
1209 hwc_display_contents_1_t* list){
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001210 hwc_rect_t fbRect = (struct hwc_rect){0, 0, 0, 0};
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001211
1212 /* Update only the region of FB needed for composition */
1213 for(int i = 0; i < mCurrentFrame.layerCount; i++ ) {
1214 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
1215 hwc_layer_1_t* layer = &list->hwLayers[i];
1216 hwc_rect_t dst = layer->displayFrame;
1217 fbRect = getUnion(fbRect, dst);
1218 }
1219 }
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001220 trimAgainstROI(ctx, fbRect);
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001221 return fbRect;
1222}
1223
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001224bool MDPComp::postHeuristicsHandling(hwc_context_t *ctx,
1225 hwc_display_contents_1_t* list) {
1226
1227 //Capability checks
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301228 if(!resourceCheck()) {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001229 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
1230 return false;
1231 }
1232
1233 //Limitations checks
1234 if(!hwLimitationsCheck(ctx, list)) {
1235 ALOGD_IF(isDebug(), "%s: HW limitations",__FUNCTION__);
1236 return false;
1237 }
1238
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001239 //Configure framebuffer first if applicable
1240 if(mCurrentFrame.fbZ >= 0) {
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001241 hwc_rect_t fbRect = getUpdatingFBRect(ctx, list);
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001242 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, fbRect, mCurrentFrame.fbZ))
1243 {
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001244 ALOGD_IF(isDebug(), "%s configure framebuffer failed",
1245 __FUNCTION__);
1246 return false;
1247 }
1248 }
1249
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001250 mCurrentFrame.map();
1251
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001252 if(!allocLayerPipes(ctx, list)) {
1253 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -07001254 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001255 }
1256
1257 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001258 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001259 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001260 int mdpIndex = mCurrentFrame.layerToMDP[index];
1261 hwc_layer_1_t* layer = &list->hwLayers[index];
1262
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301263 //Leave fbZ for framebuffer. CACHE/GLES layers go here.
1264 if(mdpNextZOrder == mCurrentFrame.fbZ) {
1265 mdpNextZOrder++;
1266 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001267 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1268 cur_pipe->zOrder = mdpNextZOrder++;
1269
radhakrishnac9a67412013-09-25 17:40:42 +05301270 private_handle_t *hnd = (private_handle_t *)layer->handle;
1271 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1272 if(configure4k2kYuv(ctx, layer,
1273 mCurrentFrame.mdpToLayer[mdpIndex])
1274 != 0 ){
1275 ALOGD_IF(isDebug(), "%s: Failed to configure split pipes \
1276 for layer %d",__FUNCTION__, index);
1277 return false;
1278 }
1279 else{
1280 mdpNextZOrder++;
1281 }
1282 continue;
1283 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001284 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
1285 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
radhakrishnac9a67412013-09-25 17:40:42 +05301286 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -07001287 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001288 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001289 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001290 }
1291
Saurabh Shaha36be922013-12-16 18:18:39 -08001292 if(!ctx->mOverlay->validateAndSet(mDpy, ctx->dpyAttr[mDpy].fd)) {
1293 ALOGD_IF(isDebug(), "%s: Failed to validate and set overlay for dpy %d"
1294 ,__FUNCTION__, mDpy);
1295 return false;
1296 }
1297
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001298 setRedraw(ctx, list);
Saurabh Shahaa236822013-04-24 18:07:26 -07001299 return true;
1300}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001301
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301302bool MDPComp::resourceCheck() {
Saurabh Shah173f4242013-11-20 09:50:12 -08001303 const bool fbUsed = mCurrentFrame.fbCount;
1304 if(mCurrentFrame.mdpCount > sMaxPipesPerMixer - fbUsed) {
1305 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
1306 return false;
1307 }
Saurabh Shah173f4242013-11-20 09:50:12 -08001308 return true;
1309}
1310
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301311bool MDPComp::hwLimitationsCheck(hwc_context_t* ctx,
1312 hwc_display_contents_1_t* list) {
1313
1314 //A-family hw limitation:
1315 //If a layer need alpha scaling, MDP can not support.
1316 if(ctx->mMDP.version < qdutils::MDSS_V5) {
1317 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1318 if(!mCurrentFrame.isFBComposed[i] &&
1319 isAlphaScaled( &list->hwLayers[i])) {
1320 ALOGD_IF(isDebug(), "%s:frame needs alphaScaling",__FUNCTION__);
1321 return false;
1322 }
1323 }
1324 }
1325
1326 // On 8x26 & 8974 hw, we have a limitation of downscaling+blending.
1327 //If multiple layers requires downscaling and also they are overlapping
1328 //fall back to GPU since MDSS can not handle it.
1329 if(qdutils::MDPVersion::getInstance().is8x74v2() ||
1330 qdutils::MDPVersion::getInstance().is8x26()) {
1331 for(int i = 0; i < mCurrentFrame.layerCount-1; ++i) {
1332 hwc_layer_1_t* botLayer = &list->hwLayers[i];
1333 if(!mCurrentFrame.isFBComposed[i] &&
1334 isDownscaleRequired(botLayer)) {
1335 //if layer-i is marked for MDP and needs downscaling
1336 //check if any MDP layer on top of i & overlaps with layer-i
1337 for(int j = i+1; j < mCurrentFrame.layerCount; ++j) {
1338 hwc_layer_1_t* topLayer = &list->hwLayers[j];
1339 if(!mCurrentFrame.isFBComposed[j] &&
1340 isDownscaleRequired(topLayer)) {
1341 hwc_rect_t r = getIntersection(botLayer->displayFrame,
1342 topLayer->displayFrame);
1343 if(isValidRect(r))
1344 return false;
1345 }
1346 }
1347 }
1348 }
1349 }
1350 return true;
1351}
1352
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001353int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001354 int ret = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -07001355 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -07001356
Raj Kamal9ed3d6b2014-02-07 16:15:17 +05301357 //Do not cache the information for next draw cycle.
1358 if(numLayers > MAX_NUM_APP_LAYERS or (!numLayers)) {
1359 ALOGI("%s: Unsupported layer count for mdp composition",
1360 __FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001361 mCachedFrame.reset();
1362 return -1;
1363 }
1364
Saurabh Shahb39f8152013-08-22 10:21:44 -07001365 //reset old data
1366 mCurrentFrame.reset(numLayers);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001367 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1368 mCurrentFrame.dropCount = 0;
Prabhanjan Kandula088bd892013-07-02 23:47:13 +05301369
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -07001370 // Detect the start of animation and fall back to GPU only once to cache
1371 // all the layers in FB and display FB content untill animation completes.
1372 if(ctx->listStats[mDpy].isDisplayAnimating) {
1373 mCurrentFrame.needsRedraw = false;
1374 if(ctx->mAnimationState[mDpy] == ANIMATION_STOPPED) {
1375 mCurrentFrame.needsRedraw = true;
1376 ctx->mAnimationState[mDpy] = ANIMATION_STARTED;
1377 }
1378 setMDPCompLayerFlags(ctx, list);
1379 mCachedFrame.updateCounts(mCurrentFrame);
1380 ret = -1;
1381 return ret;
1382 } else {
1383 ctx->mAnimationState[mDpy] = ANIMATION_STOPPED;
1384 }
1385
Saurabh Shahb39f8152013-08-22 10:21:44 -07001386 //Hard conditions, if not met, cannot do MDP comp
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001387 if(isFrameDoable(ctx)) {
1388 generateROI(ctx, list);
Saurabh Shahb39f8152013-08-22 10:21:44 -07001389
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001390 if(tryFullFrame(ctx, list) || tryVideoOnly(ctx, list)) {
1391 setMDPCompLayerFlags(ctx, list);
1392 } else {
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001393 resetROI(ctx, mDpy);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001394 reset(ctx);
1395 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1396 mCurrentFrame.dropCount = 0;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001397 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001398 }
1399 } else {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001400 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
1401 __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001402 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001403 }
Saurabh Shahb39f8152013-08-22 10:21:44 -07001404
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001405 if(isDebug()) {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001406 ALOGD("GEOMETRY change: %d",
1407 (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001408 android::String8 sDump("");
1409 dump(sDump);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001410 ALOGD("%s",sDump.string());
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001411 }
1412
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001413 mCachedFrame.cacheAll(list);
1414 mCachedFrame.updateCounts(mCurrentFrame);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001415 return ret;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001416}
1417
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001418bool MDPComp::allocSplitVGPipesfor4k2k(hwc_context_t *ctx, int index) {
radhakrishnac9a67412013-09-25 17:40:42 +05301419
1420 bool bRet = true;
radhakrishnac9a67412013-09-25 17:40:42 +05301421 int mdpIndex = mCurrentFrame.layerToMDP[index];
1422 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
1423 info.pipeInfo = new MdpYUVPipeInfo;
1424 info.rot = NULL;
1425 MdpYUVPipeInfo& pipe_info = *(MdpYUVPipeInfo*)info.pipeInfo;
radhakrishnac9a67412013-09-25 17:40:42 +05301426
1427 pipe_info.lIndex = ovutils::OV_INVALID;
1428 pipe_info.rIndex = ovutils::OV_INVALID;
1429
Saurabh Shahc62f3982014-03-05 14:28:26 -08001430 Overlay::PipeSpecs pipeSpecs;
1431 pipeSpecs.formatClass = Overlay::FORMAT_YUV;
1432 pipeSpecs.needsScaling = true;
1433 pipeSpecs.dpy = mDpy;
1434 pipeSpecs.fb = false;
1435
1436 pipe_info.lIndex = ctx->mOverlay->getPipe(pipeSpecs);
radhakrishnac9a67412013-09-25 17:40:42 +05301437 if(pipe_info.lIndex == ovutils::OV_INVALID){
1438 bRet = false;
1439 ALOGD_IF(isDebug(),"%s: allocating first VG pipe failed",
1440 __FUNCTION__);
1441 }
Saurabh Shahc62f3982014-03-05 14:28:26 -08001442 pipe_info.rIndex = ctx->mOverlay->getPipe(pipeSpecs);
radhakrishnac9a67412013-09-25 17:40:42 +05301443 if(pipe_info.rIndex == ovutils::OV_INVALID){
1444 bRet = false;
1445 ALOGD_IF(isDebug(),"%s: allocating second VG pipe failed",
1446 __FUNCTION__);
1447 }
1448 return bRet;
1449}
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001450//=============MDPCompNonSplit==================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001451
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001452void MDPCompNonSplit::adjustForSourceSplit(hwc_context_t *ctx,
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001453 hwc_display_contents_1_t*) {
radhakrishnac9a67412013-09-25 17:40:42 +05301454 //As we split 4kx2k yuv layer and program to 2 VG pipes
1455 //(if available) increase mdpcount accordingly
1456 mCurrentFrame.mdpCount += ctx->listStats[mDpy].yuv4k2kCount;
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001457
1458 //If 4k2k Yuv layer split is possible, and if
1459 //fbz is above 4k2k layer, increment fb zorder by 1
1460 //as we split 4k2k layer and increment zorder for right half
1461 //of the layer
1462 if(mCurrentFrame.fbZ >= 0) {
1463 int n4k2kYuvCount = ctx->listStats[mDpy].yuv4k2kCount;
1464 for(int index = 0; index < n4k2kYuvCount; index++){
1465 int n4k2kYuvIndex =
1466 ctx->listStats[mDpy].yuv4k2kIndices[index];
Dileep Kumar Reddi4cff9282014-04-01 12:57:08 +05301467 if(mCurrentFrame.fbZ >= n4k2kYuvIndex){
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001468 mCurrentFrame.fbZ += 1;
1469 }
1470 }
1471 }
radhakrishnac9a67412013-09-25 17:40:42 +05301472}
1473
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001474/*
1475 * Configures pipe(s) for MDP composition
1476 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001477int MDPCompNonSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001478 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001479 MdpPipeInfoNonSplit& mdp_info =
1480 *(static_cast<MdpPipeInfoNonSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001481 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
1482 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1483 eIsFg isFg = IS_FG_OFF;
1484 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001485
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001486 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
1487 __FUNCTION__, layer, zOrder, dest);
1488
Saurabh Shah88e4d272013-09-03 13:31:29 -07001489 return configureNonSplit(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001490 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001491}
1492
Saurabh Shah88e4d272013-09-03 13:31:29 -07001493bool MDPCompNonSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001494 hwc_display_contents_1_t* list) {
1495 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001496
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001497 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001498
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001499 hwc_layer_1_t* layer = &list->hwLayers[index];
1500 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301501 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001502 if(allocSplitVGPipesfor4k2k(ctx, index)){
radhakrishnac9a67412013-09-25 17:40:42 +05301503 continue;
1504 }
1505 }
1506
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001507 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001508 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001509 info.pipeInfo = new MdpPipeInfoNonSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08001510 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001511 MdpPipeInfoNonSplit& pipe_info = *(MdpPipeInfoNonSplit*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001512
Saurabh Shahc62f3982014-03-05 14:28:26 -08001513 Overlay::PipeSpecs pipeSpecs;
1514 pipeSpecs.formatClass = isYuvBuffer(hnd) ?
1515 Overlay::FORMAT_YUV : Overlay::FORMAT_RGB;
1516 pipeSpecs.needsScaling = qhwc::needsScaling(layer) or
1517 (qdutils::MDPVersion::getInstance().is8x26() and
1518 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres > 1024);
1519 pipeSpecs.dpy = mDpy;
1520 pipeSpecs.fb = false;
Xu Yang1e686f62014-04-08 13:56:47 +08001521 pipeSpecs.numActiveDisplays = ctx->numActiveDisplays;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001522
Saurabh Shahc62f3982014-03-05 14:28:26 -08001523 pipe_info.index = ctx->mOverlay->getPipe(pipeSpecs);
1524
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001525 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001526 ALOGD_IF(isDebug(), "%s: Unable to get pipe", __FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001527 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001528 }
1529 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001530 return true;
1531}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001532
radhakrishnac9a67412013-09-25 17:40:42 +05301533int MDPCompNonSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1534 PipeLayerPair& PipeLayerPair) {
1535 MdpYUVPipeInfo& mdp_info =
1536 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1537 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1538 eIsFg isFg = IS_FG_OFF;
1539 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1540 eDest lDest = mdp_info.lIndex;
1541 eDest rDest = mdp_info.rIndex;
1542
1543 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1544 lDest, rDest, &PipeLayerPair.rot);
1545}
1546
Saurabh Shah88e4d272013-09-03 13:31:29 -07001547bool MDPCompNonSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001548
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001549 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001550 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1551 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -08001552 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001553
1554 if(!ctx || !list) {
1555 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001556 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001557 }
1558
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301559 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1560 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1561 return true;
1562 }
1563
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -08001564 // Set the Handle timeout to true for MDP or MIXED composition.
1565 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount) {
1566 sHandleTimeout = true;
1567 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001568
1569 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001570 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001571
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001572 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1573 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001574 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001575 if(mCurrentFrame.isFBComposed[i]) continue;
1576
Naseer Ahmed5b6708a2012-08-02 13:46:08 -07001577 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001578 private_handle_t *hnd = (private_handle_t *)layer->handle;
1579 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001580 if (!(layer->flags & HWC_COLOR_FILL)) {
1581 ALOGE("%s handle null", __FUNCTION__);
1582 return false;
1583 }
1584 // No PLAY for Color layer
1585 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1586 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001587 }
1588
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001589 int mdpIndex = mCurrentFrame.layerToMDP[i];
1590
radhakrishnac9a67412013-09-25 17:40:42 +05301591 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1592 {
1593 MdpYUVPipeInfo& pipe_info =
1594 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1595 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1596 ovutils::eDest indexL = pipe_info.lIndex;
1597 ovutils::eDest indexR = pipe_info.rIndex;
1598 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301599 uint32_t offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05301600 if(rot) {
1601 rot->queueBuffer(fd, offset);
1602 fd = rot->getDstMemId();
1603 offset = rot->getDstOffset();
1604 }
1605 if(indexL != ovutils::OV_INVALID) {
1606 ovutils::eDest destL = (ovutils::eDest)indexL;
1607 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1608 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1609 if (!ov.queueBuffer(fd, offset, destL)) {
1610 ALOGE("%s: queueBuffer failed for display:%d",
1611 __FUNCTION__, mDpy);
1612 return false;
1613 }
1614 }
1615
1616 if(indexR != ovutils::OV_INVALID) {
1617 ovutils::eDest destR = (ovutils::eDest)indexR;
1618 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1619 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1620 if (!ov.queueBuffer(fd, offset, destR)) {
1621 ALOGE("%s: queueBuffer failed for display:%d",
1622 __FUNCTION__, mDpy);
1623 return false;
1624 }
1625 }
1626 }
1627 else{
1628 MdpPipeInfoNonSplit& pipe_info =
Saurabh Shah88e4d272013-09-03 13:31:29 -07001629 *(MdpPipeInfoNonSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
radhakrishnac9a67412013-09-25 17:40:42 +05301630 ovutils::eDest dest = pipe_info.index;
1631 if(dest == ovutils::OV_INVALID) {
1632 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001633 return false;
radhakrishnac9a67412013-09-25 17:40:42 +05301634 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001635
radhakrishnac9a67412013-09-25 17:40:42 +05301636 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1637 continue;
1638 }
1639
1640 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1641 using pipe: %d", __FUNCTION__, layer,
1642 hnd, dest );
1643
1644 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301645 uint32_t offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05301646
1647 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1648 if(rot) {
1649 if(!rot->queueBuffer(fd, offset))
1650 return false;
1651 fd = rot->getDstMemId();
1652 offset = rot->getDstOffset();
1653 }
1654
1655 if (!ov.queueBuffer(fd, offset, dest)) {
1656 ALOGE("%s: queueBuffer failed for display:%d ",
1657 __FUNCTION__, mDpy);
1658 return false;
1659 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001660 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001661
1662 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001663 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001664 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001665}
1666
Saurabh Shah88e4d272013-09-03 13:31:29 -07001667//=============MDPCompSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001668
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001669void MDPCompSplit::adjustForSourceSplit(hwc_context_t *ctx,
radhakrishnac9a67412013-09-25 17:40:42 +05301670 hwc_display_contents_1_t* list){
1671 //if 4kx2k yuv layer is totally present in either in left half
1672 //or right half then try splitting the yuv layer to avoid decimation
1673 int n4k2kYuvCount = ctx->listStats[mDpy].yuv4k2kCount;
1674 const int lSplit = getLeftSplit(ctx, mDpy);
1675 for(int index = 0; index < n4k2kYuvCount; index++){
1676 int n4k2kYuvIndex = ctx->listStats[mDpy].yuv4k2kIndices[index];
1677 hwc_layer_1_t* layer = &list->hwLayers[n4k2kYuvIndex];
1678 hwc_rect_t dst = layer->displayFrame;
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001679 if((dst.left > lSplit) || (dst.right < lSplit)) {
radhakrishnac9a67412013-09-25 17:40:42 +05301680 mCurrentFrame.mdpCount += 1;
1681 }
Dileep Kumar Reddi4cff9282014-04-01 12:57:08 +05301682 if(mCurrentFrame.fbZ >= n4k2kYuvIndex){
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001683 mCurrentFrame.fbZ += 1;
1684 }
radhakrishnac9a67412013-09-25 17:40:42 +05301685 }
1686}
1687
Saurabh Shah88e4d272013-09-03 13:31:29 -07001688bool MDPCompSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Saurabh Shahc62f3982014-03-05 14:28:26 -08001689 MdpPipeInfoSplit& pipe_info) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001690
Saurabh Shahc62f3982014-03-05 14:28:26 -08001691 const int lSplit = getLeftSplit(ctx, mDpy);
1692 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001693 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001694 pipe_info.lIndex = ovutils::OV_INVALID;
1695 pipe_info.rIndex = ovutils::OV_INVALID;
1696
Saurabh Shahc62f3982014-03-05 14:28:26 -08001697 Overlay::PipeSpecs pipeSpecs;
1698 pipeSpecs.formatClass = isYuvBuffer(hnd) ?
1699 Overlay::FORMAT_YUV : Overlay::FORMAT_RGB;
1700 pipeSpecs.needsScaling = qhwc::needsScalingWithSplit(ctx, layer, mDpy);
1701 pipeSpecs.dpy = mDpy;
1702 pipeSpecs.mixer = Overlay::MIXER_LEFT;
1703 pipeSpecs.fb = false;
1704
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001705 // Acquire pipe only for the updating half
1706 hwc_rect_t l_roi = ctx->listStats[mDpy].lRoi;
1707 hwc_rect_t r_roi = ctx->listStats[mDpy].rRoi;
1708
1709 if (dst.left < lSplit && isValidRect(getIntersection(dst, l_roi))) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001710 pipe_info.lIndex = ctx->mOverlay->getPipe(pipeSpecs);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001711 if(pipe_info.lIndex == ovutils::OV_INVALID)
1712 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001713 }
1714
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001715 if(dst.right > lSplit && isValidRect(getIntersection(dst, r_roi))) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001716 pipeSpecs.mixer = Overlay::MIXER_RIGHT;
1717 pipe_info.rIndex = ctx->mOverlay->getPipe(pipeSpecs);
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001718 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001719 return false;
1720 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001721
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001722 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001723}
1724
Saurabh Shah88e4d272013-09-03 13:31:29 -07001725bool MDPCompSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001726 hwc_display_contents_1_t* list) {
1727 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001728
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001729 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001730
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001731 hwc_layer_1_t* layer = &list->hwLayers[index];
1732 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301733 hwc_rect_t dst = layer->displayFrame;
1734 const int lSplit = getLeftSplit(ctx, mDpy);
1735 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1736 if((dst.left > lSplit)||(dst.right < lSplit)){
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001737 if(allocSplitVGPipesfor4k2k(ctx, index)){
radhakrishnac9a67412013-09-25 17:40:42 +05301738 continue;
1739 }
1740 }
1741 }
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001742 int mdpIndex = mCurrentFrame.layerToMDP[index];
1743 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001744 info.pipeInfo = new MdpPipeInfoSplit;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001745 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001746 MdpPipeInfoSplit& pipe_info = *(MdpPipeInfoSplit*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001747
Saurabh Shahc62f3982014-03-05 14:28:26 -08001748 if(!acquireMDPPipes(ctx, layer, pipe_info)) {
1749 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type",
1750 __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001751 return false;
1752 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001753 }
1754 return true;
1755}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001756
radhakrishnac9a67412013-09-25 17:40:42 +05301757int MDPCompSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1758 PipeLayerPair& PipeLayerPair) {
1759 const int lSplit = getLeftSplit(ctx, mDpy);
1760 hwc_rect_t dst = layer->displayFrame;
1761 if((dst.left > lSplit)||(dst.right < lSplit)){
1762 MdpYUVPipeInfo& mdp_info =
1763 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1764 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1765 eIsFg isFg = IS_FG_OFF;
1766 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1767 eDest lDest = mdp_info.lIndex;
1768 eDest rDest = mdp_info.rIndex;
1769
1770 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1771 lDest, rDest, &PipeLayerPair.rot);
1772 }
1773 else{
1774 return configure(ctx, layer, PipeLayerPair);
1775 }
1776}
1777
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001778/*
1779 * Configures pipe(s) for MDP composition
1780 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001781int MDPCompSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001782 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001783 MdpPipeInfoSplit& mdp_info =
1784 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001785 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1786 eIsFg isFg = IS_FG_OFF;
1787 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1788 eDest lDest = mdp_info.lIndex;
1789 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001790
1791 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1792 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1793
Saurabh Shah88e4d272013-09-03 13:31:29 -07001794 return configureSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001795 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001796}
1797
Saurabh Shah88e4d272013-09-03 13:31:29 -07001798bool MDPCompSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001799
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001800 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001801 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1802 return true;
1803 }
1804
1805 if(!ctx || !list) {
1806 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001807 return false;
1808 }
1809
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301810 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1811 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1812 return true;
1813 }
1814
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -08001815 // Set the Handle timeout to true for MDP or MIXED composition.
1816 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount) {
1817 sHandleTimeout = true;
1818 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001819
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001820 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001821 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001822
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001823 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1824 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001825 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001826 if(mCurrentFrame.isFBComposed[i]) continue;
1827
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001828 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001829 private_handle_t *hnd = (private_handle_t *)layer->handle;
1830 if(!hnd) {
1831 ALOGE("%s handle null", __FUNCTION__);
1832 return false;
1833 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001834
1835 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1836 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001837 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001838
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001839 int mdpIndex = mCurrentFrame.layerToMDP[i];
1840
radhakrishnac9a67412013-09-25 17:40:42 +05301841 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1842 {
1843 MdpYUVPipeInfo& pipe_info =
1844 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1845 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1846 ovutils::eDest indexL = pipe_info.lIndex;
1847 ovutils::eDest indexR = pipe_info.rIndex;
1848 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301849 uint32_t offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05301850 if(rot) {
1851 rot->queueBuffer(fd, offset);
1852 fd = rot->getDstMemId();
1853 offset = rot->getDstOffset();
1854 }
1855 if(indexL != ovutils::OV_INVALID) {
1856 ovutils::eDest destL = (ovutils::eDest)indexL;
1857 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1858 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1859 if (!ov.queueBuffer(fd, offset, destL)) {
1860 ALOGE("%s: queueBuffer failed for display:%d",
1861 __FUNCTION__, mDpy);
1862 return false;
1863 }
1864 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001865
radhakrishnac9a67412013-09-25 17:40:42 +05301866 if(indexR != ovutils::OV_INVALID) {
1867 ovutils::eDest destR = (ovutils::eDest)indexR;
1868 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1869 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1870 if (!ov.queueBuffer(fd, offset, destR)) {
1871 ALOGE("%s: queueBuffer failed for display:%d",
1872 __FUNCTION__, mDpy);
1873 return false;
1874 }
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001875 }
1876 }
radhakrishnac9a67412013-09-25 17:40:42 +05301877 else{
1878 MdpPipeInfoSplit& pipe_info =
1879 *(MdpPipeInfoSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1880 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001881
radhakrishnac9a67412013-09-25 17:40:42 +05301882 ovutils::eDest indexL = pipe_info.lIndex;
1883 ovutils::eDest indexR = pipe_info.rIndex;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001884
radhakrishnac9a67412013-09-25 17:40:42 +05301885 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301886 int offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05301887
1888 if(ctx->mAD->isModeOn()) {
1889 if(ctx->mAD->draw(ctx, fd, offset)) {
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001890 fd = ctx->mAD->getDstFd();
1891 offset = ctx->mAD->getDstOffset();
radhakrishnac9a67412013-09-25 17:40:42 +05301892 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001893 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001894
radhakrishnac9a67412013-09-25 17:40:42 +05301895 if(rot) {
1896 rot->queueBuffer(fd, offset);
1897 fd = rot->getDstMemId();
1898 offset = rot->getDstOffset();
1899 }
1900
1901 //************* play left mixer **********
1902 if(indexL != ovutils::OV_INVALID) {
1903 ovutils::eDest destL = (ovutils::eDest)indexL;
1904 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1905 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1906 if (!ov.queueBuffer(fd, offset, destL)) {
1907 ALOGE("%s: queueBuffer failed for left mixer",
1908 __FUNCTION__);
1909 return false;
1910 }
1911 }
1912
1913 //************* play right mixer **********
1914 if(indexR != ovutils::OV_INVALID) {
1915 ovutils::eDest destR = (ovutils::eDest)indexR;
1916 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1917 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1918 if (!ov.queueBuffer(fd, offset, destR)) {
1919 ALOGE("%s: queueBuffer failed for right mixer",
1920 __FUNCTION__);
1921 return false;
1922 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001923 }
1924 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001925
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001926 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1927 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001928
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001929 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001930}
Saurabh Shahab47c692014-02-12 18:45:57 -08001931
1932//================MDPCompSrcSplit==============================================
1933bool MDPCompSrcSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Saurabh Shahc62f3982014-03-05 14:28:26 -08001934 MdpPipeInfoSplit& pipe_info) {
Saurabh Shahab47c692014-02-12 18:45:57 -08001935 private_handle_t *hnd = (private_handle_t *)layer->handle;
1936 hwc_rect_t dst = layer->displayFrame;
1937 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
1938 pipe_info.lIndex = ovutils::OV_INVALID;
1939 pipe_info.rIndex = ovutils::OV_INVALID;
1940
1941 //If 2 pipes are staged on a single stage of a mixer, then the left pipe
1942 //should have a higher priority than the right one. Pipe priorities are
1943 //starting with VG0, VG1 ... , RGB0 ..., DMA1
Saurabh Shahab47c692014-02-12 18:45:57 -08001944
Saurabh Shahc62f3982014-03-05 14:28:26 -08001945 Overlay::PipeSpecs pipeSpecs;
1946 pipeSpecs.formatClass = isYuvBuffer(hnd) ?
1947 Overlay::FORMAT_YUV : Overlay::FORMAT_RGB;
1948 pipeSpecs.needsScaling = qhwc::needsScaling(layer);
1949 pipeSpecs.dpy = mDpy;
1950 pipeSpecs.fb = false;
1951
Saurabh Shahab47c692014-02-12 18:45:57 -08001952 //1 pipe by default for a layer
Saurabh Shahc62f3982014-03-05 14:28:26 -08001953 pipe_info.lIndex = ctx->mOverlay->getPipe(pipeSpecs);
Saurabh Shahab47c692014-02-12 18:45:57 -08001954 if(pipe_info.lIndex == ovutils::OV_INVALID) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001955 return false;
Saurabh Shahab47c692014-02-12 18:45:57 -08001956 }
1957
1958 //If layer's crop width or dest width > 2048, use 2 pipes
1959 if((dst.right - dst.left) > qdutils::MAX_DISPLAY_DIM or
1960 (crop.right - crop.left) > qdutils::MAX_DISPLAY_DIM) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001961 pipe_info.rIndex = ctx->mOverlay->getPipe(pipeSpecs);
Saurabh Shahab47c692014-02-12 18:45:57 -08001962 if(pipe_info.rIndex == ovutils::OV_INVALID) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001963 return false;
Saurabh Shahdd8237a2014-02-28 14:29:09 -08001964 }
1965
1966 // Return values
1967 // 1 Left pipe is higher priority, do nothing.
1968 // 0 Pipes of same priority.
1969 //-1 Right pipe is of higher priority, needs swap.
1970 if(ctx->mOverlay->comparePipePriority(pipe_info.lIndex,
1971 pipe_info.rIndex) == -1) {
1972 qhwc::swap(pipe_info.lIndex, pipe_info.rIndex);
Saurabh Shahab47c692014-02-12 18:45:57 -08001973 }
1974 }
1975
1976 return true;
1977}
1978
Saurabh Shahab47c692014-02-12 18:45:57 -08001979int MDPCompSrcSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
1980 PipeLayerPair& PipeLayerPair) {
1981 private_handle_t *hnd = (private_handle_t *)layer->handle;
1982 if(!hnd) {
1983 ALOGE("%s: layer handle is NULL", __FUNCTION__);
1984 return -1;
1985 }
1986 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
1987 MdpPipeInfoSplit& mdp_info =
1988 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
1989 Rotator **rot = &PipeLayerPair.rot;
1990 eZorder z = static_cast<eZorder>(mdp_info.zOrder);
1991 eIsFg isFg = IS_FG_OFF;
1992 eDest lDest = mdp_info.lIndex;
1993 eDest rDest = mdp_info.rIndex;
1994 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
1995 hwc_rect_t dst = layer->displayFrame;
1996 int transform = layer->transform;
1997 eTransform orient = static_cast<eTransform>(transform);
1998 const int downscale = 0;
1999 int rotFlags = ROT_FLAGS_NONE;
2000 uint32_t format = ovutils::getMdpFormat(hnd->format, isTileRendered(hnd));
2001 Whf whf(getWidth(hnd), getHeight(hnd), format, hnd->size);
2002
2003 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
2004 "dest_pipeR: %d",__FUNCTION__, layer, z, lDest, rDest);
2005
2006 // Handle R/B swap
2007 if (layer->flags & HWC_FORMAT_RB_SWAP) {
2008 if (hnd->format == HAL_PIXEL_FORMAT_RGBA_8888)
2009 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRA_8888);
2010 else if (hnd->format == HAL_PIXEL_FORMAT_RGBX_8888)
2011 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRX_8888);
2012 }
2013
Saurabh Shah97e2d802014-04-14 18:03:54 -07002014 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
2015 setMdpFlags(layer, mdpFlags, 0, transform);
Saurabh Shahab47c692014-02-12 18:45:57 -08002016
2017 if(lDest != OV_INVALID && rDest != OV_INVALID) {
2018 //Enable overfetch
Saurabh Shah97e2d802014-04-14 18:03:54 -07002019 setMdpFlags(mdpFlags, OV_MDSS_MDP_DUAL_PIPE);
Saurabh Shahab47c692014-02-12 18:45:57 -08002020 }
2021
2022 if(isYuvBuffer(hnd) && (transform & HWC_TRANSFORM_ROT_90)) {
2023 (*rot) = ctx->mRotMgr->getNext();
2024 if((*rot) == NULL) return -1;
Saurabh Shah39240c92014-03-31 10:31:42 -07002025 ctx->mLayerRotMap[mDpy]->add(layer, *rot);
Saurabh Shahab47c692014-02-12 18:45:57 -08002026 //Configure rotator for pre-rotation
Saurabh Shah97e2d802014-04-14 18:03:54 -07002027 if(configRotator(*rot, whf, crop, mdpFlags, orient, downscale) < 0) {
Saurabh Shahab47c692014-02-12 18:45:57 -08002028 ALOGE("%s: configRotator failed!", __FUNCTION__);
2029 return -1;
2030 }
Saurabh Shahab47c692014-02-12 18:45:57 -08002031 whf.format = (*rot)->getDstFormat();
2032 updateSource(orient, whf, crop);
2033 rotFlags |= ROT_PREROTATED;
2034 }
2035
2036 //If 2 pipes being used, divide layer into half, crop and dst
2037 hwc_rect_t cropL = crop;
2038 hwc_rect_t cropR = crop;
2039 hwc_rect_t dstL = dst;
2040 hwc_rect_t dstR = dst;
2041 if(lDest != OV_INVALID && rDest != OV_INVALID) {
2042 cropL.right = (crop.right + crop.left) / 2;
2043 cropR.left = cropL.right;
2044 sanitizeSourceCrop(cropL, cropR, hnd);
2045
2046 //Swap crops on H flip since 2 pipes are being used
2047 if((orient & OVERLAY_TRANSFORM_FLIP_H) && (*rot) == NULL) {
2048 hwc_rect_t tmp = cropL;
2049 cropL = cropR;
2050 cropR = tmp;
2051 }
2052
2053 dstL.right = (dst.right + dst.left) / 2;
2054 dstR.left = dstL.right;
2055 }
2056
2057 //For the mdp, since either we are pre-rotating or MDP does flips
2058 orient = OVERLAY_TRANSFORM_0;
2059 transform = 0;
2060
2061 //configure left pipe
2062 if(lDest != OV_INVALID) {
Saurabh Shah97e2d802014-04-14 18:03:54 -07002063 PipeArgs pargL(mdpFlags, whf, z, isFg,
Saurabh Shahab47c692014-02-12 18:45:57 -08002064 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2065 (ovutils::eBlending) getBlending(layer->blending));
2066
2067 if(configMdp(ctx->mOverlay, pargL, orient,
2068 cropL, dstL, metadata, lDest) < 0) {
2069 ALOGE("%s: commit failed for left mixer config", __FUNCTION__);
2070 return -1;
2071 }
2072 }
2073
2074 //configure right pipe
2075 if(rDest != OV_INVALID) {
Saurabh Shah97e2d802014-04-14 18:03:54 -07002076 PipeArgs pargR(mdpFlags, whf, z, isFg,
Saurabh Shahab47c692014-02-12 18:45:57 -08002077 static_cast<eRotFlags>(rotFlags),
2078 layer->planeAlpha,
2079 (ovutils::eBlending) getBlending(layer->blending));
2080 if(configMdp(ctx->mOverlay, pargR, orient,
2081 cropR, dstR, metadata, rDest) < 0) {
2082 ALOGE("%s: commit failed for right mixer config", __FUNCTION__);
2083 return -1;
2084 }
2085 }
2086
2087 return 0;
2088}
2089
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002090}; //namespace
2091