blob: bdc2dbdca096954c870ea6bd1987fc1ec87c57a7 [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));
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)) {
608 ret = loadBasedComp(ctx, list);
609 }
610
611 if(!ret) {
612 ret = cacheBasedComp(ctx, list);
613 }
614
615 return ret;
616}
617
618bool MDPComp::cacheBasedComp(hwc_context_t *ctx,
619 hwc_display_contents_1_t* list) {
620 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700621 mCurrentFrame.reset(numAppLayers);
622 updateLayerCache(ctx, list);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700623
624 //If an MDP marked layer is unsupported cannot do partial MDP Comp
625 for(int i = 0; i < numAppLayers; i++) {
626 if(!mCurrentFrame.isFBComposed[i]) {
627 hwc_layer_1_t* layer = &list->hwLayers[i];
628 if(not isSupportedForMDPComp(ctx, layer)) {
629 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",
630 __FUNCTION__);
631 return false;
632 }
633 }
634 }
635
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700636 updateYUV(ctx, list, false /*secure only*/);
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530637 bool ret = markLayersForCaching(ctx, list); //sets up fbZ also
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700638 if(!ret) {
639 ALOGD_IF(isDebug(),"%s: batching failed, dpy %d",__FUNCTION__, mDpy);
640 return false;
641 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700642
643 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700644
645 //Will benefit cases where a video has non-updating background.
646 if((mDpy > HWC_DISPLAY_PRIMARY) and
647 (mdpCount > MAX_SEC_LAYERS)) {
648 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
649 return false;
650 }
651
Saurabh Shah173f4242013-11-20 09:50:12 -0800652 if(!resourceCheck(ctx, list)) {
653 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700654 return false;
655 }
656
Saurabh Shahaa236822013-04-24 18:07:26 -0700657 return true;
658}
659
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700660bool MDPComp::loadBasedComp(hwc_context_t *ctx,
661 hwc_display_contents_1_t* list) {
662 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
663 mCurrentFrame.reset(numAppLayers);
664
665 //TODO BatchSize could be optimized further based on available pipes, split
666 //displays etc.
667 const int batchSize = numAppLayers - (sMaxPipesPerMixer - 1);
668 if(batchSize <= 0) {
669 ALOGD_IF(isDebug(), "%s: Not attempting", __FUNCTION__);
670 return false;
671 }
672
673 int minBatchStart = -1;
674 size_t minBatchPixelCount = SIZE_MAX;
675
676 for(int i = 0; i <= numAppLayers - batchSize; i++) {
677 uint32_t batchPixelCount = 0;
678 for(int j = i; j < i + batchSize; j++) {
679 hwc_layer_1_t* layer = &list->hwLayers[j];
Arun Kumar K.R91090c72013-10-28 19:40:18 -0700680 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700681 batchPixelCount += (crop.right - crop.left) *
682 (crop.bottom - crop.top);
683 }
684
685 if(batchPixelCount < minBatchPixelCount) {
686 minBatchPixelCount = batchPixelCount;
687 minBatchStart = i;
688 }
689 }
690
691 if(minBatchStart < 0) {
692 ALOGD_IF(isDebug(), "%s: No batch found batchSize %d numAppLayers %d",
693 __FUNCTION__, batchSize, numAppLayers);
694 return false;
695 }
696
697 for(int i = 0; i < numAppLayers; i++) {
698 if(i < minBatchStart || i >= minBatchStart + batchSize) {
699 hwc_layer_1_t* layer = &list->hwLayers[i];
700 if(not isSupportedForMDPComp(ctx, layer)) {
701 ALOGD_IF(isDebug(), "%s: MDP unsupported layer found at %d",
702 __FUNCTION__, i);
703 return false;
704 }
705 mCurrentFrame.isFBComposed[i] = false;
706 }
707 }
708
709 mCurrentFrame.fbZ = minBatchStart;
710 mCurrentFrame.fbCount = batchSize;
711 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - batchSize;
712
Saurabh Shah173f4242013-11-20 09:50:12 -0800713 if(!resourceCheck(ctx, list)) {
714 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700715 return false;
716 }
717
718 ALOGD_IF(isDebug(), "%s: fbZ %d batchSize %d",
719 __FUNCTION__, mCurrentFrame.fbZ, batchSize);
720 return true;
721}
722
723bool MDPComp::isLoadBasedCompDoable(hwc_context_t *ctx,
724 hwc_display_contents_1_t* list) {
725 if(mDpy or isSecurePresent(ctx, mDpy) or
726 not (list->flags & HWC_GEOMETRY_CHANGED)) {
727 return false;
728 }
729 return true;
730}
731
Saurabh Shahaa236822013-04-24 18:07:26 -0700732bool MDPComp::isOnlyVideoDoable(hwc_context_t *ctx,
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700733 hwc_display_contents_1_t* list, bool secureOnly) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700734 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700735
Saurabh Shahaa236822013-04-24 18:07:26 -0700736 mCurrentFrame.reset(numAppLayers);
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700737 updateYUV(ctx, list, secureOnly);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700738 int mdpCount = mCurrentFrame.mdpCount;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700739 int fbNeeded = (mCurrentFrame.fbCount != 0);
Saurabh Shahaa236822013-04-24 18:07:26 -0700740
741 if(!isYuvPresent(ctx, mDpy)) {
742 return false;
743 }
744
Jeykumar Sankaranf42f0d82013-11-08 18:09:20 -0800745 /* Bail out if we are processing only secured video layers
746 * and we dont have any */
747 if(!isSecurePresent(ctx, mDpy) && secureOnly){
748 return false;
749 }
750
Saurabh Shah4fdde762013-04-30 18:47:33 -0700751 if(!mdpCount)
752 return false;
753
Saurabh Shah173f4242013-11-20 09:50:12 -0800754 if(!resourceCheck(ctx, list)) {
755 ALOGD_IF(isDebug(), "%s: resource check failed", __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700756 return false;
757 }
758
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800759 return true;
760}
761
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800762/* Checks for conditions where YUV layers cannot be bypassed */
763bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Saurabh Shahe2474082013-05-15 16:32:13 -0700764 bool extAnimBlockFeature = mDpy && ctx->listStats[mDpy].isDisplayAnimating;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800765
Saurabh Shahe2474082013-05-15 16:32:13 -0700766 if(isSkipLayer(layer) && !extAnimBlockFeature) {
767 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800768 return false;
769 }
770
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700771 if(layer->transform & HWC_TRANSFORM_ROT_90 && !canUseRotator(ctx,mDpy)) {
772 ALOGD_IF(isDebug(), "%s: no free DMA pipe",__FUNCTION__);
773 return false;
774 }
775
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800776 if(isSecuring(ctx, layer)) {
777 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
778 return false;
779 }
780
Saurabh Shah4fdde762013-04-30 18:47:33 -0700781 if(!isValidDimension(ctx, layer)) {
782 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
783 __FUNCTION__);
784 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800785 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700786
Naseer Ahmeddc61a972013-07-10 17:50:54 -0400787 if(layer->planeAlpha < 0xFF) {
788 ALOGD_IF(isDebug(), "%s: Cannot handle YUV layer with plane alpha\
789 in video only mode",
790 __FUNCTION__);
791 return false;
792 }
793
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800794 return true;
795}
796
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530797/* starts at fromIndex and check for each layer to find
798 * if it it has overlapping with any Updating layer above it in zorder
799 * till the end of the batch. returns true if it finds any intersection */
800bool MDPComp::canPushBatchToTop(const hwc_display_contents_1_t* list,
801 int fromIndex, int toIndex) {
802 for(int i = fromIndex; i < toIndex; i++) {
803 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
804 if(intersectingUpdatingLayers(list, i+1, toIndex, i)) {
805 return false;
806 }
807 }
808 }
809 return true;
810}
811
812/* Checks if given layer at targetLayerIndex has any
813 * intersection with all the updating layers in beween
814 * fromIndex and toIndex. Returns true if it finds intersectiion */
815bool MDPComp::intersectingUpdatingLayers(const hwc_display_contents_1_t* list,
816 int fromIndex, int toIndex, int targetLayerIndex) {
817 for(int i = fromIndex; i <= toIndex; i++) {
818 if(!mCurrentFrame.isFBComposed[i]) {
819 if(areLayersIntersecting(&list->hwLayers[i],
820 &list->hwLayers[targetLayerIndex])) {
821 return true;
822 }
823 }
824 }
825 return false;
826}
827
828int MDPComp::getBatch(hwc_display_contents_1_t* list,
829 int& maxBatchStart, int& maxBatchEnd,
830 int& maxBatchCount) {
831 int i = 0;
832 int updatingLayersAbove = 0;//Updating layer count in middle of batch
833 int fbZOrder =-1;
834 while (i < mCurrentFrame.layerCount) {
835 int batchCount = 0;
836 int batchStart = i;
837 int batchEnd = i;
838 int fbZ = batchStart;
839 int firstZReverseIndex = -1;
840 while(i < mCurrentFrame.layerCount) {
841 if(!mCurrentFrame.isFBComposed[i]) {
842 if(!batchCount) {
843 i++;
844 break;
845 }
846 updatingLayersAbove++;
847 i++;
848 continue;
849 } else {
850 if(mCurrentFrame.drop[i]) {
851 i++;
852 continue;
853 } else if(updatingLayersAbove <= 0) {
854 batchCount++;
855 batchEnd = i;
856 i++;
857 continue;
858 } else { //Layer is FBComposed, not a drop & updatingLayer > 0
859
860 // We have a valid updating layer already. If layer-i not
861 // have overlapping with all updating layers in between
862 // batch-start and i, then we can add layer i to batch.
863 if(!intersectingUpdatingLayers(list, batchStart, i-1, i)) {
864 batchCount++;
865 batchEnd = i;
866 i++;
867 continue;
868 } else if(canPushBatchToTop(list, batchStart, i)) {
869 //If All the non-updating layers with in this batch
870 //does not have intersection with the updating layers
871 //above in z-order, then we can safely move the batch to
872 //higher z-order. Increment fbZ as it is moving up.
873 if( firstZReverseIndex < 0) {
874 firstZReverseIndex = i;
875 }
876 batchCount++;
877 batchEnd = i;
878 fbZ += updatingLayersAbove;
879 i++;
880 updatingLayersAbove = 0;
881 continue;
882 } else {
883 //both failed.start the loop again from here.
884 if(firstZReverseIndex >= 0) {
885 i = firstZReverseIndex;
886 }
887 break;
888 }
889 }
890 }
891 }
892 if(batchCount > maxBatchCount) {
893 maxBatchCount = batchCount;
894 maxBatchStart = batchStart;
895 maxBatchEnd = batchEnd;
896 fbZOrder = fbZ;
897 }
898 }
899 return fbZOrder;
900}
901
902bool MDPComp::markLayersForCaching(hwc_context_t* ctx,
903 hwc_display_contents_1_t* list) {
904 /* Idea is to keep as many non-updating(cached) layers in FB and
905 * send rest of them through MDP. This is done in 2 steps.
906 * 1. Find the maximum contiguous batch of non-updating layers.
907 * 2. See if we can improve this batch size for caching by adding
908 * opaque layers around the batch, if they don't have
909 * any overlapping with the updating layers in between.
910 * NEVER mark an updating layer for caching.
911 * But cached ones can be marked for MDP */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800912
913 int maxBatchStart = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700914 int maxBatchEnd = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800915 int maxBatchCount = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530916 int fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800917
918 /* All or Nothing is cached. No batching needed */
Saurabh Shahaa236822013-04-24 18:07:26 -0700919 if(!mCurrentFrame.fbCount) {
920 mCurrentFrame.fbZ = -1;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700921 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -0700922 }
923 if(!mCurrentFrame.mdpCount) {
924 mCurrentFrame.fbZ = 0;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700925 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -0700926 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800927
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530928 fbZ = getBatch(list, maxBatchStart, maxBatchEnd, maxBatchCount);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800929
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530930 /* reset rest of the layers lying inside ROI for MDP comp */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800931 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700932 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700933 if((i < maxBatchStart || i > maxBatchEnd) &&
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530934 mCurrentFrame.isFBComposed[i]){
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700935 if(!mCurrentFrame.drop[i]){
936 //If an unsupported layer is being attempted to
937 //be pulled out we should fail
938 if(not isSupportedForMDPComp(ctx, layer)) {
939 return false;
940 }
941 mCurrentFrame.isFBComposed[i] = false;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700942 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800943 }
944 }
945
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530946 // update the frame data
947 mCurrentFrame.fbZ = fbZ;
948 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700949 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700950 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800951
952 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530953 mCurrentFrame.fbCount);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700954
955 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800956}
Saurabh Shah85234ec2013-04-12 17:09:00 -0700957
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800958void MDPComp::updateLayerCache(hwc_context_t* ctx,
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700959 hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800960 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700961 int fbCount = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800962
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800963 for(int i = 0; i < numAppLayers; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700964 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800965 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700966 if(!mCurrentFrame.drop[i])
967 fbCount++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800968 mCurrentFrame.isFBComposed[i] = true;
969 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -0700970 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800971 }
972 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700973
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700974 mCurrentFrame.fbCount = fbCount;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700975 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount
976 - mCurrentFrame.dropCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700977
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700978 ALOGD_IF(isDebug(),"%s: MDP count: %d FB count %d drop count: %d"
979 ,__FUNCTION__, mCurrentFrame.mdpCount, mCurrentFrame.fbCount,
980 mCurrentFrame.dropCount);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800981}
982
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700983void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list,
984 bool secureOnly) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800985 int nYuvCount = ctx->listStats[mDpy].yuvCount;
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700986 if(!nYuvCount && mDpy) {
987 //Reset "No animation on external display" related parameters.
988 ctx->mPrevCropVideo.left = ctx->mPrevCropVideo.top =
989 ctx->mPrevCropVideo.right = ctx->mPrevCropVideo.bottom = 0;
990 ctx->mPrevDestVideo.left = ctx->mPrevDestVideo.top =
991 ctx->mPrevDestVideo.right = ctx->mPrevDestVideo.bottom = 0;
992 ctx->mPrevTransformVideo = 0;
993 return;
994 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800995 for(int index = 0;index < nYuvCount; index++){
996 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
997 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
998
999 if(!isYUVDoable(ctx, layer)) {
1000 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
1001 mCurrentFrame.isFBComposed[nYuvIndex] = true;
1002 mCurrentFrame.fbCount++;
1003 }
1004 } else {
1005 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001006 private_handle_t *hnd = (private_handle_t *)layer->handle;
1007 if(!secureOnly || isSecureBuffer(hnd)) {
1008 mCurrentFrame.isFBComposed[nYuvIndex] = false;
1009 mCurrentFrame.fbCount--;
1010 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001011 }
1012 }
1013 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001014
1015 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001016 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
1017 ALOGD_IF(isDebug(),"%s: fb count: %d",__FUNCTION__,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001018 mCurrentFrame.fbCount);
1019}
1020
Saurabh Shahaa236822013-04-24 18:07:26 -07001021bool MDPComp::programMDP(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001022 if(!allocLayerPipes(ctx, list)) {
1023 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -07001024 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001025 }
1026
1027 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001028 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001029 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001030 int mdpIndex = mCurrentFrame.layerToMDP[index];
1031 hwc_layer_1_t* layer = &list->hwLayers[index];
1032
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301033 //Leave fbZ for framebuffer. CACHE/GLES layers go here.
1034 if(mdpNextZOrder == mCurrentFrame.fbZ) {
1035 mdpNextZOrder++;
1036 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001037 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1038 cur_pipe->zOrder = mdpNextZOrder++;
1039
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301040
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001041 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
1042 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
1043 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -07001044 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001045 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001046 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001047 }
1048
Saurabh Shahaa236822013-04-24 18:07:26 -07001049 return true;
1050}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001051
Saurabh Shahaa236822013-04-24 18:07:26 -07001052bool MDPComp::programYUV(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
1053 if(!allocLayerPipes(ctx, list)) {
1054 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
1055 return false;
1056 }
1057 //If we are in this block, it means we have yuv + rgb layers both
1058 int mdpIdx = 0;
1059 for (int index = 0; index < mCurrentFrame.layerCount; index++) {
1060 if(!mCurrentFrame.isFBComposed[index]) {
1061 hwc_layer_1_t* layer = &list->hwLayers[index];
1062 int mdpIndex = mCurrentFrame.layerToMDP[index];
1063 MdpPipeInfo* cur_pipe =
1064 mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1065 cur_pipe->zOrder = mdpIdx++;
1066
1067 if(configure(ctx, layer,
1068 mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
1069 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
1070 layer %d",__FUNCTION__, index);
1071 return false;
1072 }
1073 }
1074 }
1075 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001076}
1077
Saurabh Shah173f4242013-11-20 09:50:12 -08001078bool MDPComp::resourceCheck(hwc_context_t *ctx,
1079 hwc_display_contents_1_t *list) {
1080 const bool fbUsed = mCurrentFrame.fbCount;
1081 if(mCurrentFrame.mdpCount > sMaxPipesPerMixer - fbUsed) {
1082 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
1083 return false;
1084 }
1085
1086 if(!arePipesAvailable(ctx, list)) {
1087 return false;
1088 }
1089
1090 uint32_t size = calcMDPBytesRead(ctx, list);
1091 if(!bandwidthCheck(ctx, size)) {
1092 ALOGD_IF(isDebug(), "%s: Exceeds bandwidth",__FUNCTION__);
1093 return false;
1094 }
1095
1096 return true;
1097}
1098
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001099uint32_t MDPComp::calcMDPBytesRead(hwc_context_t *ctx,
1100 hwc_display_contents_1_t* list) {
1101 uint32_t size = 0;
1102
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001103 if(!qdutils::MDPVersion::getInstance().is8x74v2())
1104 return 0;
1105
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001106 for (uint32_t i = 0; i < list->numHwLayers - 1; i++) {
1107 if(!mCurrentFrame.isFBComposed[i]) {
1108 hwc_layer_1_t* layer = &list->hwLayers[i];
1109 private_handle_t *hnd = (private_handle_t *)layer->handle;
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001110 if (hnd) {
Saurabh Shah62e1d732013-09-17 10:44:05 -07001111 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah90789162013-09-16 10:29:20 -07001112 hwc_rect_t dst = layer->displayFrame;
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001113 float bpp = ((float)hnd->size) / (hnd->width * hnd->height);
Saurabh Shah90789162013-09-16 10:29:20 -07001114 size += bpp * (crop.right - crop.left) *
1115 (crop.bottom - crop.top) *
1116 ctx->dpyAttr[mDpy].yres / (dst.bottom - dst.top);
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001117 }
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001118 }
1119 }
1120
1121 if(mCurrentFrame.fbCount) {
1122 hwc_layer_1_t* layer = &list->hwLayers[list->numHwLayers - 1];
1123 private_handle_t *hnd = (private_handle_t *)layer->handle;
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001124 if (hnd)
1125 size += hnd->size;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001126 }
1127
1128 return size;
1129}
1130
1131bool MDPComp::bandwidthCheck(hwc_context_t *ctx, const uint32_t& size) {
1132 //Will be added for other targets if we run into bandwidth issues and when
1133 //we have profiling data to set an upper limit.
1134 if(qdutils::MDPVersion::getInstance().is8x74v2()) {
1135 const uint32_t ONE_GIG = 1024 * 1024 * 1024;
1136 double panelRefRate =
1137 1000000000.0 / ctx->dpyAttr[mDpy].vsync_period;
1138 if((size + sCompBytesClaimed) > ((sMaxBw / panelRefRate) * ONE_GIG)) {
1139 return false;
1140 }
1141 }
1142 return true;
1143}
1144
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001145int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001146 int ret = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -07001147 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -07001148
Saurabh Shahb39f8152013-08-22 10:21:44 -07001149 //reset old data
1150 mCurrentFrame.reset(numLayers);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001151 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1152 mCurrentFrame.dropCount = 0;
Prabhanjan Kandula088bd892013-07-02 23:47:13 +05301153
Saurabh Shahb39f8152013-08-22 10:21:44 -07001154 //number of app layers exceeds MAX_NUM_APP_LAYERS fall back to GPU
1155 //do not cache the information for next draw cycle.
1156 if(numLayers > MAX_NUM_APP_LAYERS) {
Prabhanjan Kandula25469a52013-07-12 16:19:31 +05301157 mCachedFrame.updateCounts(mCurrentFrame);
Arpita Banerjeed8965982013-11-08 17:27:33 -08001158 ALOGI("%s: Number of App layers exceeded the limit ",
Tatenda Chipeperekwa835337a2013-09-27 16:58:43 -07001159 __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001160 ret = -1;
Tatenda Chipeperekwa835337a2013-09-27 16:58:43 -07001161 return ret;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001162 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001163
Saurabh Shahb39f8152013-08-22 10:21:44 -07001164 //Hard conditions, if not met, cannot do MDP comp
1165 if(!isFrameDoable(ctx)) {
1166 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
1167 __FUNCTION__);
1168 reset(numLayers, list);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001169 ret = -1;
1170 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001171 }
1172
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001173 generateROI(ctx, list);
1174
Saurabh Shahb39f8152013-08-22 10:21:44 -07001175 //Check whether layers marked for MDP Composition is actually doable.
1176 if(isFullFrameDoable(ctx, list)) {
1177 mCurrentFrame.map();
1178 //Configure framebuffer first if applicable
1179 if(mCurrentFrame.fbZ >= 0) {
1180 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list,
1181 mCurrentFrame.fbZ)) {
1182 ALOGE("%s configure framebuffer failed", __func__);
1183 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -07001184 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001185 ret = -1;
1186 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001187 }
1188 }
1189 //Acquire and Program MDP pipes
1190 if(!programMDP(ctx, list)) {
1191 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -07001192 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001193 ret = -1;
1194 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001195 } else { //Success
1196 //Any change in composition types needs an FB refresh
1197 mCurrentFrame.needsRedraw = false;
Jeykumar Sankaran988d3682013-11-15 11:57:16 -08001198 if(!mCachedFrame.isSameFrame(mCurrentFrame, list) ||
Saurabh Shahb39f8152013-08-22 10:21:44 -07001199 (list->flags & HWC_GEOMETRY_CHANGED) ||
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +05301200 isSkipPresent(ctx, mDpy)) {
Saurabh Shahb39f8152013-08-22 10:21:44 -07001201 mCurrentFrame.needsRedraw = true;
1202 }
1203 }
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001204 } else if(isOnlyVideoDoable(ctx, list, false /*secure only*/) ||
1205 isOnlyVideoDoable(ctx, list, true /*secure only*/)) {
Saurabh Shahb39f8152013-08-22 10:21:44 -07001206 //All layers marked for MDP comp cannot be bypassed.
1207 //Try to compose atleast YUV layers through MDP comp and let
1208 //all the RGB layers compose in FB
1209 //Destination over
1210 mCurrentFrame.fbZ = -1;
1211 if(mCurrentFrame.fbCount)
1212 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
1213
1214 mCurrentFrame.map();
1215
1216 //Configure framebuffer first if applicable
1217 if(mCurrentFrame.fbZ >= 0) {
1218 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, mCurrentFrame.fbZ)) {
1219 ALOGE("%s configure framebuffer failed", __func__);
1220 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -07001221 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001222 ret = -1;
1223 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001224 }
1225 }
1226 if(!programYUV(ctx, list)) {
1227 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -07001228 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001229 ret = -1;
1230 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001231 }
1232 } else {
1233 reset(numLayers, list);
Jeykumar Sankaran862d87c2013-11-08 16:47:26 -08001234 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1235 mCurrentFrame.dropCount = 0;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001236 ret = -1;
1237 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001238 }
Saurabh Shahb39f8152013-08-22 10:21:44 -07001239 //UpdateLayerFlags
1240 setMDPCompLayerFlags(ctx, list);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001241 mCachedFrame.cacheAll(list);
Saurabh Shahb39f8152013-08-22 10:21:44 -07001242 mCachedFrame.updateCounts(mCurrentFrame);
1243
Prabhanjan Kandula25469a52013-07-12 16:19:31 +05301244 // unlock it before calling dump function to avoid deadlock
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001245 if(isDebug()) {
Saurabh Shahaa236822013-04-24 18:07:26 -07001246 ALOGD("GEOMETRY change: %d", (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001247 android::String8 sDump("");
1248 dump(sDump);
1249 ALOGE("%s",sDump.string());
1250 }
1251
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001252exit:
1253 sCompBytesClaimed += calcMDPBytesRead(ctx, list);
1254 return ret;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001255}
1256
Saurabh Shah88e4d272013-09-03 13:31:29 -07001257//=============MDPCompNonSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001258
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001259/*
1260 * Configures pipe(s) for MDP composition
1261 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001262int MDPCompNonSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001263 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001264 MdpPipeInfoNonSplit& mdp_info =
1265 *(static_cast<MdpPipeInfoNonSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001266 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
1267 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1268 eIsFg isFg = IS_FG_OFF;
1269 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001270
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001271 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
1272 __FUNCTION__, layer, zOrder, dest);
1273
Saurabh Shah88e4d272013-09-03 13:31:29 -07001274 return configureNonSplit(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001275 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001276}
1277
Saurabh Shah88e4d272013-09-03 13:31:29 -07001278bool MDPCompNonSplit::arePipesAvailable(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001279 hwc_display_contents_1_t* list) {
1280 overlay::Overlay& ov = *ctx->mOverlay;
1281 int numPipesNeeded = mCurrentFrame.mdpCount;
1282 int availPipes = ov.availablePipes(mDpy, Overlay::MIXER_DEFAULT);
1283
1284 //Reserve pipe for FB
1285 if(mCurrentFrame.fbCount)
1286 availPipes -= 1;
1287
1288 if(numPipesNeeded > availPipes) {
1289 ALOGD_IF(isDebug(), "%s: Insufficient pipes, dpy %d needed %d, avail %d",
1290 __FUNCTION__, mDpy, numPipesNeeded, availPipes);
1291 return false;
1292 }
1293
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001294 if(not areVGPipesAvailable(ctx, list)) {
1295 return false;
1296 }
1297
1298 return true;
1299}
1300
1301bool MDPCompNonSplit::areVGPipesAvailable(hwc_context_t *ctx,
1302 hwc_display_contents_1_t* list) {
1303 overlay::Overlay& ov = *ctx->mOverlay;
1304 int pipesNeeded = 0;
1305 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1306 if(!mCurrentFrame.isFBComposed[i]) {
1307 hwc_layer_1_t* layer = &list->hwLayers[i];
1308 hwc_rect_t dst = layer->displayFrame;
1309 private_handle_t *hnd = (private_handle_t *)layer->handle;
1310 if(isYuvBuffer(hnd)) {
1311 pipesNeeded++;
1312 }
1313 }
1314 }
1315
1316 int availableVGPipes = ov.availablePipes(mDpy, ovutils::OV_MDP_PIPE_VG);
1317 if(pipesNeeded > availableVGPipes) {
1318 ALOGD_IF(isDebug(), "%s: Insufficient VG pipes for video layers"
1319 "dpy %d needed %d, avail %d",
1320 __FUNCTION__, mDpy, pipesNeeded, availableVGPipes);
1321 return false;
1322 }
1323
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001324 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001325}
1326
Saurabh Shah88e4d272013-09-03 13:31:29 -07001327bool MDPCompNonSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001328 hwc_display_contents_1_t* list) {
1329 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001330
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001331 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001332
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001333 hwc_layer_1_t* layer = &list->hwLayers[index];
1334 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001335 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001336 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001337 info.pipeInfo = new MdpPipeInfoNonSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08001338 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001339 MdpPipeInfoNonSplit& pipe_info = *(MdpPipeInfoNonSplit*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001340 ePipeType type = MDPCOMP_OV_ANY;
1341
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001342 if(isYuvBuffer(hnd)) {
1343 type = MDPCOMP_OV_VG;
Saurabh Shah8a117932013-05-23 12:48:13 -07001344 } else if(!qhwc::needsScaling(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001345 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
1346 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001347 type = MDPCOMP_OV_DMA;
1348 }
1349
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001350 pipe_info.index = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001351 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001352 ALOGD_IF(isDebug(), "%s: Unable to get pipe type = %d",
1353 __FUNCTION__, (int) type);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001354 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001355 }
1356 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001357 return true;
1358}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001359
Saurabh Shah88e4d272013-09-03 13:31:29 -07001360bool MDPCompNonSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001361
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001362 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001363 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1364 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -08001365 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001366
1367 if(!ctx || !list) {
1368 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001369 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001370 }
1371
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301372 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1373 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1374 return true;
1375 }
1376
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001377 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001378 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001379 idleInvalidator->markForSleep();
1380
1381 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001382 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001383
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001384 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1385 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001386 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001387 if(mCurrentFrame.isFBComposed[i]) continue;
1388
Naseer Ahmed5b6708a2012-08-02 13:46:08 -07001389 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001390 private_handle_t *hnd = (private_handle_t *)layer->handle;
1391 if(!hnd) {
1392 ALOGE("%s handle null", __FUNCTION__);
1393 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001394 }
1395
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001396 int mdpIndex = mCurrentFrame.layerToMDP[i];
1397
Saurabh Shah88e4d272013-09-03 13:31:29 -07001398 MdpPipeInfoNonSplit& pipe_info =
1399 *(MdpPipeInfoNonSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001400 ovutils::eDest dest = pipe_info.index;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001401 if(dest == ovutils::OV_INVALID) {
1402 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001403 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001404 }
1405
Saurabh Shahacf10202013-02-26 10:15:15 -08001406 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1407 continue;
1408 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001409
Saurabh Shahacf10202013-02-26 10:15:15 -08001410 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001411 using pipe: %d", __FUNCTION__, layer,
1412 hnd, dest );
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001413
Saurabh Shahacf10202013-02-26 10:15:15 -08001414 int fd = hnd->fd;
1415 uint32_t offset = hnd->offset;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001416
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001417 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -08001418 if(rot) {
1419 if(!rot->queueBuffer(fd, offset))
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001420 return false;
Saurabh Shahacf10202013-02-26 10:15:15 -08001421 fd = rot->getDstMemId();
1422 offset = rot->getDstOffset();
1423 }
1424
1425 if (!ov.queueBuffer(fd, offset, dest)) {
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301426 ALOGE("%s: queueBuffer failed for display:%d ", __FUNCTION__, mDpy);
Saurabh Shahacf10202013-02-26 10:15:15 -08001427 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001428 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001429
1430 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001431 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001432 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001433}
1434
Saurabh Shah88e4d272013-09-03 13:31:29 -07001435//=============MDPCompSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001436
Saurabh Shah88e4d272013-09-03 13:31:29 -07001437int MDPCompSplit::pipesNeeded(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001438 hwc_display_contents_1_t* list,
1439 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001440 int pipesNeeded = 0;
Saurabh Shah67a38c32013-06-10 16:23:15 -07001441 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001442
1443 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001444
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001445 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1446 if(!mCurrentFrame.isFBComposed[i]) {
1447 hwc_layer_1_t* layer = &list->hwLayers[i];
1448 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001449 if(mixer == Overlay::MIXER_LEFT && dst.left < lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001450 pipesNeeded++;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001451 } else if(mixer == Overlay::MIXER_RIGHT && dst.right > lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001452 pipesNeeded++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001453 }
1454 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001455 }
1456 return pipesNeeded;
1457}
1458
Saurabh Shah88e4d272013-09-03 13:31:29 -07001459bool MDPCompSplit::arePipesAvailable(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001460 hwc_display_contents_1_t* list) {
1461 overlay::Overlay& ov = *ctx->mOverlay;
Saurabh Shah082468e2013-09-12 10:05:32 -07001462 int totalPipesNeeded = 0;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001463
1464 for(int i = 0; i < Overlay::MIXER_MAX; i++) {
1465 int numPipesNeeded = pipesNeeded(ctx, list, i);
1466 int availPipes = ov.availablePipes(mDpy, i);
1467
1468 //Reserve pipe(s)for FB
1469 if(mCurrentFrame.fbCount)
Saurabh Shah082468e2013-09-12 10:05:32 -07001470 numPipesNeeded += 1;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001471
Saurabh Shah082468e2013-09-12 10:05:32 -07001472 totalPipesNeeded += numPipesNeeded;
1473
1474 //Per mixer check.
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001475 if(numPipesNeeded > availPipes) {
1476 ALOGD_IF(isDebug(), "%s: Insufficient pipes for "
1477 "dpy %d mixer %d needed %d, avail %d",
1478 __FUNCTION__, mDpy, i, numPipesNeeded, availPipes);
1479 return false;
1480 }
1481 }
Saurabh Shah082468e2013-09-12 10:05:32 -07001482
1483 //Per display check, since unused pipes can get counted twice.
1484 int totalPipesAvailable = ov.availablePipes(mDpy);
1485 if(totalPipesNeeded > totalPipesAvailable) {
1486 ALOGD_IF(isDebug(), "%s: Insufficient pipes for "
1487 "dpy %d needed %d, avail %d",
1488 __FUNCTION__, mDpy, totalPipesNeeded, totalPipesAvailable);
1489 return false;
1490 }
1491
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001492 if(not areVGPipesAvailable(ctx, list)) {
1493 return false;
1494 }
1495
1496 return true;
1497}
1498
1499bool MDPCompSplit::areVGPipesAvailable(hwc_context_t *ctx,
1500 hwc_display_contents_1_t* list) {
1501 overlay::Overlay& ov = *ctx->mOverlay;
1502 int pipesNeeded = 0;
1503 const int lSplit = getLeftSplit(ctx, mDpy);
1504 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1505 if(!mCurrentFrame.isFBComposed[i]) {
1506 hwc_layer_1_t* layer = &list->hwLayers[i];
1507 hwc_rect_t dst = layer->displayFrame;
1508 private_handle_t *hnd = (private_handle_t *)layer->handle;
1509 if(isYuvBuffer(hnd)) {
1510 if(dst.left < lSplit) {
1511 pipesNeeded++;
1512 }
1513 if(dst.right > lSplit) {
1514 pipesNeeded++;
1515 }
1516 }
1517 }
1518 }
1519
1520 int availableVGPipes = ov.availablePipes(mDpy, ovutils::OV_MDP_PIPE_VG);
1521 if(pipesNeeded > availableVGPipes) {
1522 ALOGD_IF(isDebug(), "%s: Insufficient VG pipes for video layers"
1523 "dpy %d needed %d, avail %d",
1524 __FUNCTION__, mDpy, pipesNeeded, availableVGPipes);
1525 return false;
1526 }
1527
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001528 return true;
1529}
1530
Saurabh Shah88e4d272013-09-03 13:31:29 -07001531bool MDPCompSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
1532 MdpPipeInfoSplit& pipe_info,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001533 ePipeType type) {
1534 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001535 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001536
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001537 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001538 pipe_info.lIndex = ovutils::OV_INVALID;
1539 pipe_info.rIndex = ovutils::OV_INVALID;
1540
1541 if (dst.left < lSplit) {
1542 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_LEFT);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001543 if(pipe_info.lIndex == ovutils::OV_INVALID)
1544 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001545 }
1546
1547 if(dst.right > lSplit) {
1548 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_RIGHT);
1549 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001550 return false;
1551 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001552
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001553 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001554}
1555
Saurabh Shah88e4d272013-09-03 13:31:29 -07001556bool MDPCompSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001557 hwc_display_contents_1_t* list) {
1558 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001559
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001560 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001561
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001562 hwc_layer_1_t* layer = &list->hwLayers[index];
1563 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001564 int mdpIndex = mCurrentFrame.layerToMDP[index];
1565 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001566 info.pipeInfo = new MdpPipeInfoSplit;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001567 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001568 MdpPipeInfoSplit& pipe_info = *(MdpPipeInfoSplit*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001569 ePipeType type = MDPCOMP_OV_ANY;
1570
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001571 if(isYuvBuffer(hnd)) {
1572 type = MDPCOMP_OV_VG;
Sushil Chauhan15a2ea62013-09-04 18:28:36 -07001573 } else if(!qhwc::needsScalingWithSplit(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001574 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001575 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001576 type = MDPCOMP_OV_DMA;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001577 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001578
1579 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001580 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type = %d",
1581 __FUNCTION__, (int) type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001582 return false;
1583 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001584 }
1585 return true;
1586}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001587
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001588/*
1589 * Configures pipe(s) for MDP composition
1590 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001591int MDPCompSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001592 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001593 MdpPipeInfoSplit& mdp_info =
1594 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001595 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1596 eIsFg isFg = IS_FG_OFF;
1597 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1598 eDest lDest = mdp_info.lIndex;
1599 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001600
1601 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1602 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1603
Saurabh Shah88e4d272013-09-03 13:31:29 -07001604 return configureSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001605 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001606}
1607
Saurabh Shah88e4d272013-09-03 13:31:29 -07001608bool MDPCompSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001609
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001610 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001611 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1612 return true;
1613 }
1614
1615 if(!ctx || !list) {
1616 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001617 return false;
1618 }
1619
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301620 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1621 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1622 return true;
1623 }
1624
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001625 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001626 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001627 idleInvalidator->markForSleep();
1628
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001629 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001630 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001631
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001632 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1633 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001634 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001635 if(mCurrentFrame.isFBComposed[i]) continue;
1636
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001637 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001638 private_handle_t *hnd = (private_handle_t *)layer->handle;
1639 if(!hnd) {
1640 ALOGE("%s handle null", __FUNCTION__);
1641 return false;
1642 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001643
1644 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1645 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001646 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001647
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001648 int mdpIndex = mCurrentFrame.layerToMDP[i];
1649
Saurabh Shah88e4d272013-09-03 13:31:29 -07001650 MdpPipeInfoSplit& pipe_info =
1651 *(MdpPipeInfoSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001652 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -08001653
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001654 ovutils::eDest indexL = pipe_info.lIndex;
1655 ovutils::eDest indexR = pipe_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001656
Saurabh Shahacf10202013-02-26 10:15:15 -08001657 int fd = hnd->fd;
1658 int offset = hnd->offset;
1659
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001660 if(ctx->mAD->isModeOn()) {
1661 if(ctx->mAD->draw(ctx, fd, offset)) {
1662 fd = ctx->mAD->getDstFd(ctx);
1663 offset = ctx->mAD->getDstOffset(ctx);
1664 }
1665 }
1666
Saurabh Shahacf10202013-02-26 10:15:15 -08001667 if(rot) {
1668 rot->queueBuffer(fd, offset);
1669 fd = rot->getDstMemId();
1670 offset = rot->getDstOffset();
1671 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001672
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001673 //************* play left mixer **********
1674 if(indexL != ovutils::OV_INVALID) {
1675 ovutils::eDest destL = (ovutils::eDest)indexL;
Saurabh Shahacf10202013-02-26 10:15:15 -08001676 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001677 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
Saurabh Shahacf10202013-02-26 10:15:15 -08001678 if (!ov.queueBuffer(fd, offset, destL)) {
1679 ALOGE("%s: queueBuffer failed for left mixer", __FUNCTION__);
1680 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001681 }
1682 }
1683
1684 //************* play right mixer **********
1685 if(indexR != ovutils::OV_INVALID) {
1686 ovutils::eDest destR = (ovutils::eDest)indexR;
Saurabh Shahacf10202013-02-26 10:15:15 -08001687 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001688 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
Saurabh Shahacf10202013-02-26 10:15:15 -08001689 if (!ov.queueBuffer(fd, offset, destR)) {
1690 ALOGE("%s: queueBuffer failed for right mixer", __FUNCTION__);
1691 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001692 }
1693 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001694
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001695 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1696 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001697
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001698 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001699}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001700}; //namespace
1701