blob: fff53ed8d1c7f78cbf4f90c399505120c65bc59e [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;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800309
310 if(dst.left < 0 || dst.top < 0 || dst.right > hw_w || dst.bottom > hw_h) {
Saurabh Shah4fdde762013-04-30 18:47:33 -0700311 hwc_rect_t scissor = {0, 0, hw_w, hw_h };
312 qhwc::calculate_crop_rects(crop, dst, scissor, layer->transform);
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800313 }
314
Saurabh Shah4fdde762013-04-30 18:47:33 -0700315 int crop_w = crop.right - crop.left;
316 int crop_h = crop.bottom - crop.top;
317 int dst_w = dst.right - dst.left;
318 int dst_h = dst.bottom - dst.top;
319 float w_dscale = ceilf((float)crop_w / (float)dst_w);
320 float h_dscale = ceilf((float)crop_h / (float)dst_h);
321
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800322 /* Workaround for MDP HW limitation in DSI command mode panels where
323 * FPS will not go beyond 30 if buffers on RGB pipes are of width or height
324 * less than 5 pixels
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530325 * There also is a HW limilation in MDP, minimum block size is 2x2
326 * Fallback to GPU if height is less than 2.
327 */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800328 if((crop_w < 5)||(crop_h < 5))
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800329 return false;
330
Saurabh Shah4fdde762013-04-30 18:47:33 -0700331 const uint32_t downscale =
332 qdutils::MDPVersion::getInstance().getMaxMDPDownscale();
333 if(ctx->mMDP.version >= qdutils::MDSS_V5) {
334 /* Workaround for downscales larger than 4x.
335 * Will be removed once decimator block is enabled for MDSS
336 */
337 if(!qdutils::MDPVersion::getInstance().supportsDecimation()) {
338 if(crop_w > MAX_DISPLAY_DIM || w_dscale > downscale ||
339 h_dscale > downscale)
340 return false;
341 } else {
342 if(w_dscale > 64 || h_dscale > 64)
343 return false;
344 }
345 } else { //A-family
346 if(w_dscale > downscale || h_dscale > downscale)
347 return false;
348 }
349
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800350 return true;
351}
352
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700353ovutils::eDest MDPComp::getMdpPipe(hwc_context_t *ctx, ePipeType type,
354 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800355 overlay::Overlay& ov = *ctx->mOverlay;
356 ovutils::eDest mdp_pipe = ovutils::OV_INVALID;
357
358 switch(type) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800359 case MDPCOMP_OV_DMA:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700360 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_DMA, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800361 if(mdp_pipe != ovutils::OV_INVALID) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800362 return mdp_pipe;
363 }
364 case MDPCOMP_OV_ANY:
365 case MDPCOMP_OV_RGB:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700366 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800367 if(mdp_pipe != ovutils::OV_INVALID) {
368 return mdp_pipe;
369 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800370
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800371 if(type == MDPCOMP_OV_RGB) {
372 //Requested only for RGB pipe
373 break;
374 }
375 case MDPCOMP_OV_VG:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700376 return ov.nextPipe(ovutils::OV_MDP_PIPE_VG, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800377 default:
378 ALOGE("%s: Invalid pipe type",__FUNCTION__);
379 return ovutils::OV_INVALID;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800380 };
381 return ovutils::OV_INVALID;
382}
383
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800384bool MDPComp::isFrameDoable(hwc_context_t *ctx) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700385 bool ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700386 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800387
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800388 if(!isEnabled()) {
389 ALOGD_IF(isDebug(),"%s: MDP Comp. not enabled.", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700390 ret = false;
Saurabh Shahd4e65852013-06-17 11:33:53 -0700391 } else if(qdutils::MDPVersion::getInstance().is8x26() &&
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700392 ctx->mVideoTransFlag && ctx->mVirtualDisplay->isConnected()) {
Saurabh Shahd4e65852013-06-17 11:33:53 -0700393 //1 Padding round to shift pipes across mixers
394 ALOGD_IF(isDebug(),"%s: MDP Comp. video transition padding round",
395 __FUNCTION__);
396 ret = false;
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700397 } else if(ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isConfiguring ||
398 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isConfiguring) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800399 ALOGD_IF( isDebug(),"%s: External Display connection is pending",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800400 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700401 ret = false;
Saurabh Shahaa236822013-04-24 18:07:26 -0700402 } else if(ctx->isPaddingRound) {
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700403 ctx->isPaddingRound = false;
404 ALOGD_IF(isDebug(), "%s: padding round",__FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700405 ret = false;
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700406 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700407 return ret;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800408}
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
417 for(int i = 0; i < numAppLayers; i++){
418 const hwc_layer_1_t* layer = &list->hwLayers[i];
419
420 hwc_rect_t dstRect = layer->displayFrame;
Arun Kumar K.R91090c72013-10-28 19:40:18 -0700421 hwc_rect_t srcRect = integerizeSourceCrop(layer->sourceCropf);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700422 int transform = layer->transform;
423 trimLayer(ctx, mDpy, transform, srcRect, dstRect);
424
425 hwc_rect_t res = getIntersection(roi, dstRect);
426
427 int res_w = res.right - res.left;
428 int res_h = res.bottom - res.top;
429 int dst_w = dstRect.right - dstRect.left;
430 int dst_h = dstRect.bottom - dstRect.top;
431
432 if(!isValidRect(res)) {
433 mCurrentFrame.drop[i] = true;
434 mCurrentFrame.dropCount++;
435 }else {
436 /* Reset frame ROI when any layer which needs scaling also needs ROI
437 * cropping */
438 if((res_w != dst_w || res_h != dst_h) &&
439 needsScaling (ctx, layer, mDpy)) {
440 ALOGE("%s: Resetting ROI due to scaling", __FUNCTION__);
441 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
442 mCurrentFrame.dropCount = 0;
443 return false;
444 }
445 }
446 }
447 return true;
448}
449
450void MDPComp::generateROI(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
451 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
452
453 if(!sEnablePartialFrameUpdate) {
454 return;
455 }
456
457 if(mDpy || isDisplaySplit(ctx, mDpy)){
458 ALOGE_IF(isDebug(), "%s: ROI not supported for"
459 "the (1) external / virtual display's (2) dual DSI displays",
460 __FUNCTION__);
461 return;
462 }
463
464 if(list->flags & HWC_GEOMETRY_CHANGED)
465 return;
466
467 struct hwc_rect roi = (struct hwc_rect){0, 0, 0, 0};
468 for(int index = 0; index < numAppLayers; index++ ) {
469 if ((mCachedFrame.hnd[index] != list->hwLayers[index].handle) ||
470 isYuvBuffer((private_handle_t *)list->hwLayers[index].handle)) {
471 hwc_rect_t dstRect = list->hwLayers[index].displayFrame;
Arun Kumar K.R91090c72013-10-28 19:40:18 -0700472 hwc_rect_t srcRect = integerizeSourceCrop(
473 list->hwLayers[index].sourceCropf);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700474 int transform = list->hwLayers[index].transform;
475
476 /* Intersect against display boundaries */
477 trimLayer(ctx, mDpy, transform, srcRect, dstRect);
478 roi = getUnion(roi, dstRect);
479 }
480 }
481
482 if(!validateAndApplyROI(ctx, list, roi)){
483 roi = (struct hwc_rect) {0, 0,
484 (int)ctx->dpyAttr[mDpy].xres, (int)ctx->dpyAttr[mDpy].yres};
485 }
486
487 ctx->listStats[mDpy].roi.x = roi.left;
488 ctx->listStats[mDpy].roi.y = roi.top;
489 ctx->listStats[mDpy].roi.w = roi.right - roi.left;
490 ctx->listStats[mDpy].roi.h = roi.bottom - roi.top;
491
492 ALOGD_IF(isDebug(),"%s: generated ROI: [%d, %d, %d, %d]", __FUNCTION__,
493 roi.left, roi.top, roi.right, roi.bottom);
494}
495
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800496/* Checks for conditions where all the layers marked for MDP comp cannot be
497 * bypassed. On such conditions we try to bypass atleast YUV layers */
498bool MDPComp::isFullFrameDoable(hwc_context_t *ctx,
499 hwc_display_contents_1_t* list){
500
Saurabh Shahaa236822013-04-24 18:07:26 -0700501 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800502
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -0700503 if(sIdleFallBack && !ctx->listStats[mDpy].secureUI) {
Saurabh Shah2d998a92013-05-14 17:55:58 -0700504 ALOGD_IF(isDebug(), "%s: Idle fallback dpy %d",__FUNCTION__, mDpy);
505 return false;
506 }
507
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800508 if(isSkipPresent(ctx, mDpy)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700509 ALOGD_IF(isDebug(),"%s: SKIP present: %d",
510 __FUNCTION__,
511 isSkipPresent(ctx, mDpy));
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800512 return false;
513 }
514
Saurabh Shah9f084ad2013-05-02 11:28:09 -0700515 if(ctx->listStats[mDpy].needsAlphaScale
516 && ctx->mMDP.version < qdutils::MDSS_V5) {
517 ALOGD_IF(isDebug(), "%s: frame needs alpha downscaling",__FUNCTION__);
518 return false;
519 }
520
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800521 for(int i = 0; i < numAppLayers; ++i) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800522 hwc_layer_1_t* layer = &list->hwLayers[i];
523 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800524
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700525 if(isYuvBuffer(hnd) && has90Transform(layer)) {
526 if(!canUseRotator(ctx, mDpy)) {
527 ALOGD_IF(isDebug(), "%s: Can't use rotator for dpy %d",
528 __FUNCTION__, mDpy);
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700529 return false;
530 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800531 }
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530532
533 //For 8x26 with panel width>1k, if RGB layer needs HFLIP fail mdp comp
534 // may not need it if Gfx pre-rotation can handle all flips & rotations
535 if(qdutils::MDPVersion::getInstance().is8x26() &&
536 (ctx->dpyAttr[mDpy].xres > 1024) &&
537 (layer->transform & HWC_TRANSFORM_FLIP_H) &&
538 (!isYuvBuffer(hnd)))
539 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800540 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700541
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700542 if(ctx->mAD->isDoable()) {
543 return false;
544 }
545
Saurabh Shahaa236822013-04-24 18:07:26 -0700546 //If all above hard conditions are met we can do full or partial MDP comp.
547 bool ret = false;
548 if(fullMDPComp(ctx, list)) {
549 ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700550 } else if(partialMDPComp(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700551 ret = true;
552 }
553 return ret;
554}
555
556bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700557 //Will benefit presentation / secondary-only layer.
558 if((mDpy > HWC_DISPLAY_PRIMARY) &&
559 (list->numHwLayers - 1) > MAX_SEC_LAYERS) {
560 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
561 return false;
562 }
563
564 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
565 for(int i = 0; i < numAppLayers; i++) {
566 hwc_layer_1_t* layer = &list->hwLayers[i];
567 if(not isSupportedForMDPComp(ctx, layer)) {
568 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",__FUNCTION__);
569 return false;
570 }
571 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700572 mCurrentFrame.fbCount = 0;
573 mCurrentFrame.fbZ = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700574 memcpy(&mCurrentFrame.isFBComposed, &mCurrentFrame.drop,
575 sizeof(mCurrentFrame.isFBComposed));
576 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount -
577 mCurrentFrame.dropCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700578
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700579 if(mCurrentFrame.mdpCount > sMaxPipesPerMixer) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700580 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
581 return false;
582 }
583
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700584 if(!arePipesAvailable(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700585 return false;
586 }
587
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700588 uint32_t size = calcMDPBytesRead(ctx, list);
589 if(!bandwidthCheck(ctx, size)) {
590 ALOGD_IF(isDebug(), "%s: Exceeds bandwidth",__FUNCTION__);
591 return false;
592 }
593
Saurabh Shahaa236822013-04-24 18:07:26 -0700594 return true;
595}
596
597bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
598{
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700599 if(!sEnableMixedMode) {
600 //Mixed mode is disabled. No need to even try caching.
601 return false;
602 }
603
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700604 bool ret = false;
605 if(isLoadBasedCompDoable(ctx, list)) {
606 ret = loadBasedComp(ctx, list);
607 }
608
609 if(!ret) {
610 ret = cacheBasedComp(ctx, list);
611 }
612
613 return ret;
614}
615
616bool MDPComp::cacheBasedComp(hwc_context_t *ctx,
617 hwc_display_contents_1_t* list) {
618 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700619 mCurrentFrame.reset(numAppLayers);
620 updateLayerCache(ctx, list);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700621
622 //If an MDP marked layer is unsupported cannot do partial MDP Comp
623 for(int i = 0; i < numAppLayers; i++) {
624 if(!mCurrentFrame.isFBComposed[i]) {
625 hwc_layer_1_t* layer = &list->hwLayers[i];
626 if(not isSupportedForMDPComp(ctx, layer)) {
627 ALOGD_IF(isDebug(), "%s: Unsupported layer in list",
628 __FUNCTION__);
629 return false;
630 }
631 }
632 }
633
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700634 updateYUV(ctx, list, false /*secure only*/);
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530635 bool ret = markLayersForCaching(ctx, list); //sets up fbZ also
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700636 if(!ret) {
637 ALOGD_IF(isDebug(),"%s: batching failed, dpy %d",__FUNCTION__, mDpy);
638 return false;
639 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700640
641 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700642
643 //Will benefit cases where a video has non-updating background.
644 if((mDpy > HWC_DISPLAY_PRIMARY) and
645 (mdpCount > MAX_SEC_LAYERS)) {
646 ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
647 return false;
648 }
649
Saurabh Shahaa236822013-04-24 18:07:26 -0700650 if(mdpCount > (sMaxPipesPerMixer - 1)) { // -1 since FB is used
651 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
652 return false;
653 }
654
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700655 if(!arePipesAvailable(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700656 return false;
657 }
658
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700659 uint32_t size = calcMDPBytesRead(ctx, list);
660 if(!bandwidthCheck(ctx, size)) {
661 ALOGD_IF(isDebug(), "%s: Exceeds bandwidth",__FUNCTION__);
662 return false;
663 }
664
Saurabh Shahaa236822013-04-24 18:07:26 -0700665 return true;
666}
667
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700668bool MDPComp::loadBasedComp(hwc_context_t *ctx,
669 hwc_display_contents_1_t* list) {
670 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
671 mCurrentFrame.reset(numAppLayers);
672
673 //TODO BatchSize could be optimized further based on available pipes, split
674 //displays etc.
675 const int batchSize = numAppLayers - (sMaxPipesPerMixer - 1);
676 if(batchSize <= 0) {
677 ALOGD_IF(isDebug(), "%s: Not attempting", __FUNCTION__);
678 return false;
679 }
680
681 int minBatchStart = -1;
682 size_t minBatchPixelCount = SIZE_MAX;
683
684 for(int i = 0; i <= numAppLayers - batchSize; i++) {
685 uint32_t batchPixelCount = 0;
686 for(int j = i; j < i + batchSize; j++) {
687 hwc_layer_1_t* layer = &list->hwLayers[j];
Arun Kumar K.R91090c72013-10-28 19:40:18 -0700688 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700689 batchPixelCount += (crop.right - crop.left) *
690 (crop.bottom - crop.top);
691 }
692
693 if(batchPixelCount < minBatchPixelCount) {
694 minBatchPixelCount = batchPixelCount;
695 minBatchStart = i;
696 }
697 }
698
699 if(minBatchStart < 0) {
700 ALOGD_IF(isDebug(), "%s: No batch found batchSize %d numAppLayers %d",
701 __FUNCTION__, batchSize, numAppLayers);
702 return false;
703 }
704
705 for(int i = 0; i < numAppLayers; i++) {
706 if(i < minBatchStart || i >= minBatchStart + batchSize) {
707 hwc_layer_1_t* layer = &list->hwLayers[i];
708 if(not isSupportedForMDPComp(ctx, layer)) {
709 ALOGD_IF(isDebug(), "%s: MDP unsupported layer found at %d",
710 __FUNCTION__, i);
711 return false;
712 }
713 mCurrentFrame.isFBComposed[i] = false;
714 }
715 }
716
717 mCurrentFrame.fbZ = minBatchStart;
718 mCurrentFrame.fbCount = batchSize;
719 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - batchSize;
720
721 if(!arePipesAvailable(ctx, list)) {
722 return false;
723 }
724
725 ALOGD_IF(isDebug(), "%s: fbZ %d batchSize %d",
726 __FUNCTION__, mCurrentFrame.fbZ, batchSize);
727 return true;
728}
729
730bool MDPComp::isLoadBasedCompDoable(hwc_context_t *ctx,
731 hwc_display_contents_1_t* list) {
732 if(mDpy or isSecurePresent(ctx, mDpy) or
733 not (list->flags & HWC_GEOMETRY_CHANGED)) {
734 return false;
735 }
736 return true;
737}
738
Saurabh Shahaa236822013-04-24 18:07:26 -0700739bool MDPComp::isOnlyVideoDoable(hwc_context_t *ctx,
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700740 hwc_display_contents_1_t* list, bool secureOnly) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700741 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700742
Saurabh Shahaa236822013-04-24 18:07:26 -0700743 mCurrentFrame.reset(numAppLayers);
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700744 updateYUV(ctx, list, secureOnly);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700745 int mdpCount = mCurrentFrame.mdpCount;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700746 int fbNeeded = (mCurrentFrame.fbCount != 0);
Saurabh Shahaa236822013-04-24 18:07:26 -0700747
748 if(!isYuvPresent(ctx, mDpy)) {
749 return false;
750 }
751
Saurabh Shah4fdde762013-04-30 18:47:33 -0700752 if(!mdpCount)
753 return false;
754
Saurabh Shahaa236822013-04-24 18:07:26 -0700755 if(mdpCount > (sMaxPipesPerMixer - fbNeeded)) {
756 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
757 return false;
758 }
759
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700760 if(!arePipesAvailable(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700761 return false;
762 }
763
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700764 uint32_t size = calcMDPBytesRead(ctx, list);
765 if(!bandwidthCheck(ctx, size)) {
766 ALOGD_IF(isDebug(), "%s: Exceeds bandwidth",__FUNCTION__);
767 return false;
768 }
769
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800770 return true;
771}
772
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800773/* Checks for conditions where YUV layers cannot be bypassed */
774bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Saurabh Shahe2474082013-05-15 16:32:13 -0700775 bool extAnimBlockFeature = mDpy && ctx->listStats[mDpy].isDisplayAnimating;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800776
Saurabh Shahe2474082013-05-15 16:32:13 -0700777 if(isSkipLayer(layer) && !extAnimBlockFeature) {
778 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800779 return false;
780 }
781
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700782 if(layer->transform & HWC_TRANSFORM_ROT_90 && !canUseRotator(ctx,mDpy)) {
783 ALOGD_IF(isDebug(), "%s: no free DMA pipe",__FUNCTION__);
784 return false;
785 }
786
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800787 if(isSecuring(ctx, layer)) {
788 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
789 return false;
790 }
791
Saurabh Shah4fdde762013-04-30 18:47:33 -0700792 if(!isValidDimension(ctx, layer)) {
793 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
794 __FUNCTION__);
795 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800796 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700797
Naseer Ahmeddc61a972013-07-10 17:50:54 -0400798 if(layer->planeAlpha < 0xFF) {
799 ALOGD_IF(isDebug(), "%s: Cannot handle YUV layer with plane alpha\
800 in video only mode",
801 __FUNCTION__);
802 return false;
803 }
804
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800805 return true;
806}
807
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530808/* starts at fromIndex and check for each layer to find
809 * if it it has overlapping with any Updating layer above it in zorder
810 * till the end of the batch. returns true if it finds any intersection */
811bool MDPComp::canPushBatchToTop(const hwc_display_contents_1_t* list,
812 int fromIndex, int toIndex) {
813 for(int i = fromIndex; i < toIndex; i++) {
814 if(mCurrentFrame.isFBComposed[i] && !mCurrentFrame.drop[i]) {
815 if(intersectingUpdatingLayers(list, i+1, toIndex, i)) {
816 return false;
817 }
818 }
819 }
820 return true;
821}
822
823/* Checks if given layer at targetLayerIndex has any
824 * intersection with all the updating layers in beween
825 * fromIndex and toIndex. Returns true if it finds intersectiion */
826bool MDPComp::intersectingUpdatingLayers(const hwc_display_contents_1_t* list,
827 int fromIndex, int toIndex, int targetLayerIndex) {
828 for(int i = fromIndex; i <= toIndex; i++) {
829 if(!mCurrentFrame.isFBComposed[i]) {
830 if(areLayersIntersecting(&list->hwLayers[i],
831 &list->hwLayers[targetLayerIndex])) {
832 return true;
833 }
834 }
835 }
836 return false;
837}
838
839int MDPComp::getBatch(hwc_display_contents_1_t* list,
840 int& maxBatchStart, int& maxBatchEnd,
841 int& maxBatchCount) {
842 int i = 0;
843 int updatingLayersAbove = 0;//Updating layer count in middle of batch
844 int fbZOrder =-1;
845 while (i < mCurrentFrame.layerCount) {
846 int batchCount = 0;
847 int batchStart = i;
848 int batchEnd = i;
849 int fbZ = batchStart;
850 int firstZReverseIndex = -1;
851 while(i < mCurrentFrame.layerCount) {
852 if(!mCurrentFrame.isFBComposed[i]) {
853 if(!batchCount) {
854 i++;
855 break;
856 }
857 updatingLayersAbove++;
858 i++;
859 continue;
860 } else {
861 if(mCurrentFrame.drop[i]) {
862 i++;
863 continue;
864 } else if(updatingLayersAbove <= 0) {
865 batchCount++;
866 batchEnd = i;
867 i++;
868 continue;
869 } else { //Layer is FBComposed, not a drop & updatingLayer > 0
870
871 // We have a valid updating layer already. If layer-i not
872 // have overlapping with all updating layers in between
873 // batch-start and i, then we can add layer i to batch.
874 if(!intersectingUpdatingLayers(list, batchStart, i-1, i)) {
875 batchCount++;
876 batchEnd = i;
877 i++;
878 continue;
879 } else if(canPushBatchToTop(list, batchStart, i)) {
880 //If All the non-updating layers with in this batch
881 //does not have intersection with the updating layers
882 //above in z-order, then we can safely move the batch to
883 //higher z-order. Increment fbZ as it is moving up.
884 if( firstZReverseIndex < 0) {
885 firstZReverseIndex = i;
886 }
887 batchCount++;
888 batchEnd = i;
889 fbZ += updatingLayersAbove;
890 i++;
891 updatingLayersAbove = 0;
892 continue;
893 } else {
894 //both failed.start the loop again from here.
895 if(firstZReverseIndex >= 0) {
896 i = firstZReverseIndex;
897 }
898 break;
899 }
900 }
901 }
902 }
903 if(batchCount > maxBatchCount) {
904 maxBatchCount = batchCount;
905 maxBatchStart = batchStart;
906 maxBatchEnd = batchEnd;
907 fbZOrder = fbZ;
908 }
909 }
910 return fbZOrder;
911}
912
913bool MDPComp::markLayersForCaching(hwc_context_t* ctx,
914 hwc_display_contents_1_t* list) {
915 /* Idea is to keep as many non-updating(cached) layers in FB and
916 * send rest of them through MDP. This is done in 2 steps.
917 * 1. Find the maximum contiguous batch of non-updating layers.
918 * 2. See if we can improve this batch size for caching by adding
919 * opaque layers around the batch, if they don't have
920 * any overlapping with the updating layers in between.
921 * NEVER mark an updating layer for caching.
922 * But cached ones can be marked for MDP */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800923
924 int maxBatchStart = -1;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700925 int maxBatchEnd = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800926 int maxBatchCount = 0;
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530927 int fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800928
929 /* All or Nothing is cached. No batching needed */
Saurabh Shahaa236822013-04-24 18:07:26 -0700930 if(!mCurrentFrame.fbCount) {
931 mCurrentFrame.fbZ = -1;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700932 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -0700933 }
934 if(!mCurrentFrame.mdpCount) {
935 mCurrentFrame.fbZ = 0;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700936 return true;
Saurabh Shahaa236822013-04-24 18:07:26 -0700937 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800938
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530939 fbZ = getBatch(list, maxBatchStart, maxBatchEnd, maxBatchCount);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800940
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530941 /* reset rest of the layers lying inside ROI for MDP comp */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800942 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700943 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700944 if((i < maxBatchStart || i > maxBatchEnd) &&
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530945 mCurrentFrame.isFBComposed[i]){
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700946 if(!mCurrentFrame.drop[i]){
947 //If an unsupported layer is being attempted to
948 //be pulled out we should fail
949 if(not isSupportedForMDPComp(ctx, layer)) {
950 return false;
951 }
952 mCurrentFrame.isFBComposed[i] = false;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700953 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800954 }
955 }
956
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530957 // update the frame data
958 mCurrentFrame.fbZ = fbZ;
959 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700960 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700961 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800962
963 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530964 mCurrentFrame.fbCount);
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700965
966 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800967}
Saurabh Shah85234ec2013-04-12 17:09:00 -0700968
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800969void MDPComp::updateLayerCache(hwc_context_t* ctx,
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700970 hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800971 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700972 int fbCount = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800973
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800974 for(int i = 0; i < numAppLayers; i++) {
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700975 hwc_layer_1_t* layer = &list->hwLayers[i];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800976 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700977 if(!mCurrentFrame.drop[i])
978 fbCount++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800979 mCurrentFrame.isFBComposed[i] = true;
980 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -0700981 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800982 }
983 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700984
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700985 mCurrentFrame.fbCount = fbCount;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700986 mCurrentFrame.mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount
987 - mCurrentFrame.dropCount;
Saurabh Shahe9bc60f2013-08-29 12:58:06 -0700988
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700989 ALOGD_IF(isDebug(),"%s: MDP count: %d FB count %d drop count: %d"
990 ,__FUNCTION__, mCurrentFrame.mdpCount, mCurrentFrame.fbCount,
991 mCurrentFrame.dropCount);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800992}
993
Saurabh Shah90b7b9b2013-09-12 16:36:08 -0700994void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list,
995 bool secureOnly) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800996 int nYuvCount = ctx->listStats[mDpy].yuvCount;
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700997 if(!nYuvCount && mDpy) {
998 //Reset "No animation on external display" related parameters.
999 ctx->mPrevCropVideo.left = ctx->mPrevCropVideo.top =
1000 ctx->mPrevCropVideo.right = ctx->mPrevCropVideo.bottom = 0;
1001 ctx->mPrevDestVideo.left = ctx->mPrevDestVideo.top =
1002 ctx->mPrevDestVideo.right = ctx->mPrevDestVideo.bottom = 0;
1003 ctx->mPrevTransformVideo = 0;
1004 return;
1005 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001006 for(int index = 0;index < nYuvCount; index++){
1007 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
1008 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
1009
1010 if(!isYUVDoable(ctx, layer)) {
1011 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
1012 mCurrentFrame.isFBComposed[nYuvIndex] = true;
1013 mCurrentFrame.fbCount++;
1014 }
1015 } else {
1016 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001017 private_handle_t *hnd = (private_handle_t *)layer->handle;
1018 if(!secureOnly || isSecureBuffer(hnd)) {
1019 mCurrentFrame.isFBComposed[nYuvIndex] = false;
1020 mCurrentFrame.fbCount--;
1021 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001022 }
1023 }
1024 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001025
1026 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001027 mCurrentFrame.fbCount - mCurrentFrame.dropCount;
1028 ALOGD_IF(isDebug(),"%s: fb count: %d",__FUNCTION__,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001029 mCurrentFrame.fbCount);
1030}
1031
Saurabh Shahaa236822013-04-24 18:07:26 -07001032bool MDPComp::programMDP(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001033 if(!allocLayerPipes(ctx, list)) {
1034 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -07001035 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001036 }
1037
1038 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -07001039 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001040 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001041 int mdpIndex = mCurrentFrame.layerToMDP[index];
1042 hwc_layer_1_t* layer = &list->hwLayers[index];
1043
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301044 //Leave fbZ for framebuffer. CACHE/GLES layers go here.
1045 if(mdpNextZOrder == mCurrentFrame.fbZ) {
1046 mdpNextZOrder++;
1047 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001048 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1049 cur_pipe->zOrder = mdpNextZOrder++;
1050
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301051
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001052 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
1053 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
1054 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -07001055 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001056 }
Saurabh Shahaa236822013-04-24 18:07:26 -07001057 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001058 }
1059
Saurabh Shahaa236822013-04-24 18:07:26 -07001060 return true;
1061}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001062
Saurabh Shahaa236822013-04-24 18:07:26 -07001063bool MDPComp::programYUV(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
1064 if(!allocLayerPipes(ctx, list)) {
1065 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
1066 return false;
1067 }
1068 //If we are in this block, it means we have yuv + rgb layers both
1069 int mdpIdx = 0;
1070 for (int index = 0; index < mCurrentFrame.layerCount; index++) {
1071 if(!mCurrentFrame.isFBComposed[index]) {
1072 hwc_layer_1_t* layer = &list->hwLayers[index];
1073 int mdpIndex = mCurrentFrame.layerToMDP[index];
1074 MdpPipeInfo* cur_pipe =
1075 mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1076 cur_pipe->zOrder = mdpIdx++;
1077
1078 if(configure(ctx, layer,
1079 mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
1080 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
1081 layer %d",__FUNCTION__, index);
1082 return false;
1083 }
1084 }
1085 }
1086 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001087}
1088
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001089uint32_t MDPComp::calcMDPBytesRead(hwc_context_t *ctx,
1090 hwc_display_contents_1_t* list) {
1091 uint32_t size = 0;
1092
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001093 if(!qdutils::MDPVersion::getInstance().is8x74v2())
1094 return 0;
1095
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001096 for (uint32_t i = 0; i < list->numHwLayers - 1; i++) {
1097 if(!mCurrentFrame.isFBComposed[i]) {
1098 hwc_layer_1_t* layer = &list->hwLayers[i];
1099 private_handle_t *hnd = (private_handle_t *)layer->handle;
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001100 if (hnd) {
Saurabh Shah62e1d732013-09-17 10:44:05 -07001101 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shah90789162013-09-16 10:29:20 -07001102 hwc_rect_t dst = layer->displayFrame;
1103 trimLayer(ctx, mDpy, layer->transform, crop, dst);
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001104 float bpp = ((float)hnd->size) / (hnd->width * hnd->height);
Saurabh Shah90789162013-09-16 10:29:20 -07001105 size += bpp * (crop.right - crop.left) *
1106 (crop.bottom - crop.top) *
1107 ctx->dpyAttr[mDpy].yres / (dst.bottom - dst.top);
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001108 }
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001109 }
1110 }
1111
1112 if(mCurrentFrame.fbCount) {
1113 hwc_layer_1_t* layer = &list->hwLayers[list->numHwLayers - 1];
1114 private_handle_t *hnd = (private_handle_t *)layer->handle;
Terence Hampson9cd5fa92013-09-10 17:06:37 -04001115 if (hnd)
1116 size += hnd->size;
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001117 }
1118
1119 return size;
1120}
1121
1122bool MDPComp::bandwidthCheck(hwc_context_t *ctx, const uint32_t& size) {
1123 //Will be added for other targets if we run into bandwidth issues and when
1124 //we have profiling data to set an upper limit.
1125 if(qdutils::MDPVersion::getInstance().is8x74v2()) {
1126 const uint32_t ONE_GIG = 1024 * 1024 * 1024;
1127 double panelRefRate =
1128 1000000000.0 / ctx->dpyAttr[mDpy].vsync_period;
1129 if((size + sCompBytesClaimed) > ((sMaxBw / panelRefRate) * ONE_GIG)) {
1130 return false;
1131 }
1132 }
1133 return true;
1134}
1135
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001136int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001137 int ret = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -07001138 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -07001139
Saurabh Shahb39f8152013-08-22 10:21:44 -07001140 //reset old data
1141 mCurrentFrame.reset(numLayers);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001142 memset(&mCurrentFrame.drop, 0, sizeof(mCurrentFrame.drop));
1143 mCurrentFrame.dropCount = 0;
Prabhanjan Kandula088bd892013-07-02 23:47:13 +05301144
Saurabh Shahb39f8152013-08-22 10:21:44 -07001145 //number of app layers exceeds MAX_NUM_APP_LAYERS fall back to GPU
1146 //do not cache the information for next draw cycle.
1147 if(numLayers > MAX_NUM_APP_LAYERS) {
Prabhanjan Kandula25469a52013-07-12 16:19:31 +05301148 mCachedFrame.updateCounts(mCurrentFrame);
Tatenda Chipeperekwa835337a2013-09-27 16:58:43 -07001149 ALOGE("%s: Number of App layers exceeded the limit ",
1150 __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001151 ret = -1;
Tatenda Chipeperekwa835337a2013-09-27 16:58:43 -07001152 return ret;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001153 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001154
Saurabh Shahb39f8152013-08-22 10:21:44 -07001155 //Hard conditions, if not met, cannot do MDP comp
1156 if(!isFrameDoable(ctx)) {
1157 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
1158 __FUNCTION__);
1159 reset(numLayers, list);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001160 ret = -1;
1161 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001162 }
1163
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001164 generateROI(ctx, list);
1165
Saurabh Shahb39f8152013-08-22 10:21:44 -07001166 //Check whether layers marked for MDP Composition is actually doable.
1167 if(isFullFrameDoable(ctx, list)) {
1168 mCurrentFrame.map();
1169 //Configure framebuffer first if applicable
1170 if(mCurrentFrame.fbZ >= 0) {
1171 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list,
1172 mCurrentFrame.fbZ)) {
1173 ALOGE("%s configure framebuffer failed", __func__);
1174 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -07001175 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001176 ret = -1;
1177 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001178 }
1179 }
1180 //Acquire and Program MDP pipes
1181 if(!programMDP(ctx, list)) {
1182 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -07001183 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001184 ret = -1;
1185 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001186 } else { //Success
1187 //Any change in composition types needs an FB refresh
1188 mCurrentFrame.needsRedraw = false;
Jeykumar Sankaran988d3682013-11-15 11:57:16 -08001189 if(!mCachedFrame.isSameFrame(mCurrentFrame, list) ||
Saurabh Shahb39f8152013-08-22 10:21:44 -07001190 (list->flags & HWC_GEOMETRY_CHANGED) ||
Prabhanjan Kandula2243aa62013-10-24 12:58:55 +05301191 isSkipPresent(ctx, mDpy)) {
Saurabh Shahb39f8152013-08-22 10:21:44 -07001192 mCurrentFrame.needsRedraw = true;
1193 }
1194 }
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001195 } else if(isOnlyVideoDoable(ctx, list, false /*secure only*/) ||
1196 isOnlyVideoDoable(ctx, list, true /*secure only*/)) {
Saurabh Shahb39f8152013-08-22 10:21:44 -07001197 //All layers marked for MDP comp cannot be bypassed.
1198 //Try to compose atleast YUV layers through MDP comp and let
1199 //all the RGB layers compose in FB
1200 //Destination over
1201 mCurrentFrame.fbZ = -1;
1202 if(mCurrentFrame.fbCount)
1203 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
1204
1205 mCurrentFrame.map();
1206
1207 //Configure framebuffer first if applicable
1208 if(mCurrentFrame.fbZ >= 0) {
1209 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, mCurrentFrame.fbZ)) {
1210 ALOGE("%s configure framebuffer failed", __func__);
1211 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -07001212 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001213 ret = -1;
1214 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001215 }
1216 }
1217 if(!programYUV(ctx, list)) {
1218 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -07001219 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001220 ret = -1;
1221 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001222 }
1223 } else {
1224 reset(numLayers, list);
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001225 ret = -1;
1226 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -07001227 }
1228
1229 //UpdateLayerFlags
1230 setMDPCompLayerFlags(ctx, list);
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -07001231 mCachedFrame.cacheAll(list);
Saurabh Shahb39f8152013-08-22 10:21:44 -07001232 mCachedFrame.updateCounts(mCurrentFrame);
1233
Prabhanjan Kandula25469a52013-07-12 16:19:31 +05301234 // unlock it before calling dump function to avoid deadlock
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001235 if(isDebug()) {
Saurabh Shahaa236822013-04-24 18:07:26 -07001236 ALOGD("GEOMETRY change: %d", (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001237 android::String8 sDump("");
1238 dump(sDump);
1239 ALOGE("%s",sDump.string());
1240 }
1241
Saurabh Shah8c5c8522013-08-29 17:32:49 -07001242exit:
1243 sCompBytesClaimed += calcMDPBytesRead(ctx, list);
1244 return ret;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001245}
1246
Saurabh Shah88e4d272013-09-03 13:31:29 -07001247//=============MDPCompNonSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001248
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001249/*
1250 * Configures pipe(s) for MDP composition
1251 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001252int MDPCompNonSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001253 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001254 MdpPipeInfoNonSplit& mdp_info =
1255 *(static_cast<MdpPipeInfoNonSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001256 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
1257 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1258 eIsFg isFg = IS_FG_OFF;
1259 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001260
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001261 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
1262 __FUNCTION__, layer, zOrder, dest);
1263
Saurabh Shah88e4d272013-09-03 13:31:29 -07001264 return configureNonSplit(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001265 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001266}
1267
Saurabh Shah88e4d272013-09-03 13:31:29 -07001268bool MDPCompNonSplit::arePipesAvailable(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001269 hwc_display_contents_1_t* list) {
1270 overlay::Overlay& ov = *ctx->mOverlay;
1271 int numPipesNeeded = mCurrentFrame.mdpCount;
1272 int availPipes = ov.availablePipes(mDpy, Overlay::MIXER_DEFAULT);
1273
1274 //Reserve pipe for FB
1275 if(mCurrentFrame.fbCount)
1276 availPipes -= 1;
1277
1278 if(numPipesNeeded > availPipes) {
1279 ALOGD_IF(isDebug(), "%s: Insufficient pipes, dpy %d needed %d, avail %d",
1280 __FUNCTION__, mDpy, numPipesNeeded, availPipes);
1281 return false;
1282 }
1283
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001284 if(not areVGPipesAvailable(ctx, list)) {
1285 return false;
1286 }
1287
1288 return true;
1289}
1290
1291bool MDPCompNonSplit::areVGPipesAvailable(hwc_context_t *ctx,
1292 hwc_display_contents_1_t* list) {
1293 overlay::Overlay& ov = *ctx->mOverlay;
1294 int pipesNeeded = 0;
1295 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1296 if(!mCurrentFrame.isFBComposed[i]) {
1297 hwc_layer_1_t* layer = &list->hwLayers[i];
1298 hwc_rect_t dst = layer->displayFrame;
1299 private_handle_t *hnd = (private_handle_t *)layer->handle;
1300 if(isYuvBuffer(hnd)) {
1301 pipesNeeded++;
1302 }
1303 }
1304 }
1305
1306 int availableVGPipes = ov.availablePipes(mDpy, ovutils::OV_MDP_PIPE_VG);
1307 if(pipesNeeded > availableVGPipes) {
1308 ALOGD_IF(isDebug(), "%s: Insufficient VG pipes for video layers"
1309 "dpy %d needed %d, avail %d",
1310 __FUNCTION__, mDpy, pipesNeeded, availableVGPipes);
1311 return false;
1312 }
1313
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001314 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001315}
1316
Saurabh Shah88e4d272013-09-03 13:31:29 -07001317bool MDPCompNonSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001318 hwc_display_contents_1_t* list) {
1319 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001320
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001321 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001322
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001323 hwc_layer_1_t* layer = &list->hwLayers[index];
1324 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001325 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001326 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001327 info.pipeInfo = new MdpPipeInfoNonSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08001328 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001329 MdpPipeInfoNonSplit& pipe_info = *(MdpPipeInfoNonSplit*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001330 ePipeType type = MDPCOMP_OV_ANY;
1331
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001332 if(isYuvBuffer(hnd)) {
1333 type = MDPCOMP_OV_VG;
Saurabh Shah8a117932013-05-23 12:48:13 -07001334 } else if(!qhwc::needsScaling(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001335 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
1336 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -08001337 type = MDPCOMP_OV_DMA;
1338 }
1339
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001340 pipe_info.index = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001341 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001342 ALOGD_IF(isDebug(), "%s: Unable to get pipe type = %d",
1343 __FUNCTION__, (int) type);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001344 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001345 }
1346 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001347 return true;
1348}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001349
Saurabh Shah88e4d272013-09-03 13:31:29 -07001350bool MDPCompNonSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001351
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001352 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001353 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1354 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -08001355 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001356
1357 if(!ctx || !list) {
1358 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001359 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001360 }
1361
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301362 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1363 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1364 return true;
1365 }
1366
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001367 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001368 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001369 idleInvalidator->markForSleep();
1370
1371 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001372 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001373
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001374 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1375 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001376 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001377 if(mCurrentFrame.isFBComposed[i]) continue;
1378
Naseer Ahmed5b6708a2012-08-02 13:46:08 -07001379 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001380 private_handle_t *hnd = (private_handle_t *)layer->handle;
1381 if(!hnd) {
1382 ALOGE("%s handle null", __FUNCTION__);
1383 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001384 }
1385
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001386 int mdpIndex = mCurrentFrame.layerToMDP[i];
1387
Saurabh Shah88e4d272013-09-03 13:31:29 -07001388 MdpPipeInfoNonSplit& pipe_info =
1389 *(MdpPipeInfoNonSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001390 ovutils::eDest dest = pipe_info.index;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001391 if(dest == ovutils::OV_INVALID) {
1392 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001393 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001394 }
1395
Saurabh Shahacf10202013-02-26 10:15:15 -08001396 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1397 continue;
1398 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001399
Saurabh Shahacf10202013-02-26 10:15:15 -08001400 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001401 using pipe: %d", __FUNCTION__, layer,
1402 hnd, dest );
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001403
Saurabh Shahacf10202013-02-26 10:15:15 -08001404 int fd = hnd->fd;
1405 uint32_t offset = hnd->offset;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001406
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001407 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -08001408 if(rot) {
1409 if(!rot->queueBuffer(fd, offset))
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001410 return false;
Saurabh Shahacf10202013-02-26 10:15:15 -08001411 fd = rot->getDstMemId();
1412 offset = rot->getDstOffset();
1413 }
1414
1415 if (!ov.queueBuffer(fd, offset, dest)) {
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301416 ALOGE("%s: queueBuffer failed for display:%d ", __FUNCTION__, mDpy);
Saurabh Shahacf10202013-02-26 10:15:15 -08001417 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001418 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001419
1420 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001421 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001422 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001423}
1424
Saurabh Shah88e4d272013-09-03 13:31:29 -07001425//=============MDPCompSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001426
Saurabh Shah88e4d272013-09-03 13:31:29 -07001427int MDPCompSplit::pipesNeeded(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001428 hwc_display_contents_1_t* list,
1429 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001430 int pipesNeeded = 0;
Saurabh Shah67a38c32013-06-10 16:23:15 -07001431 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001432
1433 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001434
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001435 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1436 if(!mCurrentFrame.isFBComposed[i]) {
1437 hwc_layer_1_t* layer = &list->hwLayers[i];
1438 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001439 if(mixer == Overlay::MIXER_LEFT && dst.left < lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001440 pipesNeeded++;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001441 } else if(mixer == Overlay::MIXER_RIGHT && dst.right > lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001442 pipesNeeded++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001443 }
1444 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001445 }
1446 return pipesNeeded;
1447}
1448
Saurabh Shah88e4d272013-09-03 13:31:29 -07001449bool MDPCompSplit::arePipesAvailable(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001450 hwc_display_contents_1_t* list) {
1451 overlay::Overlay& ov = *ctx->mOverlay;
Saurabh Shah082468e2013-09-12 10:05:32 -07001452 int totalPipesNeeded = 0;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001453
1454 for(int i = 0; i < Overlay::MIXER_MAX; i++) {
1455 int numPipesNeeded = pipesNeeded(ctx, list, i);
1456 int availPipes = ov.availablePipes(mDpy, i);
1457
1458 //Reserve pipe(s)for FB
1459 if(mCurrentFrame.fbCount)
Saurabh Shah082468e2013-09-12 10:05:32 -07001460 numPipesNeeded += 1;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001461
Saurabh Shah082468e2013-09-12 10:05:32 -07001462 totalPipesNeeded += numPipesNeeded;
1463
1464 //Per mixer check.
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001465 if(numPipesNeeded > availPipes) {
1466 ALOGD_IF(isDebug(), "%s: Insufficient pipes for "
1467 "dpy %d mixer %d needed %d, avail %d",
1468 __FUNCTION__, mDpy, i, numPipesNeeded, availPipes);
1469 return false;
1470 }
1471 }
Saurabh Shah082468e2013-09-12 10:05:32 -07001472
1473 //Per display check, since unused pipes can get counted twice.
1474 int totalPipesAvailable = ov.availablePipes(mDpy);
1475 if(totalPipesNeeded > totalPipesAvailable) {
1476 ALOGD_IF(isDebug(), "%s: Insufficient pipes for "
1477 "dpy %d needed %d, avail %d",
1478 __FUNCTION__, mDpy, totalPipesNeeded, totalPipesAvailable);
1479 return false;
1480 }
1481
Saurabh Shah90b7b9b2013-09-12 16:36:08 -07001482 if(not areVGPipesAvailable(ctx, list)) {
1483 return false;
1484 }
1485
1486 return true;
1487}
1488
1489bool MDPCompSplit::areVGPipesAvailable(hwc_context_t *ctx,
1490 hwc_display_contents_1_t* list) {
1491 overlay::Overlay& ov = *ctx->mOverlay;
1492 int pipesNeeded = 0;
1493 const int lSplit = getLeftSplit(ctx, mDpy);
1494 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1495 if(!mCurrentFrame.isFBComposed[i]) {
1496 hwc_layer_1_t* layer = &list->hwLayers[i];
1497 hwc_rect_t dst = layer->displayFrame;
1498 private_handle_t *hnd = (private_handle_t *)layer->handle;
1499 if(isYuvBuffer(hnd)) {
1500 if(dst.left < lSplit) {
1501 pipesNeeded++;
1502 }
1503 if(dst.right > lSplit) {
1504 pipesNeeded++;
1505 }
1506 }
1507 }
1508 }
1509
1510 int availableVGPipes = ov.availablePipes(mDpy, ovutils::OV_MDP_PIPE_VG);
1511 if(pipesNeeded > availableVGPipes) {
1512 ALOGD_IF(isDebug(), "%s: Insufficient VG pipes for video layers"
1513 "dpy %d needed %d, avail %d",
1514 __FUNCTION__, mDpy, pipesNeeded, availableVGPipes);
1515 return false;
1516 }
1517
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001518 return true;
1519}
1520
Saurabh Shah88e4d272013-09-03 13:31:29 -07001521bool MDPCompSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
1522 MdpPipeInfoSplit& pipe_info,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001523 ePipeType type) {
1524 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001525 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001526
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001527 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001528 pipe_info.lIndex = ovutils::OV_INVALID;
1529 pipe_info.rIndex = ovutils::OV_INVALID;
1530
1531 if (dst.left < lSplit) {
1532 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_LEFT);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001533 if(pipe_info.lIndex == ovutils::OV_INVALID)
1534 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001535 }
1536
1537 if(dst.right > lSplit) {
1538 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_RIGHT);
1539 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001540 return false;
1541 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001542
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001543 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001544}
1545
Saurabh Shah88e4d272013-09-03 13:31:29 -07001546bool MDPCompSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001547 hwc_display_contents_1_t* list) {
1548 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001549
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001550 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001551
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001552 hwc_layer_1_t* layer = &list->hwLayers[index];
1553 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001554 int mdpIndex = mCurrentFrame.layerToMDP[index];
1555 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001556 info.pipeInfo = new MdpPipeInfoSplit;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001557 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001558 MdpPipeInfoSplit& pipe_info = *(MdpPipeInfoSplit*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001559 ePipeType type = MDPCOMP_OV_ANY;
1560
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001561 if(isYuvBuffer(hnd)) {
1562 type = MDPCOMP_OV_VG;
Sushil Chauhan15a2ea62013-09-04 18:28:36 -07001563 } else if(!qhwc::needsScalingWithSplit(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001564 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001565 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001566 type = MDPCOMP_OV_DMA;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001567 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001568
1569 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001570 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type = %d",
1571 __FUNCTION__, (int) type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001572 return false;
1573 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001574 }
1575 return true;
1576}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001577
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001578/*
1579 * Configures pipe(s) for MDP composition
1580 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001581int MDPCompSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001582 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001583 MdpPipeInfoSplit& mdp_info =
1584 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001585 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1586 eIsFg isFg = IS_FG_OFF;
1587 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1588 eDest lDest = mdp_info.lIndex;
1589 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001590
1591 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1592 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1593
Saurabh Shah88e4d272013-09-03 13:31:29 -07001594 return configureSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001595 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001596}
1597
Saurabh Shah88e4d272013-09-03 13:31:29 -07001598bool MDPCompSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001599
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001600 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001601 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1602 return true;
1603 }
1604
1605 if(!ctx || !list) {
1606 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001607 return false;
1608 }
1609
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301610 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1611 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1612 return true;
1613 }
1614
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001615 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001616 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001617 idleInvalidator->markForSleep();
1618
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001619 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001620 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001621
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001622 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1623 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001624 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001625 if(mCurrentFrame.isFBComposed[i]) continue;
1626
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001627 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001628 private_handle_t *hnd = (private_handle_t *)layer->handle;
1629 if(!hnd) {
1630 ALOGE("%s handle null", __FUNCTION__);
1631 return false;
1632 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001633
1634 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1635 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001636 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001637
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001638 int mdpIndex = mCurrentFrame.layerToMDP[i];
1639
Saurabh Shah88e4d272013-09-03 13:31:29 -07001640 MdpPipeInfoSplit& pipe_info =
1641 *(MdpPipeInfoSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001642 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -08001643
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001644 ovutils::eDest indexL = pipe_info.lIndex;
1645 ovutils::eDest indexR = pipe_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001646
Saurabh Shahacf10202013-02-26 10:15:15 -08001647 int fd = hnd->fd;
1648 int offset = hnd->offset;
1649
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001650 if(ctx->mAD->isModeOn()) {
1651 if(ctx->mAD->draw(ctx, fd, offset)) {
1652 fd = ctx->mAD->getDstFd(ctx);
1653 offset = ctx->mAD->getDstOffset(ctx);
1654 }
1655 }
1656
Saurabh Shahacf10202013-02-26 10:15:15 -08001657 if(rot) {
1658 rot->queueBuffer(fd, offset);
1659 fd = rot->getDstMemId();
1660 offset = rot->getDstOffset();
1661 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001662
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001663 //************* play left mixer **********
1664 if(indexL != ovutils::OV_INVALID) {
1665 ovutils::eDest destL = (ovutils::eDest)indexL;
Saurabh Shahacf10202013-02-26 10:15:15 -08001666 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001667 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
Saurabh Shahacf10202013-02-26 10:15:15 -08001668 if (!ov.queueBuffer(fd, offset, destL)) {
1669 ALOGE("%s: queueBuffer failed for left mixer", __FUNCTION__);
1670 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001671 }
1672 }
1673
1674 //************* play right mixer **********
1675 if(indexR != ovutils::OV_INVALID) {
1676 ovutils::eDest destR = (ovutils::eDest)indexR;
Saurabh Shahacf10202013-02-26 10:15:15 -08001677 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001678 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
Saurabh Shahacf10202013-02-26 10:15:15 -08001679 if (!ov.queueBuffer(fd, offset, destR)) {
1680 ALOGE("%s: queueBuffer failed for right mixer", __FUNCTION__);
1681 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001682 }
1683 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001684
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001685 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1686 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001687
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001688 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001689}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001690}; //namespace
1691