blob: b72e3f5b7b145eb58f729e6474d03a96b00bc805 [file] [log] [blame]
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001/*
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08002 * Copyright (C) 2012-2014, The Linux Foundation. All rights reserved.
Naseer Ahmed7c958d42012-07-31 18:57:03 -07003 * Not a Contribution, Apache license notifications and license are retained
4 * for attribution purposes only.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
Saurabh Shah4fdde762013-04-30 18:47:33 -070019#include <math.h>
Naseer Ahmed7c958d42012-07-31 18:57:03 -070020#include "hwc_mdpcomp.h"
Naseer Ahmed54821fe2012-11-28 18:44:38 -050021#include <sys/ioctl.h>
Saurabh Shah56f610d2012-08-07 15:27:06 -070022#include "external.h"
Jeykumar Sankaran27dee262013-08-01 17:09:54 -070023#include "virtual.h"
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -080024#include "qdMetaData.h"
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -080025#include "mdp_version.h"
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -070026#include "hwc_fbupdate.h"
Saurabh Shaha9da08f2013-07-03 13:27:53 -070027#include "hwc_ad.h"
Saurabh Shahacf10202013-02-26 10:15:15 -080028#include <overlayRotator.h>
29
Saurabh Shah85234ec2013-04-12 17:09:00 -070030using namespace overlay;
Saurabh Shahbd2d0832013-04-04 14:33:08 -070031using namespace qdutils;
Saurabh Shahacf10202013-02-26 10:15:15 -080032using namespace overlay::utils;
33namespace ovutils = overlay::utils;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070034
Naseer Ahmed7c958d42012-07-31 18:57:03 -070035namespace qhwc {
36
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080037//==============MDPComp========================================================
38
Naseer Ahmed7c958d42012-07-31 18:57:03 -070039IdleInvalidator *MDPComp::idleInvalidator = NULL;
40bool MDPComp::sIdleFallBack = false;
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -080041bool MDPComp::sHandleTimeout = false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070042bool MDPComp::sDebugLogs = false;
Naseer Ahmed54821fe2012-11-28 18:44:38 -050043bool MDPComp::sEnabled = false;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -070044bool MDPComp::sEnableMixedMode = true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080045int MDPComp::sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
radhakrishnac9a67412013-09-25 17:40:42 +053046bool MDPComp::sEnable4k2kYUVSplit = false;
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -070047bool MDPComp::sSrcSplitEnabled = false;
Saurabh Shah88e4d272013-09-03 13:31:29 -070048MDPComp* MDPComp::getObject(hwc_context_t *ctx, const int& dpy) {
Saurabh Shah60e8bde2014-04-30 14:46:03 -070049 if(qdutils::MDPVersion::getInstance().isSrcSplit()) {
50 sSrcSplitEnabled = true;
51 return new MDPCompSrcSplit(dpy);
52 } else if(isDisplaySplit(ctx, dpy)) {
Saurabh Shah88e4d272013-09-03 13:31:29 -070053 return new MDPCompSplit(dpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080054 }
Saurabh Shah88e4d272013-09-03 13:31:29 -070055 return new MDPCompNonSplit(dpy);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080056}
57
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080058MDPComp::MDPComp(int dpy):mDpy(dpy){};
59
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080060void MDPComp::dump(android::String8& buf)
61{
Jeykumar Sankaran3c6bb042013-08-15 14:01:04 -070062 if(mCurrentFrame.layerCount > MAX_NUM_APP_LAYERS)
63 return;
64
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080065 dumpsys_log(buf,"HWC Map for Dpy: %s \n",
Jeykumar Sankaran27dee262013-08-01 17:09:54 -070066 (mDpy == 0) ? "\"PRIMARY\"" :
67 (mDpy == 1) ? "\"EXTERNAL\"" : "\"VIRTUAL\"");
Saurabh Shahe9bc60f2013-08-29 12:58:06 -070068 dumpsys_log(buf,"CURR_FRAME: layerCount:%2d mdpCount:%2d "
69 "fbCount:%2d \n", mCurrentFrame.layerCount,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080070 mCurrentFrame.mdpCount, mCurrentFrame.fbCount);
71 dumpsys_log(buf,"needsFBRedraw:%3s pipesUsed:%2d MaxPipesPerMixer: %d \n",
72 (mCurrentFrame.needsRedraw? "YES" : "NO"),
73 mCurrentFrame.mdpCount, sMaxPipesPerMixer);
74 dumpsys_log(buf," --------------------------------------------- \n");
75 dumpsys_log(buf," listIdx | cached? | mdpIndex | comptype | Z \n");
76 dumpsys_log(buf," --------------------------------------------- \n");
77 for(int index = 0; index < mCurrentFrame.layerCount; index++ )
78 dumpsys_log(buf," %7d | %7s | %8d | %9s | %2d \n",
79 index,
80 (mCurrentFrame.isFBComposed[index] ? "YES" : "NO"),
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -070081 mCurrentFrame.layerToMDP[index],
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080082 (mCurrentFrame.isFBComposed[index] ?
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -070083 (mCurrentFrame.drop[index] ? "DROP" :
84 (mCurrentFrame.needsRedraw ? "GLES" : "CACHE")) : "MDP"),
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080085 (mCurrentFrame.isFBComposed[index] ? mCurrentFrame.fbZ :
86 mCurrentFrame.mdpToLayer[mCurrentFrame.layerToMDP[index]].pipeInfo->zOrder));
87 dumpsys_log(buf,"\n");
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080088}
89
90bool MDPComp::init(hwc_context_t *ctx) {
91
92 if(!ctx) {
93 ALOGE("%s: Invalid hwc context!!",__FUNCTION__);
94 return false;
95 }
96
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080097 char property[PROPERTY_VALUE_MAX];
98
99 sEnabled = false;
100 if((property_get("persist.hwc.mdpcomp.enable", property, NULL) > 0) &&
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800101 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
102 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800103 sEnabled = true;
104 }
105
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700106 sEnableMixedMode = true;
107 if((property_get("debug.mdpcomp.mixedmode.disable", property, NULL) > 0) &&
108 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
109 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
110 sEnableMixedMode = false;
111 }
112
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800113 if(property_get("debug.mdpcomp.logs", property, NULL) > 0) {
114 if(atoi(property) != 0)
115 sDebugLogs = true;
116 }
117
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800118 sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
Saurabh Shah85234ec2013-04-12 17:09:00 -0700119 if(property_get("debug.mdpcomp.maxpermixer", property, "-1") > 0) {
120 int val = atoi(property);
121 if(val >= 0)
122 sMaxPipesPerMixer = min(val, MAX_PIPES_PER_MIXER);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800123 }
124
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400125 if(ctx->mMDP.panel != MIPI_CMD_PANEL) {
126 // Idle invalidation is not necessary on command mode panels
127 long idle_timeout = DEFAULT_IDLE_TIME;
128 if(property_get("debug.mdpcomp.idletime", property, NULL) > 0) {
129 if(atoi(property) != 0)
130 idle_timeout = atoi(property);
131 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800132
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400133 //create Idle Invalidator only when not disabled through property
134 if(idle_timeout != -1)
135 idleInvalidator = IdleInvalidator::getInstance();
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800136
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400137 if(idleInvalidator == NULL) {
138 ALOGE("%s: failed to instantiate idleInvalidator object",
139 __FUNCTION__);
140 } else {
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530141 idleInvalidator->init(timeout_handler, ctx,
142 (unsigned int)idle_timeout);
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400143 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800144 }
radhakrishnac9a67412013-09-25 17:40:42 +0530145
146 if((property_get("debug.mdpcomp.4k2kSplit", property, "0") > 0) &&
147 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
148 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
149 sEnable4k2kYUVSplit = true;
150 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700151 return true;
152}
153
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800154void MDPComp::reset(hwc_context_t *ctx) {
155 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700156 mCurrentFrame.reset(numLayers);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800157 ctx->mOverlay->clear(mDpy);
158 ctx->mLayerRotMap[mDpy]->clear();
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700159}
160
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700161void MDPComp::timeout_handler(void *udata) {
162 struct hwc_context_t* ctx = (struct hwc_context_t*)(udata);
163
164 if(!ctx) {
165 ALOGE("%s: received empty data in timer callback", __FUNCTION__);
166 return;
167 }
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -0800168 Locker::Autolock _l(ctx->mDrawLock);
169 // Handle timeout event only if the previous composition is MDP or MIXED.
170 if(!sHandleTimeout) {
171 ALOGD_IF(isDebug(), "%s:Do not handle this timeout", __FUNCTION__);
172 return;
173 }
Jesse Hall3be78d92012-08-21 15:12:23 -0700174 if(!ctx->proc) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700175 ALOGE("%s: HWC proc not registered", __FUNCTION__);
176 return;
177 }
178 sIdleFallBack = true;
179 /* Trigger SF to redraw the current frame */
Jesse Hall3be78d92012-08-21 15:12:23 -0700180 ctx->proc->invalidate(ctx->proc);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700181}
182
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800183void MDPComp::setMDPCompLayerFlags(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800184 hwc_display_contents_1_t* list) {
185 LayerProp *layerProp = ctx->layerProp[mDpy];
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800186
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800187 for(int index = 0; index < ctx->listStats[mDpy].numAppLayers; index++) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800188 hwc_layer_1_t* layer = &(list->hwLayers[index]);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800189 if(!mCurrentFrame.isFBComposed[index]) {
190 layerProp[index].mFlags |= HWC_MDPCOMP;
191 layer->compositionType = HWC_OVERLAY;
192 layer->hints |= HWC_HINT_CLEAR_FB;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800193 } else {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700194 /* Drop the layer when its already present in FB OR when it lies
195 * outside frame's ROI */
196 if(!mCurrentFrame.needsRedraw || mCurrentFrame.drop[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800197 layer->compositionType = HWC_OVERLAY;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700198 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800199 }
200 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700201}
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500202
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800203void MDPComp::setRedraw(hwc_context_t *ctx,
204 hwc_display_contents_1_t* list) {
205 mCurrentFrame.needsRedraw = false;
206 if(!mCachedFrame.isSameFrame(mCurrentFrame, list) ||
207 (list->flags & HWC_GEOMETRY_CHANGED) ||
208 isSkipPresent(ctx, mDpy)) {
209 mCurrentFrame.needsRedraw = true;
210 }
211}
212
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800213MDPComp::FrameInfo::FrameInfo() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700214 reset(0);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800215}
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800216
Saurabh Shahaa236822013-04-24 18:07:26 -0700217void MDPComp::FrameInfo::reset(const int& numLayers) {
218 for(int i = 0 ; i < MAX_PIPES_PER_MIXER && numLayers; i++ ) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800219 if(mdpToLayer[i].pipeInfo) {
220 delete mdpToLayer[i].pipeInfo;
221 mdpToLayer[i].pipeInfo = NULL;
222 //We dont own the rotator
223 mdpToLayer[i].rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800224 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800225 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800226
227 memset(&mdpToLayer, 0, sizeof(mdpToLayer));
228 memset(&layerToMDP, -1, sizeof(layerToMDP));
Saurabh Shahaa236822013-04-24 18:07:26 -0700229 memset(&isFBComposed, 1, sizeof(isFBComposed));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800230
Saurabh Shahaa236822013-04-24 18:07:26 -0700231 layerCount = numLayers;
232 fbCount = numLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800233 mdpCount = 0;
Saurabh Shah2f3895f2013-05-02 10:13:31 -0700234 needsRedraw = true;
Saurabh Shahd53bc5f2014-02-05 10:17:43 -0800235 fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800236}
237
Saurabh Shahaa236822013-04-24 18:07:26 -0700238void MDPComp::FrameInfo::map() {
239 // populate layer and MDP maps
240 int mdpIdx = 0;
241 for(int idx = 0; idx < layerCount; idx++) {
242 if(!isFBComposed[idx]) {
243 mdpToLayer[mdpIdx].listIndex = idx;
244 layerToMDP[idx] = mdpIdx++;
245 }
246 }
247}
248
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800249MDPComp::LayerCache::LayerCache() {
250 reset();
251}
252
253void MDPComp::LayerCache::reset() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700254 memset(&hnd, 0, sizeof(hnd));
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530255 memset(&isFBComposed, true, sizeof(isFBComposed));
256 memset(&drop, false, sizeof(drop));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800257 layerCount = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -0700258}
259
260void MDPComp::LayerCache::cacheAll(hwc_display_contents_1_t* list) {
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530261 const int numAppLayers = (int)list->numHwLayers - 1;
Saurabh Shahaa236822013-04-24 18:07:26 -0700262 for(int i = 0; i < numAppLayers; i++) {
263 hnd[i] = list->hwLayers[i].handle;
264 }
265}
266
267void MDPComp::LayerCache::updateCounts(const FrameInfo& curFrame) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700268 layerCount = curFrame.layerCount;
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530269 memcpy(&isFBComposed, &curFrame.isFBComposed, sizeof(isFBComposed));
270 memcpy(&drop, &curFrame.drop, sizeof(drop));
271}
272
Jeykumar Sankaran988d3682013-11-15 11:57:16 -0800273bool MDPComp::LayerCache::isSameFrame(const FrameInfo& curFrame,
274 hwc_display_contents_1_t* list) {
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530275 if(layerCount != curFrame.layerCount)
276 return false;
277 for(int i = 0; i < curFrame.layerCount; i++) {
278 if((curFrame.isFBComposed[i] != isFBComposed[i]) ||
279 (curFrame.drop[i] != drop[i])) {
280 return false;
281 }
Jeykumar Sankaran988d3682013-11-15 11:57:16 -0800282 if(curFrame.isFBComposed[i] &&
283 (hnd[i] != list->hwLayers[i].handle)){
284 return false;
285 }
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530286 }
287 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800288}
289
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700290bool MDPComp::isSupportedForMDPComp(hwc_context_t *ctx, hwc_layer_1_t* layer) {
291 private_handle_t *hnd = (private_handle_t *)layer->handle;
292 if((not isYuvBuffer(hnd) and has90Transform(layer)) or
293 (not isValidDimension(ctx,layer))
294 //More conditions here, SKIP, sRGB+Blend etc
295 ) {
296 return false;
297 }
298 return true;
299}
300
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530301bool MDPComp::isValidDimension(hwc_context_t *ctx, hwc_layer_1_t *layer) {
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800302 private_handle_t *hnd = (private_handle_t *)layer->handle;
303
304 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -0700305 if (layer->flags & HWC_COLOR_FILL) {
306 // Color layer
307 return true;
308 }
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800309 ALOGE("%s: layer handle is NULL", __FUNCTION__);
310 return false;
311 }
312
Naseer Ahmede850a802013-09-06 13:12:52 -0400313 //XXX: Investigate doing this with pixel phase on MDSS
Naseer Ahmede77f8082013-10-10 13:42:48 -0400314 if(!isSecureBuffer(hnd) && isNonIntegralSourceCrop(layer->sourceCropf))
Naseer Ahmede850a802013-09-06 13:12:52 -0400315 return false;
316
Saurabh Shah62e1d732013-09-17 10:44:05 -0700317 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700318 hwc_rect_t dst = layer->displayFrame;
Saurabh Shah4fdde762013-04-30 18:47:33 -0700319 int crop_w = crop.right - crop.left;
320 int crop_h = crop.bottom - crop.top;
321 int dst_w = dst.right - dst.left;
322 int dst_h = dst.bottom - dst.top;
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800323 float w_scale = ((float)crop_w / (float)dst_w);
324 float h_scale = ((float)crop_h / (float)dst_h);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700325
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800326 /* Workaround for MDP HW limitation in DSI command mode panels where
327 * FPS will not go beyond 30 if buffers on RGB pipes are of width or height
328 * less than 5 pixels
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530329 * There also is a HW limilation in MDP, minimum block size is 2x2
330 * Fallback to GPU if height is less than 2.
331 */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800332 if((crop_w < 5)||(crop_h < 5))
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800333 return false;
334
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800335 if((w_scale > 1.0f) || (h_scale > 1.0f)) {
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700336 const uint32_t maxMDPDownscale =
Saurabh Shah4fdde762013-04-30 18:47:33 -0700337 qdutils::MDPVersion::getInstance().getMaxMDPDownscale();
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800338 const float w_dscale = w_scale;
339 const float h_dscale = h_scale;
340
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800341 if(ctx->mMDP.version >= qdutils::MDSS_V5) {
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700342
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800343 if(!qdutils::MDPVersion::getInstance().supportsDecimation()) {
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700344 /* On targets that doesnt support Decimation (eg.,8x26)
345 * maximum downscale support is overlay pipe downscale.
346 */
347 if(crop_w > MAX_DISPLAY_DIM || w_dscale > maxMDPDownscale ||
348 h_dscale > maxMDPDownscale)
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800349 return false;
350 } else {
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700351 // Decimation on macrotile format layers is not supported.
352 if(isTileRendered(hnd)) {
353 /* MDP can read maximum MAX_DISPLAY_DIM width.
354 * Bail out if
355 * 1. Src crop > MAX_DISPLAY_DIM on nonsplit MDPComp
356 * 2. exceeds maximum downscale limit
357 */
358 if(((crop_w > MAX_DISPLAY_DIM) && !sSrcSplitEnabled) ||
359 w_dscale > maxMDPDownscale ||
360 h_dscale > maxMDPDownscale) {
361 return false;
362 }
363 } else if(w_dscale > 64 || h_dscale > 64)
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800364 return false;
365 }
366 } else { //A-family
Manoj Kumar AVM8cbbf7c2014-03-11 01:15:31 -0700367 if(w_dscale > maxMDPDownscale || h_dscale > maxMDPDownscale)
Saurabh Shah4fdde762013-04-30 18:47:33 -0700368 return false;
369 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700370 }
371
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800372 if((w_scale < 1.0f) || (h_scale < 1.0f)) {
373 const uint32_t upscale =
374 qdutils::MDPVersion::getInstance().getMaxMDPUpscale();
375 const float w_uscale = 1.0f / w_scale;
376 const float h_uscale = 1.0f / h_scale;
377
378 if(w_uscale > upscale || h_uscale > upscale)
379 return false;
380 }
381
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800382 return true;
383}
384
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800385bool MDPComp::isFrameDoable(hwc_context_t *ctx) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700386 bool ret = true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800387
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800388 if(!isEnabled()) {
389 ALOGD_IF(isDebug(),"%s: MDP Comp. not enabled.", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700390 ret = false;
Raj Kamal068f4572014-04-14 16:14:06 +0530391 } else if((qdutils::MDPVersion::getInstance().is8x26() ||
Prabhanjan Kandula958ffa92014-05-12 14:56:56 +0530392 qdutils::MDPVersion::getInstance().is8x16() ||
393 qdutils::MDPVersion::getInstance().is8x39()) &&
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -0800394 ctx->mVideoTransFlag &&
395 isSecondaryConnected(ctx)) {
Saurabh Shahd4e65852013-06-17 11:33:53 -0700396 //1 Padding round to shift pipes across mixers
397 ALOGD_IF(isDebug(),"%s: MDP Comp. video transition padding round",
398 __FUNCTION__);
399 ret = false;
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -0800400 } else if(isSecondaryConfiguring(ctx)) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800401 ALOGD_IF( isDebug(),"%s: External Display connection is pending",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800402 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700403 ret = false;
Saurabh Shahaa236822013-04-24 18:07:26 -0700404 } else if(ctx->isPaddingRound) {
Raj Kamal9ed3d6b2014-02-07 16:15:17 +0530405 ALOGD_IF(isDebug(), "%s: padding round invoked for dpy %d",
406 __FUNCTION__,mDpy);
Saurabh Shahaa236822013-04-24 18:07:26 -0700407 ret = false;
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700408 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700409 return ret;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800410}
411
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800412void MDPCompNonSplit::trimAgainstROI(hwc_context_t *ctx, hwc_rect_t& fbRect) {
413 hwc_rect_t roi = ctx->listStats[mDpy].lRoi;
414 fbRect = getIntersection(fbRect, roi);
415}
416
417/* 1) Identify layers that are not visible or lying outside the updating ROI and
418 * drop them from composition.
419 * 2) If we have a scaling layer which needs cropping against generated
420 * ROI, reset ROI to full resolution. */
421bool MDPCompNonSplit::validateAndApplyROI(hwc_context_t *ctx,
422 hwc_display_contents_1_t* list) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700423 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800424 hwc_rect_t visibleRect = ctx->listStats[mDpy].lRoi;
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800425
426 for(int i = numAppLayers - 1; i >= 0; i--){
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800427 if(!isValidRect(visibleRect)) {
428 mCurrentFrame.drop[i] = true;
429 mCurrentFrame.dropCount++;
Jeykumar Sankaran0b961452014-01-21 17:26:12 -0800430 continue;
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800431 }
432
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700433 const hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700434 hwc_rect_t dstRect = layer->displayFrame;
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800435 hwc_rect_t res = getIntersection(visibleRect, dstRect);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700436
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700437 if(!isValidRect(res)) {
438 mCurrentFrame.drop[i] = true;
439 mCurrentFrame.dropCount++;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800440 } else {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700441 /* Reset frame ROI when any layer which needs scaling also needs ROI
442 * cropping */
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800443 if(!isSameRect(res, dstRect) && needsScaling (layer)) {
Arpita Banerjeed8965982013-11-08 17:27:33 -0800444 ALOGI("%s: Resetting ROI due to scaling", __FUNCTION__);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700445 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
446 mCurrentFrame.dropCount = 0;
447 return false;
448 }
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800449
Jeykumar Sankaran0b961452014-01-21 17:26:12 -0800450 /* deduct any opaque region from visibleRect */
451 if (layer->blending == HWC_BLENDING_NONE)
452 visibleRect = deductRect(visibleRect, res);
453 }
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700454 }
455 return true;
456}
457
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800458/* Calculate ROI for the frame by accounting all the layer's dispalyFrame which
459 * are updating. If DirtyRegion is applicable, calculate it by accounting all
460 * the changing layer's dirtyRegion. */
461void MDPCompNonSplit::generateROI(hwc_context_t *ctx,
462 hwc_display_contents_1_t* list) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700463 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800464 if(!canPartialUpdate(ctx, list))
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700465 return;
466
467 struct hwc_rect roi = (struct hwc_rect){0, 0, 0, 0};
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800468 hwc_rect fullFrame = (struct hwc_rect) {0, 0,(int)ctx->dpyAttr[mDpy].xres,
469 (int)ctx->dpyAttr[mDpy].yres};
470
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700471 for(int index = 0; index < numAppLayers; index++ ) {
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800472 hwc_layer_1_t* layer = &list->hwLayers[index];
473 if ((mCachedFrame.hnd[index] != layer->handle) ||
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800474 isYuvBuffer((private_handle_t *)layer->handle)) {
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800475 hwc_rect_t updatingRect = layer->displayFrame;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800476
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800477#ifdef QCOM_BSP
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800478 if(!needsScaling(layer) && !layer->transform)
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800479 updatingRect = layer->dirtyRect;
480#endif
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800481
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800482 roi = getUnion(roi, updatingRect);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700483 }
484 }
485
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800486 /* No layer is updating. Still SF wants a refresh.*/
487 if(!isValidRect(roi))
488 return;
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800489
490 // Align ROI coordinates to panel restrictions
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800491 roi = getSanitizeROI(roi, fullFrame);
Jeykumar Sankaran7c852382014-02-26 18:26:58 -0800492
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800493 ctx->listStats[mDpy].lRoi = roi;
494 if(!validateAndApplyROI(ctx, list))
495 resetROI(ctx, mDpy);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700496
497 ALOGD_IF(isDebug(),"%s: generated ROI: [%d, %d, %d, %d]", __FUNCTION__,
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800498 ctx->listStats[mDpy].lRoi.left, ctx->listStats[mDpy].lRoi.top,
499 ctx->listStats[mDpy].lRoi.right, ctx->listStats[mDpy].lRoi.bottom);
500}
501
502void MDPCompSplit::trimAgainstROI(hwc_context_t *ctx, hwc_rect_t& fbRect) {
503 hwc_rect l_roi = ctx->listStats[mDpy].lRoi;
504 hwc_rect r_roi = ctx->listStats[mDpy].rRoi;
505
506 hwc_rect_t l_fbRect = getIntersection(fbRect, l_roi);
507 hwc_rect_t r_fbRect = getIntersection(fbRect, r_roi);
508 fbRect = getUnion(l_fbRect, r_fbRect);
509}
510/* 1) Identify layers that are not visible or lying outside BOTH the updating
511 * ROI's and drop them from composition. If a layer is spanning across both
512 * the halves of the screen but needed by only ROI, the non-contributing
513 * half will not be programmed for MDP.
514 * 2) If we have a scaling layer which needs cropping against generated
515 * ROI, reset ROI to full resolution. */
516bool MDPCompSplit::validateAndApplyROI(hwc_context_t *ctx,
517 hwc_display_contents_1_t* list) {
518
519 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
520
521 hwc_rect_t visibleRectL = ctx->listStats[mDpy].lRoi;
522 hwc_rect_t visibleRectR = ctx->listStats[mDpy].rRoi;
523
524 for(int i = numAppLayers - 1; i >= 0; i--){
525 if(!isValidRect(visibleRectL) && !isValidRect(visibleRectR))
526 {
527 mCurrentFrame.drop[i] = true;
528 mCurrentFrame.dropCount++;
529 continue;
530 }
531
532 const hwc_layer_1_t* layer = &list->hwLayers[i];
533 hwc_rect_t dstRect = layer->displayFrame;
534
535 hwc_rect_t l_res = getIntersection(visibleRectL, dstRect);
536 hwc_rect_t r_res = getIntersection(visibleRectR, dstRect);
537 hwc_rect_t res = getUnion(l_res, r_res);
538
539 if(!isValidRect(l_res) && !isValidRect(r_res)) {
540 mCurrentFrame.drop[i] = true;
541 mCurrentFrame.dropCount++;
542 } else {
543 /* Reset frame ROI when any layer which needs scaling also needs ROI
544 * cropping */
545 if(!isSameRect(res, dstRect) && needsScaling (layer)) {
546 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
547 mCurrentFrame.dropCount = 0;
548 return false;
549 }
550
551 if (layer->blending == HWC_BLENDING_NONE) {
552 visibleRectL = deductRect(visibleRectL, l_res);
553 visibleRectR = deductRect(visibleRectR, r_res);
554 }
555 }
556 }
557 return true;
558}
559/* Calculate ROI for the frame by accounting all the layer's dispalyFrame which
560 * are updating. If DirtyRegion is applicable, calculate it by accounting all
561 * the changing layer's dirtyRegion. */
562void MDPCompSplit::generateROI(hwc_context_t *ctx,
563 hwc_display_contents_1_t* list) {
564 if(!canPartialUpdate(ctx, list))
565 return;
566
567 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
568 int lSplit = getLeftSplit(ctx, mDpy);
569
570 int hw_h = (int)ctx->dpyAttr[mDpy].yres;
571 int hw_w = (int)ctx->dpyAttr[mDpy].xres;
572
573 struct hwc_rect l_frame = (struct hwc_rect){0, 0, lSplit, hw_h};
574 struct hwc_rect r_frame = (struct hwc_rect){lSplit, 0, hw_w, hw_h};
575
576 struct hwc_rect l_roi = (struct hwc_rect){0, 0, 0, 0};
577 struct hwc_rect r_roi = (struct hwc_rect){0, 0, 0, 0};
578
579 for(int index = 0; index < numAppLayers; index++ ) {
580 hwc_layer_1_t* layer = &list->hwLayers[index];
581 if ((mCachedFrame.hnd[index] != layer->handle) ||
582 isYuvBuffer((private_handle_t *)layer->handle)) {
583 hwc_rect_t updatingRect = layer->displayFrame;
584
585#ifdef QCOM_BSP
586 if(!needsScaling(layer) && !layer->transform)
587 updatingRect = layer->dirtyRect;
588#endif
589
590 hwc_rect_t l_dst = getIntersection(l_frame, updatingRect);
591 if(isValidRect(l_dst))
592 l_roi = getUnion(l_roi, l_dst);
593
594 hwc_rect_t r_dst = getIntersection(r_frame, updatingRect);
595 if(isValidRect(r_dst))
596 r_roi = getUnion(r_roi, r_dst);
597 }
598 }
599
600 /* No layer is updating. Still SF wants a refresh. */
601 if(!isValidRect(l_roi) && !isValidRect(r_roi))
602 return;
603
604 l_roi = getSanitizeROI(l_roi, l_frame);
605 r_roi = getSanitizeROI(r_roi, r_frame);
606
607 ctx->listStats[mDpy].lRoi = l_roi;
608 ctx->listStats[mDpy].rRoi = r_roi;
609
610 if(!validateAndApplyROI(ctx, list))
611 resetROI(ctx, mDpy);
612
613 ALOGD_IF(isDebug(),"%s: generated L_ROI: [%d, %d, %d, %d]"
614 "R_ROI: [%d, %d, %d, %d]", __FUNCTION__,
615 ctx->listStats[mDpy].lRoi.left, ctx->listStats[mDpy].lRoi.top,
616 ctx->listStats[mDpy].lRoi.right, ctx->listStats[mDpy].lRoi.bottom,
617 ctx->listStats[mDpy].rRoi.left, ctx->listStats[mDpy].rRoi.top,
618 ctx->listStats[mDpy].rRoi.right, ctx->listStats[mDpy].rRoi.bottom);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700619}
620
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800621/* Checks for conditions where all the layers marked for MDP comp cannot be
622 * bypassed. On such conditions we try to bypass atleast YUV layers */
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800623bool MDPComp::tryFullFrame(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800624 hwc_display_contents_1_t* list){
625
Saurabh Shahaa236822013-04-24 18:07:26 -0700626 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Arun Kumar K.R2e2871c2014-01-10 12:47:06 -0800627 int priDispW = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800628
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -0700629 if(sIdleFallBack && !ctx->listStats[mDpy].secureUI) {
Saurabh Shah2d998a92013-05-14 17:55:58 -0700630 ALOGD_IF(isDebug(), "%s: Idle fallback dpy %d",__FUNCTION__, mDpy);
631 return false;
632 }
633
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800634 if(isSkipPresent(ctx, mDpy)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700635 ALOGD_IF(isDebug(),"%s: SKIP present: %d",
636 __FUNCTION__,
637 isSkipPresent(ctx, mDpy));
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800638 return false;
639 }
640
Arun Kumar K.R2e2871c2014-01-10 12:47:06 -0800641 if(mDpy > HWC_DISPLAY_PRIMARY && (priDispW > MAX_DISPLAY_DIM) &&
642 (ctx->dpyAttr[mDpy].xres < MAX_DISPLAY_DIM)) {
643 // Disable MDP comp on Secondary when the primary is highres panel and
644 // the secondary is a normal 1080p, because, MDP comp on secondary under
645 // in such usecase, decimation gets used for downscale and there will be
646 // a quality mismatch when there will be a fallback to GPU comp
647 ALOGD_IF(isDebug(), "%s: Disable MDP Compositon for Secondary Disp",
648 __FUNCTION__);
649 return false;
650 }
651
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800652 // check for action safe flag and downscale mode which requires scaling.
653 if(ctx->dpyAttr[mDpy].mActionSafePresent
654 || ctx->dpyAttr[mDpy].mDownScaleMode) {
655 ALOGD_IF(isDebug(), "%s: Scaling needed for this frame",__FUNCTION__);
656 return false;
657 }
658
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800659 for(int i = 0; i < numAppLayers; ++i) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800660 hwc_layer_1_t* layer = &list->hwLayers[i];
661 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800662
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700663 if(isYuvBuffer(hnd) && has90Transform(layer)) {
664 if(!canUseRotator(ctx, mDpy)) {
665 ALOGD_IF(isDebug(), "%s: Can't use rotator for dpy %d",
666 __FUNCTION__, mDpy);
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700667 return false;
668 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800669 }
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530670
671 //For 8x26 with panel width>1k, if RGB layer needs HFLIP fail mdp comp
672 // may not need it if Gfx pre-rotation can handle all flips & rotations
Sushil Chauhanfda00fc2014-03-20 11:08:41 -0700673 int transform = (layer->flags & HWC_COLOR_FILL) ? 0 : layer->transform;
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530674 if(qdutils::MDPVersion::getInstance().is8x26() &&
675 (ctx->dpyAttr[mDpy].xres > 1024) &&
Sushil Chauhanfda00fc2014-03-20 11:08:41 -0700676 (transform & HWC_TRANSFORM_FLIP_H) &&
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530677 (!isYuvBuffer(hnd)))
678 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800679 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700680
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700681 if(ctx->mAD->isDoable()) {
682 return false;
683 }
684
Saurabh Shahaa236822013-04-24 18:07:26 -0700685 //If all above hard conditions are met we can do full or partial MDP comp.
686 bool ret = false;
687 if(fullMDPComp(ctx, list)) {
688 ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700689 } else if(partialMDPComp(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700690 ret = true;
691 }
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530692
Saurabh Shahaa236822013-04-24 18:07:26 -0700693 return ret;
694}
695
696bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700697 //Will benefit presentation / secondary-only layer.
698 if((mDpy > HWC_DISPLAY_PRIMARY) &&
699 (list->numHwLayers - 1) > MAX_SEC_LAYERS) {
700 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
701 return false;
702 }
703
704 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
705 for(int i = 0; i < numAppLayers; i++) {
706 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran880da832014-04-18 10:22:35 -0700707 if(not mCurrentFrame.drop[i] and
708 not isSupportedForMDPComp(ctx, layer)) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700709 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",__FUNCTION__);
710 return false;
711 }
712 }
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800713
Saurabh Shahaa236822013-04-24 18:07:26 -0700714 mCurrentFrame.fbCount = 0;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700715 memcpy(&mCurrentFrame.isFBComposed, &mCurrentFrame.drop,
716 sizeof(mCurrentFrame.isFBComposed));
717 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount -
718 mCurrentFrame.dropCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700719
radhakrishnac9a67412013-09-25 17:40:42 +0530720 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800721 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530722 }
723
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800724 if(!postHeuristicsHandling(ctx, list)) {
725 ALOGD_IF(isDebug(), "post heuristic handling failed");
726 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700727 return false;
728 }
729
Saurabh Shahaa236822013-04-24 18:07:26 -0700730 return true;
731}
732
733bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
734{
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700735 if(!sEnableMixedMode) {
736 //Mixed mode is disabled. No need to even try caching.
737 return false;
738 }
739
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700740 bool ret = false;
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800741 if(list->flags & HWC_GEOMETRY_CHANGED) { //Try load based first
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800742 ret = loadBasedComp(ctx, list) or
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800743 cacheBasedComp(ctx, list);
744 } else {
745 ret = cacheBasedComp(ctx, list) or
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800746 loadBasedComp(ctx, list);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700747 }
748
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700749 return ret;
750}
751
752bool MDPComp::cacheBasedComp(hwc_context_t *ctx,
753 hwc_display_contents_1_t* list) {
754 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700755 mCurrentFrame.reset(numAppLayers);
756 updateLayerCache(ctx, list);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700757
758 //If an MDP marked layer is unsupported cannot do partial MDP Comp
759 for(int i = 0; i < numAppLayers; i++) {
760 if(!mCurrentFrame.isFBComposed[i]) {
761 hwc_layer_1_t* layer = &list->hwLayers[i];
762 if(not isSupportedForMDPComp(ctx, layer)) {
763 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",
764 __FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800765 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700766 return false;
767 }
768 }
769 }
770
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700771 updateYUV(ctx, list, false /*secure only*/);
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530772 bool ret = markLayersForCaching(ctx, list); //sets up fbZ also
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700773 if(!ret) {
774 ALOGD_IF(isDebug(),"%s: batching failed, dpy %d",__FUNCTION__, mDpy);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800775 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700776 return false;
777 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700778
779 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700780
radhakrishnac9a67412013-09-25 17:40:42 +0530781 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800782 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530783 }
784
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700785 //Will benefit cases where a video has non-updating background.
786 if((mDpy > HWC_DISPLAY_PRIMARY) and
787 (mdpCount > MAX_SEC_LAYERS)) {
788 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800789 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700790 return false;
791 }
792
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800793 if(!postHeuristicsHandling(ctx, list)) {
794 ALOGD_IF(isDebug(), "post heuristic handling failed");
795 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700796 return false;
797 }
798
Saurabh Shahaa236822013-04-24 18:07:26 -0700799 return true;
800}
801
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800802bool MDPComp::loadBasedComp(hwc_context_t *ctx,
Saurabh Shahb772ae32013-11-18 15:40:02 -0800803 hwc_display_contents_1_t* list) {
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -0800804 if(not isLoadBasedCompDoable(ctx)) {
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800805 return false;
806 }
807
Saurabh Shahb772ae32013-11-18 15:40:02 -0800808 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800809 const int numNonDroppedLayers = numAppLayers - mCurrentFrame.dropCount;
810 const int stagesForMDP = min(sMaxPipesPerMixer,
811 ctx->mOverlay->availablePipes(mDpy, Overlay::MIXER_DEFAULT));
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800812
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800813 int mdpBatchSize = stagesForMDP - 1; //1 stage for FB
814 int fbBatchSize = numNonDroppedLayers - mdpBatchSize;
815 int lastMDPSupportedIndex = numAppLayers;
816 int dropCount = 0;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800817
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800818 //Find the minimum MDP batch size
819 for(int i = 0; i < numAppLayers;i++) {
820 if(mCurrentFrame.drop[i]) {
821 dropCount++;
Jeykumar Sankaran846e2792014-01-23 21:59:58 -0800822 continue;
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800823 }
824 hwc_layer_1_t* layer = &list->hwLayers[i];
825 if(not isSupportedForMDPComp(ctx, layer)) {
826 lastMDPSupportedIndex = i;
827 mdpBatchSize = min(i - dropCount, stagesForMDP - 1);
828 fbBatchSize = numNonDroppedLayers - mdpBatchSize;
Jeykumar Sankaran846e2792014-01-23 21:59:58 -0800829 break;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800830 }
Saurabh Shahb772ae32013-11-18 15:40:02 -0800831 }
832
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800833 ALOGD_IF(isDebug(), "%s:Before optimizing fbBatch, mdpbatch %d, fbbatch %d "
834 "dropped %d", __FUNCTION__, mdpBatchSize, fbBatchSize,
835 mCurrentFrame.dropCount);
836
837 //Start at a point where the fb batch should at least have 2 layers, for
838 //this mode to be justified.
839 while(fbBatchSize < 2) {
840 ++fbBatchSize;
841 --mdpBatchSize;
Jeykumar Sankaran846e2792014-01-23 21:59:58 -0800842 }
Saurabh Shahb772ae32013-11-18 15:40:02 -0800843
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800844 //If there are no layers for MDP, this mode doesnt make sense.
845 if(mdpBatchSize < 1) {
846 ALOGD_IF(isDebug(), "%s: No MDP layers after optimizing for fbBatch",
847 __FUNCTION__);
Saurabh Shahb772ae32013-11-18 15:40:02 -0800848 return false;
849 }
850
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800851 mCurrentFrame.reset(numAppLayers);
852
853 //Try with successively smaller mdp batch sizes until we succeed or reach 1
854 while(mdpBatchSize > 0) {
855 //Mark layers for MDP comp
856 int mdpBatchLeft = mdpBatchSize;
857 for(int i = 0; i < lastMDPSupportedIndex and mdpBatchLeft; i++) {
858 if(mCurrentFrame.drop[i]) {
859 continue;
860 }
861 mCurrentFrame.isFBComposed[i] = false;
862 --mdpBatchLeft;
863 }
864
865 mCurrentFrame.fbZ = mdpBatchSize;
866 mCurrentFrame.fbCount = fbBatchSize;
867 mCurrentFrame.mdpCount = mdpBatchSize;
868
869 ALOGD_IF(isDebug(), "%s:Trying with: mdpbatch %d fbbatch %d dropped %d",
870 __FUNCTION__, mdpBatchSize, fbBatchSize,
871 mCurrentFrame.dropCount);
872
873 if(postHeuristicsHandling(ctx, list)) {
874 ALOGD_IF(isDebug(), "%s: Postheuristics handling succeeded",
875 __FUNCTION__);
876 return true;
877 }
878
879 reset(ctx);
880 --mdpBatchSize;
881 ++fbBatchSize;
882 }
883
884 return false;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800885}
886
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -0800887bool MDPComp::isLoadBasedCompDoable(hwc_context_t *ctx) {
Prabhanjan Kandula3dbbd882013-12-11 14:43:46 +0530888 if(mDpy or isSecurePresent(ctx, mDpy) or
889 isYuvPresent(ctx, mDpy)) {
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700890 return false;
891 }
892 return true;
893}
894
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800895bool MDPComp::canPartialUpdate(hwc_context_t *ctx,
896 hwc_display_contents_1_t* list){
897 if(!qdutils::MDPVersion::getInstance().isPartialUpdateEnabled() ||
898 isSkipPresent(ctx, mDpy) || (list->flags & HWC_GEOMETRY_CHANGED) ||
899 mDpy ) {
900 return false;
901 }
902 return true;
903}
904
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800905bool MDPComp::tryVideoOnly(hwc_context_t *ctx,
906 hwc_display_contents_1_t* list) {
907 const bool secureOnly = true;
908 return videoOnlyComp(ctx, list, not secureOnly) or
909 videoOnlyComp(ctx, list, secureOnly);
910}
911
912bool MDPComp::videoOnlyComp(hwc_context_t *ctx,
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700913 hwc_display_contents_1_t* list, bool secureOnly) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700914 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700915
Saurabh Shahaa236822013-04-24 18:07:26 -0700916 mCurrentFrame.reset(numAppLayers);
Jeykumar Sankaraneb3a5e22014-04-08 16:07:55 -0700917 mCurrentFrame.fbCount -= mCurrentFrame.dropCount;
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700918 updateYUV(ctx, list, secureOnly);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700919 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700920
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800921 if(!isYuvPresent(ctx, mDpy) or (mdpCount == 0)) {
922 reset(ctx);
Saurabh Shahaa236822013-04-24 18:07:26 -0700923 return false;
924 }
925
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -0800926 /* Bail out if we are processing only secured video layers
927 * and we dont have any */
928 if(!isSecurePresent(ctx, mDpy) && secureOnly){
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800929 reset(ctx);
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -0800930 return false;
931 }
932
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800933 if(mCurrentFrame.fbCount)
934 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
Saurabh Shah4fdde762013-04-30 18:47:33 -0700935
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800936 if(sEnable4k2kYUVSplit){
937 adjustForSourceSplit(ctx, list);
938 }
939
940 if(!postHeuristicsHandling(ctx, list)) {
941 ALOGD_IF(isDebug(), "post heuristic handling failed");
942 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700943 return false;
944 }
945
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800946 return true;
947}
948
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800949/* Checks for conditions where YUV layers cannot be bypassed */
950bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -0700951 if(isSkipLayer(layer)) {
Saurabh Shahe2474082013-05-15 16:32:13 -0700952 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800953 return false;
954 }
955
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700956 if(layer->transform & HWC_TRANSFORM_ROT_90 && !canUseRotator(ctx,mDpy)) {
957 ALOGD_IF(isDebug(), "%s: no free DMA pipe",__FUNCTION__);
958 return false;
959 }
960
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800961 if(isSecuring(ctx, layer)) {
962 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
963 return false;
964 }
965
Saurabh Shah4fdde762013-04-30 18:47:33 -0700966 if(!isValidDimension(ctx, layer)) {
967 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
968 __FUNCTION__);
969 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800970 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700971
Naseer Ahmeddc61a972013-07-10 17:50:54 -0400972 if(layer->planeAlpha < 0xFF) {
973 ALOGD_IF(isDebug(), "%s: Cannot handle YUV layer with plane alpha\
974 in video only mode",
975 __FUNCTION__);
976 return false;
977 }
978
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800979 return true;
980}
981
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530982/* starts at fromIndex and check for each layer to find
983 * if it it has overlapping with any Updating layer above it in zorder
984 * till the end of the batch. returns true if it finds any intersection */
985bool MDPComp::canPushBatchToTop(const hwc_display_contents_1_t* list,
986 int fromIndex, int toIndex) {
987 for(int i = fromIndex; i < toIndex; i++) {
988 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
989 if(intersectingUpdatingLayers(list, i+1, toIndex, i)) {
990 return false;
991 }
992 }
993 }
994 return true;
995}
996
997/* Checks if given layer at targetLayerIndex has any
998 * intersection with all the updating layers in beween
999 * fromIndex and toIndex. Returns true if it finds intersectiion */
1000bool MDPComp::intersectingUpdatingLayers(const hwc_display_contents_1_t* list,
1001 int fromIndex, int toIndex, int targetLayerIndex) {
1002 for(int i = fromIndex; i <= toIndex; i++) {
1003 if(!mCurrentFrame.isFBComposed[i]) {
1004 if(areLayersIntersecting(&list->hwLayers[i],
1005 &list->hwLayers[targetLayerIndex])) {
1006 return true;
1007 }
1008 }
1009 }
1010 return false;
1011}
1012
1013int MDPComp::getBatch(hwc_display_contents_1_t* list,
1014 int& maxBatchStart, int& maxBatchEnd,
1015 int& maxBatchCount) {
1016 int i = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301017 int fbZOrder =-1;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -08001018 int droppedLayerCt = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301019 while (i < mCurrentFrame.layerCount) {
1020 int batchCount = 0;
1021 int batchStart = i;
1022 int batchEnd = i;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -08001023 /* Adjust batch Z order with the dropped layers so far */
1024 int fbZ = batchStart - droppedLayerCt;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301025 int firstZReverseIndex = -1;
Prabhanjan Kandula0ed2cc92013-12-06 12:39:04 +05301026 int updatingLayersAbove = 0;//Updating layer count in middle of batch
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301027 while(i < mCurrentFrame.layerCount) {
1028 if(!mCurrentFrame.isFBComposed[i]) {
1029 if(!batchCount) {
1030 i++;
1031 break;
1032 }
1033 updatingLayersAbove++;
1034 i++;
1035 continue;
1036 } else {
1037 if(mCurrentFrame.drop[i]) {
1038 i++;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -08001039 droppedLayerCt++;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301040 continue;
1041 } else if(updatingLayersAbove <= 0) {
1042 batchCount++;
1043 batchEnd = i;
1044 i++;
1045 continue;
1046 } else { //Layer is FBComposed, not a drop & updatingLayer > 0
1047
1048 // We have a valid updating layer already. If layer-i not
1049 // have overlapping with all updating layers in between
1050 // batch-start and i, then we can add layer i to batch.
1051 if(!intersectingUpdatingLayers(list, batchStart, i-1, i)) {
1052 batchCount++;
1053 batchEnd = i;
1054 i++;
1055 continue;
1056 } else if(canPushBatchToTop(list, batchStart, i)) {
1057 //If All the non-updating layers with in this batch
1058 //does not have intersection with the updating layers
1059 //above in z-order, then we can safely move the batch to
1060 //higher z-order. Increment fbZ as it is moving up.
1061 if( firstZReverseIndex < 0) {
1062 firstZReverseIndex = i;
1063 }
1064 batchCount++;
1065 batchEnd = i;
1066 fbZ += updatingLayersAbove;
1067 i++;
1068 updatingLayersAbove = 0;
1069 continue;
1070 } else {
1071 //both failed.start the loop again from here.
1072 if(firstZReverseIndex >= 0) {
1073 i = firstZReverseIndex;
1074 }
1075 break;
1076 }
1077 }
1078 }
1079 }
1080 if(batchCount > maxBatchCount) {
1081 maxBatchCount = batchCount;
1082 maxBatchStart = batchStart;
1083 maxBatchEnd = batchEnd;
1084 fbZOrder = fbZ;
1085 }
1086 }
1087 return fbZOrder;
1088}
1089
1090bool MDPComp::markLayersForCaching(hwc_context_t* ctx,
1091 hwc_display_contents_1_t* list) {
1092 /* Idea is to keep as many non-updating(cached) layers in FB and
1093 * send rest of them through MDP. This is done in 2 steps.
1094 * 1. Find the maximum contiguous batch of non-updating layers.
1095 * 2. See if we can improve this batch size for caching by adding
1096 * opaque layers around the batch, if they don't have
1097 * any overlapping with the updating layers in between.
1098 * NEVER mark an updating layer for caching.
1099 * But cached ones can be marked for MDP */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001100
1101 int maxBatchStart = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001102 int maxBatchEnd = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001103 int maxBatchCount = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301104 int fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001105
Saurabh Shahd53bc5f2014-02-05 10:17:43 -08001106 /* Nothing is cached. No batching needed */
1107 if(mCurrentFrame.fbCount == 0) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001108 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -07001109 }
Saurabh Shahd53bc5f2014-02-05 10:17:43 -08001110
1111 /* No MDP comp layers, try to use other comp modes */
1112 if(mCurrentFrame.mdpCount == 0) {
1113 return false;
Saurabh Shahaa236822013-04-24 18:07:26 -07001114 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001115
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301116 fbZ = getBatch(list, maxBatchStart, maxBatchEnd, maxBatchCount);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001117
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301118 /* reset rest of the layers lying inside ROI for MDP comp */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001119 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001120 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001121 if((i < maxBatchStart || i > maxBatchEnd) &&
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301122 mCurrentFrame.isFBComposed[i]){
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001123 if(!mCurrentFrame.drop[i]){
1124 //If an unsupported layer is being attempted to
1125 //be pulled out we should fail
1126 if(not isSupportedForMDPComp(ctx, layer)) {
1127 return false;
1128 }
1129 mCurrentFrame.isFBComposed[i] = false;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001130 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001131 }
1132 }
1133
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301134 // update the frame data
1135 mCurrentFrame.fbZ = fbZ;
1136 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001137 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001138 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001139
1140 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301141 mCurrentFrame.fbCount);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001142
1143 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001144}
Saurabh Shah85234ec2013-04-12 17:09:00 -07001145
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001146void MDPComp::updateLayerCache(hwc_context_t* ctx,
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001147 hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001148 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001149 int fbCount = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001150
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001151 for(int i = 0; i < numAppLayers; i++) {
1152 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001153 if(!mCurrentFrame.drop[i])
1154 fbCount++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001155 mCurrentFrame.isFBComposed[i] = true;
1156 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -07001157 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001158 }
1159 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001160
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001161 mCurrentFrame.fbCount = fbCount;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001162 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount
1163 - mCurrentFrame.dropCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001164
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001165 ALOGD_IF(isDebug(),"%s: MDP count: %d FB count %d drop count: %d"
1166 ,__FUNCTION__, mCurrentFrame.mdpCount, mCurrentFrame.fbCount,
1167 mCurrentFrame.dropCount);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001168}
1169
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001170void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list,
1171 bool secureOnly) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001172 int nYuvCount = ctx->listStats[mDpy].yuvCount;
1173 for(int index = 0;index < nYuvCount; index++){
1174 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
1175 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
1176
1177 if(!isYUVDoable(ctx, layer)) {
1178 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
1179 mCurrentFrame.isFBComposed[nYuvIndex] = true;
1180 mCurrentFrame.fbCount++;
1181 }
1182 } else {
1183 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001184 private_handle_t *hnd = (private_handle_t *)layer->handle;
1185 if(!secureOnly || isSecureBuffer(hnd)) {
1186 mCurrentFrame.isFBComposed[nYuvIndex] = false;
1187 mCurrentFrame.fbCount--;
1188 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001189 }
1190 }
1191 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001192
1193 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001194 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
1195 ALOGD_IF(isDebug(),"%s: fb count: %d",__FUNCTION__,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001196 mCurrentFrame.fbCount);
1197}
1198
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001199hwc_rect_t MDPComp::getUpdatingFBRect(hwc_context_t *ctx,
1200 hwc_display_contents_1_t* list){
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001201 hwc_rect_t fbRect = (struct hwc_rect){0, 0, 0, 0};
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001202
1203 /* Update only the region of FB needed for composition */
1204 for(int i = 0; i < mCurrentFrame.layerCount; i++ ) {
1205 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
1206 hwc_layer_1_t* layer = &list->hwLayers[i];
1207 hwc_rect_t dst = layer->displayFrame;
1208 fbRect = getUnion(fbRect, dst);
1209 }
1210 }
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001211 trimAgainstROI(ctx, fbRect);
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001212 return fbRect;
1213}
1214
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001215bool MDPComp::postHeuristicsHandling(hwc_context_t *ctx,
1216 hwc_display_contents_1_t* list) {
1217
1218 //Capability checks
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301219 if(!resourceCheck()) {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001220 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
1221 return false;
1222 }
1223
1224 //Limitations checks
1225 if(!hwLimitationsCheck(ctx, list)) {
1226 ALOGD_IF(isDebug(), "%s: HW limitations",__FUNCTION__);
1227 return false;
1228 }
1229
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001230 //Configure framebuffer first if applicable
1231 if(mCurrentFrame.fbZ >= 0) {
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001232 hwc_rect_t fbRect = getUpdatingFBRect(ctx, list);
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001233 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, fbRect, mCurrentFrame.fbZ))
1234 {
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001235 ALOGD_IF(isDebug(), "%s configure framebuffer failed",
1236 __FUNCTION__);
1237 return false;
1238 }
1239 }
1240
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001241 mCurrentFrame.map();
1242
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001243 if(!allocLayerPipes(ctx, list)) {
1244 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -07001245 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001246 }
1247
1248 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001249 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001250 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001251 int mdpIndex = mCurrentFrame.layerToMDP[index];
1252 hwc_layer_1_t* layer = &list->hwLayers[index];
1253
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301254 //Leave fbZ for framebuffer. CACHE/GLES layers go here.
1255 if(mdpNextZOrder == mCurrentFrame.fbZ) {
1256 mdpNextZOrder++;
1257 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001258 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1259 cur_pipe->zOrder = mdpNextZOrder++;
1260
radhakrishnac9a67412013-09-25 17:40:42 +05301261 private_handle_t *hnd = (private_handle_t *)layer->handle;
1262 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1263 if(configure4k2kYuv(ctx, layer,
1264 mCurrentFrame.mdpToLayer[mdpIndex])
1265 != 0 ){
1266 ALOGD_IF(isDebug(), "%s: Failed to configure split pipes \
1267 for layer %d",__FUNCTION__, index);
1268 return false;
1269 }
1270 else{
1271 mdpNextZOrder++;
1272 }
1273 continue;
1274 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001275 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
1276 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
radhakrishnac9a67412013-09-25 17:40:42 +05301277 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -07001278 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001279 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001280 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001281 }
1282
Saurabh Shaha36be922013-12-16 18:18:39 -08001283 if(!ctx->mOverlay->validateAndSet(mDpy, ctx->dpyAttr[mDpy].fd)) {
1284 ALOGD_IF(isDebug(), "%s: Failed to validate and set overlay for dpy %d"
1285 ,__FUNCTION__, mDpy);
1286 return false;
1287 }
1288
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001289 setRedraw(ctx, list);
Saurabh Shahaa236822013-04-24 18:07:26 -07001290 return true;
1291}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001292
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301293bool MDPComp::resourceCheck() {
Saurabh Shah173f4242013-11-20 09:50:12 -08001294 const bool fbUsed = mCurrentFrame.fbCount;
1295 if(mCurrentFrame.mdpCount > sMaxPipesPerMixer - fbUsed) {
1296 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
1297 return false;
1298 }
Saurabh Shah173f4242013-11-20 09:50:12 -08001299 return true;
1300}
1301
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301302bool MDPComp::hwLimitationsCheck(hwc_context_t* ctx,
1303 hwc_display_contents_1_t* list) {
1304
1305 //A-family hw limitation:
1306 //If a layer need alpha scaling, MDP can not support.
1307 if(ctx->mMDP.version < qdutils::MDSS_V5) {
1308 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1309 if(!mCurrentFrame.isFBComposed[i] &&
1310 isAlphaScaled( &list->hwLayers[i])) {
1311 ALOGD_IF(isDebug(), "%s:frame needs alphaScaling",__FUNCTION__);
1312 return false;
1313 }
1314 }
1315 }
1316
1317 // On 8x26 & 8974 hw, we have a limitation of downscaling+blending.
1318 //If multiple layers requires downscaling and also they are overlapping
1319 //fall back to GPU since MDSS can not handle it.
1320 if(qdutils::MDPVersion::getInstance().is8x74v2() ||
1321 qdutils::MDPVersion::getInstance().is8x26()) {
1322 for(int i = 0; i < mCurrentFrame.layerCount-1; ++i) {
1323 hwc_layer_1_t* botLayer = &list->hwLayers[i];
1324 if(!mCurrentFrame.isFBComposed[i] &&
1325 isDownscaleRequired(botLayer)) {
1326 //if layer-i is marked for MDP and needs downscaling
1327 //check if any MDP layer on top of i & overlaps with layer-i
1328 for(int j = i+1; j < mCurrentFrame.layerCount; ++j) {
1329 hwc_layer_1_t* topLayer = &list->hwLayers[j];
1330 if(!mCurrentFrame.isFBComposed[j] &&
1331 isDownscaleRequired(topLayer)) {
1332 hwc_rect_t r = getIntersection(botLayer->displayFrame,
1333 topLayer->displayFrame);
1334 if(isValidRect(r))
1335 return false;
1336 }
1337 }
1338 }
1339 }
1340 }
1341 return true;
1342}
1343
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001344int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001345 int ret = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -07001346 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -07001347
Raj Kamal9ed3d6b2014-02-07 16:15:17 +05301348 //Do not cache the information for next draw cycle.
1349 if(numLayers > MAX_NUM_APP_LAYERS or (!numLayers)) {
1350 ALOGI("%s: Unsupported layer count for mdp composition",
1351 __FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001352 mCachedFrame.reset();
1353 return -1;
1354 }
1355
Saurabh Shahb39f8152013-08-22 10:21:44 -07001356 //reset old data
1357 mCurrentFrame.reset(numLayers);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001358 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1359 mCurrentFrame.dropCount = 0;
Prabhanjan Kandula088bd892013-07-02 23:47:13 +05301360
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -07001361 // Detect the start of animation and fall back to GPU only once to cache
1362 // all the layers in FB and display FB content untill animation completes.
1363 if(ctx->listStats[mDpy].isDisplayAnimating) {
1364 mCurrentFrame.needsRedraw = false;
1365 if(ctx->mAnimationState[mDpy] == ANIMATION_STOPPED) {
1366 mCurrentFrame.needsRedraw = true;
1367 ctx->mAnimationState[mDpy] = ANIMATION_STARTED;
1368 }
1369 setMDPCompLayerFlags(ctx, list);
1370 mCachedFrame.updateCounts(mCurrentFrame);
1371 ret = -1;
1372 return ret;
1373 } else {
1374 ctx->mAnimationState[mDpy] = ANIMATION_STOPPED;
1375 }
1376
Saurabh Shahb39f8152013-08-22 10:21:44 -07001377 //Hard conditions, if not met, cannot do MDP comp
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001378 if(isFrameDoable(ctx)) {
1379 generateROI(ctx, list);
Saurabh Shahb39f8152013-08-22 10:21:44 -07001380
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001381 if(tryFullFrame(ctx, list) || tryVideoOnly(ctx, list)) {
1382 setMDPCompLayerFlags(ctx, list);
1383 } else {
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001384 resetROI(ctx, mDpy);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001385 reset(ctx);
1386 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1387 mCurrentFrame.dropCount = 0;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001388 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001389 }
1390 } else {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001391 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
1392 __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001393 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001394 }
Saurabh Shahb39f8152013-08-22 10:21:44 -07001395
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001396 if(isDebug()) {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001397 ALOGD("GEOMETRY change: %d",
1398 (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001399 android::String8 sDump("");
1400 dump(sDump);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001401 ALOGD("%s",sDump.string());
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001402 }
1403
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001404 mCachedFrame.cacheAll(list);
1405 mCachedFrame.updateCounts(mCurrentFrame);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001406 return ret;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001407}
1408
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001409bool MDPComp::allocSplitVGPipesfor4k2k(hwc_context_t *ctx, int index) {
radhakrishnac9a67412013-09-25 17:40:42 +05301410
1411 bool bRet = true;
radhakrishnac9a67412013-09-25 17:40:42 +05301412 int mdpIndex = mCurrentFrame.layerToMDP[index];
1413 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
1414 info.pipeInfo = new MdpYUVPipeInfo;
1415 info.rot = NULL;
1416 MdpYUVPipeInfo& pipe_info = *(MdpYUVPipeInfo*)info.pipeInfo;
radhakrishnac9a67412013-09-25 17:40:42 +05301417
1418 pipe_info.lIndex = ovutils::OV_INVALID;
1419 pipe_info.rIndex = ovutils::OV_INVALID;
1420
Saurabh Shahc62f3982014-03-05 14:28:26 -08001421 Overlay::PipeSpecs pipeSpecs;
1422 pipeSpecs.formatClass = Overlay::FORMAT_YUV;
1423 pipeSpecs.needsScaling = true;
1424 pipeSpecs.dpy = mDpy;
1425 pipeSpecs.fb = false;
1426
1427 pipe_info.lIndex = ctx->mOverlay->getPipe(pipeSpecs);
radhakrishnac9a67412013-09-25 17:40:42 +05301428 if(pipe_info.lIndex == ovutils::OV_INVALID){
1429 bRet = false;
1430 ALOGD_IF(isDebug(),"%s: allocating first VG pipe failed",
1431 __FUNCTION__);
1432 }
Saurabh Shahc62f3982014-03-05 14:28:26 -08001433 pipe_info.rIndex = ctx->mOverlay->getPipe(pipeSpecs);
radhakrishnac9a67412013-09-25 17:40:42 +05301434 if(pipe_info.rIndex == ovutils::OV_INVALID){
1435 bRet = false;
1436 ALOGD_IF(isDebug(),"%s: allocating second VG pipe failed",
1437 __FUNCTION__);
1438 }
1439 return bRet;
1440}
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001441//=============MDPCompNonSplit==================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001442
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001443void MDPCompNonSplit::adjustForSourceSplit(hwc_context_t *ctx,
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001444 hwc_display_contents_1_t*) {
radhakrishnac9a67412013-09-25 17:40:42 +05301445 //As we split 4kx2k yuv layer and program to 2 VG pipes
1446 //(if available) increase mdpcount accordingly
1447 mCurrentFrame.mdpCount += ctx->listStats[mDpy].yuv4k2kCount;
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001448
1449 //If 4k2k Yuv layer split is possible, and if
1450 //fbz is above 4k2k layer, increment fb zorder by 1
1451 //as we split 4k2k layer and increment zorder for right half
1452 //of the layer
1453 if(mCurrentFrame.fbZ >= 0) {
1454 int n4k2kYuvCount = ctx->listStats[mDpy].yuv4k2kCount;
1455 for(int index = 0; index < n4k2kYuvCount; index++){
1456 int n4k2kYuvIndex =
1457 ctx->listStats[mDpy].yuv4k2kIndices[index];
Dileep Kumar Reddi4cff9282014-04-01 12:57:08 +05301458 if(mCurrentFrame.fbZ >= n4k2kYuvIndex){
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001459 mCurrentFrame.fbZ += 1;
1460 }
1461 }
1462 }
radhakrishnac9a67412013-09-25 17:40:42 +05301463}
1464
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001465/*
1466 * Configures pipe(s) for MDP composition
1467 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001468int MDPCompNonSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001469 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001470 MdpPipeInfoNonSplit& mdp_info =
1471 *(static_cast<MdpPipeInfoNonSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001472 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
1473 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1474 eIsFg isFg = IS_FG_OFF;
1475 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001476
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001477 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
1478 __FUNCTION__, layer, zOrder, dest);
1479
Saurabh Shah88e4d272013-09-03 13:31:29 -07001480 return configureNonSplit(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001481 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001482}
1483
Saurabh Shah88e4d272013-09-03 13:31:29 -07001484bool MDPCompNonSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001485 hwc_display_contents_1_t* list) {
1486 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001487
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001488 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001489
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001490 hwc_layer_1_t* layer = &list->hwLayers[index];
1491 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301492 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001493 if(allocSplitVGPipesfor4k2k(ctx, index)){
radhakrishnac9a67412013-09-25 17:40:42 +05301494 continue;
1495 }
1496 }
1497
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001498 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001499 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001500 info.pipeInfo = new MdpPipeInfoNonSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08001501 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001502 MdpPipeInfoNonSplit& pipe_info = *(MdpPipeInfoNonSplit*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001503
Saurabh Shahc62f3982014-03-05 14:28:26 -08001504 Overlay::PipeSpecs pipeSpecs;
1505 pipeSpecs.formatClass = isYuvBuffer(hnd) ?
1506 Overlay::FORMAT_YUV : Overlay::FORMAT_RGB;
1507 pipeSpecs.needsScaling = qhwc::needsScaling(layer) or
1508 (qdutils::MDPVersion::getInstance().is8x26() and
1509 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres > 1024);
1510 pipeSpecs.dpy = mDpy;
1511 pipeSpecs.fb = false;
Xu Yang1e686f62014-04-08 13:56:47 +08001512 pipeSpecs.numActiveDisplays = ctx->numActiveDisplays;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001513
Saurabh Shahc62f3982014-03-05 14:28:26 -08001514 pipe_info.index = ctx->mOverlay->getPipe(pipeSpecs);
1515
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001516 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001517 ALOGD_IF(isDebug(), "%s: Unable to get pipe", __FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001518 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001519 }
1520 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001521 return true;
1522}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001523
radhakrishnac9a67412013-09-25 17:40:42 +05301524int MDPCompNonSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1525 PipeLayerPair& PipeLayerPair) {
1526 MdpYUVPipeInfo& mdp_info =
1527 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1528 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1529 eIsFg isFg = IS_FG_OFF;
1530 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1531 eDest lDest = mdp_info.lIndex;
1532 eDest rDest = mdp_info.rIndex;
1533
1534 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1535 lDest, rDest, &PipeLayerPair.rot);
1536}
1537
Saurabh Shah88e4d272013-09-03 13:31:29 -07001538bool MDPCompNonSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001539
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001540 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001541 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1542 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -08001543 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001544
1545 if(!ctx || !list) {
1546 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001547 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001548 }
1549
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301550 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1551 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1552 return true;
1553 }
1554
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -08001555 // Set the Handle timeout to true for MDP or MIXED composition.
1556 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount) {
1557 sHandleTimeout = true;
1558 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001559
1560 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001561 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001562
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001563 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1564 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001565 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001566 if(mCurrentFrame.isFBComposed[i]) continue;
1567
Naseer Ahmed5b6708a2012-08-02 13:46:08 -07001568 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001569 private_handle_t *hnd = (private_handle_t *)layer->handle;
1570 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001571 if (!(layer->flags & HWC_COLOR_FILL)) {
1572 ALOGE("%s handle null", __FUNCTION__);
1573 return false;
1574 }
1575 // No PLAY for Color layer
1576 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1577 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001578 }
1579
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001580 int mdpIndex = mCurrentFrame.layerToMDP[i];
1581
radhakrishnac9a67412013-09-25 17:40:42 +05301582 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1583 {
1584 MdpYUVPipeInfo& pipe_info =
1585 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1586 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1587 ovutils::eDest indexL = pipe_info.lIndex;
1588 ovutils::eDest indexR = pipe_info.rIndex;
1589 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301590 uint32_t offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05301591 if(rot) {
1592 rot->queueBuffer(fd, offset);
1593 fd = rot->getDstMemId();
1594 offset = rot->getDstOffset();
1595 }
1596 if(indexL != ovutils::OV_INVALID) {
1597 ovutils::eDest destL = (ovutils::eDest)indexL;
1598 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1599 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1600 if (!ov.queueBuffer(fd, offset, destL)) {
1601 ALOGE("%s: queueBuffer failed for display:%d",
1602 __FUNCTION__, mDpy);
1603 return false;
1604 }
1605 }
1606
1607 if(indexR != ovutils::OV_INVALID) {
1608 ovutils::eDest destR = (ovutils::eDest)indexR;
1609 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1610 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1611 if (!ov.queueBuffer(fd, offset, destR)) {
1612 ALOGE("%s: queueBuffer failed for display:%d",
1613 __FUNCTION__, mDpy);
1614 return false;
1615 }
1616 }
1617 }
1618 else{
1619 MdpPipeInfoNonSplit& pipe_info =
Saurabh Shah88e4d272013-09-03 13:31:29 -07001620 *(MdpPipeInfoNonSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
radhakrishnac9a67412013-09-25 17:40:42 +05301621 ovutils::eDest dest = pipe_info.index;
1622 if(dest == ovutils::OV_INVALID) {
1623 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001624 return false;
radhakrishnac9a67412013-09-25 17:40:42 +05301625 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001626
radhakrishnac9a67412013-09-25 17:40:42 +05301627 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1628 continue;
1629 }
1630
1631 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1632 using pipe: %d", __FUNCTION__, layer,
1633 hnd, dest );
1634
1635 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301636 uint32_t offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05301637
1638 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1639 if(rot) {
1640 if(!rot->queueBuffer(fd, offset))
1641 return false;
1642 fd = rot->getDstMemId();
1643 offset = rot->getDstOffset();
1644 }
1645
1646 if (!ov.queueBuffer(fd, offset, dest)) {
1647 ALOGE("%s: queueBuffer failed for display:%d ",
1648 __FUNCTION__, mDpy);
1649 return false;
1650 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001651 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001652
1653 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001654 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001655 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001656}
1657
Saurabh Shah88e4d272013-09-03 13:31:29 -07001658//=============MDPCompSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001659
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001660void MDPCompSplit::adjustForSourceSplit(hwc_context_t *ctx,
radhakrishnac9a67412013-09-25 17:40:42 +05301661 hwc_display_contents_1_t* list){
1662 //if 4kx2k yuv layer is totally present in either in left half
1663 //or right half then try splitting the yuv layer to avoid decimation
1664 int n4k2kYuvCount = ctx->listStats[mDpy].yuv4k2kCount;
1665 const int lSplit = getLeftSplit(ctx, mDpy);
1666 for(int index = 0; index < n4k2kYuvCount; index++){
1667 int n4k2kYuvIndex = ctx->listStats[mDpy].yuv4k2kIndices[index];
1668 hwc_layer_1_t* layer = &list->hwLayers[n4k2kYuvIndex];
1669 hwc_rect_t dst = layer->displayFrame;
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001670 if((dst.left > lSplit) || (dst.right < lSplit)) {
radhakrishnac9a67412013-09-25 17:40:42 +05301671 mCurrentFrame.mdpCount += 1;
1672 }
Dileep Kumar Reddi4cff9282014-04-01 12:57:08 +05301673 if(mCurrentFrame.fbZ >= n4k2kYuvIndex){
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001674 mCurrentFrame.fbZ += 1;
1675 }
radhakrishnac9a67412013-09-25 17:40:42 +05301676 }
1677}
1678
Saurabh Shah88e4d272013-09-03 13:31:29 -07001679bool MDPCompSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Saurabh Shahc62f3982014-03-05 14:28:26 -08001680 MdpPipeInfoSplit& pipe_info) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001681
Saurabh Shahc62f3982014-03-05 14:28:26 -08001682 const int lSplit = getLeftSplit(ctx, mDpy);
1683 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001684 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001685 pipe_info.lIndex = ovutils::OV_INVALID;
1686 pipe_info.rIndex = ovutils::OV_INVALID;
1687
Saurabh Shahc62f3982014-03-05 14:28:26 -08001688 Overlay::PipeSpecs pipeSpecs;
1689 pipeSpecs.formatClass = isYuvBuffer(hnd) ?
1690 Overlay::FORMAT_YUV : Overlay::FORMAT_RGB;
1691 pipeSpecs.needsScaling = qhwc::needsScalingWithSplit(ctx, layer, mDpy);
1692 pipeSpecs.dpy = mDpy;
1693 pipeSpecs.mixer = Overlay::MIXER_LEFT;
1694 pipeSpecs.fb = false;
1695
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001696 // Acquire pipe only for the updating half
1697 hwc_rect_t l_roi = ctx->listStats[mDpy].lRoi;
1698 hwc_rect_t r_roi = ctx->listStats[mDpy].rRoi;
1699
1700 if (dst.left < lSplit && isValidRect(getIntersection(dst, l_roi))) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001701 pipe_info.lIndex = ctx->mOverlay->getPipe(pipeSpecs);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001702 if(pipe_info.lIndex == ovutils::OV_INVALID)
1703 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001704 }
1705
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001706 if(dst.right > lSplit && isValidRect(getIntersection(dst, r_roi))) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001707 pipeSpecs.mixer = Overlay::MIXER_RIGHT;
1708 pipe_info.rIndex = ctx->mOverlay->getPipe(pipeSpecs);
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001709 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001710 return false;
1711 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001712
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001713 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001714}
1715
Saurabh Shah88e4d272013-09-03 13:31:29 -07001716bool MDPCompSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001717 hwc_display_contents_1_t* list) {
1718 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001719
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001720 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001721
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001722 hwc_layer_1_t* layer = &list->hwLayers[index];
1723 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301724 hwc_rect_t dst = layer->displayFrame;
1725 const int lSplit = getLeftSplit(ctx, mDpy);
1726 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1727 if((dst.left > lSplit)||(dst.right < lSplit)){
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001728 if(allocSplitVGPipesfor4k2k(ctx, index)){
radhakrishnac9a67412013-09-25 17:40:42 +05301729 continue;
1730 }
1731 }
1732 }
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001733 int mdpIndex = mCurrentFrame.layerToMDP[index];
1734 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001735 info.pipeInfo = new MdpPipeInfoSplit;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001736 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001737 MdpPipeInfoSplit& pipe_info = *(MdpPipeInfoSplit*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001738
Saurabh Shahc62f3982014-03-05 14:28:26 -08001739 if(!acquireMDPPipes(ctx, layer, pipe_info)) {
1740 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type",
1741 __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001742 return false;
1743 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001744 }
1745 return true;
1746}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001747
radhakrishnac9a67412013-09-25 17:40:42 +05301748int MDPCompSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1749 PipeLayerPair& PipeLayerPair) {
1750 const int lSplit = getLeftSplit(ctx, mDpy);
1751 hwc_rect_t dst = layer->displayFrame;
1752 if((dst.left > lSplit)||(dst.right < lSplit)){
1753 MdpYUVPipeInfo& mdp_info =
1754 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1755 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1756 eIsFg isFg = IS_FG_OFF;
1757 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1758 eDest lDest = mdp_info.lIndex;
1759 eDest rDest = mdp_info.rIndex;
1760
1761 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1762 lDest, rDest, &PipeLayerPair.rot);
1763 }
1764 else{
1765 return configure(ctx, layer, PipeLayerPair);
1766 }
1767}
1768
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001769/*
1770 * Configures pipe(s) for MDP composition
1771 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001772int MDPCompSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001773 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001774 MdpPipeInfoSplit& mdp_info =
1775 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001776 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1777 eIsFg isFg = IS_FG_OFF;
1778 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1779 eDest lDest = mdp_info.lIndex;
1780 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001781
1782 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1783 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1784
Saurabh Shah88e4d272013-09-03 13:31:29 -07001785 return configureSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001786 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001787}
1788
Saurabh Shah88e4d272013-09-03 13:31:29 -07001789bool MDPCompSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001790
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001791 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001792 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1793 return true;
1794 }
1795
1796 if(!ctx || !list) {
1797 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001798 return false;
1799 }
1800
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301801 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1802 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1803 return true;
1804 }
1805
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -08001806 // Set the Handle timeout to true for MDP or MIXED composition.
1807 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount) {
1808 sHandleTimeout = true;
1809 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001810
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001811 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001812 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001813
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001814 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1815 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001816 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001817 if(mCurrentFrame.isFBComposed[i]) continue;
1818
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001819 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001820 private_handle_t *hnd = (private_handle_t *)layer->handle;
1821 if(!hnd) {
1822 ALOGE("%s handle null", __FUNCTION__);
1823 return false;
1824 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001825
1826 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1827 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001828 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001829
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001830 int mdpIndex = mCurrentFrame.layerToMDP[i];
1831
radhakrishnac9a67412013-09-25 17:40:42 +05301832 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1833 {
1834 MdpYUVPipeInfo& pipe_info =
1835 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1836 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1837 ovutils::eDest indexL = pipe_info.lIndex;
1838 ovutils::eDest indexR = pipe_info.rIndex;
1839 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301840 uint32_t offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05301841 if(rot) {
1842 rot->queueBuffer(fd, offset);
1843 fd = rot->getDstMemId();
1844 offset = rot->getDstOffset();
1845 }
1846 if(indexL != ovutils::OV_INVALID) {
1847 ovutils::eDest destL = (ovutils::eDest)indexL;
1848 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1849 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1850 if (!ov.queueBuffer(fd, offset, destL)) {
1851 ALOGE("%s: queueBuffer failed for display:%d",
1852 __FUNCTION__, mDpy);
1853 return false;
1854 }
1855 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001856
radhakrishnac9a67412013-09-25 17:40:42 +05301857 if(indexR != ovutils::OV_INVALID) {
1858 ovutils::eDest destR = (ovutils::eDest)indexR;
1859 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1860 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1861 if (!ov.queueBuffer(fd, offset, destR)) {
1862 ALOGE("%s: queueBuffer failed for display:%d",
1863 __FUNCTION__, mDpy);
1864 return false;
1865 }
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001866 }
1867 }
radhakrishnac9a67412013-09-25 17:40:42 +05301868 else{
1869 MdpPipeInfoSplit& pipe_info =
1870 *(MdpPipeInfoSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1871 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001872
radhakrishnac9a67412013-09-25 17:40:42 +05301873 ovutils::eDest indexL = pipe_info.lIndex;
1874 ovutils::eDest indexR = pipe_info.rIndex;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001875
radhakrishnac9a67412013-09-25 17:40:42 +05301876 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301877 int offset = (uint32_t)hnd->offset;
radhakrishnac9a67412013-09-25 17:40:42 +05301878
Tatenda Chipeperekwa88fe6352014-04-14 10:36:06 -07001879 if(ctx->mAD->draw(ctx, fd, offset)) {
1880 fd = ctx->mAD->getDstFd();
1881 offset = ctx->mAD->getDstOffset();
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001882 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001883
radhakrishnac9a67412013-09-25 17:40:42 +05301884 if(rot) {
1885 rot->queueBuffer(fd, offset);
1886 fd = rot->getDstMemId();
1887 offset = rot->getDstOffset();
1888 }
1889
1890 //************* play left mixer **********
1891 if(indexL != ovutils::OV_INVALID) {
1892 ovutils::eDest destL = (ovutils::eDest)indexL;
1893 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1894 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1895 if (!ov.queueBuffer(fd, offset, destL)) {
1896 ALOGE("%s: queueBuffer failed for left mixer",
1897 __FUNCTION__);
1898 return false;
1899 }
1900 }
1901
1902 //************* play right mixer **********
1903 if(indexR != ovutils::OV_INVALID) {
1904 ovutils::eDest destR = (ovutils::eDest)indexR;
1905 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1906 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1907 if (!ov.queueBuffer(fd, offset, destR)) {
1908 ALOGE("%s: queueBuffer failed for right mixer",
1909 __FUNCTION__);
1910 return false;
1911 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001912 }
1913 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001914
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001915 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1916 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001917
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001918 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001919}
Saurabh Shahab47c692014-02-12 18:45:57 -08001920
1921//================MDPCompSrcSplit==============================================
1922bool MDPCompSrcSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Saurabh Shahc62f3982014-03-05 14:28:26 -08001923 MdpPipeInfoSplit& pipe_info) {
Saurabh Shahab47c692014-02-12 18:45:57 -08001924 private_handle_t *hnd = (private_handle_t *)layer->handle;
1925 hwc_rect_t dst = layer->displayFrame;
1926 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
1927 pipe_info.lIndex = ovutils::OV_INVALID;
1928 pipe_info.rIndex = ovutils::OV_INVALID;
1929
1930 //If 2 pipes are staged on a single stage of a mixer, then the left pipe
1931 //should have a higher priority than the right one. Pipe priorities are
1932 //starting with VG0, VG1 ... , RGB0 ..., DMA1
Saurabh Shahab47c692014-02-12 18:45:57 -08001933
Saurabh Shahc62f3982014-03-05 14:28:26 -08001934 Overlay::PipeSpecs pipeSpecs;
1935 pipeSpecs.formatClass = isYuvBuffer(hnd) ?
1936 Overlay::FORMAT_YUV : Overlay::FORMAT_RGB;
1937 pipeSpecs.needsScaling = qhwc::needsScaling(layer);
1938 pipeSpecs.dpy = mDpy;
1939 pipeSpecs.fb = false;
1940
Saurabh Shahab47c692014-02-12 18:45:57 -08001941 //1 pipe by default for a layer
Saurabh Shahc62f3982014-03-05 14:28:26 -08001942 pipe_info.lIndex = ctx->mOverlay->getPipe(pipeSpecs);
Saurabh Shahab47c692014-02-12 18:45:57 -08001943 if(pipe_info.lIndex == ovutils::OV_INVALID) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001944 return false;
Saurabh Shahab47c692014-02-12 18:45:57 -08001945 }
1946
1947 //If layer's crop width or dest width > 2048, use 2 pipes
1948 if((dst.right - dst.left) > qdutils::MAX_DISPLAY_DIM or
1949 (crop.right - crop.left) > qdutils::MAX_DISPLAY_DIM) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001950 pipe_info.rIndex = ctx->mOverlay->getPipe(pipeSpecs);
Saurabh Shahab47c692014-02-12 18:45:57 -08001951 if(pipe_info.rIndex == ovutils::OV_INVALID) {
Saurabh Shahc62f3982014-03-05 14:28:26 -08001952 return false;
Saurabh Shahdd8237a2014-02-28 14:29:09 -08001953 }
1954
1955 // Return values
1956 // 1 Left pipe is higher priority, do nothing.
1957 // 0 Pipes of same priority.
1958 //-1 Right pipe is of higher priority, needs swap.
1959 if(ctx->mOverlay->comparePipePriority(pipe_info.lIndex,
1960 pipe_info.rIndex) == -1) {
1961 qhwc::swap(pipe_info.lIndex, pipe_info.rIndex);
Saurabh Shahab47c692014-02-12 18:45:57 -08001962 }
1963 }
1964
1965 return true;
1966}
1967
Saurabh Shahab47c692014-02-12 18:45:57 -08001968int MDPCompSrcSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
1969 PipeLayerPair& PipeLayerPair) {
1970 private_handle_t *hnd = (private_handle_t *)layer->handle;
1971 if(!hnd) {
1972 ALOGE("%s: layer handle is NULL", __FUNCTION__);
1973 return -1;
1974 }
1975 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
1976 MdpPipeInfoSplit& mdp_info =
1977 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
1978 Rotator **rot = &PipeLayerPair.rot;
1979 eZorder z = static_cast<eZorder>(mdp_info.zOrder);
1980 eIsFg isFg = IS_FG_OFF;
1981 eDest lDest = mdp_info.lIndex;
1982 eDest rDest = mdp_info.rIndex;
1983 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
1984 hwc_rect_t dst = layer->displayFrame;
1985 int transform = layer->transform;
1986 eTransform orient = static_cast<eTransform>(transform);
1987 const int downscale = 0;
1988 int rotFlags = ROT_FLAGS_NONE;
1989 uint32_t format = ovutils::getMdpFormat(hnd->format, isTileRendered(hnd));
1990 Whf whf(getWidth(hnd), getHeight(hnd), format, hnd->size);
1991
1992 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1993 "dest_pipeR: %d",__FUNCTION__, layer, z, lDest, rDest);
1994
1995 // Handle R/B swap
1996 if (layer->flags & HWC_FORMAT_RB_SWAP) {
1997 if (hnd->format == HAL_PIXEL_FORMAT_RGBA_8888)
1998 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRA_8888);
1999 else if (hnd->format == HAL_PIXEL_FORMAT_RGBX_8888)
2000 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRX_8888);
2001 }
2002
Saurabh Shah97e2d802014-04-14 18:03:54 -07002003 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
2004 setMdpFlags(layer, mdpFlags, 0, transform);
Saurabh Shahab47c692014-02-12 18:45:57 -08002005
2006 if(lDest != OV_INVALID && rDest != OV_INVALID) {
2007 //Enable overfetch
Saurabh Shah97e2d802014-04-14 18:03:54 -07002008 setMdpFlags(mdpFlags, OV_MDSS_MDP_DUAL_PIPE);
Saurabh Shahab47c692014-02-12 18:45:57 -08002009 }
2010
2011 if(isYuvBuffer(hnd) && (transform & HWC_TRANSFORM_ROT_90)) {
2012 (*rot) = ctx->mRotMgr->getNext();
2013 if((*rot) == NULL) return -1;
Saurabh Shah39240c92014-03-31 10:31:42 -07002014 ctx->mLayerRotMap[mDpy]->add(layer, *rot);
Saurabh Shahab47c692014-02-12 18:45:57 -08002015 //Configure rotator for pre-rotation
Saurabh Shah97e2d802014-04-14 18:03:54 -07002016 if(configRotator(*rot, whf, crop, mdpFlags, orient, downscale) < 0) {
Saurabh Shahab47c692014-02-12 18:45:57 -08002017 ALOGE("%s: configRotator failed!", __FUNCTION__);
2018 return -1;
2019 }
Saurabh Shahab47c692014-02-12 18:45:57 -08002020 whf.format = (*rot)->getDstFormat();
2021 updateSource(orient, whf, crop);
2022 rotFlags |= ROT_PREROTATED;
2023 }
2024
2025 //If 2 pipes being used, divide layer into half, crop and dst
2026 hwc_rect_t cropL = crop;
2027 hwc_rect_t cropR = crop;
2028 hwc_rect_t dstL = dst;
2029 hwc_rect_t dstR = dst;
2030 if(lDest != OV_INVALID && rDest != OV_INVALID) {
2031 cropL.right = (crop.right + crop.left) / 2;
2032 cropR.left = cropL.right;
2033 sanitizeSourceCrop(cropL, cropR, hnd);
2034
2035 //Swap crops on H flip since 2 pipes are being used
2036 if((orient & OVERLAY_TRANSFORM_FLIP_H) && (*rot) == NULL) {
2037 hwc_rect_t tmp = cropL;
2038 cropL = cropR;
2039 cropR = tmp;
2040 }
2041
2042 dstL.right = (dst.right + dst.left) / 2;
2043 dstR.left = dstL.right;
2044 }
2045
2046 //For the mdp, since either we are pre-rotating or MDP does flips
2047 orient = OVERLAY_TRANSFORM_0;
2048 transform = 0;
2049
2050 //configure left pipe
2051 if(lDest != OV_INVALID) {
Saurabh Shah97e2d802014-04-14 18:03:54 -07002052 PipeArgs pargL(mdpFlags, whf, z, isFg,
Saurabh Shahab47c692014-02-12 18:45:57 -08002053 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2054 (ovutils::eBlending) getBlending(layer->blending));
2055
2056 if(configMdp(ctx->mOverlay, pargL, orient,
2057 cropL, dstL, metadata, lDest) < 0) {
2058 ALOGE("%s: commit failed for left mixer config", __FUNCTION__);
2059 return -1;
2060 }
2061 }
2062
2063 //configure right pipe
2064 if(rDest != OV_INVALID) {
Saurabh Shah97e2d802014-04-14 18:03:54 -07002065 PipeArgs pargR(mdpFlags, whf, z, isFg,
Saurabh Shahab47c692014-02-12 18:45:57 -08002066 static_cast<eRotFlags>(rotFlags),
2067 layer->planeAlpha,
2068 (ovutils::eBlending) getBlending(layer->blending));
2069 if(configMdp(ctx->mOverlay, pargR, orient,
2070 cropR, dstR, metadata, rDest) < 0) {
2071 ALOGE("%s: commit failed for right mixer config", __FUNCTION__);
2072 return -1;
2073 }
2074 }
2075
2076 return 0;
2077}
2078
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002079}; //namespace
2080