blob: de41d8722dd43f3a6ff5892d19f4c071e8863ad1 [file] [log] [blame]
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001/*
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002 * Copyright (C) 2012-2013, 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;
41bool MDPComp::sDebugLogs = false;
Naseer Ahmed54821fe2012-11-28 18:44:38 -050042bool MDPComp::sEnabled = false;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -070043bool MDPComp::sEnableMixedMode = true;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -070044bool MDPComp::sEnablePartialFrameUpdate = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080045int MDPComp::sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
radhakrishnac9a67412013-09-25 17:40:42 +053046bool MDPComp::sEnable4k2kYUVSplit = false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070047
Saurabh Shah88e4d272013-09-03 13:31:29 -070048MDPComp* MDPComp::getObject(hwc_context_t *ctx, const int& dpy) {
49 if(isDisplaySplit(ctx, dpy)) {
50 return new MDPCompSplit(dpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080051 }
Saurabh Shah88e4d272013-09-03 13:31:29 -070052 return new MDPCompNonSplit(dpy);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080053}
54
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080055MDPComp::MDPComp(int dpy):mDpy(dpy){};
56
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080057void MDPComp::dump(android::String8& buf)
58{
Jeykumar Sankaran3c6bb042013-08-15 14:01:04 -070059 if(mCurrentFrame.layerCount > MAX_NUM_APP_LAYERS)
60 return;
61
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080062 dumpsys_log(buf,"HWC Map for Dpy: %s \n",
Jeykumar Sankaran27dee262013-08-01 17:09:54 -070063 (mDpy == 0) ? "\"PRIMARY\"" :
64 (mDpy == 1) ? "\"EXTERNAL\"" : "\"VIRTUAL\"");
Saurabh Shahe9bc60f2013-08-29 12:58:06 -070065 dumpsys_log(buf,"CURR_FRAME: layerCount:%2d mdpCount:%2d "
66 "fbCount:%2d \n", mCurrentFrame.layerCount,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080067 mCurrentFrame.mdpCount, mCurrentFrame.fbCount);
68 dumpsys_log(buf,"needsFBRedraw:%3s pipesUsed:%2d MaxPipesPerMixer: %d \n",
69 (mCurrentFrame.needsRedraw? "YES" : "NO"),
70 mCurrentFrame.mdpCount, sMaxPipesPerMixer);
71 dumpsys_log(buf," --------------------------------------------- \n");
72 dumpsys_log(buf," listIdx | cached? | mdpIndex | comptype | Z \n");
73 dumpsys_log(buf," --------------------------------------------- \n");
74 for(int index = 0; index < mCurrentFrame.layerCount; index++ )
75 dumpsys_log(buf," %7d | %7s | %8d | %9s | %2d \n",
76 index,
77 (mCurrentFrame.isFBComposed[index] ? "YES" : "NO"),
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -070078 mCurrentFrame.layerToMDP[index],
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080079 (mCurrentFrame.isFBComposed[index] ?
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -070080 (mCurrentFrame.drop[index] ? "DROP" :
81 (mCurrentFrame.needsRedraw ? "GLES" : "CACHE")) : "MDP"),
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080082 (mCurrentFrame.isFBComposed[index] ? mCurrentFrame.fbZ :
83 mCurrentFrame.mdpToLayer[mCurrentFrame.layerToMDP[index]].pipeInfo->zOrder));
84 dumpsys_log(buf,"\n");
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080085}
86
87bool MDPComp::init(hwc_context_t *ctx) {
88
89 if(!ctx) {
90 ALOGE("%s: Invalid hwc context!!",__FUNCTION__);
91 return false;
92 }
93
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080094 char property[PROPERTY_VALUE_MAX];
95
96 sEnabled = false;
97 if((property_get("persist.hwc.mdpcomp.enable", property, NULL) > 0) &&
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080098 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
99 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800100 sEnabled = true;
101 }
102
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700103 sEnableMixedMode = true;
104 if((property_get("debug.mdpcomp.mixedmode.disable", property, NULL) > 0) &&
105 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
106 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
107 sEnableMixedMode = false;
108 }
109
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800110 if(property_get("debug.mdpcomp.logs", property, NULL) > 0) {
111 if(atoi(property) != 0)
112 sDebugLogs = true;
113 }
114
Jeykumar Sankaran18469742014-02-19 12:40:57 -0800115 if(property_get("persist.hwc.partialupdate", property, NULL) > 0) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700116 if((atoi(property) != 0) && ctx->mMDP.panel == MIPI_CMD_PANEL &&
117 qdutils::MDPVersion::getInstance().is8x74v2())
118 sEnablePartialFrameUpdate = true;
119 }
120 ALOGE_IF(isDebug(), "%s: Partial Update applicable?: %d",__FUNCTION__,
121 sEnablePartialFrameUpdate);
122
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800123 sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
Saurabh Shah85234ec2013-04-12 17:09:00 -0700124 if(property_get("debug.mdpcomp.maxpermixer", property, "-1") > 0) {
125 int val = atoi(property);
126 if(val >= 0)
127 sMaxPipesPerMixer = min(val, MAX_PIPES_PER_MIXER);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800128 }
129
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400130 if(ctx->mMDP.panel != MIPI_CMD_PANEL) {
131 // Idle invalidation is not necessary on command mode panels
132 long idle_timeout = DEFAULT_IDLE_TIME;
133 if(property_get("debug.mdpcomp.idletime", property, NULL) > 0) {
134 if(atoi(property) != 0)
135 idle_timeout = atoi(property);
136 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800137
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400138 //create Idle Invalidator only when not disabled through property
139 if(idle_timeout != -1)
140 idleInvalidator = IdleInvalidator::getInstance();
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800141
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400142 if(idleInvalidator == NULL) {
143 ALOGE("%s: failed to instantiate idleInvalidator object",
144 __FUNCTION__);
145 } else {
146 idleInvalidator->init(timeout_handler, ctx, idle_timeout);
147 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800148 }
radhakrishnac9a67412013-09-25 17:40:42 +0530149
150 if((property_get("debug.mdpcomp.4k2kSplit", property, "0") > 0) &&
151 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
152 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
153 sEnable4k2kYUVSplit = true;
154 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700155 return true;
156}
157
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800158void MDPComp::reset(hwc_context_t *ctx) {
159 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700160 mCurrentFrame.reset(numLayers);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800161 ctx->mOverlay->clear(mDpy);
162 ctx->mLayerRotMap[mDpy]->clear();
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700163}
164
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700165void MDPComp::timeout_handler(void *udata) {
166 struct hwc_context_t* ctx = (struct hwc_context_t*)(udata);
167
168 if(!ctx) {
169 ALOGE("%s: received empty data in timer callback", __FUNCTION__);
170 return;
171 }
172
Jesse Hall3be78d92012-08-21 15:12:23 -0700173 if(!ctx->proc) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700174 ALOGE("%s: HWC proc not registered", __FUNCTION__);
175 return;
176 }
177 sIdleFallBack = true;
178 /* Trigger SF to redraw the current frame */
Jesse Hall3be78d92012-08-21 15:12:23 -0700179 ctx->proc->invalidate(ctx->proc);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700180}
181
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800182void MDPComp::setMDPCompLayerFlags(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800183 hwc_display_contents_1_t* list) {
184 LayerProp *layerProp = ctx->layerProp[mDpy];
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800185
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800186 for(int index = 0; index < ctx->listStats[mDpy].numAppLayers; index++) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800187 hwc_layer_1_t* layer = &(list->hwLayers[index]);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800188 if(!mCurrentFrame.isFBComposed[index]) {
189 layerProp[index].mFlags |= HWC_MDPCOMP;
190 layer->compositionType = HWC_OVERLAY;
191 layer->hints |= HWC_HINT_CLEAR_FB;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800192 } else {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700193 /* Drop the layer when its already present in FB OR when it lies
194 * outside frame's ROI */
195 if(!mCurrentFrame.needsRedraw || mCurrentFrame.drop[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800196 layer->compositionType = HWC_OVERLAY;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700197 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800198 }
199 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700200}
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500201
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800202void MDPComp::setRedraw(hwc_context_t *ctx,
203 hwc_display_contents_1_t* list) {
204 mCurrentFrame.needsRedraw = false;
205 if(!mCachedFrame.isSameFrame(mCurrentFrame, list) ||
206 (list->flags & HWC_GEOMETRY_CHANGED) ||
207 isSkipPresent(ctx, mDpy)) {
208 mCurrentFrame.needsRedraw = true;
209 }
210}
211
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800212MDPComp::FrameInfo::FrameInfo() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700213 reset(0);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800214}
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800215
Saurabh Shahaa236822013-04-24 18:07:26 -0700216void MDPComp::FrameInfo::reset(const int& numLayers) {
217 for(int i = 0 ; i < MAX_PIPES_PER_MIXER && numLayers; i++ ) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800218 if(mdpToLayer[i].pipeInfo) {
219 delete mdpToLayer[i].pipeInfo;
220 mdpToLayer[i].pipeInfo = NULL;
221 //We dont own the rotator
222 mdpToLayer[i].rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800223 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800224 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800225
226 memset(&mdpToLayer, 0, sizeof(mdpToLayer));
227 memset(&layerToMDP, -1, sizeof(layerToMDP));
Saurabh Shahaa236822013-04-24 18:07:26 -0700228 memset(&isFBComposed, 1, sizeof(isFBComposed));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800229
Saurabh Shahaa236822013-04-24 18:07:26 -0700230 layerCount = numLayers;
231 fbCount = numLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800232 mdpCount = 0;
Saurabh Shah2f3895f2013-05-02 10:13:31 -0700233 needsRedraw = true;
Saurabh Shahce188452014-02-05 10:17:43 -0800234 fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800235}
236
Saurabh Shahaa236822013-04-24 18:07:26 -0700237void MDPComp::FrameInfo::map() {
238 // populate layer and MDP maps
239 int mdpIdx = 0;
240 for(int idx = 0; idx < layerCount; idx++) {
241 if(!isFBComposed[idx]) {
242 mdpToLayer[mdpIdx].listIndex = idx;
243 layerToMDP[idx] = mdpIdx++;
244 }
245 }
246}
247
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800248MDPComp::LayerCache::LayerCache() {
249 reset();
250}
251
252void MDPComp::LayerCache::reset() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700253 memset(&hnd, 0, sizeof(hnd));
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530254 memset(&isFBComposed, true, sizeof(isFBComposed));
255 memset(&drop, false, sizeof(drop));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800256 layerCount = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -0700257}
258
259void MDPComp::LayerCache::cacheAll(hwc_display_contents_1_t* list) {
260 const int numAppLayers = list->numHwLayers - 1;
261 for(int i = 0; i < numAppLayers; i++) {
262 hnd[i] = list->hwLayers[i].handle;
263 }
264}
265
266void MDPComp::LayerCache::updateCounts(const FrameInfo& curFrame) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700267 layerCount = curFrame.layerCount;
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530268 memcpy(&isFBComposed, &curFrame.isFBComposed, sizeof(isFBComposed));
269 memcpy(&drop, &curFrame.drop, sizeof(drop));
270}
271
Jeykumar Sankaran988d3682013-11-15 11:57:16 -0800272bool MDPComp::LayerCache::isSameFrame(const FrameInfo& curFrame,
273 hwc_display_contents_1_t* list) {
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530274 if(layerCount != curFrame.layerCount)
275 return false;
276 for(int i = 0; i < curFrame.layerCount; i++) {
277 if((curFrame.isFBComposed[i] != isFBComposed[i]) ||
278 (curFrame.drop[i] != drop[i])) {
279 return false;
280 }
Jeykumar Sankaran988d3682013-11-15 11:57:16 -0800281 if(curFrame.isFBComposed[i] &&
282 (hnd[i] != list->hwLayers[i].handle)){
283 return false;
284 }
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530285 }
286 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800287}
288
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700289bool MDPComp::isSupportedForMDPComp(hwc_context_t *ctx, hwc_layer_1_t* layer) {
290 private_handle_t *hnd = (private_handle_t *)layer->handle;
291 if((not isYuvBuffer(hnd) and has90Transform(layer)) or
292 (not isValidDimension(ctx,layer))
293 //More conditions here, SKIP, sRGB+Blend etc
294 ) {
295 return false;
296 }
297 return true;
298}
299
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530300bool MDPComp::isValidDimension(hwc_context_t *ctx, hwc_layer_1_t *layer) {
Saurabh Shah4fdde762013-04-30 18:47:33 -0700301 const int dpy = HWC_DISPLAY_PRIMARY;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800302 private_handle_t *hnd = (private_handle_t *)layer->handle;
303
304 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -0700305 if (layer->flags & HWC_COLOR_FILL) {
306 // Color layer
307 return true;
308 }
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800309 ALOGE("%s: layer handle is NULL", __FUNCTION__);
310 return false;
311 }
312
Naseer Ahmede850a802013-09-06 13:12:52 -0400313 //XXX: Investigate doing this with pixel phase on MDSS
Naseer Ahmede77f8082013-10-10 13:42:48 -0400314 if(!isSecureBuffer(hnd) && isNonIntegralSourceCrop(layer->sourceCropf))
Naseer Ahmede850a802013-09-06 13:12:52 -0400315 return false;
316
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800317 int hw_w = ctx->dpyAttr[mDpy].xres;
318 int hw_h = ctx->dpyAttr[mDpy].yres;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800319
Saurabh Shah62e1d732013-09-17 10:44:05 -0700320 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700321 hwc_rect_t dst = layer->displayFrame;
Saurabh Shah4fdde762013-04-30 18:47:33 -0700322 int crop_w = crop.right - crop.left;
323 int crop_h = crop.bottom - crop.top;
324 int dst_w = dst.right - dst.left;
325 int dst_h = dst.bottom - dst.top;
326 float w_dscale = ceilf((float)crop_w / (float)dst_w);
327 float h_dscale = ceilf((float)crop_h / (float)dst_h);
328
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800329 /* Workaround for MDP HW limitation in DSI command mode panels where
330 * FPS will not go beyond 30 if buffers on RGB pipes are of width or height
331 * less than 5 pixels
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530332 * There also is a HW limilation in MDP, minimum block size is 2x2
333 * Fallback to GPU if height is less than 2.
334 */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800335 if((crop_w < 5)||(crop_h < 5))
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800336 return false;
337
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800338 if((w_dscale > 1.0f) || (h_dscale > 1.0f)) {
339 const uint32_t downscale =
Saurabh Shah4fdde762013-04-30 18:47:33 -0700340 qdutils::MDPVersion::getInstance().getMaxMDPDownscale();
Jeykumar Sankaran1706a772013-11-27 12:55:19 -0800341 if(ctx->mMDP.version >= qdutils::MDSS_V5) {
342 /* Workaround for downscales larger than 4x.
343 * Will be removed once decimator block is enabled for MDSS
344 */
345 if(!qdutils::MDPVersion::getInstance().supportsDecimation()) {
346 if(crop_w > MAX_DISPLAY_DIM || w_dscale > downscale ||
347 h_dscale > downscale)
348 return false;
349 } else {
350 if(w_dscale > 64 || h_dscale > 64)
351 return false;
352 }
353 } else { //A-family
354 if(w_dscale > downscale || h_dscale > downscale)
Saurabh Shah4fdde762013-04-30 18:47:33 -0700355 return false;
356 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700357 }
358
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800359 return true;
360}
361
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700362ovutils::eDest MDPComp::getMdpPipe(hwc_context_t *ctx, ePipeType type,
363 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800364 overlay::Overlay& ov = *ctx->mOverlay;
365 ovutils::eDest mdp_pipe = ovutils::OV_INVALID;
366
367 switch(type) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800368 case MDPCOMP_OV_DMA:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700369 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_DMA, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800370 if(mdp_pipe != ovutils::OV_INVALID) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800371 return mdp_pipe;
372 }
373 case MDPCOMP_OV_ANY:
374 case MDPCOMP_OV_RGB:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700375 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800376 if(mdp_pipe != ovutils::OV_INVALID) {
377 return mdp_pipe;
378 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800379
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800380 if(type == MDPCOMP_OV_RGB) {
381 //Requested only for RGB pipe
382 break;
383 }
384 case MDPCOMP_OV_VG:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700385 return ov.nextPipe(ovutils::OV_MDP_PIPE_VG, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800386 default:
387 ALOGE("%s: Invalid pipe type",__FUNCTION__);
388 return ovutils::OV_INVALID;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800389 };
390 return ovutils::OV_INVALID;
391}
392
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800393bool MDPComp::isFrameDoable(hwc_context_t *ctx) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700394 bool ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700395 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800396
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800397 if(!isEnabled()) {
398 ALOGD_IF(isDebug(),"%s: MDP Comp. not enabled.", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700399 ret = false;
Saurabh Shahd4e65852013-06-17 11:33:53 -0700400 } else if(qdutils::MDPVersion::getInstance().is8x26() &&
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700401 ctx->mVideoTransFlag && ctx->mVirtualDisplay->isConnected()) {
Saurabh Shahd4e65852013-06-17 11:33:53 -0700402 //1 Padding round to shift pipes across mixers
403 ALOGD_IF(isDebug(),"%s: MDP Comp. video transition padding round",
404 __FUNCTION__);
405 ret = false;
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700406 } else if(ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isConfiguring ||
407 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isConfiguring) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800408 ALOGD_IF( isDebug(),"%s: External Display connection is pending",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800409 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700410 ret = false;
Saurabh Shahaa236822013-04-24 18:07:26 -0700411 } else if(ctx->isPaddingRound) {
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700412 ctx->isPaddingRound = false;
413 ALOGD_IF(isDebug(), "%s: padding round",__FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700414 ret = false;
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700415 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700416 return ret;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800417}
418
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800419/*
420 * 1) Identify layers that are not visible in the updating ROI and drop them
421 * from composition.
422 * 2) If we have a scaling layers which needs cropping against generated ROI.
423 * Reset ROI to full resolution.
424 */
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700425bool MDPComp::validateAndApplyROI(hwc_context_t *ctx,
426 hwc_display_contents_1_t* list, hwc_rect_t roi) {
427 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
428
429 if(!isValidRect(roi))
430 return false;
431
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800432 hwc_rect_t visibleRect = roi;
433
434 for(int i = numAppLayers - 1; i >= 0; i--){
435
436 if(!isValidRect(visibleRect)) {
437 mCurrentFrame.drop[i] = true;
438 mCurrentFrame.dropCount++;
Jeykumar Sankaran65bc8022014-01-21 17:26:12 -0800439 continue;
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800440 }
441
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700442 const hwc_layer_1_t* layer = &list->hwLayers[i];
443
444 hwc_rect_t dstRect = layer->displayFrame;
Arun Kumar K.R91090c72013-10-28 19:40:18 -0700445 hwc_rect_t srcRect = integerizeSourceCrop(layer->sourceCropf);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700446 int transform = layer->transform;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700447
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800448 hwc_rect_t res = getIntersection(visibleRect, dstRect);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700449
450 int res_w = res.right - res.left;
451 int res_h = res.bottom - res.top;
452 int dst_w = dstRect.right - dstRect.left;
453 int dst_h = dstRect.bottom - dstRect.top;
454
455 if(!isValidRect(res)) {
456 mCurrentFrame.drop[i] = true;
457 mCurrentFrame.dropCount++;
458 }else {
459 /* Reset frame ROI when any layer which needs scaling also needs ROI
460 * cropping */
Jeykumar Sankaran65bc8022014-01-21 17:26:12 -0800461 if((res_w != dst_w || res_h != dst_h) && needsScaling (layer)) {
Arpita Banerjeed8965982013-11-08 17:27:33 -0800462 ALOGI("%s: Resetting ROI due to scaling", __FUNCTION__);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700463 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
464 mCurrentFrame.dropCount = 0;
465 return false;
466 }
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800467
Jeykumar Sankaran65bc8022014-01-21 17:26:12 -0800468 /* deduct any opaque region from visibleRect */
469 if (layer->blending == HWC_BLENDING_NONE)
470 visibleRect = deductRect(visibleRect, res);
471 }
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700472 }
473 return true;
474}
475
476void MDPComp::generateROI(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
477 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
478
479 if(!sEnablePartialFrameUpdate) {
480 return;
481 }
482
483 if(mDpy || isDisplaySplit(ctx, mDpy)){
484 ALOGE_IF(isDebug(), "%s: ROI not supported for"
485 "the (1) external / virtual display's (2) dual DSI displays",
486 __FUNCTION__);
487 return;
488 }
489
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800490 if(isSkipPresent(ctx, mDpy))
491 return;
492
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700493 if(list->flags & HWC_GEOMETRY_CHANGED)
494 return;
495
496 struct hwc_rect roi = (struct hwc_rect){0, 0, 0, 0};
497 for(int index = 0; index < numAppLayers; index++ ) {
498 if ((mCachedFrame.hnd[index] != list->hwLayers[index].handle) ||
499 isYuvBuffer((private_handle_t *)list->hwLayers[index].handle)) {
500 hwc_rect_t dstRect = list->hwLayers[index].displayFrame;
Arun Kumar K.R91090c72013-10-28 19:40:18 -0700501 hwc_rect_t srcRect = integerizeSourceCrop(
502 list->hwLayers[index].sourceCropf);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700503 int transform = list->hwLayers[index].transform;
504
505 /* Intersect against display boundaries */
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700506 roi = getUnion(roi, dstRect);
507 }
508 }
509
510 if(!validateAndApplyROI(ctx, list, roi)){
511 roi = (struct hwc_rect) {0, 0,
512 (int)ctx->dpyAttr[mDpy].xres, (int)ctx->dpyAttr[mDpy].yres};
513 }
514
515 ctx->listStats[mDpy].roi.x = roi.left;
516 ctx->listStats[mDpy].roi.y = roi.top;
517 ctx->listStats[mDpy].roi.w = roi.right - roi.left;
518 ctx->listStats[mDpy].roi.h = roi.bottom - roi.top;
519
520 ALOGD_IF(isDebug(),"%s: generated ROI: [%d, %d, %d, %d]", __FUNCTION__,
521 roi.left, roi.top, roi.right, roi.bottom);
522}
523
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800524/* Checks for conditions where all the layers marked for MDP comp cannot be
525 * bypassed. On such conditions we try to bypass atleast YUV layers */
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800526bool MDPComp::tryFullFrame(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800527 hwc_display_contents_1_t* list){
528
Saurabh Shahaa236822013-04-24 18:07:26 -0700529 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800530
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -0700531 if(sIdleFallBack && !ctx->listStats[mDpy].secureUI) {
Saurabh Shah2d998a92013-05-14 17:55:58 -0700532 ALOGD_IF(isDebug(), "%s: Idle fallback dpy %d",__FUNCTION__, mDpy);
533 return false;
534 }
535
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800536 if(isSkipPresent(ctx, mDpy)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700537 ALOGD_IF(isDebug(),"%s: SKIP present: %d",
538 __FUNCTION__,
539 isSkipPresent(ctx, mDpy));
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800540 return false;
541 }
542
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800543 // check for action safe flag and downscale mode which requires scaling.
544 if(ctx->dpyAttr[mDpy].mActionSafePresent
545 || ctx->dpyAttr[mDpy].mDownScaleMode) {
546 ALOGD_IF(isDebug(), "%s: Scaling needed for this frame",__FUNCTION__);
547 return false;
548 }
549
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800550 for(int i = 0; i < numAppLayers; ++i) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800551 hwc_layer_1_t* layer = &list->hwLayers[i];
552 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800553
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700554 if(isYuvBuffer(hnd) && has90Transform(layer)) {
555 if(!canUseRotator(ctx, mDpy)) {
556 ALOGD_IF(isDebug(), "%s: Can't use rotator for dpy %d",
557 __FUNCTION__, mDpy);
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700558 return false;
559 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800560 }
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530561
562 //For 8x26 with panel width>1k, if RGB layer needs HFLIP fail mdp comp
563 // may not need it if Gfx pre-rotation can handle all flips & rotations
564 if(qdutils::MDPVersion::getInstance().is8x26() &&
565 (ctx->dpyAttr[mDpy].xres > 1024) &&
566 (layer->transform & HWC_TRANSFORM_FLIP_H) &&
567 (!isYuvBuffer(hnd)))
568 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800569 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700570
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700571 if(ctx->mAD->isDoable()) {
572 return false;
573 }
574
Saurabh Shahaa236822013-04-24 18:07:26 -0700575 //If all above hard conditions are met we can do full or partial MDP comp.
576 bool ret = false;
577 if(fullMDPComp(ctx, list)) {
578 ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700579 } else if(partialMDPComp(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700580 ret = true;
581 }
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530582
Saurabh Shahaa236822013-04-24 18:07:26 -0700583 return ret;
584}
585
586bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700587 //Will benefit presentation / secondary-only layer.
588 if((mDpy > HWC_DISPLAY_PRIMARY) &&
589 (list->numHwLayers - 1) > MAX_SEC_LAYERS) {
590 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
591 return false;
592 }
593
594 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
595 for(int i = 0; i < numAppLayers; i++) {
596 hwc_layer_1_t* layer = &list->hwLayers[i];
597 if(not isSupportedForMDPComp(ctx, layer)) {
598 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",__FUNCTION__);
599 return false;
600 }
Yang Xu9c1eb2b2013-11-26 01:28:13 +0800601
602 //For 8x26, if there is only one layer which needs scale for secondary
603 //while no scale for primary display, DMA pipe is occupied by primary.
604 //If need to fall back to GLES composition, virtual display lacks DMA
605 //pipe and error is reported.
606 if(qdutils::MDPVersion::getInstance().is8x26() &&
607 mDpy >= HWC_DISPLAY_EXTERNAL &&
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530608 qhwc::needsScaling(layer))
Yang Xu9c1eb2b2013-11-26 01:28:13 +0800609 return false;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700610 }
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800611
Saurabh Shahaa236822013-04-24 18:07:26 -0700612 mCurrentFrame.fbCount = 0;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700613 memcpy(&mCurrentFrame.isFBComposed, &mCurrentFrame.drop,
614 sizeof(mCurrentFrame.isFBComposed));
615 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount -
616 mCurrentFrame.dropCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700617
radhakrishnac9a67412013-09-25 17:40:42 +0530618 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800619 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530620 }
621
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800622 if(!postHeuristicsHandling(ctx, list)) {
623 ALOGD_IF(isDebug(), "post heuristic handling failed");
624 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700625 return false;
626 }
627
Saurabh Shahaa236822013-04-24 18:07:26 -0700628 return true;
629}
630
631bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
632{
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700633 if(!sEnableMixedMode) {
634 //Mixed mode is disabled. No need to even try caching.
635 return false;
636 }
637
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700638 bool ret = false;
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800639 if(list->flags & HWC_GEOMETRY_CHANGED) { //Try load based first
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800640 ret = loadBasedComp(ctx, list) or
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800641 cacheBasedComp(ctx, list);
642 } else {
643 ret = cacheBasedComp(ctx, list) or
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800644 loadBasedComp(ctx, list);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700645 }
646
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700647 return ret;
648}
649
650bool MDPComp::cacheBasedComp(hwc_context_t *ctx,
651 hwc_display_contents_1_t* list) {
652 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700653 mCurrentFrame.reset(numAppLayers);
654 updateLayerCache(ctx, list);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700655
656 //If an MDP marked layer is unsupported cannot do partial MDP Comp
657 for(int i = 0; i < numAppLayers; i++) {
658 if(!mCurrentFrame.isFBComposed[i]) {
659 hwc_layer_1_t* layer = &list->hwLayers[i];
660 if(not isSupportedForMDPComp(ctx, layer)) {
661 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",
662 __FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800663 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700664 return false;
665 }
666 }
667 }
668
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700669 updateYUV(ctx, list, false /*secure only*/);
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530670 bool ret = markLayersForCaching(ctx, list); //sets up fbZ also
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700671 if(!ret) {
672 ALOGD_IF(isDebug(),"%s: batching failed, dpy %d",__FUNCTION__, mDpy);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800673 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700674 return false;
675 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700676
677 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700678
radhakrishnac9a67412013-09-25 17:40:42 +0530679 if(sEnable4k2kYUVSplit){
Saurabh Shah3d4b8042013-12-10 15:19:17 -0800680 adjustForSourceSplit(ctx, list);
radhakrishnac9a67412013-09-25 17:40:42 +0530681 }
682
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700683 //Will benefit cases where a video has non-updating background.
684 if((mDpy > HWC_DISPLAY_PRIMARY) and
685 (mdpCount > MAX_SEC_LAYERS)) {
686 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800687 reset(ctx);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700688 return false;
689 }
690
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800691 if(!postHeuristicsHandling(ctx, list)) {
692 ALOGD_IF(isDebug(), "post heuristic handling failed");
693 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700694 return false;
695 }
696
Saurabh Shahaa236822013-04-24 18:07:26 -0700697 return true;
698}
699
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800700bool MDPComp::loadBasedComp(hwc_context_t *ctx,
Saurabh Shahb772ae32013-11-18 15:40:02 -0800701 hwc_display_contents_1_t* list) {
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800702 if(not isLoadBasedCompDoable(ctx, list)) {
703 return false;
704 }
705
Saurabh Shahb772ae32013-11-18 15:40:02 -0800706 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800707 const int numNonDroppedLayers = numAppLayers - mCurrentFrame.dropCount;
708 const int stagesForMDP = min(sMaxPipesPerMixer,
709 ctx->mOverlay->availablePipes(mDpy, Overlay::MIXER_DEFAULT));
Saurabh Shahf2de00f2013-12-11 17:52:53 -0800710
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800711 int mdpBatchSize = stagesForMDP - 1; //1 stage for FB
712 int fbBatchSize = numNonDroppedLayers - mdpBatchSize;
713 int lastMDPSupportedIndex = numAppLayers;
714 int dropCount = 0;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800715
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800716 //Find the minimum MDP batch size
717 for(int i = 0; i < numAppLayers;i++) {
718 if(mCurrentFrame.drop[i]) {
719 dropCount++;
Jeykumar Sankaran6279bc32014-01-23 21:59:58 -0800720 continue;
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800721 }
722 hwc_layer_1_t* layer = &list->hwLayers[i];
723 if(not isSupportedForMDPComp(ctx, layer)) {
724 lastMDPSupportedIndex = i;
725 mdpBatchSize = min(i - dropCount, stagesForMDP - 1);
726 fbBatchSize = numNonDroppedLayers - mdpBatchSize;
Jeykumar Sankaran6279bc32014-01-23 21:59:58 -0800727 break;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800728 }
Saurabh Shahb772ae32013-11-18 15:40:02 -0800729 }
730
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800731 ALOGD_IF(isDebug(), "%s:Before optimizing fbBatch, mdpbatch %d, fbbatch %d "
732 "dropped %d", __FUNCTION__, mdpBatchSize, fbBatchSize,
733 mCurrentFrame.dropCount);
734
735 //Start at a point where the fb batch should at least have 2 layers, for
736 //this mode to be justified.
737 while(fbBatchSize < 2) {
738 ++fbBatchSize;
739 --mdpBatchSize;
Jeykumar Sankaran6279bc32014-01-23 21:59:58 -0800740 }
Saurabh Shahb772ae32013-11-18 15:40:02 -0800741
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800742 //If there are no layers for MDP, this mode doesnt make sense.
743 if(mdpBatchSize < 1) {
744 ALOGD_IF(isDebug(), "%s: No MDP layers after optimizing for fbBatch",
745 __FUNCTION__);
Saurabh Shahb772ae32013-11-18 15:40:02 -0800746 return false;
747 }
748
Saurabh Shah6e8ab772014-02-20 16:18:45 -0800749 mCurrentFrame.reset(numAppLayers);
750
751 //Try with successively smaller mdp batch sizes until we succeed or reach 1
752 while(mdpBatchSize > 0) {
753 //Mark layers for MDP comp
754 int mdpBatchLeft = mdpBatchSize;
755 for(int i = 0; i < lastMDPSupportedIndex and mdpBatchLeft; i++) {
756 if(mCurrentFrame.drop[i]) {
757 continue;
758 }
759 mCurrentFrame.isFBComposed[i] = false;
760 --mdpBatchLeft;
761 }
762
763 mCurrentFrame.fbZ = mdpBatchSize;
764 mCurrentFrame.fbCount = fbBatchSize;
765 mCurrentFrame.mdpCount = mdpBatchSize;
766
767 ALOGD_IF(isDebug(), "%s:Trying with: mdpbatch %d fbbatch %d dropped %d",
768 __FUNCTION__, mdpBatchSize, fbBatchSize,
769 mCurrentFrame.dropCount);
770
771 if(postHeuristicsHandling(ctx, list)) {
772 ALOGD_IF(isDebug(), "%s: Postheuristics handling succeeded",
773 __FUNCTION__);
774 return true;
775 }
776
777 reset(ctx);
778 --mdpBatchSize;
779 ++fbBatchSize;
780 }
781
782 return false;
Saurabh Shahb772ae32013-11-18 15:40:02 -0800783}
784
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700785bool MDPComp::isLoadBasedCompDoable(hwc_context_t *ctx,
786 hwc_display_contents_1_t* list) {
Prabhanjan Kandula3dbbd882013-12-11 14:43:46 +0530787 if(mDpy or isSecurePresent(ctx, mDpy) or
788 isYuvPresent(ctx, mDpy)) {
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700789 return false;
790 }
791 return true;
792}
793
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800794bool MDPComp::tryVideoOnly(hwc_context_t *ctx,
795 hwc_display_contents_1_t* list) {
796 const bool secureOnly = true;
797 return videoOnlyComp(ctx, list, not secureOnly) or
798 videoOnlyComp(ctx, list, secureOnly);
799}
800
801bool MDPComp::videoOnlyComp(hwc_context_t *ctx,
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700802 hwc_display_contents_1_t* list, bool secureOnly) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700803 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700804
Saurabh Shahaa236822013-04-24 18:07:26 -0700805 mCurrentFrame.reset(numAppLayers);
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700806 updateYUV(ctx, list, secureOnly);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700807 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700808
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800809 if(!isYuvPresent(ctx, mDpy) or (mdpCount == 0)) {
810 reset(ctx);
Saurabh Shahaa236822013-04-24 18:07:26 -0700811 return false;
812 }
813
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -0800814 /* Bail out if we are processing only secured video layers
815 * and we dont have any */
816 if(!isSecurePresent(ctx, mDpy) && secureOnly){
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800817 reset(ctx);
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -0800818 return false;
819 }
820
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800821 if(mCurrentFrame.fbCount)
822 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
Saurabh Shah4fdde762013-04-30 18:47:33 -0700823
Saurabh Shahdf4741d2013-12-12 16:40:28 -0800824 if(sEnable4k2kYUVSplit){
825 adjustForSourceSplit(ctx, list);
826 }
827
828 if(!postHeuristicsHandling(ctx, list)) {
829 ALOGD_IF(isDebug(), "post heuristic handling failed");
830 reset(ctx);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700831 return false;
832 }
833
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800834 return true;
835}
836
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800837/* Checks for conditions where YUV layers cannot be bypassed */
838bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -0700839 if(isSkipLayer(layer)) {
Saurabh Shahe2474082013-05-15 16:32:13 -0700840 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800841 return false;
842 }
843
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700844 if(layer->transform & HWC_TRANSFORM_ROT_90 && !canUseRotator(ctx,mDpy)) {
845 ALOGD_IF(isDebug(), "%s: no free DMA pipe",__FUNCTION__);
846 return false;
847 }
848
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800849 if(isSecuring(ctx, layer)) {
850 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
851 return false;
852 }
853
Saurabh Shah4fdde762013-04-30 18:47:33 -0700854 if(!isValidDimension(ctx, layer)) {
855 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
856 __FUNCTION__);
857 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800858 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700859
Naseer Ahmeddc61a972013-07-10 17:50:54 -0400860 if(layer->planeAlpha < 0xFF) {
861 ALOGD_IF(isDebug(), "%s: Cannot handle YUV layer with plane alpha\
862 in video only mode",
863 __FUNCTION__);
864 return false;
865 }
866
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800867 return true;
868}
869
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530870/* starts at fromIndex and check for each layer to find
871 * if it it has overlapping with any Updating layer above it in zorder
872 * till the end of the batch. returns true if it finds any intersection */
873bool MDPComp::canPushBatchToTop(const hwc_display_contents_1_t* list,
874 int fromIndex, int toIndex) {
875 for(int i = fromIndex; i < toIndex; i++) {
876 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
877 if(intersectingUpdatingLayers(list, i+1, toIndex, i)) {
878 return false;
879 }
880 }
881 }
882 return true;
883}
884
885/* Checks if given layer at targetLayerIndex has any
886 * intersection with all the updating layers in beween
887 * fromIndex and toIndex. Returns true if it finds intersectiion */
888bool MDPComp::intersectingUpdatingLayers(const hwc_display_contents_1_t* list,
889 int fromIndex, int toIndex, int targetLayerIndex) {
890 for(int i = fromIndex; i <= toIndex; i++) {
891 if(!mCurrentFrame.isFBComposed[i]) {
892 if(areLayersIntersecting(&list->hwLayers[i],
893 &list->hwLayers[targetLayerIndex])) {
894 return true;
895 }
896 }
897 }
898 return false;
899}
900
901int MDPComp::getBatch(hwc_display_contents_1_t* list,
902 int& maxBatchStart, int& maxBatchEnd,
903 int& maxBatchCount) {
904 int i = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530905 int fbZOrder =-1;
Jeykumar Sankaran5a495da2014-01-20 12:25:32 -0800906 int droppedLayerCt = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530907 while (i < mCurrentFrame.layerCount) {
908 int batchCount = 0;
909 int batchStart = i;
910 int batchEnd = i;
Jeykumar Sankaran5a495da2014-01-20 12:25:32 -0800911 /* Adjust batch Z order with the dropped layers so far */
912 int fbZ = batchStart - droppedLayerCt;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530913 int firstZReverseIndex = -1;
Prabhanjan Kandula0ed2cc92013-12-06 12:39:04 +0530914 int updatingLayersAbove = 0;//Updating layer count in middle of batch
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530915 while(i < mCurrentFrame.layerCount) {
916 if(!mCurrentFrame.isFBComposed[i]) {
917 if(!batchCount) {
918 i++;
919 break;
920 }
921 updatingLayersAbove++;
922 i++;
923 continue;
924 } else {
925 if(mCurrentFrame.drop[i]) {
926 i++;
Jeykumar Sankaran5a495da2014-01-20 12:25:32 -0800927 droppedLayerCt++;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530928 continue;
929 } else if(updatingLayersAbove <= 0) {
930 batchCount++;
931 batchEnd = i;
932 i++;
933 continue;
934 } else { //Layer is FBComposed, not a drop & updatingLayer > 0
935
936 // We have a valid updating layer already. If layer-i not
937 // have overlapping with all updating layers in between
938 // batch-start and i, then we can add layer i to batch.
939 if(!intersectingUpdatingLayers(list, batchStart, i-1, i)) {
940 batchCount++;
941 batchEnd = i;
942 i++;
943 continue;
944 } else if(canPushBatchToTop(list, batchStart, i)) {
945 //If All the non-updating layers with in this batch
946 //does not have intersection with the updating layers
947 //above in z-order, then we can safely move the batch to
948 //higher z-order. Increment fbZ as it is moving up.
949 if( firstZReverseIndex < 0) {
950 firstZReverseIndex = i;
951 }
952 batchCount++;
953 batchEnd = i;
954 fbZ += updatingLayersAbove;
955 i++;
956 updatingLayersAbove = 0;
957 continue;
958 } else {
959 //both failed.start the loop again from here.
960 if(firstZReverseIndex >= 0) {
961 i = firstZReverseIndex;
962 }
963 break;
964 }
965 }
966 }
967 }
968 if(batchCount > maxBatchCount) {
969 maxBatchCount = batchCount;
970 maxBatchStart = batchStart;
971 maxBatchEnd = batchEnd;
972 fbZOrder = fbZ;
973 }
974 }
975 return fbZOrder;
976}
977
978bool MDPComp::markLayersForCaching(hwc_context_t* ctx,
979 hwc_display_contents_1_t* list) {
980 /* Idea is to keep as many non-updating(cached) layers in FB and
981 * send rest of them through MDP. This is done in 2 steps.
982 * 1. Find the maximum contiguous batch of non-updating layers.
983 * 2. See if we can improve this batch size for caching by adding
984 * opaque layers around the batch, if they don't have
985 * any overlapping with the updating layers in between.
986 * NEVER mark an updating layer for caching.
987 * But cached ones can be marked for MDP */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800988
989 int maxBatchStart = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700990 int maxBatchEnd = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800991 int maxBatchCount = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530992 int fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800993
Saurabh Shahce188452014-02-05 10:17:43 -0800994 /* Nothing is cached. No batching needed */
995 if(mCurrentFrame.fbCount == 0) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700996 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -0700997 }
Saurabh Shahce188452014-02-05 10:17:43 -0800998
999 /* No MDP comp layers, try to use other comp modes */
1000 if(mCurrentFrame.mdpCount == 0) {
1001 return false;
Saurabh Shahaa236822013-04-24 18:07:26 -07001002 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001003
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301004 fbZ = getBatch(list, maxBatchStart, maxBatchEnd, maxBatchCount);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001005
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301006 /* reset rest of the layers lying inside ROI for MDP comp */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001007 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001008 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001009 if((i < maxBatchStart || i > maxBatchEnd) &&
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301010 mCurrentFrame.isFBComposed[i]){
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001011 if(!mCurrentFrame.drop[i]){
1012 //If an unsupported layer is being attempted to
1013 //be pulled out we should fail
1014 if(not isSupportedForMDPComp(ctx, layer)) {
1015 return false;
1016 }
1017 mCurrentFrame.isFBComposed[i] = false;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001018 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001019 }
1020 }
1021
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301022 // update the frame data
1023 mCurrentFrame.fbZ = fbZ;
1024 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001025 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001026 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001027
1028 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301029 mCurrentFrame.fbCount);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001030
1031 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001032}
Saurabh Shah85234ec2013-04-12 17:09:00 -07001033
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001034void MDPComp::updateLayerCache(hwc_context_t* ctx,
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001035 hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001036 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001037 int fbCount = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001038
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001039 for(int i = 0; i < numAppLayers; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001040 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001041 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001042 if(!mCurrentFrame.drop[i])
1043 fbCount++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001044 mCurrentFrame.isFBComposed[i] = true;
1045 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -07001046 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001047 }
1048 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001049
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001050 mCurrentFrame.fbCount = fbCount;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001051 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount
1052 - mCurrentFrame.dropCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001053
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001054 ALOGD_IF(isDebug(),"%s: MDP count: %d FB count %d drop count: %d"
1055 ,__FUNCTION__, mCurrentFrame.mdpCount, mCurrentFrame.fbCount,
1056 mCurrentFrame.dropCount);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001057}
1058
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001059void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list,
1060 bool secureOnly) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001061 int nYuvCount = ctx->listStats[mDpy].yuvCount;
1062 for(int index = 0;index < nYuvCount; index++){
1063 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
1064 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
1065
1066 if(!isYUVDoable(ctx, layer)) {
1067 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
1068 mCurrentFrame.isFBComposed[nYuvIndex] = true;
1069 mCurrentFrame.fbCount++;
1070 }
1071 } else {
1072 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001073 private_handle_t *hnd = (private_handle_t *)layer->handle;
1074 if(!secureOnly || isSecureBuffer(hnd)) {
1075 mCurrentFrame.isFBComposed[nYuvIndex] = false;
1076 mCurrentFrame.fbCount--;
1077 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001078 }
1079 }
1080 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001081
1082 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001083 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
1084 ALOGD_IF(isDebug(),"%s: fb count: %d",__FUNCTION__,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001085 mCurrentFrame.fbCount);
1086}
1087
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001088bool MDPComp::postHeuristicsHandling(hwc_context_t *ctx,
1089 hwc_display_contents_1_t* list) {
1090
1091 //Capability checks
1092 if(!resourceCheck(ctx, list)) {
1093 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
1094 return false;
1095 }
1096
1097 //Limitations checks
1098 if(!hwLimitationsCheck(ctx, list)) {
1099 ALOGD_IF(isDebug(), "%s: HW limitations",__FUNCTION__);
1100 return false;
1101 }
1102
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001103 //Configure framebuffer first if applicable
1104 if(mCurrentFrame.fbZ >= 0) {
1105 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, mCurrentFrame.fbZ)) {
1106 ALOGD_IF(isDebug(), "%s configure framebuffer failed",
1107 __FUNCTION__);
1108 return false;
1109 }
1110 }
1111
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001112 mCurrentFrame.map();
1113
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001114 if(!allocLayerPipes(ctx, list)) {
1115 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -07001116 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001117 }
1118
1119 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001120 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001121 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001122 int mdpIndex = mCurrentFrame.layerToMDP[index];
1123 hwc_layer_1_t* layer = &list->hwLayers[index];
1124
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301125 //Leave fbZ for framebuffer. CACHE/GLES layers go here.
1126 if(mdpNextZOrder == mCurrentFrame.fbZ) {
1127 mdpNextZOrder++;
1128 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001129 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1130 cur_pipe->zOrder = mdpNextZOrder++;
1131
radhakrishnac9a67412013-09-25 17:40:42 +05301132 private_handle_t *hnd = (private_handle_t *)layer->handle;
1133 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1134 if(configure4k2kYuv(ctx, layer,
1135 mCurrentFrame.mdpToLayer[mdpIndex])
1136 != 0 ){
1137 ALOGD_IF(isDebug(), "%s: Failed to configure split pipes \
1138 for layer %d",__FUNCTION__, index);
1139 return false;
1140 }
1141 else{
1142 mdpNextZOrder++;
1143 }
1144 continue;
1145 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001146 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
1147 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
radhakrishnac9a67412013-09-25 17:40:42 +05301148 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -07001149 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001150 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001151 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001152 }
1153
Saurabh Shah450ac972013-12-16 18:18:39 -08001154 if(!ctx->mOverlay->validateAndSet(mDpy, ctx->dpyAttr[mDpy].fd)) {
1155 ALOGD_IF(isDebug(), "%s: Failed to validate and set overlay for dpy %d"
1156 ,__FUNCTION__, mDpy);
1157 return false;
1158 }
1159
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001160 setRedraw(ctx, list);
Saurabh Shahaa236822013-04-24 18:07:26 -07001161 return true;
1162}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001163
Saurabh Shah173f4242013-11-20 09:50:12 -08001164bool MDPComp::resourceCheck(hwc_context_t *ctx,
1165 hwc_display_contents_1_t *list) {
1166 const bool fbUsed = mCurrentFrame.fbCount;
1167 if(mCurrentFrame.mdpCount > sMaxPipesPerMixer - fbUsed) {
1168 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
1169 return false;
1170 }
Saurabh Shah173f4242013-11-20 09:50:12 -08001171 return true;
1172}
1173
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301174bool MDPComp::hwLimitationsCheck(hwc_context_t* ctx,
1175 hwc_display_contents_1_t* list) {
1176
1177 //A-family hw limitation:
1178 //If a layer need alpha scaling, MDP can not support.
1179 if(ctx->mMDP.version < qdutils::MDSS_V5) {
1180 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1181 if(!mCurrentFrame.isFBComposed[i] &&
1182 isAlphaScaled( &list->hwLayers[i])) {
1183 ALOGD_IF(isDebug(), "%s:frame needs alphaScaling",__FUNCTION__);
1184 return false;
1185 }
1186 }
1187 }
1188
1189 // On 8x26 & 8974 hw, we have a limitation of downscaling+blending.
1190 //If multiple layers requires downscaling and also they are overlapping
1191 //fall back to GPU since MDSS can not handle it.
1192 if(qdutils::MDPVersion::getInstance().is8x74v2() ||
1193 qdutils::MDPVersion::getInstance().is8x26()) {
1194 for(int i = 0; i < mCurrentFrame.layerCount-1; ++i) {
1195 hwc_layer_1_t* botLayer = &list->hwLayers[i];
1196 if(!mCurrentFrame.isFBComposed[i] &&
1197 isDownscaleRequired(botLayer)) {
1198 //if layer-i is marked for MDP and needs downscaling
1199 //check if any MDP layer on top of i & overlaps with layer-i
1200 for(int j = i+1; j < mCurrentFrame.layerCount; ++j) {
1201 hwc_layer_1_t* topLayer = &list->hwLayers[j];
1202 if(!mCurrentFrame.isFBComposed[j] &&
1203 isDownscaleRequired(topLayer)) {
1204 hwc_rect_t r = getIntersection(botLayer->displayFrame,
1205 topLayer->displayFrame);
1206 if(isValidRect(r))
1207 return false;
1208 }
1209 }
1210 }
1211 }
1212 }
1213 return true;
1214}
1215
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001216int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001217 int ret = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -07001218 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahf5f2b132013-11-25 12:08:35 -08001219 MDPVersion& mdpVersion = qdutils::MDPVersion::getInstance();
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -07001220
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001221 //number of app layers exceeds MAX_NUM_APP_LAYERS fall back to GPU
1222 //do not cache the information for next draw cycle.
1223 if(numLayers > MAX_NUM_APP_LAYERS) {
1224 ALOGI("%s: Number of App layers exceeded the limit ",
1225 __FUNCTION__);
1226 mCachedFrame.reset();
1227 return -1;
1228 }
1229
Saurabh Shahb39f8152013-08-22 10:21:44 -07001230 //reset old data
1231 mCurrentFrame.reset(numLayers);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001232 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1233 mCurrentFrame.dropCount = 0;
Prabhanjan Kandula088bd892013-07-02 23:47:13 +05301234
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -07001235 // Detect the start of animation and fall back to GPU only once to cache
1236 // all the layers in FB and display FB content untill animation completes.
1237 if(ctx->listStats[mDpy].isDisplayAnimating) {
1238 mCurrentFrame.needsRedraw = false;
1239 if(ctx->mAnimationState[mDpy] == ANIMATION_STOPPED) {
1240 mCurrentFrame.needsRedraw = true;
1241 ctx->mAnimationState[mDpy] = ANIMATION_STARTED;
1242 }
1243 setMDPCompLayerFlags(ctx, list);
1244 mCachedFrame.updateCounts(mCurrentFrame);
1245 ret = -1;
1246 return ret;
1247 } else {
1248 ctx->mAnimationState[mDpy] = ANIMATION_STOPPED;
1249 }
1250
Saurabh Shahb39f8152013-08-22 10:21:44 -07001251 //Hard conditions, if not met, cannot do MDP comp
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001252 if(isFrameDoable(ctx)) {
1253 generateROI(ctx, list);
Saurabh Shahb39f8152013-08-22 10:21:44 -07001254
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001255 if(tryFullFrame(ctx, list) || tryVideoOnly(ctx, list)) {
1256 setMDPCompLayerFlags(ctx, list);
1257 } else {
1258 reset(ctx);
1259 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1260 mCurrentFrame.dropCount = 0;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001261 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001262 }
1263 } else {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001264 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
1265 __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001266 ret = -1;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001267 }
Saurabh Shahb39f8152013-08-22 10:21:44 -07001268
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001269 if(isDebug()) {
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001270 ALOGD("GEOMETRY change: %d",
1271 (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001272 android::String8 sDump("");
1273 dump(sDump);
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001274 ALOGD("%s",sDump.string());
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001275 }
1276
Saurabh Shahdf4741d2013-12-12 16:40:28 -08001277 mCachedFrame.cacheAll(list);
1278 mCachedFrame.updateCounts(mCurrentFrame);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001279 return ret;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001280}
1281
radhakrishnac9a67412013-09-25 17:40:42 +05301282bool MDPComp::allocSplitVGPipesfor4k2k(hwc_context_t *ctx,
1283 hwc_display_contents_1_t* list, int index) {
1284
1285 bool bRet = true;
1286 hwc_layer_1_t* layer = &list->hwLayers[index];
1287 private_handle_t *hnd = (private_handle_t *)layer->handle;
1288 int mdpIndex = mCurrentFrame.layerToMDP[index];
1289 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
1290 info.pipeInfo = new MdpYUVPipeInfo;
1291 info.rot = NULL;
1292 MdpYUVPipeInfo& pipe_info = *(MdpYUVPipeInfo*)info.pipeInfo;
1293 ePipeType type = MDPCOMP_OV_VG;
1294
1295 pipe_info.lIndex = ovutils::OV_INVALID;
1296 pipe_info.rIndex = ovutils::OV_INVALID;
1297
1298 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
1299 if(pipe_info.lIndex == ovutils::OV_INVALID){
1300 bRet = false;
1301 ALOGD_IF(isDebug(),"%s: allocating first VG pipe failed",
1302 __FUNCTION__);
1303 }
1304 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
1305 if(pipe_info.rIndex == ovutils::OV_INVALID){
1306 bRet = false;
1307 ALOGD_IF(isDebug(),"%s: allocating second VG pipe failed",
1308 __FUNCTION__);
1309 }
1310 return bRet;
1311}
Saurabh Shah88e4d272013-09-03 13:31:29 -07001312//=============MDPCompNonSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001313
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001314void MDPCompNonSplit::adjustForSourceSplit(hwc_context_t *ctx,
radhakrishnac9a67412013-09-25 17:40:42 +05301315 hwc_display_contents_1_t* list){
1316 //As we split 4kx2k yuv layer and program to 2 VG pipes
1317 //(if available) increase mdpcount accordingly
1318 mCurrentFrame.mdpCount += ctx->listStats[mDpy].yuv4k2kCount;
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001319
1320 //If 4k2k Yuv layer split is possible, and if
1321 //fbz is above 4k2k layer, increment fb zorder by 1
1322 //as we split 4k2k layer and increment zorder for right half
1323 //of the layer
1324 if(mCurrentFrame.fbZ >= 0) {
1325 int n4k2kYuvCount = ctx->listStats[mDpy].yuv4k2kCount;
1326 for(int index = 0; index < n4k2kYuvCount; index++){
1327 int n4k2kYuvIndex =
1328 ctx->listStats[mDpy].yuv4k2kIndices[index];
1329 if(mCurrentFrame.fbZ > n4k2kYuvIndex){
1330 mCurrentFrame.fbZ += 1;
1331 }
1332 }
1333 }
radhakrishnac9a67412013-09-25 17:40:42 +05301334}
1335
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001336/*
1337 * Configures pipe(s) for MDP composition
1338 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001339int MDPCompNonSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001340 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001341 MdpPipeInfoNonSplit& mdp_info =
1342 *(static_cast<MdpPipeInfoNonSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001343 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
1344 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1345 eIsFg isFg = IS_FG_OFF;
1346 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001347
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001348 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
1349 __FUNCTION__, layer, zOrder, dest);
1350
Saurabh Shah88e4d272013-09-03 13:31:29 -07001351 return configureNonSplit(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001352 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001353}
1354
Saurabh Shah88e4d272013-09-03 13:31:29 -07001355bool MDPCompNonSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001356 hwc_display_contents_1_t* list) {
1357 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001358
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001359 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001360
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001361 hwc_layer_1_t* layer = &list->hwLayers[index];
1362 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301363 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1364 if(allocSplitVGPipesfor4k2k(ctx, list, index)){
1365 continue;
1366 }
1367 }
1368
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001369 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001370 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001371 info.pipeInfo = new MdpPipeInfoNonSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08001372 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001373 MdpPipeInfoNonSplit& pipe_info = *(MdpPipeInfoNonSplit*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001374 ePipeType type = MDPCOMP_OV_ANY;
1375
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001376 if(isYuvBuffer(hnd)) {
1377 type = MDPCOMP_OV_VG;
Prabhanjan Kandula5b8913e2014-01-22 23:01:45 +05301378 } else if(qdutils::MDPVersion::getInstance().is8x26() &&
1379 (ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres > 1024)) {
1380 if(qhwc::needsScaling(layer))
1381 type = MDPCOMP_OV_RGB;
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301382 } else if(!qhwc::needsScaling(layer)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001383 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
1384 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001385 type = MDPCOMP_OV_DMA;
1386 }
1387
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001388 pipe_info.index = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001389 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001390 ALOGD_IF(isDebug(), "%s: Unable to get pipe type = %d",
1391 __FUNCTION__, (int) type);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001392 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001393 }
1394 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001395 return true;
1396}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001397
radhakrishnac9a67412013-09-25 17:40:42 +05301398int MDPCompNonSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1399 PipeLayerPair& PipeLayerPair) {
1400 MdpYUVPipeInfo& mdp_info =
1401 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1402 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1403 eIsFg isFg = IS_FG_OFF;
1404 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1405 eDest lDest = mdp_info.lIndex;
1406 eDest rDest = mdp_info.rIndex;
1407
1408 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1409 lDest, rDest, &PipeLayerPair.rot);
1410}
1411
Saurabh Shah88e4d272013-09-03 13:31:29 -07001412bool MDPCompNonSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001413
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001414 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001415 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1416 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -08001417 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001418
1419 if(!ctx || !list) {
1420 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001421 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001422 }
1423
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301424 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1425 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1426 return true;
1427 }
1428
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001429 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001430 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Saurabh Shahc2f04cf2014-01-23 18:39:01 -08001431 idleInvalidator->handleUpdateEvent();
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001432
1433 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001434 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001435
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001436 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1437 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001438 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001439 if(mCurrentFrame.isFBComposed[i]) continue;
1440
Naseer Ahmed5b6708a2012-08-02 13:46:08 -07001441 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001442 private_handle_t *hnd = (private_handle_t *)layer->handle;
1443 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001444 if (!(layer->flags & HWC_COLOR_FILL)) {
1445 ALOGE("%s handle null", __FUNCTION__);
1446 return false;
1447 }
1448 // No PLAY for Color layer
1449 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1450 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001451 }
1452
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001453 int mdpIndex = mCurrentFrame.layerToMDP[i];
1454
radhakrishnac9a67412013-09-25 17:40:42 +05301455 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1456 {
1457 MdpYUVPipeInfo& pipe_info =
1458 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1459 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1460 ovutils::eDest indexL = pipe_info.lIndex;
1461 ovutils::eDest indexR = pipe_info.rIndex;
1462 int fd = hnd->fd;
1463 uint32_t offset = hnd->offset;
1464 if(rot) {
1465 rot->queueBuffer(fd, offset);
1466 fd = rot->getDstMemId();
1467 offset = rot->getDstOffset();
1468 }
1469 if(indexL != ovutils::OV_INVALID) {
1470 ovutils::eDest destL = (ovutils::eDest)indexL;
1471 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1472 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1473 if (!ov.queueBuffer(fd, offset, destL)) {
1474 ALOGE("%s: queueBuffer failed for display:%d",
1475 __FUNCTION__, mDpy);
1476 return false;
1477 }
1478 }
1479
1480 if(indexR != ovutils::OV_INVALID) {
1481 ovutils::eDest destR = (ovutils::eDest)indexR;
1482 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1483 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1484 if (!ov.queueBuffer(fd, offset, destR)) {
1485 ALOGE("%s: queueBuffer failed for display:%d",
1486 __FUNCTION__, mDpy);
1487 return false;
1488 }
1489 }
1490 }
1491 else{
1492 MdpPipeInfoNonSplit& pipe_info =
Saurabh Shah88e4d272013-09-03 13:31:29 -07001493 *(MdpPipeInfoNonSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
radhakrishnac9a67412013-09-25 17:40:42 +05301494 ovutils::eDest dest = pipe_info.index;
1495 if(dest == ovutils::OV_INVALID) {
1496 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001497 return false;
radhakrishnac9a67412013-09-25 17:40:42 +05301498 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001499
radhakrishnac9a67412013-09-25 17:40:42 +05301500 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1501 continue;
1502 }
1503
1504 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1505 using pipe: %d", __FUNCTION__, layer,
1506 hnd, dest );
1507
1508 int fd = hnd->fd;
1509 uint32_t offset = hnd->offset;
1510
1511 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1512 if(rot) {
1513 if(!rot->queueBuffer(fd, offset))
1514 return false;
1515 fd = rot->getDstMemId();
1516 offset = rot->getDstOffset();
1517 }
1518
1519 if (!ov.queueBuffer(fd, offset, dest)) {
1520 ALOGE("%s: queueBuffer failed for display:%d ",
1521 __FUNCTION__, mDpy);
1522 return false;
1523 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001524 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001525
1526 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001527 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001528 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001529}
1530
Saurabh Shah88e4d272013-09-03 13:31:29 -07001531//=============MDPCompSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001532
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001533void MDPCompSplit::adjustForSourceSplit(hwc_context_t *ctx,
radhakrishnac9a67412013-09-25 17:40:42 +05301534 hwc_display_contents_1_t* list){
1535 //if 4kx2k yuv layer is totally present in either in left half
1536 //or right half then try splitting the yuv layer to avoid decimation
1537 int n4k2kYuvCount = ctx->listStats[mDpy].yuv4k2kCount;
1538 const int lSplit = getLeftSplit(ctx, mDpy);
1539 for(int index = 0; index < n4k2kYuvCount; index++){
1540 int n4k2kYuvIndex = ctx->listStats[mDpy].yuv4k2kIndices[index];
1541 hwc_layer_1_t* layer = &list->hwLayers[n4k2kYuvIndex];
1542 hwc_rect_t dst = layer->displayFrame;
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001543 if((dst.left > lSplit) || (dst.right < lSplit)) {
radhakrishnac9a67412013-09-25 17:40:42 +05301544 mCurrentFrame.mdpCount += 1;
1545 }
Saurabh Shah3d4b8042013-12-10 15:19:17 -08001546 if(mCurrentFrame.fbZ > n4k2kYuvIndex){
1547 mCurrentFrame.fbZ += 1;
1548 }
radhakrishnac9a67412013-09-25 17:40:42 +05301549 }
1550}
1551
Saurabh Shah88e4d272013-09-03 13:31:29 -07001552bool MDPCompSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
1553 MdpPipeInfoSplit& pipe_info,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001554 ePipeType type) {
1555 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001556 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001557
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001558 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001559 pipe_info.lIndex = ovutils::OV_INVALID;
1560 pipe_info.rIndex = ovutils::OV_INVALID;
1561
1562 if (dst.left < lSplit) {
1563 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_LEFT);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001564 if(pipe_info.lIndex == ovutils::OV_INVALID)
1565 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001566 }
1567
1568 if(dst.right > lSplit) {
1569 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_RIGHT);
1570 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001571 return false;
1572 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001573
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001574 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001575}
1576
Saurabh Shah88e4d272013-09-03 13:31:29 -07001577bool MDPCompSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001578 hwc_display_contents_1_t* list) {
1579 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001580
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001581 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001582
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001583 hwc_layer_1_t* layer = &list->hwLayers[index];
1584 private_handle_t *hnd = (private_handle_t *)layer->handle;
radhakrishnac9a67412013-09-25 17:40:42 +05301585 hwc_rect_t dst = layer->displayFrame;
1586 const int lSplit = getLeftSplit(ctx, mDpy);
1587 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit){
1588 if((dst.left > lSplit)||(dst.right < lSplit)){
1589 if(allocSplitVGPipesfor4k2k(ctx, list, index)){
1590 continue;
1591 }
1592 }
1593 }
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001594 int mdpIndex = mCurrentFrame.layerToMDP[index];
1595 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001596 info.pipeInfo = new MdpPipeInfoSplit;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001597 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001598 MdpPipeInfoSplit& pipe_info = *(MdpPipeInfoSplit*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001599 ePipeType type = MDPCOMP_OV_ANY;
1600
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001601 if(isYuvBuffer(hnd)) {
1602 type = MDPCOMP_OV_VG;
Sushil Chauhan15a2ea62013-09-04 18:28:36 -07001603 } else if(!qhwc::needsScalingWithSplit(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001604 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001605 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001606 type = MDPCOMP_OV_DMA;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001607 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001608
1609 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001610 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type = %d",
1611 __FUNCTION__, (int) type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001612 return false;
1613 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001614 }
1615 return true;
1616}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001617
radhakrishnac9a67412013-09-25 17:40:42 +05301618int MDPCompSplit::configure4k2kYuv(hwc_context_t *ctx, hwc_layer_1_t *layer,
1619 PipeLayerPair& PipeLayerPair) {
1620 const int lSplit = getLeftSplit(ctx, mDpy);
1621 hwc_rect_t dst = layer->displayFrame;
1622 if((dst.left > lSplit)||(dst.right < lSplit)){
1623 MdpYUVPipeInfo& mdp_info =
1624 *(static_cast<MdpYUVPipeInfo*>(PipeLayerPair.pipeInfo));
1625 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1626 eIsFg isFg = IS_FG_OFF;
1627 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1628 eDest lDest = mdp_info.lIndex;
1629 eDest rDest = mdp_info.rIndex;
1630
1631 return configureSourceSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg,
1632 lDest, rDest, &PipeLayerPair.rot);
1633 }
1634 else{
1635 return configure(ctx, layer, PipeLayerPair);
1636 }
1637}
1638
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001639/*
1640 * Configures pipe(s) for MDP composition
1641 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001642int MDPCompSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001643 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001644 MdpPipeInfoSplit& mdp_info =
1645 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001646 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1647 eIsFg isFg = IS_FG_OFF;
1648 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1649 eDest lDest = mdp_info.lIndex;
1650 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001651
1652 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1653 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1654
Saurabh Shah88e4d272013-09-03 13:31:29 -07001655 return configureSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001656 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001657}
1658
Saurabh Shah88e4d272013-09-03 13:31:29 -07001659bool MDPCompSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001660
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001661 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001662 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1663 return true;
1664 }
1665
1666 if(!ctx || !list) {
1667 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001668 return false;
1669 }
1670
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301671 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1672 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1673 return true;
1674 }
1675
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001676 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001677 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Saurabh Shahc2f04cf2014-01-23 18:39:01 -08001678 idleInvalidator->handleUpdateEvent();
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001679
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001680 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001681 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001682
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001683 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1684 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001685 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001686 if(mCurrentFrame.isFBComposed[i]) continue;
1687
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001688 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001689 private_handle_t *hnd = (private_handle_t *)layer->handle;
1690 if(!hnd) {
1691 ALOGE("%s handle null", __FUNCTION__);
1692 return false;
1693 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001694
1695 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1696 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001697 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001698
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001699 int mdpIndex = mCurrentFrame.layerToMDP[i];
1700
radhakrishnac9a67412013-09-25 17:40:42 +05301701 if(is4kx2kYuvBuffer(hnd) && sEnable4k2kYUVSplit)
1702 {
1703 MdpYUVPipeInfo& pipe_info =
1704 *(MdpYUVPipeInfo*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1705 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
1706 ovutils::eDest indexL = pipe_info.lIndex;
1707 ovutils::eDest indexR = pipe_info.rIndex;
1708 int fd = hnd->fd;
1709 uint32_t offset = hnd->offset;
1710 if(rot) {
1711 rot->queueBuffer(fd, offset);
1712 fd = rot->getDstMemId();
1713 offset = rot->getDstOffset();
1714 }
1715 if(indexL != ovutils::OV_INVALID) {
1716 ovutils::eDest destL = (ovutils::eDest)indexL;
1717 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1718 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1719 if (!ov.queueBuffer(fd, offset, destL)) {
1720 ALOGE("%s: queueBuffer failed for display:%d",
1721 __FUNCTION__, mDpy);
1722 return false;
1723 }
1724 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001725
radhakrishnac9a67412013-09-25 17:40:42 +05301726 if(indexR != ovutils::OV_INVALID) {
1727 ovutils::eDest destR = (ovutils::eDest)indexR;
1728 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1729 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1730 if (!ov.queueBuffer(fd, offset, destR)) {
1731 ALOGE("%s: queueBuffer failed for display:%d",
1732 __FUNCTION__, mDpy);
1733 return false;
1734 }
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001735 }
1736 }
radhakrishnac9a67412013-09-25 17:40:42 +05301737 else{
1738 MdpPipeInfoSplit& pipe_info =
1739 *(MdpPipeInfoSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1740 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001741
radhakrishnac9a67412013-09-25 17:40:42 +05301742 ovutils::eDest indexL = pipe_info.lIndex;
1743 ovutils::eDest indexR = pipe_info.rIndex;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001744
radhakrishnac9a67412013-09-25 17:40:42 +05301745 int fd = hnd->fd;
1746 int offset = hnd->offset;
1747
1748 if(ctx->mAD->isModeOn()) {
1749 if(ctx->mAD->draw(ctx, fd, offset)) {
1750 fd = ctx->mAD->getDstFd(ctx);
1751 offset = ctx->mAD->getDstOffset(ctx);
1752 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001753 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001754
radhakrishnac9a67412013-09-25 17:40:42 +05301755 if(rot) {
1756 rot->queueBuffer(fd, offset);
1757 fd = rot->getDstMemId();
1758 offset = rot->getDstOffset();
1759 }
1760
1761 //************* play left mixer **********
1762 if(indexL != ovutils::OV_INVALID) {
1763 ovutils::eDest destL = (ovutils::eDest)indexL;
1764 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1765 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
1766 if (!ov.queueBuffer(fd, offset, destL)) {
1767 ALOGE("%s: queueBuffer failed for left mixer",
1768 __FUNCTION__);
1769 return false;
1770 }
1771 }
1772
1773 //************* play right mixer **********
1774 if(indexR != ovutils::OV_INVALID) {
1775 ovutils::eDest destR = (ovutils::eDest)indexR;
1776 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
1777 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
1778 if (!ov.queueBuffer(fd, offset, destR)) {
1779 ALOGE("%s: queueBuffer failed for right mixer",
1780 __FUNCTION__);
1781 return false;
1782 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001783 }
1784 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001785
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001786 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1787 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001788
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001789 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001790}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001791}; //namespace
1792