blob: fab9a8bd7191f44c751e69d07d3e46736bfc54fb [file] [log] [blame]
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001/*
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08002 * Copyright (C) 2012-2014, The Linux Foundation. All rights reserved.
Naseer Ahmed7c958d42012-07-31 18:57:03 -07003 * Not a Contribution, Apache license notifications and license are retained
4 * for attribution purposes only.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
Saurabh Shah4fdde762013-04-30 18:47:33 -070019#include <math.h>
Naseer Ahmed7c958d42012-07-31 18:57:03 -070020#include "hwc_mdpcomp.h"
Naseer Ahmed54821fe2012-11-28 18:44:38 -050021#include <sys/ioctl.h>
Saurabh Shah56f610d2012-08-07 15:27:06 -070022#include "external.h"
Jeykumar Sankaran27dee262013-08-01 17:09:54 -070023#include "virtual.h"
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -080024#include "qdMetaData.h"
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -080025#include "mdp_version.h"
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -070026#include "hwc_fbupdate.h"
Saurabh Shaha9da08f2013-07-03 13:27:53 -070027#include "hwc_ad.h"
Saurabh Shahacf10202013-02-26 10:15:15 -080028#include <overlayRotator.h>
29
Saurabh Shah85234ec2013-04-12 17:09:00 -070030using namespace overlay;
Saurabh Shahbd2d0832013-04-04 14:33:08 -070031using namespace qdutils;
Saurabh Shahacf10202013-02-26 10:15:15 -080032using namespace overlay::utils;
33namespace ovutils = overlay::utils;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070034
Naseer Ahmed7c958d42012-07-31 18:57:03 -070035namespace qhwc {
36
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080037//==============MDPComp========================================================
38
Naseer Ahmed7c958d42012-07-31 18:57:03 -070039IdleInvalidator *MDPComp::idleInvalidator = NULL;
40bool MDPComp::sIdleFallBack = false;
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -080041bool MDPComp::sHandleTimeout = false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070042bool MDPComp::sDebugLogs = false;
Naseer Ahmed54821fe2012-11-28 18:44:38 -050043bool MDPComp::sEnabled = false;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -070044bool MDPComp::sEnableMixedMode = true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080045int MDPComp::sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
radhakrishnac9a67412013-09-25 17:40:42 +053046bool MDPComp::sEnable4k2kYUVSplit = false;
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -070047bool MDPComp::sSrcSplitEnabled = false;
Saurabh Shah88e4d272013-09-03 13:31:29 -070048MDPComp* MDPComp::getObject(hwc_context_t *ctx, const int& dpy) {
Saurabh Shah60e8bde2014-04-30 14:46:03 -070049 if(qdutils::MDPVersion::getInstance().isSrcSplit()) {
50 sSrcSplitEnabled = true;
51 return new MDPCompSrcSplit(dpy);
52 } else if(isDisplaySplit(ctx, dpy)) {
Saurabh Shah88e4d272013-09-03 13:31:29 -070053 return new MDPCompSplit(dpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080054 }
Saurabh Shah88e4d272013-09-03 13:31:29 -070055 return new MDPCompNonSplit(dpy);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080056}
57
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080058MDPComp::MDPComp(int dpy):mDpy(dpy){};
59
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080060void MDPComp::dump(android::String8& buf)
61{
Jeykumar Sankaran3c6bb042013-08-15 14:01:04 -070062 if(mCurrentFrame.layerCount > MAX_NUM_APP_LAYERS)
63 return;
64
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080065 dumpsys_log(buf,"HWC Map for Dpy: %s \n",
Jeykumar Sankaran27dee262013-08-01 17:09:54 -070066 (mDpy == 0) ? "\"PRIMARY\"" :
67 (mDpy == 1) ? "\"EXTERNAL\"" : "\"VIRTUAL\"");
Saurabh Shahe9bc60f2013-08-29 12:58:06 -070068 dumpsys_log(buf,"CURR_FRAME: layerCount:%2d mdpCount:%2d "
69 "fbCount:%2d \n", mCurrentFrame.layerCount,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080070 mCurrentFrame.mdpCount, mCurrentFrame.fbCount);
71 dumpsys_log(buf,"needsFBRedraw:%3s pipesUsed:%2d MaxPipesPerMixer: %d \n",
72 (mCurrentFrame.needsRedraw? "YES" : "NO"),
73 mCurrentFrame.mdpCount, sMaxPipesPerMixer);
74 dumpsys_log(buf," --------------------------------------------- \n");
75 dumpsys_log(buf," listIdx | cached? | mdpIndex | comptype | Z \n");
76 dumpsys_log(buf," --------------------------------------------- \n");
77 for(int index = 0; index < mCurrentFrame.layerCount; index++ )
78 dumpsys_log(buf," %7d | %7s | %8d | %9s | %2d \n",
79 index,
80 (mCurrentFrame.isFBComposed[index] ? "YES" : "NO"),
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -070081 mCurrentFrame.layerToMDP[index],
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080082 (mCurrentFrame.isFBComposed[index] ?
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -070083 (mCurrentFrame.drop[index] ? "DROP" :
84 (mCurrentFrame.needsRedraw ? "GLES" : "CACHE")) : "MDP"),
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080085 (mCurrentFrame.isFBComposed[index] ? mCurrentFrame.fbZ :
86 mCurrentFrame.mdpToLayer[mCurrentFrame.layerToMDP[index]].pipeInfo->zOrder));
87 dumpsys_log(buf,"\n");
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080088}
89
90bool MDPComp::init(hwc_context_t *ctx) {
91
92 if(!ctx) {
93 ALOGE("%s: Invalid hwc context!!",__FUNCTION__);
94 return false;
95 }
96
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080097 char property[PROPERTY_VALUE_MAX];
98
99 sEnabled = false;
100 if((property_get("persist.hwc.mdpcomp.enable", property, NULL) > 0) &&
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800101 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
102 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800103 sEnabled = true;
104 }
105
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700106 sEnableMixedMode = true;
107 if((property_get("debug.mdpcomp.mixedmode.disable", property, NULL) > 0) &&
108 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
109 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
110 sEnableMixedMode = false;
111 }
112
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800113 if(property_get("debug.mdpcomp.logs", property, NULL) > 0) {
114 if(atoi(property) != 0)
115 sDebugLogs = true;
116 }
117
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800118 sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
Saurabh Shah85234ec2013-04-12 17:09:00 -0700119 if(property_get("debug.mdpcomp.maxpermixer", property, "-1") > 0) {
120 int val = atoi(property);
121 if(val >= 0)
122 sMaxPipesPerMixer = min(val, MAX_PIPES_PER_MIXER);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800123 }
124
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400125 if(ctx->mMDP.panel != MIPI_CMD_PANEL) {
126 // Idle invalidation is not necessary on command mode panels
127 long idle_timeout = DEFAULT_IDLE_TIME;
128 if(property_get("debug.mdpcomp.idletime", property, NULL) > 0) {
129 if(atoi(property) != 0)
130 idle_timeout = atoi(property);
131 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800132
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400133 //create Idle Invalidator only when not disabled through property
134 if(idle_timeout != -1)
135 idleInvalidator = IdleInvalidator::getInstance();
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800136
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400137 if(idleInvalidator == NULL) {
138 ALOGE("%s: failed to instantiate idleInvalidator object",
139 __FUNCTION__);
140 } else {
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530141 idleInvalidator->init(timeout_handler, ctx,
142 (unsigned int)idle_timeout);
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400143 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800144 }
radhakrishnac9a67412013-09-25 17:40:42 +0530145
146 if((property_get("debug.mdpcomp.4k2kSplit", property, "0") > 0) &&
147 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
148 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
149 sEnable4k2kYUVSplit = true;
150 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700151 return true;
152}
153
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800154void MDPComp::reset(hwc_context_t *ctx) {
155 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700156 mCurrentFrame.reset(numLayers);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800157 ctx->mOverlay->clear(mDpy);
158 ctx->mLayerRotMap[mDpy]->clear();
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700159}
160
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700161void MDPComp::timeout_handler(void *udata) {
162 struct hwc_context_t* ctx = (struct hwc_context_t*)(udata);
163
164 if(!ctx) {
165 ALOGE("%s: received empty data in timer callback", __FUNCTION__);
166 return;
167 }
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -0800168 Locker::Autolock _l(ctx->mDrawLock);
169 // Handle timeout event only if the previous composition is MDP or MIXED.
170 if(!sHandleTimeout) {
171 ALOGD_IF(isDebug(), "%s:Do not handle this timeout", __FUNCTION__);
172 return;
173 }
Jesse Hall3be78d92012-08-21 15:12:23 -0700174 if(!ctx->proc) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700175 ALOGE("%s: HWC proc not registered", __FUNCTION__);
176 return;
177 }
178 sIdleFallBack = true;
179 /* Trigger SF to redraw the current frame */
Jesse Hall3be78d92012-08-21 15:12:23 -0700180 ctx->proc->invalidate(ctx->proc);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700181}
182
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800183void MDPComp::setMDPCompLayerFlags(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800184 hwc_display_contents_1_t* list) {
185 LayerProp *layerProp = ctx->layerProp[mDpy];
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800186
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800187 for(int index = 0; index < ctx->listStats[mDpy].numAppLayers; index++) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800188 hwc_layer_1_t* layer = &(list->hwLayers[index]);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800189 if(!mCurrentFrame.isFBComposed[index]) {
190 layerProp[index].mFlags |= HWC_MDPCOMP;
191 layer->compositionType = HWC_OVERLAY;
192 layer->hints |= HWC_HINT_CLEAR_FB;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800193 } else {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700194 /* Drop the layer when its already present in FB OR when it lies
195 * outside frame's ROI */
196 if(!mCurrentFrame.needsRedraw || mCurrentFrame.drop[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800197 layer->compositionType = HWC_OVERLAY;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700198 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800199 }
200 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700201}
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500202
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800203void MDPComp::setRedraw(hwc_context_t *ctx,
204 hwc_display_contents_1_t* list) {
205 mCurrentFrame.needsRedraw = false;
206 if(!mCachedFrame.isSameFrame(mCurrentFrame, list) ||
207 (list->flags & HWC_GEOMETRY_CHANGED) ||
208 isSkipPresent(ctx, mDpy)) {
209 mCurrentFrame.needsRedraw = true;
210 }
211}
212
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800213MDPComp::FrameInfo::FrameInfo() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700214 reset(0);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800215}
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800216
Saurabh Shahaa236822013-04-24 18:07:26 -0700217void MDPComp::FrameInfo::reset(const int& numLayers) {
218 for(int i = 0 ; i < MAX_PIPES_PER_MIXER && numLayers; i++ ) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800219 if(mdpToLayer[i].pipeInfo) {
220 delete mdpToLayer[i].pipeInfo;
221 mdpToLayer[i].pipeInfo = NULL;
222 //We dont own the rotator
223 mdpToLayer[i].rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800224 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800225 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800226
227 memset(&mdpToLayer, 0, sizeof(mdpToLayer));
228 memset(&layerToMDP, -1, sizeof(layerToMDP));
Saurabh Shahaa236822013-04-24 18:07:26 -0700229 memset(&isFBComposed, 1, sizeof(isFBComposed));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800230
Saurabh Shahaa236822013-04-24 18:07:26 -0700231 layerCount = numLayers;
232 fbCount = numLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800233 mdpCount = 0;
Saurabh Shah2f3895f2013-05-02 10:13:31 -0700234 needsRedraw = true;
Saurabh Shahd53bc5f2014-02-05 10:17:43 -0800235 fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800236}
237
Saurabh Shahaa236822013-04-24 18:07:26 -0700238void MDPComp::FrameInfo::map() {
239 // populate layer and MDP maps
240 int mdpIdx = 0;
241 for(int idx = 0; idx < layerCount; idx++) {
242 if(!isFBComposed[idx]) {
243 mdpToLayer[mdpIdx].listIndex = idx;
244 layerToMDP[idx] = mdpIdx++;
245 }
246 }
247}
248
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800249MDPComp::LayerCache::LayerCache() {
250 reset();
251}
252
253void MDPComp::LayerCache::reset() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700254 memset(&hnd, 0, sizeof(hnd));
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530255 memset(&isFBComposed, true, sizeof(isFBComposed));
256 memset(&drop, false, sizeof(drop));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800257 layerCount = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -0700258}
259
260void MDPComp::LayerCache::cacheAll(hwc_display_contents_1_t* list) {
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530261 const int numAppLayers = (int)list->numHwLayers - 1;
Saurabh Shahaa236822013-04-24 18:07:26 -0700262 for(int i = 0; i < numAppLayers; i++) {
263 hnd[i] = list->hwLayers[i].handle;
264 }
265}
266
267void MDPComp::LayerCache::updateCounts(const FrameInfo& curFrame) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700268 layerCount = curFrame.layerCount;
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530269 memcpy(&isFBComposed, &curFrame.isFBComposed, sizeof(isFBComposed));
270 memcpy(&drop, &curFrame.drop, sizeof(drop));
271}
272
Jeykumar Sankaran988d3682013-11-15 11:57:16 -0800273bool MDPComp::LayerCache::isSameFrame(const FrameInfo& curFrame,
274 hwc_display_contents_1_t* list) {
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530275 if(layerCount != curFrame.layerCount)
276 return false;
277 for(int i = 0; i < curFrame.layerCount; i++) {
278 if((curFrame.isFBComposed[i] != isFBComposed[i]) ||
279 (curFrame.drop[i] != drop[i])) {
280 return false;
281 }
Jeykumar Sankaran988d3682013-11-15 11:57:16 -0800282 if(curFrame.isFBComposed[i] &&
283 (hnd[i] != list->hwLayers[i].handle)){
284 return false;
285 }
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530286 }
287 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800288}
289
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700290bool MDPComp::isSupportedForMDPComp(hwc_context_t *ctx, hwc_layer_1_t* layer) {
291 private_handle_t *hnd = (private_handle_t *)layer->handle;
292 if((not isYuvBuffer(hnd) and has90Transform(layer)) or
293 (not isValidDimension(ctx,layer))
294 //More conditions here, SKIP, sRGB+Blend etc
295 ) {
296 return false;
297 }
298 return true;
299}
300
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530301bool MDPComp::isValidDimension(hwc_context_t *ctx, hwc_layer_1_t *layer) {
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800302 private_handle_t *hnd = (private_handle_t *)layer->handle;
303
304 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -0700305 if (layer->flags & HWC_COLOR_FILL) {
306 // Color layer
307 return true;
308 }
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800309 ALOGE("%s: layer handle is NULL", __FUNCTION__);
310 return false;
311 }
312
Naseer Ahmede850a802013-09-06 13:12:52 -0400313 //XXX: Investigate doing this with pixel phase on MDSS
Naseer Ahmede77f8082013-10-10 13:42:48 -0400314 if(!isSecureBuffer(hnd) && isNonIntegralSourceCrop(layer->sourceCropf))
Naseer Ahmede850a802013-09-06 13:12:52 -0400315 return false;
316
Saurabh Shah62e1d732013-09-17 10:44:05 -0700317 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700318 hwc_rect_t dst = layer->displayFrame;
Saurabh Shah4fdde762013-04-30 18:47:33 -0700319 int crop_w = crop.right - crop.left;
320 int crop_h = crop.bottom - crop.top;
321 int dst_w = dst.right - dst.left;
322 int dst_h = dst.bottom - dst.top;
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800323 float w_scale = ((float)crop_w / (float)dst_w);
324 float h_scale = ((float)crop_h / (float)dst_h);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700325
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800326 /* Workaround for MDP HW limitation in DSI command mode panels where
327 * FPS will not go beyond 30 if buffers on RGB pipes are of width or height
328 * less than 5 pixels
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530329 * There also is a HW limilation in MDP, minimum block size is 2x2
330 * Fallback to GPU if height is less than 2.
331 */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800332 if((crop_w < 5)||(crop_h < 5))
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800333 return false;
334
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800335 if((w_scale > 1.0f) || (h_scale > 1.0f)) {
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700336 const uint32_t maxMDPDownscale =
Saurabh Shah4fdde762013-04-30 18:47:33 -0700337 qdutils::MDPVersion::getInstance().getMaxMDPDownscale();
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800338 const float w_dscale = w_scale;
339 const float h_dscale = h_scale;
340
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800341 if(ctx->mMDP.version >= qdutils::MDSS_V5) {
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700342
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800343 if(!qdutils::MDPVersion::getInstance().supportsDecimation()) {
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700344 /* On targets that doesnt support Decimation (eg.,8x26)
345 * maximum downscale support is overlay pipe downscale.
346 */
347 if(crop_w > MAX_DISPLAY_DIM || w_dscale > maxMDPDownscale ||
348 h_dscale > maxMDPDownscale)
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800349 return false;
350 } else {
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700351 // Decimation on macrotile format layers is not supported.
352 if(isTileRendered(hnd)) {
353 /* MDP can read maximum MAX_DISPLAY_DIM width.
354 * Bail out if
355 * 1. Src crop > MAX_DISPLAY_DIM on nonsplit MDPComp
356 * 2. exceeds maximum downscale limit
357 */
358 if(((crop_w > MAX_DISPLAY_DIM) && !sSrcSplitEnabled) ||
359 w_dscale > maxMDPDownscale ||
360 h_dscale > maxMDPDownscale) {
361 return false;
362 }
363 } else if(w_dscale > 64 || h_dscale > 64)
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800364 return false;
365 }
366 } else { //A-family
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700367 if(w_dscale > maxMDPDownscale || h_dscale > maxMDPDownscale)
Saurabh Shah4fdde762013-04-30 18:47:33 -0700368 return false;
369 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700370 }
371
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800372 if((w_scale < 1.0f) || (h_scale < 1.0f)) {
373 const uint32_t upscale =
374 qdutils::MDPVersion::getInstance().getMaxMDPUpscale();
375 const float w_uscale = 1.0f / w_scale;
376 const float h_uscale = 1.0f / h_scale;
377
378 if(w_uscale > upscale || h_uscale > upscale)
379 return false;
380 }
381
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800382 return true;
383}
384
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800385bool MDPComp::isFrameDoable(hwc_context_t *ctx) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700386 bool ret = true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800387
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800388 if(!isEnabled()) {
389 ALOGD_IF(isDebug(),"%s: MDP Comp. not enabled.", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700390 ret = false;
Raj Kamal068f4572014-04-14 16:14:06 +0530391 } else if((qdutils::MDPVersion::getInstance().is8x26() ||
392 qdutils::MDPVersion::getInstance().is8x16()) &&
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -0800393 ctx->mVideoTransFlag &&
394 isSecondaryConnected(ctx)) {
Saurabh Shahd4e65852013-06-17 11:33:53 -0700395 //1 Padding round to shift pipes across mixers
396 ALOGD_IF(isDebug(),"%s: MDP Comp. video transition padding round",
397 __FUNCTION__);
398 ret = false;
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -0800399 } else if(isSecondaryConfiguring(ctx)) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800400 ALOGD_IF( isDebug(),"%s: External Display connection is pending",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800401 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700402 ret = false;
Saurabh Shahaa236822013-04-24 18:07:26 -0700403 } else if(ctx->isPaddingRound) {
Raj Kamal9ed3d6b2014-02-07 16:15:17 +0530404 ALOGD_IF(isDebug(), "%s: padding round invoked for dpy %d",
405 __FUNCTION__,mDpy);
Saurabh Shahaa236822013-04-24 18:07:26 -0700406 ret = false;
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700407 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700408 return ret;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800409}
410
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800411void MDPCompNonSplit::trimAgainstROI(hwc_context_t *ctx, hwc_rect_t& fbRect) {
412 hwc_rect_t roi = ctx->listStats[mDpy].lRoi;
413 fbRect = getIntersection(fbRect, roi);
414}
415
416/* 1) Identify layers that are not visible or lying outside the updating ROI and
417 * drop them from composition.
418 * 2) If we have a scaling layer which needs cropping against generated
419 * ROI, reset ROI to full resolution. */
420bool MDPCompNonSplit::validateAndApplyROI(hwc_context_t *ctx,
421 hwc_display_contents_1_t* list) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700422 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800423 hwc_rect_t visibleRect = ctx->listStats[mDpy].lRoi;
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800424
425 for(int i = numAppLayers - 1; i >= 0; i--){
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800426 if(!isValidRect(visibleRect)) {
427 mCurrentFrame.drop[i] = true;
428 mCurrentFrame.dropCount++;
Jeykumar Sankaran0b961452014-01-21 17:26:12 -0800429 continue;
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800430 }
431
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700432 const hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700433 hwc_rect_t dstRect = layer->displayFrame;
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800434 hwc_rect_t res = getIntersection(visibleRect, dstRect);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700435
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700436 if(!isValidRect(res)) {
437 mCurrentFrame.drop[i] = true;
438 mCurrentFrame.dropCount++;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800439 } else {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700440 /* Reset frame ROI when any layer which needs scaling also needs ROI
441 * cropping */
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800442 if(!isSameRect(res, dstRect) && needsScaling (layer)) {
Arpita Banerjeed8965982013-11-08 17:27:33 -0800443 ALOGI("%s: Resetting ROI due to scaling", __FUNCTION__);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700444 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
445 mCurrentFrame.dropCount = 0;
446 return false;
447 }
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800448
Jeykumar Sankaran0b961452014-01-21 17:26:12 -0800449 /* deduct any opaque region from visibleRect */
450 if (layer->blending == HWC_BLENDING_NONE)
451 visibleRect = deductRect(visibleRect, res);
452 }
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700453 }
454 return true;
455}
456
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800457/* Calculate ROI for the frame by accounting all the layer's dispalyFrame which
458 * are updating. If DirtyRegion is applicable, calculate it by accounting all
459 * the changing layer's dirtyRegion. */
460void MDPCompNonSplit::generateROI(hwc_context_t *ctx,
461 hwc_display_contents_1_t* list) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700462 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800463 if(!canPartialUpdate(ctx, list))
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700464 return;
465
466 struct hwc_rect roi = (struct hwc_rect){0, 0, 0, 0};
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800467 hwc_rect fullFrame = (struct hwc_rect) {0, 0,(int)ctx->dpyAttr[mDpy].xres,
468 (int)ctx->dpyAttr[mDpy].yres};
469
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700470 for(int index = 0; index < numAppLayers; index++ ) {
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800471 hwc_layer_1_t* layer = &list->hwLayers[index];
472 if ((mCachedFrame.hnd[index] != layer->handle) ||
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800473 isYuvBuffer((private_handle_t *)layer->handle)) {
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800474 hwc_rect_t updatingRect = layer->displayFrame;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800475
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800476#ifdef QCOM_BSP
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800477 if(!needsScaling(layer) && !layer->transform)
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800478 updatingRect = layer->dirtyRect;
479#endif
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800480
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800481 roi = getUnion(roi, updatingRect);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700482 }
483 }
484
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800485 /* No layer is updating. Still SF wants a refresh.*/
486 if(!isValidRect(roi))
487 return;
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800488
489 // Align ROI coordinates to panel restrictions
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800490 roi = getSanitizeROI(roi, fullFrame);
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800491
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800492 ctx->listStats[mDpy].lRoi = roi;
493 if(!validateAndApplyROI(ctx, list))
494 resetROI(ctx, mDpy);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700495
496 ALOGD_IF(isDebug(),"%s: generated ROI: [%d, %d, %d, %d]", __FUNCTION__,
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800497 ctx->listStats[mDpy].lRoi.left, ctx->listStats[mDpy].lRoi.top,
498 ctx->listStats[mDpy].lRoi.right, ctx->listStats[mDpy].lRoi.bottom);
499}
500
501void MDPCompSplit::trimAgainstROI(hwc_context_t *ctx, hwc_rect_t& fbRect) {
502 hwc_rect l_roi = ctx->listStats[mDpy].lRoi;
503 hwc_rect r_roi = ctx->listStats[mDpy].rRoi;
504
505 hwc_rect_t l_fbRect = getIntersection(fbRect, l_roi);
506 hwc_rect_t r_fbRect = getIntersection(fbRect, r_roi);
507 fbRect = getUnion(l_fbRect, r_fbRect);
508}
509/* 1) Identify layers that are not visible or lying outside BOTH the updating
510 * ROI's and drop them from composition. If a layer is spanning across both
511 * the halves of the screen but needed by only ROI, the non-contributing
512 * half will not be programmed for MDP.
513 * 2) If we have a scaling layer which needs cropping against generated
514 * ROI, reset ROI to full resolution. */
515bool MDPCompSplit::validateAndApplyROI(hwc_context_t *ctx,
516 hwc_display_contents_1_t* list) {
517
518 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
519
520 hwc_rect_t visibleRectL = ctx->listStats[mDpy].lRoi;
521 hwc_rect_t visibleRectR = ctx->listStats[mDpy].rRoi;
522
523 for(int i = numAppLayers - 1; i >= 0; i--){
524 if(!isValidRect(visibleRectL) && !isValidRect(visibleRectR))
525 {
526 mCurrentFrame.drop[i] = true;
527 mCurrentFrame.dropCount++;
528 continue;
529 }
530
531 const hwc_layer_1_t* layer = &list->hwLayers[i];
532 hwc_rect_t dstRect = layer->displayFrame;
533
534 hwc_rect_t l_res = getIntersection(visibleRectL, dstRect);
535 hwc_rect_t r_res = getIntersection(visibleRectR, dstRect);
536 hwc_rect_t res = getUnion(l_res, r_res);
537
538 if(!isValidRect(l_res) && !isValidRect(r_res)) {
539 mCurrentFrame.drop[i] = true;
540 mCurrentFrame.dropCount++;
541 } else {
542 /* Reset frame ROI when any layer which needs scaling also needs ROI
543 * cropping */
544 if(!isSameRect(res, dstRect) && needsScaling (layer)) {
545 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
546 mCurrentFrame.dropCount = 0;
547 return false;
548 }
549
550 if (layer->blending == HWC_BLENDING_NONE) {
551 visibleRectL = deductRect(visibleRectL, l_res);
552 visibleRectR = deductRect(visibleRectR, r_res);
553 }
554 }
555 }
556 return true;
557}
558/* Calculate ROI for the frame by accounting all the layer's dispalyFrame which
559 * are updating. If DirtyRegion is applicable, calculate it by accounting all
560 * the changing layer's dirtyRegion. */
561void MDPCompSplit::generateROI(hwc_context_t *ctx,
562 hwc_display_contents_1_t* list) {
563 if(!canPartialUpdate(ctx, list))
564 return;
565
566 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
567 int lSplit = getLeftSplit(ctx, mDpy);
568
569 int hw_h = (int)ctx->dpyAttr[mDpy].yres;
570 int hw_w = (int)ctx->dpyAttr[mDpy].xres;
571
572 struct hwc_rect l_frame = (struct hwc_rect){0, 0, lSplit, hw_h};
573 struct hwc_rect r_frame = (struct hwc_rect){lSplit, 0, hw_w, hw_h};
574
575 struct hwc_rect l_roi = (struct hwc_rect){0, 0, 0, 0};
576 struct hwc_rect r_roi = (struct hwc_rect){0, 0, 0, 0};
577
578 for(int index = 0; index < numAppLayers; index++ ) {
579 hwc_layer_1_t* layer = &list->hwLayers[index];
580 if ((mCachedFrame.hnd[index] != layer->handle) ||
581 isYuvBuffer((private_handle_t *)layer->handle)) {
582 hwc_rect_t updatingRect = layer->displayFrame;
583
584#ifdef QCOM_BSP
585 if(!needsScaling(layer) && !layer->transform)
586 updatingRect = layer->dirtyRect;
587#endif
588
589 hwc_rect_t l_dst = getIntersection(l_frame, updatingRect);
590 if(isValidRect(l_dst))
591 l_roi = getUnion(l_roi, l_dst);
592
593 hwc_rect_t r_dst = getIntersection(r_frame, updatingRect);
594 if(isValidRect(r_dst))
595 r_roi = getUnion(r_roi, r_dst);
596 }
597 }
598
599 /* No layer is updating. Still SF wants a refresh. */
600 if(!isValidRect(l_roi) && !isValidRect(r_roi))
601 return;
602
603 l_roi = getSanitizeROI(l_roi, l_frame);
604 r_roi = getSanitizeROI(r_roi, r_frame);
605
606 ctx->listStats[mDpy].lRoi = l_roi;
607 ctx->listStats[mDpy].rRoi = r_roi;
608
609 if(!validateAndApplyROI(ctx, list))
610 resetROI(ctx, mDpy);
611
612 ALOGD_IF(isDebug(),"%s: generated L_ROI: [%d, %d, %d, %d]"
613 "R_ROI: [%d, %d, %d, %d]", __FUNCTION__,
614 ctx->listStats[mDpy].lRoi.left, ctx->listStats[mDpy].lRoi.top,
615 ctx->listStats[mDpy].lRoi.right, ctx->listStats[mDpy].lRoi.bottom,
616 ctx->listStats[mDpy].rRoi.left, ctx->listStats[mDpy].rRoi.top,
617 ctx->listStats[mDpy].rRoi.right, ctx->listStats[mDpy].rRoi.bottom);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700618}
619
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800620/* Checks for conditions where all the layers marked for MDP comp cannot be
621 * bypassed. On such conditions we try to bypass atleast YUV layers */
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800622bool MDPComp::tryFullFrame(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800623 hwc_display_contents_1_t* list){
624
Saurabh Shahaa236822013-04-24 18:07:26 -0700625 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Arun Kumar K.R2e2871c2014-01-10 12:47:06 -0800626 int priDispW = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800627
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -0700628 if(sIdleFallBack && !ctx->listStats[mDpy].secureUI) {
Saurabh Shah2d998a92013-05-14 17:55:58 -0700629 ALOGD_IF(isDebug(), "%s: Idle fallback dpy %d",__FUNCTION__, mDpy);
630 return false;
631 }
632
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800633 if(isSkipPresent(ctx, mDpy)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700634 ALOGD_IF(isDebug(),"%s: SKIP present: %d",
635 __FUNCTION__,
636 isSkipPresent(ctx, mDpy));
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800637 return false;
638 }
639
Arun Kumar K.R2e2871c2014-01-10 12:47:06 -0800640 if(mDpy > HWC_DISPLAY_PRIMARY && (priDispW > MAX_DISPLAY_DIM) &&
641 (ctx->dpyAttr[mDpy].xres < MAX_DISPLAY_DIM)) {
642 // Disable MDP comp on Secondary when the primary is highres panel and
643 // the secondary is a normal 1080p, because, MDP comp on secondary under
644 // in such usecase, decimation gets used for downscale and there will be
645 // a quality mismatch when there will be a fallback to GPU comp
646 ALOGD_IF(isDebug(), "%s: Disable MDP Compositon for Secondary Disp",
647 __FUNCTION__);
648 return false;
649 }
650
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800651 // check for action safe flag and downscale mode which requires scaling.
652 if(ctx->dpyAttr[mDpy].mActionSafePresent
653 || ctx->dpyAttr[mDpy].mDownScaleMode) {
654 ALOGD_IF(isDebug(), "%s: Scaling needed for this frame",__FUNCTION__);
655 return false;
656 }
657
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800658 for(int i = 0; i < numAppLayers; ++i) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800659 hwc_layer_1_t* layer = &list->hwLayers[i];
660 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800661
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700662 if(isYuvBuffer(hnd) && has90Transform(layer)) {
663 if(!canUseRotator(ctx, mDpy)) {
664 ALOGD_IF(isDebug(), "%s: Can't use rotator for dpy %d",
665 __FUNCTION__, mDpy);
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700666 return false;
667 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800668 }
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530669
670 //For 8x26 with panel width>1k, if RGB layer needs HFLIP fail mdp comp
671 // may not need it if Gfx pre-rotation can handle all flips & rotations
Sushil Chauhanfda00fc2014-03-20 11:08:41 -0700672 int transform = (layer->flags & HWC_COLOR_FILL) ? 0 : layer->transform;
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530673 if(qdutils::MDPVersion::getInstance().is8x26() &&
674 (ctx->dpyAttr[mDpy].xres > 1024) &&
Sushil Chauhanfda00fc2014-03-20 11:08:41 -0700675 (transform & HWC_TRANSFORM_FLIP_H) &&
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530676 (!isYuvBuffer(hnd)))
677 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800678 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700679
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700680 if(ctx->mAD->isDoable()) {
681 return false;
682 }
683
Saurabh Shahaa236822013-04-24 18:07:26 -0700684 //If all above hard conditions are met we can do full or partial MDP comp.
685 bool ret = false;
686 if(fullMDPComp(ctx, list)) {
687 ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700688 } else if(partialMDPComp(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700689 ret = true;
690 }
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530691
Saurabh Shahaa236822013-04-24 18:07:26 -0700692 return ret;
693}
694
695bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700696 //Will benefit presentation / secondary-only layer.
697 if((mDpy > HWC_DISPLAY_PRIMARY) &&
698 (list->numHwLayers - 1) > MAX_SEC_LAYERS) {
699 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
700 return false;
701 }
702
703 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
704 for(int i = 0; i < numAppLayers; i++) {
705 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran880da832014-04-18 10:22:35 -0700706 if(not mCurrentFrame.drop[i] and
707 not isSupportedForMDPComp(ctx, layer)) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700708 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",__FUNCTION__);
709 return false;
710 }
711 }
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800712
Saurabh Shahaa236822013-04-24 18:07:26 -0700713 mCurrentFrame.fbCount = 0;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700714 memcpy(&mCurrentFrame.isFBComposed, &mCurrentFrame.drop,
715 sizeof(mCurrentFrame.isFBComposed));
716 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount -
717 mCurrentFrame.dropCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700718
radhakrishnac9a67412013-09-25 17:40:42 +0530719 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800720 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530721 }
722
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800723 if(!postHeuristicsHandling(ctx, list)) {
724 ALOGD_IF(isDebug(), "post heuristic handling failed");
725 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700726 return false;
727 }
728
Saurabh Shahaa236822013-04-24 18:07:26 -0700729 return true;
730}
731
732bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
733{
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700734 if(!sEnableMixedMode) {
735 //Mixed mode is disabled. No need to even try caching.
736 return false;
737 }
738
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700739 bool ret = false;
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800740 if(list->flags & HWC_GEOMETRY_CHANGED) { //Try load based first
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800741 ret = loadBasedComp(ctx, list) or
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800742 cacheBasedComp(ctx, list);
743 } else {
744 ret = cacheBasedComp(ctx, list) or
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800745 loadBasedComp(ctx, list);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700746 }
747
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700748 return ret;
749}
750
751bool MDPComp::cacheBasedComp(hwc_context_t *ctx,
752 hwc_display_contents_1_t* list) {
753 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700754 mCurrentFrame.reset(numAppLayers);
755 updateLayerCache(ctx, list);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700756
757 //If an MDP marked layer is unsupported cannot do partial MDP Comp
758 for(int i = 0; i < numAppLayers; i++) {
759 if(!mCurrentFrame.isFBComposed[i]) {
760 hwc_layer_1_t* layer = &list->hwLayers[i];
761 if(not isSupportedForMDPComp(ctx, layer)) {
762 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",
763 __FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800764 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700765 return false;
766 }
767 }
768 }
769
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700770 updateYUV(ctx, list, false /*secure only*/);
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530771 bool ret = markLayersForCaching(ctx, list); //sets up fbZ also
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700772 if(!ret) {
773 ALOGD_IF(isDebug(),"%s: batching failed, dpy %d",__FUNCTION__, mDpy);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800774 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700775 return false;
776 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700777
778 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700779
radhakrishnac9a67412013-09-25 17:40:42 +0530780 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800781 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530782 }
783
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700784 //Will benefit cases where a video has non-updating background.
785 if((mDpy > HWC_DISPLAY_PRIMARY) and
786 (mdpCount > MAX_SEC_LAYERS)) {
787 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800788 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700789 return false;
790 }
791
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800792 if(!postHeuristicsHandling(ctx, list)) {
793 ALOGD_IF(isDebug(), "post heuristic handling failed");
794 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700795 return false;
796 }
797
Saurabh Shahaa236822013-04-24 18:07:26 -0700798 return true;
799}
800
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800801bool MDPComp::loadBasedComp(hwc_context_t *ctx,
Saurabh Shahb772ae32013-11-18 15:40:02 -0800802 hwc_display_contents_1_t* list) {
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -0800803 if(not isLoadBasedCompDoable(ctx)) {
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800804 return false;
805 }
806
Saurabh Shahb772ae32013-11-18 15:40:02 -0800807 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800808 const int numNonDroppedLayers = numAppLayers - mCurrentFrame.dropCount;
809 const int stagesForMDP = min(sMaxPipesPerMixer,
810 ctx->mOverlay->availablePipes(mDpy, Overlay::MIXER_DEFAULT));
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800811
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800812 int mdpBatchSize = stagesForMDP - 1; //1 stage for FB
813 int fbBatchSize = numNonDroppedLayers - mdpBatchSize;
814 int lastMDPSupportedIndex = numAppLayers;
815 int dropCount = 0;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800816
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800817 //Find the minimum MDP batch size
818 for(int i = 0; i < numAppLayers;i++) {
819 if(mCurrentFrame.drop[i]) {
820 dropCount++;
Jeykumar Sankaran846e2792014-01-23 21:59:58 -0800821 continue;
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800822 }
823 hwc_layer_1_t* layer = &list->hwLayers[i];
824 if(not isSupportedForMDPComp(ctx, layer)) {
825 lastMDPSupportedIndex = i;
826 mdpBatchSize = min(i - dropCount, stagesForMDP - 1);
827 fbBatchSize = numNonDroppedLayers - mdpBatchSize;
Jeykumar Sankaran846e2792014-01-23 21:59:58 -0800828 break;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800829 }
Saurabh Shahb772ae32013-11-18 15:40:02 -0800830 }
831
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800832 ALOGD_IF(isDebug(), "%s:Before optimizing fbBatch, mdpbatch %d, fbbatch %d "
833 "dropped %d", __FUNCTION__, mdpBatchSize, fbBatchSize,
834 mCurrentFrame.dropCount);
835
836 //Start at a point where the fb batch should at least have 2 layers, for
837 //this mode to be justified.
838 while(fbBatchSize < 2) {
839 ++fbBatchSize;
840 --mdpBatchSize;
Jeykumar Sankaran846e2792014-01-23 21:59:58 -0800841 }
Saurabh Shahb772ae32013-11-18 15:40:02 -0800842
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800843 //If there are no layers for MDP, this mode doesnt make sense.
844 if(mdpBatchSize < 1) {
845 ALOGD_IF(isDebug(), "%s: No MDP layers after optimizing for fbBatch",
846 __FUNCTION__);
Saurabh Shahb772ae32013-11-18 15:40:02 -0800847 return false;
848 }
849
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800850 mCurrentFrame.reset(numAppLayers);
851
852 //Try with successively smaller mdp batch sizes until we succeed or reach 1
853 while(mdpBatchSize > 0) {
854 //Mark layers for MDP comp
855 int mdpBatchLeft = mdpBatchSize;
856 for(int i = 0; i < lastMDPSupportedIndex and mdpBatchLeft; i++) {
857 if(mCurrentFrame.drop[i]) {
858 continue;
859 }
860 mCurrentFrame.isFBComposed[i] = false;
861 --mdpBatchLeft;
862 }
863
864 mCurrentFrame.fbZ = mdpBatchSize;
865 mCurrentFrame.fbCount = fbBatchSize;
866 mCurrentFrame.mdpCount = mdpBatchSize;
867
868 ALOGD_IF(isDebug(), "%s:Trying with: mdpbatch %d fbbatch %d dropped %d",
869 __FUNCTION__, mdpBatchSize, fbBatchSize,
870 mCurrentFrame.dropCount);
871
872 if(postHeuristicsHandling(ctx, list)) {
873 ALOGD_IF(isDebug(), "%s: Postheuristics handling succeeded",
874 __FUNCTION__);
875 return true;
876 }
877
878 reset(ctx);
879 --mdpBatchSize;
880 ++fbBatchSize;
881 }
882
883 return false;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800884}
885
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -0800886bool MDPComp::isLoadBasedCompDoable(hwc_context_t *ctx) {
Prabhanjan Kandula3dbbd882013-12-11 14:43:46 +0530887 if(mDpy or isSecurePresent(ctx, mDpy) or
888 isYuvPresent(ctx, mDpy)) {
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700889 return false;
890 }
891 return true;
892}
893
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800894bool MDPComp::canPartialUpdate(hwc_context_t *ctx,
895 hwc_display_contents_1_t* list){
896 if(!qdutils::MDPVersion::getInstance().isPartialUpdateEnabled() ||
897 isSkipPresent(ctx, mDpy) || (list->flags & HWC_GEOMETRY_CHANGED) ||
898 mDpy ) {
899 return false;
900 }
901 return true;
902}
903
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800904bool MDPComp::tryVideoOnly(hwc_context_t *ctx,
905 hwc_display_contents_1_t* list) {
906 const bool secureOnly = true;
907 return videoOnlyComp(ctx, list, not secureOnly) or
908 videoOnlyComp(ctx, list, secureOnly);
909}
910
911bool MDPComp::videoOnlyComp(hwc_context_t *ctx,
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700912 hwc_display_contents_1_t* list, bool secureOnly) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700913 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700914
Saurabh Shahaa236822013-04-24 18:07:26 -0700915 mCurrentFrame.reset(numAppLayers);
Jeykumar Sankaraneb3a5e22014-04-08 16:07:55 -0700916 mCurrentFrame.fbCount -= mCurrentFrame.dropCount;
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700917 updateYUV(ctx, list, secureOnly);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700918 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700919
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800920 if(!isYuvPresent(ctx, mDpy) or (mdpCount == 0)) {
921 reset(ctx);
Saurabh Shahaa236822013-04-24 18:07:26 -0700922 return false;
923 }
924
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -0800925 /* Bail out if we are processing only secured video layers
926 * and we dont have any */
927 if(!isSecurePresent(ctx, mDpy) && secureOnly){
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800928 reset(ctx);
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -0800929 return false;
930 }
931
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800932 if(mCurrentFrame.fbCount)
933 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
Saurabh Shah4fdde762013-04-30 18:47:33 -0700934
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800935 if(sEnable4k2kYUVSplit){
936 adjustForSourceSplit(ctx, list);
937 }
938
939 if(!postHeuristicsHandling(ctx, list)) {
940 ALOGD_IF(isDebug(), "post heuristic handling failed");
941 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700942 return false;
943 }
944
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800945 return true;
946}
947
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800948/* Checks for conditions where YUV layers cannot be bypassed */
949bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -0700950 if(isSkipLayer(layer)) {
Saurabh Shahe2474082013-05-15 16:32:13 -0700951 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800952 return false;
953 }
954
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700955 if(layer->transform & HWC_TRANSFORM_ROT_90 && !canUseRotator(ctx,mDpy)) {
956 ALOGD_IF(isDebug(), "%s: no free DMA pipe",__FUNCTION__);
957 return false;
958 }
959
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800960 if(isSecuring(ctx, layer)) {
961 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
962 return false;
963 }
964
Saurabh Shah4fdde762013-04-30 18:47:33 -0700965 if(!isValidDimension(ctx, layer)) {
966 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
967 __FUNCTION__);
968 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800969 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700970
Naseer Ahmeddc61a972013-07-10 17:50:54 -0400971 if(layer->planeAlpha < 0xFF) {
972 ALOGD_IF(isDebug(), "%s: Cannot handle YUV layer with plane alpha\
973 in video only mode",
974 __FUNCTION__);
975 return false;
976 }
977
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800978 return true;
979}
980
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530981/* starts at fromIndex and check for each layer to find
982 * if it it has overlapping with any Updating layer above it in zorder
983 * till the end of the batch. returns true if it finds any intersection */
984bool MDPComp::canPushBatchToTop(const hwc_display_contents_1_t* list,
985 int fromIndex, int toIndex) {
986 for(int i = fromIndex; i < toIndex; i++) {
987 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
988 if(intersectingUpdatingLayers(list, i+1, toIndex, i)) {
989 return false;
990 }
991 }
992 }
993 return true;
994}
995
996/* Checks if given layer at targetLayerIndex has any
997 * intersection with all the updating layers in beween
998 * fromIndex and toIndex. Returns true if it finds intersectiion */
999bool MDPComp::intersectingUpdatingLayers(const hwc_display_contents_1_t* list,
1000 int fromIndex, int toIndex, int targetLayerIndex) {
1001 for(int i = fromIndex; i <= toIndex; i++) {
1002 if(!mCurrentFrame.isFBComposed[i]) {
1003 if(areLayersIntersecting(&list->hwLayers[i],
1004 &list->hwLayers[targetLayerIndex])) {
1005 return true;
1006 }
1007 }
1008 }
1009 return false;
1010}
1011
1012int MDPComp::getBatch(hwc_display_contents_1_t* list,
1013 int& maxBatchStart, int& maxBatchEnd,
1014 int& maxBatchCount) {
1015 int i = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301016 int fbZOrder =-1;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -08001017 int droppedLayerCt = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301018 while (i < mCurrentFrame.layerCount) {
1019 int batchCount = 0;
1020 int batchStart = i;
1021 int batchEnd = i;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -08001022 /* Adjust batch Z order with the dropped layers so far */
1023 int fbZ = batchStart - droppedLayerCt;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301024 int firstZReverseIndex = -1;
Prabhanjan Kandula0ed2cc92013-12-06 12:39:04 +05301025 int updatingLayersAbove = 0;//Updating layer count in middle of batch
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301026 while(i < mCurrentFrame.layerCount) {
1027 if(!mCurrentFrame.isFBComposed[i]) {
1028 if(!batchCount) {
1029 i++;
1030 break;
1031 }
1032 updatingLayersAbove++;
1033 i++;
1034 continue;
1035 } else {
1036 if(mCurrentFrame.drop[i]) {
1037 i++;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -08001038 droppedLayerCt++;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301039 continue;
1040 } else if(updatingLayersAbove <= 0) {
1041 batchCount++;
1042 batchEnd = i;
1043 i++;
1044 continue;
1045 } else { //Layer is FBComposed, not a drop & updatingLayer > 0
1046
1047 // We have a valid updating layer already. If layer-i not
1048 // have overlapping with all updating layers in between
1049 // batch-start and i, then we can add layer i to batch.
1050 if(!intersectingUpdatingLayers(list, batchStart, i-1, i)) {
1051 batchCount++;
1052 batchEnd = i;
1053 i++;
1054 continue;
1055 } else if(canPushBatchToTop(list, batchStart, i)) {
1056 //If All the non-updating layers with in this batch
1057 //does not have intersection with the updating layers
1058 //above in z-order, then we can safely move the batch to
1059 //higher z-order. Increment fbZ as it is moving up.
1060 if( firstZReverseIndex < 0) {
1061 firstZReverseIndex = i;
1062 }
1063 batchCount++;
1064 batchEnd = i;
1065 fbZ += updatingLayersAbove;
1066 i++;
1067 updatingLayersAbove = 0;
1068 continue;
1069 } else {
1070 //both failed.start the loop again from here.
1071 if(firstZReverseIndex >= 0) {
1072 i = firstZReverseIndex;
1073 }
1074 break;
1075 }
1076 }
1077 }
1078 }
1079 if(batchCount > maxBatchCount) {
1080 maxBatchCount = batchCount;
1081 maxBatchStart = batchStart;
1082 maxBatchEnd = batchEnd;
1083 fbZOrder = fbZ;
1084 }
1085 }
1086 return fbZOrder;
1087}
1088
1089bool MDPComp::markLayersForCaching(hwc_context_t* ctx,
1090 hwc_display_contents_1_t* list) {
1091 /* Idea is to keep as many non-updating(cached) layers in FB and
1092 * send rest of them through MDP. This is done in 2 steps.
1093 * 1. Find the maximum contiguous batch of non-updating layers.
1094 * 2. See if we can improve this batch size for caching by adding
1095 * opaque layers around the batch, if they don't have
1096 * any overlapping with the updating layers in between.
1097 * NEVER mark an updating layer for caching.
1098 * But cached ones can be marked for MDP */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001099
1100 int maxBatchStart = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001101 int maxBatchEnd = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001102 int maxBatchCount = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301103 int fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001104
Saurabh Shahd53bc5f2014-02-05 10:17:43 -08001105 /* Nothing is cached. No batching needed */
1106 if(mCurrentFrame.fbCount == 0) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001107 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -07001108 }
Saurabh Shahd53bc5f2014-02-05 10:17:43 -08001109
1110 /* No MDP comp layers, try to use other comp modes */
1111 if(mCurrentFrame.mdpCount == 0) {
1112 return false;
Saurabh Shahaa236822013-04-24 18:07:26 -07001113 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001114
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301115 fbZ = getBatch(list, maxBatchStart, maxBatchEnd, maxBatchCount);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001116
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301117 /* reset rest of the layers lying inside ROI for MDP comp */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001118 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001119 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001120 if((i < maxBatchStart || i > maxBatchEnd) &&
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301121 mCurrentFrame.isFBComposed[i]){
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001122 if(!mCurrentFrame.drop[i]){
1123 //If an unsupported layer is being attempted to
1124 //be pulled out we should fail
1125 if(not isSupportedForMDPComp(ctx, layer)) {
1126 return false;
1127 }
1128 mCurrentFrame.isFBComposed[i] = false;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001129 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001130 }
1131 }
1132
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301133 // update the frame data
1134 mCurrentFrame.fbZ = fbZ;
1135 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001136 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001137 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001138
1139 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301140 mCurrentFrame.fbCount);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001141
1142 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001143}
Saurabh Shah85234ec2013-04-12 17:09:00 -07001144
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001145void MDPComp::updateLayerCache(hwc_context_t* ctx,
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001146 hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001147 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001148 int fbCount = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001149
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001150 for(int i = 0; i < numAppLayers; i++) {
1151 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001152 if(!mCurrentFrame.drop[i])
1153 fbCount++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001154 mCurrentFrame.isFBComposed[i] = true;
1155 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -07001156 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001157 }
1158 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001159
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001160 mCurrentFrame.fbCount = fbCount;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001161 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount
1162 - mCurrentFrame.dropCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001163
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001164 ALOGD_IF(isDebug(),"%s: MDP count: %d FB count %d drop count: %d"
1165 ,__FUNCTION__, mCurrentFrame.mdpCount, mCurrentFrame.fbCount,
1166 mCurrentFrame.dropCount);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001167}
1168
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001169void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list,
1170 bool secureOnly) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001171 int nYuvCount = ctx->listStats[mDpy].yuvCount;
1172 for(int index = 0;index < nYuvCount; index++){
1173 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
1174 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
1175
1176 if(!isYUVDoable(ctx, layer)) {
1177 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
1178 mCurrentFrame.isFBComposed[nYuvIndex] = true;
1179 mCurrentFrame.fbCount++;
1180 }
1181 } else {
1182 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001183 private_handle_t *hnd = (private_handle_t *)layer->handle;
1184 if(!secureOnly || isSecureBuffer(hnd)) {
1185 mCurrentFrame.isFBComposed[nYuvIndex] = false;
1186 mCurrentFrame.fbCount--;
1187 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001188 }
1189 }
1190 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001191
1192 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001193 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
1194 ALOGD_IF(isDebug(),"%s: fb count: %d",__FUNCTION__,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001195 mCurrentFrame.fbCount);
1196}
1197
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001198hwc_rect_t MDPComp::getUpdatingFBRect(hwc_context_t *ctx,
1199 hwc_display_contents_1_t* list){
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001200 hwc_rect_t fbRect = (struct hwc_rect){0, 0, 0, 0};
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001201
1202 /* Update only the region of FB needed for composition */
1203 for(int i = 0; i < mCurrentFrame.layerCount; i++ ) {
1204 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
1205 hwc_layer_1_t* layer = &list->hwLayers[i];
1206 hwc_rect_t dst = layer->displayFrame;
1207 fbRect = getUnion(fbRect, dst);
1208 }
1209 }
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001210 trimAgainstROI(ctx, fbRect);
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001211 return fbRect;
1212}
1213
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001214bool MDPComp::postHeuristicsHandling(hwc_context_t *ctx,
1215 hwc_display_contents_1_t* list) {
1216
1217 //Capability checks
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301218 if(!resourceCheck()) {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001219 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
1220 return false;
1221 }
1222
1223 //Limitations checks
1224 if(!hwLimitationsCheck(ctx, list)) {
1225 ALOGD_IF(isDebug(), "%s: HW limitations",__FUNCTION__);
1226 return false;
1227 }
1228
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001229 //Configure framebuffer first if applicable
1230 if(mCurrentFrame.fbZ >= 0) {
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001231 hwc_rect_t fbRect = getUpdatingFBRect(ctx, list);
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001232 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, fbRect, mCurrentFrame.fbZ))
1233 {
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001234 ALOGD_IF(isDebug(), "%s configure framebuffer failed",
1235 __FUNCTION__);
1236 return false;
1237 }
1238 }
1239
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001240 mCurrentFrame.map();
1241
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001242 if(!allocLayerPipes(ctx, list)) {
1243 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -07001244 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001245 }
1246
1247 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001248 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001249 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001250 int mdpIndex = mCurrentFrame.layerToMDP[index];
1251 hwc_layer_1_t* layer = &list->hwLayers[index];
1252
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301253 //Leave fbZ for framebuffer. CACHE/GLES layers go here.
1254 if(mdpNextZOrder == mCurrentFrame.fbZ) {
1255 mdpNextZOrder++;
1256 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001257 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1258 cur_pipe->zOrder = mdpNextZOrder++;
1259
radhakrishnac9a67412013-09-25 17:40:42 +05301260 private_handle_t *hnd = (private_handle_t *)layer->handle;
1261 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1262 if(configure4k2kYuv(ctx, layer,
1263 mCurrentFrame.mdpToLayer[mdpIndex])
1264 != 0 ){
1265 ALOGD_IF(isDebug(), "%s: Failed to configure split pipes \
1266 for layer %d",__FUNCTION__, index);
1267 return false;
1268 }
1269 else{
1270 mdpNextZOrder++;
1271 }
1272 continue;
1273 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001274 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
1275 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
radhakrishnac9a67412013-09-25 17:40:42 +05301276 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -07001277 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001278 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001279 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001280 }
1281
Saurabh Shaha36be922013-12-16 18:18:39 -08001282 if(!ctx->mOverlay->validateAndSet(mDpy, ctx->dpyAttr[mDpy].fd)) {
1283 ALOGD_IF(isDebug(), "%s: Failed to validate and set overlay for dpy %d"
1284 ,__FUNCTION__, mDpy);
1285 return false;
1286 }
1287
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001288 setRedraw(ctx, list);
Saurabh Shahaa236822013-04-24 18:07:26 -07001289 return true;
1290}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001291
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301292bool MDPComp::resourceCheck() {
Saurabh Shah173f4242013-11-20 09:50:12 -08001293 const bool fbUsed = mCurrentFrame.fbCount;
1294 if(mCurrentFrame.mdpCount > sMaxPipesPerMixer - fbUsed) {
1295 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
1296 return false;
1297 }
Saurabh Shah173f4242013-11-20 09:50:12 -08001298 return true;
1299}
1300
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301301bool MDPComp::hwLimitationsCheck(hwc_context_t* ctx,
1302 hwc_display_contents_1_t* list) {
1303
1304 //A-family hw limitation:
1305 //If a layer need alpha scaling, MDP can not support.
1306 if(ctx->mMDP.version < qdutils::MDSS_V5) {
1307 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1308 if(!mCurrentFrame.isFBComposed[i] &&
1309 isAlphaScaled( &list->hwLayers[i])) {
1310 ALOGD_IF(isDebug(), "%s:frame needs alphaScaling",__FUNCTION__);
1311 return false;
1312 }
1313 }
1314 }
1315
1316 // On 8x26 & 8974 hw, we have a limitation of downscaling+blending.
1317 //If multiple layers requires downscaling and also they are overlapping
1318 //fall back to GPU since MDSS can not handle it.
1319 if(qdutils::MDPVersion::getInstance().is8x74v2() ||
1320 qdutils::MDPVersion::getInstance().is8x26()) {
1321 for(int i = 0; i < mCurrentFrame.layerCount-1; ++i) {
1322 hwc_layer_1_t* botLayer = &list->hwLayers[i];
1323 if(!mCurrentFrame.isFBComposed[i] &&
1324 isDownscaleRequired(botLayer)) {
1325 //if layer-i is marked for MDP and needs downscaling
1326 //check if any MDP layer on top of i & overlaps with layer-i
1327 for(int j = i+1; j < mCurrentFrame.layerCount; ++j) {
1328 hwc_layer_1_t* topLayer = &list->hwLayers[j];
1329 if(!mCurrentFrame.isFBComposed[j] &&
1330 isDownscaleRequired(topLayer)) {
1331 hwc_rect_t r = getIntersection(botLayer->displayFrame,
1332 topLayer->displayFrame);
1333 if(isValidRect(r))
1334 return false;
1335 }
1336 }
1337 }
1338 }
1339 }
1340 return true;
1341}
1342
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001343int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001344 int ret = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -07001345 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -07001346
Raj Kamal9ed3d6b2014-02-07 16:15:17 +05301347 //Do not cache the information for next draw cycle.
1348 if(numLayers > MAX_NUM_APP_LAYERS or (!numLayers)) {
1349 ALOGI("%s: Unsupported layer count for mdp composition",
1350 __FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001351 mCachedFrame.reset();
1352 return -1;
1353 }
1354
Saurabh Shahb39f8152013-08-22 10:21:44 -07001355 //reset old data
1356 mCurrentFrame.reset(numLayers);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001357 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1358 mCurrentFrame.dropCount = 0;
Prabhanjan Kandula088bd892013-07-02 23:47:13 +05301359
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -07001360 // Detect the start of animation and fall back to GPU only once to cache
1361 // all the layers in FB and display FB content untill animation completes.
1362 if(ctx->listStats[mDpy].isDisplayAnimating) {
1363 mCurrentFrame.needsRedraw = false;
1364 if(ctx->mAnimationState[mDpy] == ANIMATION_STOPPED) {
1365 mCurrentFrame.needsRedraw = true;
1366 ctx->mAnimationState[mDpy] = ANIMATION_STARTED;
1367 }
1368 setMDPCompLayerFlags(ctx, list);
1369 mCachedFrame.updateCounts(mCurrentFrame);
1370 ret = -1;
1371 return ret;
1372 } else {
1373 ctx->mAnimationState[mDpy] = ANIMATION_STOPPED;
1374 }
1375
Saurabh Shahb39f8152013-08-22 10:21:44 -07001376 //Hard conditions, if not met, cannot do MDP comp
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001377 if(isFrameDoable(ctx)) {
1378 generateROI(ctx, list);
Saurabh Shahb39f8152013-08-22 10:21:44 -07001379
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001380 if(tryFullFrame(ctx, list) || tryVideoOnly(ctx, list)) {
1381 setMDPCompLayerFlags(ctx, list);
1382 } else {
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001383 resetROI(ctx, mDpy);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001384 reset(ctx);
1385 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1386 mCurrentFrame.dropCount = 0;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001387 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001388 }
1389 } else {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001390 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
1391 __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001392 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001393 }
Saurabh Shahb39f8152013-08-22 10:21:44 -07001394
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001395 if(isDebug()) {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001396 ALOGD("GEOMETRY change: %d",
1397 (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001398 android::String8 sDump("");
1399 dump(sDump);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001400 ALOGD("%s",sDump.string());
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001401 }
1402
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001403 mCachedFrame.cacheAll(list);
1404 mCachedFrame.updateCounts(mCurrentFrame);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001405 return ret;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001406}
1407
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001408bool MDPComp::allocSplitVGPipesfor4k2k(hwc_context_t *ctx, int index) {
radhakrishnac9a67412013-09-25 17:40:42 +05301409
1410 bool bRet = true;
radhakrishnac9a67412013-09-25 17:40:42 +05301411 int mdpIndex = mCurrentFrame.layerToMDP[index];
1412 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
1413 info.pipeInfo = new MdpYUVPipeInfo;
1414 info.rot = NULL;
1415 MdpYUVPipeInfo& pipe_info = *(MdpYUVPipeInfo*)info.pipeInfo;
radhakrishnac9a67412013-09-25 17:40:42 +05301416
1417 pipe_info.lIndex = ovutils::OV_INVALID;
1418 pipe_info.rIndex = ovutils::OV_INVALID;
1419
Saurabh Shahc62f3982014-03-05 14:28:26 -08001420 Overlay::PipeSpecs pipeSpecs;
1421 pipeSpecs.formatClass = Overlay::FORMAT_YUV;
1422 pipeSpecs.needsScaling = true;
1423 pipeSpecs.dpy = mDpy;
1424 pipeSpecs.fb = false;
1425
1426 pipe_info.lIndex = ctx->mOverlay->getPipe(pipeSpecs);
radhakrishnac9a67412013-09-25 17:40:42 +05301427 if(pipe_info.lIndex == ovutils::OV_INVALID){
1428 bRet = false;
1429 ALOGD_IF(isDebug(),"%s: allocating first VG pipe failed",
1430 __FUNCTION__);
1431 }
Saurabh Shahc62f3982014-03-05 14:28:26 -08001432 pipe_info.rIndex = ctx->mOverlay->getPipe(pipeSpecs);
radhakrishnac9a67412013-09-25 17:40:42 +05301433 if(pipe_info.rIndex == ovutils::OV_INVALID){
1434 bRet = false;
1435 ALOGD_IF(isDebug(),"%s: allocating second VG pipe failed",
1436 __FUNCTION__);
1437 }
1438 return bRet;
1439}
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001440//=============MDPCompNonSplit==================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001441
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001442void MDPCompNonSplit::adjustForSourceSplit(hwc_context_t *ctx,
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001443 hwc_display_contents_1_t*) {
radhakrishnac9a67412013-09-25 17:40:42 +05301444 //As we split 4kx2k yuv layer and program to 2 VG pipes
1445 //(if available) increase mdpcount accordingly
1446 mCurrentFrame.mdpCount += ctx->listStats[mDpy].yuv4k2kCount;
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001447
1448 //If 4k2k Yuv layer split is possible, and if
1449 //fbz is above 4k2k layer, increment fb zorder by 1
1450 //as we split 4k2k layer and increment zorder for right half
1451 //of the layer
1452 if(mCurrentFrame.fbZ >= 0) {
1453 int n4k2kYuvCount = ctx->listStats[mDpy].yuv4k2kCount;
1454 for(int index = 0; index < n4k2kYuvCount; index++){
1455 int n4k2kYuvIndex =
1456 ctx->listStats[mDpy].yuv4k2kIndices[index];
Dileep Kumar Reddi4cff9282014-04-01 12:57:08 +05301457 if(mCurrentFrame.fbZ >= n4k2kYuvIndex){
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001458 mCurrentFrame.fbZ += 1;
1459 }
1460 }
1461 }
radhakrishnac9a67412013-09-25 17:40:42 +05301462}
1463
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001464/*
1465 * Configures pipe(s) for MDP composition
1466 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001467int MDPCompNonSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001468 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001469 MdpPipeInfoNonSplit& mdp_info =
1470 *(static_cast<MdpPipeInfoNonSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001471 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
1472 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1473 eIsFg isFg = IS_FG_OFF;
1474 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001475
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001476 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
1477 __FUNCTION__, layer, zOrder, dest);
1478
Saurabh Shah88e4d272013-09-03 13:31:29 -07001479 return configureNonSplit(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001480 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001481}
1482
Saurabh Shah88e4d272013-09-03 13:31:29 -07001483bool MDPCompNonSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001484 hwc_display_contents_1_t* list) {
1485 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001486
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001487 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001488
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001489 hwc_layer_1_t* layer = &list->hwLayers[index];
1490 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301491 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001492 if(allocSplitVGPipesfor4k2k(ctx, index)){
radhakrishnac9a67412013-09-25 17:40:42 +05301493 continue;
1494 }
1495 }
1496
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001497 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001498 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001499 info.pipeInfo = new MdpPipeInfoNonSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08001500 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001501 MdpPipeInfoNonSplit& pipe_info = *(MdpPipeInfoNonSplit*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001502
Saurabh Shahc62f3982014-03-05 14:28:26 -08001503 Overlay::PipeSpecs pipeSpecs;
1504 pipeSpecs.formatClass = isYuvBuffer(hnd) ?
1505 Overlay::FORMAT_YUV : Overlay::FORMAT_RGB;
1506 pipeSpecs.needsScaling = qhwc::needsScaling(layer) or
1507 (qdutils::MDPVersion::getInstance().is8x26() and
1508 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres > 1024);
1509 pipeSpecs.dpy = mDpy;
1510 pipeSpecs.fb = false;
Xu Yang1e686f62014-04-08 13:56:47 +08001511 pipeSpecs.numActiveDisplays = ctx->numActiveDisplays;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001512
Saurabh Shahc62f3982014-03-05 14:28:26 -08001513 pipe_info.index = ctx->mOverlay->getPipe(pipeSpecs);
1514
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001515 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001516 ALOGD_IF(isDebug(), "%s: Unable to get pipe", __FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001517 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001518 }
1519 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001520 return true;
1521}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001522
radhakrishnac9a67412013-09-25 17:40:42 +05301523int MDPCompNonSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1524 PipeLayerPair& PipeLayerPair) {
1525 MdpYUVPipeInfo& mdp_info =
1526 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1527 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1528 eIsFg isFg = IS_FG_OFF;
1529 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1530 eDest lDest = mdp_info.lIndex;
1531 eDest rDest = mdp_info.rIndex;
1532
1533 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1534 lDest, rDest, &PipeLayerPair.rot);
1535}
1536
Saurabh Shah88e4d272013-09-03 13:31:29 -07001537bool MDPCompNonSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001538
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001539 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001540 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1541 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -08001542 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001543
1544 if(!ctx || !list) {
1545 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001546 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001547 }
1548
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301549 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1550 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1551 return true;
1552 }
1553
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -08001554 // Set the Handle timeout to true for MDP or MIXED composition.
1555 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount) {
1556 sHandleTimeout = true;
1557 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001558
1559 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001560 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001561
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001562 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1563 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001564 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001565 if(mCurrentFrame.isFBComposed[i]) continue;
1566
Naseer Ahmed5b6708a2012-08-02 13:46:08 -07001567 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001568 private_handle_t *hnd = (private_handle_t *)layer->handle;
1569 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001570 if (!(layer->flags & HWC_COLOR_FILL)) {
1571 ALOGE("%s handle null", __FUNCTION__);
1572 return false;
1573 }
1574 // No PLAY for Color layer
1575 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1576 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001577 }
1578
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001579 int mdpIndex = mCurrentFrame.layerToMDP[i];
1580
radhakrishnac9a67412013-09-25 17:40:42 +05301581 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1582 {
1583 MdpYUVPipeInfo& pipe_info =
1584 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1585 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1586 ovutils::eDest indexL = pipe_info.lIndex;
1587 ovutils::eDest indexR = pipe_info.rIndex;
1588 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301589 uint32_t offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05301590 if(rot) {
1591 rot->queueBuffer(fd, offset);
1592 fd = rot->getDstMemId();
1593 offset = rot->getDstOffset();
1594 }
1595 if(indexL != ovutils::OV_INVALID) {
1596 ovutils::eDest destL = (ovutils::eDest)indexL;
1597 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1598 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1599 if (!ov.queueBuffer(fd, offset, destL)) {
1600 ALOGE("%s: queueBuffer failed for display:%d",
1601 __FUNCTION__, mDpy);
1602 return false;
1603 }
1604 }
1605
1606 if(indexR != ovutils::OV_INVALID) {
1607 ovutils::eDest destR = (ovutils::eDest)indexR;
1608 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1609 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1610 if (!ov.queueBuffer(fd, offset, destR)) {
1611 ALOGE("%s: queueBuffer failed for display:%d",
1612 __FUNCTION__, mDpy);
1613 return false;
1614 }
1615 }
1616 }
1617 else{
1618 MdpPipeInfoNonSplit& pipe_info =
Saurabh Shah88e4d272013-09-03 13:31:29 -07001619 *(MdpPipeInfoNonSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
radhakrishnac9a67412013-09-25 17:40:42 +05301620 ovutils::eDest dest = pipe_info.index;
1621 if(dest == ovutils::OV_INVALID) {
1622 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001623 return false;
radhakrishnac9a67412013-09-25 17:40:42 +05301624 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001625
radhakrishnac9a67412013-09-25 17:40:42 +05301626 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1627 continue;
1628 }
1629
1630 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1631 using pipe: %d", __FUNCTION__, layer,
1632 hnd, dest );
1633
1634 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301635 uint32_t offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05301636
1637 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1638 if(rot) {
1639 if(!rot->queueBuffer(fd, offset))
1640 return false;
1641 fd = rot->getDstMemId();
1642 offset = rot->getDstOffset();
1643 }
1644
1645 if (!ov.queueBuffer(fd, offset, dest)) {
1646 ALOGE("%s: queueBuffer failed for display:%d ",
1647 __FUNCTION__, mDpy);
1648 return false;
1649 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001650 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001651
1652 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001653 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001654 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001655}
1656
Saurabh Shah88e4d272013-09-03 13:31:29 -07001657//=============MDPCompSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001658
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001659void MDPCompSplit::adjustForSourceSplit(hwc_context_t *ctx,
radhakrishnac9a67412013-09-25 17:40:42 +05301660 hwc_display_contents_1_t* list){
1661 //if 4kx2k yuv layer is totally present in either in left half
1662 //or right half then try splitting the yuv layer to avoid decimation
1663 int n4k2kYuvCount = ctx->listStats[mDpy].yuv4k2kCount;
1664 const int lSplit = getLeftSplit(ctx, mDpy);
1665 for(int index = 0; index < n4k2kYuvCount; index++){
1666 int n4k2kYuvIndex = ctx->listStats[mDpy].yuv4k2kIndices[index];
1667 hwc_layer_1_t* layer = &list->hwLayers[n4k2kYuvIndex];
1668 hwc_rect_t dst = layer->displayFrame;
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001669 if((dst.left > lSplit) || (dst.right < lSplit)) {
radhakrishnac9a67412013-09-25 17:40:42 +05301670 mCurrentFrame.mdpCount += 1;
1671 }
Dileep Kumar Reddi4cff9282014-04-01 12:57:08 +05301672 if(mCurrentFrame.fbZ >= n4k2kYuvIndex){
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001673 mCurrentFrame.fbZ += 1;
1674 }
radhakrishnac9a67412013-09-25 17:40:42 +05301675 }
1676}
1677
Saurabh Shah88e4d272013-09-03 13:31:29 -07001678bool MDPCompSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Saurabh Shahc62f3982014-03-05 14:28:26 -08001679 MdpPipeInfoSplit& pipe_info) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001680
Saurabh Shahc62f3982014-03-05 14:28:26 -08001681 const int lSplit = getLeftSplit(ctx, mDpy);
1682 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001683 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001684 pipe_info.lIndex = ovutils::OV_INVALID;
1685 pipe_info.rIndex = ovutils::OV_INVALID;
1686
Saurabh Shahc62f3982014-03-05 14:28:26 -08001687 Overlay::PipeSpecs pipeSpecs;
1688 pipeSpecs.formatClass = isYuvBuffer(hnd) ?
1689 Overlay::FORMAT_YUV : Overlay::FORMAT_RGB;
1690 pipeSpecs.needsScaling = qhwc::needsScalingWithSplit(ctx, layer, mDpy);
1691 pipeSpecs.dpy = mDpy;
1692 pipeSpecs.mixer = Overlay::MIXER_LEFT;
1693 pipeSpecs.fb = false;
1694
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001695 // Acquire pipe only for the updating half
1696 hwc_rect_t l_roi = ctx->listStats[mDpy].lRoi;
1697 hwc_rect_t r_roi = ctx->listStats[mDpy].rRoi;
1698
1699 if (dst.left < lSplit && isValidRect(getIntersection(dst, l_roi))) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001700 pipe_info.lIndex = ctx->mOverlay->getPipe(pipeSpecs);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001701 if(pipe_info.lIndex == ovutils::OV_INVALID)
1702 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001703 }
1704
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001705 if(dst.right > lSplit && isValidRect(getIntersection(dst, r_roi))) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001706 pipeSpecs.mixer = Overlay::MIXER_RIGHT;
1707 pipe_info.rIndex = ctx->mOverlay->getPipe(pipeSpecs);
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001708 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001709 return false;
1710 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001711
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001712 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001713}
1714
Saurabh Shah88e4d272013-09-03 13:31:29 -07001715bool MDPCompSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001716 hwc_display_contents_1_t* list) {
1717 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001718
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001719 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001720
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001721 hwc_layer_1_t* layer = &list->hwLayers[index];
1722 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301723 hwc_rect_t dst = layer->displayFrame;
1724 const int lSplit = getLeftSplit(ctx, mDpy);
1725 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1726 if((dst.left > lSplit)||(dst.right < lSplit)){
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001727 if(allocSplitVGPipesfor4k2k(ctx, index)){
radhakrishnac9a67412013-09-25 17:40:42 +05301728 continue;
1729 }
1730 }
1731 }
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001732 int mdpIndex = mCurrentFrame.layerToMDP[index];
1733 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001734 info.pipeInfo = new MdpPipeInfoSplit;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001735 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001736 MdpPipeInfoSplit& pipe_info = *(MdpPipeInfoSplit*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001737
Saurabh Shahc62f3982014-03-05 14:28:26 -08001738 if(!acquireMDPPipes(ctx, layer, pipe_info)) {
1739 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type",
1740 __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001741 return false;
1742 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001743 }
1744 return true;
1745}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001746
radhakrishnac9a67412013-09-25 17:40:42 +05301747int MDPCompSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1748 PipeLayerPair& PipeLayerPair) {
1749 const int lSplit = getLeftSplit(ctx, mDpy);
1750 hwc_rect_t dst = layer->displayFrame;
1751 if((dst.left > lSplit)||(dst.right < lSplit)){
1752 MdpYUVPipeInfo& mdp_info =
1753 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1754 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1755 eIsFg isFg = IS_FG_OFF;
1756 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1757 eDest lDest = mdp_info.lIndex;
1758 eDest rDest = mdp_info.rIndex;
1759
1760 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1761 lDest, rDest, &PipeLayerPair.rot);
1762 }
1763 else{
1764 return configure(ctx, layer, PipeLayerPair);
1765 }
1766}
1767
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001768/*
1769 * Configures pipe(s) for MDP composition
1770 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001771int MDPCompSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001772 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001773 MdpPipeInfoSplit& mdp_info =
1774 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001775 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1776 eIsFg isFg = IS_FG_OFF;
1777 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1778 eDest lDest = mdp_info.lIndex;
1779 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001780
1781 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1782 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1783
Saurabh Shah88e4d272013-09-03 13:31:29 -07001784 return configureSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001785 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001786}
1787
Saurabh Shah88e4d272013-09-03 13:31:29 -07001788bool MDPCompSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001789
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001790 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001791 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1792 return true;
1793 }
1794
1795 if(!ctx || !list) {
1796 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001797 return false;
1798 }
1799
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301800 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1801 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1802 return true;
1803 }
1804
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -08001805 // Set the Handle timeout to true for MDP or MIXED composition.
1806 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount) {
1807 sHandleTimeout = true;
1808 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001809
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001810 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001811 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001812
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001813 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1814 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001815 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001816 if(mCurrentFrame.isFBComposed[i]) continue;
1817
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001818 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001819 private_handle_t *hnd = (private_handle_t *)layer->handle;
1820 if(!hnd) {
1821 ALOGE("%s handle null", __FUNCTION__);
1822 return false;
1823 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001824
1825 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1826 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001827 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001828
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001829 int mdpIndex = mCurrentFrame.layerToMDP[i];
1830
radhakrishnac9a67412013-09-25 17:40:42 +05301831 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1832 {
1833 MdpYUVPipeInfo& pipe_info =
1834 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1835 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1836 ovutils::eDest indexL = pipe_info.lIndex;
1837 ovutils::eDest indexR = pipe_info.rIndex;
1838 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301839 uint32_t offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05301840 if(rot) {
1841 rot->queueBuffer(fd, offset);
1842 fd = rot->getDstMemId();
1843 offset = rot->getDstOffset();
1844 }
1845 if(indexL != ovutils::OV_INVALID) {
1846 ovutils::eDest destL = (ovutils::eDest)indexL;
1847 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1848 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1849 if (!ov.queueBuffer(fd, offset, destL)) {
1850 ALOGE("%s: queueBuffer failed for display:%d",
1851 __FUNCTION__, mDpy);
1852 return false;
1853 }
1854 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001855
radhakrishnac9a67412013-09-25 17:40:42 +05301856 if(indexR != ovutils::OV_INVALID) {
1857 ovutils::eDest destR = (ovutils::eDest)indexR;
1858 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1859 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1860 if (!ov.queueBuffer(fd, offset, destR)) {
1861 ALOGE("%s: queueBuffer failed for display:%d",
1862 __FUNCTION__, mDpy);
1863 return false;
1864 }
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001865 }
1866 }
radhakrishnac9a67412013-09-25 17:40:42 +05301867 else{
1868 MdpPipeInfoSplit& pipe_info =
1869 *(MdpPipeInfoSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1870 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001871
radhakrishnac9a67412013-09-25 17:40:42 +05301872 ovutils::eDest indexL = pipe_info.lIndex;
1873 ovutils::eDest indexR = pipe_info.rIndex;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001874
radhakrishnac9a67412013-09-25 17:40:42 +05301875 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301876 int offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05301877
1878 if(ctx->mAD->isModeOn()) {
1879 if(ctx->mAD->draw(ctx, fd, offset)) {
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001880 fd = ctx->mAD->getDstFd();
1881 offset = ctx->mAD->getDstOffset();
radhakrishnac9a67412013-09-25 17:40:42 +05301882 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001883 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001884
radhakrishnac9a67412013-09-25 17:40:42 +05301885 if(rot) {
1886 rot->queueBuffer(fd, offset);
1887 fd = rot->getDstMemId();
1888 offset = rot->getDstOffset();
1889 }
1890
1891 //************* play left mixer **********
1892 if(indexL != ovutils::OV_INVALID) {
1893 ovutils::eDest destL = (ovutils::eDest)indexL;
1894 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1895 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1896 if (!ov.queueBuffer(fd, offset, destL)) {
1897 ALOGE("%s: queueBuffer failed for left mixer",
1898 __FUNCTION__);
1899 return false;
1900 }
1901 }
1902
1903 //************* play right mixer **********
1904 if(indexR != ovutils::OV_INVALID) {
1905 ovutils::eDest destR = (ovutils::eDest)indexR;
1906 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1907 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1908 if (!ov.queueBuffer(fd, offset, destR)) {
1909 ALOGE("%s: queueBuffer failed for right mixer",
1910 __FUNCTION__);
1911 return false;
1912 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001913 }
1914 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001915
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001916 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1917 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001918
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001919 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001920}
Saurabh Shahab47c692014-02-12 18:45:57 -08001921
1922//================MDPCompSrcSplit==============================================
1923bool MDPCompSrcSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Saurabh Shahc62f3982014-03-05 14:28:26 -08001924 MdpPipeInfoSplit& pipe_info) {
Saurabh Shahab47c692014-02-12 18:45:57 -08001925 private_handle_t *hnd = (private_handle_t *)layer->handle;
1926 hwc_rect_t dst = layer->displayFrame;
1927 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
1928 pipe_info.lIndex = ovutils::OV_INVALID;
1929 pipe_info.rIndex = ovutils::OV_INVALID;
1930
1931 //If 2 pipes are staged on a single stage of a mixer, then the left pipe
1932 //should have a higher priority than the right one. Pipe priorities are
1933 //starting with VG0, VG1 ... , RGB0 ..., DMA1
Saurabh Shahab47c692014-02-12 18:45:57 -08001934
Saurabh Shahc62f3982014-03-05 14:28:26 -08001935 Overlay::PipeSpecs pipeSpecs;
1936 pipeSpecs.formatClass = isYuvBuffer(hnd) ?
1937 Overlay::FORMAT_YUV : Overlay::FORMAT_RGB;
1938 pipeSpecs.needsScaling = qhwc::needsScaling(layer);
1939 pipeSpecs.dpy = mDpy;
1940 pipeSpecs.fb = false;
1941
Saurabh Shahab47c692014-02-12 18:45:57 -08001942 //1 pipe by default for a layer
Saurabh Shahc62f3982014-03-05 14:28:26 -08001943 pipe_info.lIndex = ctx->mOverlay->getPipe(pipeSpecs);
Saurabh Shahab47c692014-02-12 18:45:57 -08001944 if(pipe_info.lIndex == ovutils::OV_INVALID) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001945 return false;
Saurabh Shahab47c692014-02-12 18:45:57 -08001946 }
1947
1948 //If layer's crop width or dest width > 2048, use 2 pipes
1949 if((dst.right - dst.left) > qdutils::MAX_DISPLAY_DIM or
1950 (crop.right - crop.left) > qdutils::MAX_DISPLAY_DIM) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001951 pipe_info.rIndex = ctx->mOverlay->getPipe(pipeSpecs);
Saurabh Shahab47c692014-02-12 18:45:57 -08001952 if(pipe_info.rIndex == ovutils::OV_INVALID) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001953 return false;
Saurabh Shahdd8237a2014-02-28 14:29:09 -08001954 }
1955
1956 // Return values
1957 // 1 Left pipe is higher priority, do nothing.
1958 // 0 Pipes of same priority.
1959 //-1 Right pipe is of higher priority, needs swap.
1960 if(ctx->mOverlay->comparePipePriority(pipe_info.lIndex,
1961 pipe_info.rIndex) == -1) {
1962 qhwc::swap(pipe_info.lIndex, pipe_info.rIndex);
Saurabh Shahab47c692014-02-12 18:45:57 -08001963 }
1964 }
1965
1966 return true;
1967}
1968
Saurabh Shahab47c692014-02-12 18:45:57 -08001969int MDPCompSrcSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
1970 PipeLayerPair& PipeLayerPair) {
1971 private_handle_t *hnd = (private_handle_t *)layer->handle;
1972 if(!hnd) {
1973 ALOGE("%s: layer handle is NULL", __FUNCTION__);
1974 return -1;
1975 }
1976 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
1977 MdpPipeInfoSplit& mdp_info =
1978 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
1979 Rotator **rot = &PipeLayerPair.rot;
1980 eZorder z = static_cast<eZorder>(mdp_info.zOrder);
1981 eIsFg isFg = IS_FG_OFF;
1982 eDest lDest = mdp_info.lIndex;
1983 eDest rDest = mdp_info.rIndex;
1984 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
1985 hwc_rect_t dst = layer->displayFrame;
1986 int transform = layer->transform;
1987 eTransform orient = static_cast<eTransform>(transform);
1988 const int downscale = 0;
1989 int rotFlags = ROT_FLAGS_NONE;
1990 uint32_t format = ovutils::getMdpFormat(hnd->format, isTileRendered(hnd));
1991 Whf whf(getWidth(hnd), getHeight(hnd), format, hnd->size);
1992
1993 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1994 "dest_pipeR: %d",__FUNCTION__, layer, z, lDest, rDest);
1995
1996 // Handle R/B swap
1997 if (layer->flags & HWC_FORMAT_RB_SWAP) {
1998 if (hnd->format == HAL_PIXEL_FORMAT_RGBA_8888)
1999 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRA_8888);
2000 else if (hnd->format == HAL_PIXEL_FORMAT_RGBX_8888)
2001 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRX_8888);
2002 }
2003
Saurabh Shah97e2d802014-04-14 18:03:54 -07002004 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
2005 setMdpFlags(layer, mdpFlags, 0, transform);
Saurabh Shahab47c692014-02-12 18:45:57 -08002006
2007 if(lDest != OV_INVALID && rDest != OV_INVALID) {
2008 //Enable overfetch
Saurabh Shah97e2d802014-04-14 18:03:54 -07002009 setMdpFlags(mdpFlags, OV_MDSS_MDP_DUAL_PIPE);
Saurabh Shahab47c692014-02-12 18:45:57 -08002010 }
2011
2012 if(isYuvBuffer(hnd) && (transform & HWC_TRANSFORM_ROT_90)) {
2013 (*rot) = ctx->mRotMgr->getNext();
2014 if((*rot) == NULL) return -1;
Saurabh Shah39240c92014-03-31 10:31:42 -07002015 ctx->mLayerRotMap[mDpy]->add(layer, *rot);
Saurabh Shahab47c692014-02-12 18:45:57 -08002016 //Configure rotator for pre-rotation
Saurabh Shah97e2d802014-04-14 18:03:54 -07002017 if(configRotator(*rot, whf, crop, mdpFlags, orient, downscale) < 0) {
Saurabh Shahab47c692014-02-12 18:45:57 -08002018 ALOGE("%s: configRotator failed!", __FUNCTION__);
2019 return -1;
2020 }
Saurabh Shahab47c692014-02-12 18:45:57 -08002021 whf.format = (*rot)->getDstFormat();
2022 updateSource(orient, whf, crop);
2023 rotFlags |= ROT_PREROTATED;
2024 }
2025
2026 //If 2 pipes being used, divide layer into half, crop and dst
2027 hwc_rect_t cropL = crop;
2028 hwc_rect_t cropR = crop;
2029 hwc_rect_t dstL = dst;
2030 hwc_rect_t dstR = dst;
2031 if(lDest != OV_INVALID && rDest != OV_INVALID) {
2032 cropL.right = (crop.right + crop.left) / 2;
2033 cropR.left = cropL.right;
2034 sanitizeSourceCrop(cropL, cropR, hnd);
2035
2036 //Swap crops on H flip since 2 pipes are being used
2037 if((orient & OVERLAY_TRANSFORM_FLIP_H) && (*rot) == NULL) {
2038 hwc_rect_t tmp = cropL;
2039 cropL = cropR;
2040 cropR = tmp;
2041 }
2042
2043 dstL.right = (dst.right + dst.left) / 2;
2044 dstR.left = dstL.right;
2045 }
2046
2047 //For the mdp, since either we are pre-rotating or MDP does flips
2048 orient = OVERLAY_TRANSFORM_0;
2049 transform = 0;
2050
2051 //configure left pipe
2052 if(lDest != OV_INVALID) {
Saurabh Shah97e2d802014-04-14 18:03:54 -07002053 PipeArgs pargL(mdpFlags, whf, z, isFg,
Saurabh Shahab47c692014-02-12 18:45:57 -08002054 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2055 (ovutils::eBlending) getBlending(layer->blending));
2056
2057 if(configMdp(ctx->mOverlay, pargL, orient,
2058 cropL, dstL, metadata, lDest) < 0) {
2059 ALOGE("%s: commit failed for left mixer config", __FUNCTION__);
2060 return -1;
2061 }
2062 }
2063
2064 //configure right pipe
2065 if(rDest != OV_INVALID) {
Saurabh Shah97e2d802014-04-14 18:03:54 -07002066 PipeArgs pargR(mdpFlags, whf, z, isFg,
Saurabh Shahab47c692014-02-12 18:45:57 -08002067 static_cast<eRotFlags>(rotFlags),
2068 layer->planeAlpha,
2069 (ovutils::eBlending) getBlending(layer->blending));
2070 if(configMdp(ctx->mOverlay, pargR, orient,
2071 cropR, dstR, metadata, rDest) < 0) {
2072 ALOGE("%s: commit failed for right mixer config", __FUNCTION__);
2073 return -1;
2074 }
2075 }
2076
2077 return 0;
2078}
2079
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002080}; //namespace
2081