blob: 6e442349cd0e1cba027470e2256a5fb0c0623031 [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 Sankaran85977e32013-02-25 17:06:08 -080044int MDPComp::sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
Saurabh Shah8c5c8522013-08-29 17:32:49 -070045float MDPComp::sMaxBw = 2.3f;
46uint32_t MDPComp::sCompBytesClaimed = 0;
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\"");
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080065 dumpsys_log(buf,"PREV_FRAME: layerCount:%2d mdpCount:%2d \
66 cacheCount:%2d \n", mCachedFrame.layerCount,
67 mCachedFrame.mdpCount, mCachedFrame.cacheCount);
68 dumpsys_log(buf,"CURR_FRAME: layerCount:%2d mdpCount:%2d \
69 fbCount:%2d \n", mCurrentFrame.layerCount,
70 mCurrentFrame.mdpCount, mCurrentFrame.fbCount);
71 dumpsys_log(buf,"needsFBRedraw:%3s pipesUsed:%2d MaxPipesPerMixer: %d \n",
72 (mCurrentFrame.needsRedraw? "YES" : "NO"),
73 mCurrentFrame.mdpCount, sMaxPipesPerMixer);
74 dumpsys_log(buf," --------------------------------------------- \n");
75 dumpsys_log(buf," listIdx | cached? | mdpIndex | comptype | Z \n");
76 dumpsys_log(buf," --------------------------------------------- \n");
77 for(int index = 0; index < mCurrentFrame.layerCount; index++ )
78 dumpsys_log(buf," %7d | %7s | %8d | %9s | %2d \n",
79 index,
80 (mCurrentFrame.isFBComposed[index] ? "YES" : "NO"),
81 mCurrentFrame.layerToMDP[index],
82 (mCurrentFrame.isFBComposed[index] ?
83 (mCurrentFrame.needsRedraw ? "GLES" : "CACHE") : "MDP"),
84 (mCurrentFrame.isFBComposed[index] ? mCurrentFrame.fbZ :
85 mCurrentFrame.mdpToLayer[mCurrentFrame.layerToMDP[index]].pipeInfo->zOrder));
86 dumpsys_log(buf,"\n");
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080087}
88
89bool MDPComp::init(hwc_context_t *ctx) {
90
91 if(!ctx) {
92 ALOGE("%s: Invalid hwc context!!",__FUNCTION__);
93 return false;
94 }
95
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080096 char property[PROPERTY_VALUE_MAX];
97
98 sEnabled = false;
99 if((property_get("persist.hwc.mdpcomp.enable", property, NULL) > 0) &&
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800100 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
101 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800102 sEnabled = true;
103 }
104
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700105 sEnableMixedMode = true;
106 if((property_get("debug.mdpcomp.mixedmode.disable", property, NULL) > 0) &&
107 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
108 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
109 sEnableMixedMode = false;
110 }
111
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800112 sDebugLogs = false;
113 if(property_get("debug.mdpcomp.logs", property, NULL) > 0) {
114 if(atoi(property) != 0)
115 sDebugLogs = true;
116 }
117
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800118 sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
Saurabh Shah85234ec2013-04-12 17:09:00 -0700119 if(property_get("debug.mdpcomp.maxpermixer", property, "-1") > 0) {
120 int val = atoi(property);
121 if(val >= 0)
122 sMaxPipesPerMixer = min(val, MAX_PIPES_PER_MIXER);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800123 }
124
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700125 if(property_get("debug.mdpcomp.bw", property, "0") > 0) {
126 float val = atof(property);
127 if(val > 0.0f) {
128 sMaxBw = val;
129 }
130 }
131
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400132 if(ctx->mMDP.panel != MIPI_CMD_PANEL) {
133 // Idle invalidation is not necessary on command mode panels
134 long idle_timeout = DEFAULT_IDLE_TIME;
135 if(property_get("debug.mdpcomp.idletime", property, NULL) > 0) {
136 if(atoi(property) != 0)
137 idle_timeout = atoi(property);
138 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800139
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400140 //create Idle Invalidator only when not disabled through property
141 if(idle_timeout != -1)
142 idleInvalidator = IdleInvalidator::getInstance();
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800143
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400144 if(idleInvalidator == NULL) {
145 ALOGE("%s: failed to instantiate idleInvalidator object",
146 __FUNCTION__);
147 } else {
148 idleInvalidator->init(timeout_handler, ctx, idle_timeout);
149 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800150 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700151 return true;
152}
153
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700154void MDPComp::reset(const int& numLayers, hwc_display_contents_1_t* list) {
155 mCurrentFrame.reset(numLayers);
156 mCachedFrame.cacheAll(list);
157 mCachedFrame.updateCounts(mCurrentFrame);
158}
159
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700160void MDPComp::timeout_handler(void *udata) {
161 struct hwc_context_t* ctx = (struct hwc_context_t*)(udata);
162
163 if(!ctx) {
164 ALOGE("%s: received empty data in timer callback", __FUNCTION__);
165 return;
166 }
167
Jesse Hall3be78d92012-08-21 15:12:23 -0700168 if(!ctx->proc) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700169 ALOGE("%s: HWC proc not registered", __FUNCTION__);
170 return;
171 }
172 sIdleFallBack = true;
173 /* Trigger SF to redraw the current frame */
Jesse Hall3be78d92012-08-21 15:12:23 -0700174 ctx->proc->invalidate(ctx->proc);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700175}
176
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800177void MDPComp::setMDPCompLayerFlags(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800178 hwc_display_contents_1_t* list) {
179 LayerProp *layerProp = ctx->layerProp[mDpy];
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800180
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800181 for(int index = 0; index < ctx->listStats[mDpy].numAppLayers; index++) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800182 hwc_layer_1_t* layer = &(list->hwLayers[index]);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800183 if(!mCurrentFrame.isFBComposed[index]) {
184 layerProp[index].mFlags |= HWC_MDPCOMP;
185 layer->compositionType = HWC_OVERLAY;
186 layer->hints |= HWC_HINT_CLEAR_FB;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800187 } else {
188 if(!mCurrentFrame.needsRedraw)
189 layer->compositionType = HWC_OVERLAY;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800190 }
191 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700192}
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500193
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800194MDPComp::FrameInfo::FrameInfo() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700195 reset(0);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800196}
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800197
Saurabh Shahaa236822013-04-24 18:07:26 -0700198void MDPComp::FrameInfo::reset(const int& numLayers) {
199 for(int i = 0 ; i < MAX_PIPES_PER_MIXER && numLayers; i++ ) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800200 if(mdpToLayer[i].pipeInfo) {
201 delete mdpToLayer[i].pipeInfo;
202 mdpToLayer[i].pipeInfo = NULL;
203 //We dont own the rotator
204 mdpToLayer[i].rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800205 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800206 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800207
208 memset(&mdpToLayer, 0, sizeof(mdpToLayer));
209 memset(&layerToMDP, -1, sizeof(layerToMDP));
Saurabh Shahaa236822013-04-24 18:07:26 -0700210 memset(&isFBComposed, 1, sizeof(isFBComposed));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800211
Saurabh Shahaa236822013-04-24 18:07:26 -0700212 layerCount = numLayers;
213 fbCount = numLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800214 mdpCount = 0;
Saurabh Shah2f3895f2013-05-02 10:13:31 -0700215 needsRedraw = true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800216 fbZ = 0;
217}
218
Saurabh Shahaa236822013-04-24 18:07:26 -0700219void MDPComp::FrameInfo::map() {
220 // populate layer and MDP maps
221 int mdpIdx = 0;
222 for(int idx = 0; idx < layerCount; idx++) {
223 if(!isFBComposed[idx]) {
224 mdpToLayer[mdpIdx].listIndex = idx;
225 layerToMDP[idx] = mdpIdx++;
226 }
227 }
228}
229
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800230MDPComp::LayerCache::LayerCache() {
231 reset();
232}
233
234void MDPComp::LayerCache::reset() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700235 memset(&hnd, 0, sizeof(hnd));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800236 mdpCount = 0;
237 cacheCount = 0;
238 layerCount = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -0700239 fbZ = -1;
240}
241
242void MDPComp::LayerCache::cacheAll(hwc_display_contents_1_t* list) {
243 const int numAppLayers = list->numHwLayers - 1;
244 for(int i = 0; i < numAppLayers; i++) {
245 hnd[i] = list->hwLayers[i].handle;
246 }
247}
248
249void MDPComp::LayerCache::updateCounts(const FrameInfo& curFrame) {
250 mdpCount = curFrame.mdpCount;
251 cacheCount = curFrame.fbCount;
252 layerCount = curFrame.layerCount;
253 fbZ = curFrame.fbZ;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800254}
255
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530256bool MDPComp::isValidDimension(hwc_context_t *ctx, hwc_layer_1_t *layer) {
Saurabh Shah4fdde762013-04-30 18:47:33 -0700257 const int dpy = HWC_DISPLAY_PRIMARY;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800258 private_handle_t *hnd = (private_handle_t *)layer->handle;
259
260 if(!hnd) {
261 ALOGE("%s: layer handle is NULL", __FUNCTION__);
262 return false;
263 }
264
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800265 int hw_w = ctx->dpyAttr[mDpy].xres;
266 int hw_h = ctx->dpyAttr[mDpy].yres;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800267
Saurabh Shah4fdde762013-04-30 18:47:33 -0700268 hwc_rect_t crop = layer->sourceCrop;
269 hwc_rect_t dst = layer->displayFrame;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800270
271 if(dst.left < 0 || dst.top < 0 || dst.right > hw_w || dst.bottom > hw_h) {
Saurabh Shah4fdde762013-04-30 18:47:33 -0700272 hwc_rect_t scissor = {0, 0, hw_w, hw_h };
273 qhwc::calculate_crop_rects(crop, dst, scissor, layer->transform);
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800274 }
275
Saurabh Shah4fdde762013-04-30 18:47:33 -0700276 int crop_w = crop.right - crop.left;
277 int crop_h = crop.bottom - crop.top;
278 int dst_w = dst.right - dst.left;
279 int dst_h = dst.bottom - dst.top;
280 float w_dscale = ceilf((float)crop_w / (float)dst_w);
281 float h_dscale = ceilf((float)crop_h / (float)dst_h);
282
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800283 /* Workaround for MDP HW limitation in DSI command mode panels where
284 * FPS will not go beyond 30 if buffers on RGB pipes are of width or height
285 * less than 5 pixels
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530286 * There also is a HW limilation in MDP, minimum block size is 2x2
287 * Fallback to GPU if height is less than 2.
288 */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800289 if((crop_w < 5)||(crop_h < 5))
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800290 return false;
291
Saurabh Shah4fdde762013-04-30 18:47:33 -0700292 const uint32_t downscale =
293 qdutils::MDPVersion::getInstance().getMaxMDPDownscale();
294 if(ctx->mMDP.version >= qdutils::MDSS_V5) {
295 /* Workaround for downscales larger than 4x.
296 * Will be removed once decimator block is enabled for MDSS
297 */
298 if(!qdutils::MDPVersion::getInstance().supportsDecimation()) {
299 if(crop_w > MAX_DISPLAY_DIM || w_dscale > downscale ||
300 h_dscale > downscale)
301 return false;
302 } else {
303 if(w_dscale > 64 || h_dscale > 64)
304 return false;
305 }
306 } else { //A-family
307 if(w_dscale > downscale || h_dscale > downscale)
308 return false;
309 }
310
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800311 return true;
312}
313
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700314ovutils::eDest MDPComp::getMdpPipe(hwc_context_t *ctx, ePipeType type,
315 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800316 overlay::Overlay& ov = *ctx->mOverlay;
317 ovutils::eDest mdp_pipe = ovutils::OV_INVALID;
318
319 switch(type) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800320 case MDPCOMP_OV_DMA:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700321 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_DMA, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800322 if(mdp_pipe != ovutils::OV_INVALID) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800323 return mdp_pipe;
324 }
325 case MDPCOMP_OV_ANY:
326 case MDPCOMP_OV_RGB:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700327 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800328 if(mdp_pipe != ovutils::OV_INVALID) {
329 return mdp_pipe;
330 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800331
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800332 if(type == MDPCOMP_OV_RGB) {
333 //Requested only for RGB pipe
334 break;
335 }
336 case MDPCOMP_OV_VG:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700337 return ov.nextPipe(ovutils::OV_MDP_PIPE_VG, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800338 default:
339 ALOGE("%s: Invalid pipe type",__FUNCTION__);
340 return ovutils::OV_INVALID;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800341 };
342 return ovutils::OV_INVALID;
343}
344
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800345bool MDPComp::isFrameDoable(hwc_context_t *ctx) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700346 bool ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700347 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800348
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800349 if(!isEnabled()) {
350 ALOGD_IF(isDebug(),"%s: MDP Comp. not enabled.", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700351 ret = false;
Saurabh Shahd4e65852013-06-17 11:33:53 -0700352 } else if(qdutils::MDPVersion::getInstance().is8x26() &&
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700353 ctx->mVideoTransFlag && ctx->mVirtualDisplay->isConnected()) {
Saurabh Shahd4e65852013-06-17 11:33:53 -0700354 //1 Padding round to shift pipes across mixers
355 ALOGD_IF(isDebug(),"%s: MDP Comp. video transition padding round",
356 __FUNCTION__);
357 ret = false;
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700358 } else if(ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isConfiguring ||
359 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isConfiguring) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800360 ALOGD_IF( isDebug(),"%s: External Display connection is pending",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800361 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700362 ret = false;
Saurabh Shahaa236822013-04-24 18:07:26 -0700363 } else if(ctx->isPaddingRound) {
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700364 ctx->isPaddingRound = false;
365 ALOGD_IF(isDebug(), "%s: padding round",__FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700366 ret = false;
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700367 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700368 return ret;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800369}
370
371/* Checks for conditions where all the layers marked for MDP comp cannot be
372 * bypassed. On such conditions we try to bypass atleast YUV layers */
373bool MDPComp::isFullFrameDoable(hwc_context_t *ctx,
374 hwc_display_contents_1_t* list){
375
Saurabh Shahaa236822013-04-24 18:07:26 -0700376 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800377
Saurabh Shah2d998a92013-05-14 17:55:58 -0700378 if(sIdleFallBack) {
379 ALOGD_IF(isDebug(), "%s: Idle fallback dpy %d",__FUNCTION__, mDpy);
380 return false;
381 }
382
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800383 if(mDpy > HWC_DISPLAY_PRIMARY){
384 ALOGD_IF(isDebug(), "%s: Cannot support External display(s)",
385 __FUNCTION__);
386 return false;
387 }
388
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800389 if(isSkipPresent(ctx, mDpy)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700390 ALOGD_IF(isDebug(),"%s: SKIP present: %d",
391 __FUNCTION__,
392 isSkipPresent(ctx, mDpy));
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800393 return false;
394 }
395
Saurabh Shah9f084ad2013-05-02 11:28:09 -0700396 if(ctx->listStats[mDpy].needsAlphaScale
397 && ctx->mMDP.version < qdutils::MDSS_V5) {
398 ALOGD_IF(isDebug(), "%s: frame needs alpha downscaling",__FUNCTION__);
399 return false;
400 }
401
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800402 //MDP composition is not efficient if layer needs rotator.
403 for(int i = 0; i < numAppLayers; ++i) {
404 // As MDP h/w supports flip operation, use MDP comp only for
405 // 180 transforms. Fail for any transform involving 90 (90, 270).
406 hwc_layer_1_t* layer = &list->hwLayers[i];
407 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800408
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700409 if(layer->transform & HWC_TRANSFORM_ROT_90) {
410 if(!isYuvBuffer(hnd) ) {
411 ALOGD_IF(isDebug(), "%s: orientation involved",__FUNCTION__);
412 return false;
413 }else if(!canUseRotator(ctx, mDpy)) {
414 ALOGD_IF(isDebug(), "%s: no free DMA pipe",__FUNCTION__);
415 return false;
416 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800417 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700418 if(!isValidDimension(ctx,layer)) {
419 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
420 __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800421 return false;
422 }
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530423
424 //For 8x26 with panel width>1k, if RGB layer needs HFLIP fail mdp comp
425 // may not need it if Gfx pre-rotation can handle all flips & rotations
426 if(qdutils::MDPVersion::getInstance().is8x26() &&
427 (ctx->dpyAttr[mDpy].xres > 1024) &&
428 (layer->transform & HWC_TRANSFORM_FLIP_H) &&
429 (!isYuvBuffer(hnd)))
430 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800431 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700432
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700433 if(ctx->mAD->isDoable()) {
434 return false;
435 }
436
Saurabh Shahaa236822013-04-24 18:07:26 -0700437 //If all above hard conditions are met we can do full or partial MDP comp.
438 bool ret = false;
439 if(fullMDPComp(ctx, list)) {
440 ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700441 } else if(partialMDPComp(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700442 ret = true;
443 }
444 return ret;
445}
446
447bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
448 //Setup mCurrentFrame
449 mCurrentFrame.mdpCount = mCurrentFrame.layerCount;
450 mCurrentFrame.fbCount = 0;
451 mCurrentFrame.fbZ = -1;
452 memset(&mCurrentFrame.isFBComposed, 0, sizeof(mCurrentFrame.isFBComposed));
453
454 int mdpCount = mCurrentFrame.mdpCount;
455 if(mdpCount > sMaxPipesPerMixer) {
456 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
457 return false;
458 }
459
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700460 if(!arePipesAvailable(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700461 return false;
462 }
463
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700464 uint32_t size = calcMDPBytesRead(ctx, list);
465 if(!bandwidthCheck(ctx, size)) {
466 ALOGD_IF(isDebug(), "%s: Exceeds bandwidth",__FUNCTION__);
467 return false;
468 }
469
Saurabh Shahaa236822013-04-24 18:07:26 -0700470 return true;
471}
472
473bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
474{
475 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700476
477 if(!sEnableMixedMode) {
478 //Mixed mode is disabled. No need to even try caching.
479 return false;
480 }
481
Saurabh Shahaa236822013-04-24 18:07:26 -0700482 //Setup mCurrentFrame
483 mCurrentFrame.reset(numAppLayers);
484 updateLayerCache(ctx, list);
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700485 updateYUV(ctx, list, false /*secure only*/);
Saurabh Shahaa236822013-04-24 18:07:26 -0700486 batchLayers(); //sets up fbZ also
487
488 int mdpCount = mCurrentFrame.mdpCount;
489 if(mdpCount > (sMaxPipesPerMixer - 1)) { // -1 since FB is used
490 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
491 return false;
492 }
493
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700494 if(!arePipesAvailable(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700495 return false;
496 }
497
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700498 uint32_t size = calcMDPBytesRead(ctx, list);
499 if(!bandwidthCheck(ctx, size)) {
500 ALOGD_IF(isDebug(), "%s: Exceeds bandwidth",__FUNCTION__);
501 return false;
502 }
503
Saurabh Shahaa236822013-04-24 18:07:26 -0700504 return true;
505}
506
507bool MDPComp::isOnlyVideoDoable(hwc_context_t *ctx,
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700508 hwc_display_contents_1_t* list, bool secureOnly) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700509 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
510 mCurrentFrame.reset(numAppLayers);
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700511 updateYUV(ctx, list, secureOnly);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700512 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700513 int fbNeeded = int(mCurrentFrame.fbCount != 0);
514
515 if(!isYuvPresent(ctx, mDpy)) {
516 return false;
517 }
518
Saurabh Shah4fdde762013-04-30 18:47:33 -0700519 if(!mdpCount)
520 return false;
521
Saurabh Shahaa236822013-04-24 18:07:26 -0700522 if(mdpCount > (sMaxPipesPerMixer - fbNeeded)) {
523 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
524 return false;
525 }
526
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700527 if(!arePipesAvailable(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700528 return false;
529 }
530
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700531 uint32_t size = calcMDPBytesRead(ctx, list);
532 if(!bandwidthCheck(ctx, size)) {
533 ALOGD_IF(isDebug(), "%s: Exceeds bandwidth",__FUNCTION__);
534 return false;
535 }
536
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800537 return true;
538}
539
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800540/* Checks for conditions where YUV layers cannot be bypassed */
541bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Saurabh Shahe2474082013-05-15 16:32:13 -0700542 bool extAnimBlockFeature = mDpy && ctx->listStats[mDpy].isDisplayAnimating;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800543
Saurabh Shahe2474082013-05-15 16:32:13 -0700544 if(isSkipLayer(layer) && !extAnimBlockFeature) {
545 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800546 return false;
547 }
548
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700549 if(layer->transform & HWC_TRANSFORM_ROT_90 && !canUseRotator(ctx,mDpy)) {
550 ALOGD_IF(isDebug(), "%s: no free DMA pipe",__FUNCTION__);
551 return false;
552 }
553
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800554 if(isSecuring(ctx, layer)) {
555 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
556 return false;
557 }
558
Saurabh Shah4fdde762013-04-30 18:47:33 -0700559 if(!isValidDimension(ctx, layer)) {
560 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
561 __FUNCTION__);
562 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800563 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700564
Naseer Ahmeddc61a972013-07-10 17:50:54 -0400565 if(layer->planeAlpha < 0xFF) {
566 ALOGD_IF(isDebug(), "%s: Cannot handle YUV layer with plane alpha\
567 in video only mode",
568 __FUNCTION__);
569 return false;
570 }
571
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800572 return true;
573}
574
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800575void MDPComp::batchLayers() {
576 /* Idea is to keep as many contiguous non-updating(cached) layers in FB and
577 * send rest of them through MDP. NEVER mark an updating layer for caching.
578 * But cached ones can be marked for MDP*/
579
580 int maxBatchStart = -1;
581 int maxBatchCount = 0;
582
583 /* All or Nothing is cached. No batching needed */
Saurabh Shahaa236822013-04-24 18:07:26 -0700584 if(!mCurrentFrame.fbCount) {
585 mCurrentFrame.fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800586 return;
Saurabh Shahaa236822013-04-24 18:07:26 -0700587 }
588 if(!mCurrentFrame.mdpCount) {
589 mCurrentFrame.fbZ = 0;
590 return;
591 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800592
593 /* Search for max number of contiguous (cached) layers */
594 int i = 0;
595 while (i < mCurrentFrame.layerCount) {
596 int count = 0;
597 while(mCurrentFrame.isFBComposed[i] && i < mCurrentFrame.layerCount) {
598 count++; i++;
599 }
600 if(count > maxBatchCount) {
601 maxBatchCount = count;
602 maxBatchStart = i - count;
Saurabh Shahaa236822013-04-24 18:07:26 -0700603 mCurrentFrame.fbZ = maxBatchStart;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800604 }
605 if(i < mCurrentFrame.layerCount) i++;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800606 }
607
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800608 /* reset rest of the layers for MDP comp */
609 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
610 if(i != maxBatchStart){
611 mCurrentFrame.isFBComposed[i] = false;
612 } else {
613 i += maxBatchCount;
614 }
615 }
616
617 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700618 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
619 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800620
621 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
622 mCurrentFrame.fbCount);
623}
Saurabh Shah85234ec2013-04-12 17:09:00 -0700624
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800625void MDPComp::updateLayerCache(hwc_context_t* ctx,
626 hwc_display_contents_1_t* list) {
627
628 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
629 int numCacheableLayers = 0;
630
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800631 for(int i = 0; i < numAppLayers; i++) {
632 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
633 numCacheableLayers++;
634 mCurrentFrame.isFBComposed[i] = true;
635 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -0700636 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800637 mCachedFrame.hnd[i] = list->hwLayers[i].handle;
638 }
639 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700640
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800641 mCurrentFrame.fbCount = numCacheableLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700642 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
643 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800644 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__, numCacheableLayers);
645}
646
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700647void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list,
648 bool secureOnly) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800649 int nYuvCount = ctx->listStats[mDpy].yuvCount;
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700650 if(!nYuvCount && mDpy) {
651 //Reset "No animation on external display" related parameters.
652 ctx->mPrevCropVideo.left = ctx->mPrevCropVideo.top =
653 ctx->mPrevCropVideo.right = ctx->mPrevCropVideo.bottom = 0;
654 ctx->mPrevDestVideo.left = ctx->mPrevDestVideo.top =
655 ctx->mPrevDestVideo.right = ctx->mPrevDestVideo.bottom = 0;
656 ctx->mPrevTransformVideo = 0;
657 return;
658 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800659 for(int index = 0;index < nYuvCount; index++){
660 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
661 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
662
663 if(!isYUVDoable(ctx, layer)) {
664 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
665 mCurrentFrame.isFBComposed[nYuvIndex] = true;
666 mCurrentFrame.fbCount++;
667 }
668 } else {
669 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700670 private_handle_t *hnd = (private_handle_t *)layer->handle;
671 if(!secureOnly || isSecureBuffer(hnd)) {
672 mCurrentFrame.isFBComposed[nYuvIndex] = false;
673 mCurrentFrame.fbCount--;
674 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800675 }
676 }
677 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700678
679 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
680 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800681 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
682 mCurrentFrame.fbCount);
683}
684
Saurabh Shahaa236822013-04-24 18:07:26 -0700685bool MDPComp::programMDP(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800686 if(!allocLayerPipes(ctx, list)) {
687 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700688 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800689 }
690
Saurabh Shahaa236822013-04-24 18:07:26 -0700691 bool fbBatch = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800692 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700693 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800694 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800695 int mdpIndex = mCurrentFrame.layerToMDP[index];
696 hwc_layer_1_t* layer = &list->hwLayers[index];
697
698 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
699 cur_pipe->zOrder = mdpNextZOrder++;
700
701 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
702 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
703 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -0700704 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800705 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700706 } else if(fbBatch == false) {
707 mdpNextZOrder++;
708 fbBatch = true;
709 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800710 }
711
Saurabh Shahaa236822013-04-24 18:07:26 -0700712 return true;
713}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800714
Saurabh Shahaa236822013-04-24 18:07:26 -0700715bool MDPComp::programYUV(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
716 if(!allocLayerPipes(ctx, list)) {
717 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
718 return false;
719 }
720 //If we are in this block, it means we have yuv + rgb layers both
721 int mdpIdx = 0;
722 for (int index = 0; index < mCurrentFrame.layerCount; index++) {
723 if(!mCurrentFrame.isFBComposed[index]) {
724 hwc_layer_1_t* layer = &list->hwLayers[index];
725 int mdpIndex = mCurrentFrame.layerToMDP[index];
726 MdpPipeInfo* cur_pipe =
727 mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
728 cur_pipe->zOrder = mdpIdx++;
729
730 if(configure(ctx, layer,
731 mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
732 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
733 layer %d",__FUNCTION__, index);
734 return false;
735 }
736 }
737 }
738 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800739}
740
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700741uint32_t MDPComp::calcMDPBytesRead(hwc_context_t *ctx,
742 hwc_display_contents_1_t* list) {
743 uint32_t size = 0;
744
Terence Hampson9cd5fa92013-09-10 17:06:37 -0400745 if(!qdutils::MDPVersion::getInstance().is8x74v2())
746 return 0;
747
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700748 for (uint32_t i = 0; i < list->numHwLayers - 1; i++) {
749 if(!mCurrentFrame.isFBComposed[i]) {
750 hwc_layer_1_t* layer = &list->hwLayers[i];
751 private_handle_t *hnd = (private_handle_t *)layer->handle;
Terence Hampson9cd5fa92013-09-10 17:06:37 -0400752 if (hnd) {
753 hwc_rect_t crop = layer->sourceCrop;
754 float bpp = ((float)hnd->size) / (hnd->width * hnd->height);
755 size += bpp * ((crop.right - crop.left) *
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700756 (crop.bottom - crop.top));
Terence Hampson9cd5fa92013-09-10 17:06:37 -0400757 }
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700758 }
759 }
760
761 if(mCurrentFrame.fbCount) {
762 hwc_layer_1_t* layer = &list->hwLayers[list->numHwLayers - 1];
763 private_handle_t *hnd = (private_handle_t *)layer->handle;
Terence Hampson9cd5fa92013-09-10 17:06:37 -0400764 if (hnd)
765 size += hnd->size;
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700766 }
767
768 return size;
769}
770
771bool MDPComp::bandwidthCheck(hwc_context_t *ctx, const uint32_t& size) {
772 //Will be added for other targets if we run into bandwidth issues and when
773 //we have profiling data to set an upper limit.
774 if(qdutils::MDPVersion::getInstance().is8x74v2()) {
775 const uint32_t ONE_GIG = 1024 * 1024 * 1024;
776 double panelRefRate =
777 1000000000.0 / ctx->dpyAttr[mDpy].vsync_period;
778 if((size + sCompBytesClaimed) > ((sMaxBw / panelRefRate) * ONE_GIG)) {
779 return false;
780 }
781 }
782 return true;
783}
784
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800785int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700786 int ret = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -0700787 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -0700788
Saurabh Shahb39f8152013-08-22 10:21:44 -0700789 //reset old data
790 mCurrentFrame.reset(numLayers);
Prabhanjan Kandula088bd892013-07-02 23:47:13 +0530791
Saurabh Shahb39f8152013-08-22 10:21:44 -0700792 //number of app layers exceeds MAX_NUM_APP_LAYERS fall back to GPU
793 //do not cache the information for next draw cycle.
794 if(numLayers > MAX_NUM_APP_LAYERS) {
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530795 mCachedFrame.updateCounts(mCurrentFrame);
Saurabh Shahb39f8152013-08-22 10:21:44 -0700796 ALOGD_IF(isDebug(), "%s: Number of App layers exceeded the limit ",
797 __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700798 ret = -1;
799 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -0700800 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800801
Saurabh Shahb39f8152013-08-22 10:21:44 -0700802 //Hard conditions, if not met, cannot do MDP comp
803 if(!isFrameDoable(ctx)) {
804 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
805 __FUNCTION__);
806 reset(numLayers, list);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700807 ret = -1;
808 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -0700809 }
810
811 //Check whether layers marked for MDP Composition is actually doable.
812 if(isFullFrameDoable(ctx, list)) {
813 mCurrentFrame.map();
814 //Configure framebuffer first if applicable
815 if(mCurrentFrame.fbZ >= 0) {
816 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list,
817 mCurrentFrame.fbZ)) {
818 ALOGE("%s configure framebuffer failed", __func__);
819 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -0700820 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700821 ret = -1;
822 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -0700823 }
824 }
825 //Acquire and Program MDP pipes
826 if(!programMDP(ctx, list)) {
827 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -0700828 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700829 ret = -1;
830 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -0700831 } else { //Success
832 //Any change in composition types needs an FB refresh
833 mCurrentFrame.needsRedraw = false;
834 if(mCurrentFrame.fbCount &&
835 ((mCurrentFrame.mdpCount != mCachedFrame.mdpCount) ||
836 (mCurrentFrame.fbCount != mCachedFrame.cacheCount) ||
837 (mCurrentFrame.fbZ != mCachedFrame.fbZ) ||
838 (!mCurrentFrame.mdpCount) ||
839 (list->flags & HWC_GEOMETRY_CHANGED) ||
840 isSkipPresent(ctx, mDpy) ||
841 (mDpy > HWC_DISPLAY_PRIMARY))) {
842 mCurrentFrame.needsRedraw = true;
843 }
844 }
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700845 } else if(isOnlyVideoDoable(ctx, list, false /*secure only*/) ||
846 isOnlyVideoDoable(ctx, list, true /*secure only*/)) {
Saurabh Shahb39f8152013-08-22 10:21:44 -0700847 //All layers marked for MDP comp cannot be bypassed.
848 //Try to compose atleast YUV layers through MDP comp and let
849 //all the RGB layers compose in FB
850 //Destination over
851 mCurrentFrame.fbZ = -1;
852 if(mCurrentFrame.fbCount)
853 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
854
855 mCurrentFrame.map();
856
857 //Configure framebuffer first if applicable
858 if(mCurrentFrame.fbZ >= 0) {
859 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, mCurrentFrame.fbZ)) {
860 ALOGE("%s configure framebuffer failed", __func__);
861 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -0700862 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700863 ret = -1;
864 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -0700865 }
866 }
867 if(!programYUV(ctx, list)) {
868 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -0700869 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700870 ret = -1;
871 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -0700872 }
873 } else {
874 reset(numLayers, list);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700875 ret = -1;
876 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -0700877 }
878
879 //UpdateLayerFlags
880 setMDPCompLayerFlags(ctx, list);
881 mCachedFrame.updateCounts(mCurrentFrame);
882
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530883 // unlock it before calling dump function to avoid deadlock
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800884 if(isDebug()) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700885 ALOGD("GEOMETRY change: %d", (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800886 android::String8 sDump("");
887 dump(sDump);
888 ALOGE("%s",sDump.string());
889 }
890
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700891exit:
892 sCompBytesClaimed += calcMDPBytesRead(ctx, list);
893 return ret;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800894}
895
Saurabh Shah88e4d272013-09-03 13:31:29 -0700896//=============MDPCompNonSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800897
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700898/*
899 * Configures pipe(s) for MDP composition
900 */
Saurabh Shah88e4d272013-09-03 13:31:29 -0700901int MDPCompNonSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800902 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -0700903 MdpPipeInfoNonSplit& mdp_info =
904 *(static_cast<MdpPipeInfoNonSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -0800905 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
906 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
907 eIsFg isFg = IS_FG_OFF;
908 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700909
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800910 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
911 __FUNCTION__, layer, zOrder, dest);
912
Saurabh Shah88e4d272013-09-03 13:31:29 -0700913 return configureNonSplit(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800914 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700915}
916
Saurabh Shah88e4d272013-09-03 13:31:29 -0700917bool MDPCompNonSplit::arePipesAvailable(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700918 hwc_display_contents_1_t* list) {
919 overlay::Overlay& ov = *ctx->mOverlay;
920 int numPipesNeeded = mCurrentFrame.mdpCount;
921 int availPipes = ov.availablePipes(mDpy, Overlay::MIXER_DEFAULT);
922
923 //Reserve pipe for FB
924 if(mCurrentFrame.fbCount)
925 availPipes -= 1;
926
927 if(numPipesNeeded > availPipes) {
928 ALOGD_IF(isDebug(), "%s: Insufficient pipes, dpy %d needed %d, avail %d",
929 __FUNCTION__, mDpy, numPipesNeeded, availPipes);
930 return false;
931 }
932
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700933 if(not areVGPipesAvailable(ctx, list)) {
934 return false;
935 }
936
937 return true;
938}
939
940bool MDPCompNonSplit::areVGPipesAvailable(hwc_context_t *ctx,
941 hwc_display_contents_1_t* list) {
942 overlay::Overlay& ov = *ctx->mOverlay;
943 int pipesNeeded = 0;
944 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
945 if(!mCurrentFrame.isFBComposed[i]) {
946 hwc_layer_1_t* layer = &list->hwLayers[i];
947 hwc_rect_t dst = layer->displayFrame;
948 private_handle_t *hnd = (private_handle_t *)layer->handle;
949 if(isYuvBuffer(hnd)) {
950 pipesNeeded++;
951 }
952 }
953 }
954
955 int availableVGPipes = ov.availablePipes(mDpy, ovutils::OV_MDP_PIPE_VG);
956 if(pipesNeeded > availableVGPipes) {
957 ALOGD_IF(isDebug(), "%s: Insufficient VG pipes for video layers"
958 "dpy %d needed %d, avail %d",
959 __FUNCTION__, mDpy, pipesNeeded, availableVGPipes);
960 return false;
961 }
962
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700963 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700964}
965
Saurabh Shah88e4d272013-09-03 13:31:29 -0700966bool MDPCompNonSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700967 hwc_display_contents_1_t* list) {
968 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700969
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800970 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700971
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800972 hwc_layer_1_t* layer = &list->hwLayers[index];
973 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800974 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800975 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -0700976 info.pipeInfo = new MdpPipeInfoNonSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -0800977 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -0700978 MdpPipeInfoNonSplit& pipe_info = *(MdpPipeInfoNonSplit*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800979 ePipeType type = MDPCOMP_OV_ANY;
980
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700981 if(isYuvBuffer(hnd)) {
982 type = MDPCOMP_OV_VG;
Saurabh Shah8a117932013-05-23 12:48:13 -0700983 } else if(!qhwc::needsScaling(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -0700984 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
985 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800986 type = MDPCOMP_OV_DMA;
987 }
988
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700989 pipe_info.index = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800990 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700991 ALOGD_IF(isDebug(), "%s: Unable to get pipe type = %d",
992 __FUNCTION__, (int) type);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500993 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700994 }
995 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700996 return true;
997}
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700998
Saurabh Shah88e4d272013-09-03 13:31:29 -0700999bool MDPCompNonSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001000
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001001 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001002 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1003 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -08001004 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001005
1006 if(!ctx || !list) {
1007 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001008 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001009 }
1010
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301011 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1012 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1013 return true;
1014 }
1015
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001016 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001017 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001018 idleInvalidator->markForSleep();
1019
1020 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001021 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001022
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001023 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1024 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001025 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001026 if(mCurrentFrame.isFBComposed[i]) continue;
1027
Naseer Ahmed5b6708a2012-08-02 13:46:08 -07001028 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001029 private_handle_t *hnd = (private_handle_t *)layer->handle;
1030 if(!hnd) {
1031 ALOGE("%s handle null", __FUNCTION__);
1032 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001033 }
1034
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001035 int mdpIndex = mCurrentFrame.layerToMDP[i];
1036
Saurabh Shah88e4d272013-09-03 13:31:29 -07001037 MdpPipeInfoNonSplit& pipe_info =
1038 *(MdpPipeInfoNonSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001039 ovutils::eDest dest = pipe_info.index;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001040 if(dest == ovutils::OV_INVALID) {
1041 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001042 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001043 }
1044
Saurabh Shahacf10202013-02-26 10:15:15 -08001045 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1046 continue;
1047 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001048
Saurabh Shahacf10202013-02-26 10:15:15 -08001049 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001050 using pipe: %d", __FUNCTION__, layer,
1051 hnd, dest );
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001052
Saurabh Shahacf10202013-02-26 10:15:15 -08001053 int fd = hnd->fd;
1054 uint32_t offset = hnd->offset;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001055
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001056 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -08001057 if(rot) {
1058 if(!rot->queueBuffer(fd, offset))
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001059 return false;
Saurabh Shahacf10202013-02-26 10:15:15 -08001060 fd = rot->getDstMemId();
1061 offset = rot->getDstOffset();
1062 }
1063
1064 if (!ov.queueBuffer(fd, offset, dest)) {
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301065 ALOGE("%s: queueBuffer failed for display:%d ", __FUNCTION__, mDpy);
Saurabh Shahacf10202013-02-26 10:15:15 -08001066 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001067 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001068
1069 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001070 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001071 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001072}
1073
Saurabh Shah88e4d272013-09-03 13:31:29 -07001074//=============MDPCompSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001075
Saurabh Shah88e4d272013-09-03 13:31:29 -07001076int MDPCompSplit::pipesNeeded(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001077 hwc_display_contents_1_t* list,
1078 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001079 int pipesNeeded = 0;
Saurabh Shah67a38c32013-06-10 16:23:15 -07001080 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001081
1082 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001083
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001084 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1085 if(!mCurrentFrame.isFBComposed[i]) {
1086 hwc_layer_1_t* layer = &list->hwLayers[i];
1087 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001088 if(mixer == Overlay::MIXER_LEFT && dst.left < lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001089 pipesNeeded++;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001090 } else if(mixer == Overlay::MIXER_RIGHT && dst.right > lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001091 pipesNeeded++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001092 }
1093 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001094 }
1095 return pipesNeeded;
1096}
1097
Saurabh Shah88e4d272013-09-03 13:31:29 -07001098bool MDPCompSplit::arePipesAvailable(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001099 hwc_display_contents_1_t* list) {
1100 overlay::Overlay& ov = *ctx->mOverlay;
Saurabh Shah082468e2013-09-12 10:05:32 -07001101 int totalPipesNeeded = 0;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001102
1103 for(int i = 0; i < Overlay::MIXER_MAX; i++) {
1104 int numPipesNeeded = pipesNeeded(ctx, list, i);
1105 int availPipes = ov.availablePipes(mDpy, i);
1106
1107 //Reserve pipe(s)for FB
1108 if(mCurrentFrame.fbCount)
Saurabh Shah082468e2013-09-12 10:05:32 -07001109 numPipesNeeded += 1;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001110
Saurabh Shah082468e2013-09-12 10:05:32 -07001111 totalPipesNeeded += numPipesNeeded;
1112
1113 //Per mixer check.
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001114 if(numPipesNeeded > availPipes) {
1115 ALOGD_IF(isDebug(), "%s: Insufficient pipes for "
1116 "dpy %d mixer %d needed %d, avail %d",
1117 __FUNCTION__, mDpy, i, numPipesNeeded, availPipes);
1118 return false;
1119 }
1120 }
Saurabh Shah082468e2013-09-12 10:05:32 -07001121
1122 //Per display check, since unused pipes can get counted twice.
1123 int totalPipesAvailable = ov.availablePipes(mDpy);
1124 if(totalPipesNeeded > totalPipesAvailable) {
1125 ALOGD_IF(isDebug(), "%s: Insufficient pipes for "
1126 "dpy %d needed %d, avail %d",
1127 __FUNCTION__, mDpy, totalPipesNeeded, totalPipesAvailable);
1128 return false;
1129 }
1130
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001131 if(not areVGPipesAvailable(ctx, list)) {
1132 return false;
1133 }
1134
1135 return true;
1136}
1137
1138bool MDPCompSplit::areVGPipesAvailable(hwc_context_t *ctx,
1139 hwc_display_contents_1_t* list) {
1140 overlay::Overlay& ov = *ctx->mOverlay;
1141 int pipesNeeded = 0;
1142 const int lSplit = getLeftSplit(ctx, mDpy);
1143 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1144 if(!mCurrentFrame.isFBComposed[i]) {
1145 hwc_layer_1_t* layer = &list->hwLayers[i];
1146 hwc_rect_t dst = layer->displayFrame;
1147 private_handle_t *hnd = (private_handle_t *)layer->handle;
1148 if(isYuvBuffer(hnd)) {
1149 if(dst.left < lSplit) {
1150 pipesNeeded++;
1151 }
1152 if(dst.right > lSplit) {
1153 pipesNeeded++;
1154 }
1155 }
1156 }
1157 }
1158
1159 int availableVGPipes = ov.availablePipes(mDpy, ovutils::OV_MDP_PIPE_VG);
1160 if(pipesNeeded > availableVGPipes) {
1161 ALOGD_IF(isDebug(), "%s: Insufficient VG pipes for video layers"
1162 "dpy %d needed %d, avail %d",
1163 __FUNCTION__, mDpy, pipesNeeded, availableVGPipes);
1164 return false;
1165 }
1166
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001167 return true;
1168}
1169
Saurabh Shah88e4d272013-09-03 13:31:29 -07001170bool MDPCompSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
1171 MdpPipeInfoSplit& pipe_info,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001172 ePipeType type) {
1173 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001174 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001175
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001176 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001177 pipe_info.lIndex = ovutils::OV_INVALID;
1178 pipe_info.rIndex = ovutils::OV_INVALID;
1179
1180 if (dst.left < lSplit) {
1181 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_LEFT);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001182 if(pipe_info.lIndex == ovutils::OV_INVALID)
1183 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001184 }
1185
1186 if(dst.right > lSplit) {
1187 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_RIGHT);
1188 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001189 return false;
1190 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001191
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001192 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001193}
1194
Saurabh Shah88e4d272013-09-03 13:31:29 -07001195bool MDPCompSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001196 hwc_display_contents_1_t* list) {
1197 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001198
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001199 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001200
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001201 hwc_layer_1_t* layer = &list->hwLayers[index];
1202 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001203 int mdpIndex = mCurrentFrame.layerToMDP[index];
1204 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001205 info.pipeInfo = new MdpPipeInfoSplit;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001206 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001207 MdpPipeInfoSplit& pipe_info = *(MdpPipeInfoSplit*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001208 ePipeType type = MDPCOMP_OV_ANY;
1209
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001210 if(isYuvBuffer(hnd)) {
1211 type = MDPCOMP_OV_VG;
Sushil Chauhan15a2ea62013-09-04 18:28:36 -07001212 } else if(!qhwc::needsScalingWithSplit(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001213 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001214 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001215 type = MDPCOMP_OV_DMA;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001216 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001217
1218 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001219 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type = %d",
1220 __FUNCTION__, (int) type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001221 return false;
1222 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001223 }
1224 return true;
1225}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001226
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001227/*
1228 * Configures pipe(s) for MDP composition
1229 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001230int MDPCompSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001231 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001232 MdpPipeInfoSplit& mdp_info =
1233 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001234 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1235 eIsFg isFg = IS_FG_OFF;
1236 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1237 eDest lDest = mdp_info.lIndex;
1238 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001239
1240 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1241 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1242
Saurabh Shah88e4d272013-09-03 13:31:29 -07001243 return configureSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001244 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001245}
1246
Saurabh Shah88e4d272013-09-03 13:31:29 -07001247bool MDPCompSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001248
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001249 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001250 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1251 return true;
1252 }
1253
1254 if(!ctx || !list) {
1255 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001256 return false;
1257 }
1258
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301259 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1260 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1261 return true;
1262 }
1263
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001264 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001265 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001266 idleInvalidator->markForSleep();
1267
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001268 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001269 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001270
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001271 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1272 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001273 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001274 if(mCurrentFrame.isFBComposed[i]) continue;
1275
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001276 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001277 private_handle_t *hnd = (private_handle_t *)layer->handle;
1278 if(!hnd) {
1279 ALOGE("%s handle null", __FUNCTION__);
1280 return false;
1281 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001282
1283 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1284 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001285 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001286
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001287 int mdpIndex = mCurrentFrame.layerToMDP[i];
1288
Saurabh Shah88e4d272013-09-03 13:31:29 -07001289 MdpPipeInfoSplit& pipe_info =
1290 *(MdpPipeInfoSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001291 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -08001292
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001293 ovutils::eDest indexL = pipe_info.lIndex;
1294 ovutils::eDest indexR = pipe_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001295
Saurabh Shahacf10202013-02-26 10:15:15 -08001296 int fd = hnd->fd;
1297 int offset = hnd->offset;
1298
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001299 if(ctx->mAD->isModeOn()) {
1300 if(ctx->mAD->draw(ctx, fd, offset)) {
1301 fd = ctx->mAD->getDstFd(ctx);
1302 offset = ctx->mAD->getDstOffset(ctx);
1303 }
1304 }
1305
Saurabh Shahacf10202013-02-26 10:15:15 -08001306 if(rot) {
1307 rot->queueBuffer(fd, offset);
1308 fd = rot->getDstMemId();
1309 offset = rot->getDstOffset();
1310 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001311
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001312 //************* play left mixer **********
1313 if(indexL != ovutils::OV_INVALID) {
1314 ovutils::eDest destL = (ovutils::eDest)indexL;
Saurabh Shahacf10202013-02-26 10:15:15 -08001315 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001316 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
Saurabh Shahacf10202013-02-26 10:15:15 -08001317 if (!ov.queueBuffer(fd, offset, destL)) {
1318 ALOGE("%s: queueBuffer failed for left mixer", __FUNCTION__);
1319 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001320 }
1321 }
1322
1323 //************* play right mixer **********
1324 if(indexR != ovutils::OV_INVALID) {
1325 ovutils::eDest destR = (ovutils::eDest)indexR;
Saurabh Shahacf10202013-02-26 10:15:15 -08001326 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001327 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
Saurabh Shahacf10202013-02-26 10:15:15 -08001328 if (!ov.queueBuffer(fd, offset, destR)) {
1329 ALOGE("%s: queueBuffer failed for right mixer", __FUNCTION__);
1330 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001331 }
1332 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001333
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001334 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1335 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001336
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001337 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001338}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001339}; //namespace
1340