blob: f5912f249bde677ae2adcbc4c7d99572682d8524 [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"
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -080023#include "qdMetaData.h"
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -080024#include "mdp_version.h"
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -070025#include "hwc_fbupdate.h"
Saurabh Shaha9da08f2013-07-03 13:27:53 -070026#include "hwc_ad.h"
Saurabh Shahacf10202013-02-26 10:15:15 -080027#include <overlayRotator.h>
28
Saurabh Shah85234ec2013-04-12 17:09:00 -070029using namespace overlay;
Saurabh Shahbd2d0832013-04-04 14:33:08 -070030using namespace qdutils;
Saurabh Shahacf10202013-02-26 10:15:15 -080031using namespace overlay::utils;
32namespace ovutils = overlay::utils;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070033
Naseer Ahmed7c958d42012-07-31 18:57:03 -070034namespace qhwc {
35
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080036//==============MDPComp========================================================
37
Naseer Ahmed7c958d42012-07-31 18:57:03 -070038IdleInvalidator *MDPComp::idleInvalidator = NULL;
39bool MDPComp::sIdleFallBack = false;
40bool MDPComp::sDebugLogs = false;
Naseer Ahmed54821fe2012-11-28 18:44:38 -050041bool MDPComp::sEnabled = false;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -070042bool MDPComp::sEnableMixedMode = true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080043int MDPComp::sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070044
Saurabh Shah67a38c32013-06-10 16:23:15 -070045MDPComp* MDPComp::getObject(const int& width, const int& rightSplit,
46 const int& dpy) {
47 if(width > MAX_DISPLAY_DIM || rightSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080048 return new MDPCompHighRes(dpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080049 }
Saurabh Shah67a38c32013-06-10 16:23:15 -070050 return new MDPCompLowRes(dpy);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080051}
52
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080053MDPComp::MDPComp(int dpy):mDpy(dpy){};
54
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080055void MDPComp::dump(android::String8& buf)
56{
Prabhanjan Kandula088bd892013-07-02 23:47:13 +053057 Locker::Autolock _l(mMdpCompLock);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080058 dumpsys_log(buf,"HWC Map for Dpy: %s \n",
59 mDpy ? "\"EXTERNAL\"" : "\"PRIMARY\"");
60 dumpsys_log(buf,"PREV_FRAME: layerCount:%2d mdpCount:%2d \
61 cacheCount:%2d \n", mCachedFrame.layerCount,
62 mCachedFrame.mdpCount, mCachedFrame.cacheCount);
63 dumpsys_log(buf,"CURR_FRAME: layerCount:%2d mdpCount:%2d \
64 fbCount:%2d \n", mCurrentFrame.layerCount,
65 mCurrentFrame.mdpCount, mCurrentFrame.fbCount);
66 dumpsys_log(buf,"needsFBRedraw:%3s pipesUsed:%2d MaxPipesPerMixer: %d \n",
67 (mCurrentFrame.needsRedraw? "YES" : "NO"),
68 mCurrentFrame.mdpCount, sMaxPipesPerMixer);
69 dumpsys_log(buf," --------------------------------------------- \n");
70 dumpsys_log(buf," listIdx | cached? | mdpIndex | comptype | Z \n");
71 dumpsys_log(buf," --------------------------------------------- \n");
72 for(int index = 0; index < mCurrentFrame.layerCount; index++ )
73 dumpsys_log(buf," %7d | %7s | %8d | %9s | %2d \n",
74 index,
75 (mCurrentFrame.isFBComposed[index] ? "YES" : "NO"),
76 mCurrentFrame.layerToMDP[index],
77 (mCurrentFrame.isFBComposed[index] ?
78 (mCurrentFrame.needsRedraw ? "GLES" : "CACHE") : "MDP"),
79 (mCurrentFrame.isFBComposed[index] ? mCurrentFrame.fbZ :
80 mCurrentFrame.mdpToLayer[mCurrentFrame.layerToMDP[index]].pipeInfo->zOrder));
81 dumpsys_log(buf,"\n");
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080082}
83
84bool MDPComp::init(hwc_context_t *ctx) {
85
86 if(!ctx) {
87 ALOGE("%s: Invalid hwc context!!",__FUNCTION__);
88 return false;
89 }
90
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080091 char property[PROPERTY_VALUE_MAX];
92
93 sEnabled = false;
94 if((property_get("persist.hwc.mdpcomp.enable", property, NULL) > 0) &&
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080095 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
96 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080097 sEnabled = true;
Xiaoming Zhou944e02e2013-05-01 20:54:03 -040098 if(!setupBasePipe(ctx)) {
99 ALOGE("%s: Failed to setup primary base pipe", __FUNCTION__);
100 return false;
101 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800102 }
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 sDebugLogs = false;
112 if(property_get("debug.mdpcomp.logs", property, NULL) > 0) {
113 if(atoi(property) != 0)
114 sDebugLogs = true;
115 }
116
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800117 sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
Saurabh Shah85234ec2013-04-12 17:09:00 -0700118 if(property_get("debug.mdpcomp.maxpermixer", property, "-1") > 0) {
119 int val = atoi(property);
120 if(val >= 0)
121 sMaxPipesPerMixer = min(val, MAX_PIPES_PER_MIXER);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800122 }
123
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400124 if(ctx->mMDP.panel != MIPI_CMD_PANEL) {
125 // Idle invalidation is not necessary on command mode panels
126 long idle_timeout = DEFAULT_IDLE_TIME;
127 if(property_get("debug.mdpcomp.idletime", property, NULL) > 0) {
128 if(atoi(property) != 0)
129 idle_timeout = atoi(property);
130 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800131
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400132 //create Idle Invalidator only when not disabled through property
133 if(idle_timeout != -1)
134 idleInvalidator = IdleInvalidator::getInstance();
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800135
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400136 if(idleInvalidator == NULL) {
137 ALOGE("%s: failed to instantiate idleInvalidator object",
138 __FUNCTION__);
139 } else {
140 idleInvalidator->init(timeout_handler, ctx, idle_timeout);
141 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800142 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700143 return true;
144}
145
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700146void MDPComp::reset(const int& numLayers, hwc_display_contents_1_t* list) {
147 mCurrentFrame.reset(numLayers);
148 mCachedFrame.cacheAll(list);
149 mCachedFrame.updateCounts(mCurrentFrame);
150}
151
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700152void MDPComp::timeout_handler(void *udata) {
153 struct hwc_context_t* ctx = (struct hwc_context_t*)(udata);
154
155 if(!ctx) {
156 ALOGE("%s: received empty data in timer callback", __FUNCTION__);
157 return;
158 }
159
Jesse Hall3be78d92012-08-21 15:12:23 -0700160 if(!ctx->proc) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700161 ALOGE("%s: HWC proc not registered", __FUNCTION__);
162 return;
163 }
164 sIdleFallBack = true;
165 /* Trigger SF to redraw the current frame */
Jesse Hall3be78d92012-08-21 15:12:23 -0700166 ctx->proc->invalidate(ctx->proc);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700167}
168
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800169void MDPComp::setMDPCompLayerFlags(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800170 hwc_display_contents_1_t* list) {
171 LayerProp *layerProp = ctx->layerProp[mDpy];
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800172
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800173 for(int index = 0; index < ctx->listStats[mDpy].numAppLayers; index++) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800174 hwc_layer_1_t* layer = &(list->hwLayers[index]);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800175 if(!mCurrentFrame.isFBComposed[index]) {
176 layerProp[index].mFlags |= HWC_MDPCOMP;
177 layer->compositionType = HWC_OVERLAY;
178 layer->hints |= HWC_HINT_CLEAR_FB;
179 mCachedFrame.hnd[index] = NULL;
180 } else {
181 if(!mCurrentFrame.needsRedraw)
182 layer->compositionType = HWC_OVERLAY;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800183 }
184 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700185}
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500186
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800187/*
188 * Sets up BORDERFILL as default base pipe and detaches RGB0.
189 * Framebuffer is always updated using PLAY ioctl.
190 */
191bool MDPComp::setupBasePipe(hwc_context_t *ctx) {
192 const int dpy = HWC_DISPLAY_PRIMARY;
193 int fb_stride = ctx->dpyAttr[dpy].stride;
194 int fb_width = ctx->dpyAttr[dpy].xres;
195 int fb_height = ctx->dpyAttr[dpy].yres;
196 int fb_fd = ctx->dpyAttr[dpy].fd;
197
198 mdp_overlay ovInfo;
199 msmfb_overlay_data ovData;
200 memset(&ovInfo, 0, sizeof(mdp_overlay));
201 memset(&ovData, 0, sizeof(msmfb_overlay_data));
202
203 ovInfo.src.format = MDP_RGB_BORDERFILL;
204 ovInfo.src.width = fb_width;
205 ovInfo.src.height = fb_height;
206 ovInfo.src_rect.w = fb_width;
207 ovInfo.src_rect.h = fb_height;
208 ovInfo.dst_rect.w = fb_width;
209 ovInfo.dst_rect.h = fb_height;
210 ovInfo.id = MSMFB_NEW_REQUEST;
211
212 if (ioctl(fb_fd, MSMFB_OVERLAY_SET, &ovInfo) < 0) {
213 ALOGE("Failed to call ioctl MSMFB_OVERLAY_SET err=%s",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800214 strerror(errno));
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800215 return false;
216 }
217
218 ovData.id = ovInfo.id;
219 if (ioctl(fb_fd, MSMFB_OVERLAY_PLAY, &ovData) < 0) {
220 ALOGE("Failed to call ioctl MSMFB_OVERLAY_PLAY err=%s",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800221 strerror(errno));
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800222 return false;
223 }
224 return true;
225}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800226MDPComp::FrameInfo::FrameInfo() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700227 reset(0);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800228}
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800229
Saurabh Shahaa236822013-04-24 18:07:26 -0700230void MDPComp::FrameInfo::reset(const int& numLayers) {
231 for(int i = 0 ; i < MAX_PIPES_PER_MIXER && numLayers; i++ ) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800232 if(mdpToLayer[i].pipeInfo) {
233 delete mdpToLayer[i].pipeInfo;
234 mdpToLayer[i].pipeInfo = NULL;
235 //We dont own the rotator
236 mdpToLayer[i].rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800237 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800238 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800239
240 memset(&mdpToLayer, 0, sizeof(mdpToLayer));
241 memset(&layerToMDP, -1, sizeof(layerToMDP));
Saurabh Shahaa236822013-04-24 18:07:26 -0700242 memset(&isFBComposed, 1, sizeof(isFBComposed));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800243
Saurabh Shahaa236822013-04-24 18:07:26 -0700244 layerCount = numLayers;
245 fbCount = numLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800246 mdpCount = 0;
Saurabh Shah2f3895f2013-05-02 10:13:31 -0700247 needsRedraw = true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800248 fbZ = 0;
249}
250
Saurabh Shahaa236822013-04-24 18:07:26 -0700251void MDPComp::FrameInfo::map() {
252 // populate layer and MDP maps
253 int mdpIdx = 0;
254 for(int idx = 0; idx < layerCount; idx++) {
255 if(!isFBComposed[idx]) {
256 mdpToLayer[mdpIdx].listIndex = idx;
257 layerToMDP[idx] = mdpIdx++;
258 }
259 }
260}
261
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800262MDPComp::LayerCache::LayerCache() {
263 reset();
264}
265
266void MDPComp::LayerCache::reset() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700267 memset(&hnd, 0, sizeof(hnd));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800268 mdpCount = 0;
269 cacheCount = 0;
270 layerCount = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -0700271 fbZ = -1;
272}
273
274void MDPComp::LayerCache::cacheAll(hwc_display_contents_1_t* list) {
275 const int numAppLayers = list->numHwLayers - 1;
276 for(int i = 0; i < numAppLayers; i++) {
277 hnd[i] = list->hwLayers[i].handle;
278 }
279}
280
281void MDPComp::LayerCache::updateCounts(const FrameInfo& curFrame) {
282 mdpCount = curFrame.mdpCount;
283 cacheCount = curFrame.fbCount;
284 layerCount = curFrame.layerCount;
285 fbZ = curFrame.fbZ;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800286}
287
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530288bool MDPComp::isValidDimension(hwc_context_t *ctx, hwc_layer_1_t *layer) {
Saurabh Shah4fdde762013-04-30 18:47:33 -0700289 const int dpy = HWC_DISPLAY_PRIMARY;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800290 private_handle_t *hnd = (private_handle_t *)layer->handle;
291
292 if(!hnd) {
293 ALOGE("%s: layer handle is NULL", __FUNCTION__);
294 return false;
295 }
296
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800297 int hw_w = ctx->dpyAttr[mDpy].xres;
298 int hw_h = ctx->dpyAttr[mDpy].yres;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800299
Saurabh Shah4fdde762013-04-30 18:47:33 -0700300 hwc_rect_t crop = layer->sourceCrop;
301 hwc_rect_t dst = layer->displayFrame;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800302
303 if(dst.left < 0 || dst.top < 0 || dst.right > hw_w || dst.bottom > hw_h) {
Saurabh Shah4fdde762013-04-30 18:47:33 -0700304 hwc_rect_t scissor = {0, 0, hw_w, hw_h };
305 qhwc::calculate_crop_rects(crop, dst, scissor, layer->transform);
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800306 }
307
Saurabh Shah4fdde762013-04-30 18:47:33 -0700308 int crop_w = crop.right - crop.left;
309 int crop_h = crop.bottom - crop.top;
310 int dst_w = dst.right - dst.left;
311 int dst_h = dst.bottom - dst.top;
312 float w_dscale = ceilf((float)crop_w / (float)dst_w);
313 float h_dscale = ceilf((float)crop_h / (float)dst_h);
314
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800315 /* Workaround for MDP HW limitation in DSI command mode panels where
316 * FPS will not go beyond 30 if buffers on RGB pipes are of width or height
317 * less than 5 pixels
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530318 * There also is a HW limilation in MDP, minimum block size is 2x2
319 * Fallback to GPU if height is less than 2.
320 */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800321 if((crop_w < 5)||(crop_h < 5))
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800322 return false;
323
Saurabh Shah4fdde762013-04-30 18:47:33 -0700324 const uint32_t downscale =
325 qdutils::MDPVersion::getInstance().getMaxMDPDownscale();
326 if(ctx->mMDP.version >= qdutils::MDSS_V5) {
327 /* Workaround for downscales larger than 4x.
328 * Will be removed once decimator block is enabled for MDSS
329 */
330 if(!qdutils::MDPVersion::getInstance().supportsDecimation()) {
331 if(crop_w > MAX_DISPLAY_DIM || w_dscale > downscale ||
332 h_dscale > downscale)
333 return false;
334 } else {
335 if(w_dscale > 64 || h_dscale > 64)
336 return false;
337 }
338 } else { //A-family
339 if(w_dscale > downscale || h_dscale > downscale)
340 return false;
341 }
342
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800343 return true;
344}
345
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700346ovutils::eDest MDPComp::getMdpPipe(hwc_context_t *ctx, ePipeType type,
347 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800348 overlay::Overlay& ov = *ctx->mOverlay;
349 ovutils::eDest mdp_pipe = ovutils::OV_INVALID;
350
351 switch(type) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800352 case MDPCOMP_OV_DMA:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700353 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_DMA, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800354 if(mdp_pipe != ovutils::OV_INVALID) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800355 return mdp_pipe;
356 }
357 case MDPCOMP_OV_ANY:
358 case MDPCOMP_OV_RGB:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700359 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800360 if(mdp_pipe != ovutils::OV_INVALID) {
361 return mdp_pipe;
362 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800363
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800364 if(type == MDPCOMP_OV_RGB) {
365 //Requested only for RGB pipe
366 break;
367 }
368 case MDPCOMP_OV_VG:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700369 return ov.nextPipe(ovutils::OV_MDP_PIPE_VG, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800370 default:
371 ALOGE("%s: Invalid pipe type",__FUNCTION__);
372 return ovutils::OV_INVALID;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800373 };
374 return ovutils::OV_INVALID;
375}
376
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800377bool MDPComp::isFrameDoable(hwc_context_t *ctx) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700378 bool ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700379 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800380
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800381 if(!isEnabled()) {
382 ALOGD_IF(isDebug(),"%s: MDP Comp. not enabled.", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700383 ret = false;
Saurabh Shahd4e65852013-06-17 11:33:53 -0700384 } else if(qdutils::MDPVersion::getInstance().is8x26() &&
385 ctx->mVideoTransFlag &&
386 ctx->mExtDisplay->isExternalConnected()) {
387 //1 Padding round to shift pipes across mixers
388 ALOGD_IF(isDebug(),"%s: MDP Comp. video transition padding round",
389 __FUNCTION__);
390 ret = false;
Saurabh Shahaa236822013-04-24 18:07:26 -0700391 } else if(ctx->mExtDispConfiguring) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800392 ALOGD_IF( isDebug(),"%s: External Display connection is pending",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800393 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700394 ret = false;
Saurabh Shahaa236822013-04-24 18:07:26 -0700395 } else if(ctx->isPaddingRound) {
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700396 ctx->isPaddingRound = false;
397 ALOGD_IF(isDebug(), "%s: padding round",__FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700398 ret = false;
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700399 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700400 return ret;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800401}
402
403/* Checks for conditions where all the layers marked for MDP comp cannot be
404 * bypassed. On such conditions we try to bypass atleast YUV layers */
405bool MDPComp::isFullFrameDoable(hwc_context_t *ctx,
406 hwc_display_contents_1_t* list){
407
Saurabh Shahaa236822013-04-24 18:07:26 -0700408 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800409
Saurabh Shah2d998a92013-05-14 17:55:58 -0700410 if(sIdleFallBack) {
411 ALOGD_IF(isDebug(), "%s: Idle fallback dpy %d",__FUNCTION__, mDpy);
412 return false;
413 }
414
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800415 if(mDpy > HWC_DISPLAY_PRIMARY){
416 ALOGD_IF(isDebug(), "%s: Cannot support External display(s)",
417 __FUNCTION__);
418 return false;
419 }
420
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800421 if(isSkipPresent(ctx, mDpy)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700422 ALOGD_IF(isDebug(),"%s: SKIP present: %d",
423 __FUNCTION__,
424 isSkipPresent(ctx, mDpy));
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800425 return false;
426 }
427
Saurabh Shah9f084ad2013-05-02 11:28:09 -0700428 if(ctx->listStats[mDpy].needsAlphaScale
429 && ctx->mMDP.version < qdutils::MDSS_V5) {
430 ALOGD_IF(isDebug(), "%s: frame needs alpha downscaling",__FUNCTION__);
431 return false;
432 }
433
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800434 //MDP composition is not efficient if layer needs rotator.
435 for(int i = 0; i < numAppLayers; ++i) {
436 // As MDP h/w supports flip operation, use MDP comp only for
437 // 180 transforms. Fail for any transform involving 90 (90, 270).
438 hwc_layer_1_t* layer = &list->hwLayers[i];
439 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800440
Saurabh Shah4fdde762013-04-30 18:47:33 -0700441 if((layer->transform & HWC_TRANSFORM_ROT_90) && !isYuvBuffer(hnd)) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800442 ALOGD_IF(isDebug(), "%s: orientation involved",__FUNCTION__);
443 return false;
444 }
445
Saurabh Shah4fdde762013-04-30 18:47:33 -0700446 if(!isValidDimension(ctx,layer)) {
447 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
448 __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800449 return false;
450 }
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530451
452 //For 8x26 with panel width>1k, if RGB layer needs HFLIP fail mdp comp
453 // may not need it if Gfx pre-rotation can handle all flips & rotations
454 if(qdutils::MDPVersion::getInstance().is8x26() &&
455 (ctx->dpyAttr[mDpy].xres > 1024) &&
456 (layer->transform & HWC_TRANSFORM_FLIP_H) &&
457 (!isYuvBuffer(hnd)))
458 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800459 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700460
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700461 if(ctx->mAD->isDoable()) {
462 return false;
463 }
464
Saurabh Shahaa236822013-04-24 18:07:26 -0700465 //If all above hard conditions are met we can do full or partial MDP comp.
466 bool ret = false;
467 if(fullMDPComp(ctx, list)) {
468 ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700469 } else if(partialMDPComp(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700470 ret = true;
471 }
472 return ret;
473}
474
475bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
476 //Setup mCurrentFrame
477 mCurrentFrame.mdpCount = mCurrentFrame.layerCount;
478 mCurrentFrame.fbCount = 0;
479 mCurrentFrame.fbZ = -1;
480 memset(&mCurrentFrame.isFBComposed, 0, sizeof(mCurrentFrame.isFBComposed));
481
482 int mdpCount = mCurrentFrame.mdpCount;
483 if(mdpCount > sMaxPipesPerMixer) {
484 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
485 return false;
486 }
487
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700488 if(!arePipesAvailable(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700489 return false;
490 }
491
492 return true;
493}
494
495bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
496{
497 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700498
499 if(!sEnableMixedMode) {
500 //Mixed mode is disabled. No need to even try caching.
501 return false;
502 }
503
Saurabh Shahaa236822013-04-24 18:07:26 -0700504 //Setup mCurrentFrame
505 mCurrentFrame.reset(numAppLayers);
506 updateLayerCache(ctx, list);
507 updateYUV(ctx, list);
508 batchLayers(); //sets up fbZ also
509
510 int mdpCount = mCurrentFrame.mdpCount;
511 if(mdpCount > (sMaxPipesPerMixer - 1)) { // -1 since FB is used
512 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
513 return false;
514 }
515
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700516 if(!arePipesAvailable(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700517 return false;
518 }
519
520 return true;
521}
522
523bool MDPComp::isOnlyVideoDoable(hwc_context_t *ctx,
524 hwc_display_contents_1_t* list){
525 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
526 mCurrentFrame.reset(numAppLayers);
527 updateYUV(ctx, list);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700528 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700529 int fbNeeded = int(mCurrentFrame.fbCount != 0);
530
531 if(!isYuvPresent(ctx, mDpy)) {
532 return false;
533 }
534
Saurabh Shah4fdde762013-04-30 18:47:33 -0700535 if(!mdpCount)
536 return false;
537
Saurabh Shahaa236822013-04-24 18:07:26 -0700538 if(mdpCount > (sMaxPipesPerMixer - fbNeeded)) {
539 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
540 return false;
541 }
542
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700543 if(!arePipesAvailable(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700544 return false;
545 }
546
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800547 return true;
548}
549
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800550/* Checks for conditions where YUV layers cannot be bypassed */
551bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Saurabh Shahe2474082013-05-15 16:32:13 -0700552 bool extAnimBlockFeature = mDpy && ctx->listStats[mDpy].isDisplayAnimating;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800553
Saurabh Shahe2474082013-05-15 16:32:13 -0700554 if(isSkipLayer(layer) && !extAnimBlockFeature) {
555 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800556 return false;
557 }
558
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800559 if(isSecuring(ctx, layer)) {
560 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
561 return false;
562 }
563
Saurabh Shah4fdde762013-04-30 18:47:33 -0700564 if(!isValidDimension(ctx, layer)) {
565 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
566 __FUNCTION__);
567 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800568 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700569
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800570 return true;
571}
572
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800573void MDPComp::batchLayers() {
574 /* Idea is to keep as many contiguous non-updating(cached) layers in FB and
575 * send rest of them through MDP. NEVER mark an updating layer for caching.
576 * But cached ones can be marked for MDP*/
577
578 int maxBatchStart = -1;
579 int maxBatchCount = 0;
580
581 /* All or Nothing is cached. No batching needed */
Saurabh Shahaa236822013-04-24 18:07:26 -0700582 if(!mCurrentFrame.fbCount) {
583 mCurrentFrame.fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800584 return;
Saurabh Shahaa236822013-04-24 18:07:26 -0700585 }
586 if(!mCurrentFrame.mdpCount) {
587 mCurrentFrame.fbZ = 0;
588 return;
589 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800590
591 /* Search for max number of contiguous (cached) layers */
592 int i = 0;
593 while (i < mCurrentFrame.layerCount) {
594 int count = 0;
595 while(mCurrentFrame.isFBComposed[i] && i < mCurrentFrame.layerCount) {
596 count++; i++;
597 }
598 if(count > maxBatchCount) {
599 maxBatchCount = count;
600 maxBatchStart = i - count;
Saurabh Shahaa236822013-04-24 18:07:26 -0700601 mCurrentFrame.fbZ = maxBatchStart;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800602 }
603 if(i < mCurrentFrame.layerCount) i++;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800604 }
605
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800606 /* reset rest of the layers for MDP comp */
607 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
608 if(i != maxBatchStart){
609 mCurrentFrame.isFBComposed[i] = false;
610 } else {
611 i += maxBatchCount;
612 }
613 }
614
615 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700616 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
617 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800618
619 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
620 mCurrentFrame.fbCount);
621}
Saurabh Shah85234ec2013-04-12 17:09:00 -0700622
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800623void MDPComp::updateLayerCache(hwc_context_t* ctx,
624 hwc_display_contents_1_t* list) {
625
626 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
627 int numCacheableLayers = 0;
628
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800629 for(int i = 0; i < numAppLayers; i++) {
630 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
631 numCacheableLayers++;
632 mCurrentFrame.isFBComposed[i] = true;
633 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -0700634 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800635 mCachedFrame.hnd[i] = list->hwLayers[i].handle;
636 }
637 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700638
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800639 mCurrentFrame.fbCount = numCacheableLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700640 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
641 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800642 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__, numCacheableLayers);
643}
644
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800645void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list) {
646
647 int nYuvCount = ctx->listStats[mDpy].yuvCount;
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700648 if(!nYuvCount && mDpy) {
649 //Reset "No animation on external display" related parameters.
650 ctx->mPrevCropVideo.left = ctx->mPrevCropVideo.top =
651 ctx->mPrevCropVideo.right = ctx->mPrevCropVideo.bottom = 0;
652 ctx->mPrevDestVideo.left = ctx->mPrevDestVideo.top =
653 ctx->mPrevDestVideo.right = ctx->mPrevDestVideo.bottom = 0;
654 ctx->mPrevTransformVideo = 0;
655 return;
656 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800657 for(int index = 0;index < nYuvCount; index++){
658 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
659 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
660
661 if(!isYUVDoable(ctx, layer)) {
662 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
663 mCurrentFrame.isFBComposed[nYuvIndex] = true;
664 mCurrentFrame.fbCount++;
665 }
666 } else {
667 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
668 mCurrentFrame.isFBComposed[nYuvIndex] = false;
669 mCurrentFrame.fbCount--;
670 }
671 }
672 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700673
674 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
675 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800676 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
677 mCurrentFrame.fbCount);
678}
679
Saurabh Shahaa236822013-04-24 18:07:26 -0700680bool MDPComp::programMDP(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800681 if(!allocLayerPipes(ctx, list)) {
682 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700683 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800684 }
685
Saurabh Shahaa236822013-04-24 18:07:26 -0700686 bool fbBatch = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800687 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700688 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800689 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800690 int mdpIndex = mCurrentFrame.layerToMDP[index];
691 hwc_layer_1_t* layer = &list->hwLayers[index];
692
693 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
694 cur_pipe->zOrder = mdpNextZOrder++;
695
696 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
697 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
698 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -0700699 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800700 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700701 } else if(fbBatch == false) {
702 mdpNextZOrder++;
703 fbBatch = true;
704 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800705 }
706
Saurabh Shahaa236822013-04-24 18:07:26 -0700707 return true;
708}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800709
Saurabh Shahaa236822013-04-24 18:07:26 -0700710bool MDPComp::programYUV(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
711 if(!allocLayerPipes(ctx, list)) {
712 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
713 return false;
714 }
715 //If we are in this block, it means we have yuv + rgb layers both
716 int mdpIdx = 0;
717 for (int index = 0; index < mCurrentFrame.layerCount; index++) {
718 if(!mCurrentFrame.isFBComposed[index]) {
719 hwc_layer_1_t* layer = &list->hwLayers[index];
720 int mdpIndex = mCurrentFrame.layerToMDP[index];
721 MdpPipeInfo* cur_pipe =
722 mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
723 cur_pipe->zOrder = mdpIdx++;
724
725 if(configure(ctx, layer,
726 mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
727 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
728 layer %d",__FUNCTION__, index);
729 return false;
730 }
731 }
732 }
733 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800734}
735
736int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700737 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -0700738
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530739 { //LOCK SCOPE BEGIN
740 Locker::Autolock _l(mMdpCompLock);
Prabhanjan Kandula088bd892013-07-02 23:47:13 +0530741
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530742 //reset old data
Saurabh Shahaa236822013-04-24 18:07:26 -0700743 mCurrentFrame.reset(numLayers);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800744
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530745 //number of app layers exceeds MAX_NUM_APP_LAYERS fall back to GPU
746 //do not cache the information for next draw cycle.
747 if(numLayers > MAX_NUM_APP_LAYERS) {
748 mCachedFrame.updateCounts(mCurrentFrame);
749 ALOGD_IF(isDebug(), "%s: Number of App layers exceeded the limit ",
750 __FUNCTION__);
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700751 return -1;
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530752 }
753
754 //Hard conditions, if not met, cannot do MDP comp
755 if(!isFrameDoable(ctx)) {
756 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
757 __FUNCTION__);
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700758 reset(numLayers, list);
759 return -1;
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530760 }
761
762 //Check whether layers marked for MDP Composition is actually doable.
763 if(isFullFrameDoable(ctx, list)){
764 mCurrentFrame.map();
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700765 //Configure framebuffer first if applicable
766 if(mCurrentFrame.fbZ >= 0) {
767 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list,
768 mCurrentFrame.fbZ)) {
769 ALOGE("%s configure framebuffer failed", __func__);
770 reset(numLayers, list);
771 return -1;
772 }
773 }
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530774 //Acquire and Program MDP pipes
775 if(!programMDP(ctx, list)) {
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700776 reset(numLayers, list);
777 return -1;
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530778 } else { //Success
779 //Any change in composition types needs an FB refresh
780 mCurrentFrame.needsRedraw = false;
781 if(mCurrentFrame.fbCount &&
782 ((mCurrentFrame.mdpCount != mCachedFrame.mdpCount) ||
783 (mCurrentFrame.fbCount != mCachedFrame.cacheCount) ||
784 (mCurrentFrame.fbZ != mCachedFrame.fbZ) ||
785 (!mCurrentFrame.mdpCount) ||
786 (list->flags & HWC_GEOMETRY_CHANGED) ||
787 isSkipPresent(ctx, mDpy) ||
788 (mDpy > HWC_DISPLAY_PRIMARY))) {
789 mCurrentFrame.needsRedraw = true;
790 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700791 }
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530792 } else if(isOnlyVideoDoable(ctx, list)) {
793 //All layers marked for MDP comp cannot be bypassed.
794 //Try to compose atleast YUV layers through MDP comp and let
795 //all the RGB layers compose in FB
796 //Destination over
797 mCurrentFrame.fbZ = -1;
798 if(mCurrentFrame.fbCount)
799 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800800
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530801 mCurrentFrame.map();
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700802
803 //Configure framebuffer first if applicable
804 if(mCurrentFrame.fbZ >= 0) {
805 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, mCurrentFrame.fbZ)) {
806 ALOGE("%s configure framebuffer failed", __func__);
807 reset(numLayers, list);
808 return -1;
809 }
810 }
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530811 if(!programYUV(ctx, list)) {
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700812 reset(numLayers, list);
813 return -1;
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530814 }
815 } else {
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700816 reset(numLayers, list);
817 return -1;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800818 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800819
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530820 //UpdateLayerFlags
821 setMDPCompLayerFlags(ctx, list);
822 mCachedFrame.updateCounts(mCurrentFrame);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800823
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530824 } //LOCK SCOPE END. dump also need this lock.
825 // unlock it before calling dump function to avoid deadlock
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800826 if(isDebug()) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700827 ALOGD("GEOMETRY change: %d", (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800828 android::String8 sDump("");
829 dump(sDump);
830 ALOGE("%s",sDump.string());
831 }
832
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700833 return 0;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800834}
835
836//=============MDPCompLowRes===================================================
837
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700838/*
839 * Configures pipe(s) for MDP composition
840 */
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800841int MDPCompLowRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800842 PipeLayerPair& PipeLayerPair) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800843 MdpPipeInfoLowRes& mdp_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800844 *(static_cast<MdpPipeInfoLowRes*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -0800845 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
846 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
847 eIsFg isFg = IS_FG_OFF;
848 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700849
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800850 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
851 __FUNCTION__, layer, zOrder, dest);
852
853 return configureLowRes(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
854 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700855}
856
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700857bool MDPCompLowRes::arePipesAvailable(hwc_context_t *ctx,
858 hwc_display_contents_1_t* list) {
859 overlay::Overlay& ov = *ctx->mOverlay;
860 int numPipesNeeded = mCurrentFrame.mdpCount;
861 int availPipes = ov.availablePipes(mDpy, Overlay::MIXER_DEFAULT);
862
863 //Reserve pipe for FB
864 if(mCurrentFrame.fbCount)
865 availPipes -= 1;
866
867 if(numPipesNeeded > availPipes) {
868 ALOGD_IF(isDebug(), "%s: Insufficient pipes, dpy %d needed %d, avail %d",
869 __FUNCTION__, mDpy, numPipesNeeded, availPipes);
870 return false;
871 }
872
873 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700874}
875
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800876bool MDPCompLowRes::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700877 hwc_display_contents_1_t* list) {
878 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700879
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800880 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700881
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800882 hwc_layer_1_t* layer = &list->hwLayers[index];
883 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800884 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800885 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800886 info.pipeInfo = new MdpPipeInfoLowRes;
Saurabh Shahacf10202013-02-26 10:15:15 -0800887 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800888 MdpPipeInfoLowRes& pipe_info = *(MdpPipeInfoLowRes*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800889 ePipeType type = MDPCOMP_OV_ANY;
890
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700891 if(isYuvBuffer(hnd)) {
892 type = MDPCOMP_OV_VG;
Saurabh Shah8a117932013-05-23 12:48:13 -0700893 } else if(!qhwc::needsScaling(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -0700894 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
895 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800896 type = MDPCOMP_OV_DMA;
897 }
898
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700899 pipe_info.index = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800900 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700901 ALOGD_IF(isDebug(), "%s: Unable to get pipe type = %d",
902 __FUNCTION__, (int) type);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500903 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700904 }
905 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700906 return true;
907}
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700908
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800909bool MDPCompLowRes::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700910
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800911 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500912 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
913 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800914 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700915
916 if(!ctx || !list) {
917 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500918 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700919 }
920
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +0530921 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
922 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
923 return true;
924 }
925
Prabhanjan Kandula088bd892013-07-02 23:47:13 +0530926 Locker::Autolock _l(mMdpCompLock);
927
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500928 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -0700929 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500930 idleInvalidator->markForSleep();
931
932 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800933 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700934
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800935 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
936 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700937 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800938 if(mCurrentFrame.isFBComposed[i]) continue;
939
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700940 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -0800941 private_handle_t *hnd = (private_handle_t *)layer->handle;
942 if(!hnd) {
943 ALOGE("%s handle null", __FUNCTION__);
944 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700945 }
946
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800947 int mdpIndex = mCurrentFrame.layerToMDP[i];
948
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800949 MdpPipeInfoLowRes& pipe_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800950 *(MdpPipeInfoLowRes*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800951 ovutils::eDest dest = pipe_info.index;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800952 if(dest == ovutils::OV_INVALID) {
953 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500954 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700955 }
956
Saurabh Shahacf10202013-02-26 10:15:15 -0800957 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
958 continue;
959 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700960
Saurabh Shahacf10202013-02-26 10:15:15 -0800961 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800962 using pipe: %d", __FUNCTION__, layer,
963 hnd, dest );
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700964
Saurabh Shahacf10202013-02-26 10:15:15 -0800965 int fd = hnd->fd;
966 uint32_t offset = hnd->offset;
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700967
968 if(ctx->mAD->isModeOn()) {
969 if(ctx->mAD->draw(ctx, fd, offset)) {
970 fd = ctx->mAD->getDstFd(ctx);
971 offset = ctx->mAD->getDstOffset(ctx);
972 }
973 }
974
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800975 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -0800976 if(rot) {
977 if(!rot->queueBuffer(fd, offset))
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500978 return false;
Saurabh Shahacf10202013-02-26 10:15:15 -0800979 fd = rot->getDstMemId();
980 offset = rot->getDstOffset();
981 }
982
983 if (!ov.queueBuffer(fd, offset, dest)) {
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +0530984 ALOGE("%s: queueBuffer failed for display:%d ", __FUNCTION__, mDpy);
Saurabh Shahacf10202013-02-26 10:15:15 -0800985 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700986 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500987
988 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700989 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500990 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700991}
992
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800993//=============MDPCompHighRes===================================================
994
995int MDPCompHighRes::pipesNeeded(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700996 hwc_display_contents_1_t* list,
997 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800998 int pipesNeeded = 0;
Saurabh Shah67a38c32013-06-10 16:23:15 -0700999 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001000
1001 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001002
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001003 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1004 if(!mCurrentFrame.isFBComposed[i]) {
1005 hwc_layer_1_t* layer = &list->hwLayers[i];
1006 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001007 if(mixer == Overlay::MIXER_LEFT && dst.left < lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001008 pipesNeeded++;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001009 } else if(mixer == Overlay::MIXER_RIGHT && dst.right > lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001010 pipesNeeded++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001011 }
1012 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001013 }
1014 return pipesNeeded;
1015}
1016
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001017bool MDPCompHighRes::arePipesAvailable(hwc_context_t *ctx,
1018 hwc_display_contents_1_t* list) {
1019 overlay::Overlay& ov = *ctx->mOverlay;
1020
1021 for(int i = 0; i < Overlay::MIXER_MAX; i++) {
1022 int numPipesNeeded = pipesNeeded(ctx, list, i);
1023 int availPipes = ov.availablePipes(mDpy, i);
1024
1025 //Reserve pipe(s)for FB
1026 if(mCurrentFrame.fbCount)
1027 availPipes -= 1;
1028
1029 if(numPipesNeeded > availPipes) {
1030 ALOGD_IF(isDebug(), "%s: Insufficient pipes for "
1031 "dpy %d mixer %d needed %d, avail %d",
1032 __FUNCTION__, mDpy, i, numPipesNeeded, availPipes);
1033 return false;
1034 }
1035 }
1036 return true;
1037}
1038
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001039bool MDPCompHighRes::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001040 MdpPipeInfoHighRes& pipe_info,
1041 ePipeType type) {
1042 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001043 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001044
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001045 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001046 pipe_info.lIndex = ovutils::OV_INVALID;
1047 pipe_info.rIndex = ovutils::OV_INVALID;
1048
1049 if (dst.left < lSplit) {
1050 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_LEFT);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001051 if(pipe_info.lIndex == ovutils::OV_INVALID)
1052 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001053 }
1054
1055 if(dst.right > lSplit) {
1056 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_RIGHT);
1057 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001058 return false;
1059 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001060
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001061 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001062}
1063
1064bool MDPCompHighRes::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001065 hwc_display_contents_1_t* list) {
1066 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001067
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001068 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001069
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001070 hwc_layer_1_t* layer = &list->hwLayers[index];
1071 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001072 int mdpIndex = mCurrentFrame.layerToMDP[index];
1073 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001074 info.pipeInfo = new MdpPipeInfoHighRes;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001075 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001076 MdpPipeInfoHighRes& pipe_info = *(MdpPipeInfoHighRes*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001077 ePipeType type = MDPCOMP_OV_ANY;
1078
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001079 if(isYuvBuffer(hnd)) {
1080 type = MDPCOMP_OV_VG;
Saurabh Shah8a117932013-05-23 12:48:13 -07001081 } else if(!qhwc::needsScaling(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001082 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001083 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001084 type = MDPCOMP_OV_DMA;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001085 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001086
1087 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001088 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type = %d",
1089 __FUNCTION__, (int) type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001090 return false;
1091 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001092 }
1093 return true;
1094}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001095
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001096/*
1097 * Configures pipe(s) for MDP composition
1098 */
1099int MDPCompHighRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001100 PipeLayerPair& PipeLayerPair) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001101 MdpPipeInfoHighRes& mdp_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001102 *(static_cast<MdpPipeInfoHighRes*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001103 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1104 eIsFg isFg = IS_FG_OFF;
1105 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1106 eDest lDest = mdp_info.lIndex;
1107 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001108
1109 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1110 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1111
1112 return configureHighRes(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
1113 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001114}
1115
1116bool MDPCompHighRes::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
1117
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001118 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001119 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1120 return true;
1121 }
1122
1123 if(!ctx || !list) {
1124 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001125 return false;
1126 }
1127
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301128 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1129 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1130 return true;
1131 }
1132
Prabhanjan Kandula088bd892013-07-02 23:47:13 +05301133 Locker::Autolock _l(mMdpCompLock);
1134
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001135 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001136 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001137 idleInvalidator->markForSleep();
1138
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001139 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001140 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001141
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001142 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1143 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001144 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001145 if(mCurrentFrame.isFBComposed[i]) continue;
1146
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001147 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001148 private_handle_t *hnd = (private_handle_t *)layer->handle;
1149 if(!hnd) {
1150 ALOGE("%s handle null", __FUNCTION__);
1151 return false;
1152 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001153
1154 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1155 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001156 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001157
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001158 int mdpIndex = mCurrentFrame.layerToMDP[i];
1159
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001160 MdpPipeInfoHighRes& pipe_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001161 *(MdpPipeInfoHighRes*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1162 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -08001163
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001164 ovutils::eDest indexL = pipe_info.lIndex;
1165 ovutils::eDest indexR = pipe_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001166
Saurabh Shahacf10202013-02-26 10:15:15 -08001167 int fd = hnd->fd;
1168 int offset = hnd->offset;
1169
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001170 if(ctx->mAD->isModeOn()) {
1171 if(ctx->mAD->draw(ctx, fd, offset)) {
1172 fd = ctx->mAD->getDstFd(ctx);
1173 offset = ctx->mAD->getDstOffset(ctx);
1174 }
1175 }
1176
Saurabh Shahacf10202013-02-26 10:15:15 -08001177 if(rot) {
1178 rot->queueBuffer(fd, offset);
1179 fd = rot->getDstMemId();
1180 offset = rot->getDstOffset();
1181 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001182
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001183 //************* play left mixer **********
1184 if(indexL != ovutils::OV_INVALID) {
1185 ovutils::eDest destL = (ovutils::eDest)indexL;
Saurabh Shahacf10202013-02-26 10:15:15 -08001186 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001187 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
Saurabh Shahacf10202013-02-26 10:15:15 -08001188 if (!ov.queueBuffer(fd, offset, destL)) {
1189 ALOGE("%s: queueBuffer failed for left mixer", __FUNCTION__);
1190 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001191 }
1192 }
1193
1194 //************* play right mixer **********
1195 if(indexR != ovutils::OV_INVALID) {
1196 ovutils::eDest destR = (ovutils::eDest)indexR;
Saurabh Shahacf10202013-02-26 10:15:15 -08001197 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001198 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
Saurabh Shahacf10202013-02-26 10:15:15 -08001199 if (!ov.queueBuffer(fd, offset, destR)) {
1200 ALOGE("%s: queueBuffer failed for right mixer", __FUNCTION__);
1201 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001202 }
1203 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001204
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001205 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1206 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001207
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001208 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001209}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001210}; //namespace
1211