blob: 028af475d8125c1c1b0a340b1f716da70b592038 [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 Sankaran6a9bb9e2013-08-01 14:19:26 -070045bool MDPComp::sEnablePartialFrameUpdate = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080046int MDPComp::sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
radhakrishnac9a67412013-09-25 17:40:42 +053047bool MDPComp::sEnable4k2kYUVSplit = false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070048
Saurabh Shah88e4d272013-09-03 13:31:29 -070049MDPComp* MDPComp::getObject(hwc_context_t *ctx, const int& dpy) {
50 if(isDisplaySplit(ctx, dpy)) {
Saurabh Shahab47c692014-02-12 18:45:57 -080051 if(qdutils::MDPVersion::getInstance().isSrcSplit()) {
52 return new MDPCompSrcSplit(dpy);
53 }
Saurabh Shah88e4d272013-09-03 13:31:29 -070054 return new MDPCompSplit(dpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080055 }
Saurabh Shah88e4d272013-09-03 13:31:29 -070056 return new MDPCompNonSplit(dpy);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080057}
58
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080059MDPComp::MDPComp(int dpy):mDpy(dpy){};
60
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080061void MDPComp::dump(android::String8& buf)
62{
Jeykumar Sankaran3c6bb042013-08-15 14:01:04 -070063 if(mCurrentFrame.layerCount > MAX_NUM_APP_LAYERS)
64 return;
65
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080066 dumpsys_log(buf,"HWC Map for Dpy: %s \n",
Jeykumar Sankaran27dee262013-08-01 17:09:54 -070067 (mDpy == 0) ? "\"PRIMARY\"" :
68 (mDpy == 1) ? "\"EXTERNAL\"" : "\"VIRTUAL\"");
Saurabh Shahe9bc60f2013-08-29 12:58:06 -070069 dumpsys_log(buf,"CURR_FRAME: layerCount:%2d mdpCount:%2d "
70 "fbCount:%2d \n", mCurrentFrame.layerCount,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080071 mCurrentFrame.mdpCount, mCurrentFrame.fbCount);
72 dumpsys_log(buf,"needsFBRedraw:%3s pipesUsed:%2d MaxPipesPerMixer: %d \n",
73 (mCurrentFrame.needsRedraw? "YES" : "NO"),
74 mCurrentFrame.mdpCount, sMaxPipesPerMixer);
75 dumpsys_log(buf," --------------------------------------------- \n");
76 dumpsys_log(buf," listIdx | cached? | mdpIndex | comptype | Z \n");
77 dumpsys_log(buf," --------------------------------------------- \n");
78 for(int index = 0; index < mCurrentFrame.layerCount; index++ )
79 dumpsys_log(buf," %7d | %7s | %8d | %9s | %2d \n",
80 index,
81 (mCurrentFrame.isFBComposed[index] ? "YES" : "NO"),
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -070082 mCurrentFrame.layerToMDP[index],
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080083 (mCurrentFrame.isFBComposed[index] ?
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -070084 (mCurrentFrame.drop[index] ? "DROP" :
85 (mCurrentFrame.needsRedraw ? "GLES" : "CACHE")) : "MDP"),
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080086 (mCurrentFrame.isFBComposed[index] ? mCurrentFrame.fbZ :
87 mCurrentFrame.mdpToLayer[mCurrentFrame.layerToMDP[index]].pipeInfo->zOrder));
88 dumpsys_log(buf,"\n");
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080089}
90
91bool MDPComp::init(hwc_context_t *ctx) {
92
93 if(!ctx) {
94 ALOGE("%s: Invalid hwc context!!",__FUNCTION__);
95 return false;
96 }
97
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080098 char property[PROPERTY_VALUE_MAX];
99
100 sEnabled = false;
101 if((property_get("persist.hwc.mdpcomp.enable", property, NULL) > 0) &&
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800102 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
103 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800104 sEnabled = true;
105 }
106
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700107 sEnableMixedMode = true;
108 if((property_get("debug.mdpcomp.mixedmode.disable", property, NULL) > 0) &&
109 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
110 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
111 sEnableMixedMode = false;
112 }
113
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800114 if(property_get("debug.mdpcomp.logs", property, NULL) > 0) {
115 if(atoi(property) != 0)
116 sDebugLogs = true;
117 }
118
Jeykumar Sankaran7d6c4c02014-02-19 12:40:57 -0800119 if(property_get("persist.hwc.partialupdate", property, NULL) > 0) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700120 if((atoi(property) != 0) && ctx->mMDP.panel == MIPI_CMD_PANEL &&
121 qdutils::MDPVersion::getInstance().is8x74v2())
122 sEnablePartialFrameUpdate = true;
123 }
124 ALOGE_IF(isDebug(), "%s: Partial Update applicable?: %d",__FUNCTION__,
125 sEnablePartialFrameUpdate);
126
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800127 sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
Saurabh Shah85234ec2013-04-12 17:09:00 -0700128 if(property_get("debug.mdpcomp.maxpermixer", property, "-1") > 0) {
129 int val = atoi(property);
130 if(val >= 0)
131 sMaxPipesPerMixer = min(val, MAX_PIPES_PER_MIXER);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800132 }
133
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400134 if(ctx->mMDP.panel != MIPI_CMD_PANEL) {
135 // Idle invalidation is not necessary on command mode panels
136 long idle_timeout = DEFAULT_IDLE_TIME;
137 if(property_get("debug.mdpcomp.idletime", property, NULL) > 0) {
138 if(atoi(property) != 0)
139 idle_timeout = atoi(property);
140 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800141
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400142 //create Idle Invalidator only when not disabled through property
143 if(idle_timeout != -1)
144 idleInvalidator = IdleInvalidator::getInstance();
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800145
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400146 if(idleInvalidator == NULL) {
147 ALOGE("%s: failed to instantiate idleInvalidator object",
148 __FUNCTION__);
149 } else {
150 idleInvalidator->init(timeout_handler, ctx, idle_timeout);
151 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800152 }
radhakrishnac9a67412013-09-25 17:40:42 +0530153
154 if((property_get("debug.mdpcomp.4k2kSplit", property, "0") > 0) &&
155 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
156 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
157 sEnable4k2kYUVSplit = true;
158 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700159 return true;
160}
161
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800162void MDPComp::reset(hwc_context_t *ctx) {
163 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700164 mCurrentFrame.reset(numLayers);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800165 ctx->mOverlay->clear(mDpy);
166 ctx->mLayerRotMap[mDpy]->clear();
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700167}
168
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700169void MDPComp::timeout_handler(void *udata) {
170 struct hwc_context_t* ctx = (struct hwc_context_t*)(udata);
171
172 if(!ctx) {
173 ALOGE("%s: received empty data in timer callback", __FUNCTION__);
174 return;
175 }
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -0800176 Locker::Autolock _l(ctx->mDrawLock);
177 // Handle timeout event only if the previous composition is MDP or MIXED.
178 if(!sHandleTimeout) {
179 ALOGD_IF(isDebug(), "%s:Do not handle this timeout", __FUNCTION__);
180 return;
181 }
Jesse Hall3be78d92012-08-21 15:12:23 -0700182 if(!ctx->proc) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700183 ALOGE("%s: HWC proc not registered", __FUNCTION__);
184 return;
185 }
186 sIdleFallBack = true;
187 /* Trigger SF to redraw the current frame */
Jesse Hall3be78d92012-08-21 15:12:23 -0700188 ctx->proc->invalidate(ctx->proc);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700189}
190
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800191void MDPComp::setMDPCompLayerFlags(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800192 hwc_display_contents_1_t* list) {
193 LayerProp *layerProp = ctx->layerProp[mDpy];
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800194
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800195 for(int index = 0; index < ctx->listStats[mDpy].numAppLayers; index++) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800196 hwc_layer_1_t* layer = &(list->hwLayers[index]);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800197 if(!mCurrentFrame.isFBComposed[index]) {
198 layerProp[index].mFlags |= HWC_MDPCOMP;
199 layer->compositionType = HWC_OVERLAY;
200 layer->hints |= HWC_HINT_CLEAR_FB;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800201 } else {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700202 /* Drop the layer when its already present in FB OR when it lies
203 * outside frame's ROI */
204 if(!mCurrentFrame.needsRedraw || mCurrentFrame.drop[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800205 layer->compositionType = HWC_OVERLAY;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700206 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800207 }
208 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700209}
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500210
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800211void MDPComp::setRedraw(hwc_context_t *ctx,
212 hwc_display_contents_1_t* list) {
213 mCurrentFrame.needsRedraw = false;
214 if(!mCachedFrame.isSameFrame(mCurrentFrame, list) ||
215 (list->flags & HWC_GEOMETRY_CHANGED) ||
216 isSkipPresent(ctx, mDpy)) {
217 mCurrentFrame.needsRedraw = true;
218 }
219}
220
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800221MDPComp::FrameInfo::FrameInfo() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700222 reset(0);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800223}
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800224
Saurabh Shahaa236822013-04-24 18:07:26 -0700225void MDPComp::FrameInfo::reset(const int& numLayers) {
226 for(int i = 0 ; i < MAX_PIPES_PER_MIXER && numLayers; i++ ) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800227 if(mdpToLayer[i].pipeInfo) {
228 delete mdpToLayer[i].pipeInfo;
229 mdpToLayer[i].pipeInfo = NULL;
230 //We dont own the rotator
231 mdpToLayer[i].rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800232 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800233 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800234
235 memset(&mdpToLayer, 0, sizeof(mdpToLayer));
236 memset(&layerToMDP, -1, sizeof(layerToMDP));
Saurabh Shahaa236822013-04-24 18:07:26 -0700237 memset(&isFBComposed, 1, sizeof(isFBComposed));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800238
Saurabh Shahaa236822013-04-24 18:07:26 -0700239 layerCount = numLayers;
240 fbCount = numLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800241 mdpCount = 0;
Saurabh Shah2f3895f2013-05-02 10:13:31 -0700242 needsRedraw = true;
Saurabh Shahd53bc5f2014-02-05 10:17:43 -0800243 fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800244}
245
Saurabh Shahaa236822013-04-24 18:07:26 -0700246void MDPComp::FrameInfo::map() {
247 // populate layer and MDP maps
248 int mdpIdx = 0;
249 for(int idx = 0; idx < layerCount; idx++) {
250 if(!isFBComposed[idx]) {
251 mdpToLayer[mdpIdx].listIndex = idx;
252 layerToMDP[idx] = mdpIdx++;
253 }
254 }
255}
256
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800257MDPComp::LayerCache::LayerCache() {
258 reset();
259}
260
261void MDPComp::LayerCache::reset() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700262 memset(&hnd, 0, sizeof(hnd));
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530263 memset(&isFBComposed, true, sizeof(isFBComposed));
264 memset(&drop, false, sizeof(drop));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800265 layerCount = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -0700266}
267
268void MDPComp::LayerCache::cacheAll(hwc_display_contents_1_t* list) {
269 const int numAppLayers = list->numHwLayers - 1;
270 for(int i = 0; i < numAppLayers; i++) {
271 hnd[i] = list->hwLayers[i].handle;
272 }
273}
274
275void MDPComp::LayerCache::updateCounts(const FrameInfo& curFrame) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700276 layerCount = curFrame.layerCount;
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530277 memcpy(&isFBComposed, &curFrame.isFBComposed, sizeof(isFBComposed));
278 memcpy(&drop, &curFrame.drop, sizeof(drop));
279}
280
Jeykumar Sankaran988d3682013-11-15 11:57:16 -0800281bool MDPComp::LayerCache::isSameFrame(const FrameInfo& curFrame,
282 hwc_display_contents_1_t* list) {
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530283 if(layerCount != curFrame.layerCount)
284 return false;
285 for(int i = 0; i < curFrame.layerCount; i++) {
286 if((curFrame.isFBComposed[i] != isFBComposed[i]) ||
287 (curFrame.drop[i] != drop[i])) {
288 return false;
289 }
Jeykumar Sankaran988d3682013-11-15 11:57:16 -0800290 if(curFrame.isFBComposed[i] &&
291 (hnd[i] != list->hwLayers[i].handle)){
292 return false;
293 }
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530294 }
295 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800296}
297
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700298bool MDPComp::isSupportedForMDPComp(hwc_context_t *ctx, hwc_layer_1_t* layer) {
299 private_handle_t *hnd = (private_handle_t *)layer->handle;
300 if((not isYuvBuffer(hnd) and has90Transform(layer)) or
301 (not isValidDimension(ctx,layer))
302 //More conditions here, SKIP, sRGB+Blend etc
303 ) {
304 return false;
305 }
306 return true;
307}
308
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530309bool MDPComp::isValidDimension(hwc_context_t *ctx, hwc_layer_1_t *layer) {
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800310 private_handle_t *hnd = (private_handle_t *)layer->handle;
311
312 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -0700313 if (layer->flags & HWC_COLOR_FILL) {
314 // Color layer
315 return true;
316 }
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800317 ALOGE("%s: layer handle is NULL", __FUNCTION__);
318 return false;
319 }
320
Naseer Ahmede850a802013-09-06 13:12:52 -0400321 //XXX: Investigate doing this with pixel phase on MDSS
Naseer Ahmede77f8082013-10-10 13:42:48 -0400322 if(!isSecureBuffer(hnd) && isNonIntegralSourceCrop(layer->sourceCropf))
Naseer Ahmede850a802013-09-06 13:12:52 -0400323 return false;
324
Saurabh Shah62e1d732013-09-17 10:44:05 -0700325 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700326 hwc_rect_t dst = layer->displayFrame;
Saurabh Shah4fdde762013-04-30 18:47:33 -0700327 int crop_w = crop.right - crop.left;
328 int crop_h = crop.bottom - crop.top;
329 int dst_w = dst.right - dst.left;
330 int dst_h = dst.bottom - dst.top;
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800331 float w_scale = ((float)crop_w / (float)dst_w);
332 float h_scale = ((float)crop_h / (float)dst_h);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700333
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800334 /* Workaround for MDP HW limitation in DSI command mode panels where
335 * FPS will not go beyond 30 if buffers on RGB pipes are of width or height
336 * less than 5 pixels
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530337 * There also is a HW limilation in MDP, minimum block size is 2x2
338 * Fallback to GPU if height is less than 2.
339 */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800340 if((crop_w < 5)||(crop_h < 5))
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800341 return false;
342
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800343 if((w_scale > 1.0f) || (h_scale > 1.0f)) {
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800344 const uint32_t downscale =
Saurabh Shah4fdde762013-04-30 18:47:33 -0700345 qdutils::MDPVersion::getInstance().getMaxMDPDownscale();
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800346 const float w_dscale = w_scale;
347 const float h_dscale = h_scale;
348
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800349 if(ctx->mMDP.version >= qdutils::MDSS_V5) {
350 /* Workaround for downscales larger than 4x.
351 * Will be removed once decimator block is enabled for MDSS
352 */
353 if(!qdutils::MDPVersion::getInstance().supportsDecimation()) {
354 if(crop_w > MAX_DISPLAY_DIM || w_dscale > downscale ||
355 h_dscale > downscale)
356 return false;
357 } else {
358 if(w_dscale > 64 || h_dscale > 64)
359 return false;
360 }
361 } else { //A-family
362 if(w_dscale > downscale || h_dscale > downscale)
Saurabh Shah4fdde762013-04-30 18:47:33 -0700363 return false;
364 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700365 }
366
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800367 if((w_scale < 1.0f) || (h_scale < 1.0f)) {
368 const uint32_t upscale =
369 qdutils::MDPVersion::getInstance().getMaxMDPUpscale();
370 const float w_uscale = 1.0f / w_scale;
371 const float h_uscale = 1.0f / h_scale;
372
373 if(w_uscale > upscale || h_uscale > upscale)
374 return false;
375 }
376
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800377 return true;
378}
379
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700380ovutils::eDest MDPComp::getMdpPipe(hwc_context_t *ctx, ePipeType type,
381 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800382 overlay::Overlay& ov = *ctx->mOverlay;
383 ovutils::eDest mdp_pipe = ovutils::OV_INVALID;
384
385 switch(type) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800386 case MDPCOMP_OV_DMA:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700387 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_DMA, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800388 if(mdp_pipe != ovutils::OV_INVALID) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800389 return mdp_pipe;
390 }
391 case MDPCOMP_OV_ANY:
392 case MDPCOMP_OV_RGB:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700393 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800394 if(mdp_pipe != ovutils::OV_INVALID) {
395 return mdp_pipe;
396 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800397
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800398 if(type == MDPCOMP_OV_RGB) {
399 //Requested only for RGB pipe
400 break;
401 }
402 case MDPCOMP_OV_VG:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700403 return ov.nextPipe(ovutils::OV_MDP_PIPE_VG, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800404 default:
405 ALOGE("%s: Invalid pipe type",__FUNCTION__);
406 return ovutils::OV_INVALID;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800407 };
408 return ovutils::OV_INVALID;
409}
410
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800411bool MDPComp::isFrameDoable(hwc_context_t *ctx) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700412 bool ret = true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800413
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800414 if(!isEnabled()) {
415 ALOGD_IF(isDebug(),"%s: MDP Comp. not enabled.", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700416 ret = false;
Saurabh Shahd4e65852013-06-17 11:33:53 -0700417 } else if(qdutils::MDPVersion::getInstance().is8x26() &&
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -0800418 ctx->mVideoTransFlag &&
419 isSecondaryConnected(ctx)) {
Saurabh Shahd4e65852013-06-17 11:33:53 -0700420 //1 Padding round to shift pipes across mixers
421 ALOGD_IF(isDebug(),"%s: MDP Comp. video transition padding round",
422 __FUNCTION__);
423 ret = false;
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -0800424 } else if(isSecondaryConfiguring(ctx)) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800425 ALOGD_IF( isDebug(),"%s: External Display connection is pending",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800426 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700427 ret = false;
Saurabh Shahaa236822013-04-24 18:07:26 -0700428 } else if(ctx->isPaddingRound) {
Raj Kamal9ed3d6b2014-02-07 16:15:17 +0530429 ALOGD_IF(isDebug(), "%s: padding round invoked for dpy %d",
430 __FUNCTION__,mDpy);
Saurabh Shahaa236822013-04-24 18:07:26 -0700431 ret = false;
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700432 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700433 return ret;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800434}
435
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800436/*
437 * 1) Identify layers that are not visible in the updating ROI and drop them
438 * from composition.
439 * 2) If we have a scaling layers which needs cropping against generated ROI.
440 * Reset ROI to full resolution.
441 */
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700442bool MDPComp::validateAndApplyROI(hwc_context_t *ctx,
443 hwc_display_contents_1_t* list, hwc_rect_t roi) {
444 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
445
446 if(!isValidRect(roi))
447 return false;
448
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800449 hwc_rect_t visibleRect = roi;
450
451 for(int i = numAppLayers - 1; i >= 0; i--){
452
453 if(!isValidRect(visibleRect)) {
454 mCurrentFrame.drop[i] = true;
455 mCurrentFrame.dropCount++;
Jeykumar Sankaran0b961452014-01-21 17:26:12 -0800456 continue;
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800457 }
458
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700459 const hwc_layer_1_t* layer = &list->hwLayers[i];
460
461 hwc_rect_t dstRect = layer->displayFrame;
Arun Kumar K.R91090c72013-10-28 19:40:18 -0700462 hwc_rect_t srcRect = integerizeSourceCrop(layer->sourceCropf);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700463
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800464 hwc_rect_t res = getIntersection(visibleRect, dstRect);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700465
466 int res_w = res.right - res.left;
467 int res_h = res.bottom - res.top;
468 int dst_w = dstRect.right - dstRect.left;
469 int dst_h = dstRect.bottom - dstRect.top;
470
471 if(!isValidRect(res)) {
472 mCurrentFrame.drop[i] = true;
473 mCurrentFrame.dropCount++;
474 }else {
475 /* Reset frame ROI when any layer which needs scaling also needs ROI
476 * cropping */
Jeykumar Sankaran0b961452014-01-21 17:26:12 -0800477 if((res_w != dst_w || res_h != dst_h) && needsScaling (layer)) {
Arpita Banerjeed8965982013-11-08 17:27:33 -0800478 ALOGI("%s: Resetting ROI due to scaling", __FUNCTION__);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700479 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
480 mCurrentFrame.dropCount = 0;
481 return false;
482 }
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800483
Jeykumar Sankaran0b961452014-01-21 17:26:12 -0800484 /* deduct any opaque region from visibleRect */
485 if (layer->blending == HWC_BLENDING_NONE)
486 visibleRect = deductRect(visibleRect, res);
487 }
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700488 }
489 return true;
490}
491
492void MDPComp::generateROI(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
493 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
494
495 if(!sEnablePartialFrameUpdate) {
496 return;
497 }
498
499 if(mDpy || isDisplaySplit(ctx, mDpy)){
500 ALOGE_IF(isDebug(), "%s: ROI not supported for"
501 "the (1) external / virtual display's (2) dual DSI displays",
502 __FUNCTION__);
503 return;
504 }
505
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800506 if(isSkipPresent(ctx, mDpy))
507 return;
508
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700509 if(list->flags & HWC_GEOMETRY_CHANGED)
510 return;
511
512 struct hwc_rect roi = (struct hwc_rect){0, 0, 0, 0};
513 for(int index = 0; index < numAppLayers; index++ ) {
514 if ((mCachedFrame.hnd[index] != list->hwLayers[index].handle) ||
515 isYuvBuffer((private_handle_t *)list->hwLayers[index].handle)) {
516 hwc_rect_t dstRect = list->hwLayers[index].displayFrame;
Arun Kumar K.R91090c72013-10-28 19:40:18 -0700517 hwc_rect_t srcRect = integerizeSourceCrop(
518 list->hwLayers[index].sourceCropf);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700519
520 /* Intersect against display boundaries */
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700521 roi = getUnion(roi, dstRect);
522 }
523 }
524
525 if(!validateAndApplyROI(ctx, list, roi)){
526 roi = (struct hwc_rect) {0, 0,
527 (int)ctx->dpyAttr[mDpy].xres, (int)ctx->dpyAttr[mDpy].yres};
528 }
529
530 ctx->listStats[mDpy].roi.x = roi.left;
531 ctx->listStats[mDpy].roi.y = roi.top;
532 ctx->listStats[mDpy].roi.w = roi.right - roi.left;
533 ctx->listStats[mDpy].roi.h = roi.bottom - roi.top;
534
535 ALOGD_IF(isDebug(),"%s: generated ROI: [%d, %d, %d, %d]", __FUNCTION__,
536 roi.left, roi.top, roi.right, roi.bottom);
537}
538
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800539/* Checks for conditions where all the layers marked for MDP comp cannot be
540 * bypassed. On such conditions we try to bypass atleast YUV layers */
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800541bool MDPComp::tryFullFrame(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800542 hwc_display_contents_1_t* list){
543
Saurabh Shahaa236822013-04-24 18:07:26 -0700544 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Arun Kumar K.R2e2871c2014-01-10 12:47:06 -0800545 int priDispW = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800546
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -0700547 if(sIdleFallBack && !ctx->listStats[mDpy].secureUI) {
Saurabh Shah2d998a92013-05-14 17:55:58 -0700548 ALOGD_IF(isDebug(), "%s: Idle fallback dpy %d",__FUNCTION__, mDpy);
549 return false;
550 }
551
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800552 if(isSkipPresent(ctx, mDpy)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700553 ALOGD_IF(isDebug(),"%s: SKIP present: %d",
554 __FUNCTION__,
555 isSkipPresent(ctx, mDpy));
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800556 return false;
557 }
558
Arun Kumar K.R2e2871c2014-01-10 12:47:06 -0800559 if(mDpy > HWC_DISPLAY_PRIMARY && (priDispW > MAX_DISPLAY_DIM) &&
560 (ctx->dpyAttr[mDpy].xres < MAX_DISPLAY_DIM)) {
561 // Disable MDP comp on Secondary when the primary is highres panel and
562 // the secondary is a normal 1080p, because, MDP comp on secondary under
563 // in such usecase, decimation gets used for downscale and there will be
564 // a quality mismatch when there will be a fallback to GPU comp
565 ALOGD_IF(isDebug(), "%s: Disable MDP Compositon for Secondary Disp",
566 __FUNCTION__);
567 return false;
568 }
569
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800570 // check for action safe flag and downscale mode which requires scaling.
571 if(ctx->dpyAttr[mDpy].mActionSafePresent
572 || ctx->dpyAttr[mDpy].mDownScaleMode) {
573 ALOGD_IF(isDebug(), "%s: Scaling needed for this frame",__FUNCTION__);
574 return false;
575 }
576
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800577 for(int i = 0; i < numAppLayers; ++i) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800578 hwc_layer_1_t* layer = &list->hwLayers[i];
579 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800580
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700581 if(isYuvBuffer(hnd) && has90Transform(layer)) {
582 if(!canUseRotator(ctx, mDpy)) {
583 ALOGD_IF(isDebug(), "%s: Can't use rotator for dpy %d",
584 __FUNCTION__, mDpy);
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700585 return false;
586 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800587 }
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530588
589 //For 8x26 with panel width>1k, if RGB layer needs HFLIP fail mdp comp
590 // may not need it if Gfx pre-rotation can handle all flips & rotations
591 if(qdutils::MDPVersion::getInstance().is8x26() &&
592 (ctx->dpyAttr[mDpy].xres > 1024) &&
593 (layer->transform & HWC_TRANSFORM_FLIP_H) &&
594 (!isYuvBuffer(hnd)))
595 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800596 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700597
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700598 if(ctx->mAD->isDoable()) {
599 return false;
600 }
601
Saurabh Shahaa236822013-04-24 18:07:26 -0700602 //If all above hard conditions are met we can do full or partial MDP comp.
603 bool ret = false;
604 if(fullMDPComp(ctx, list)) {
605 ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700606 } else if(partialMDPComp(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700607 ret = true;
608 }
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530609
Saurabh Shahaa236822013-04-24 18:07:26 -0700610 return ret;
611}
612
613bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700614 //Will benefit presentation / secondary-only layer.
615 if((mDpy > HWC_DISPLAY_PRIMARY) &&
616 (list->numHwLayers - 1) > MAX_SEC_LAYERS) {
617 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
618 return false;
619 }
620
621 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
622 for(int i = 0; i < numAppLayers; i++) {
623 hwc_layer_1_t* layer = &list->hwLayers[i];
624 if(not isSupportedForMDPComp(ctx, layer)) {
625 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",__FUNCTION__);
626 return false;
627 }
Yang Xu9c1eb2b2013-11-26 01:28:13 +0800628
629 //For 8x26, if there is only one layer which needs scale for secondary
630 //while no scale for primary display, DMA pipe is occupied by primary.
631 //If need to fall back to GLES composition, virtual display lacks DMA
632 //pipe and error is reported.
633 if(qdutils::MDPVersion::getInstance().is8x26() &&
634 mDpy >= HWC_DISPLAY_EXTERNAL &&
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530635 qhwc::needsScaling(layer))
Yang Xu9c1eb2b2013-11-26 01:28:13 +0800636 return false;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700637 }
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800638
Saurabh Shahaa236822013-04-24 18:07:26 -0700639 mCurrentFrame.fbCount = 0;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700640 memcpy(&mCurrentFrame.isFBComposed, &mCurrentFrame.drop,
641 sizeof(mCurrentFrame.isFBComposed));
642 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount -
643 mCurrentFrame.dropCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700644
radhakrishnac9a67412013-09-25 17:40:42 +0530645 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800646 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530647 }
648
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800649 if(!postHeuristicsHandling(ctx, list)) {
650 ALOGD_IF(isDebug(), "post heuristic handling failed");
651 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700652 return false;
653 }
654
Saurabh Shahaa236822013-04-24 18:07:26 -0700655 return true;
656}
657
658bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
659{
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700660 if(!sEnableMixedMode) {
661 //Mixed mode is disabled. No need to even try caching.
662 return false;
663 }
664
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700665 bool ret = false;
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800666 if(list->flags & HWC_GEOMETRY_CHANGED) { //Try load based first
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800667 ret = loadBasedComp(ctx, list) or
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800668 cacheBasedComp(ctx, list);
669 } else {
670 ret = cacheBasedComp(ctx, list) or
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800671 loadBasedComp(ctx, list);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700672 }
673
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700674 return ret;
675}
676
677bool MDPComp::cacheBasedComp(hwc_context_t *ctx,
678 hwc_display_contents_1_t* list) {
679 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700680 mCurrentFrame.reset(numAppLayers);
681 updateLayerCache(ctx, list);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700682
683 //If an MDP marked layer is unsupported cannot do partial MDP Comp
684 for(int i = 0; i < numAppLayers; i++) {
685 if(!mCurrentFrame.isFBComposed[i]) {
686 hwc_layer_1_t* layer = &list->hwLayers[i];
687 if(not isSupportedForMDPComp(ctx, layer)) {
688 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",
689 __FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800690 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700691 return false;
692 }
693 }
694 }
695
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700696 updateYUV(ctx, list, false /*secure only*/);
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530697 bool ret = markLayersForCaching(ctx, list); //sets up fbZ also
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700698 if(!ret) {
699 ALOGD_IF(isDebug(),"%s: batching failed, dpy %d",__FUNCTION__, mDpy);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800700 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700701 return false;
702 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700703
704 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700705
radhakrishnac9a67412013-09-25 17:40:42 +0530706 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800707 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530708 }
709
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700710 //Will benefit cases where a video has non-updating background.
711 if((mDpy > HWC_DISPLAY_PRIMARY) and
712 (mdpCount > MAX_SEC_LAYERS)) {
713 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800714 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700715 return false;
716 }
717
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800718 if(!postHeuristicsHandling(ctx, list)) {
719 ALOGD_IF(isDebug(), "post heuristic handling failed");
720 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700721 return false;
722 }
723
Saurabh Shahaa236822013-04-24 18:07:26 -0700724 return true;
725}
726
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800727bool MDPComp::loadBasedComp(hwc_context_t *ctx,
Saurabh Shahb772ae32013-11-18 15:40:02 -0800728 hwc_display_contents_1_t* list) {
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -0800729 if(not isLoadBasedCompDoable(ctx)) {
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800730 return false;
731 }
732
Saurabh Shahb772ae32013-11-18 15:40:02 -0800733 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800734 const int numNonDroppedLayers = numAppLayers - mCurrentFrame.dropCount;
735 const int stagesForMDP = min(sMaxPipesPerMixer,
736 ctx->mOverlay->availablePipes(mDpy, Overlay::MIXER_DEFAULT));
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800737
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800738 int mdpBatchSize = stagesForMDP - 1; //1 stage for FB
739 int fbBatchSize = numNonDroppedLayers - mdpBatchSize;
740 int lastMDPSupportedIndex = numAppLayers;
741 int dropCount = 0;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800742
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800743 //Find the minimum MDP batch size
744 for(int i = 0; i < numAppLayers;i++) {
745 if(mCurrentFrame.drop[i]) {
746 dropCount++;
Jeykumar Sankaran846e2792014-01-23 21:59:58 -0800747 continue;
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800748 }
749 hwc_layer_1_t* layer = &list->hwLayers[i];
750 if(not isSupportedForMDPComp(ctx, layer)) {
751 lastMDPSupportedIndex = i;
752 mdpBatchSize = min(i - dropCount, stagesForMDP - 1);
753 fbBatchSize = numNonDroppedLayers - mdpBatchSize;
Jeykumar Sankaran846e2792014-01-23 21:59:58 -0800754 break;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800755 }
Saurabh Shahb772ae32013-11-18 15:40:02 -0800756 }
757
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800758 ALOGD_IF(isDebug(), "%s:Before optimizing fbBatch, mdpbatch %d, fbbatch %d "
759 "dropped %d", __FUNCTION__, mdpBatchSize, fbBatchSize,
760 mCurrentFrame.dropCount);
761
762 //Start at a point where the fb batch should at least have 2 layers, for
763 //this mode to be justified.
764 while(fbBatchSize < 2) {
765 ++fbBatchSize;
766 --mdpBatchSize;
Jeykumar Sankaran846e2792014-01-23 21:59:58 -0800767 }
Saurabh Shahb772ae32013-11-18 15:40:02 -0800768
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800769 //If there are no layers for MDP, this mode doesnt make sense.
770 if(mdpBatchSize < 1) {
771 ALOGD_IF(isDebug(), "%s: No MDP layers after optimizing for fbBatch",
772 __FUNCTION__);
Saurabh Shahb772ae32013-11-18 15:40:02 -0800773 return false;
774 }
775
Saurabh Shahbe7bd322014-02-20 16:18:45 -0800776 mCurrentFrame.reset(numAppLayers);
777
778 //Try with successively smaller mdp batch sizes until we succeed or reach 1
779 while(mdpBatchSize > 0) {
780 //Mark layers for MDP comp
781 int mdpBatchLeft = mdpBatchSize;
782 for(int i = 0; i < lastMDPSupportedIndex and mdpBatchLeft; i++) {
783 if(mCurrentFrame.drop[i]) {
784 continue;
785 }
786 mCurrentFrame.isFBComposed[i] = false;
787 --mdpBatchLeft;
788 }
789
790 mCurrentFrame.fbZ = mdpBatchSize;
791 mCurrentFrame.fbCount = fbBatchSize;
792 mCurrentFrame.mdpCount = mdpBatchSize;
793
794 ALOGD_IF(isDebug(), "%s:Trying with: mdpbatch %d fbbatch %d dropped %d",
795 __FUNCTION__, mdpBatchSize, fbBatchSize,
796 mCurrentFrame.dropCount);
797
798 if(postHeuristicsHandling(ctx, list)) {
799 ALOGD_IF(isDebug(), "%s: Postheuristics handling succeeded",
800 __FUNCTION__);
801 return true;
802 }
803
804 reset(ctx);
805 --mdpBatchSize;
806 ++fbBatchSize;
807 }
808
809 return false;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800810}
811
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -0800812bool MDPComp::isLoadBasedCompDoable(hwc_context_t *ctx) {
Prabhanjan Kandula3dbbd882013-12-11 14:43:46 +0530813 if(mDpy or isSecurePresent(ctx, mDpy) or
814 isYuvPresent(ctx, mDpy)) {
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700815 return false;
816 }
817 return true;
818}
819
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800820bool MDPComp::tryVideoOnly(hwc_context_t *ctx,
821 hwc_display_contents_1_t* list) {
822 const bool secureOnly = true;
823 return videoOnlyComp(ctx, list, not secureOnly) or
824 videoOnlyComp(ctx, list, secureOnly);
825}
826
827bool MDPComp::videoOnlyComp(hwc_context_t *ctx,
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700828 hwc_display_contents_1_t* list, bool secureOnly) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700829 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700830
Saurabh Shahaa236822013-04-24 18:07:26 -0700831 mCurrentFrame.reset(numAppLayers);
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700832 updateYUV(ctx, list, secureOnly);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700833 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700834
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800835 if(!isYuvPresent(ctx, mDpy) or (mdpCount == 0)) {
836 reset(ctx);
Saurabh Shahaa236822013-04-24 18:07:26 -0700837 return false;
838 }
839
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -0800840 /* Bail out if we are processing only secured video layers
841 * and we dont have any */
842 if(!isSecurePresent(ctx, mDpy) && secureOnly){
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800843 reset(ctx);
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -0800844 return false;
845 }
846
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800847 if(mCurrentFrame.fbCount)
848 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
Saurabh Shah4fdde762013-04-30 18:47:33 -0700849
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800850 if(sEnable4k2kYUVSplit){
851 adjustForSourceSplit(ctx, list);
852 }
853
854 if(!postHeuristicsHandling(ctx, list)) {
855 ALOGD_IF(isDebug(), "post heuristic handling failed");
856 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700857 return false;
858 }
859
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800860 return true;
861}
862
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800863/* Checks for conditions where YUV layers cannot be bypassed */
864bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -0700865 if(isSkipLayer(layer)) {
Saurabh Shahe2474082013-05-15 16:32:13 -0700866 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800867 return false;
868 }
869
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700870 if(layer->transform & HWC_TRANSFORM_ROT_90 && !canUseRotator(ctx,mDpy)) {
871 ALOGD_IF(isDebug(), "%s: no free DMA pipe",__FUNCTION__);
872 return false;
873 }
874
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800875 if(isSecuring(ctx, layer)) {
876 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
877 return false;
878 }
879
Saurabh Shah4fdde762013-04-30 18:47:33 -0700880 if(!isValidDimension(ctx, layer)) {
881 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
882 __FUNCTION__);
883 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800884 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700885
Naseer Ahmeddc61a972013-07-10 17:50:54 -0400886 if(layer->planeAlpha < 0xFF) {
887 ALOGD_IF(isDebug(), "%s: Cannot handle YUV layer with plane alpha\
888 in video only mode",
889 __FUNCTION__);
890 return false;
891 }
892
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800893 return true;
894}
895
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530896/* starts at fromIndex and check for each layer to find
897 * if it it has overlapping with any Updating layer above it in zorder
898 * till the end of the batch. returns true if it finds any intersection */
899bool MDPComp::canPushBatchToTop(const hwc_display_contents_1_t* list,
900 int fromIndex, int toIndex) {
901 for(int i = fromIndex; i < toIndex; i++) {
902 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
903 if(intersectingUpdatingLayers(list, i+1, toIndex, i)) {
904 return false;
905 }
906 }
907 }
908 return true;
909}
910
911/* Checks if given layer at targetLayerIndex has any
912 * intersection with all the updating layers in beween
913 * fromIndex and toIndex. Returns true if it finds intersectiion */
914bool MDPComp::intersectingUpdatingLayers(const hwc_display_contents_1_t* list,
915 int fromIndex, int toIndex, int targetLayerIndex) {
916 for(int i = fromIndex; i <= toIndex; i++) {
917 if(!mCurrentFrame.isFBComposed[i]) {
918 if(areLayersIntersecting(&list->hwLayers[i],
919 &list->hwLayers[targetLayerIndex])) {
920 return true;
921 }
922 }
923 }
924 return false;
925}
926
927int MDPComp::getBatch(hwc_display_contents_1_t* list,
928 int& maxBatchStart, int& maxBatchEnd,
929 int& maxBatchCount) {
930 int i = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530931 int fbZOrder =-1;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -0800932 int droppedLayerCt = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530933 while (i < mCurrentFrame.layerCount) {
934 int batchCount = 0;
935 int batchStart = i;
936 int batchEnd = i;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -0800937 /* Adjust batch Z order with the dropped layers so far */
938 int fbZ = batchStart - droppedLayerCt;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530939 int firstZReverseIndex = -1;
Prabhanjan Kandula0ed2cc92013-12-06 12:39:04 +0530940 int updatingLayersAbove = 0;//Updating layer count in middle of batch
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530941 while(i < mCurrentFrame.layerCount) {
942 if(!mCurrentFrame.isFBComposed[i]) {
943 if(!batchCount) {
944 i++;
945 break;
946 }
947 updatingLayersAbove++;
948 i++;
949 continue;
950 } else {
951 if(mCurrentFrame.drop[i]) {
952 i++;
Jeykumar Sankaran9502f352014-01-20 12:25:32 -0800953 droppedLayerCt++;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530954 continue;
955 } else if(updatingLayersAbove <= 0) {
956 batchCount++;
957 batchEnd = i;
958 i++;
959 continue;
960 } else { //Layer is FBComposed, not a drop & updatingLayer > 0
961
962 // We have a valid updating layer already. If layer-i not
963 // have overlapping with all updating layers in between
964 // batch-start and i, then we can add layer i to batch.
965 if(!intersectingUpdatingLayers(list, batchStart, i-1, i)) {
966 batchCount++;
967 batchEnd = i;
968 i++;
969 continue;
970 } else if(canPushBatchToTop(list, batchStart, i)) {
971 //If All the non-updating layers with in this batch
972 //does not have intersection with the updating layers
973 //above in z-order, then we can safely move the batch to
974 //higher z-order. Increment fbZ as it is moving up.
975 if( firstZReverseIndex < 0) {
976 firstZReverseIndex = i;
977 }
978 batchCount++;
979 batchEnd = i;
980 fbZ += updatingLayersAbove;
981 i++;
982 updatingLayersAbove = 0;
983 continue;
984 } else {
985 //both failed.start the loop again from here.
986 if(firstZReverseIndex >= 0) {
987 i = firstZReverseIndex;
988 }
989 break;
990 }
991 }
992 }
993 }
994 if(batchCount > maxBatchCount) {
995 maxBatchCount = batchCount;
996 maxBatchStart = batchStart;
997 maxBatchEnd = batchEnd;
998 fbZOrder = fbZ;
999 }
1000 }
1001 return fbZOrder;
1002}
1003
1004bool MDPComp::markLayersForCaching(hwc_context_t* ctx,
1005 hwc_display_contents_1_t* list) {
1006 /* Idea is to keep as many non-updating(cached) layers in FB and
1007 * send rest of them through MDP. This is done in 2 steps.
1008 * 1. Find the maximum contiguous batch of non-updating layers.
1009 * 2. See if we can improve this batch size for caching by adding
1010 * opaque layers around the batch, if they don't have
1011 * any overlapping with the updating layers in between.
1012 * NEVER mark an updating layer for caching.
1013 * But cached ones can be marked for MDP */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001014
1015 int maxBatchStart = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001016 int maxBatchEnd = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001017 int maxBatchCount = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301018 int fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001019
Saurabh Shahd53bc5f2014-02-05 10:17:43 -08001020 /* Nothing is cached. No batching needed */
1021 if(mCurrentFrame.fbCount == 0) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001022 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -07001023 }
Saurabh Shahd53bc5f2014-02-05 10:17:43 -08001024
1025 /* No MDP comp layers, try to use other comp modes */
1026 if(mCurrentFrame.mdpCount == 0) {
1027 return false;
Saurabh Shahaa236822013-04-24 18:07:26 -07001028 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001029
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301030 fbZ = getBatch(list, maxBatchStart, maxBatchEnd, maxBatchCount);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001031
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301032 /* reset rest of the layers lying inside ROI for MDP comp */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001033 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001034 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001035 if((i < maxBatchStart || i > maxBatchEnd) &&
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301036 mCurrentFrame.isFBComposed[i]){
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001037 if(!mCurrentFrame.drop[i]){
1038 //If an unsupported layer is being attempted to
1039 //be pulled out we should fail
1040 if(not isSupportedForMDPComp(ctx, layer)) {
1041 return false;
1042 }
1043 mCurrentFrame.isFBComposed[i] = false;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001044 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001045 }
1046 }
1047
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301048 // update the frame data
1049 mCurrentFrame.fbZ = fbZ;
1050 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001051 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001052 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001053
1054 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301055 mCurrentFrame.fbCount);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001056
1057 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001058}
Saurabh Shah85234ec2013-04-12 17:09:00 -07001059
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001060void MDPComp::updateLayerCache(hwc_context_t* ctx,
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001061 hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001062 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001063 int fbCount = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001064
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001065 for(int i = 0; i < numAppLayers; i++) {
1066 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001067 if(!mCurrentFrame.drop[i])
1068 fbCount++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001069 mCurrentFrame.isFBComposed[i] = true;
1070 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -07001071 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001072 }
1073 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001074
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001075 mCurrentFrame.fbCount = fbCount;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001076 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount
1077 - mCurrentFrame.dropCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001078
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001079 ALOGD_IF(isDebug(),"%s: MDP count: %d FB count %d drop count: %d"
1080 ,__FUNCTION__, mCurrentFrame.mdpCount, mCurrentFrame.fbCount,
1081 mCurrentFrame.dropCount);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001082}
1083
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001084void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list,
1085 bool secureOnly) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001086 int nYuvCount = ctx->listStats[mDpy].yuvCount;
1087 for(int index = 0;index < nYuvCount; index++){
1088 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
1089 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
1090
1091 if(!isYUVDoable(ctx, layer)) {
1092 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
1093 mCurrentFrame.isFBComposed[nYuvIndex] = true;
1094 mCurrentFrame.fbCount++;
1095 }
1096 } else {
1097 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001098 private_handle_t *hnd = (private_handle_t *)layer->handle;
1099 if(!secureOnly || isSecureBuffer(hnd)) {
1100 mCurrentFrame.isFBComposed[nYuvIndex] = false;
1101 mCurrentFrame.fbCount--;
1102 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001103 }
1104 }
1105 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001106
1107 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001108 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
1109 ALOGD_IF(isDebug(),"%s: fb count: %d",__FUNCTION__,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001110 mCurrentFrame.fbCount);
1111}
1112
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001113hwc_rect_t MDPComp::getUpdatingFBRect(hwc_context_t *ctx,
1114 hwc_display_contents_1_t* list){
1115 hwc_rect_t fbRect = (struct hwc_rect){0, 0, 0, 0};
1116 hwc_layer_1_t *fbLayer = &list->hwLayers[mCurrentFrame.layerCount];
1117
1118 /* Update only the region of FB needed for composition */
1119 for(int i = 0; i < mCurrentFrame.layerCount; i++ ) {
1120 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
1121 hwc_layer_1_t* layer = &list->hwLayers[i];
1122 hwc_rect_t dst = layer->displayFrame;
1123 fbRect = getUnion(fbRect, dst);
1124 }
1125 }
1126 return fbRect;
1127}
1128
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001129bool MDPComp::postHeuristicsHandling(hwc_context_t *ctx,
1130 hwc_display_contents_1_t* list) {
1131
1132 //Capability checks
1133 if(!resourceCheck(ctx, list)) {
1134 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
1135 return false;
1136 }
1137
1138 //Limitations checks
1139 if(!hwLimitationsCheck(ctx, list)) {
1140 ALOGD_IF(isDebug(), "%s: HW limitations",__FUNCTION__);
1141 return false;
1142 }
1143
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001144 //Configure framebuffer first if applicable
1145 if(mCurrentFrame.fbZ >= 0) {
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -08001146 hwc_rect_t fbRect = getUpdatingFBRect(ctx, list);
1147 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, fbRect, mCurrentFrame.fbZ))
1148 {
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001149 ALOGD_IF(isDebug(), "%s configure framebuffer failed",
1150 __FUNCTION__);
1151 return false;
1152 }
1153 }
1154
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001155 mCurrentFrame.map();
1156
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001157 if(!allocLayerPipes(ctx, list)) {
1158 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -07001159 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001160 }
1161
1162 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001163 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001164 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001165 int mdpIndex = mCurrentFrame.layerToMDP[index];
1166 hwc_layer_1_t* layer = &list->hwLayers[index];
1167
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301168 //Leave fbZ for framebuffer. CACHE/GLES layers go here.
1169 if(mdpNextZOrder == mCurrentFrame.fbZ) {
1170 mdpNextZOrder++;
1171 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001172 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1173 cur_pipe->zOrder = mdpNextZOrder++;
1174
radhakrishnac9a67412013-09-25 17:40:42 +05301175 private_handle_t *hnd = (private_handle_t *)layer->handle;
1176 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1177 if(configure4k2kYuv(ctx, layer,
1178 mCurrentFrame.mdpToLayer[mdpIndex])
1179 != 0 ){
1180 ALOGD_IF(isDebug(), "%s: Failed to configure split pipes \
1181 for layer %d",__FUNCTION__, index);
1182 return false;
1183 }
1184 else{
1185 mdpNextZOrder++;
1186 }
1187 continue;
1188 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001189 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
1190 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
radhakrishnac9a67412013-09-25 17:40:42 +05301191 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -07001192 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001193 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001194 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001195 }
1196
Saurabh Shaha36be922013-12-16 18:18:39 -08001197 if(!ctx->mOverlay->validateAndSet(mDpy, ctx->dpyAttr[mDpy].fd)) {
1198 ALOGD_IF(isDebug(), "%s: Failed to validate and set overlay for dpy %d"
1199 ,__FUNCTION__, mDpy);
1200 return false;
1201 }
1202
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001203 setRedraw(ctx, list);
Saurabh Shahaa236822013-04-24 18:07:26 -07001204 return true;
1205}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001206
Saurabh Shah173f4242013-11-20 09:50:12 -08001207bool MDPComp::resourceCheck(hwc_context_t *ctx,
1208 hwc_display_contents_1_t *list) {
1209 const bool fbUsed = mCurrentFrame.fbCount;
1210 if(mCurrentFrame.mdpCount > sMaxPipesPerMixer - fbUsed) {
1211 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
1212 return false;
1213 }
Saurabh Shah173f4242013-11-20 09:50:12 -08001214 return true;
1215}
1216
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301217bool MDPComp::hwLimitationsCheck(hwc_context_t* ctx,
1218 hwc_display_contents_1_t* list) {
1219
1220 //A-family hw limitation:
1221 //If a layer need alpha scaling, MDP can not support.
1222 if(ctx->mMDP.version < qdutils::MDSS_V5) {
1223 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1224 if(!mCurrentFrame.isFBComposed[i] &&
1225 isAlphaScaled( &list->hwLayers[i])) {
1226 ALOGD_IF(isDebug(), "%s:frame needs alphaScaling",__FUNCTION__);
1227 return false;
1228 }
1229 }
1230 }
1231
1232 // On 8x26 & 8974 hw, we have a limitation of downscaling+blending.
1233 //If multiple layers requires downscaling and also they are overlapping
1234 //fall back to GPU since MDSS can not handle it.
1235 if(qdutils::MDPVersion::getInstance().is8x74v2() ||
1236 qdutils::MDPVersion::getInstance().is8x26()) {
1237 for(int i = 0; i < mCurrentFrame.layerCount-1; ++i) {
1238 hwc_layer_1_t* botLayer = &list->hwLayers[i];
1239 if(!mCurrentFrame.isFBComposed[i] &&
1240 isDownscaleRequired(botLayer)) {
1241 //if layer-i is marked for MDP and needs downscaling
1242 //check if any MDP layer on top of i & overlaps with layer-i
1243 for(int j = i+1; j < mCurrentFrame.layerCount; ++j) {
1244 hwc_layer_1_t* topLayer = &list->hwLayers[j];
1245 if(!mCurrentFrame.isFBComposed[j] &&
1246 isDownscaleRequired(topLayer)) {
1247 hwc_rect_t r = getIntersection(botLayer->displayFrame,
1248 topLayer->displayFrame);
1249 if(isValidRect(r))
1250 return false;
1251 }
1252 }
1253 }
1254 }
1255 }
1256 return true;
1257}
1258
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001259int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001260 int ret = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -07001261 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001262 MDPVersion& mdpVersion = qdutils::MDPVersion::getInstance();
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -07001263
Raj Kamal9ed3d6b2014-02-07 16:15:17 +05301264 //Do not cache the information for next draw cycle.
1265 if(numLayers > MAX_NUM_APP_LAYERS or (!numLayers)) {
1266 ALOGI("%s: Unsupported layer count for mdp composition",
1267 __FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001268 mCachedFrame.reset();
1269 return -1;
1270 }
1271
Saurabh Shahb39f8152013-08-22 10:21:44 -07001272 //reset old data
1273 mCurrentFrame.reset(numLayers);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001274 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1275 mCurrentFrame.dropCount = 0;
Prabhanjan Kandula088bd892013-07-02 23:47:13 +05301276
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -07001277 // Detect the start of animation and fall back to GPU only once to cache
1278 // all the layers in FB and display FB content untill animation completes.
1279 if(ctx->listStats[mDpy].isDisplayAnimating) {
1280 mCurrentFrame.needsRedraw = false;
1281 if(ctx->mAnimationState[mDpy] == ANIMATION_STOPPED) {
1282 mCurrentFrame.needsRedraw = true;
1283 ctx->mAnimationState[mDpy] = ANIMATION_STARTED;
1284 }
1285 setMDPCompLayerFlags(ctx, list);
1286 mCachedFrame.updateCounts(mCurrentFrame);
1287 ret = -1;
1288 return ret;
1289 } else {
1290 ctx->mAnimationState[mDpy] = ANIMATION_STOPPED;
1291 }
1292
Saurabh Shahb39f8152013-08-22 10:21:44 -07001293 //Hard conditions, if not met, cannot do MDP comp
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001294 if(isFrameDoable(ctx)) {
1295 generateROI(ctx, list);
Saurabh Shahb39f8152013-08-22 10:21:44 -07001296
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001297 if(tryFullFrame(ctx, list) || tryVideoOnly(ctx, list)) {
1298 setMDPCompLayerFlags(ctx, list);
1299 } else {
1300 reset(ctx);
1301 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1302 mCurrentFrame.dropCount = 0;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001303 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001304 }
1305 } else {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001306 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
1307 __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001308 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001309 }
Saurabh Shahb39f8152013-08-22 10:21:44 -07001310
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001311 if(isDebug()) {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001312 ALOGD("GEOMETRY change: %d",
1313 (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001314 android::String8 sDump("");
1315 dump(sDump);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001316 ALOGD("%s",sDump.string());
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001317 }
1318
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001319 mCachedFrame.cacheAll(list);
1320 mCachedFrame.updateCounts(mCurrentFrame);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001321 return ret;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001322}
1323
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001324bool MDPComp::allocSplitVGPipesfor4k2k(hwc_context_t *ctx, int index) {
radhakrishnac9a67412013-09-25 17:40:42 +05301325
1326 bool bRet = true;
radhakrishnac9a67412013-09-25 17:40:42 +05301327 int mdpIndex = mCurrentFrame.layerToMDP[index];
1328 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
1329 info.pipeInfo = new MdpYUVPipeInfo;
1330 info.rot = NULL;
1331 MdpYUVPipeInfo& pipe_info = *(MdpYUVPipeInfo*)info.pipeInfo;
1332 ePipeType type = MDPCOMP_OV_VG;
1333
1334 pipe_info.lIndex = ovutils::OV_INVALID;
1335 pipe_info.rIndex = ovutils::OV_INVALID;
1336
1337 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
1338 if(pipe_info.lIndex == ovutils::OV_INVALID){
1339 bRet = false;
1340 ALOGD_IF(isDebug(),"%s: allocating first VG pipe failed",
1341 __FUNCTION__);
1342 }
1343 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
1344 if(pipe_info.rIndex == ovutils::OV_INVALID){
1345 bRet = false;
1346 ALOGD_IF(isDebug(),"%s: allocating second VG pipe failed",
1347 __FUNCTION__);
1348 }
1349 return bRet;
1350}
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001351//=============MDPCompNonSplit==================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001352
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001353void MDPCompNonSplit::adjustForSourceSplit(hwc_context_t *ctx,
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001354 hwc_display_contents_1_t*) {
radhakrishnac9a67412013-09-25 17:40:42 +05301355 //As we split 4kx2k yuv layer and program to 2 VG pipes
1356 //(if available) increase mdpcount accordingly
1357 mCurrentFrame.mdpCount += ctx->listStats[mDpy].yuv4k2kCount;
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001358
1359 //If 4k2k Yuv layer split is possible, and if
1360 //fbz is above 4k2k layer, increment fb zorder by 1
1361 //as we split 4k2k layer and increment zorder for right half
1362 //of the layer
1363 if(mCurrentFrame.fbZ >= 0) {
1364 int n4k2kYuvCount = ctx->listStats[mDpy].yuv4k2kCount;
1365 for(int index = 0; index < n4k2kYuvCount; index++){
1366 int n4k2kYuvIndex =
1367 ctx->listStats[mDpy].yuv4k2kIndices[index];
1368 if(mCurrentFrame.fbZ > n4k2kYuvIndex){
1369 mCurrentFrame.fbZ += 1;
1370 }
1371 }
1372 }
radhakrishnac9a67412013-09-25 17:40:42 +05301373}
1374
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001375/*
1376 * Configures pipe(s) for MDP composition
1377 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001378int MDPCompNonSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001379 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001380 MdpPipeInfoNonSplit& mdp_info =
1381 *(static_cast<MdpPipeInfoNonSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001382 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
1383 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1384 eIsFg isFg = IS_FG_OFF;
1385 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001386
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001387 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
1388 __FUNCTION__, layer, zOrder, dest);
1389
Saurabh Shah88e4d272013-09-03 13:31:29 -07001390 return configureNonSplit(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001391 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001392}
1393
Saurabh Shah88e4d272013-09-03 13:31:29 -07001394bool MDPCompNonSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001395 hwc_display_contents_1_t* list) {
1396 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001397
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001398 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001399
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001400 hwc_layer_1_t* layer = &list->hwLayers[index];
1401 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301402 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001403 if(allocSplitVGPipesfor4k2k(ctx, index)){
radhakrishnac9a67412013-09-25 17:40:42 +05301404 continue;
1405 }
1406 }
1407
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001408 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001409 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001410 info.pipeInfo = new MdpPipeInfoNonSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08001411 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001412 MdpPipeInfoNonSplit& pipe_info = *(MdpPipeInfoNonSplit*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001413 ePipeType type = MDPCOMP_OV_ANY;
1414
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001415 if(isYuvBuffer(hnd)) {
1416 type = MDPCOMP_OV_VG;
Prabhanjan Kandula47191dc2014-01-22 23:01:45 +05301417 } else if(qdutils::MDPVersion::getInstance().is8x26() &&
1418 (ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres > 1024)) {
1419 if(qhwc::needsScaling(layer))
1420 type = MDPCOMP_OV_RGB;
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301421 } else if(!qhwc::needsScaling(layer)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001422 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
1423 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001424 type = MDPCOMP_OV_DMA;
1425 }
1426
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001427 pipe_info.index = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001428 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001429 ALOGD_IF(isDebug(), "%s: Unable to get pipe type = %d",
1430 __FUNCTION__, (int) type);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001431 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001432 }
1433 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001434 return true;
1435}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001436
radhakrishnac9a67412013-09-25 17:40:42 +05301437int MDPCompNonSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1438 PipeLayerPair& PipeLayerPair) {
1439 MdpYUVPipeInfo& mdp_info =
1440 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1441 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1442 eIsFg isFg = IS_FG_OFF;
1443 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1444 eDest lDest = mdp_info.lIndex;
1445 eDest rDest = mdp_info.rIndex;
1446
1447 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1448 lDest, rDest, &PipeLayerPair.rot);
1449}
1450
Saurabh Shah88e4d272013-09-03 13:31:29 -07001451bool MDPCompNonSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001452
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001453 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001454 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1455 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -08001456 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001457
1458 if(!ctx || !list) {
1459 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001460 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001461 }
1462
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301463 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1464 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1465 return true;
1466 }
1467
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -08001468 // Set the Handle timeout to true for MDP or MIXED composition.
1469 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount) {
1470 sHandleTimeout = true;
1471 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001472
1473 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001474 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001475
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001476 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1477 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001478 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001479 if(mCurrentFrame.isFBComposed[i]) continue;
1480
Naseer Ahmed5b6708a2012-08-02 13:46:08 -07001481 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001482 private_handle_t *hnd = (private_handle_t *)layer->handle;
1483 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001484 if (!(layer->flags & HWC_COLOR_FILL)) {
1485 ALOGE("%s handle null", __FUNCTION__);
1486 return false;
1487 }
1488 // No PLAY for Color layer
1489 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1490 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001491 }
1492
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001493 int mdpIndex = mCurrentFrame.layerToMDP[i];
1494
radhakrishnac9a67412013-09-25 17:40:42 +05301495 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1496 {
1497 MdpYUVPipeInfo& pipe_info =
1498 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1499 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1500 ovutils::eDest indexL = pipe_info.lIndex;
1501 ovutils::eDest indexR = pipe_info.rIndex;
1502 int fd = hnd->fd;
1503 uint32_t offset = hnd->offset;
1504 if(rot) {
1505 rot->queueBuffer(fd, offset);
1506 fd = rot->getDstMemId();
1507 offset = rot->getDstOffset();
1508 }
1509 if(indexL != ovutils::OV_INVALID) {
1510 ovutils::eDest destL = (ovutils::eDest)indexL;
1511 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1512 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1513 if (!ov.queueBuffer(fd, offset, destL)) {
1514 ALOGE("%s: queueBuffer failed for display:%d",
1515 __FUNCTION__, mDpy);
1516 return false;
1517 }
1518 }
1519
1520 if(indexR != ovutils::OV_INVALID) {
1521 ovutils::eDest destR = (ovutils::eDest)indexR;
1522 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1523 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1524 if (!ov.queueBuffer(fd, offset, destR)) {
1525 ALOGE("%s: queueBuffer failed for display:%d",
1526 __FUNCTION__, mDpy);
1527 return false;
1528 }
1529 }
1530 }
1531 else{
1532 MdpPipeInfoNonSplit& pipe_info =
Saurabh Shah88e4d272013-09-03 13:31:29 -07001533 *(MdpPipeInfoNonSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
radhakrishnac9a67412013-09-25 17:40:42 +05301534 ovutils::eDest dest = pipe_info.index;
1535 if(dest == ovutils::OV_INVALID) {
1536 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001537 return false;
radhakrishnac9a67412013-09-25 17:40:42 +05301538 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001539
radhakrishnac9a67412013-09-25 17:40:42 +05301540 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1541 continue;
1542 }
1543
1544 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1545 using pipe: %d", __FUNCTION__, layer,
1546 hnd, dest );
1547
1548 int fd = hnd->fd;
1549 uint32_t offset = hnd->offset;
1550
1551 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1552 if(rot) {
1553 if(!rot->queueBuffer(fd, offset))
1554 return false;
1555 fd = rot->getDstMemId();
1556 offset = rot->getDstOffset();
1557 }
1558
1559 if (!ov.queueBuffer(fd, offset, dest)) {
1560 ALOGE("%s: queueBuffer failed for display:%d ",
1561 __FUNCTION__, mDpy);
1562 return false;
1563 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001564 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001565
1566 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001567 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001568 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001569}
1570
Saurabh Shah88e4d272013-09-03 13:31:29 -07001571//=============MDPCompSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001572
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001573void MDPCompSplit::adjustForSourceSplit(hwc_context_t *ctx,
radhakrishnac9a67412013-09-25 17:40:42 +05301574 hwc_display_contents_1_t* list){
1575 //if 4kx2k yuv layer is totally present in either in left half
1576 //or right half then try splitting the yuv layer to avoid decimation
1577 int n4k2kYuvCount = ctx->listStats[mDpy].yuv4k2kCount;
1578 const int lSplit = getLeftSplit(ctx, mDpy);
1579 for(int index = 0; index < n4k2kYuvCount; index++){
1580 int n4k2kYuvIndex = ctx->listStats[mDpy].yuv4k2kIndices[index];
1581 hwc_layer_1_t* layer = &list->hwLayers[n4k2kYuvIndex];
1582 hwc_rect_t dst = layer->displayFrame;
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001583 if((dst.left > lSplit) || (dst.right < lSplit)) {
radhakrishnac9a67412013-09-25 17:40:42 +05301584 mCurrentFrame.mdpCount += 1;
1585 }
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001586 if(mCurrentFrame.fbZ > n4k2kYuvIndex){
1587 mCurrentFrame.fbZ += 1;
1588 }
radhakrishnac9a67412013-09-25 17:40:42 +05301589 }
1590}
1591
Saurabh Shah88e4d272013-09-03 13:31:29 -07001592bool MDPCompSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
1593 MdpPipeInfoSplit& pipe_info,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001594 ePipeType type) {
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001595 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001596
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001597 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001598 pipe_info.lIndex = ovutils::OV_INVALID;
1599 pipe_info.rIndex = ovutils::OV_INVALID;
1600
1601 if (dst.left < lSplit) {
1602 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_LEFT);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001603 if(pipe_info.lIndex == ovutils::OV_INVALID)
1604 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001605 }
1606
1607 if(dst.right > lSplit) {
1608 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_RIGHT);
1609 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001610 return false;
1611 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001612
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001613 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001614}
1615
Saurabh Shah88e4d272013-09-03 13:31:29 -07001616bool MDPCompSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001617 hwc_display_contents_1_t* list) {
1618 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001619
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001620 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001621
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001622 hwc_layer_1_t* layer = &list->hwLayers[index];
1623 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301624 hwc_rect_t dst = layer->displayFrame;
1625 const int lSplit = getLeftSplit(ctx, mDpy);
1626 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1627 if((dst.left > lSplit)||(dst.right < lSplit)){
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001628 if(allocSplitVGPipesfor4k2k(ctx, index)){
radhakrishnac9a67412013-09-25 17:40:42 +05301629 continue;
1630 }
1631 }
1632 }
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001633 int mdpIndex = mCurrentFrame.layerToMDP[index];
1634 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001635 info.pipeInfo = new MdpPipeInfoSplit;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001636 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001637 MdpPipeInfoSplit& pipe_info = *(MdpPipeInfoSplit*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001638 ePipeType type = MDPCOMP_OV_ANY;
1639
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001640 if(isYuvBuffer(hnd)) {
1641 type = MDPCOMP_OV_VG;
Sushil Chauhan15a2ea62013-09-04 18:28:36 -07001642 } else if(!qhwc::needsScalingWithSplit(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001643 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001644 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001645 type = MDPCOMP_OV_DMA;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001646 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001647
1648 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001649 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type = %d",
1650 __FUNCTION__, (int) type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001651 return false;
1652 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001653 }
1654 return true;
1655}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001656
radhakrishnac9a67412013-09-25 17:40:42 +05301657int MDPCompSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1658 PipeLayerPair& PipeLayerPair) {
1659 const int lSplit = getLeftSplit(ctx, mDpy);
1660 hwc_rect_t dst = layer->displayFrame;
1661 if((dst.left > lSplit)||(dst.right < lSplit)){
1662 MdpYUVPipeInfo& mdp_info =
1663 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1664 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1665 eIsFg isFg = IS_FG_OFF;
1666 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1667 eDest lDest = mdp_info.lIndex;
1668 eDest rDest = mdp_info.rIndex;
1669
1670 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1671 lDest, rDest, &PipeLayerPair.rot);
1672 }
1673 else{
1674 return configure(ctx, layer, PipeLayerPair);
1675 }
1676}
1677
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001678/*
1679 * Configures pipe(s) for MDP composition
1680 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001681int MDPCompSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001682 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001683 MdpPipeInfoSplit& mdp_info =
1684 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001685 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1686 eIsFg isFg = IS_FG_OFF;
1687 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1688 eDest lDest = mdp_info.lIndex;
1689 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001690
1691 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1692 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1693
Saurabh Shah88e4d272013-09-03 13:31:29 -07001694 return configureSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001695 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001696}
1697
Saurabh Shah88e4d272013-09-03 13:31:29 -07001698bool MDPCompSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001699
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001700 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001701 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1702 return true;
1703 }
1704
1705 if(!ctx || !list) {
1706 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001707 return false;
1708 }
1709
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301710 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1711 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1712 return true;
1713 }
1714
Ramkumar Radhakrishnan92abb4f2014-02-06 21:31:29 -08001715 // Set the Handle timeout to true for MDP or MIXED composition.
1716 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount) {
1717 sHandleTimeout = true;
1718 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001719
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001720 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001721 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001722
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001723 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1724 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001725 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001726 if(mCurrentFrame.isFBComposed[i]) continue;
1727
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001728 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001729 private_handle_t *hnd = (private_handle_t *)layer->handle;
1730 if(!hnd) {
1731 ALOGE("%s handle null", __FUNCTION__);
1732 return false;
1733 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001734
1735 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1736 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001737 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001738
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001739 int mdpIndex = mCurrentFrame.layerToMDP[i];
1740
radhakrishnac9a67412013-09-25 17:40:42 +05301741 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1742 {
1743 MdpYUVPipeInfo& pipe_info =
1744 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1745 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1746 ovutils::eDest indexL = pipe_info.lIndex;
1747 ovutils::eDest indexR = pipe_info.rIndex;
1748 int fd = hnd->fd;
1749 uint32_t offset = hnd->offset;
1750 if(rot) {
1751 rot->queueBuffer(fd, offset);
1752 fd = rot->getDstMemId();
1753 offset = rot->getDstOffset();
1754 }
1755 if(indexL != ovutils::OV_INVALID) {
1756 ovutils::eDest destL = (ovutils::eDest)indexL;
1757 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1758 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1759 if (!ov.queueBuffer(fd, offset, destL)) {
1760 ALOGE("%s: queueBuffer failed for display:%d",
1761 __FUNCTION__, mDpy);
1762 return false;
1763 }
1764 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001765
radhakrishnac9a67412013-09-25 17:40:42 +05301766 if(indexR != ovutils::OV_INVALID) {
1767 ovutils::eDest destR = (ovutils::eDest)indexR;
1768 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1769 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1770 if (!ov.queueBuffer(fd, offset, destR)) {
1771 ALOGE("%s: queueBuffer failed for display:%d",
1772 __FUNCTION__, mDpy);
1773 return false;
1774 }
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001775 }
1776 }
radhakrishnac9a67412013-09-25 17:40:42 +05301777 else{
1778 MdpPipeInfoSplit& pipe_info =
1779 *(MdpPipeInfoSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1780 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001781
radhakrishnac9a67412013-09-25 17:40:42 +05301782 ovutils::eDest indexL = pipe_info.lIndex;
1783 ovutils::eDest indexR = pipe_info.rIndex;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001784
radhakrishnac9a67412013-09-25 17:40:42 +05301785 int fd = hnd->fd;
1786 int offset = hnd->offset;
1787
1788 if(ctx->mAD->isModeOn()) {
1789 if(ctx->mAD->draw(ctx, fd, offset)) {
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001790 fd = ctx->mAD->getDstFd();
1791 offset = ctx->mAD->getDstOffset();
radhakrishnac9a67412013-09-25 17:40:42 +05301792 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001793 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001794
radhakrishnac9a67412013-09-25 17:40:42 +05301795 if(rot) {
1796 rot->queueBuffer(fd, offset);
1797 fd = rot->getDstMemId();
1798 offset = rot->getDstOffset();
1799 }
1800
1801 //************* play left mixer **********
1802 if(indexL != ovutils::OV_INVALID) {
1803 ovutils::eDest destL = (ovutils::eDest)indexL;
1804 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1805 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1806 if (!ov.queueBuffer(fd, offset, destL)) {
1807 ALOGE("%s: queueBuffer failed for left mixer",
1808 __FUNCTION__);
1809 return false;
1810 }
1811 }
1812
1813 //************* play right mixer **********
1814 if(indexR != ovutils::OV_INVALID) {
1815 ovutils::eDest destR = (ovutils::eDest)indexR;
1816 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1817 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1818 if (!ov.queueBuffer(fd, offset, destR)) {
1819 ALOGE("%s: queueBuffer failed for right mixer",
1820 __FUNCTION__);
1821 return false;
1822 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001823 }
1824 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001825
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001826 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1827 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001828
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001829 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001830}
Saurabh Shahab47c692014-02-12 18:45:57 -08001831
1832//================MDPCompSrcSplit==============================================
1833bool MDPCompSrcSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
1834 MdpPipeInfoSplit& pipe_info, ePipeType /*type*/) {
1835 private_handle_t *hnd = (private_handle_t *)layer->handle;
1836 hwc_rect_t dst = layer->displayFrame;
1837 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
1838 pipe_info.lIndex = ovutils::OV_INVALID;
1839 pipe_info.rIndex = ovutils::OV_INVALID;
1840
1841 //If 2 pipes are staged on a single stage of a mixer, then the left pipe
1842 //should have a higher priority than the right one. Pipe priorities are
1843 //starting with VG0, VG1 ... , RGB0 ..., DMA1
1844 //TODO Currently we acquire VG pipes for left side and RGB/DMA for right to
1845 //make sure pipe priorities are satisfied. A better way is to have priority
1846 //as part of overlay object and acquire any 2 pipes. Assign the higher
1847 //priority one to left side and lower to right side.
1848
1849 //1 pipe by default for a layer
1850 pipe_info.lIndex = getMdpPipe(ctx, MDPCOMP_OV_VG, Overlay::MIXER_DEFAULT);
1851 if(pipe_info.lIndex == ovutils::OV_INVALID) {
1852 if(isYuvBuffer(hnd)) {
1853 return false;
1854 }
1855 pipe_info.lIndex = getMdpPipe(ctx, MDPCOMP_OV_ANY,
1856 Overlay::MIXER_DEFAULT);
1857 if(pipe_info.lIndex == ovutils::OV_INVALID) {
1858 return false;
1859 }
1860 }
1861
1862 //If layer's crop width or dest width > 2048, use 2 pipes
1863 if((dst.right - dst.left) > qdutils::MAX_DISPLAY_DIM or
1864 (crop.right - crop.left) > qdutils::MAX_DISPLAY_DIM) {
1865 ePipeType rightType = isYuvBuffer(hnd) ?
1866 MDPCOMP_OV_VG : MDPCOMP_OV_ANY;
1867 pipe_info.rIndex = getMdpPipe(ctx, rightType, Overlay::MIXER_DEFAULT);
1868 if(pipe_info.rIndex == ovutils::OV_INVALID) {
1869 return false;
1870 }
1871 }
1872
1873 return true;
1874}
1875
1876bool MDPCompSrcSplit::allocLayerPipes(hwc_context_t *ctx,
1877 hwc_display_contents_1_t* list) {
1878 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
1879 if(mCurrentFrame.isFBComposed[index]) continue;
1880 hwc_layer_1_t* layer = &list->hwLayers[index];
1881 int mdpIndex = mCurrentFrame.layerToMDP[index];
1882 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
1883 info.pipeInfo = new MdpPipeInfoSplit;
1884 info.rot = NULL;
1885 MdpPipeInfoSplit& pipe_info = *(MdpPipeInfoSplit*)info.pipeInfo;
1886
1887 ePipeType type = MDPCOMP_OV_ANY;
1888 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
1889 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type = %d",
1890 __FUNCTION__, (int) type);
1891 return false;
1892 }
1893 }
1894 return true;
1895}
1896
1897int MDPCompSrcSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
1898 PipeLayerPair& PipeLayerPair) {
1899 private_handle_t *hnd = (private_handle_t *)layer->handle;
1900 if(!hnd) {
1901 ALOGE("%s: layer handle is NULL", __FUNCTION__);
1902 return -1;
1903 }
1904 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
1905 MdpPipeInfoSplit& mdp_info =
1906 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
1907 Rotator **rot = &PipeLayerPair.rot;
1908 eZorder z = static_cast<eZorder>(mdp_info.zOrder);
1909 eIsFg isFg = IS_FG_OFF;
1910 eDest lDest = mdp_info.lIndex;
1911 eDest rDest = mdp_info.rIndex;
1912 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
1913 hwc_rect_t dst = layer->displayFrame;
1914 int transform = layer->transform;
1915 eTransform orient = static_cast<eTransform>(transform);
1916 const int downscale = 0;
1917 int rotFlags = ROT_FLAGS_NONE;
1918 uint32_t format = ovutils::getMdpFormat(hnd->format, isTileRendered(hnd));
1919 Whf whf(getWidth(hnd), getHeight(hnd), format, hnd->size);
1920
1921 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1922 "dest_pipeR: %d",__FUNCTION__, layer, z, lDest, rDest);
1923
1924 // Handle R/B swap
1925 if (layer->flags & HWC_FORMAT_RB_SWAP) {
1926 if (hnd->format == HAL_PIXEL_FORMAT_RGBA_8888)
1927 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRA_8888);
1928 else if (hnd->format == HAL_PIXEL_FORMAT_RGBX_8888)
1929 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRX_8888);
1930 }
1931
1932 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1933 setMdpFlags(layer, mdpFlagsL, 0, transform);
1934 eMdpFlags mdpFlagsR = mdpFlagsL;
1935
1936 if(lDest != OV_INVALID && rDest != OV_INVALID) {
1937 //Enable overfetch
1938 setMdpFlags(mdpFlagsL, OV_MDSS_MDP_DUAL_PIPE);
1939 }
1940
1941 if(isYuvBuffer(hnd) && (transform & HWC_TRANSFORM_ROT_90)) {
1942 (*rot) = ctx->mRotMgr->getNext();
1943 if((*rot) == NULL) return -1;
1944 //Configure rotator for pre-rotation
1945 if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale) < 0) {
1946 ALOGE("%s: configRotator failed!", __FUNCTION__);
1947 return -1;
1948 }
1949 ctx->mLayerRotMap[mDpy]->add(layer, *rot);
1950 whf.format = (*rot)->getDstFormat();
1951 updateSource(orient, whf, crop);
1952 rotFlags |= ROT_PREROTATED;
1953 }
1954
1955 //If 2 pipes being used, divide layer into half, crop and dst
1956 hwc_rect_t cropL = crop;
1957 hwc_rect_t cropR = crop;
1958 hwc_rect_t dstL = dst;
1959 hwc_rect_t dstR = dst;
1960 if(lDest != OV_INVALID && rDest != OV_INVALID) {
1961 cropL.right = (crop.right + crop.left) / 2;
1962 cropR.left = cropL.right;
1963 sanitizeSourceCrop(cropL, cropR, hnd);
1964
1965 //Swap crops on H flip since 2 pipes are being used
1966 if((orient & OVERLAY_TRANSFORM_FLIP_H) && (*rot) == NULL) {
1967 hwc_rect_t tmp = cropL;
1968 cropL = cropR;
1969 cropR = tmp;
1970 }
1971
1972 dstL.right = (dst.right + dst.left) / 2;
1973 dstR.left = dstL.right;
1974 }
1975
1976 //For the mdp, since either we are pre-rotating or MDP does flips
1977 orient = OVERLAY_TRANSFORM_0;
1978 transform = 0;
1979
1980 //configure left pipe
1981 if(lDest != OV_INVALID) {
1982 PipeArgs pargL(mdpFlagsL, whf, z, isFg,
1983 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
1984 (ovutils::eBlending) getBlending(layer->blending));
1985
1986 if(configMdp(ctx->mOverlay, pargL, orient,
1987 cropL, dstL, metadata, lDest) < 0) {
1988 ALOGE("%s: commit failed for left mixer config", __FUNCTION__);
1989 return -1;
1990 }
1991 }
1992
1993 //configure right pipe
1994 if(rDest != OV_INVALID) {
1995 PipeArgs pargR(mdpFlagsR, whf, z, isFg,
1996 static_cast<eRotFlags>(rotFlags),
1997 layer->planeAlpha,
1998 (ovutils::eBlending) getBlending(layer->blending));
1999 if(configMdp(ctx->mOverlay, pargR, orient,
2000 cropR, dstR, metadata, rDest) < 0) {
2001 ALOGE("%s: commit failed for right mixer config", __FUNCTION__);
2002 return -1;
2003 }
2004 }
2005
2006 return 0;
2007}
2008
Naseer Ahmed7c958d42012-07-31 18:57:03 -07002009}; //namespace
2010