blob: ff33e94cc8098fbe03e1bfc7979a78f27f9129bd [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;
Saurabh Shah8c5c8522013-08-29 17:32:49 -070046float MDPComp::sMaxBw = 2.3f;
47uint32_t MDPComp::sCompBytesClaimed = 0;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070048
Saurabh Shah88e4d272013-09-03 13:31:29 -070049MDPComp* MDPComp::getObject(hwc_context_t *ctx, const int& dpy) {
50 if(isDisplaySplit(ctx, dpy)) {
51 return new MDPCompSplit(dpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080052 }
Saurabh Shah88e4d272013-09-03 13:31:29 -070053 return new MDPCompNonSplit(dpy);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080054}
55
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080056MDPComp::MDPComp(int dpy):mDpy(dpy){};
57
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080058void MDPComp::dump(android::String8& buf)
59{
Jeykumar Sankaran3c6bb042013-08-15 14:01:04 -070060 if(mCurrentFrame.layerCount > MAX_NUM_APP_LAYERS)
61 return;
62
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080063 dumpsys_log(buf,"HWC Map for Dpy: %s \n",
Jeykumar Sankaran27dee262013-08-01 17:09:54 -070064 (mDpy == 0) ? "\"PRIMARY\"" :
65 (mDpy == 1) ? "\"EXTERNAL\"" : "\"VIRTUAL\"");
Saurabh Shahe9bc60f2013-08-29 12:58:06 -070066 dumpsys_log(buf,"CURR_FRAME: layerCount:%2d mdpCount:%2d "
67 "fbCount:%2d \n", mCurrentFrame.layerCount,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080068 mCurrentFrame.mdpCount, mCurrentFrame.fbCount);
69 dumpsys_log(buf,"needsFBRedraw:%3s pipesUsed:%2d MaxPipesPerMixer: %d \n",
70 (mCurrentFrame.needsRedraw? "YES" : "NO"),
71 mCurrentFrame.mdpCount, sMaxPipesPerMixer);
72 dumpsys_log(buf," --------------------------------------------- \n");
73 dumpsys_log(buf," listIdx | cached? | mdpIndex | comptype | Z \n");
74 dumpsys_log(buf," --------------------------------------------- \n");
75 for(int index = 0; index < mCurrentFrame.layerCount; index++ )
76 dumpsys_log(buf," %7d | %7s | %8d | %9s | %2d \n",
77 index,
78 (mCurrentFrame.isFBComposed[index] ? "YES" : "NO"),
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -070079 mCurrentFrame.layerToMDP[index],
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080080 (mCurrentFrame.isFBComposed[index] ?
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -070081 (mCurrentFrame.drop[index] ? "DROP" :
82 (mCurrentFrame.needsRedraw ? "GLES" : "CACHE")) : "MDP"),
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080083 (mCurrentFrame.isFBComposed[index] ? mCurrentFrame.fbZ :
84 mCurrentFrame.mdpToLayer[mCurrentFrame.layerToMDP[index]].pipeInfo->zOrder));
85 dumpsys_log(buf,"\n");
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080086}
87
88bool MDPComp::init(hwc_context_t *ctx) {
89
90 if(!ctx) {
91 ALOGE("%s: Invalid hwc context!!",__FUNCTION__);
92 return false;
93 }
94
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080095 char property[PROPERTY_VALUE_MAX];
96
97 sEnabled = false;
98 if((property_get("persist.hwc.mdpcomp.enable", property, NULL) > 0) &&
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080099 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
100 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800101 sEnabled = true;
102 }
103
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700104 sEnableMixedMode = true;
105 if((property_get("debug.mdpcomp.mixedmode.disable", property, NULL) > 0) &&
106 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
107 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
108 sEnableMixedMode = false;
109 }
110
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800111 if(property_get("debug.mdpcomp.logs", property, NULL) > 0) {
112 if(atoi(property) != 0)
113 sDebugLogs = true;
114 }
115
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700116 if(property_get("persist.hwc.partialupdate.enable", property, NULL) > 0) {
117 if((atoi(property) != 0) && ctx->mMDP.panel == MIPI_CMD_PANEL &&
118 qdutils::MDPVersion::getInstance().is8x74v2())
119 sEnablePartialFrameUpdate = true;
120 }
121 ALOGE_IF(isDebug(), "%s: Partial Update applicable?: %d",__FUNCTION__,
122 sEnablePartialFrameUpdate);
123
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800124 sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
Saurabh Shah85234ec2013-04-12 17:09:00 -0700125 if(property_get("debug.mdpcomp.maxpermixer", property, "-1") > 0) {
126 int val = atoi(property);
127 if(val >= 0)
128 sMaxPipesPerMixer = min(val, MAX_PIPES_PER_MIXER);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800129 }
130
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700131 if(property_get("debug.mdpcomp.bw", property, "0") > 0) {
132 float val = atof(property);
133 if(val > 0.0f) {
134 sMaxBw = val;
135 }
136 }
137
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400138 if(ctx->mMDP.panel != MIPI_CMD_PANEL) {
139 // Idle invalidation is not necessary on command mode panels
140 long idle_timeout = DEFAULT_IDLE_TIME;
141 if(property_get("debug.mdpcomp.idletime", property, NULL) > 0) {
142 if(atoi(property) != 0)
143 idle_timeout = atoi(property);
144 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800145
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400146 //create Idle Invalidator only when not disabled through property
147 if(idle_timeout != -1)
148 idleInvalidator = IdleInvalidator::getInstance();
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800149
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400150 if(idleInvalidator == NULL) {
151 ALOGE("%s: failed to instantiate idleInvalidator object",
152 __FUNCTION__);
153 } else {
154 idleInvalidator->init(timeout_handler, ctx, idle_timeout);
155 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800156 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700157 return true;
158}
159
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700160void MDPComp::reset(const int& numLayers, hwc_display_contents_1_t* list) {
161 mCurrentFrame.reset(numLayers);
162 mCachedFrame.cacheAll(list);
163 mCachedFrame.updateCounts(mCurrentFrame);
164}
165
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700166void MDPComp::timeout_handler(void *udata) {
167 struct hwc_context_t* ctx = (struct hwc_context_t*)(udata);
168
169 if(!ctx) {
170 ALOGE("%s: received empty data in timer callback", __FUNCTION__);
171 return;
172 }
173
Jesse Hall3be78d92012-08-21 15:12:23 -0700174 if(!ctx->proc) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700175 ALOGE("%s: HWC proc not registered", __FUNCTION__);
176 return;
177 }
178 sIdleFallBack = true;
179 /* Trigger SF to redraw the current frame */
Jesse Hall3be78d92012-08-21 15:12:23 -0700180 ctx->proc->invalidate(ctx->proc);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700181}
182
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800183void MDPComp::setMDPCompLayerFlags(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800184 hwc_display_contents_1_t* list) {
185 LayerProp *layerProp = ctx->layerProp[mDpy];
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800186
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800187 for(int index = 0; index < ctx->listStats[mDpy].numAppLayers; index++) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800188 hwc_layer_1_t* layer = &(list->hwLayers[index]);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800189 if(!mCurrentFrame.isFBComposed[index]) {
190 layerProp[index].mFlags |= HWC_MDPCOMP;
191 layer->compositionType = HWC_OVERLAY;
192 layer->hints |= HWC_HINT_CLEAR_FB;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800193 } else {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700194 /* Drop the layer when its already present in FB OR when it lies
195 * outside frame's ROI */
196 if(!mCurrentFrame.needsRedraw || mCurrentFrame.drop[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800197 layer->compositionType = HWC_OVERLAY;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700198 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800199 }
200 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700201}
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500202
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800203MDPComp::FrameInfo::FrameInfo() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700204 reset(0);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800205}
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800206
Saurabh Shahaa236822013-04-24 18:07:26 -0700207void MDPComp::FrameInfo::reset(const int& numLayers) {
208 for(int i = 0 ; i < MAX_PIPES_PER_MIXER && numLayers; i++ ) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800209 if(mdpToLayer[i].pipeInfo) {
210 delete mdpToLayer[i].pipeInfo;
211 mdpToLayer[i].pipeInfo = NULL;
212 //We dont own the rotator
213 mdpToLayer[i].rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800214 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800215 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800216
217 memset(&mdpToLayer, 0, sizeof(mdpToLayer));
218 memset(&layerToMDP, -1, sizeof(layerToMDP));
Saurabh Shahaa236822013-04-24 18:07:26 -0700219 memset(&isFBComposed, 1, sizeof(isFBComposed));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800220
Saurabh Shahaa236822013-04-24 18:07:26 -0700221 layerCount = numLayers;
222 fbCount = numLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800223 mdpCount = 0;
Saurabh Shah2f3895f2013-05-02 10:13:31 -0700224 needsRedraw = true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800225 fbZ = 0;
226}
227
Saurabh Shahaa236822013-04-24 18:07:26 -0700228void MDPComp::FrameInfo::map() {
229 // populate layer and MDP maps
230 int mdpIdx = 0;
231 for(int idx = 0; idx < layerCount; idx++) {
232 if(!isFBComposed[idx]) {
233 mdpToLayer[mdpIdx].listIndex = idx;
234 layerToMDP[idx] = mdpIdx++;
235 }
236 }
237}
238
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800239MDPComp::LayerCache::LayerCache() {
240 reset();
241}
242
243void MDPComp::LayerCache::reset() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700244 memset(&hnd, 0, sizeof(hnd));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800245 mdpCount = 0;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700246 fbCount = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800247 layerCount = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -0700248 fbZ = -1;
249}
250
251void MDPComp::LayerCache::cacheAll(hwc_display_contents_1_t* list) {
252 const int numAppLayers = list->numHwLayers - 1;
253 for(int i = 0; i < numAppLayers; i++) {
254 hnd[i] = list->hwLayers[i].handle;
255 }
256}
257
258void MDPComp::LayerCache::updateCounts(const FrameInfo& curFrame) {
259 mdpCount = curFrame.mdpCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700260 fbCount = curFrame.fbCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700261 layerCount = curFrame.layerCount;
262 fbZ = curFrame.fbZ;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800263}
264
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700265bool MDPComp::isSupportedForMDPComp(hwc_context_t *ctx, hwc_layer_1_t* layer) {
266 private_handle_t *hnd = (private_handle_t *)layer->handle;
267 if((not isYuvBuffer(hnd) and has90Transform(layer)) or
268 (not isValidDimension(ctx,layer))
269 //More conditions here, SKIP, sRGB+Blend etc
270 ) {
271 return false;
272 }
273 return true;
274}
275
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530276bool MDPComp::isValidDimension(hwc_context_t *ctx, hwc_layer_1_t *layer) {
Saurabh Shah4fdde762013-04-30 18:47:33 -0700277 const int dpy = HWC_DISPLAY_PRIMARY;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800278 private_handle_t *hnd = (private_handle_t *)layer->handle;
279
280 if(!hnd) {
281 ALOGE("%s: layer handle is NULL", __FUNCTION__);
282 return false;
283 }
284
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800285 int hw_w = ctx->dpyAttr[mDpy].xres;
286 int hw_h = ctx->dpyAttr[mDpy].yres;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800287
Saurabh Shah4fdde762013-04-30 18:47:33 -0700288 hwc_rect_t crop = layer->sourceCrop;
289 hwc_rect_t dst = layer->displayFrame;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800290
291 if(dst.left < 0 || dst.top < 0 || dst.right > hw_w || dst.bottom > hw_h) {
Saurabh Shah4fdde762013-04-30 18:47:33 -0700292 hwc_rect_t scissor = {0, 0, hw_w, hw_h };
293 qhwc::calculate_crop_rects(crop, dst, scissor, layer->transform);
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800294 }
295
Saurabh Shah4fdde762013-04-30 18:47:33 -0700296 int crop_w = crop.right - crop.left;
297 int crop_h = crop.bottom - crop.top;
298 int dst_w = dst.right - dst.left;
299 int dst_h = dst.bottom - dst.top;
300 float w_dscale = ceilf((float)crop_w / (float)dst_w);
301 float h_dscale = ceilf((float)crop_h / (float)dst_h);
302
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800303 /* Workaround for MDP HW limitation in DSI command mode panels where
304 * FPS will not go beyond 30 if buffers on RGB pipes are of width or height
305 * less than 5 pixels
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530306 * There also is a HW limilation in MDP, minimum block size is 2x2
307 * Fallback to GPU if height is less than 2.
308 */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800309 if((crop_w < 5)||(crop_h < 5))
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800310 return false;
311
Saurabh Shah4fdde762013-04-30 18:47:33 -0700312 const uint32_t downscale =
313 qdutils::MDPVersion::getInstance().getMaxMDPDownscale();
314 if(ctx->mMDP.version >= qdutils::MDSS_V5) {
315 /* Workaround for downscales larger than 4x.
316 * Will be removed once decimator block is enabled for MDSS
317 */
318 if(!qdutils::MDPVersion::getInstance().supportsDecimation()) {
319 if(crop_w > MAX_DISPLAY_DIM || w_dscale > downscale ||
320 h_dscale > downscale)
321 return false;
322 } else {
323 if(w_dscale > 64 || h_dscale > 64)
324 return false;
325 }
326 } else { //A-family
327 if(w_dscale > downscale || h_dscale > downscale)
328 return false;
329 }
330
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800331 return true;
332}
333
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700334ovutils::eDest MDPComp::getMdpPipe(hwc_context_t *ctx, ePipeType type,
335 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800336 overlay::Overlay& ov = *ctx->mOverlay;
337 ovutils::eDest mdp_pipe = ovutils::OV_INVALID;
338
339 switch(type) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800340 case MDPCOMP_OV_DMA:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700341 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_DMA, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800342 if(mdp_pipe != ovutils::OV_INVALID) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800343 return mdp_pipe;
344 }
345 case MDPCOMP_OV_ANY:
346 case MDPCOMP_OV_RGB:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700347 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800348 if(mdp_pipe != ovutils::OV_INVALID) {
349 return mdp_pipe;
350 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800351
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800352 if(type == MDPCOMP_OV_RGB) {
353 //Requested only for RGB pipe
354 break;
355 }
356 case MDPCOMP_OV_VG:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700357 return ov.nextPipe(ovutils::OV_MDP_PIPE_VG, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800358 default:
359 ALOGE("%s: Invalid pipe type",__FUNCTION__);
360 return ovutils::OV_INVALID;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800361 };
362 return ovutils::OV_INVALID;
363}
364
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800365bool MDPComp::isFrameDoable(hwc_context_t *ctx) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700366 bool ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700367 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800368
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800369 if(!isEnabled()) {
370 ALOGD_IF(isDebug(),"%s: MDP Comp. not enabled.", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700371 ret = false;
Saurabh Shahd4e65852013-06-17 11:33:53 -0700372 } else if(qdutils::MDPVersion::getInstance().is8x26() &&
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700373 ctx->mVideoTransFlag && ctx->mVirtualDisplay->isConnected()) {
Saurabh Shahd4e65852013-06-17 11:33:53 -0700374 //1 Padding round to shift pipes across mixers
375 ALOGD_IF(isDebug(),"%s: MDP Comp. video transition padding round",
376 __FUNCTION__);
377 ret = false;
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700378 } else if(ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isConfiguring ||
379 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isConfiguring) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800380 ALOGD_IF( isDebug(),"%s: External Display connection is pending",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800381 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700382 ret = false;
Saurabh Shahaa236822013-04-24 18:07:26 -0700383 } else if(ctx->isPaddingRound) {
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700384 ctx->isPaddingRound = false;
385 ALOGD_IF(isDebug(), "%s: padding round",__FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700386 ret = false;
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700387 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700388 return ret;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800389}
390
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700391bool MDPComp::validateAndApplyROI(hwc_context_t *ctx,
392 hwc_display_contents_1_t* list, hwc_rect_t roi) {
393 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
394
395 if(!isValidRect(roi))
396 return false;
397
398 for(int i = 0; i < numAppLayers; i++){
399 const hwc_layer_1_t* layer = &list->hwLayers[i];
400
401 hwc_rect_t dstRect = layer->displayFrame;
402 hwc_rect_t srcRect = layer->sourceCrop;
403 int transform = layer->transform;
404 trimLayer(ctx, mDpy, transform, srcRect, dstRect);
405
406 hwc_rect_t res = getIntersection(roi, dstRect);
407
408 int res_w = res.right - res.left;
409 int res_h = res.bottom - res.top;
410 int dst_w = dstRect.right - dstRect.left;
411 int dst_h = dstRect.bottom - dstRect.top;
412
413 if(!isValidRect(res)) {
414 mCurrentFrame.drop[i] = true;
415 mCurrentFrame.dropCount++;
416 }else {
417 /* Reset frame ROI when any layer which needs scaling also needs ROI
418 * cropping */
419 if((res_w != dst_w || res_h != dst_h) &&
420 needsScaling (ctx, layer, mDpy)) {
421 ALOGE("%s: Resetting ROI due to scaling", __FUNCTION__);
422 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
423 mCurrentFrame.dropCount = 0;
424 return false;
425 }
426 }
427 }
428 return true;
429}
430
431void MDPComp::generateROI(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
432 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
433
434 if(!sEnablePartialFrameUpdate) {
435 return;
436 }
437
438 if(mDpy || isDisplaySplit(ctx, mDpy)){
439 ALOGE_IF(isDebug(), "%s: ROI not supported for"
440 "the (1) external / virtual display's (2) dual DSI displays",
441 __FUNCTION__);
442 return;
443 }
444
445 if(list->flags & HWC_GEOMETRY_CHANGED)
446 return;
447
448 struct hwc_rect roi = (struct hwc_rect){0, 0, 0, 0};
449 for(int index = 0; index < numAppLayers; index++ ) {
450 if ((mCachedFrame.hnd[index] != list->hwLayers[index].handle) ||
451 isYuvBuffer((private_handle_t *)list->hwLayers[index].handle)) {
452 hwc_rect_t dstRect = list->hwLayers[index].displayFrame;
453 hwc_rect_t srcRect = list->hwLayers[index].sourceCrop;
454 int transform = list->hwLayers[index].transform;
455
456 /* Intersect against display boundaries */
457 trimLayer(ctx, mDpy, transform, srcRect, dstRect);
458 roi = getUnion(roi, dstRect);
459 }
460 }
461
462 if(!validateAndApplyROI(ctx, list, roi)){
463 roi = (struct hwc_rect) {0, 0,
464 (int)ctx->dpyAttr[mDpy].xres, (int)ctx->dpyAttr[mDpy].yres};
465 }
466
467 ctx->listStats[mDpy].roi.x = roi.left;
468 ctx->listStats[mDpy].roi.y = roi.top;
469 ctx->listStats[mDpy].roi.w = roi.right - roi.left;
470 ctx->listStats[mDpy].roi.h = roi.bottom - roi.top;
471
472 ALOGD_IF(isDebug(),"%s: generated ROI: [%d, %d, %d, %d]", __FUNCTION__,
473 roi.left, roi.top, roi.right, roi.bottom);
474}
475
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800476/* Checks for conditions where all the layers marked for MDP comp cannot be
477 * bypassed. On such conditions we try to bypass atleast YUV layers */
478bool MDPComp::isFullFrameDoable(hwc_context_t *ctx,
479 hwc_display_contents_1_t* list){
480
Saurabh Shahaa236822013-04-24 18:07:26 -0700481 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800482
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -0700483 if(sIdleFallBack && !ctx->listStats[mDpy].secureUI) {
Saurabh Shah2d998a92013-05-14 17:55:58 -0700484 ALOGD_IF(isDebug(), "%s: Idle fallback dpy %d",__FUNCTION__, mDpy);
485 return false;
486 }
487
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800488 if(isSkipPresent(ctx, mDpy)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700489 ALOGD_IF(isDebug(),"%s: SKIP present: %d",
490 __FUNCTION__,
491 isSkipPresent(ctx, mDpy));
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800492 return false;
493 }
494
Saurabh Shah9f084ad2013-05-02 11:28:09 -0700495 if(ctx->listStats[mDpy].needsAlphaScale
496 && ctx->mMDP.version < qdutils::MDSS_V5) {
497 ALOGD_IF(isDebug(), "%s: frame needs alpha downscaling",__FUNCTION__);
498 return false;
499 }
500
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800501 for(int i = 0; i < numAppLayers; ++i) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800502 hwc_layer_1_t* layer = &list->hwLayers[i];
503 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800504
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700505 if(isYuvBuffer(hnd) && has90Transform(layer)) {
506 if(!canUseRotator(ctx, mDpy)) {
507 ALOGD_IF(isDebug(), "%s: Can't use rotator for dpy %d",
508 __FUNCTION__, mDpy);
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700509 return false;
510 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800511 }
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530512
513 //For 8x26 with panel width>1k, if RGB layer needs HFLIP fail mdp comp
514 // may not need it if Gfx pre-rotation can handle all flips & rotations
515 if(qdutils::MDPVersion::getInstance().is8x26() &&
516 (ctx->dpyAttr[mDpy].xres > 1024) &&
517 (layer->transform & HWC_TRANSFORM_FLIP_H) &&
518 (!isYuvBuffer(hnd)))
519 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800520 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700521
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700522 if(ctx->mAD->isDoable()) {
523 return false;
524 }
525
Saurabh Shahaa236822013-04-24 18:07:26 -0700526 //If all above hard conditions are met we can do full or partial MDP comp.
527 bool ret = false;
528 if(fullMDPComp(ctx, list)) {
529 ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700530 } else if(partialMDPComp(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700531 ret = true;
532 }
533 return ret;
534}
535
536bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700537 //Will benefit presentation / secondary-only layer.
538 if((mDpy > HWC_DISPLAY_PRIMARY) &&
539 (list->numHwLayers - 1) > MAX_SEC_LAYERS) {
540 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
541 return false;
542 }
543
544 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
545 for(int i = 0; i < numAppLayers; i++) {
546 hwc_layer_1_t* layer = &list->hwLayers[i];
547 if(not isSupportedForMDPComp(ctx, layer)) {
548 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",__FUNCTION__);
549 return false;
550 }
551 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700552 mCurrentFrame.fbCount = 0;
553 mCurrentFrame.fbZ = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700554 memcpy(&mCurrentFrame.isFBComposed, &mCurrentFrame.drop,
555 sizeof(mCurrentFrame.isFBComposed));
556 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount -
557 mCurrentFrame.dropCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700558
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700559 if(mCurrentFrame.mdpCount > sMaxPipesPerMixer) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700560 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
561 return false;
562 }
563
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700564 if(!arePipesAvailable(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700565 return false;
566 }
567
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700568 uint32_t size = calcMDPBytesRead(ctx, list);
569 if(!bandwidthCheck(ctx, size)) {
570 ALOGD_IF(isDebug(), "%s: Exceeds bandwidth",__FUNCTION__);
571 return false;
572 }
573
Saurabh Shahaa236822013-04-24 18:07:26 -0700574 return true;
575}
576
577bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
578{
579 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700580
581 if(!sEnableMixedMode) {
582 //Mixed mode is disabled. No need to even try caching.
583 return false;
584 }
585
Saurabh Shahaa236822013-04-24 18:07:26 -0700586 //Setup mCurrentFrame
587 mCurrentFrame.reset(numAppLayers);
588 updateLayerCache(ctx, list);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700589
590 //If an MDP marked layer is unsupported cannot do partial MDP Comp
591 for(int i = 0; i < numAppLayers; i++) {
592 if(!mCurrentFrame.isFBComposed[i]) {
593 hwc_layer_1_t* layer = &list->hwLayers[i];
594 if(not isSupportedForMDPComp(ctx, layer)) {
595 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",
596 __FUNCTION__);
597 return false;
598 }
599 }
600 }
601
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700602 updateYUV(ctx, list, false /*secure only*/);
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530603 bool ret = markLayersForCaching(ctx, list); //sets up fbZ also
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700604 if(!ret) {
605 ALOGD_IF(isDebug(),"%s: batching failed, dpy %d",__FUNCTION__, mDpy);
606 return false;
607 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700608
609 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700610
611 //Will benefit cases where a video has non-updating background.
612 if((mDpy > HWC_DISPLAY_PRIMARY) and
613 (mdpCount > MAX_SEC_LAYERS)) {
614 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
615 return false;
616 }
617
Saurabh Shahaa236822013-04-24 18:07:26 -0700618 if(mdpCount > (sMaxPipesPerMixer - 1)) { // -1 since FB is used
619 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
620 return false;
621 }
622
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700623 if(!arePipesAvailable(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700624 return false;
625 }
626
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700627 uint32_t size = calcMDPBytesRead(ctx, list);
628 if(!bandwidthCheck(ctx, size)) {
629 ALOGD_IF(isDebug(), "%s: Exceeds bandwidth",__FUNCTION__);
630 return false;
631 }
632
Saurabh Shahaa236822013-04-24 18:07:26 -0700633 return true;
634}
635
636bool MDPComp::isOnlyVideoDoable(hwc_context_t *ctx,
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700637 hwc_display_contents_1_t* list, bool secureOnly) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700638 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700639
Saurabh Shahaa236822013-04-24 18:07:26 -0700640 mCurrentFrame.reset(numAppLayers);
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700641 updateYUV(ctx, list, secureOnly);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700642 int mdpCount = mCurrentFrame.mdpCount;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700643 int fbNeeded = (mCurrentFrame.fbCount != 0);
Saurabh Shahaa236822013-04-24 18:07:26 -0700644
645 if(!isYuvPresent(ctx, mDpy)) {
646 return false;
647 }
648
Saurabh Shah4fdde762013-04-30 18:47:33 -0700649 if(!mdpCount)
650 return false;
651
Saurabh Shahaa236822013-04-24 18:07:26 -0700652 if(mdpCount > (sMaxPipesPerMixer - fbNeeded)) {
653 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
654 return false;
655 }
656
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700657 if(!arePipesAvailable(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700658 return false;
659 }
660
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700661 uint32_t size = calcMDPBytesRead(ctx, list);
662 if(!bandwidthCheck(ctx, size)) {
663 ALOGD_IF(isDebug(), "%s: Exceeds bandwidth",__FUNCTION__);
664 return false;
665 }
666
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800667 return true;
668}
669
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800670/* Checks for conditions where YUV layers cannot be bypassed */
671bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Saurabh Shahe2474082013-05-15 16:32:13 -0700672 bool extAnimBlockFeature = mDpy && ctx->listStats[mDpy].isDisplayAnimating;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800673
Saurabh Shahe2474082013-05-15 16:32:13 -0700674 if(isSkipLayer(layer) && !extAnimBlockFeature) {
675 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800676 return false;
677 }
678
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700679 if(layer->transform & HWC_TRANSFORM_ROT_90 && !canUseRotator(ctx,mDpy)) {
680 ALOGD_IF(isDebug(), "%s: no free DMA pipe",__FUNCTION__);
681 return false;
682 }
683
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800684 if(isSecuring(ctx, layer)) {
685 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
686 return false;
687 }
688
Saurabh Shah4fdde762013-04-30 18:47:33 -0700689 if(!isValidDimension(ctx, layer)) {
690 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
691 __FUNCTION__);
692 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800693 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700694
Naseer Ahmeddc61a972013-07-10 17:50:54 -0400695 if(layer->planeAlpha < 0xFF) {
696 ALOGD_IF(isDebug(), "%s: Cannot handle YUV layer with plane alpha\
697 in video only mode",
698 __FUNCTION__);
699 return false;
700 }
701
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800702 return true;
703}
704
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530705/* starts at fromIndex and check for each layer to find
706 * if it it has overlapping with any Updating layer above it in zorder
707 * till the end of the batch. returns true if it finds any intersection */
708bool MDPComp::canPushBatchToTop(const hwc_display_contents_1_t* list,
709 int fromIndex, int toIndex) {
710 for(int i = fromIndex; i < toIndex; i++) {
711 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
712 if(intersectingUpdatingLayers(list, i+1, toIndex, i)) {
713 return false;
714 }
715 }
716 }
717 return true;
718}
719
720/* Checks if given layer at targetLayerIndex has any
721 * intersection with all the updating layers in beween
722 * fromIndex and toIndex. Returns true if it finds intersectiion */
723bool MDPComp::intersectingUpdatingLayers(const hwc_display_contents_1_t* list,
724 int fromIndex, int toIndex, int targetLayerIndex) {
725 for(int i = fromIndex; i <= toIndex; i++) {
726 if(!mCurrentFrame.isFBComposed[i]) {
727 if(areLayersIntersecting(&list->hwLayers[i],
728 &list->hwLayers[targetLayerIndex])) {
729 return true;
730 }
731 }
732 }
733 return false;
734}
735
736int MDPComp::getBatch(hwc_display_contents_1_t* list,
737 int& maxBatchStart, int& maxBatchEnd,
738 int& maxBatchCount) {
739 int i = 0;
740 int updatingLayersAbove = 0;//Updating layer count in middle of batch
741 int fbZOrder =-1;
742 while (i < mCurrentFrame.layerCount) {
743 int batchCount = 0;
744 int batchStart = i;
745 int batchEnd = i;
746 int fbZ = batchStart;
747 int firstZReverseIndex = -1;
748 while(i < mCurrentFrame.layerCount) {
749 if(!mCurrentFrame.isFBComposed[i]) {
750 if(!batchCount) {
751 i++;
752 break;
753 }
754 updatingLayersAbove++;
755 i++;
756 continue;
757 } else {
758 if(mCurrentFrame.drop[i]) {
759 i++;
760 continue;
761 } else if(updatingLayersAbove <= 0) {
762 batchCount++;
763 batchEnd = i;
764 i++;
765 continue;
766 } else { //Layer is FBComposed, not a drop & updatingLayer > 0
767
768 // We have a valid updating layer already. If layer-i not
769 // have overlapping with all updating layers in between
770 // batch-start and i, then we can add layer i to batch.
771 if(!intersectingUpdatingLayers(list, batchStart, i-1, i)) {
772 batchCount++;
773 batchEnd = i;
774 i++;
775 continue;
776 } else if(canPushBatchToTop(list, batchStart, i)) {
777 //If All the non-updating layers with in this batch
778 //does not have intersection with the updating layers
779 //above in z-order, then we can safely move the batch to
780 //higher z-order. Increment fbZ as it is moving up.
781 if( firstZReverseIndex < 0) {
782 firstZReverseIndex = i;
783 }
784 batchCount++;
785 batchEnd = i;
786 fbZ += updatingLayersAbove;
787 i++;
788 updatingLayersAbove = 0;
789 continue;
790 } else {
791 //both failed.start the loop again from here.
792 if(firstZReverseIndex >= 0) {
793 i = firstZReverseIndex;
794 }
795 break;
796 }
797 }
798 }
799 }
800 if(batchCount > maxBatchCount) {
801 maxBatchCount = batchCount;
802 maxBatchStart = batchStart;
803 maxBatchEnd = batchEnd;
804 fbZOrder = fbZ;
805 }
806 }
807 return fbZOrder;
808}
809
810bool MDPComp::markLayersForCaching(hwc_context_t* ctx,
811 hwc_display_contents_1_t* list) {
812 /* Idea is to keep as many non-updating(cached) layers in FB and
813 * send rest of them through MDP. This is done in 2 steps.
814 * 1. Find the maximum contiguous batch of non-updating layers.
815 * 2. See if we can improve this batch size for caching by adding
816 * opaque layers around the batch, if they don't have
817 * any overlapping with the updating layers in between.
818 * NEVER mark an updating layer for caching.
819 * But cached ones can be marked for MDP */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800820
821 int maxBatchStart = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700822 int maxBatchEnd = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800823 int maxBatchCount = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530824 int fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800825
826 /* All or Nothing is cached. No batching needed */
Saurabh Shahaa236822013-04-24 18:07:26 -0700827 if(!mCurrentFrame.fbCount) {
828 mCurrentFrame.fbZ = -1;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700829 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -0700830 }
831 if(!mCurrentFrame.mdpCount) {
832 mCurrentFrame.fbZ = 0;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700833 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -0700834 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800835
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530836 fbZ = getBatch(list, maxBatchStart, maxBatchEnd, maxBatchCount);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800837
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530838 /* reset rest of the layers lying inside ROI for MDP comp */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800839 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700840 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700841 if((i < maxBatchStart || i > maxBatchEnd) &&
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530842 mCurrentFrame.isFBComposed[i]){
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700843 if(!mCurrentFrame.drop[i]){
844 //If an unsupported layer is being attempted to
845 //be pulled out we should fail
846 if(not isSupportedForMDPComp(ctx, layer)) {
847 return false;
848 }
849 mCurrentFrame.isFBComposed[i] = false;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700850 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800851 }
852 }
853
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530854 // update the frame data
855 mCurrentFrame.fbZ = fbZ;
856 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700857 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700858 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800859
860 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530861 mCurrentFrame.fbCount);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700862
863 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800864}
Saurabh Shah85234ec2013-04-12 17:09:00 -0700865
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800866void MDPComp::updateLayerCache(hwc_context_t* ctx,
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700867 hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800868 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700869 int fbCount = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800870
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800871 for(int i = 0; i < numAppLayers; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700872 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800873 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700874 if(!mCurrentFrame.drop[i])
875 fbCount++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800876 mCurrentFrame.isFBComposed[i] = true;
877 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -0700878 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800879 mCachedFrame.hnd[i] = list->hwLayers[i].handle;
880 }
881 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700882
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700883 mCurrentFrame.fbCount = fbCount;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700884 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount
885 - mCurrentFrame.dropCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700886
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700887 ALOGD_IF(isDebug(),"%s: MDP count: %d FB count %d drop count: %d"
888 ,__FUNCTION__, mCurrentFrame.mdpCount, mCurrentFrame.fbCount,
889 mCurrentFrame.dropCount);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800890}
891
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700892void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list,
893 bool secureOnly) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800894 int nYuvCount = ctx->listStats[mDpy].yuvCount;
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700895 if(!nYuvCount && mDpy) {
896 //Reset "No animation on external display" related parameters.
897 ctx->mPrevCropVideo.left = ctx->mPrevCropVideo.top =
898 ctx->mPrevCropVideo.right = ctx->mPrevCropVideo.bottom = 0;
899 ctx->mPrevDestVideo.left = ctx->mPrevDestVideo.top =
900 ctx->mPrevDestVideo.right = ctx->mPrevDestVideo.bottom = 0;
901 ctx->mPrevTransformVideo = 0;
902 return;
903 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800904 for(int index = 0;index < nYuvCount; index++){
905 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
906 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
907
908 if(!isYUVDoable(ctx, layer)) {
909 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
910 mCurrentFrame.isFBComposed[nYuvIndex] = true;
911 mCurrentFrame.fbCount++;
912 }
913 } else {
914 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700915 private_handle_t *hnd = (private_handle_t *)layer->handle;
916 if(!secureOnly || isSecureBuffer(hnd)) {
917 mCurrentFrame.isFBComposed[nYuvIndex] = false;
918 mCurrentFrame.fbCount--;
919 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800920 }
921 }
922 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700923
924 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700925 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
926 ALOGD_IF(isDebug(),"%s: fb count: %d",__FUNCTION__,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800927 mCurrentFrame.fbCount);
928}
929
Saurabh Shahaa236822013-04-24 18:07:26 -0700930bool MDPComp::programMDP(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800931 if(!allocLayerPipes(ctx, list)) {
932 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700933 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800934 }
935
936 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700937 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800938 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800939 int mdpIndex = mCurrentFrame.layerToMDP[index];
940 hwc_layer_1_t* layer = &list->hwLayers[index];
941
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530942 //Leave fbZ for framebuffer. CACHE/GLES layers go here.
943 if(mdpNextZOrder == mCurrentFrame.fbZ) {
944 mdpNextZOrder++;
945 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800946 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
947 cur_pipe->zOrder = mdpNextZOrder++;
948
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530949
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800950 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
951 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
952 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -0700953 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800954 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700955 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800956 }
957
Saurabh Shahaa236822013-04-24 18:07:26 -0700958 return true;
959}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800960
Saurabh Shahaa236822013-04-24 18:07:26 -0700961bool MDPComp::programYUV(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
962 if(!allocLayerPipes(ctx, list)) {
963 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
964 return false;
965 }
966 //If we are in this block, it means we have yuv + rgb layers both
967 int mdpIdx = 0;
968 for (int index = 0; index < mCurrentFrame.layerCount; index++) {
969 if(!mCurrentFrame.isFBComposed[index]) {
970 hwc_layer_1_t* layer = &list->hwLayers[index];
971 int mdpIndex = mCurrentFrame.layerToMDP[index];
972 MdpPipeInfo* cur_pipe =
973 mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
974 cur_pipe->zOrder = mdpIdx++;
975
976 if(configure(ctx, layer,
977 mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
978 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
979 layer %d",__FUNCTION__, index);
980 return false;
981 }
982 }
983 }
984 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800985}
986
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700987uint32_t MDPComp::calcMDPBytesRead(hwc_context_t *ctx,
988 hwc_display_contents_1_t* list) {
989 uint32_t size = 0;
990
Terence Hampson9cd5fa92013-09-10 17:06:37 -0400991 if(!qdutils::MDPVersion::getInstance().is8x74v2())
992 return 0;
993
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700994 for (uint32_t i = 0; i < list->numHwLayers - 1; i++) {
995 if(!mCurrentFrame.isFBComposed[i]) {
996 hwc_layer_1_t* layer = &list->hwLayers[i];
997 private_handle_t *hnd = (private_handle_t *)layer->handle;
Terence Hampson9cd5fa92013-09-10 17:06:37 -0400998 if (hnd) {
999 hwc_rect_t crop = layer->sourceCrop;
Saurabh Shah90789162013-09-16 10:29:20 -07001000 hwc_rect_t dst = layer->displayFrame;
1001 trimLayer(ctx, mDpy, layer->transform, crop, dst);
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001002 float bpp = ((float)hnd->size) / (hnd->width * hnd->height);
Saurabh Shah90789162013-09-16 10:29:20 -07001003 size += bpp * (crop.right - crop.left) *
1004 (crop.bottom - crop.top) *
1005 ctx->dpyAttr[mDpy].yres / (dst.bottom - dst.top);
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001006 }
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001007 }
1008 }
1009
1010 if(mCurrentFrame.fbCount) {
1011 hwc_layer_1_t* layer = &list->hwLayers[list->numHwLayers - 1];
1012 private_handle_t *hnd = (private_handle_t *)layer->handle;
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001013 if (hnd)
1014 size += hnd->size;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001015 }
1016
1017 return size;
1018}
1019
1020bool MDPComp::bandwidthCheck(hwc_context_t *ctx, const uint32_t& size) {
1021 //Will be added for other targets if we run into bandwidth issues and when
1022 //we have profiling data to set an upper limit.
1023 if(qdutils::MDPVersion::getInstance().is8x74v2()) {
1024 const uint32_t ONE_GIG = 1024 * 1024 * 1024;
1025 double panelRefRate =
1026 1000000000.0 / ctx->dpyAttr[mDpy].vsync_period;
1027 if((size + sCompBytesClaimed) > ((sMaxBw / panelRefRate) * ONE_GIG)) {
1028 return false;
1029 }
1030 }
1031 return true;
1032}
1033
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001034int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001035 int ret = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -07001036 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -07001037
Saurabh Shahb39f8152013-08-22 10:21:44 -07001038 //reset old data
1039 mCurrentFrame.reset(numLayers);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001040 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1041 mCurrentFrame.dropCount = 0;
Prabhanjan Kandula088bd892013-07-02 23:47:13 +05301042
Saurabh Shahb39f8152013-08-22 10:21:44 -07001043 //number of app layers exceeds MAX_NUM_APP_LAYERS fall back to GPU
1044 //do not cache the information for next draw cycle.
1045 if(numLayers > MAX_NUM_APP_LAYERS) {
Prabhanjan Kandula25469a52013-07-12 16:19:31 +05301046 mCachedFrame.updateCounts(mCurrentFrame);
Tatenda Chipeperekwa835337a2013-09-27 16:58:43 -07001047 ALOGE("%s: Number of App layers exceeded the limit ",
1048 __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001049 ret = -1;
Tatenda Chipeperekwa835337a2013-09-27 16:58:43 -07001050 return ret;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001051 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001052
Saurabh Shahb39f8152013-08-22 10:21:44 -07001053 //Hard conditions, if not met, cannot do MDP comp
1054 if(!isFrameDoable(ctx)) {
1055 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
1056 __FUNCTION__);
1057 reset(numLayers, list);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001058 ret = -1;
1059 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001060 }
1061
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001062 generateROI(ctx, list);
1063
Saurabh Shahb39f8152013-08-22 10:21:44 -07001064 //Check whether layers marked for MDP Composition is actually doable.
1065 if(isFullFrameDoable(ctx, list)) {
1066 mCurrentFrame.map();
1067 //Configure framebuffer first if applicable
1068 if(mCurrentFrame.fbZ >= 0) {
1069 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list,
1070 mCurrentFrame.fbZ)) {
1071 ALOGE("%s configure framebuffer failed", __func__);
1072 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -07001073 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001074 ret = -1;
1075 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001076 }
1077 }
1078 //Acquire and Program MDP pipes
1079 if(!programMDP(ctx, list)) {
1080 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -07001081 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001082 ret = -1;
1083 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001084 } else { //Success
1085 //Any change in composition types needs an FB refresh
1086 mCurrentFrame.needsRedraw = false;
1087 if(mCurrentFrame.fbCount &&
1088 ((mCurrentFrame.mdpCount != mCachedFrame.mdpCount) ||
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001089 (mCurrentFrame.fbCount != mCachedFrame.fbCount) ||
Saurabh Shahb39f8152013-08-22 10:21:44 -07001090 (mCurrentFrame.fbZ != mCachedFrame.fbZ) ||
1091 (!mCurrentFrame.mdpCount) ||
1092 (list->flags & HWC_GEOMETRY_CHANGED) ||
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001093 isSkipPresent(ctx, mDpy))) {
Saurabh Shahb39f8152013-08-22 10:21:44 -07001094 mCurrentFrame.needsRedraw = true;
1095 }
1096 }
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001097 } else if(isOnlyVideoDoable(ctx, list, false /*secure only*/) ||
1098 isOnlyVideoDoable(ctx, list, true /*secure only*/)) {
Saurabh Shahb39f8152013-08-22 10:21:44 -07001099 //All layers marked for MDP comp cannot be bypassed.
1100 //Try to compose atleast YUV layers through MDP comp and let
1101 //all the RGB layers compose in FB
1102 //Destination over
1103 mCurrentFrame.fbZ = -1;
1104 if(mCurrentFrame.fbCount)
1105 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
1106
1107 mCurrentFrame.map();
1108
1109 //Configure framebuffer first if applicable
1110 if(mCurrentFrame.fbZ >= 0) {
1111 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, mCurrentFrame.fbZ)) {
1112 ALOGE("%s configure framebuffer failed", __func__);
1113 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -07001114 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001115 ret = -1;
1116 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001117 }
1118 }
1119 if(!programYUV(ctx, list)) {
1120 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -07001121 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001122 ret = -1;
1123 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001124 }
1125 } else {
1126 reset(numLayers, list);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001127 ret = -1;
1128 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001129 }
1130
1131 //UpdateLayerFlags
1132 setMDPCompLayerFlags(ctx, list);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001133 mCachedFrame.cacheAll(list);
Saurabh Shahb39f8152013-08-22 10:21:44 -07001134 mCachedFrame.updateCounts(mCurrentFrame);
1135
Prabhanjan Kandula25469a52013-07-12 16:19:31 +05301136 // unlock it before calling dump function to avoid deadlock
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001137 if(isDebug()) {
Saurabh Shahaa236822013-04-24 18:07:26 -07001138 ALOGD("GEOMETRY change: %d", (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001139 android::String8 sDump("");
1140 dump(sDump);
1141 ALOGE("%s",sDump.string());
1142 }
1143
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001144exit:
1145 sCompBytesClaimed += calcMDPBytesRead(ctx, list);
1146 return ret;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001147}
1148
Saurabh Shah88e4d272013-09-03 13:31:29 -07001149//=============MDPCompNonSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001150
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001151/*
1152 * Configures pipe(s) for MDP composition
1153 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001154int MDPCompNonSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001155 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001156 MdpPipeInfoNonSplit& mdp_info =
1157 *(static_cast<MdpPipeInfoNonSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001158 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
1159 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1160 eIsFg isFg = IS_FG_OFF;
1161 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001162
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001163 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
1164 __FUNCTION__, layer, zOrder, dest);
1165
Saurabh Shah88e4d272013-09-03 13:31:29 -07001166 return configureNonSplit(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001167 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001168}
1169
Saurabh Shah88e4d272013-09-03 13:31:29 -07001170bool MDPCompNonSplit::arePipesAvailable(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001171 hwc_display_contents_1_t* list) {
1172 overlay::Overlay& ov = *ctx->mOverlay;
1173 int numPipesNeeded = mCurrentFrame.mdpCount;
1174 int availPipes = ov.availablePipes(mDpy, Overlay::MIXER_DEFAULT);
1175
1176 //Reserve pipe for FB
1177 if(mCurrentFrame.fbCount)
1178 availPipes -= 1;
1179
1180 if(numPipesNeeded > availPipes) {
1181 ALOGD_IF(isDebug(), "%s: Insufficient pipes, dpy %d needed %d, avail %d",
1182 __FUNCTION__, mDpy, numPipesNeeded, availPipes);
1183 return false;
1184 }
1185
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001186 if(not areVGPipesAvailable(ctx, list)) {
1187 return false;
1188 }
1189
1190 return true;
1191}
1192
1193bool MDPCompNonSplit::areVGPipesAvailable(hwc_context_t *ctx,
1194 hwc_display_contents_1_t* list) {
1195 overlay::Overlay& ov = *ctx->mOverlay;
1196 int pipesNeeded = 0;
1197 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1198 if(!mCurrentFrame.isFBComposed[i]) {
1199 hwc_layer_1_t* layer = &list->hwLayers[i];
1200 hwc_rect_t dst = layer->displayFrame;
1201 private_handle_t *hnd = (private_handle_t *)layer->handle;
1202 if(isYuvBuffer(hnd)) {
1203 pipesNeeded++;
1204 }
1205 }
1206 }
1207
1208 int availableVGPipes = ov.availablePipes(mDpy, ovutils::OV_MDP_PIPE_VG);
1209 if(pipesNeeded > availableVGPipes) {
1210 ALOGD_IF(isDebug(), "%s: Insufficient VG pipes for video layers"
1211 "dpy %d needed %d, avail %d",
1212 __FUNCTION__, mDpy, pipesNeeded, availableVGPipes);
1213 return false;
1214 }
1215
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001216 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001217}
1218
Saurabh Shah88e4d272013-09-03 13:31:29 -07001219bool MDPCompNonSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001220 hwc_display_contents_1_t* list) {
1221 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001222
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001223 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001224
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001225 hwc_layer_1_t* layer = &list->hwLayers[index];
1226 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001227 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001228 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001229 info.pipeInfo = new MdpPipeInfoNonSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08001230 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001231 MdpPipeInfoNonSplit& pipe_info = *(MdpPipeInfoNonSplit*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001232 ePipeType type = MDPCOMP_OV_ANY;
1233
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001234 if(isYuvBuffer(hnd)) {
1235 type = MDPCOMP_OV_VG;
Saurabh Shah8a117932013-05-23 12:48:13 -07001236 } else if(!qhwc::needsScaling(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001237 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
1238 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001239 type = MDPCOMP_OV_DMA;
1240 }
1241
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001242 pipe_info.index = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001243 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001244 ALOGD_IF(isDebug(), "%s: Unable to get pipe type = %d",
1245 __FUNCTION__, (int) type);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001246 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001247 }
1248 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001249 return true;
1250}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001251
Saurabh Shah88e4d272013-09-03 13:31:29 -07001252bool MDPCompNonSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001253
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001254 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001255 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1256 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -08001257 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001258
1259 if(!ctx || !list) {
1260 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001261 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001262 }
1263
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301264 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1265 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1266 return true;
1267 }
1268
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001269 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001270 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001271 idleInvalidator->markForSleep();
1272
1273 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001274 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001275
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001276 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1277 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001278 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001279 if(mCurrentFrame.isFBComposed[i]) continue;
1280
Naseer Ahmed5b6708a2012-08-02 13:46:08 -07001281 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001282 private_handle_t *hnd = (private_handle_t *)layer->handle;
1283 if(!hnd) {
1284 ALOGE("%s handle null", __FUNCTION__);
1285 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001286 }
1287
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001288 int mdpIndex = mCurrentFrame.layerToMDP[i];
1289
Saurabh Shah88e4d272013-09-03 13:31:29 -07001290 MdpPipeInfoNonSplit& pipe_info =
1291 *(MdpPipeInfoNonSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001292 ovutils::eDest dest = pipe_info.index;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001293 if(dest == ovutils::OV_INVALID) {
1294 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001295 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001296 }
1297
Saurabh Shahacf10202013-02-26 10:15:15 -08001298 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1299 continue;
1300 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001301
Saurabh Shahacf10202013-02-26 10:15:15 -08001302 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001303 using pipe: %d", __FUNCTION__, layer,
1304 hnd, dest );
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001305
Saurabh Shahacf10202013-02-26 10:15:15 -08001306 int fd = hnd->fd;
1307 uint32_t offset = hnd->offset;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001308
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001309 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -08001310 if(rot) {
1311 if(!rot->queueBuffer(fd, offset))
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001312 return false;
Saurabh Shahacf10202013-02-26 10:15:15 -08001313 fd = rot->getDstMemId();
1314 offset = rot->getDstOffset();
1315 }
1316
1317 if (!ov.queueBuffer(fd, offset, dest)) {
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301318 ALOGE("%s: queueBuffer failed for display:%d ", __FUNCTION__, mDpy);
Saurabh Shahacf10202013-02-26 10:15:15 -08001319 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001320 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001321
1322 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001323 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001324 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001325}
1326
Saurabh Shah88e4d272013-09-03 13:31:29 -07001327//=============MDPCompSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001328
Saurabh Shah88e4d272013-09-03 13:31:29 -07001329int MDPCompSplit::pipesNeeded(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001330 hwc_display_contents_1_t* list,
1331 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001332 int pipesNeeded = 0;
Saurabh Shah67a38c32013-06-10 16:23:15 -07001333 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001334
1335 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001336
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001337 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1338 if(!mCurrentFrame.isFBComposed[i]) {
1339 hwc_layer_1_t* layer = &list->hwLayers[i];
1340 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001341 if(mixer == Overlay::MIXER_LEFT && dst.left < lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001342 pipesNeeded++;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001343 } else if(mixer == Overlay::MIXER_RIGHT && dst.right > lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001344 pipesNeeded++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001345 }
1346 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001347 }
1348 return pipesNeeded;
1349}
1350
Saurabh Shah88e4d272013-09-03 13:31:29 -07001351bool MDPCompSplit::arePipesAvailable(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001352 hwc_display_contents_1_t* list) {
1353 overlay::Overlay& ov = *ctx->mOverlay;
Saurabh Shah082468e2013-09-12 10:05:32 -07001354 int totalPipesNeeded = 0;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001355
1356 for(int i = 0; i < Overlay::MIXER_MAX; i++) {
1357 int numPipesNeeded = pipesNeeded(ctx, list, i);
1358 int availPipes = ov.availablePipes(mDpy, i);
1359
1360 //Reserve pipe(s)for FB
1361 if(mCurrentFrame.fbCount)
Saurabh Shah082468e2013-09-12 10:05:32 -07001362 numPipesNeeded += 1;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001363
Saurabh Shah082468e2013-09-12 10:05:32 -07001364 totalPipesNeeded += numPipesNeeded;
1365
1366 //Per mixer check.
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001367 if(numPipesNeeded > availPipes) {
1368 ALOGD_IF(isDebug(), "%s: Insufficient pipes for "
1369 "dpy %d mixer %d needed %d, avail %d",
1370 __FUNCTION__, mDpy, i, numPipesNeeded, availPipes);
1371 return false;
1372 }
1373 }
Saurabh Shah082468e2013-09-12 10:05:32 -07001374
1375 //Per display check, since unused pipes can get counted twice.
1376 int totalPipesAvailable = ov.availablePipes(mDpy);
1377 if(totalPipesNeeded > totalPipesAvailable) {
1378 ALOGD_IF(isDebug(), "%s: Insufficient pipes for "
1379 "dpy %d needed %d, avail %d",
1380 __FUNCTION__, mDpy, totalPipesNeeded, totalPipesAvailable);
1381 return false;
1382 }
1383
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001384 if(not areVGPipesAvailable(ctx, list)) {
1385 return false;
1386 }
1387
1388 return true;
1389}
1390
1391bool MDPCompSplit::areVGPipesAvailable(hwc_context_t *ctx,
1392 hwc_display_contents_1_t* list) {
1393 overlay::Overlay& ov = *ctx->mOverlay;
1394 int pipesNeeded = 0;
1395 const int lSplit = getLeftSplit(ctx, mDpy);
1396 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1397 if(!mCurrentFrame.isFBComposed[i]) {
1398 hwc_layer_1_t* layer = &list->hwLayers[i];
1399 hwc_rect_t dst = layer->displayFrame;
1400 private_handle_t *hnd = (private_handle_t *)layer->handle;
1401 if(isYuvBuffer(hnd)) {
1402 if(dst.left < lSplit) {
1403 pipesNeeded++;
1404 }
1405 if(dst.right > lSplit) {
1406 pipesNeeded++;
1407 }
1408 }
1409 }
1410 }
1411
1412 int availableVGPipes = ov.availablePipes(mDpy, ovutils::OV_MDP_PIPE_VG);
1413 if(pipesNeeded > availableVGPipes) {
1414 ALOGD_IF(isDebug(), "%s: Insufficient VG pipes for video layers"
1415 "dpy %d needed %d, avail %d",
1416 __FUNCTION__, mDpy, pipesNeeded, availableVGPipes);
1417 return false;
1418 }
1419
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001420 return true;
1421}
1422
Saurabh Shah88e4d272013-09-03 13:31:29 -07001423bool MDPCompSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
1424 MdpPipeInfoSplit& pipe_info,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001425 ePipeType type) {
1426 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001427 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001428
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001429 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001430 pipe_info.lIndex = ovutils::OV_INVALID;
1431 pipe_info.rIndex = ovutils::OV_INVALID;
1432
1433 if (dst.left < lSplit) {
1434 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_LEFT);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001435 if(pipe_info.lIndex == ovutils::OV_INVALID)
1436 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001437 }
1438
1439 if(dst.right > lSplit) {
1440 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_RIGHT);
1441 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001442 return false;
1443 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001444
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001445 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001446}
1447
Saurabh Shah88e4d272013-09-03 13:31:29 -07001448bool MDPCompSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001449 hwc_display_contents_1_t* list) {
1450 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001451
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001452 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001453
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001454 hwc_layer_1_t* layer = &list->hwLayers[index];
1455 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001456 int mdpIndex = mCurrentFrame.layerToMDP[index];
1457 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001458 info.pipeInfo = new MdpPipeInfoSplit;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001459 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001460 MdpPipeInfoSplit& pipe_info = *(MdpPipeInfoSplit*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001461 ePipeType type = MDPCOMP_OV_ANY;
1462
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001463 if(isYuvBuffer(hnd)) {
1464 type = MDPCOMP_OV_VG;
Sushil Chauhan15a2ea62013-09-04 18:28:36 -07001465 } else if(!qhwc::needsScalingWithSplit(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001466 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001467 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001468 type = MDPCOMP_OV_DMA;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001469 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001470
1471 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001472 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type = %d",
1473 __FUNCTION__, (int) type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001474 return false;
1475 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001476 }
1477 return true;
1478}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001479
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001480/*
1481 * Configures pipe(s) for MDP composition
1482 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001483int MDPCompSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001484 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001485 MdpPipeInfoSplit& mdp_info =
1486 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001487 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1488 eIsFg isFg = IS_FG_OFF;
1489 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1490 eDest lDest = mdp_info.lIndex;
1491 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001492
1493 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1494 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1495
Saurabh Shah88e4d272013-09-03 13:31:29 -07001496 return configureSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001497 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001498}
1499
Saurabh Shah88e4d272013-09-03 13:31:29 -07001500bool MDPCompSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001501
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001502 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001503 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1504 return true;
1505 }
1506
1507 if(!ctx || !list) {
1508 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001509 return false;
1510 }
1511
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301512 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1513 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1514 return true;
1515 }
1516
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001517 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001518 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001519 idleInvalidator->markForSleep();
1520
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001521 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001522 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001523
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001524 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1525 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001526 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001527 if(mCurrentFrame.isFBComposed[i]) continue;
1528
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001529 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001530 private_handle_t *hnd = (private_handle_t *)layer->handle;
1531 if(!hnd) {
1532 ALOGE("%s handle null", __FUNCTION__);
1533 return false;
1534 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001535
1536 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1537 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001538 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001539
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001540 int mdpIndex = mCurrentFrame.layerToMDP[i];
1541
Saurabh Shah88e4d272013-09-03 13:31:29 -07001542 MdpPipeInfoSplit& pipe_info =
1543 *(MdpPipeInfoSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001544 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -08001545
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001546 ovutils::eDest indexL = pipe_info.lIndex;
1547 ovutils::eDest indexR = pipe_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001548
Saurabh Shahacf10202013-02-26 10:15:15 -08001549 int fd = hnd->fd;
1550 int offset = hnd->offset;
1551
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001552 if(ctx->mAD->isModeOn()) {
1553 if(ctx->mAD->draw(ctx, fd, offset)) {
1554 fd = ctx->mAD->getDstFd(ctx);
1555 offset = ctx->mAD->getDstOffset(ctx);
1556 }
1557 }
1558
Saurabh Shahacf10202013-02-26 10:15:15 -08001559 if(rot) {
1560 rot->queueBuffer(fd, offset);
1561 fd = rot->getDstMemId();
1562 offset = rot->getDstOffset();
1563 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001564
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001565 //************* play left mixer **********
1566 if(indexL != ovutils::OV_INVALID) {
1567 ovutils::eDest destL = (ovutils::eDest)indexL;
Saurabh Shahacf10202013-02-26 10:15:15 -08001568 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001569 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
Saurabh Shahacf10202013-02-26 10:15:15 -08001570 if (!ov.queueBuffer(fd, offset, destL)) {
1571 ALOGE("%s: queueBuffer failed for left mixer", __FUNCTION__);
1572 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001573 }
1574 }
1575
1576 //************* play right mixer **********
1577 if(indexR != ovutils::OV_INVALID) {
1578 ovutils::eDest destR = (ovutils::eDest)indexR;
Saurabh Shahacf10202013-02-26 10:15:15 -08001579 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001580 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
Saurabh Shahacf10202013-02-26 10:15:15 -08001581 if (!ov.queueBuffer(fd, offset, destR)) {
1582 ALOGE("%s: queueBuffer failed for right mixer", __FUNCTION__);
1583 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001584 }
1585 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001586
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001587 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1588 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001589
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001590 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001591}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001592}; //namespace
1593