blob: 540a8e7730a2b402a556a9e740d9bb45d073836d [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() ||
Prabhanjan Kandula958ffa92014-05-12 14:56:56 +0530392 qdutils::MDPVersion::getInstance().is8x16() ||
393 qdutils::MDPVersion::getInstance().is8x39()) &&
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -0800394 ctx->mVideoTransFlag &&
395 isSecondaryConnected(ctx)) {
Saurabh Shahd4e65852013-06-17 11:33:53 -0700396 //1 Padding round to shift pipes across mixers
397 ALOGD_IF(isDebug(),"%s: MDP Comp. video transition padding round",
398 __FUNCTION__);
399 ret = false;
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -0800400 } else if(isSecondaryConfiguring(ctx)) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800401 ALOGD_IF( isDebug(),"%s: External Display connection is pending",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800402 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700403 ret = false;
Saurabh Shahaa236822013-04-24 18:07:26 -0700404 } else if(ctx->isPaddingRound) {
Raj Kamal9ed3d6b2014-02-07 16:15:17 +0530405 ALOGD_IF(isDebug(), "%s: padding round invoked for dpy %d",
406 __FUNCTION__,mDpy);
Saurabh Shahaa236822013-04-24 18:07:26 -0700407 ret = false;
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700408 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700409 return ret;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800410}
411
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800412void MDPCompNonSplit::trimAgainstROI(hwc_context_t *ctx, hwc_rect_t& fbRect) {
413 hwc_rect_t roi = ctx->listStats[mDpy].lRoi;
414 fbRect = getIntersection(fbRect, roi);
415}
416
417/* 1) Identify layers that are not visible or lying outside the updating ROI and
418 * drop them from composition.
419 * 2) If we have a scaling layer which needs cropping against generated
420 * ROI, reset ROI to full resolution. */
421bool MDPCompNonSplit::validateAndApplyROI(hwc_context_t *ctx,
422 hwc_display_contents_1_t* list) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700423 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800424 hwc_rect_t visibleRect = ctx->listStats[mDpy].lRoi;
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800425
426 for(int i = numAppLayers - 1; i >= 0; i--){
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800427 if(!isValidRect(visibleRect)) {
428 mCurrentFrame.drop[i] = true;
429 mCurrentFrame.dropCount++;
Jeykumar Sankaran0b961452014-01-21 17:26:12 -0800430 continue;
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800431 }
432
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700433 const hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700434 hwc_rect_t dstRect = layer->displayFrame;
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800435 hwc_rect_t res = getIntersection(visibleRect, dstRect);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700436
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700437 if(!isValidRect(res)) {
438 mCurrentFrame.drop[i] = true;
439 mCurrentFrame.dropCount++;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800440 } else {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700441 /* Reset frame ROI when any layer which needs scaling also needs ROI
442 * cropping */
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800443 if(!isSameRect(res, dstRect) && needsScaling (layer)) {
Arpita Banerjeed8965982013-11-08 17:27:33 -0800444 ALOGI("%s: Resetting ROI due to scaling", __FUNCTION__);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700445 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
446 mCurrentFrame.dropCount = 0;
447 return false;
448 }
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800449
Jeykumar Sankaran0b961452014-01-21 17:26:12 -0800450 /* deduct any opaque region from visibleRect */
451 if (layer->blending == HWC_BLENDING_NONE)
452 visibleRect = deductRect(visibleRect, res);
453 }
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700454 }
455 return true;
456}
457
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800458/* Calculate ROI for the frame by accounting all the layer's dispalyFrame which
459 * are updating. If DirtyRegion is applicable, calculate it by accounting all
460 * the changing layer's dirtyRegion. */
461void MDPCompNonSplit::generateROI(hwc_context_t *ctx,
462 hwc_display_contents_1_t* list) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700463 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800464 if(!canPartialUpdate(ctx, list))
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700465 return;
466
467 struct hwc_rect roi = (struct hwc_rect){0, 0, 0, 0};
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800468 hwc_rect fullFrame = (struct hwc_rect) {0, 0,(int)ctx->dpyAttr[mDpy].xres,
469 (int)ctx->dpyAttr[mDpy].yres};
470
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700471 for(int index = 0; index < numAppLayers; index++ ) {
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800472 hwc_layer_1_t* layer = &list->hwLayers[index];
473 if ((mCachedFrame.hnd[index] != layer->handle) ||
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800474 isYuvBuffer((private_handle_t *)layer->handle)) {
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800475 hwc_rect_t updatingRect = layer->displayFrame;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800476
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800477#ifdef QCOM_BSP
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800478 if(!needsScaling(layer) && !layer->transform)
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800479 updatingRect = layer->dirtyRect;
480#endif
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800481
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800482 roi = getUnion(roi, updatingRect);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700483 }
484 }
485
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800486 /* No layer is updating. Still SF wants a refresh.*/
487 if(!isValidRect(roi))
488 return;
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800489
490 // Align ROI coordinates to panel restrictions
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800491 roi = getSanitizeROI(roi, fullFrame);
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800492
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800493 ctx->listStats[mDpy].lRoi = roi;
494 if(!validateAndApplyROI(ctx, list))
495 resetROI(ctx, mDpy);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700496
497 ALOGD_IF(isDebug(),"%s: generated ROI: [%d, %d, %d, %d]", __FUNCTION__,
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800498 ctx->listStats[mDpy].lRoi.left, ctx->listStats[mDpy].lRoi.top,
499 ctx->listStats[mDpy].lRoi.right, ctx->listStats[mDpy].lRoi.bottom);
500}
501
502void MDPCompSplit::trimAgainstROI(hwc_context_t *ctx, hwc_rect_t& fbRect) {
503 hwc_rect l_roi = ctx->listStats[mDpy].lRoi;
504 hwc_rect r_roi = ctx->listStats[mDpy].rRoi;
505
506 hwc_rect_t l_fbRect = getIntersection(fbRect, l_roi);
507 hwc_rect_t r_fbRect = getIntersection(fbRect, r_roi);
508 fbRect = getUnion(l_fbRect, r_fbRect);
509}
510/* 1) Identify layers that are not visible or lying outside BOTH the updating
511 * ROI's and drop them from composition. If a layer is spanning across both
512 * the halves of the screen but needed by only ROI, the non-contributing
513 * half will not be programmed for MDP.
514 * 2) If we have a scaling layer which needs cropping against generated
515 * ROI, reset ROI to full resolution. */
516bool MDPCompSplit::validateAndApplyROI(hwc_context_t *ctx,
517 hwc_display_contents_1_t* list) {
518
519 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
520
521 hwc_rect_t visibleRectL = ctx->listStats[mDpy].lRoi;
522 hwc_rect_t visibleRectR = ctx->listStats[mDpy].rRoi;
523
524 for(int i = numAppLayers - 1; i >= 0; i--){
525 if(!isValidRect(visibleRectL) && !isValidRect(visibleRectR))
526 {
527 mCurrentFrame.drop[i] = true;
528 mCurrentFrame.dropCount++;
529 continue;
530 }
531
532 const hwc_layer_1_t* layer = &list->hwLayers[i];
533 hwc_rect_t dstRect = layer->displayFrame;
534
535 hwc_rect_t l_res = getIntersection(visibleRectL, dstRect);
536 hwc_rect_t r_res = getIntersection(visibleRectR, dstRect);
537 hwc_rect_t res = getUnion(l_res, r_res);
538
539 if(!isValidRect(l_res) && !isValidRect(r_res)) {
540 mCurrentFrame.drop[i] = true;
541 mCurrentFrame.dropCount++;
542 } else {
543 /* Reset frame ROI when any layer which needs scaling also needs ROI
544 * cropping */
545 if(!isSameRect(res, dstRect) && needsScaling (layer)) {
546 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
547 mCurrentFrame.dropCount = 0;
548 return false;
549 }
550
551 if (layer->blending == HWC_BLENDING_NONE) {
552 visibleRectL = deductRect(visibleRectL, l_res);
553 visibleRectR = deductRect(visibleRectR, r_res);
554 }
555 }
556 }
557 return true;
558}
559/* Calculate ROI for the frame by accounting all the layer's dispalyFrame which
560 * are updating. If DirtyRegion is applicable, calculate it by accounting all
561 * the changing layer's dirtyRegion. */
562void MDPCompSplit::generateROI(hwc_context_t *ctx,
563 hwc_display_contents_1_t* list) {
564 if(!canPartialUpdate(ctx, list))
565 return;
566
567 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
568 int lSplit = getLeftSplit(ctx, mDpy);
569
570 int hw_h = (int)ctx->dpyAttr[mDpy].yres;
571 int hw_w = (int)ctx->dpyAttr[mDpy].xres;
572
573 struct hwc_rect l_frame = (struct hwc_rect){0, 0, lSplit, hw_h};
574 struct hwc_rect r_frame = (struct hwc_rect){lSplit, 0, hw_w, hw_h};
575
576 struct hwc_rect l_roi = (struct hwc_rect){0, 0, 0, 0};
577 struct hwc_rect r_roi = (struct hwc_rect){0, 0, 0, 0};
578
579 for(int index = 0; index < numAppLayers; index++ ) {
580 hwc_layer_1_t* layer = &list->hwLayers[index];
581 if ((mCachedFrame.hnd[index] != layer->handle) ||
582 isYuvBuffer((private_handle_t *)layer->handle)) {
Jeykumar Sankaran71e597c2014-05-07 16:23:14 -0700583 hwc_rect_t dst = layer->displayFrame;
584 hwc_rect_t updatingRect = dst;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800585
586#ifdef QCOM_BSP
587 if(!needsScaling(layer) && !layer->transform)
Jeykumar Sankaran71e597c2014-05-07 16:23:14 -0700588 {
589 hwc_rect_t src = integerizeSourceCrop(layer->sourceCropf);
590 int x_off = dst.left - src.left;
591 int y_off = dst.top - src.top;
592 updatingRect = moveRect(layer->dirtyRect, x_off, y_off);
593 }
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800594#endif
595
596 hwc_rect_t l_dst = getIntersection(l_frame, updatingRect);
597 if(isValidRect(l_dst))
598 l_roi = getUnion(l_roi, l_dst);
599
600 hwc_rect_t r_dst = getIntersection(r_frame, updatingRect);
601 if(isValidRect(r_dst))
602 r_roi = getUnion(r_roi, r_dst);
603 }
604 }
605
Jeykumar Sankarana40a9342014-04-25 09:37:10 -0700606 /* For panels that cannot accept commands in both the interfaces, we cannot
607 * send two ROI's (for each half). We merge them into single ROI and split
608 * them across lSplit for MDP mixer use. The ROI's will be merged again
609 * finally before udpating the panel in the driver. */
610 if(qdutils::MDPVersion::getInstance().needsROIMerge()) {
611 hwc_rect_t temp_roi = getUnion(l_roi, r_roi);
612 l_roi = getIntersection(temp_roi, l_frame);
613 r_roi = getIntersection(temp_roi, r_frame);
614 }
615
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800616 /* No layer is updating. Still SF wants a refresh. */
617 if(!isValidRect(l_roi) && !isValidRect(r_roi))
618 return;
619
620 l_roi = getSanitizeROI(l_roi, l_frame);
621 r_roi = getSanitizeROI(r_roi, r_frame);
622
623 ctx->listStats[mDpy].lRoi = l_roi;
624 ctx->listStats[mDpy].rRoi = r_roi;
625
626 if(!validateAndApplyROI(ctx, list))
627 resetROI(ctx, mDpy);
628
629 ALOGD_IF(isDebug(),"%s: generated L_ROI: [%d, %d, %d, %d]"
630 "R_ROI: [%d, %d, %d, %d]", __FUNCTION__,
631 ctx->listStats[mDpy].lRoi.left, ctx->listStats[mDpy].lRoi.top,
632 ctx->listStats[mDpy].lRoi.right, ctx->listStats[mDpy].lRoi.bottom,
633 ctx->listStats[mDpy].rRoi.left, ctx->listStats[mDpy].rRoi.top,
634 ctx->listStats[mDpy].rRoi.right, ctx->listStats[mDpy].rRoi.bottom);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700635}
636
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800637/* Checks for conditions where all the layers marked for MDP comp cannot be
638 * bypassed. On such conditions we try to bypass atleast YUV layers */
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800639bool MDPComp::tryFullFrame(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800640 hwc_display_contents_1_t* list){
641
Saurabh Shahaa236822013-04-24 18:07:26 -0700642 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Arun Kumar K.R2e2871c2014-01-10 12:47:06 -0800643 int priDispW = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800644
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -0700645 if(sIdleFallBack && !ctx->listStats[mDpy].secureUI) {
Saurabh Shah2d998a92013-05-14 17:55:58 -0700646 ALOGD_IF(isDebug(), "%s: Idle fallback dpy %d",__FUNCTION__, mDpy);
647 return false;
648 }
649
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800650 if(isSkipPresent(ctx, mDpy)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700651 ALOGD_IF(isDebug(),"%s: SKIP present: %d",
652 __FUNCTION__,
653 isSkipPresent(ctx, mDpy));
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800654 return false;
655 }
656
Arun Kumar K.R2e2871c2014-01-10 12:47:06 -0800657 if(mDpy > HWC_DISPLAY_PRIMARY && (priDispW > MAX_DISPLAY_DIM) &&
658 (ctx->dpyAttr[mDpy].xres < MAX_DISPLAY_DIM)) {
659 // Disable MDP comp on Secondary when the primary is highres panel and
660 // the secondary is a normal 1080p, because, MDP comp on secondary under
661 // in such usecase, decimation gets used for downscale and there will be
662 // a quality mismatch when there will be a fallback to GPU comp
663 ALOGD_IF(isDebug(), "%s: Disable MDP Compositon for Secondary Disp",
664 __FUNCTION__);
665 return false;
666 }
667
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800668 // check for action safe flag and downscale mode which requires scaling.
669 if(ctx->dpyAttr[mDpy].mActionSafePresent
670 || ctx->dpyAttr[mDpy].mDownScaleMode) {
671 ALOGD_IF(isDebug(), "%s: Scaling needed for this frame",__FUNCTION__);
672 return false;
673 }
674
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800675 for(int i = 0; i < numAppLayers; ++i) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800676 hwc_layer_1_t* layer = &list->hwLayers[i];
677 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800678
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700679 if(isYuvBuffer(hnd) && has90Transform(layer)) {
680 if(!canUseRotator(ctx, mDpy)) {
681 ALOGD_IF(isDebug(), "%s: Can't use rotator for dpy %d",
682 __FUNCTION__, mDpy);
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700683 return false;
684 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800685 }
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530686
687 //For 8x26 with panel width>1k, if RGB layer needs HFLIP fail mdp comp
688 // may not need it if Gfx pre-rotation can handle all flips & rotations
Sushil Chauhanfda00fc2014-03-20 11:08:41 -0700689 int transform = (layer->flags & HWC_COLOR_FILL) ? 0 : layer->transform;
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530690 if(qdutils::MDPVersion::getInstance().is8x26() &&
691 (ctx->dpyAttr[mDpy].xres > 1024) &&
Sushil Chauhanfda00fc2014-03-20 11:08:41 -0700692 (transform & HWC_TRANSFORM_FLIP_H) &&
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530693 (!isYuvBuffer(hnd)))
694 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800695 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700696
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700697 if(ctx->mAD->isDoable()) {
698 return false;
699 }
700
Saurabh Shahaa236822013-04-24 18:07:26 -0700701 //If all above hard conditions are met we can do full or partial MDP comp.
702 bool ret = false;
703 if(fullMDPComp(ctx, list)) {
704 ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700705 } else if(partialMDPComp(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700706 ret = true;
707 }
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530708
Saurabh Shahaa236822013-04-24 18:07:26 -0700709 return ret;
710}
711
712bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700713 //Will benefit presentation / secondary-only layer.
714 if((mDpy > HWC_DISPLAY_PRIMARY) &&
715 (list->numHwLayers - 1) > MAX_SEC_LAYERS) {
716 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
717 return false;
718 }
719
720 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
721 for(int i = 0; i < numAppLayers; i++) {
722 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran880da832014-04-18 10:22:35 -0700723 if(not mCurrentFrame.drop[i] and
724 not isSupportedForMDPComp(ctx, layer)) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700725 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",__FUNCTION__);
726 return false;
727 }
728 }
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800729
Saurabh Shahaa236822013-04-24 18:07:26 -0700730 mCurrentFrame.fbCount = 0;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700731 memcpy(&mCurrentFrame.isFBComposed, &mCurrentFrame.drop,
732 sizeof(mCurrentFrame.isFBComposed));
733 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount -
734 mCurrentFrame.dropCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700735
radhakrishnac9a67412013-09-25 17:40:42 +0530736 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800737 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530738 }
739
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800740 if(!postHeuristicsHandling(ctx, list)) {
741 ALOGD_IF(isDebug(), "post heuristic handling failed");
742 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700743 return false;
744 }
745
Saurabh Shahaa236822013-04-24 18:07:26 -0700746 return true;
747}
748
749bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
750{
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700751 if(!sEnableMixedMode) {
752 //Mixed mode is disabled. No need to even try caching.
753 return false;
754 }
755
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700756 bool ret = false;
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800757 if(list->flags & HWC_GEOMETRY_CHANGED) { //Try load based first
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800758 ret = loadBasedComp(ctx, list) or
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800759 cacheBasedComp(ctx, list);
760 } else {
761 ret = cacheBasedComp(ctx, list) or
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800762 loadBasedComp(ctx, list);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700763 }
764
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700765 return ret;
766}
767
768bool MDPComp::cacheBasedComp(hwc_context_t *ctx,
769 hwc_display_contents_1_t* list) {
770 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700771 mCurrentFrame.reset(numAppLayers);
772 updateLayerCache(ctx, list);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700773
774 //If an MDP marked layer is unsupported cannot do partial MDP Comp
775 for(int i = 0; i < numAppLayers; i++) {
776 if(!mCurrentFrame.isFBComposed[i]) {
777 hwc_layer_1_t* layer = &list->hwLayers[i];
778 if(not isSupportedForMDPComp(ctx, layer)) {
779 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",
780 __FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800781 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700782 return false;
783 }
784 }
785 }
786
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700787 updateYUV(ctx, list, false /*secure only*/);
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530788 bool ret = markLayersForCaching(ctx, list); //sets up fbZ also
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700789 if(!ret) {
790 ALOGD_IF(isDebug(),"%s: batching failed, dpy %d",__FUNCTION__, mDpy);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800791 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700792 return false;
793 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700794
795 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700796
radhakrishnac9a67412013-09-25 17:40:42 +0530797 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800798 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530799 }
800
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700801 //Will benefit cases where a video has non-updating background.
802 if((mDpy > HWC_DISPLAY_PRIMARY) and
803 (mdpCount > MAX_SEC_LAYERS)) {
804 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800805 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700806 return false;
807 }
808
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800809 if(!postHeuristicsHandling(ctx, list)) {
810 ALOGD_IF(isDebug(), "post heuristic handling failed");
811 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700812 return false;
813 }
814
Saurabh Shahaa236822013-04-24 18:07:26 -0700815 return true;
816}
817
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800818bool MDPComp::loadBasedComp(hwc_context_t *ctx,
Saurabh Shahb772ae32013-11-18 15:40:02 -0800819 hwc_display_contents_1_t* list) {
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -0800820 if(not isLoadBasedCompDoable(ctx)) {
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800821 return false;
822 }
823
Saurabh Shahb772ae32013-11-18 15:40:02 -0800824 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800825 const int numNonDroppedLayers = numAppLayers - mCurrentFrame.dropCount;
826 const int stagesForMDP = min(sMaxPipesPerMixer,
827 ctx->mOverlay->availablePipes(mDpy, Overlay::MIXER_DEFAULT));
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800828
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800829 int mdpBatchSize = stagesForMDP - 1; //1 stage for FB
830 int fbBatchSize = numNonDroppedLayers - mdpBatchSize;
831 int lastMDPSupportedIndex = numAppLayers;
832 int dropCount = 0;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800833
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800834 //Find the minimum MDP batch size
835 for(int i = 0; i < numAppLayers;i++) {
836 if(mCurrentFrame.drop[i]) {
837 dropCount++;
Jeykumar Sankaran846e2792014-01-23 21:59:58 -0800838 continue;
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800839 }
840 hwc_layer_1_t* layer = &list->hwLayers[i];
841 if(not isSupportedForMDPComp(ctx, layer)) {
842 lastMDPSupportedIndex = i;
843 mdpBatchSize = min(i - dropCount, stagesForMDP - 1);
844 fbBatchSize = numNonDroppedLayers - mdpBatchSize;
Jeykumar Sankaran846e2792014-01-23 21:59:58 -0800845 break;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800846 }
Saurabh Shahb772ae32013-11-18 15:40:02 -0800847 }
848
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800849 ALOGD_IF(isDebug(), "%s:Before optimizing fbBatch, mdpbatch %d, fbbatch %d "
850 "dropped %d", __FUNCTION__, mdpBatchSize, fbBatchSize,
851 mCurrentFrame.dropCount);
852
853 //Start at a point where the fb batch should at least have 2 layers, for
854 //this mode to be justified.
855 while(fbBatchSize < 2) {
856 ++fbBatchSize;
857 --mdpBatchSize;
Jeykumar Sankaran846e2792014-01-23 21:59:58 -0800858 }
Saurabh Shahb772ae32013-11-18 15:40:02 -0800859
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800860 //If there are no layers for MDP, this mode doesnt make sense.
861 if(mdpBatchSize < 1) {
862 ALOGD_IF(isDebug(), "%s: No MDP layers after optimizing for fbBatch",
863 __FUNCTION__);
Saurabh Shahb772ae32013-11-18 15:40:02 -0800864 return false;
865 }
866
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800867 mCurrentFrame.reset(numAppLayers);
868
869 //Try with successively smaller mdp batch sizes until we succeed or reach 1
870 while(mdpBatchSize > 0) {
871 //Mark layers for MDP comp
872 int mdpBatchLeft = mdpBatchSize;
873 for(int i = 0; i < lastMDPSupportedIndex and mdpBatchLeft; i++) {
874 if(mCurrentFrame.drop[i]) {
875 continue;
876 }
877 mCurrentFrame.isFBComposed[i] = false;
878 --mdpBatchLeft;
879 }
880
881 mCurrentFrame.fbZ = mdpBatchSize;
882 mCurrentFrame.fbCount = fbBatchSize;
883 mCurrentFrame.mdpCount = mdpBatchSize;
884
885 ALOGD_IF(isDebug(), "%s:Trying with: mdpbatch %d fbbatch %d dropped %d",
886 __FUNCTION__, mdpBatchSize, fbBatchSize,
887 mCurrentFrame.dropCount);
888
889 if(postHeuristicsHandling(ctx, list)) {
890 ALOGD_IF(isDebug(), "%s: Postheuristics handling succeeded",
891 __FUNCTION__);
892 return true;
893 }
894
895 reset(ctx);
896 --mdpBatchSize;
897 ++fbBatchSize;
898 }
899
900 return false;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800901}
902
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -0800903bool MDPComp::isLoadBasedCompDoable(hwc_context_t *ctx) {
Prabhanjan Kandula3dbbd882013-12-11 14:43:46 +0530904 if(mDpy or isSecurePresent(ctx, mDpy) or
905 isYuvPresent(ctx, mDpy)) {
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700906 return false;
907 }
908 return true;
909}
910
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800911bool MDPComp::canPartialUpdate(hwc_context_t *ctx,
912 hwc_display_contents_1_t* list){
913 if(!qdutils::MDPVersion::getInstance().isPartialUpdateEnabled() ||
914 isSkipPresent(ctx, mDpy) || (list->flags & HWC_GEOMETRY_CHANGED) ||
915 mDpy ) {
916 return false;
917 }
918 return true;
919}
920
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800921bool MDPComp::tryVideoOnly(hwc_context_t *ctx,
922 hwc_display_contents_1_t* list) {
923 const bool secureOnly = true;
924 return videoOnlyComp(ctx, list, not secureOnly) or
925 videoOnlyComp(ctx, list, secureOnly);
926}
927
928bool MDPComp::videoOnlyComp(hwc_context_t *ctx,
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700929 hwc_display_contents_1_t* list, bool secureOnly) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700930 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700931
Saurabh Shahaa236822013-04-24 18:07:26 -0700932 mCurrentFrame.reset(numAppLayers);
Jeykumar Sankaraneb3a5e22014-04-08 16:07:55 -0700933 mCurrentFrame.fbCount -= mCurrentFrame.dropCount;
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700934 updateYUV(ctx, list, secureOnly);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700935 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700936
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800937 if(!isYuvPresent(ctx, mDpy) or (mdpCount == 0)) {
938 reset(ctx);
Saurabh Shahaa236822013-04-24 18:07:26 -0700939 return false;
940 }
941
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -0800942 /* Bail out if we are processing only secured video layers
943 * and we dont have any */
944 if(!isSecurePresent(ctx, mDpy) && secureOnly){
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800945 reset(ctx);
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -0800946 return false;
947 }
948
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800949 if(mCurrentFrame.fbCount)
950 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
Saurabh Shah4fdde762013-04-30 18:47:33 -0700951
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800952 if(sEnable4k2kYUVSplit){
953 adjustForSourceSplit(ctx, list);
954 }
955
956 if(!postHeuristicsHandling(ctx, list)) {
957 ALOGD_IF(isDebug(), "post heuristic handling failed");
958 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700959 return false;
960 }
961
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800962 return true;
963}
964
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800965/* Checks for conditions where YUV layers cannot be bypassed */
966bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -0700967 if(isSkipLayer(layer)) {
Saurabh Shahe2474082013-05-15 16:32:13 -0700968 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800969 return false;
970 }
971
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700972 if(layer->transform & HWC_TRANSFORM_ROT_90 && !canUseRotator(ctx,mDpy)) {
973 ALOGD_IF(isDebug(), "%s: no free DMA pipe",__FUNCTION__);
974 return false;
975 }
976
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800977 if(isSecuring(ctx, layer)) {
978 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
979 return false;
980 }
981
Saurabh Shah4fdde762013-04-30 18:47:33 -0700982 if(!isValidDimension(ctx, layer)) {
983 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
984 __FUNCTION__);
985 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800986 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700987
Naseer Ahmeddc61a972013-07-10 17:50:54 -0400988 if(layer->planeAlpha < 0xFF) {
989 ALOGD_IF(isDebug(), "%s: Cannot handle YUV layer with plane alpha\
990 in video only mode",
991 __FUNCTION__);
992 return false;
993 }
994
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800995 return true;
996}
997
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530998/* starts at fromIndex and check for each layer to find
999 * if it it has overlapping with any Updating layer above it in zorder
1000 * till the end of the batch. returns true if it finds any intersection */
1001bool MDPComp::canPushBatchToTop(const hwc_display_contents_1_t* list,
1002 int fromIndex, int toIndex) {
1003 for(int i = fromIndex; i < toIndex; i++) {
1004 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
1005 if(intersectingUpdatingLayers(list, i+1, toIndex, i)) {
1006 return false;
1007 }
1008 }
1009 }
1010 return true;
1011}
1012
1013/* Checks if given layer at targetLayerIndex has any
1014 * intersection with all the updating layers in beween
1015 * fromIndex and toIndex. Returns true if it finds intersectiion */
1016bool MDPComp::intersectingUpdatingLayers(const hwc_display_contents_1_t* list,
1017 int fromIndex, int toIndex, int targetLayerIndex) {
1018 for(int i = fromIndex; i <= toIndex; i++) {
1019 if(!mCurrentFrame.isFBComposed[i]) {
1020 if(areLayersIntersecting(&list->hwLayers[i],
1021 &list->hwLayers[targetLayerIndex])) {
1022 return true;
1023 }
1024 }
1025 }
1026 return false;
1027}
1028
1029int MDPComp::getBatch(hwc_display_contents_1_t* list,
1030 int& maxBatchStart, int& maxBatchEnd,
1031 int& maxBatchCount) {
1032 int i = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301033 int fbZOrder =-1;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -08001034 int droppedLayerCt = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301035 while (i < mCurrentFrame.layerCount) {
1036 int batchCount = 0;
1037 int batchStart = i;
1038 int batchEnd = i;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -08001039 /* Adjust batch Z order with the dropped layers so far */
1040 int fbZ = batchStart - droppedLayerCt;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301041 int firstZReverseIndex = -1;
Prabhanjan Kandula0ed2cc92013-12-06 12:39:04 +05301042 int updatingLayersAbove = 0;//Updating layer count in middle of batch
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301043 while(i < mCurrentFrame.layerCount) {
1044 if(!mCurrentFrame.isFBComposed[i]) {
1045 if(!batchCount) {
1046 i++;
1047 break;
1048 }
1049 updatingLayersAbove++;
1050 i++;
1051 continue;
1052 } else {
1053 if(mCurrentFrame.drop[i]) {
1054 i++;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -08001055 droppedLayerCt++;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301056 continue;
1057 } else if(updatingLayersAbove <= 0) {
1058 batchCount++;
1059 batchEnd = i;
1060 i++;
1061 continue;
1062 } else { //Layer is FBComposed, not a drop & updatingLayer > 0
1063
1064 // We have a valid updating layer already. If layer-i not
1065 // have overlapping with all updating layers in between
1066 // batch-start and i, then we can add layer i to batch.
1067 if(!intersectingUpdatingLayers(list, batchStart, i-1, i)) {
1068 batchCount++;
1069 batchEnd = i;
1070 i++;
1071 continue;
1072 } else if(canPushBatchToTop(list, batchStart, i)) {
1073 //If All the non-updating layers with in this batch
1074 //does not have intersection with the updating layers
1075 //above in z-order, then we can safely move the batch to
1076 //higher z-order. Increment fbZ as it is moving up.
1077 if( firstZReverseIndex < 0) {
1078 firstZReverseIndex = i;
1079 }
1080 batchCount++;
1081 batchEnd = i;
1082 fbZ += updatingLayersAbove;
1083 i++;
1084 updatingLayersAbove = 0;
1085 continue;
1086 } else {
1087 //both failed.start the loop again from here.
1088 if(firstZReverseIndex >= 0) {
1089 i = firstZReverseIndex;
1090 }
1091 break;
1092 }
1093 }
1094 }
1095 }
1096 if(batchCount > maxBatchCount) {
1097 maxBatchCount = batchCount;
1098 maxBatchStart = batchStart;
1099 maxBatchEnd = batchEnd;
1100 fbZOrder = fbZ;
1101 }
1102 }
1103 return fbZOrder;
1104}
1105
1106bool MDPComp::markLayersForCaching(hwc_context_t* ctx,
1107 hwc_display_contents_1_t* list) {
1108 /* Idea is to keep as many non-updating(cached) layers in FB and
1109 * send rest of them through MDP. This is done in 2 steps.
1110 * 1. Find the maximum contiguous batch of non-updating layers.
1111 * 2. See if we can improve this batch size for caching by adding
1112 * opaque layers around the batch, if they don't have
1113 * any overlapping with the updating layers in between.
1114 * NEVER mark an updating layer for caching.
1115 * But cached ones can be marked for MDP */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001116
1117 int maxBatchStart = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001118 int maxBatchEnd = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001119 int maxBatchCount = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301120 int fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001121
Saurabh Shahd53bc5f2014-02-05 10:17:43 -08001122 /* Nothing is cached. No batching needed */
1123 if(mCurrentFrame.fbCount == 0) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001124 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -07001125 }
Saurabh Shahd53bc5f2014-02-05 10:17:43 -08001126
1127 /* No MDP comp layers, try to use other comp modes */
1128 if(mCurrentFrame.mdpCount == 0) {
1129 return false;
Saurabh Shahaa236822013-04-24 18:07:26 -07001130 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001131
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301132 fbZ = getBatch(list, maxBatchStart, maxBatchEnd, maxBatchCount);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001133
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301134 /* reset rest of the layers lying inside ROI for MDP comp */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001135 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001136 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001137 if((i < maxBatchStart || i > maxBatchEnd) &&
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301138 mCurrentFrame.isFBComposed[i]){
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001139 if(!mCurrentFrame.drop[i]){
1140 //If an unsupported layer is being attempted to
1141 //be pulled out we should fail
1142 if(not isSupportedForMDPComp(ctx, layer)) {
1143 return false;
1144 }
1145 mCurrentFrame.isFBComposed[i] = false;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001146 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001147 }
1148 }
1149
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301150 // update the frame data
1151 mCurrentFrame.fbZ = fbZ;
1152 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001153 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001154 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001155
1156 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301157 mCurrentFrame.fbCount);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001158
1159 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001160}
Saurabh Shah85234ec2013-04-12 17:09:00 -07001161
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001162void MDPComp::updateLayerCache(hwc_context_t* ctx,
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001163 hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001164 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001165 int fbCount = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001166
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001167 for(int i = 0; i < numAppLayers; i++) {
1168 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001169 if(!mCurrentFrame.drop[i])
1170 fbCount++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001171 mCurrentFrame.isFBComposed[i] = true;
1172 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -07001173 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001174 }
1175 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001176
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001177 mCurrentFrame.fbCount = fbCount;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001178 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount
1179 - mCurrentFrame.dropCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001180
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001181 ALOGD_IF(isDebug(),"%s: MDP count: %d FB count %d drop count: %d"
1182 ,__FUNCTION__, mCurrentFrame.mdpCount, mCurrentFrame.fbCount,
1183 mCurrentFrame.dropCount);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001184}
1185
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001186void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list,
1187 bool secureOnly) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001188 int nYuvCount = ctx->listStats[mDpy].yuvCount;
1189 for(int index = 0;index < nYuvCount; index++){
1190 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
1191 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
1192
1193 if(!isYUVDoable(ctx, layer)) {
1194 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
1195 mCurrentFrame.isFBComposed[nYuvIndex] = true;
1196 mCurrentFrame.fbCount++;
1197 }
1198 } else {
1199 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001200 private_handle_t *hnd = (private_handle_t *)layer->handle;
1201 if(!secureOnly || isSecureBuffer(hnd)) {
1202 mCurrentFrame.isFBComposed[nYuvIndex] = false;
1203 mCurrentFrame.fbCount--;
1204 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001205 }
1206 }
1207 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001208
1209 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001210 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
1211 ALOGD_IF(isDebug(),"%s: fb count: %d",__FUNCTION__,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001212 mCurrentFrame.fbCount);
1213}
1214
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001215hwc_rect_t MDPComp::getUpdatingFBRect(hwc_context_t *ctx,
1216 hwc_display_contents_1_t* list){
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001217 hwc_rect_t fbRect = (struct hwc_rect){0, 0, 0, 0};
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001218
1219 /* Update only the region of FB needed for composition */
1220 for(int i = 0; i < mCurrentFrame.layerCount; i++ ) {
1221 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
1222 hwc_layer_1_t* layer = &list->hwLayers[i];
1223 hwc_rect_t dst = layer->displayFrame;
1224 fbRect = getUnion(fbRect, dst);
1225 }
1226 }
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001227 trimAgainstROI(ctx, fbRect);
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001228 return fbRect;
1229}
1230
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001231bool MDPComp::postHeuristicsHandling(hwc_context_t *ctx,
1232 hwc_display_contents_1_t* list) {
1233
1234 //Capability checks
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301235 if(!resourceCheck()) {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001236 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
1237 return false;
1238 }
1239
1240 //Limitations checks
1241 if(!hwLimitationsCheck(ctx, list)) {
1242 ALOGD_IF(isDebug(), "%s: HW limitations",__FUNCTION__);
1243 return false;
1244 }
1245
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001246 //Configure framebuffer first if applicable
1247 if(mCurrentFrame.fbZ >= 0) {
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001248 hwc_rect_t fbRect = getUpdatingFBRect(ctx, list);
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001249 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, fbRect, mCurrentFrame.fbZ))
1250 {
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001251 ALOGD_IF(isDebug(), "%s configure framebuffer failed",
1252 __FUNCTION__);
1253 return false;
1254 }
1255 }
1256
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001257 mCurrentFrame.map();
1258
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001259 if(!allocLayerPipes(ctx, list)) {
1260 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -07001261 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001262 }
1263
1264 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001265 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001266 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001267 int mdpIndex = mCurrentFrame.layerToMDP[index];
1268 hwc_layer_1_t* layer = &list->hwLayers[index];
1269
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301270 //Leave fbZ for framebuffer. CACHE/GLES layers go here.
1271 if(mdpNextZOrder == mCurrentFrame.fbZ) {
1272 mdpNextZOrder++;
1273 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001274 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1275 cur_pipe->zOrder = mdpNextZOrder++;
1276
radhakrishnac9a67412013-09-25 17:40:42 +05301277 private_handle_t *hnd = (private_handle_t *)layer->handle;
1278 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1279 if(configure4k2kYuv(ctx, layer,
1280 mCurrentFrame.mdpToLayer[mdpIndex])
1281 != 0 ){
1282 ALOGD_IF(isDebug(), "%s: Failed to configure split pipes \
1283 for layer %d",__FUNCTION__, index);
1284 return false;
1285 }
1286 else{
1287 mdpNextZOrder++;
1288 }
1289 continue;
1290 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001291 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
1292 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
radhakrishnac9a67412013-09-25 17:40:42 +05301293 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -07001294 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001295 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001296 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001297 }
1298
Saurabh Shaha36be922013-12-16 18:18:39 -08001299 if(!ctx->mOverlay->validateAndSet(mDpy, ctx->dpyAttr[mDpy].fd)) {
1300 ALOGD_IF(isDebug(), "%s: Failed to validate and set overlay for dpy %d"
1301 ,__FUNCTION__, mDpy);
1302 return false;
1303 }
1304
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001305 setRedraw(ctx, list);
Saurabh Shahaa236822013-04-24 18:07:26 -07001306 return true;
1307}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001308
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301309bool MDPComp::resourceCheck() {
Saurabh Shah173f4242013-11-20 09:50:12 -08001310 const bool fbUsed = mCurrentFrame.fbCount;
1311 if(mCurrentFrame.mdpCount > sMaxPipesPerMixer - fbUsed) {
1312 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
1313 return false;
1314 }
Saurabh Shah173f4242013-11-20 09:50:12 -08001315 return true;
1316}
1317
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301318bool MDPComp::hwLimitationsCheck(hwc_context_t* ctx,
1319 hwc_display_contents_1_t* list) {
1320
1321 //A-family hw limitation:
1322 //If a layer need alpha scaling, MDP can not support.
1323 if(ctx->mMDP.version < qdutils::MDSS_V5) {
1324 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1325 if(!mCurrentFrame.isFBComposed[i] &&
1326 isAlphaScaled( &list->hwLayers[i])) {
1327 ALOGD_IF(isDebug(), "%s:frame needs alphaScaling",__FUNCTION__);
1328 return false;
1329 }
1330 }
1331 }
1332
1333 // On 8x26 & 8974 hw, we have a limitation of downscaling+blending.
1334 //If multiple layers requires downscaling and also they are overlapping
1335 //fall back to GPU since MDSS can not handle it.
1336 if(qdutils::MDPVersion::getInstance().is8x74v2() ||
1337 qdutils::MDPVersion::getInstance().is8x26()) {
1338 for(int i = 0; i < mCurrentFrame.layerCount-1; ++i) {
1339 hwc_layer_1_t* botLayer = &list->hwLayers[i];
1340 if(!mCurrentFrame.isFBComposed[i] &&
1341 isDownscaleRequired(botLayer)) {
1342 //if layer-i is marked for MDP and needs downscaling
1343 //check if any MDP layer on top of i & overlaps with layer-i
1344 for(int j = i+1; j < mCurrentFrame.layerCount; ++j) {
1345 hwc_layer_1_t* topLayer = &list->hwLayers[j];
1346 if(!mCurrentFrame.isFBComposed[j] &&
1347 isDownscaleRequired(topLayer)) {
1348 hwc_rect_t r = getIntersection(botLayer->displayFrame,
1349 topLayer->displayFrame);
1350 if(isValidRect(r))
1351 return false;
1352 }
1353 }
1354 }
1355 }
1356 }
1357 return true;
1358}
1359
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001360int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001361 int ret = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -07001362 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -07001363
Raj Kamal9ed3d6b2014-02-07 16:15:17 +05301364 //Do not cache the information for next draw cycle.
1365 if(numLayers > MAX_NUM_APP_LAYERS or (!numLayers)) {
1366 ALOGI("%s: Unsupported layer count for mdp composition",
1367 __FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001368 mCachedFrame.reset();
1369 return -1;
1370 }
1371
Saurabh Shahb39f8152013-08-22 10:21:44 -07001372 //reset old data
1373 mCurrentFrame.reset(numLayers);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001374 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1375 mCurrentFrame.dropCount = 0;
Prabhanjan Kandula088bd892013-07-02 23:47:13 +05301376
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -07001377 // Detect the start of animation and fall back to GPU only once to cache
1378 // all the layers in FB and display FB content untill animation completes.
1379 if(ctx->listStats[mDpy].isDisplayAnimating) {
1380 mCurrentFrame.needsRedraw = false;
1381 if(ctx->mAnimationState[mDpy] == ANIMATION_STOPPED) {
1382 mCurrentFrame.needsRedraw = true;
1383 ctx->mAnimationState[mDpy] = ANIMATION_STARTED;
1384 }
1385 setMDPCompLayerFlags(ctx, list);
1386 mCachedFrame.updateCounts(mCurrentFrame);
1387 ret = -1;
1388 return ret;
1389 } else {
1390 ctx->mAnimationState[mDpy] = ANIMATION_STOPPED;
1391 }
1392
Saurabh Shahb39f8152013-08-22 10:21:44 -07001393 //Hard conditions, if not met, cannot do MDP comp
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001394 if(isFrameDoable(ctx)) {
1395 generateROI(ctx, list);
Saurabh Shahb39f8152013-08-22 10:21:44 -07001396
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001397 if(tryFullFrame(ctx, list) || tryVideoOnly(ctx, list)) {
1398 setMDPCompLayerFlags(ctx, list);
1399 } else {
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001400 resetROI(ctx, mDpy);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001401 reset(ctx);
1402 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1403 mCurrentFrame.dropCount = 0;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001404 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001405 }
1406 } else {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001407 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
1408 __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001409 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001410 }
Saurabh Shahb39f8152013-08-22 10:21:44 -07001411
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001412 if(isDebug()) {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001413 ALOGD("GEOMETRY change: %d",
1414 (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001415 android::String8 sDump("");
1416 dump(sDump);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001417 ALOGD("%s",sDump.string());
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001418 }
1419
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001420 mCachedFrame.cacheAll(list);
1421 mCachedFrame.updateCounts(mCurrentFrame);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001422 return ret;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001423}
1424
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001425bool MDPComp::allocSplitVGPipesfor4k2k(hwc_context_t *ctx, int index) {
radhakrishnac9a67412013-09-25 17:40:42 +05301426
1427 bool bRet = true;
radhakrishnac9a67412013-09-25 17:40:42 +05301428 int mdpIndex = mCurrentFrame.layerToMDP[index];
1429 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
1430 info.pipeInfo = new MdpYUVPipeInfo;
1431 info.rot = NULL;
1432 MdpYUVPipeInfo& pipe_info = *(MdpYUVPipeInfo*)info.pipeInfo;
radhakrishnac9a67412013-09-25 17:40:42 +05301433
1434 pipe_info.lIndex = ovutils::OV_INVALID;
1435 pipe_info.rIndex = ovutils::OV_INVALID;
1436
Saurabh Shahc62f3982014-03-05 14:28:26 -08001437 Overlay::PipeSpecs pipeSpecs;
1438 pipeSpecs.formatClass = Overlay::FORMAT_YUV;
1439 pipeSpecs.needsScaling = true;
1440 pipeSpecs.dpy = mDpy;
1441 pipeSpecs.fb = false;
1442
1443 pipe_info.lIndex = ctx->mOverlay->getPipe(pipeSpecs);
radhakrishnac9a67412013-09-25 17:40:42 +05301444 if(pipe_info.lIndex == ovutils::OV_INVALID){
1445 bRet = false;
1446 ALOGD_IF(isDebug(),"%s: allocating first VG pipe failed",
1447 __FUNCTION__);
1448 }
Saurabh Shahc62f3982014-03-05 14:28:26 -08001449 pipe_info.rIndex = ctx->mOverlay->getPipe(pipeSpecs);
radhakrishnac9a67412013-09-25 17:40:42 +05301450 if(pipe_info.rIndex == ovutils::OV_INVALID){
1451 bRet = false;
1452 ALOGD_IF(isDebug(),"%s: allocating second VG pipe failed",
1453 __FUNCTION__);
1454 }
1455 return bRet;
1456}
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001457//=============MDPCompNonSplit==================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001458
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001459void MDPCompNonSplit::adjustForSourceSplit(hwc_context_t *ctx,
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001460 hwc_display_contents_1_t*) {
radhakrishnac9a67412013-09-25 17:40:42 +05301461 //As we split 4kx2k yuv layer and program to 2 VG pipes
1462 //(if available) increase mdpcount accordingly
1463 mCurrentFrame.mdpCount += ctx->listStats[mDpy].yuv4k2kCount;
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001464
1465 //If 4k2k Yuv layer split is possible, and if
1466 //fbz is above 4k2k layer, increment fb zorder by 1
1467 //as we split 4k2k layer and increment zorder for right half
1468 //of the layer
1469 if(mCurrentFrame.fbZ >= 0) {
1470 int n4k2kYuvCount = ctx->listStats[mDpy].yuv4k2kCount;
1471 for(int index = 0; index < n4k2kYuvCount; index++){
1472 int n4k2kYuvIndex =
1473 ctx->listStats[mDpy].yuv4k2kIndices[index];
Dileep Kumar Reddi4cff9282014-04-01 12:57:08 +05301474 if(mCurrentFrame.fbZ >= n4k2kYuvIndex){
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001475 mCurrentFrame.fbZ += 1;
1476 }
1477 }
1478 }
radhakrishnac9a67412013-09-25 17:40:42 +05301479}
1480
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001481/*
1482 * Configures pipe(s) for MDP composition
1483 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001484int MDPCompNonSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001485 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001486 MdpPipeInfoNonSplit& mdp_info =
1487 *(static_cast<MdpPipeInfoNonSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001488 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
1489 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1490 eIsFg isFg = IS_FG_OFF;
1491 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001492
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001493 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
1494 __FUNCTION__, layer, zOrder, dest);
1495
Saurabh Shah88e4d272013-09-03 13:31:29 -07001496 return configureNonSplit(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001497 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001498}
1499
Saurabh Shah88e4d272013-09-03 13:31:29 -07001500bool MDPCompNonSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001501 hwc_display_contents_1_t* list) {
1502 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001503
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001504 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001505
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001506 hwc_layer_1_t* layer = &list->hwLayers[index];
1507 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301508 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001509 if(allocSplitVGPipesfor4k2k(ctx, index)){
radhakrishnac9a67412013-09-25 17:40:42 +05301510 continue;
1511 }
1512 }
1513
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001514 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001515 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001516 info.pipeInfo = new MdpPipeInfoNonSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08001517 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001518 MdpPipeInfoNonSplit& pipe_info = *(MdpPipeInfoNonSplit*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001519
Saurabh Shahc62f3982014-03-05 14:28:26 -08001520 Overlay::PipeSpecs pipeSpecs;
1521 pipeSpecs.formatClass = isYuvBuffer(hnd) ?
1522 Overlay::FORMAT_YUV : Overlay::FORMAT_RGB;
1523 pipeSpecs.needsScaling = qhwc::needsScaling(layer) or
1524 (qdutils::MDPVersion::getInstance().is8x26() and
1525 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres > 1024);
1526 pipeSpecs.dpy = mDpy;
1527 pipeSpecs.fb = false;
Xu Yang1e686f62014-04-08 13:56:47 +08001528 pipeSpecs.numActiveDisplays = ctx->numActiveDisplays;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001529
Saurabh Shahc62f3982014-03-05 14:28:26 -08001530 pipe_info.index = ctx->mOverlay->getPipe(pipeSpecs);
1531
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001532 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001533 ALOGD_IF(isDebug(), "%s: Unable to get pipe", __FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001534 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001535 }
1536 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001537 return true;
1538}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001539
radhakrishnac9a67412013-09-25 17:40:42 +05301540int MDPCompNonSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1541 PipeLayerPair& PipeLayerPair) {
1542 MdpYUVPipeInfo& mdp_info =
1543 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1544 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1545 eIsFg isFg = IS_FG_OFF;
1546 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1547 eDest lDest = mdp_info.lIndex;
1548 eDest rDest = mdp_info.rIndex;
1549
1550 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1551 lDest, rDest, &PipeLayerPair.rot);
1552}
1553
Saurabh Shah88e4d272013-09-03 13:31:29 -07001554bool MDPCompNonSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001555
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001556 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001557 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1558 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -08001559 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001560
1561 if(!ctx || !list) {
1562 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001563 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001564 }
1565
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301566 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1567 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1568 return true;
1569 }
1570
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -08001571 // Set the Handle timeout to true for MDP or MIXED composition.
1572 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount) {
1573 sHandleTimeout = true;
1574 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001575
1576 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001577 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001578
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001579 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1580 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001581 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001582 if(mCurrentFrame.isFBComposed[i]) continue;
1583
Naseer Ahmed5b6708a2012-08-02 13:46:08 -07001584 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001585 private_handle_t *hnd = (private_handle_t *)layer->handle;
1586 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001587 if (!(layer->flags & HWC_COLOR_FILL)) {
1588 ALOGE("%s handle null", __FUNCTION__);
1589 return false;
1590 }
1591 // No PLAY for Color layer
1592 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1593 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001594 }
1595
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001596 int mdpIndex = mCurrentFrame.layerToMDP[i];
1597
radhakrishnac9a67412013-09-25 17:40:42 +05301598 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1599 {
1600 MdpYUVPipeInfo& pipe_info =
1601 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1602 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1603 ovutils::eDest indexL = pipe_info.lIndex;
1604 ovutils::eDest indexR = pipe_info.rIndex;
1605 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301606 uint32_t offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05301607 if(rot) {
1608 rot->queueBuffer(fd, offset);
1609 fd = rot->getDstMemId();
1610 offset = rot->getDstOffset();
1611 }
1612 if(indexL != ovutils::OV_INVALID) {
1613 ovutils::eDest destL = (ovutils::eDest)indexL;
1614 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1615 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1616 if (!ov.queueBuffer(fd, offset, destL)) {
1617 ALOGE("%s: queueBuffer failed for display:%d",
1618 __FUNCTION__, mDpy);
1619 return false;
1620 }
1621 }
1622
1623 if(indexR != ovutils::OV_INVALID) {
1624 ovutils::eDest destR = (ovutils::eDest)indexR;
1625 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1626 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1627 if (!ov.queueBuffer(fd, offset, destR)) {
1628 ALOGE("%s: queueBuffer failed for display:%d",
1629 __FUNCTION__, mDpy);
1630 return false;
1631 }
1632 }
1633 }
1634 else{
1635 MdpPipeInfoNonSplit& pipe_info =
Saurabh Shah88e4d272013-09-03 13:31:29 -07001636 *(MdpPipeInfoNonSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
radhakrishnac9a67412013-09-25 17:40:42 +05301637 ovutils::eDest dest = pipe_info.index;
1638 if(dest == ovutils::OV_INVALID) {
1639 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001640 return false;
radhakrishnac9a67412013-09-25 17:40:42 +05301641 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001642
radhakrishnac9a67412013-09-25 17:40:42 +05301643 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1644 continue;
1645 }
1646
1647 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1648 using pipe: %d", __FUNCTION__, layer,
1649 hnd, dest );
1650
1651 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301652 uint32_t offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05301653
1654 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1655 if(rot) {
1656 if(!rot->queueBuffer(fd, offset))
1657 return false;
1658 fd = rot->getDstMemId();
1659 offset = rot->getDstOffset();
1660 }
1661
1662 if (!ov.queueBuffer(fd, offset, dest)) {
1663 ALOGE("%s: queueBuffer failed for display:%d ",
1664 __FUNCTION__, mDpy);
1665 return false;
1666 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001667 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001668
1669 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001670 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001671 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001672}
1673
Saurabh Shah88e4d272013-09-03 13:31:29 -07001674//=============MDPCompSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001675
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001676void MDPCompSplit::adjustForSourceSplit(hwc_context_t *ctx,
radhakrishnac9a67412013-09-25 17:40:42 +05301677 hwc_display_contents_1_t* list){
1678 //if 4kx2k yuv layer is totally present in either in left half
1679 //or right half then try splitting the yuv layer to avoid decimation
1680 int n4k2kYuvCount = ctx->listStats[mDpy].yuv4k2kCount;
1681 const int lSplit = getLeftSplit(ctx, mDpy);
1682 for(int index = 0; index < n4k2kYuvCount; index++){
1683 int n4k2kYuvIndex = ctx->listStats[mDpy].yuv4k2kIndices[index];
1684 hwc_layer_1_t* layer = &list->hwLayers[n4k2kYuvIndex];
1685 hwc_rect_t dst = layer->displayFrame;
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001686 if((dst.left > lSplit) || (dst.right < lSplit)) {
radhakrishnac9a67412013-09-25 17:40:42 +05301687 mCurrentFrame.mdpCount += 1;
1688 }
Dileep Kumar Reddi4cff9282014-04-01 12:57:08 +05301689 if(mCurrentFrame.fbZ >= n4k2kYuvIndex){
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001690 mCurrentFrame.fbZ += 1;
1691 }
radhakrishnac9a67412013-09-25 17:40:42 +05301692 }
1693}
1694
Saurabh Shah88e4d272013-09-03 13:31:29 -07001695bool MDPCompSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Saurabh Shahc62f3982014-03-05 14:28:26 -08001696 MdpPipeInfoSplit& pipe_info) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001697
Saurabh Shahc62f3982014-03-05 14:28:26 -08001698 const int lSplit = getLeftSplit(ctx, mDpy);
1699 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001700 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001701 pipe_info.lIndex = ovutils::OV_INVALID;
1702 pipe_info.rIndex = ovutils::OV_INVALID;
1703
Saurabh Shahc62f3982014-03-05 14:28:26 -08001704 Overlay::PipeSpecs pipeSpecs;
1705 pipeSpecs.formatClass = isYuvBuffer(hnd) ?
1706 Overlay::FORMAT_YUV : Overlay::FORMAT_RGB;
1707 pipeSpecs.needsScaling = qhwc::needsScalingWithSplit(ctx, layer, mDpy);
1708 pipeSpecs.dpy = mDpy;
1709 pipeSpecs.mixer = Overlay::MIXER_LEFT;
1710 pipeSpecs.fb = false;
1711
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001712 // Acquire pipe only for the updating half
1713 hwc_rect_t l_roi = ctx->listStats[mDpy].lRoi;
1714 hwc_rect_t r_roi = ctx->listStats[mDpy].rRoi;
1715
1716 if (dst.left < lSplit && isValidRect(getIntersection(dst, l_roi))) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001717 pipe_info.lIndex = ctx->mOverlay->getPipe(pipeSpecs);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001718 if(pipe_info.lIndex == ovutils::OV_INVALID)
1719 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001720 }
1721
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001722 if(dst.right > lSplit && isValidRect(getIntersection(dst, r_roi))) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001723 pipeSpecs.mixer = Overlay::MIXER_RIGHT;
1724 pipe_info.rIndex = ctx->mOverlay->getPipe(pipeSpecs);
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001725 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001726 return false;
1727 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001728
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001729 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001730}
1731
Saurabh Shah88e4d272013-09-03 13:31:29 -07001732bool MDPCompSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001733 hwc_display_contents_1_t* list) {
1734 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001735
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001736 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001737
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001738 hwc_layer_1_t* layer = &list->hwLayers[index];
1739 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301740 hwc_rect_t dst = layer->displayFrame;
1741 const int lSplit = getLeftSplit(ctx, mDpy);
1742 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1743 if((dst.left > lSplit)||(dst.right < lSplit)){
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001744 if(allocSplitVGPipesfor4k2k(ctx, index)){
radhakrishnac9a67412013-09-25 17:40:42 +05301745 continue;
1746 }
1747 }
1748 }
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001749 int mdpIndex = mCurrentFrame.layerToMDP[index];
1750 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001751 info.pipeInfo = new MdpPipeInfoSplit;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001752 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001753 MdpPipeInfoSplit& pipe_info = *(MdpPipeInfoSplit*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001754
Saurabh Shahc62f3982014-03-05 14:28:26 -08001755 if(!acquireMDPPipes(ctx, layer, pipe_info)) {
1756 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type",
1757 __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001758 return false;
1759 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001760 }
1761 return true;
1762}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001763
radhakrishnac9a67412013-09-25 17:40:42 +05301764int MDPCompSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1765 PipeLayerPair& PipeLayerPair) {
1766 const int lSplit = getLeftSplit(ctx, mDpy);
1767 hwc_rect_t dst = layer->displayFrame;
1768 if((dst.left > lSplit)||(dst.right < lSplit)){
1769 MdpYUVPipeInfo& mdp_info =
1770 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1771 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1772 eIsFg isFg = IS_FG_OFF;
1773 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1774 eDest lDest = mdp_info.lIndex;
1775 eDest rDest = mdp_info.rIndex;
1776
1777 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1778 lDest, rDest, &PipeLayerPair.rot);
1779 }
1780 else{
1781 return configure(ctx, layer, PipeLayerPair);
1782 }
1783}
1784
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001785/*
1786 * Configures pipe(s) for MDP composition
1787 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001788int MDPCompSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001789 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001790 MdpPipeInfoSplit& mdp_info =
1791 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001792 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1793 eIsFg isFg = IS_FG_OFF;
1794 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1795 eDest lDest = mdp_info.lIndex;
1796 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001797
1798 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1799 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1800
Saurabh Shah88e4d272013-09-03 13:31:29 -07001801 return configureSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001802 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001803}
1804
Saurabh Shah88e4d272013-09-03 13:31:29 -07001805bool MDPCompSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001806
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001807 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001808 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1809 return true;
1810 }
1811
1812 if(!ctx || !list) {
1813 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001814 return false;
1815 }
1816
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301817 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1818 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1819 return true;
1820 }
1821
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -08001822 // Set the Handle timeout to true for MDP or MIXED composition.
1823 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount) {
1824 sHandleTimeout = true;
1825 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001826
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001827 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001828 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001829
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001830 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1831 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001832 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001833 if(mCurrentFrame.isFBComposed[i]) continue;
1834
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001835 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001836 private_handle_t *hnd = (private_handle_t *)layer->handle;
1837 if(!hnd) {
1838 ALOGE("%s handle null", __FUNCTION__);
1839 return false;
1840 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001841
1842 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1843 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001844 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001845
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001846 int mdpIndex = mCurrentFrame.layerToMDP[i];
1847
radhakrishnac9a67412013-09-25 17:40:42 +05301848 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1849 {
1850 MdpYUVPipeInfo& pipe_info =
1851 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1852 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1853 ovutils::eDest indexL = pipe_info.lIndex;
1854 ovutils::eDest indexR = pipe_info.rIndex;
1855 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301856 uint32_t offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05301857 if(rot) {
1858 rot->queueBuffer(fd, offset);
1859 fd = rot->getDstMemId();
1860 offset = rot->getDstOffset();
1861 }
1862 if(indexL != ovutils::OV_INVALID) {
1863 ovutils::eDest destL = (ovutils::eDest)indexL;
1864 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1865 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1866 if (!ov.queueBuffer(fd, offset, destL)) {
1867 ALOGE("%s: queueBuffer failed for display:%d",
1868 __FUNCTION__, mDpy);
1869 return false;
1870 }
1871 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001872
radhakrishnac9a67412013-09-25 17:40:42 +05301873 if(indexR != ovutils::OV_INVALID) {
1874 ovutils::eDest destR = (ovutils::eDest)indexR;
1875 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1876 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1877 if (!ov.queueBuffer(fd, offset, destR)) {
1878 ALOGE("%s: queueBuffer failed for display:%d",
1879 __FUNCTION__, mDpy);
1880 return false;
1881 }
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001882 }
1883 }
radhakrishnac9a67412013-09-25 17:40:42 +05301884 else{
1885 MdpPipeInfoSplit& pipe_info =
1886 *(MdpPipeInfoSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1887 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001888
radhakrishnac9a67412013-09-25 17:40:42 +05301889 ovutils::eDest indexL = pipe_info.lIndex;
1890 ovutils::eDest indexR = pipe_info.rIndex;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001891
radhakrishnac9a67412013-09-25 17:40:42 +05301892 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301893 int offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05301894
Tatenda Chipeperekwa88fe6352014-04-14 10:36:06 -07001895 if(ctx->mAD->draw(ctx, fd, offset)) {
1896 fd = ctx->mAD->getDstFd();
1897 offset = ctx->mAD->getDstOffset();
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001898 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001899
radhakrishnac9a67412013-09-25 17:40:42 +05301900 if(rot) {
1901 rot->queueBuffer(fd, offset);
1902 fd = rot->getDstMemId();
1903 offset = rot->getDstOffset();
1904 }
1905
1906 //************* play left mixer **********
1907 if(indexL != ovutils::OV_INVALID) {
1908 ovutils::eDest destL = (ovutils::eDest)indexL;
1909 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1910 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1911 if (!ov.queueBuffer(fd, offset, destL)) {
1912 ALOGE("%s: queueBuffer failed for left mixer",
1913 __FUNCTION__);
1914 return false;
1915 }
1916 }
1917
1918 //************* play right mixer **********
1919 if(indexR != ovutils::OV_INVALID) {
1920 ovutils::eDest destR = (ovutils::eDest)indexR;
1921 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1922 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1923 if (!ov.queueBuffer(fd, offset, destR)) {
1924 ALOGE("%s: queueBuffer failed for right mixer",
1925 __FUNCTION__);
1926 return false;
1927 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001928 }
1929 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001930
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001931 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1932 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001933
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001934 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001935}
Saurabh Shahab47c692014-02-12 18:45:57 -08001936
1937//================MDPCompSrcSplit==============================================
1938bool MDPCompSrcSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Saurabh Shahc62f3982014-03-05 14:28:26 -08001939 MdpPipeInfoSplit& pipe_info) {
Saurabh Shahab47c692014-02-12 18:45:57 -08001940 private_handle_t *hnd = (private_handle_t *)layer->handle;
1941 hwc_rect_t dst = layer->displayFrame;
1942 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
1943 pipe_info.lIndex = ovutils::OV_INVALID;
1944 pipe_info.rIndex = ovutils::OV_INVALID;
1945
1946 //If 2 pipes are staged on a single stage of a mixer, then the left pipe
1947 //should have a higher priority than the right one. Pipe priorities are
1948 //starting with VG0, VG1 ... , RGB0 ..., DMA1
Saurabh Shahab47c692014-02-12 18:45:57 -08001949
Saurabh Shahc62f3982014-03-05 14:28:26 -08001950 Overlay::PipeSpecs pipeSpecs;
1951 pipeSpecs.formatClass = isYuvBuffer(hnd) ?
1952 Overlay::FORMAT_YUV : Overlay::FORMAT_RGB;
1953 pipeSpecs.needsScaling = qhwc::needsScaling(layer);
1954 pipeSpecs.dpy = mDpy;
1955 pipeSpecs.fb = false;
1956
Saurabh Shahab47c692014-02-12 18:45:57 -08001957 //1 pipe by default for a layer
Saurabh Shahc62f3982014-03-05 14:28:26 -08001958 pipe_info.lIndex = ctx->mOverlay->getPipe(pipeSpecs);
Saurabh Shahab47c692014-02-12 18:45:57 -08001959 if(pipe_info.lIndex == ovutils::OV_INVALID) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001960 return false;
Saurabh Shahab47c692014-02-12 18:45:57 -08001961 }
1962
1963 //If layer's crop width or dest width > 2048, use 2 pipes
1964 if((dst.right - dst.left) > qdutils::MAX_DISPLAY_DIM or
1965 (crop.right - crop.left) > qdutils::MAX_DISPLAY_DIM) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001966 pipe_info.rIndex = ctx->mOverlay->getPipe(pipeSpecs);
Saurabh Shahab47c692014-02-12 18:45:57 -08001967 if(pipe_info.rIndex == ovutils::OV_INVALID) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001968 return false;
Saurabh Shahdd8237a2014-02-28 14:29:09 -08001969 }
1970
1971 // Return values
1972 // 1 Left pipe is higher priority, do nothing.
1973 // 0 Pipes of same priority.
1974 //-1 Right pipe is of higher priority, needs swap.
1975 if(ctx->mOverlay->comparePipePriority(pipe_info.lIndex,
1976 pipe_info.rIndex) == -1) {
1977 qhwc::swap(pipe_info.lIndex, pipe_info.rIndex);
Saurabh Shahab47c692014-02-12 18:45:57 -08001978 }
1979 }
1980
1981 return true;
1982}
1983
Saurabh Shahab47c692014-02-12 18:45:57 -08001984int MDPCompSrcSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
1985 PipeLayerPair& PipeLayerPair) {
1986 private_handle_t *hnd = (private_handle_t *)layer->handle;
1987 if(!hnd) {
1988 ALOGE("%s: layer handle is NULL", __FUNCTION__);
1989 return -1;
1990 }
1991 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
1992 MdpPipeInfoSplit& mdp_info =
1993 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
1994 Rotator **rot = &PipeLayerPair.rot;
1995 eZorder z = static_cast<eZorder>(mdp_info.zOrder);
1996 eIsFg isFg = IS_FG_OFF;
1997 eDest lDest = mdp_info.lIndex;
1998 eDest rDest = mdp_info.rIndex;
1999 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
2000 hwc_rect_t dst = layer->displayFrame;
2001 int transform = layer->transform;
2002 eTransform orient = static_cast<eTransform>(transform);
2003 const int downscale = 0;
2004 int rotFlags = ROT_FLAGS_NONE;
2005 uint32_t format = ovutils::getMdpFormat(hnd->format, isTileRendered(hnd));
2006 Whf whf(getWidth(hnd), getHeight(hnd), format, hnd->size);
2007
2008 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
2009 "dest_pipeR: %d",__FUNCTION__, layer, z, lDest, rDest);
2010
2011 // Handle R/B swap
2012 if (layer->flags & HWC_FORMAT_RB_SWAP) {
2013 if (hnd->format == HAL_PIXEL_FORMAT_RGBA_8888)
2014 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRA_8888);
2015 else if (hnd->format == HAL_PIXEL_FORMAT_RGBX_8888)
2016 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRX_8888);
2017 }
2018
Saurabh Shah97e2d802014-04-14 18:03:54 -07002019 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
2020 setMdpFlags(layer, mdpFlags, 0, transform);
Saurabh Shahab47c692014-02-12 18:45:57 -08002021
2022 if(lDest != OV_INVALID && rDest != OV_INVALID) {
2023 //Enable overfetch
Saurabh Shah97e2d802014-04-14 18:03:54 -07002024 setMdpFlags(mdpFlags, OV_MDSS_MDP_DUAL_PIPE);
Saurabh Shahab47c692014-02-12 18:45:57 -08002025 }
2026
2027 if(isYuvBuffer(hnd) && (transform & HWC_TRANSFORM_ROT_90)) {
2028 (*rot) = ctx->mRotMgr->getNext();
2029 if((*rot) == NULL) return -1;
Saurabh Shah39240c92014-03-31 10:31:42 -07002030 ctx->mLayerRotMap[mDpy]->add(layer, *rot);
Saurabh Shahab47c692014-02-12 18:45:57 -08002031 //Configure rotator for pre-rotation
Saurabh Shah97e2d802014-04-14 18:03:54 -07002032 if(configRotator(*rot, whf, crop, mdpFlags, orient, downscale) < 0) {
Saurabh Shahab47c692014-02-12 18:45:57 -08002033 ALOGE("%s: configRotator failed!", __FUNCTION__);
2034 return -1;
2035 }
Saurabh Shahab47c692014-02-12 18:45:57 -08002036 whf.format = (*rot)->getDstFormat();
2037 updateSource(orient, whf, crop);
2038 rotFlags |= ROT_PREROTATED;
2039 }
2040
2041 //If 2 pipes being used, divide layer into half, crop and dst
2042 hwc_rect_t cropL = crop;
2043 hwc_rect_t cropR = crop;
2044 hwc_rect_t dstL = dst;
2045 hwc_rect_t dstR = dst;
2046 if(lDest != OV_INVALID && rDest != OV_INVALID) {
2047 cropL.right = (crop.right + crop.left) / 2;
2048 cropR.left = cropL.right;
2049 sanitizeSourceCrop(cropL, cropR, hnd);
2050
2051 //Swap crops on H flip since 2 pipes are being used
2052 if((orient & OVERLAY_TRANSFORM_FLIP_H) && (*rot) == NULL) {
2053 hwc_rect_t tmp = cropL;
2054 cropL = cropR;
2055 cropR = tmp;
2056 }
2057
2058 dstL.right = (dst.right + dst.left) / 2;
2059 dstR.left = dstL.right;
2060 }
2061
2062 //For the mdp, since either we are pre-rotating or MDP does flips
2063 orient = OVERLAY_TRANSFORM_0;
2064 transform = 0;
2065
2066 //configure left pipe
2067 if(lDest != OV_INVALID) {
Saurabh Shah97e2d802014-04-14 18:03:54 -07002068 PipeArgs pargL(mdpFlags, whf, z, isFg,
Saurabh Shahab47c692014-02-12 18:45:57 -08002069 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2070 (ovutils::eBlending) getBlending(layer->blending));
2071
2072 if(configMdp(ctx->mOverlay, pargL, orient,
2073 cropL, dstL, metadata, lDest) < 0) {
2074 ALOGE("%s: commit failed for left mixer config", __FUNCTION__);
2075 return -1;
2076 }
2077 }
2078
2079 //configure right pipe
2080 if(rDest != OV_INVALID) {
Saurabh Shah97e2d802014-04-14 18:03:54 -07002081 PipeArgs pargR(mdpFlags, whf, z, isFg,
Saurabh Shahab47c692014-02-12 18:45:57 -08002082 static_cast<eRotFlags>(rotFlags),
2083 layer->planeAlpha,
2084 (ovutils::eBlending) getBlending(layer->blending));
2085 if(configMdp(ctx->mOverlay, pargR, orient,
2086 cropR, dstR, metadata, rDest) < 0) {
2087 ALOGE("%s: commit failed for right mixer config", __FUNCTION__);
2088 return -1;
2089 }
2090 }
2091
2092 return 0;
2093}
2094
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002095}; //namespace
2096