blob: 2a1b1232d80caf1c8349b23717280dd335f7c2db [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;
Saurabh Shah3c1a6b02013-11-22 11:10:20 -080047double MDPComp::sBwClaimed = 0.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));
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530245 memset(&isFBComposed, true, sizeof(isFBComposed));
246 memset(&drop, false, sizeof(drop));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800247 layerCount = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -0700248}
249
250void MDPComp::LayerCache::cacheAll(hwc_display_contents_1_t* list) {
251 const int numAppLayers = list->numHwLayers - 1;
252 for(int i = 0; i < numAppLayers; i++) {
253 hnd[i] = list->hwLayers[i].handle;
254 }
255}
256
257void MDPComp::LayerCache::updateCounts(const FrameInfo& curFrame) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700258 layerCount = curFrame.layerCount;
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530259 memcpy(&isFBComposed, &curFrame.isFBComposed, sizeof(isFBComposed));
260 memcpy(&drop, &curFrame.drop, sizeof(drop));
261}
262
Jeykumar Sankaran988d3682013-11-15 11:57:16 -0800263bool MDPComp::LayerCache::isSameFrame(const FrameInfo& curFrame,
264 hwc_display_contents_1_t* list) {
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530265 if(layerCount != curFrame.layerCount)
266 return false;
267 for(int i = 0; i < curFrame.layerCount; i++) {
268 if((curFrame.isFBComposed[i] != isFBComposed[i]) ||
269 (curFrame.drop[i] != drop[i])) {
270 return false;
271 }
Jeykumar Sankaran988d3682013-11-15 11:57:16 -0800272 if(curFrame.isFBComposed[i] &&
273 (hnd[i] != list->hwLayers[i].handle)){
274 return false;
275 }
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +0530276 }
277 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800278}
279
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700280bool MDPComp::isSupportedForMDPComp(hwc_context_t *ctx, hwc_layer_1_t* layer) {
281 private_handle_t *hnd = (private_handle_t *)layer->handle;
282 if((not isYuvBuffer(hnd) and has90Transform(layer)) or
283 (not isValidDimension(ctx,layer))
284 //More conditions here, SKIP, sRGB+Blend etc
285 ) {
286 return false;
287 }
288 return true;
289}
290
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530291bool MDPComp::isValidDimension(hwc_context_t *ctx, hwc_layer_1_t *layer) {
Saurabh Shah4fdde762013-04-30 18:47:33 -0700292 const int dpy = HWC_DISPLAY_PRIMARY;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800293 private_handle_t *hnd = (private_handle_t *)layer->handle;
294
295 if(!hnd) {
296 ALOGE("%s: layer handle is NULL", __FUNCTION__);
297 return false;
298 }
299
Naseer Ahmede850a802013-09-06 13:12:52 -0400300 //XXX: Investigate doing this with pixel phase on MDSS
Naseer Ahmede77f8082013-10-10 13:42:48 -0400301 if(!isSecureBuffer(hnd) && isNonIntegralSourceCrop(layer->sourceCropf))
Naseer Ahmede850a802013-09-06 13:12:52 -0400302 return false;
303
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800304 int hw_w = ctx->dpyAttr[mDpy].xres;
305 int hw_h = ctx->dpyAttr[mDpy].yres;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800306
Saurabh Shah62e1d732013-09-17 10:44:05 -0700307 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700308 hwc_rect_t dst = layer->displayFrame;
Saurabh Shah4fdde762013-04-30 18:47:33 -0700309 int crop_w = crop.right - crop.left;
310 int crop_h = crop.bottom - crop.top;
311 int dst_w = dst.right - dst.left;
312 int dst_h = dst.bottom - dst.top;
313 float w_dscale = ceilf((float)crop_w / (float)dst_w);
314 float h_dscale = ceilf((float)crop_h / (float)dst_h);
315
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800316 /* Workaround for MDP HW limitation in DSI command mode panels where
317 * FPS will not go beyond 30 if buffers on RGB pipes are of width or height
318 * less than 5 pixels
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530319 * There also is a HW limilation in MDP, minimum block size is 2x2
320 * Fallback to GPU if height is less than 2.
321 */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800322 if((crop_w < 5)||(crop_h < 5))
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800323 return false;
324
Saurabh Shah4fdde762013-04-30 18:47:33 -0700325 const uint32_t downscale =
326 qdutils::MDPVersion::getInstance().getMaxMDPDownscale();
327 if(ctx->mMDP.version >= qdutils::MDSS_V5) {
328 /* Workaround for downscales larger than 4x.
329 * Will be removed once decimator block is enabled for MDSS
330 */
331 if(!qdutils::MDPVersion::getInstance().supportsDecimation()) {
332 if(crop_w > MAX_DISPLAY_DIM || w_dscale > downscale ||
333 h_dscale > downscale)
334 return false;
335 } else {
336 if(w_dscale > 64 || h_dscale > 64)
337 return false;
338 }
339 } else { //A-family
340 if(w_dscale > downscale || h_dscale > downscale)
341 return false;
342 }
343
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800344 return true;
345}
346
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700347ovutils::eDest MDPComp::getMdpPipe(hwc_context_t *ctx, ePipeType type,
348 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800349 overlay::Overlay& ov = *ctx->mOverlay;
350 ovutils::eDest mdp_pipe = ovutils::OV_INVALID;
351
352 switch(type) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800353 case MDPCOMP_OV_DMA:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700354 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_DMA, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800355 if(mdp_pipe != ovutils::OV_INVALID) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800356 return mdp_pipe;
357 }
358 case MDPCOMP_OV_ANY:
359 case MDPCOMP_OV_RGB:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700360 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800361 if(mdp_pipe != ovutils::OV_INVALID) {
362 return mdp_pipe;
363 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800364
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800365 if(type == MDPCOMP_OV_RGB) {
366 //Requested only for RGB pipe
367 break;
368 }
369 case MDPCOMP_OV_VG:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700370 return ov.nextPipe(ovutils::OV_MDP_PIPE_VG, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800371 default:
372 ALOGE("%s: Invalid pipe type",__FUNCTION__);
373 return ovutils::OV_INVALID;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800374 };
375 return ovutils::OV_INVALID;
376}
377
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800378bool MDPComp::isFrameDoable(hwc_context_t *ctx) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700379 bool ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700380 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800381
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800382 if(!isEnabled()) {
383 ALOGD_IF(isDebug(),"%s: MDP Comp. not enabled.", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700384 ret = false;
Saurabh Shahd4e65852013-06-17 11:33:53 -0700385 } else if(qdutils::MDPVersion::getInstance().is8x26() &&
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700386 ctx->mVideoTransFlag && ctx->mVirtualDisplay->isConnected()) {
Saurabh Shahd4e65852013-06-17 11:33:53 -0700387 //1 Padding round to shift pipes across mixers
388 ALOGD_IF(isDebug(),"%s: MDP Comp. video transition padding round",
389 __FUNCTION__);
390 ret = false;
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700391 } else if(ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isConfiguring ||
392 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isConfiguring) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800393 ALOGD_IF( isDebug(),"%s: External Display connection is pending",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800394 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700395 ret = false;
Saurabh Shahaa236822013-04-24 18:07:26 -0700396 } else if(ctx->isPaddingRound) {
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700397 ctx->isPaddingRound = false;
398 ALOGD_IF(isDebug(), "%s: padding round",__FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700399 ret = false;
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700400 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700401 return ret;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800402}
403
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800404/*
405 * 1) Identify layers that are not visible in the updating ROI and drop them
406 * from composition.
407 * 2) If we have a scaling layers which needs cropping against generated ROI.
408 * Reset ROI to full resolution.
409 */
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700410bool MDPComp::validateAndApplyROI(hwc_context_t *ctx,
411 hwc_display_contents_1_t* list, hwc_rect_t roi) {
412 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
413
414 if(!isValidRect(roi))
415 return false;
416
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800417 hwc_rect_t visibleRect = roi;
418
419 for(int i = numAppLayers - 1; i >= 0; i--){
420
421 if(!isValidRect(visibleRect)) {
422 mCurrentFrame.drop[i] = true;
423 mCurrentFrame.dropCount++;
424 }
425
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700426 const hwc_layer_1_t* layer = &list->hwLayers[i];
427
428 hwc_rect_t dstRect = layer->displayFrame;
Arun Kumar K.R91090c72013-10-28 19:40:18 -0700429 hwc_rect_t srcRect = integerizeSourceCrop(layer->sourceCropf);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700430 int transform = layer->transform;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700431
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800432 hwc_rect_t res = getIntersection(visibleRect, dstRect);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700433
434 int res_w = res.right - res.left;
435 int res_h = res.bottom - res.top;
436 int dst_w = dstRect.right - dstRect.left;
437 int dst_h = dstRect.bottom - dstRect.top;
438
439 if(!isValidRect(res)) {
440 mCurrentFrame.drop[i] = true;
441 mCurrentFrame.dropCount++;
442 }else {
443 /* Reset frame ROI when any layer which needs scaling also needs ROI
444 * cropping */
445 if((res_w != dst_w || res_h != dst_h) &&
446 needsScaling (ctx, layer, mDpy)) {
Arpita Banerjeed8965982013-11-08 17:27:33 -0800447 ALOGI("%s: Resetting ROI due to scaling", __FUNCTION__);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700448 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
449 mCurrentFrame.dropCount = 0;
450 return false;
451 }
452 }
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800453
454 if (layer->blending == HWC_BLENDING_NONE)
455 visibleRect = deductRect(visibleRect, res);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700456 }
457 return true;
458}
459
460void MDPComp::generateROI(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
461 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
462
463 if(!sEnablePartialFrameUpdate) {
464 return;
465 }
466
467 if(mDpy || isDisplaySplit(ctx, mDpy)){
468 ALOGE_IF(isDebug(), "%s: ROI not supported for"
469 "the (1) external / virtual display's (2) dual DSI displays",
470 __FUNCTION__);
471 return;
472 }
473
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -0800474 if(isSkipPresent(ctx, mDpy))
475 return;
476
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700477 if(list->flags & HWC_GEOMETRY_CHANGED)
478 return;
479
480 struct hwc_rect roi = (struct hwc_rect){0, 0, 0, 0};
481 for(int index = 0; index < numAppLayers; index++ ) {
482 if ((mCachedFrame.hnd[index] != list->hwLayers[index].handle) ||
483 isYuvBuffer((private_handle_t *)list->hwLayers[index].handle)) {
484 hwc_rect_t dstRect = list->hwLayers[index].displayFrame;
Arun Kumar K.R91090c72013-10-28 19:40:18 -0700485 hwc_rect_t srcRect = integerizeSourceCrop(
486 list->hwLayers[index].sourceCropf);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700487 int transform = list->hwLayers[index].transform;
488
489 /* Intersect against display boundaries */
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700490 roi = getUnion(roi, dstRect);
491 }
492 }
493
494 if(!validateAndApplyROI(ctx, list, roi)){
495 roi = (struct hwc_rect) {0, 0,
496 (int)ctx->dpyAttr[mDpy].xres, (int)ctx->dpyAttr[mDpy].yres};
497 }
498
499 ctx->listStats[mDpy].roi.x = roi.left;
500 ctx->listStats[mDpy].roi.y = roi.top;
501 ctx->listStats[mDpy].roi.w = roi.right - roi.left;
502 ctx->listStats[mDpy].roi.h = roi.bottom - roi.top;
503
504 ALOGD_IF(isDebug(),"%s: generated ROI: [%d, %d, %d, %d]", __FUNCTION__,
505 roi.left, roi.top, roi.right, roi.bottom);
506}
507
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800508/* Checks for conditions where all the layers marked for MDP comp cannot be
509 * bypassed. On such conditions we try to bypass atleast YUV layers */
510bool MDPComp::isFullFrameDoable(hwc_context_t *ctx,
511 hwc_display_contents_1_t* list){
512
Saurabh Shahaa236822013-04-24 18:07:26 -0700513 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800514
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -0700515 if(sIdleFallBack && !ctx->listStats[mDpy].secureUI) {
Saurabh Shah2d998a92013-05-14 17:55:58 -0700516 ALOGD_IF(isDebug(), "%s: Idle fallback dpy %d",__FUNCTION__, mDpy);
517 return false;
518 }
519
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800520 if(isSkipPresent(ctx, mDpy)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700521 ALOGD_IF(isDebug(),"%s: SKIP present: %d",
522 __FUNCTION__,
523 isSkipPresent(ctx, mDpy));
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800524 return false;
525 }
526
Saurabh Shah9f084ad2013-05-02 11:28:09 -0700527 if(ctx->listStats[mDpy].needsAlphaScale
528 && ctx->mMDP.version < qdutils::MDSS_V5) {
529 ALOGD_IF(isDebug(), "%s: frame needs alpha downscaling",__FUNCTION__);
530 return false;
531 }
532
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800533 for(int i = 0; i < numAppLayers; ++i) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800534 hwc_layer_1_t* layer = &list->hwLayers[i];
535 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800536
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700537 if(isYuvBuffer(hnd) && has90Transform(layer)) {
538 if(!canUseRotator(ctx, mDpy)) {
539 ALOGD_IF(isDebug(), "%s: Can't use rotator for dpy %d",
540 __FUNCTION__, mDpy);
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700541 return false;
542 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800543 }
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530544
545 //For 8x26 with panel width>1k, if RGB layer needs HFLIP fail mdp comp
546 // may not need it if Gfx pre-rotation can handle all flips & rotations
547 if(qdutils::MDPVersion::getInstance().is8x26() &&
548 (ctx->dpyAttr[mDpy].xres > 1024) &&
549 (layer->transform & HWC_TRANSFORM_FLIP_H) &&
550 (!isYuvBuffer(hnd)))
551 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800552 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700553
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700554 if(ctx->mAD->isDoable()) {
555 return false;
556 }
557
Saurabh Shahaa236822013-04-24 18:07:26 -0700558 //If all above hard conditions are met we can do full or partial MDP comp.
559 bool ret = false;
560 if(fullMDPComp(ctx, list)) {
561 ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700562 } else if(partialMDPComp(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700563 ret = true;
564 }
565 return ret;
566}
567
568bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700569 //Will benefit presentation / secondary-only layer.
570 if((mDpy > HWC_DISPLAY_PRIMARY) &&
571 (list->numHwLayers - 1) > MAX_SEC_LAYERS) {
572 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
573 return false;
574 }
575
576 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
577 for(int i = 0; i < numAppLayers; i++) {
578 hwc_layer_1_t* layer = &list->hwLayers[i];
579 if(not isSupportedForMDPComp(ctx, layer)) {
580 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",__FUNCTION__);
581 return false;
582 }
583 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700584 mCurrentFrame.fbCount = 0;
585 mCurrentFrame.fbZ = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700586 memcpy(&mCurrentFrame.isFBComposed, &mCurrentFrame.drop,
587 sizeof(mCurrentFrame.isFBComposed));
588 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount -
589 mCurrentFrame.dropCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700590
Saurabh Shah173f4242013-11-20 09:50:12 -0800591 if(!resourceCheck(ctx, list)) {
592 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700593 return false;
594 }
595
Saurabh Shahaa236822013-04-24 18:07:26 -0700596 return true;
597}
598
599bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
600{
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700601 if(!sEnableMixedMode) {
602 //Mixed mode is disabled. No need to even try caching.
603 return false;
604 }
605
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700606 bool ret = false;
607 if(isLoadBasedCompDoable(ctx, list)) {
Saurabh Shahb772ae32013-11-18 15:40:02 -0800608 ret = loadBasedCompPreferGPU(ctx, list) ||
609 loadBasedCompPreferMDP(ctx, list);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700610 }
611
612 if(!ret) {
613 ret = cacheBasedComp(ctx, list);
614 }
615
616 return ret;
617}
618
619bool MDPComp::cacheBasedComp(hwc_context_t *ctx,
620 hwc_display_contents_1_t* list) {
621 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700622 mCurrentFrame.reset(numAppLayers);
623 updateLayerCache(ctx, list);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700624
625 //If an MDP marked layer is unsupported cannot do partial MDP Comp
626 for(int i = 0; i < numAppLayers; i++) {
627 if(!mCurrentFrame.isFBComposed[i]) {
628 hwc_layer_1_t* layer = &list->hwLayers[i];
629 if(not isSupportedForMDPComp(ctx, layer)) {
630 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",
631 __FUNCTION__);
632 return false;
633 }
634 }
635 }
636
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700637 updateYUV(ctx, list, false /*secure only*/);
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530638 bool ret = markLayersForCaching(ctx, list); //sets up fbZ also
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700639 if(!ret) {
640 ALOGD_IF(isDebug(),"%s: batching failed, dpy %d",__FUNCTION__, mDpy);
641 return false;
642 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700643
644 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700645
646 //Will benefit cases where a video has non-updating background.
647 if((mDpy > HWC_DISPLAY_PRIMARY) and
648 (mdpCount > MAX_SEC_LAYERS)) {
649 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
650 return false;
651 }
652
Saurabh Shah173f4242013-11-20 09:50:12 -0800653 if(!resourceCheck(ctx, list)) {
654 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700655 return false;
656 }
657
Saurabh Shahaa236822013-04-24 18:07:26 -0700658 return true;
659}
660
Saurabh Shahb772ae32013-11-18 15:40:02 -0800661bool MDPComp::loadBasedCompPreferGPU(hwc_context_t *ctx,
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700662 hwc_display_contents_1_t* list) {
663 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
664 mCurrentFrame.reset(numAppLayers);
665
Saurabh Shahb772ae32013-11-18 15:40:02 -0800666 int stagesForMDP = min(sMaxPipesPerMixer, ctx->mOverlay->availablePipes(
667 mDpy, Overlay::MIXER_DEFAULT));
668 //If MDP has X possible stages, it can take X layers.
669 const int batchSize = numAppLayers - (stagesForMDP - 1); //1 for FB
670
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700671 if(batchSize <= 0) {
672 ALOGD_IF(isDebug(), "%s: Not attempting", __FUNCTION__);
673 return false;
674 }
675
676 int minBatchStart = -1;
677 size_t minBatchPixelCount = SIZE_MAX;
678
679 for(int i = 0; i <= numAppLayers - batchSize; i++) {
680 uint32_t batchPixelCount = 0;
681 for(int j = i; j < i + batchSize; j++) {
682 hwc_layer_1_t* layer = &list->hwLayers[j];
Arun Kumar K.R91090c72013-10-28 19:40:18 -0700683 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700684 batchPixelCount += (crop.right - crop.left) *
685 (crop.bottom - crop.top);
686 }
687
688 if(batchPixelCount < minBatchPixelCount) {
689 minBatchPixelCount = batchPixelCount;
690 minBatchStart = i;
691 }
692 }
693
694 if(minBatchStart < 0) {
695 ALOGD_IF(isDebug(), "%s: No batch found batchSize %d numAppLayers %d",
696 __FUNCTION__, batchSize, numAppLayers);
697 return false;
698 }
699
700 for(int i = 0; i < numAppLayers; i++) {
701 if(i < minBatchStart || i >= minBatchStart + batchSize) {
702 hwc_layer_1_t* layer = &list->hwLayers[i];
703 if(not isSupportedForMDPComp(ctx, layer)) {
704 ALOGD_IF(isDebug(), "%s: MDP unsupported layer found at %d",
705 __FUNCTION__, i);
706 return false;
707 }
708 mCurrentFrame.isFBComposed[i] = false;
709 }
710 }
711
712 mCurrentFrame.fbZ = minBatchStart;
713 mCurrentFrame.fbCount = batchSize;
714 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - batchSize;
715
Saurabh Shah173f4242013-11-20 09:50:12 -0800716 if(!resourceCheck(ctx, list)) {
717 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700718 return false;
719 }
720
721 ALOGD_IF(isDebug(), "%s: fbZ %d batchSize %d",
722 __FUNCTION__, mCurrentFrame.fbZ, batchSize);
723 return true;
724}
725
Saurabh Shahb772ae32013-11-18 15:40:02 -0800726bool MDPComp::loadBasedCompPreferMDP(hwc_context_t *ctx,
727 hwc_display_contents_1_t* list) {
728 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
729 //TODO get the ib from sysfs node.
730 //Full screen is from ib perspective, not actual full screen
731 const int bpp = 4;
732 double panelRefRate =
733 1000000000.0 / ctx->dpyAttr[mDpy].vsync_period;
734
735 double bwLeft = sMaxBw - sBwClaimed;
736
737 const int fullScreenLayers = bwLeft * 1000000000 / (ctx->dpyAttr[mDpy].xres
738 * ctx->dpyAttr[mDpy].yres * bpp * panelRefRate);
739
740 const int fbBatchSize = numAppLayers - (fullScreenLayers - 1);
741 //If batch size is not at least 2, we aren't really preferring MDP, since
742 //only 1 layer going to GPU could actually translate into an entire FB
743 //needed to be fetched by MDP, thus needing more b/w rather than less.
744 if(fbBatchSize < 2 || fbBatchSize > numAppLayers) {
745 ALOGD_IF(isDebug(), "%s: Not attempting", __FUNCTION__);
746 return false;
747 }
748
749 //Top-most layers constitute FB batch
750 const int fbBatchStart = numAppLayers - fbBatchSize;
751
752 //Bottom-most layers constitute MDP batch
753 for(int i = 0; i < fbBatchStart; i++) {
754 hwc_layer_1_t* layer = &list->hwLayers[i];
755 if(not isSupportedForMDPComp(ctx, layer)) {
756 ALOGD_IF(isDebug(), "%s: MDP unsupported layer found at %d",
757 __FUNCTION__, i);
758 return false;
759 }
760 mCurrentFrame.isFBComposed[i] = false;
761 }
762
763 mCurrentFrame.fbZ = fbBatchStart;
764 mCurrentFrame.fbCount = fbBatchSize;
765 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - fbBatchSize;
766
767 if(!resourceCheck(ctx, list)) {
768 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
769 return false;
770 }
771
772 ALOGD_IF(isDebug(), "%s: FB Z %d, num app layers %d, MDP Batch Size %d",
773 __FUNCTION__, mCurrentFrame.fbZ, numAppLayers,
774 numAppLayers - fbBatchSize);
775
776 return true;
777}
778
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700779bool MDPComp::isLoadBasedCompDoable(hwc_context_t *ctx,
780 hwc_display_contents_1_t* list) {
781 if(mDpy or isSecurePresent(ctx, mDpy) or
782 not (list->flags & HWC_GEOMETRY_CHANGED)) {
783 return false;
784 }
785 return true;
786}
787
Saurabh Shahaa236822013-04-24 18:07:26 -0700788bool MDPComp::isOnlyVideoDoable(hwc_context_t *ctx,
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700789 hwc_display_contents_1_t* list, bool secureOnly) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700790 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700791
Saurabh Shahaa236822013-04-24 18:07:26 -0700792 mCurrentFrame.reset(numAppLayers);
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700793 updateYUV(ctx, list, secureOnly);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700794 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700795
796 if(!isYuvPresent(ctx, mDpy)) {
797 return false;
798 }
799
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -0800800 /* Bail out if we are processing only secured video layers
801 * and we dont have any */
802 if(!isSecurePresent(ctx, mDpy) && secureOnly){
803 return false;
804 }
805
Saurabh Shah4fdde762013-04-30 18:47:33 -0700806 if(!mdpCount)
807 return false;
808
Saurabh Shah173f4242013-11-20 09:50:12 -0800809 if(!resourceCheck(ctx, list)) {
810 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700811 return false;
812 }
813
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800814 return true;
815}
816
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800817/* Checks for conditions where YUV layers cannot be bypassed */
818bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Saurabh Shahe2474082013-05-15 16:32:13 -0700819 bool extAnimBlockFeature = mDpy && ctx->listStats[mDpy].isDisplayAnimating;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800820
Saurabh Shahe2474082013-05-15 16:32:13 -0700821 if(isSkipLayer(layer) && !extAnimBlockFeature) {
822 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800823 return false;
824 }
825
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700826 if(layer->transform & HWC_TRANSFORM_ROT_90 && !canUseRotator(ctx,mDpy)) {
827 ALOGD_IF(isDebug(), "%s: no free DMA pipe",__FUNCTION__);
828 return false;
829 }
830
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800831 if(isSecuring(ctx, layer)) {
832 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
833 return false;
834 }
835
Saurabh Shah4fdde762013-04-30 18:47:33 -0700836 if(!isValidDimension(ctx, layer)) {
837 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
838 __FUNCTION__);
839 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800840 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700841
Naseer Ahmeddc61a972013-07-10 17:50:54 -0400842 if(layer->planeAlpha < 0xFF) {
843 ALOGD_IF(isDebug(), "%s: Cannot handle YUV layer with plane alpha\
844 in video only mode",
845 __FUNCTION__);
846 return false;
847 }
848
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800849 return true;
850}
851
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530852/* starts at fromIndex and check for each layer to find
853 * if it it has overlapping with any Updating layer above it in zorder
854 * till the end of the batch. returns true if it finds any intersection */
855bool MDPComp::canPushBatchToTop(const hwc_display_contents_1_t* list,
856 int fromIndex, int toIndex) {
857 for(int i = fromIndex; i < toIndex; i++) {
858 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
859 if(intersectingUpdatingLayers(list, i+1, toIndex, i)) {
860 return false;
861 }
862 }
863 }
864 return true;
865}
866
867/* Checks if given layer at targetLayerIndex has any
868 * intersection with all the updating layers in beween
869 * fromIndex and toIndex. Returns true if it finds intersectiion */
870bool MDPComp::intersectingUpdatingLayers(const hwc_display_contents_1_t* list,
871 int fromIndex, int toIndex, int targetLayerIndex) {
872 for(int i = fromIndex; i <= toIndex; i++) {
873 if(!mCurrentFrame.isFBComposed[i]) {
874 if(areLayersIntersecting(&list->hwLayers[i],
875 &list->hwLayers[targetLayerIndex])) {
876 return true;
877 }
878 }
879 }
880 return false;
881}
882
883int MDPComp::getBatch(hwc_display_contents_1_t* list,
884 int& maxBatchStart, int& maxBatchEnd,
885 int& maxBatchCount) {
886 int i = 0;
887 int updatingLayersAbove = 0;//Updating layer count in middle of batch
888 int fbZOrder =-1;
889 while (i < mCurrentFrame.layerCount) {
890 int batchCount = 0;
891 int batchStart = i;
892 int batchEnd = i;
893 int fbZ = batchStart;
894 int firstZReverseIndex = -1;
895 while(i < mCurrentFrame.layerCount) {
896 if(!mCurrentFrame.isFBComposed[i]) {
897 if(!batchCount) {
898 i++;
899 break;
900 }
901 updatingLayersAbove++;
902 i++;
903 continue;
904 } else {
905 if(mCurrentFrame.drop[i]) {
906 i++;
907 continue;
908 } else if(updatingLayersAbove <= 0) {
909 batchCount++;
910 batchEnd = i;
911 i++;
912 continue;
913 } else { //Layer is FBComposed, not a drop & updatingLayer > 0
914
915 // We have a valid updating layer already. If layer-i not
916 // have overlapping with all updating layers in between
917 // batch-start and i, then we can add layer i to batch.
918 if(!intersectingUpdatingLayers(list, batchStart, i-1, i)) {
919 batchCount++;
920 batchEnd = i;
921 i++;
922 continue;
923 } else if(canPushBatchToTop(list, batchStart, i)) {
924 //If All the non-updating layers with in this batch
925 //does not have intersection with the updating layers
926 //above in z-order, then we can safely move the batch to
927 //higher z-order. Increment fbZ as it is moving up.
928 if( firstZReverseIndex < 0) {
929 firstZReverseIndex = i;
930 }
931 batchCount++;
932 batchEnd = i;
933 fbZ += updatingLayersAbove;
934 i++;
935 updatingLayersAbove = 0;
936 continue;
937 } else {
938 //both failed.start the loop again from here.
939 if(firstZReverseIndex >= 0) {
940 i = firstZReverseIndex;
941 }
942 break;
943 }
944 }
945 }
946 }
947 if(batchCount > maxBatchCount) {
948 maxBatchCount = batchCount;
949 maxBatchStart = batchStart;
950 maxBatchEnd = batchEnd;
951 fbZOrder = fbZ;
952 }
953 }
954 return fbZOrder;
955}
956
957bool MDPComp::markLayersForCaching(hwc_context_t* ctx,
958 hwc_display_contents_1_t* list) {
959 /* Idea is to keep as many non-updating(cached) layers in FB and
960 * send rest of them through MDP. This is done in 2 steps.
961 * 1. Find the maximum contiguous batch of non-updating layers.
962 * 2. See if we can improve this batch size for caching by adding
963 * opaque layers around the batch, if they don't have
964 * any overlapping with the updating layers in between.
965 * NEVER mark an updating layer for caching.
966 * But cached ones can be marked for MDP */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800967
968 int maxBatchStart = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700969 int maxBatchEnd = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800970 int maxBatchCount = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530971 int fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800972
973 /* All or Nothing is cached. No batching needed */
Saurabh Shahaa236822013-04-24 18:07:26 -0700974 if(!mCurrentFrame.fbCount) {
975 mCurrentFrame.fbZ = -1;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700976 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -0700977 }
978 if(!mCurrentFrame.mdpCount) {
979 mCurrentFrame.fbZ = 0;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700980 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -0700981 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800982
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530983 fbZ = getBatch(list, maxBatchStart, maxBatchEnd, maxBatchCount);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800984
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530985 /* reset rest of the layers lying inside ROI for MDP comp */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800986 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700987 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700988 if((i < maxBatchStart || i > maxBatchEnd) &&
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530989 mCurrentFrame.isFBComposed[i]){
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700990 if(!mCurrentFrame.drop[i]){
991 //If an unsupported layer is being attempted to
992 //be pulled out we should fail
993 if(not isSupportedForMDPComp(ctx, layer)) {
994 return false;
995 }
996 mCurrentFrame.isFBComposed[i] = false;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700997 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800998 }
999 }
1000
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301001 // update the frame data
1002 mCurrentFrame.fbZ = fbZ;
1003 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001004 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001005 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001006
1007 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301008 mCurrentFrame.fbCount);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001009
1010 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001011}
Saurabh Shah85234ec2013-04-12 17:09:00 -07001012
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001013void MDPComp::updateLayerCache(hwc_context_t* ctx,
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001014 hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001015 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001016 int fbCount = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001017
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001018 for(int i = 0; i < numAppLayers; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001019 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001020 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001021 if(!mCurrentFrame.drop[i])
1022 fbCount++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001023 mCurrentFrame.isFBComposed[i] = true;
1024 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -07001025 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001026 }
1027 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001028
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001029 mCurrentFrame.fbCount = fbCount;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001030 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount
1031 - mCurrentFrame.dropCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -07001032
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001033 ALOGD_IF(isDebug(),"%s: MDP count: %d FB count %d drop count: %d"
1034 ,__FUNCTION__, mCurrentFrame.mdpCount, mCurrentFrame.fbCount,
1035 mCurrentFrame.dropCount);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001036}
1037
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001038void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list,
1039 bool secureOnly) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001040 int nYuvCount = ctx->listStats[mDpy].yuvCount;
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001041 if(!nYuvCount && mDpy) {
1042 //Reset "No animation on external display" related parameters.
1043 ctx->mPrevCropVideo.left = ctx->mPrevCropVideo.top =
1044 ctx->mPrevCropVideo.right = ctx->mPrevCropVideo.bottom = 0;
1045 ctx->mPrevDestVideo.left = ctx->mPrevDestVideo.top =
1046 ctx->mPrevDestVideo.right = ctx->mPrevDestVideo.bottom = 0;
1047 ctx->mPrevTransformVideo = 0;
1048 return;
1049 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001050 for(int index = 0;index < nYuvCount; index++){
1051 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
1052 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
1053
1054 if(!isYUVDoable(ctx, layer)) {
1055 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
1056 mCurrentFrame.isFBComposed[nYuvIndex] = true;
1057 mCurrentFrame.fbCount++;
1058 }
1059 } else {
1060 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001061 private_handle_t *hnd = (private_handle_t *)layer->handle;
1062 if(!secureOnly || isSecureBuffer(hnd)) {
1063 mCurrentFrame.isFBComposed[nYuvIndex] = false;
1064 mCurrentFrame.fbCount--;
1065 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001066 }
1067 }
1068 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001069
1070 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001071 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
1072 ALOGD_IF(isDebug(),"%s: fb count: %d",__FUNCTION__,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001073 mCurrentFrame.fbCount);
1074}
1075
Saurabh Shahaa236822013-04-24 18:07:26 -07001076bool MDPComp::programMDP(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001077 if(!allocLayerPipes(ctx, list)) {
1078 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -07001079 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001080 }
1081
1082 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001083 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001084 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001085 int mdpIndex = mCurrentFrame.layerToMDP[index];
1086 hwc_layer_1_t* layer = &list->hwLayers[index];
1087
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301088 //Leave fbZ for framebuffer. CACHE/GLES layers go here.
1089 if(mdpNextZOrder == mCurrentFrame.fbZ) {
1090 mdpNextZOrder++;
1091 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001092 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1093 cur_pipe->zOrder = mdpNextZOrder++;
1094
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301095
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001096 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
1097 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
1098 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -07001099 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001100 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001101 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001102 }
1103
Saurabh Shahaa236822013-04-24 18:07:26 -07001104 return true;
1105}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001106
Saurabh Shahaa236822013-04-24 18:07:26 -07001107bool MDPComp::programYUV(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
1108 if(!allocLayerPipes(ctx, list)) {
1109 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
1110 return false;
1111 }
1112 //If we are in this block, it means we have yuv + rgb layers both
1113 int mdpIdx = 0;
1114 for (int index = 0; index < mCurrentFrame.layerCount; index++) {
1115 if(!mCurrentFrame.isFBComposed[index]) {
1116 hwc_layer_1_t* layer = &list->hwLayers[index];
1117 int mdpIndex = mCurrentFrame.layerToMDP[index];
1118 MdpPipeInfo* cur_pipe =
1119 mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1120 cur_pipe->zOrder = mdpIdx++;
1121
1122 if(configure(ctx, layer,
1123 mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
1124 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
1125 layer %d",__FUNCTION__, index);
1126 return false;
1127 }
1128 }
1129 }
1130 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001131}
1132
Saurabh Shah173f4242013-11-20 09:50:12 -08001133bool MDPComp::resourceCheck(hwc_context_t *ctx,
1134 hwc_display_contents_1_t *list) {
1135 const bool fbUsed = mCurrentFrame.fbCount;
1136 if(mCurrentFrame.mdpCount > sMaxPipesPerMixer - fbUsed) {
1137 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
1138 return false;
1139 }
1140
1141 if(!arePipesAvailable(ctx, list)) {
1142 return false;
1143 }
1144
1145 uint32_t size = calcMDPBytesRead(ctx, list);
1146 if(!bandwidthCheck(ctx, size)) {
1147 ALOGD_IF(isDebug(), "%s: Exceeds bandwidth",__FUNCTION__);
1148 return false;
1149 }
1150
1151 return true;
1152}
1153
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001154uint32_t MDPComp::calcMDPBytesRead(hwc_context_t *ctx,
1155 hwc_display_contents_1_t* list) {
1156 uint32_t size = 0;
1157
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001158 if(!qdutils::MDPVersion::getInstance().is8x74v2())
1159 return 0;
1160
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001161 for (uint32_t i = 0; i < list->numHwLayers - 1; i++) {
1162 if(!mCurrentFrame.isFBComposed[i]) {
1163 hwc_layer_1_t* layer = &list->hwLayers[i];
1164 private_handle_t *hnd = (private_handle_t *)layer->handle;
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001165 if (hnd) {
Saurabh Shah62e1d732013-09-17 10:44:05 -07001166 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah90789162013-09-16 10:29:20 -07001167 hwc_rect_t dst = layer->displayFrame;
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001168 float bpp = ((float)hnd->size) / (hnd->width * hnd->height);
Saurabh Shah90789162013-09-16 10:29:20 -07001169 size += bpp * (crop.right - crop.left) *
1170 (crop.bottom - crop.top) *
1171 ctx->dpyAttr[mDpy].yres / (dst.bottom - dst.top);
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001172 }
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001173 }
1174 }
1175
1176 if(mCurrentFrame.fbCount) {
1177 hwc_layer_1_t* layer = &list->hwLayers[list->numHwLayers - 1];
1178 private_handle_t *hnd = (private_handle_t *)layer->handle;
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001179 if (hnd)
1180 size += hnd->size;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001181 }
1182
1183 return size;
1184}
1185
1186bool MDPComp::bandwidthCheck(hwc_context_t *ctx, const uint32_t& size) {
1187 //Will be added for other targets if we run into bandwidth issues and when
1188 //we have profiling data to set an upper limit.
1189 if(qdutils::MDPVersion::getInstance().is8x74v2()) {
Saurabh Shah3c1a6b02013-11-22 11:10:20 -08001190 const uint32_t ONE_GIG = 1000 * 1000 * 1000;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001191 double panelRefRate =
1192 1000000000.0 / ctx->dpyAttr[mDpy].vsync_period;
Saurabh Shah3c1a6b02013-11-22 11:10:20 -08001193 if((size * panelRefRate) > ((sMaxBw - sBwClaimed) * ONE_GIG)) {
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001194 return false;
1195 }
1196 }
1197 return true;
1198}
1199
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001200int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001201 int ret = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -07001202 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -07001203
Saurabh Shahb39f8152013-08-22 10:21:44 -07001204 //reset old data
1205 mCurrentFrame.reset(numLayers);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001206 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1207 mCurrentFrame.dropCount = 0;
Prabhanjan Kandula088bd892013-07-02 23:47:13 +05301208
Saurabh Shahb39f8152013-08-22 10:21:44 -07001209 //number of app layers exceeds MAX_NUM_APP_LAYERS fall back to GPU
1210 //do not cache the information for next draw cycle.
1211 if(numLayers > MAX_NUM_APP_LAYERS) {
Prabhanjan Kandula25469a52013-07-12 16:19:31 +05301212 mCachedFrame.updateCounts(mCurrentFrame);
Arpita Banerjeed8965982013-11-08 17:27:33 -08001213 ALOGI("%s: Number of App layers exceeded the limit ",
Tatenda Chipeperekwa835337a2013-09-27 16:58:43 -07001214 __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001215 ret = -1;
Tatenda Chipeperekwa835337a2013-09-27 16:58:43 -07001216 return ret;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001217 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001218
Saurabh Shahb39f8152013-08-22 10:21:44 -07001219 //Hard conditions, if not met, cannot do MDP comp
1220 if(!isFrameDoable(ctx)) {
1221 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
1222 __FUNCTION__);
1223 reset(numLayers, list);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001224 ret = -1;
1225 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001226 }
1227
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001228 generateROI(ctx, list);
1229
Saurabh Shahb39f8152013-08-22 10:21:44 -07001230 //Check whether layers marked for MDP Composition is actually doable.
1231 if(isFullFrameDoable(ctx, list)) {
1232 mCurrentFrame.map();
1233 //Configure framebuffer first if applicable
1234 if(mCurrentFrame.fbZ >= 0) {
1235 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list,
1236 mCurrentFrame.fbZ)) {
1237 ALOGE("%s configure framebuffer failed", __func__);
1238 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -07001239 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001240 ret = -1;
1241 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001242 }
1243 }
1244 //Acquire and Program MDP pipes
1245 if(!programMDP(ctx, list)) {
1246 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -07001247 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001248 ret = -1;
1249 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001250 } else { //Success
1251 //Any change in composition types needs an FB refresh
1252 mCurrentFrame.needsRedraw = false;
Jeykumar Sankaran988d3682013-11-15 11:57:16 -08001253 if(!mCachedFrame.isSameFrame(mCurrentFrame, list) ||
Saurabh Shahb39f8152013-08-22 10:21:44 -07001254 (list->flags & HWC_GEOMETRY_CHANGED) ||
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +05301255 isSkipPresent(ctx, mDpy)) {
Saurabh Shahb39f8152013-08-22 10:21:44 -07001256 mCurrentFrame.needsRedraw = true;
1257 }
1258 }
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001259 } else if(isOnlyVideoDoable(ctx, list, false /*secure only*/) ||
1260 isOnlyVideoDoable(ctx, list, true /*secure only*/)) {
Saurabh Shahb39f8152013-08-22 10:21:44 -07001261 //All layers marked for MDP comp cannot be bypassed.
1262 //Try to compose atleast YUV layers through MDP comp and let
1263 //all the RGB layers compose in FB
1264 //Destination over
1265 mCurrentFrame.fbZ = -1;
1266 if(mCurrentFrame.fbCount)
1267 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
1268
1269 mCurrentFrame.map();
1270
1271 //Configure framebuffer first if applicable
1272 if(mCurrentFrame.fbZ >= 0) {
1273 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, mCurrentFrame.fbZ)) {
1274 ALOGE("%s configure framebuffer failed", __func__);
1275 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -07001276 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001277 ret = -1;
1278 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001279 }
1280 }
1281 if(!programYUV(ctx, list)) {
1282 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -07001283 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001284 ret = -1;
1285 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001286 }
1287 } else {
1288 reset(numLayers, list);
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -08001289 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1290 mCurrentFrame.dropCount = 0;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001291 ret = -1;
1292 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001293 }
Saurabh Shahb39f8152013-08-22 10:21:44 -07001294 //UpdateLayerFlags
1295 setMDPCompLayerFlags(ctx, list);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001296 mCachedFrame.cacheAll(list);
Saurabh Shahb39f8152013-08-22 10:21:44 -07001297 mCachedFrame.updateCounts(mCurrentFrame);
1298
Prabhanjan Kandula25469a52013-07-12 16:19:31 +05301299 // unlock it before calling dump function to avoid deadlock
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001300 if(isDebug()) {
Saurabh Shahaa236822013-04-24 18:07:26 -07001301 ALOGD("GEOMETRY change: %d", (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001302 android::String8 sDump("");
1303 dump(sDump);
1304 ALOGE("%s",sDump.string());
1305 }
1306
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001307exit:
Saurabh Shah3c1a6b02013-11-22 11:10:20 -08001308 //gbps (bytes / nanosec = gigabytes / sec)
1309 sBwClaimed += calcMDPBytesRead(ctx, list) /
1310 (double)ctx->dpyAttr[mDpy].vsync_period;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001311 return ret;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001312}
1313
Saurabh Shah88e4d272013-09-03 13:31:29 -07001314//=============MDPCompNonSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001315
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001316/*
1317 * Configures pipe(s) for MDP composition
1318 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001319int MDPCompNonSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001320 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001321 MdpPipeInfoNonSplit& mdp_info =
1322 *(static_cast<MdpPipeInfoNonSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001323 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
1324 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1325 eIsFg isFg = IS_FG_OFF;
1326 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001327
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001328 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
1329 __FUNCTION__, layer, zOrder, dest);
1330
Saurabh Shah88e4d272013-09-03 13:31:29 -07001331 return configureNonSplit(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001332 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001333}
1334
Saurabh Shah88e4d272013-09-03 13:31:29 -07001335bool MDPCompNonSplit::arePipesAvailable(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001336 hwc_display_contents_1_t* list) {
1337 overlay::Overlay& ov = *ctx->mOverlay;
1338 int numPipesNeeded = mCurrentFrame.mdpCount;
1339 int availPipes = ov.availablePipes(mDpy, Overlay::MIXER_DEFAULT);
1340
1341 //Reserve pipe for FB
1342 if(mCurrentFrame.fbCount)
1343 availPipes -= 1;
1344
1345 if(numPipesNeeded > availPipes) {
1346 ALOGD_IF(isDebug(), "%s: Insufficient pipes, dpy %d needed %d, avail %d",
1347 __FUNCTION__, mDpy, numPipesNeeded, availPipes);
1348 return false;
1349 }
1350
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001351 if(not areVGPipesAvailable(ctx, list)) {
1352 return false;
1353 }
1354
1355 return true;
1356}
1357
1358bool MDPCompNonSplit::areVGPipesAvailable(hwc_context_t *ctx,
1359 hwc_display_contents_1_t* list) {
1360 overlay::Overlay& ov = *ctx->mOverlay;
1361 int pipesNeeded = 0;
1362 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1363 if(!mCurrentFrame.isFBComposed[i]) {
1364 hwc_layer_1_t* layer = &list->hwLayers[i];
1365 hwc_rect_t dst = layer->displayFrame;
1366 private_handle_t *hnd = (private_handle_t *)layer->handle;
1367 if(isYuvBuffer(hnd)) {
1368 pipesNeeded++;
1369 }
1370 }
1371 }
1372
1373 int availableVGPipes = ov.availablePipes(mDpy, ovutils::OV_MDP_PIPE_VG);
1374 if(pipesNeeded > availableVGPipes) {
1375 ALOGD_IF(isDebug(), "%s: Insufficient VG pipes for video layers"
1376 "dpy %d needed %d, avail %d",
1377 __FUNCTION__, mDpy, pipesNeeded, availableVGPipes);
1378 return false;
1379 }
1380
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001381 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001382}
1383
Saurabh Shah88e4d272013-09-03 13:31:29 -07001384bool MDPCompNonSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001385 hwc_display_contents_1_t* list) {
1386 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001387
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001388 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001389
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001390 hwc_layer_1_t* layer = &list->hwLayers[index];
1391 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001392 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001393 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001394 info.pipeInfo = new MdpPipeInfoNonSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08001395 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001396 MdpPipeInfoNonSplit& pipe_info = *(MdpPipeInfoNonSplit*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001397 ePipeType type = MDPCOMP_OV_ANY;
1398
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001399 if(isYuvBuffer(hnd)) {
1400 type = MDPCOMP_OV_VG;
Saurabh Shah8a117932013-05-23 12:48:13 -07001401 } else if(!qhwc::needsScaling(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001402 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
1403 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001404 type = MDPCOMP_OV_DMA;
1405 }
1406
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001407 pipe_info.index = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001408 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001409 ALOGD_IF(isDebug(), "%s: Unable to get pipe type = %d",
1410 __FUNCTION__, (int) type);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001411 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001412 }
1413 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001414 return true;
1415}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001416
Saurabh Shah88e4d272013-09-03 13:31:29 -07001417bool MDPCompNonSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001418
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001419 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001420 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1421 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -08001422 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001423
1424 if(!ctx || !list) {
1425 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001426 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001427 }
1428
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301429 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1430 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1431 return true;
1432 }
1433
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001434 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001435 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001436 idleInvalidator->markForSleep();
1437
1438 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001439 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001440
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001441 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1442 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001443 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001444 if(mCurrentFrame.isFBComposed[i]) continue;
1445
Naseer Ahmed5b6708a2012-08-02 13:46:08 -07001446 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001447 private_handle_t *hnd = (private_handle_t *)layer->handle;
1448 if(!hnd) {
1449 ALOGE("%s handle null", __FUNCTION__);
1450 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001451 }
1452
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001453 int mdpIndex = mCurrentFrame.layerToMDP[i];
1454
Saurabh Shah88e4d272013-09-03 13:31:29 -07001455 MdpPipeInfoNonSplit& pipe_info =
1456 *(MdpPipeInfoNonSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001457 ovutils::eDest dest = pipe_info.index;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001458 if(dest == ovutils::OV_INVALID) {
1459 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001460 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001461 }
1462
Saurabh Shahacf10202013-02-26 10:15:15 -08001463 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1464 continue;
1465 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001466
Saurabh Shahacf10202013-02-26 10:15:15 -08001467 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001468 using pipe: %d", __FUNCTION__, layer,
1469 hnd, dest );
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001470
Saurabh Shahacf10202013-02-26 10:15:15 -08001471 int fd = hnd->fd;
1472 uint32_t offset = hnd->offset;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001473
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001474 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -08001475 if(rot) {
1476 if(!rot->queueBuffer(fd, offset))
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001477 return false;
Saurabh Shahacf10202013-02-26 10:15:15 -08001478 fd = rot->getDstMemId();
1479 offset = rot->getDstOffset();
1480 }
1481
1482 if (!ov.queueBuffer(fd, offset, dest)) {
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301483 ALOGE("%s: queueBuffer failed for display:%d ", __FUNCTION__, mDpy);
Saurabh Shahacf10202013-02-26 10:15:15 -08001484 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001485 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001486
1487 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001488 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001489 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001490}
1491
Saurabh Shah88e4d272013-09-03 13:31:29 -07001492//=============MDPCompSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001493
Saurabh Shah88e4d272013-09-03 13:31:29 -07001494int MDPCompSplit::pipesNeeded(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001495 hwc_display_contents_1_t* list,
1496 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001497 int pipesNeeded = 0;
Saurabh Shah67a38c32013-06-10 16:23:15 -07001498 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001499
1500 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001501
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001502 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1503 if(!mCurrentFrame.isFBComposed[i]) {
1504 hwc_layer_1_t* layer = &list->hwLayers[i];
1505 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001506 if(mixer == Overlay::MIXER_LEFT && dst.left < lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001507 pipesNeeded++;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001508 } else if(mixer == Overlay::MIXER_RIGHT && dst.right > lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001509 pipesNeeded++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001510 }
1511 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001512 }
1513 return pipesNeeded;
1514}
1515
Saurabh Shah88e4d272013-09-03 13:31:29 -07001516bool MDPCompSplit::arePipesAvailable(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001517 hwc_display_contents_1_t* list) {
1518 overlay::Overlay& ov = *ctx->mOverlay;
Saurabh Shah082468e2013-09-12 10:05:32 -07001519 int totalPipesNeeded = 0;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001520
1521 for(int i = 0; i < Overlay::MIXER_MAX; i++) {
1522 int numPipesNeeded = pipesNeeded(ctx, list, i);
1523 int availPipes = ov.availablePipes(mDpy, i);
1524
1525 //Reserve pipe(s)for FB
1526 if(mCurrentFrame.fbCount)
Saurabh Shah082468e2013-09-12 10:05:32 -07001527 numPipesNeeded += 1;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001528
Saurabh Shah082468e2013-09-12 10:05:32 -07001529 totalPipesNeeded += numPipesNeeded;
1530
1531 //Per mixer check.
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001532 if(numPipesNeeded > availPipes) {
1533 ALOGD_IF(isDebug(), "%s: Insufficient pipes for "
1534 "dpy %d mixer %d needed %d, avail %d",
1535 __FUNCTION__, mDpy, i, numPipesNeeded, availPipes);
1536 return false;
1537 }
1538 }
Saurabh Shah082468e2013-09-12 10:05:32 -07001539
1540 //Per display check, since unused pipes can get counted twice.
1541 int totalPipesAvailable = ov.availablePipes(mDpy);
1542 if(totalPipesNeeded > totalPipesAvailable) {
1543 ALOGD_IF(isDebug(), "%s: Insufficient pipes for "
1544 "dpy %d needed %d, avail %d",
1545 __FUNCTION__, mDpy, totalPipesNeeded, totalPipesAvailable);
1546 return false;
1547 }
1548
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001549 if(not areVGPipesAvailable(ctx, list)) {
1550 return false;
1551 }
1552
1553 return true;
1554}
1555
1556bool MDPCompSplit::areVGPipesAvailable(hwc_context_t *ctx,
1557 hwc_display_contents_1_t* list) {
1558 overlay::Overlay& ov = *ctx->mOverlay;
1559 int pipesNeeded = 0;
1560 const int lSplit = getLeftSplit(ctx, mDpy);
1561 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1562 if(!mCurrentFrame.isFBComposed[i]) {
1563 hwc_layer_1_t* layer = &list->hwLayers[i];
1564 hwc_rect_t dst = layer->displayFrame;
1565 private_handle_t *hnd = (private_handle_t *)layer->handle;
1566 if(isYuvBuffer(hnd)) {
1567 if(dst.left < lSplit) {
1568 pipesNeeded++;
1569 }
1570 if(dst.right > lSplit) {
1571 pipesNeeded++;
1572 }
1573 }
1574 }
1575 }
1576
1577 int availableVGPipes = ov.availablePipes(mDpy, ovutils::OV_MDP_PIPE_VG);
1578 if(pipesNeeded > availableVGPipes) {
1579 ALOGD_IF(isDebug(), "%s: Insufficient VG pipes for video layers"
1580 "dpy %d needed %d, avail %d",
1581 __FUNCTION__, mDpy, pipesNeeded, availableVGPipes);
1582 return false;
1583 }
1584
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001585 return true;
1586}
1587
Saurabh Shah88e4d272013-09-03 13:31:29 -07001588bool MDPCompSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
1589 MdpPipeInfoSplit& pipe_info,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001590 ePipeType type) {
1591 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001592 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001593
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001594 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001595 pipe_info.lIndex = ovutils::OV_INVALID;
1596 pipe_info.rIndex = ovutils::OV_INVALID;
1597
1598 if (dst.left < lSplit) {
1599 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_LEFT);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001600 if(pipe_info.lIndex == ovutils::OV_INVALID)
1601 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001602 }
1603
1604 if(dst.right > lSplit) {
1605 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_RIGHT);
1606 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001607 return false;
1608 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001609
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001610 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001611}
1612
Saurabh Shah88e4d272013-09-03 13:31:29 -07001613bool MDPCompSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001614 hwc_display_contents_1_t* list) {
1615 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001616
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001617 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001618
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001619 hwc_layer_1_t* layer = &list->hwLayers[index];
1620 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001621 int mdpIndex = mCurrentFrame.layerToMDP[index];
1622 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001623 info.pipeInfo = new MdpPipeInfoSplit;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001624 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001625 MdpPipeInfoSplit& pipe_info = *(MdpPipeInfoSplit*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001626 ePipeType type = MDPCOMP_OV_ANY;
1627
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001628 if(isYuvBuffer(hnd)) {
1629 type = MDPCOMP_OV_VG;
Sushil Chauhan15a2ea62013-09-04 18:28:36 -07001630 } else if(!qhwc::needsScalingWithSplit(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001631 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001632 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001633 type = MDPCOMP_OV_DMA;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001634 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001635
1636 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001637 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type = %d",
1638 __FUNCTION__, (int) type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001639 return false;
1640 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001641 }
1642 return true;
1643}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001644
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001645/*
1646 * Configures pipe(s) for MDP composition
1647 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001648int MDPCompSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001649 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001650 MdpPipeInfoSplit& mdp_info =
1651 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001652 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1653 eIsFg isFg = IS_FG_OFF;
1654 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1655 eDest lDest = mdp_info.lIndex;
1656 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001657
1658 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1659 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1660
Saurabh Shah88e4d272013-09-03 13:31:29 -07001661 return configureSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001662 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001663}
1664
Saurabh Shah88e4d272013-09-03 13:31:29 -07001665bool MDPCompSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001666
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001667 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001668 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1669 return true;
1670 }
1671
1672 if(!ctx || !list) {
1673 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001674 return false;
1675 }
1676
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301677 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1678 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1679 return true;
1680 }
1681
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001682 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001683 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001684 idleInvalidator->markForSleep();
1685
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001686 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001687 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001688
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001689 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1690 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001691 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001692 if(mCurrentFrame.isFBComposed[i]) continue;
1693
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001694 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001695 private_handle_t *hnd = (private_handle_t *)layer->handle;
1696 if(!hnd) {
1697 ALOGE("%s handle null", __FUNCTION__);
1698 return false;
1699 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001700
1701 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1702 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001703 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001704
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001705 int mdpIndex = mCurrentFrame.layerToMDP[i];
1706
Saurabh Shah88e4d272013-09-03 13:31:29 -07001707 MdpPipeInfoSplit& pipe_info =
1708 *(MdpPipeInfoSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001709 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -08001710
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001711 ovutils::eDest indexL = pipe_info.lIndex;
1712 ovutils::eDest indexR = pipe_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001713
Saurabh Shahacf10202013-02-26 10:15:15 -08001714 int fd = hnd->fd;
1715 int offset = hnd->offset;
1716
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001717 if(ctx->mAD->isModeOn()) {
1718 if(ctx->mAD->draw(ctx, fd, offset)) {
1719 fd = ctx->mAD->getDstFd(ctx);
1720 offset = ctx->mAD->getDstOffset(ctx);
1721 }
1722 }
1723
Saurabh Shahacf10202013-02-26 10:15:15 -08001724 if(rot) {
1725 rot->queueBuffer(fd, offset);
1726 fd = rot->getDstMemId();
1727 offset = rot->getDstOffset();
1728 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001729
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001730 //************* play left mixer **********
1731 if(indexL != ovutils::OV_INVALID) {
1732 ovutils::eDest destL = (ovutils::eDest)indexL;
Saurabh Shahacf10202013-02-26 10:15:15 -08001733 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001734 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
Saurabh Shahacf10202013-02-26 10:15:15 -08001735 if (!ov.queueBuffer(fd, offset, destL)) {
1736 ALOGE("%s: queueBuffer failed for left mixer", __FUNCTION__);
1737 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001738 }
1739 }
1740
1741 //************* play right mixer **********
1742 if(indexR != ovutils::OV_INVALID) {
1743 ovutils::eDest destR = (ovutils::eDest)indexR;
Saurabh Shahacf10202013-02-26 10:15:15 -08001744 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001745 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
Saurabh Shahacf10202013-02-26 10:15:15 -08001746 if (!ov.queueBuffer(fd, offset, destR)) {
1747 ALOGE("%s: queueBuffer failed for right mixer", __FUNCTION__);
1748 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001749 }
1750 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001751
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001752 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1753 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001754
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001755 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001756}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001757}; //namespace
1758