blob: 462cc6d00cda35193ab040fd2808f053c9123049 [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 Shahacf10202013-02-26 10:15:15 -080026#include <overlayRotator.h>
27
Saurabh Shah85234ec2013-04-12 17:09:00 -070028using namespace overlay;
Saurabh Shahbd2d0832013-04-04 14:33:08 -070029using namespace qdutils;
Saurabh Shahacf10202013-02-26 10:15:15 -080030using namespace overlay::utils;
31namespace ovutils = overlay::utils;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070032
Naseer Ahmed7c958d42012-07-31 18:57:03 -070033namespace qhwc {
34
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080035//==============MDPComp========================================================
36
Naseer Ahmed7c958d42012-07-31 18:57:03 -070037IdleInvalidator *MDPComp::idleInvalidator = NULL;
38bool MDPComp::sIdleFallBack = false;
39bool MDPComp::sDebugLogs = false;
Naseer Ahmed54821fe2012-11-28 18:44:38 -050040bool MDPComp::sEnabled = false;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -070041bool MDPComp::sEnableMixedMode = true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080042int MDPComp::sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070043
Saurabh Shah67a38c32013-06-10 16:23:15 -070044MDPComp* MDPComp::getObject(const int& width, const int& rightSplit,
45 const int& dpy) {
46 if(width > MAX_DISPLAY_DIM || rightSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080047 return new MDPCompHighRes(dpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080048 }
Saurabh Shah67a38c32013-06-10 16:23:15 -070049 return new MDPCompLowRes(dpy);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080050}
51
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080052MDPComp::MDPComp(int dpy):mDpy(dpy){};
53
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080054void MDPComp::dump(android::String8& buf)
55{
Prabhanjan Kandula088bd892013-07-02 23:47:13 +053056 Locker::Autolock _l(mMdpCompLock);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080057 dumpsys_log(buf,"HWC Map for Dpy: %s \n",
58 mDpy ? "\"EXTERNAL\"" : "\"PRIMARY\"");
59 dumpsys_log(buf,"PREV_FRAME: layerCount:%2d mdpCount:%2d \
60 cacheCount:%2d \n", mCachedFrame.layerCount,
61 mCachedFrame.mdpCount, mCachedFrame.cacheCount);
62 dumpsys_log(buf,"CURR_FRAME: layerCount:%2d mdpCount:%2d \
63 fbCount:%2d \n", mCurrentFrame.layerCount,
64 mCurrentFrame.mdpCount, mCurrentFrame.fbCount);
65 dumpsys_log(buf,"needsFBRedraw:%3s pipesUsed:%2d MaxPipesPerMixer: %d \n",
66 (mCurrentFrame.needsRedraw? "YES" : "NO"),
67 mCurrentFrame.mdpCount, sMaxPipesPerMixer);
68 dumpsys_log(buf," --------------------------------------------- \n");
69 dumpsys_log(buf," listIdx | cached? | mdpIndex | comptype | Z \n");
70 dumpsys_log(buf," --------------------------------------------- \n");
71 for(int index = 0; index < mCurrentFrame.layerCount; index++ )
72 dumpsys_log(buf," %7d | %7s | %8d | %9s | %2d \n",
73 index,
74 (mCurrentFrame.isFBComposed[index] ? "YES" : "NO"),
75 mCurrentFrame.layerToMDP[index],
76 (mCurrentFrame.isFBComposed[index] ?
77 (mCurrentFrame.needsRedraw ? "GLES" : "CACHE") : "MDP"),
78 (mCurrentFrame.isFBComposed[index] ? mCurrentFrame.fbZ :
79 mCurrentFrame.mdpToLayer[mCurrentFrame.layerToMDP[index]].pipeInfo->zOrder));
80 dumpsys_log(buf,"\n");
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080081}
82
83bool MDPComp::init(hwc_context_t *ctx) {
84
85 if(!ctx) {
86 ALOGE("%s: Invalid hwc context!!",__FUNCTION__);
87 return false;
88 }
89
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080090 char property[PROPERTY_VALUE_MAX];
91
92 sEnabled = false;
93 if((property_get("persist.hwc.mdpcomp.enable", property, NULL) > 0) &&
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080094 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
95 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080096 sEnabled = true;
Xiaoming Zhou944e02e2013-05-01 20:54:03 -040097 if(!setupBasePipe(ctx)) {
98 ALOGE("%s: Failed to setup primary base pipe", __FUNCTION__);
99 return false;
100 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800101 }
102
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700103 sEnableMixedMode = true;
104 if((property_get("debug.mdpcomp.mixedmode.disable", property, NULL) > 0) &&
105 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
106 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
107 sEnableMixedMode = false;
108 }
109
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800110 sDebugLogs = false;
111 if(property_get("debug.mdpcomp.logs", property, NULL) > 0) {
112 if(atoi(property) != 0)
113 sDebugLogs = true;
114 }
115
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800116 sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
Saurabh Shah85234ec2013-04-12 17:09:00 -0700117 if(property_get("debug.mdpcomp.maxpermixer", property, "-1") > 0) {
118 int val = atoi(property);
119 if(val >= 0)
120 sMaxPipesPerMixer = min(val, MAX_PIPES_PER_MIXER);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800121 }
122
Zohaib Alamd9743242013-07-19 16:07:34 -0400123 long idle_timeout = DEFAULT_IDLE_TIME;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800124 if(property_get("debug.mdpcomp.idletime", property, NULL) > 0) {
125 if(atoi(property) != 0)
126 idle_timeout = atoi(property);
127 }
128
Zohaib Alamd9743242013-07-19 16:07:34 -0400129 //create Idle Invalidator only when not disabled through property
130 if(idle_timeout != -1)
131 idleInvalidator = IdleInvalidator::getInstance();
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800132
133 if(idleInvalidator == NULL) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800134 ALOGE("%s: failed to instantiate idleInvalidator object", __FUNCTION__);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800135 } else {
136 idleInvalidator->init(timeout_handler, ctx, idle_timeout);
137 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700138 return true;
139}
140
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700141void MDPComp::reset(const int& numLayers, hwc_display_contents_1_t* list) {
142 mCurrentFrame.reset(numLayers);
143 mCachedFrame.cacheAll(list);
144 mCachedFrame.updateCounts(mCurrentFrame);
145}
146
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700147void MDPComp::timeout_handler(void *udata) {
148 struct hwc_context_t* ctx = (struct hwc_context_t*)(udata);
149
150 if(!ctx) {
151 ALOGE("%s: received empty data in timer callback", __FUNCTION__);
152 return;
153 }
154
Jesse Hall3be78d92012-08-21 15:12:23 -0700155 if(!ctx->proc) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700156 ALOGE("%s: HWC proc not registered", __FUNCTION__);
157 return;
158 }
159 sIdleFallBack = true;
160 /* Trigger SF to redraw the current frame */
Jesse Hall3be78d92012-08-21 15:12:23 -0700161 ctx->proc->invalidate(ctx->proc);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700162}
163
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800164void MDPComp::setMDPCompLayerFlags(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800165 hwc_display_contents_1_t* list) {
166 LayerProp *layerProp = ctx->layerProp[mDpy];
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800167
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800168 for(int index = 0; index < ctx->listStats[mDpy].numAppLayers; index++) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800169 hwc_layer_1_t* layer = &(list->hwLayers[index]);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800170 if(!mCurrentFrame.isFBComposed[index]) {
171 layerProp[index].mFlags |= HWC_MDPCOMP;
172 layer->compositionType = HWC_OVERLAY;
173 layer->hints |= HWC_HINT_CLEAR_FB;
174 mCachedFrame.hnd[index] = NULL;
175 } else {
176 if(!mCurrentFrame.needsRedraw)
177 layer->compositionType = HWC_OVERLAY;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800178 }
179 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700180}
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500181
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800182/*
183 * Sets up BORDERFILL as default base pipe and detaches RGB0.
184 * Framebuffer is always updated using PLAY ioctl.
185 */
186bool MDPComp::setupBasePipe(hwc_context_t *ctx) {
187 const int dpy = HWC_DISPLAY_PRIMARY;
188 int fb_stride = ctx->dpyAttr[dpy].stride;
189 int fb_width = ctx->dpyAttr[dpy].xres;
190 int fb_height = ctx->dpyAttr[dpy].yres;
191 int fb_fd = ctx->dpyAttr[dpy].fd;
192
193 mdp_overlay ovInfo;
194 msmfb_overlay_data ovData;
195 memset(&ovInfo, 0, sizeof(mdp_overlay));
196 memset(&ovData, 0, sizeof(msmfb_overlay_data));
197
198 ovInfo.src.format = MDP_RGB_BORDERFILL;
199 ovInfo.src.width = fb_width;
200 ovInfo.src.height = fb_height;
201 ovInfo.src_rect.w = fb_width;
202 ovInfo.src_rect.h = fb_height;
203 ovInfo.dst_rect.w = fb_width;
204 ovInfo.dst_rect.h = fb_height;
205 ovInfo.id = MSMFB_NEW_REQUEST;
206
207 if (ioctl(fb_fd, MSMFB_OVERLAY_SET, &ovInfo) < 0) {
208 ALOGE("Failed to call ioctl MSMFB_OVERLAY_SET err=%s",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800209 strerror(errno));
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800210 return false;
211 }
212
213 ovData.id = ovInfo.id;
214 if (ioctl(fb_fd, MSMFB_OVERLAY_PLAY, &ovData) < 0) {
215 ALOGE("Failed to call ioctl MSMFB_OVERLAY_PLAY err=%s",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800216 strerror(errno));
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800217 return false;
218 }
219 return true;
220}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800221MDPComp::FrameInfo::FrameInfo() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700222 reset(0);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800223}
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800224
Saurabh Shahaa236822013-04-24 18:07:26 -0700225void MDPComp::FrameInfo::reset(const int& numLayers) {
226 for(int i = 0 ; i < MAX_PIPES_PER_MIXER && numLayers; i++ ) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800227 if(mdpToLayer[i].pipeInfo) {
228 delete mdpToLayer[i].pipeInfo;
229 mdpToLayer[i].pipeInfo = NULL;
230 //We dont own the rotator
231 mdpToLayer[i].rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800232 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800233 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800234
235 memset(&mdpToLayer, 0, sizeof(mdpToLayer));
236 memset(&layerToMDP, -1, sizeof(layerToMDP));
Saurabh Shahaa236822013-04-24 18:07:26 -0700237 memset(&isFBComposed, 1, sizeof(isFBComposed));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800238
Saurabh Shahaa236822013-04-24 18:07:26 -0700239 layerCount = numLayers;
240 fbCount = numLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800241 mdpCount = 0;
Saurabh Shah2f3895f2013-05-02 10:13:31 -0700242 needsRedraw = true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800243 fbZ = 0;
244}
245
Saurabh Shahaa236822013-04-24 18:07:26 -0700246void MDPComp::FrameInfo::map() {
247 // populate layer and MDP maps
248 int mdpIdx = 0;
249 for(int idx = 0; idx < layerCount; idx++) {
250 if(!isFBComposed[idx]) {
251 mdpToLayer[mdpIdx].listIndex = idx;
252 layerToMDP[idx] = mdpIdx++;
253 }
254 }
255}
256
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800257MDPComp::LayerCache::LayerCache() {
258 reset();
259}
260
261void MDPComp::LayerCache::reset() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700262 memset(&hnd, 0, sizeof(hnd));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800263 mdpCount = 0;
264 cacheCount = 0;
265 layerCount = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -0700266 fbZ = -1;
267}
268
269void MDPComp::LayerCache::cacheAll(hwc_display_contents_1_t* list) {
270 const int numAppLayers = list->numHwLayers - 1;
271 for(int i = 0; i < numAppLayers; i++) {
272 hnd[i] = list->hwLayers[i].handle;
273 }
274}
275
276void MDPComp::LayerCache::updateCounts(const FrameInfo& curFrame) {
277 mdpCount = curFrame.mdpCount;
278 cacheCount = curFrame.fbCount;
279 layerCount = curFrame.layerCount;
280 fbZ = curFrame.fbZ;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800281}
282
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530283bool MDPComp::isValidDimension(hwc_context_t *ctx, hwc_layer_1_t *layer) {
Saurabh Shah4fdde762013-04-30 18:47:33 -0700284 const int dpy = HWC_DISPLAY_PRIMARY;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800285 private_handle_t *hnd = (private_handle_t *)layer->handle;
286
287 if(!hnd) {
288 ALOGE("%s: layer handle is NULL", __FUNCTION__);
289 return false;
290 }
291
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800292 int hw_w = ctx->dpyAttr[mDpy].xres;
293 int hw_h = ctx->dpyAttr[mDpy].yres;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800294
Saurabh Shah4fdde762013-04-30 18:47:33 -0700295 hwc_rect_t crop = layer->sourceCrop;
296 hwc_rect_t dst = layer->displayFrame;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800297
298 if(dst.left < 0 || dst.top < 0 || dst.right > hw_w || dst.bottom > hw_h) {
Saurabh Shah4fdde762013-04-30 18:47:33 -0700299 hwc_rect_t scissor = {0, 0, hw_w, hw_h };
300 qhwc::calculate_crop_rects(crop, dst, scissor, layer->transform);
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800301 }
302
Saurabh Shah4fdde762013-04-30 18:47:33 -0700303 int crop_w = crop.right - crop.left;
304 int crop_h = crop.bottom - crop.top;
305 int dst_w = dst.right - dst.left;
306 int dst_h = dst.bottom - dst.top;
307 float w_dscale = ceilf((float)crop_w / (float)dst_w);
308 float h_dscale = ceilf((float)crop_h / (float)dst_h);
309
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800310 /* Workaround for MDP HW limitation in DSI command mode panels where
311 * FPS will not go beyond 30 if buffers on RGB pipes are of width or height
312 * less than 5 pixels
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530313 * There also is a HW limilation in MDP, minimum block size is 2x2
314 * Fallback to GPU if height is less than 2.
315 */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800316 if((crop_w < 5)||(crop_h < 5))
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800317 return false;
318
Saurabh Shah4fdde762013-04-30 18:47:33 -0700319 const uint32_t downscale =
320 qdutils::MDPVersion::getInstance().getMaxMDPDownscale();
321 if(ctx->mMDP.version >= qdutils::MDSS_V5) {
322 /* Workaround for downscales larger than 4x.
323 * Will be removed once decimator block is enabled for MDSS
324 */
325 if(!qdutils::MDPVersion::getInstance().supportsDecimation()) {
326 if(crop_w > MAX_DISPLAY_DIM || w_dscale > downscale ||
327 h_dscale > downscale)
328 return false;
329 } else {
330 if(w_dscale > 64 || h_dscale > 64)
331 return false;
332 }
333 } else { //A-family
334 if(w_dscale > downscale || h_dscale > downscale)
335 return false;
336 }
337
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800338 return true;
339}
340
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700341ovutils::eDest MDPComp::getMdpPipe(hwc_context_t *ctx, ePipeType type,
342 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800343 overlay::Overlay& ov = *ctx->mOverlay;
344 ovutils::eDest mdp_pipe = ovutils::OV_INVALID;
345
346 switch(type) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800347 case MDPCOMP_OV_DMA:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700348 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_DMA, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800349 if(mdp_pipe != ovutils::OV_INVALID) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800350 return mdp_pipe;
351 }
352 case MDPCOMP_OV_ANY:
353 case MDPCOMP_OV_RGB:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700354 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800355 if(mdp_pipe != ovutils::OV_INVALID) {
356 return mdp_pipe;
357 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800358
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800359 if(type == MDPCOMP_OV_RGB) {
360 //Requested only for RGB pipe
361 break;
362 }
363 case MDPCOMP_OV_VG:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700364 return ov.nextPipe(ovutils::OV_MDP_PIPE_VG, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800365 default:
366 ALOGE("%s: Invalid pipe type",__FUNCTION__);
367 return ovutils::OV_INVALID;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800368 };
369 return ovutils::OV_INVALID;
370}
371
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800372bool MDPComp::isFrameDoable(hwc_context_t *ctx) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700373 bool ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700374 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800375
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800376 if(!isEnabled()) {
377 ALOGD_IF(isDebug(),"%s: MDP Comp. not enabled.", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700378 ret = false;
Saurabh Shahd4e65852013-06-17 11:33:53 -0700379 } else if(qdutils::MDPVersion::getInstance().is8x26() &&
380 ctx->mVideoTransFlag &&
381 ctx->mExtDisplay->isExternalConnected()) {
382 //1 Padding round to shift pipes across mixers
383 ALOGD_IF(isDebug(),"%s: MDP Comp. video transition padding round",
384 __FUNCTION__);
385 ret = false;
Saurabh Shahaa236822013-04-24 18:07:26 -0700386 } else if(ctx->mExtDispConfiguring) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800387 ALOGD_IF( isDebug(),"%s: External Display connection is pending",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800388 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700389 ret = false;
Saurabh Shahaa236822013-04-24 18:07:26 -0700390 } else if(ctx->isPaddingRound) {
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700391 ctx->isPaddingRound = false;
392 ALOGD_IF(isDebug(), "%s: padding round",__FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700393 ret = false;
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700394 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700395 return ret;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800396}
397
398/* Checks for conditions where all the layers marked for MDP comp cannot be
399 * bypassed. On such conditions we try to bypass atleast YUV layers */
400bool MDPComp::isFullFrameDoable(hwc_context_t *ctx,
401 hwc_display_contents_1_t* list){
402
Saurabh Shahaa236822013-04-24 18:07:26 -0700403 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800404
Saurabh Shah2d998a92013-05-14 17:55:58 -0700405 if(sIdleFallBack) {
406 ALOGD_IF(isDebug(), "%s: Idle fallback dpy %d",__FUNCTION__, mDpy);
407 return false;
408 }
409
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800410 if(mDpy > HWC_DISPLAY_PRIMARY){
411 ALOGD_IF(isDebug(), "%s: Cannot support External display(s)",
412 __FUNCTION__);
413 return false;
414 }
415
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800416 if(isSkipPresent(ctx, mDpy)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700417 ALOGD_IF(isDebug(),"%s: SKIP present: %d",
418 __FUNCTION__,
419 isSkipPresent(ctx, mDpy));
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800420 return false;
421 }
422
Saurabh Shah9f084ad2013-05-02 11:28:09 -0700423 if(ctx->listStats[mDpy].needsAlphaScale
424 && ctx->mMDP.version < qdutils::MDSS_V5) {
425 ALOGD_IF(isDebug(), "%s: frame needs alpha downscaling",__FUNCTION__);
426 return false;
427 }
428
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800429 //MDP composition is not efficient if layer needs rotator.
430 for(int i = 0; i < numAppLayers; ++i) {
431 // As MDP h/w supports flip operation, use MDP comp only for
432 // 180 transforms. Fail for any transform involving 90 (90, 270).
433 hwc_layer_1_t* layer = &list->hwLayers[i];
434 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800435
Saurabh Shah4fdde762013-04-30 18:47:33 -0700436 if((layer->transform & HWC_TRANSFORM_ROT_90) && !isYuvBuffer(hnd)) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800437 ALOGD_IF(isDebug(), "%s: orientation involved",__FUNCTION__);
438 return false;
439 }
440
Saurabh Shah4fdde762013-04-30 18:47:33 -0700441 if(!isValidDimension(ctx,layer)) {
442 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
443 __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800444 return false;
445 }
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530446
447 //For 8x26 with panel width>1k, if RGB layer needs HFLIP fail mdp comp
448 // may not need it if Gfx pre-rotation can handle all flips & rotations
449 if(qdutils::MDPVersion::getInstance().is8x26() &&
450 (ctx->dpyAttr[mDpy].xres > 1024) &&
451 (layer->transform & HWC_TRANSFORM_FLIP_H) &&
452 (!isYuvBuffer(hnd)))
453 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800454 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700455
456 //If all above hard conditions are met we can do full or partial MDP comp.
457 bool ret = false;
458 if(fullMDPComp(ctx, list)) {
459 ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700460 } else if(partialMDPComp(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700461 ret = true;
462 }
463 return ret;
464}
465
466bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
467 //Setup mCurrentFrame
468 mCurrentFrame.mdpCount = mCurrentFrame.layerCount;
469 mCurrentFrame.fbCount = 0;
470 mCurrentFrame.fbZ = -1;
471 memset(&mCurrentFrame.isFBComposed, 0, sizeof(mCurrentFrame.isFBComposed));
472
473 int mdpCount = mCurrentFrame.mdpCount;
474 if(mdpCount > sMaxPipesPerMixer) {
475 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
476 return false;
477 }
478
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700479 if(!arePipesAvailable(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700480 return false;
481 }
482
483 return true;
484}
485
486bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
487{
488 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700489
490 if(!sEnableMixedMode) {
491 //Mixed mode is disabled. No need to even try caching.
492 return false;
493 }
494
Saurabh Shahaa236822013-04-24 18:07:26 -0700495 //Setup mCurrentFrame
496 mCurrentFrame.reset(numAppLayers);
497 updateLayerCache(ctx, list);
498 updateYUV(ctx, list);
499 batchLayers(); //sets up fbZ also
500
501 int mdpCount = mCurrentFrame.mdpCount;
502 if(mdpCount > (sMaxPipesPerMixer - 1)) { // -1 since FB is used
503 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
504 return false;
505 }
506
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700507 if(!arePipesAvailable(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700508 return false;
509 }
510
511 return true;
512}
513
514bool MDPComp::isOnlyVideoDoable(hwc_context_t *ctx,
515 hwc_display_contents_1_t* list){
516 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
517 mCurrentFrame.reset(numAppLayers);
518 updateYUV(ctx, list);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700519 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700520 int fbNeeded = int(mCurrentFrame.fbCount != 0);
521
522 if(!isYuvPresent(ctx, mDpy)) {
523 return false;
524 }
525
Saurabh Shah4fdde762013-04-30 18:47:33 -0700526 if(!mdpCount)
527 return false;
528
Saurabh Shahaa236822013-04-24 18:07:26 -0700529 if(mdpCount > (sMaxPipesPerMixer - fbNeeded)) {
530 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
531 return false;
532 }
533
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700534 if(!arePipesAvailable(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700535 return false;
536 }
537
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800538 return true;
539}
540
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800541/* Checks for conditions where YUV layers cannot be bypassed */
542bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Saurabh Shahe2474082013-05-15 16:32:13 -0700543 bool extAnimBlockFeature = mDpy && ctx->listStats[mDpy].isDisplayAnimating;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800544
Saurabh Shahe2474082013-05-15 16:32:13 -0700545 if(isSkipLayer(layer) && !extAnimBlockFeature) {
546 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800547 return false;
548 }
549
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800550 if(isSecuring(ctx, layer)) {
551 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
552 return false;
553 }
554
Saurabh Shah4fdde762013-04-30 18:47:33 -0700555 if(!isValidDimension(ctx, layer)) {
556 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
557 __FUNCTION__);
558 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800559 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700560
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800561 return true;
562}
563
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800564void MDPComp::batchLayers() {
565 /* Idea is to keep as many contiguous non-updating(cached) layers in FB and
566 * send rest of them through MDP. NEVER mark an updating layer for caching.
567 * But cached ones can be marked for MDP*/
568
569 int maxBatchStart = -1;
570 int maxBatchCount = 0;
571
572 /* All or Nothing is cached. No batching needed */
Saurabh Shahaa236822013-04-24 18:07:26 -0700573 if(!mCurrentFrame.fbCount) {
574 mCurrentFrame.fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800575 return;
Saurabh Shahaa236822013-04-24 18:07:26 -0700576 }
577 if(!mCurrentFrame.mdpCount) {
578 mCurrentFrame.fbZ = 0;
579 return;
580 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800581
582 /* Search for max number of contiguous (cached) layers */
583 int i = 0;
584 while (i < mCurrentFrame.layerCount) {
585 int count = 0;
586 while(mCurrentFrame.isFBComposed[i] && i < mCurrentFrame.layerCount) {
587 count++; i++;
588 }
589 if(count > maxBatchCount) {
590 maxBatchCount = count;
591 maxBatchStart = i - count;
Saurabh Shahaa236822013-04-24 18:07:26 -0700592 mCurrentFrame.fbZ = maxBatchStart;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800593 }
594 if(i < mCurrentFrame.layerCount) i++;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800595 }
596
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800597 /* reset rest of the layers for MDP comp */
598 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
599 if(i != maxBatchStart){
600 mCurrentFrame.isFBComposed[i] = false;
601 } else {
602 i += maxBatchCount;
603 }
604 }
605
606 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700607 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
608 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800609
610 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
611 mCurrentFrame.fbCount);
612}
Saurabh Shah85234ec2013-04-12 17:09:00 -0700613
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800614void MDPComp::updateLayerCache(hwc_context_t* ctx,
615 hwc_display_contents_1_t* list) {
616
617 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
618 int numCacheableLayers = 0;
619
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800620 for(int i = 0; i < numAppLayers; i++) {
621 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
622 numCacheableLayers++;
623 mCurrentFrame.isFBComposed[i] = true;
624 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -0700625 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800626 mCachedFrame.hnd[i] = list->hwLayers[i].handle;
627 }
628 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700629
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800630 mCurrentFrame.fbCount = numCacheableLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700631 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
632 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800633 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__, numCacheableLayers);
634}
635
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800636void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list) {
637
638 int nYuvCount = ctx->listStats[mDpy].yuvCount;
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700639 if(!nYuvCount && mDpy) {
640 //Reset "No animation on external display" related parameters.
641 ctx->mPrevCropVideo.left = ctx->mPrevCropVideo.top =
642 ctx->mPrevCropVideo.right = ctx->mPrevCropVideo.bottom = 0;
643 ctx->mPrevDestVideo.left = ctx->mPrevDestVideo.top =
644 ctx->mPrevDestVideo.right = ctx->mPrevDestVideo.bottom = 0;
645 ctx->mPrevTransformVideo = 0;
646 return;
647 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800648 for(int index = 0;index < nYuvCount; index++){
649 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
650 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
651
652 if(!isYUVDoable(ctx, layer)) {
653 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
654 mCurrentFrame.isFBComposed[nYuvIndex] = true;
655 mCurrentFrame.fbCount++;
656 }
657 } else {
658 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
659 mCurrentFrame.isFBComposed[nYuvIndex] = false;
660 mCurrentFrame.fbCount--;
661 }
662 }
663 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700664
665 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
666 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800667 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
668 mCurrentFrame.fbCount);
669}
670
Saurabh Shahaa236822013-04-24 18:07:26 -0700671bool MDPComp::programMDP(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800672 if(!allocLayerPipes(ctx, list)) {
673 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700674 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800675 }
676
Saurabh Shahaa236822013-04-24 18:07:26 -0700677 bool fbBatch = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800678 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700679 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800680 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800681 int mdpIndex = mCurrentFrame.layerToMDP[index];
682 hwc_layer_1_t* layer = &list->hwLayers[index];
683
684 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
685 cur_pipe->zOrder = mdpNextZOrder++;
686
687 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
688 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
689 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -0700690 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800691 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700692 } else if(fbBatch == false) {
693 mdpNextZOrder++;
694 fbBatch = true;
695 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800696 }
697
Saurabh Shahaa236822013-04-24 18:07:26 -0700698 return true;
699}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800700
Saurabh Shahaa236822013-04-24 18:07:26 -0700701bool MDPComp::programYUV(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
702 if(!allocLayerPipes(ctx, list)) {
703 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
704 return false;
705 }
706 //If we are in this block, it means we have yuv + rgb layers both
707 int mdpIdx = 0;
708 for (int index = 0; index < mCurrentFrame.layerCount; index++) {
709 if(!mCurrentFrame.isFBComposed[index]) {
710 hwc_layer_1_t* layer = &list->hwLayers[index];
711 int mdpIndex = mCurrentFrame.layerToMDP[index];
712 MdpPipeInfo* cur_pipe =
713 mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
714 cur_pipe->zOrder = mdpIdx++;
715
716 if(configure(ctx, layer,
717 mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
718 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
719 layer %d",__FUNCTION__, index);
720 return false;
721 }
722 }
723 }
724 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800725}
726
727int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700728 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -0700729
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530730 { //LOCK SCOPE BEGIN
731 Locker::Autolock _l(mMdpCompLock);
Prabhanjan Kandula088bd892013-07-02 23:47:13 +0530732
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530733 //reset old data
Saurabh Shahaa236822013-04-24 18:07:26 -0700734 mCurrentFrame.reset(numLayers);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800735
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530736 //number of app layers exceeds MAX_NUM_APP_LAYERS fall back to GPU
737 //do not cache the information for next draw cycle.
738 if(numLayers > MAX_NUM_APP_LAYERS) {
739 mCachedFrame.updateCounts(mCurrentFrame);
740 ALOGD_IF(isDebug(), "%s: Number of App layers exceeded the limit ",
741 __FUNCTION__);
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700742 return -1;
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530743 }
744
745 //Hard conditions, if not met, cannot do MDP comp
746 if(!isFrameDoable(ctx)) {
747 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
748 __FUNCTION__);
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700749 reset(numLayers, list);
750 return -1;
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530751 }
752
753 //Check whether layers marked for MDP Composition is actually doable.
754 if(isFullFrameDoable(ctx, list)){
755 mCurrentFrame.map();
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700756 //Configure framebuffer first if applicable
757 if(mCurrentFrame.fbZ >= 0) {
758 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list,
759 mCurrentFrame.fbZ)) {
760 ALOGE("%s configure framebuffer failed", __func__);
761 reset(numLayers, list);
762 return -1;
763 }
764 }
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530765 //Acquire and Program MDP pipes
766 if(!programMDP(ctx, list)) {
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700767 reset(numLayers, list);
768 return -1;
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530769 } else { //Success
770 //Any change in composition types needs an FB refresh
771 mCurrentFrame.needsRedraw = false;
772 if(mCurrentFrame.fbCount &&
773 ((mCurrentFrame.mdpCount != mCachedFrame.mdpCount) ||
774 (mCurrentFrame.fbCount != mCachedFrame.cacheCount) ||
775 (mCurrentFrame.fbZ != mCachedFrame.fbZ) ||
776 (!mCurrentFrame.mdpCount) ||
777 (list->flags & HWC_GEOMETRY_CHANGED) ||
778 isSkipPresent(ctx, mDpy) ||
779 (mDpy > HWC_DISPLAY_PRIMARY))) {
780 mCurrentFrame.needsRedraw = true;
781 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700782 }
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530783 } else if(isOnlyVideoDoable(ctx, list)) {
784 //All layers marked for MDP comp cannot be bypassed.
785 //Try to compose atleast YUV layers through MDP comp and let
786 //all the RGB layers compose in FB
787 //Destination over
788 mCurrentFrame.fbZ = -1;
789 if(mCurrentFrame.fbCount)
790 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800791
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530792 mCurrentFrame.map();
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700793
794 //Configure framebuffer first if applicable
795 if(mCurrentFrame.fbZ >= 0) {
796 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, mCurrentFrame.fbZ)) {
797 ALOGE("%s configure framebuffer failed", __func__);
798 reset(numLayers, list);
799 return -1;
800 }
801 }
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530802 if(!programYUV(ctx, list)) {
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700803 reset(numLayers, list);
804 return -1;
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530805 }
806 } else {
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700807 reset(numLayers, list);
808 return -1;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800809 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800810
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530811 //UpdateLayerFlags
812 setMDPCompLayerFlags(ctx, list);
813 mCachedFrame.updateCounts(mCurrentFrame);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800814
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530815 } //LOCK SCOPE END. dump also need this lock.
816 // unlock it before calling dump function to avoid deadlock
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800817 if(isDebug()) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700818 ALOGD("GEOMETRY change: %d", (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800819 android::String8 sDump("");
820 dump(sDump);
821 ALOGE("%s",sDump.string());
822 }
823
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700824 return 0;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800825}
826
827//=============MDPCompLowRes===================================================
828
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700829/*
830 * Configures pipe(s) for MDP composition
831 */
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800832int MDPCompLowRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800833 PipeLayerPair& PipeLayerPair) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800834 MdpPipeInfoLowRes& mdp_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800835 *(static_cast<MdpPipeInfoLowRes*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -0800836 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
837 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
838 eIsFg isFg = IS_FG_OFF;
839 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700840
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800841 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
842 __FUNCTION__, layer, zOrder, dest);
843
844 return configureLowRes(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
845 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700846}
847
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700848bool MDPCompLowRes::arePipesAvailable(hwc_context_t *ctx,
849 hwc_display_contents_1_t* list) {
850 overlay::Overlay& ov = *ctx->mOverlay;
851 int numPipesNeeded = mCurrentFrame.mdpCount;
852 int availPipes = ov.availablePipes(mDpy, Overlay::MIXER_DEFAULT);
853
854 //Reserve pipe for FB
855 if(mCurrentFrame.fbCount)
856 availPipes -= 1;
857
858 if(numPipesNeeded > availPipes) {
859 ALOGD_IF(isDebug(), "%s: Insufficient pipes, dpy %d needed %d, avail %d",
860 __FUNCTION__, mDpy, numPipesNeeded, availPipes);
861 return false;
862 }
863
864 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700865}
866
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800867bool MDPCompLowRes::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700868 hwc_display_contents_1_t* list) {
869 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700870
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800871 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700872
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800873 hwc_layer_1_t* layer = &list->hwLayers[index];
874 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800875 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800876 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800877 info.pipeInfo = new MdpPipeInfoLowRes;
Saurabh Shahacf10202013-02-26 10:15:15 -0800878 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800879 MdpPipeInfoLowRes& pipe_info = *(MdpPipeInfoLowRes*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800880 ePipeType type = MDPCOMP_OV_ANY;
881
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700882 if(isYuvBuffer(hnd)) {
883 type = MDPCOMP_OV_VG;
Saurabh Shah8a117932013-05-23 12:48:13 -0700884 } else if(!qhwc::needsScaling(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -0700885 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
886 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800887 type = MDPCOMP_OV_DMA;
888 }
889
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700890 pipe_info.index = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800891 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700892 ALOGD_IF(isDebug(), "%s: Unable to get pipe type = %d",
893 __FUNCTION__, (int) type);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500894 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700895 }
896 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700897 return true;
898}
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700899
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800900bool MDPCompLowRes::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700901
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800902 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500903 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
904 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800905 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700906
907 if(!ctx || !list) {
908 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500909 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700910 }
911
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +0530912 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
913 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
914 return true;
915 }
916
Prabhanjan Kandula088bd892013-07-02 23:47:13 +0530917 Locker::Autolock _l(mMdpCompLock);
918
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500919 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -0700920 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500921 idleInvalidator->markForSleep();
922
923 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800924 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700925
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800926 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
927 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700928 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800929 if(mCurrentFrame.isFBComposed[i]) continue;
930
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700931 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -0800932 private_handle_t *hnd = (private_handle_t *)layer->handle;
933 if(!hnd) {
934 ALOGE("%s handle null", __FUNCTION__);
935 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700936 }
937
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800938 int mdpIndex = mCurrentFrame.layerToMDP[i];
939
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800940 MdpPipeInfoLowRes& pipe_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800941 *(MdpPipeInfoLowRes*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800942 ovutils::eDest dest = pipe_info.index;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800943 if(dest == ovutils::OV_INVALID) {
944 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500945 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700946 }
947
Saurabh Shahacf10202013-02-26 10:15:15 -0800948 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
949 continue;
950 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700951
Saurabh Shahacf10202013-02-26 10:15:15 -0800952 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800953 using pipe: %d", __FUNCTION__, layer,
954 hnd, dest );
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700955
Saurabh Shahacf10202013-02-26 10:15:15 -0800956 int fd = hnd->fd;
957 uint32_t offset = hnd->offset;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800958 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -0800959 if(rot) {
960 if(!rot->queueBuffer(fd, offset))
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500961 return false;
Saurabh Shahacf10202013-02-26 10:15:15 -0800962 fd = rot->getDstMemId();
963 offset = rot->getDstOffset();
964 }
965
966 if (!ov.queueBuffer(fd, offset, dest)) {
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +0530967 ALOGE("%s: queueBuffer failed for display:%d ", __FUNCTION__, mDpy);
Saurabh Shahacf10202013-02-26 10:15:15 -0800968 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700969 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500970
971 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700972 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500973 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700974}
975
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800976//=============MDPCompHighRes===================================================
977
978int MDPCompHighRes::pipesNeeded(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700979 hwc_display_contents_1_t* list,
980 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800981 int pipesNeeded = 0;
Saurabh Shah67a38c32013-06-10 16:23:15 -0700982 const int xres = ctx->dpyAttr[mDpy].xres;
983 //Default even split for all displays with high res
984 int lSplit = xres / 2;
985 if(mDpy == HWC_DISPLAY_PRIMARY &&
986 qdutils::MDPVersion::getInstance().getLeftSplit()) {
987 //Override if split published by driver for primary
988 lSplit = qdutils::MDPVersion::getInstance().getLeftSplit();
989 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800990
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800991 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
992 if(!mCurrentFrame.isFBComposed[i]) {
993 hwc_layer_1_t* layer = &list->hwLayers[i];
994 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700995 if(mixer == Overlay::MIXER_LEFT && dst.left < lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800996 pipesNeeded++;
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700997 } else if(mixer == Overlay::MIXER_RIGHT && dst.right > lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800998 pipesNeeded++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800999 }
1000 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001001 }
1002 return pipesNeeded;
1003}
1004
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001005bool MDPCompHighRes::arePipesAvailable(hwc_context_t *ctx,
1006 hwc_display_contents_1_t* list) {
1007 overlay::Overlay& ov = *ctx->mOverlay;
1008
1009 for(int i = 0; i < Overlay::MIXER_MAX; i++) {
1010 int numPipesNeeded = pipesNeeded(ctx, list, i);
1011 int availPipes = ov.availablePipes(mDpy, i);
1012
1013 //Reserve pipe(s)for FB
1014 if(mCurrentFrame.fbCount)
1015 availPipes -= 1;
1016
1017 if(numPipesNeeded > availPipes) {
1018 ALOGD_IF(isDebug(), "%s: Insufficient pipes for "
1019 "dpy %d mixer %d needed %d, avail %d",
1020 __FUNCTION__, mDpy, i, numPipesNeeded, availPipes);
1021 return false;
1022 }
1023 }
1024 return true;
1025}
1026
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001027bool MDPCompHighRes::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001028 MdpPipeInfoHighRes& pipe_info,
1029 ePipeType type) {
1030 const int xres = ctx->dpyAttr[mDpy].xres;
1031 //Default even split for all displays with high res
1032 int lSplit = xres / 2;
1033 if(mDpy == HWC_DISPLAY_PRIMARY &&
1034 qdutils::MDPVersion::getInstance().getLeftSplit()) {
1035 //Override if split published by driver for primary
1036 lSplit = qdutils::MDPVersion::getInstance().getLeftSplit();
1037 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001038
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001039 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001040 pipe_info.lIndex = ovutils::OV_INVALID;
1041 pipe_info.rIndex = ovutils::OV_INVALID;
1042
1043 if (dst.left < lSplit) {
1044 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_LEFT);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001045 if(pipe_info.lIndex == ovutils::OV_INVALID)
1046 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001047 }
1048
1049 if(dst.right > lSplit) {
1050 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_RIGHT);
1051 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001052 return false;
1053 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001054
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001055 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001056}
1057
1058bool MDPCompHighRes::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001059 hwc_display_contents_1_t* list) {
1060 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001061
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001062 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001063
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001064 hwc_layer_1_t* layer = &list->hwLayers[index];
1065 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001066 int mdpIndex = mCurrentFrame.layerToMDP[index];
1067 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001068 info.pipeInfo = new MdpPipeInfoHighRes;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001069 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001070 MdpPipeInfoHighRes& pipe_info = *(MdpPipeInfoHighRes*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001071 ePipeType type = MDPCOMP_OV_ANY;
1072
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001073 if(isYuvBuffer(hnd)) {
1074 type = MDPCOMP_OV_VG;
Saurabh Shah8a117932013-05-23 12:48:13 -07001075 } else if(!qhwc::needsScaling(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001076 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001077 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001078 type = MDPCOMP_OV_DMA;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001079 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001080
1081 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001082 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type = %d",
1083 __FUNCTION__, (int) type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001084 return false;
1085 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001086 }
1087 return true;
1088}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001089
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001090/*
1091 * Configures pipe(s) for MDP composition
1092 */
1093int MDPCompHighRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001094 PipeLayerPair& PipeLayerPair) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001095 MdpPipeInfoHighRes& mdp_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001096 *(static_cast<MdpPipeInfoHighRes*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001097 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1098 eIsFg isFg = IS_FG_OFF;
1099 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1100 eDest lDest = mdp_info.lIndex;
1101 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001102
1103 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1104 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1105
1106 return configureHighRes(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
1107 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001108}
1109
1110bool MDPCompHighRes::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
1111
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001112 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001113 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1114 return true;
1115 }
1116
1117 if(!ctx || !list) {
1118 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001119 return false;
1120 }
1121
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301122 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1123 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1124 return true;
1125 }
1126
Prabhanjan Kandula088bd892013-07-02 23:47:13 +05301127 Locker::Autolock _l(mMdpCompLock);
1128
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001129 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001130 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001131 idleInvalidator->markForSleep();
1132
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001133 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001134 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001135
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001136 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1137 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001138 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001139 if(mCurrentFrame.isFBComposed[i]) continue;
1140
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001141 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001142 private_handle_t *hnd = (private_handle_t *)layer->handle;
1143 if(!hnd) {
1144 ALOGE("%s handle null", __FUNCTION__);
1145 return false;
1146 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001147
1148 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1149 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001150 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001151
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001152 int mdpIndex = mCurrentFrame.layerToMDP[i];
1153
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001154 MdpPipeInfoHighRes& pipe_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001155 *(MdpPipeInfoHighRes*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1156 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -08001157
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001158 ovutils::eDest indexL = pipe_info.lIndex;
1159 ovutils::eDest indexR = pipe_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001160
Saurabh Shahacf10202013-02-26 10:15:15 -08001161 int fd = hnd->fd;
1162 int offset = hnd->offset;
1163
1164 if(rot) {
1165 rot->queueBuffer(fd, offset);
1166 fd = rot->getDstMemId();
1167 offset = rot->getDstOffset();
1168 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001169
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001170 //************* play left mixer **********
1171 if(indexL != ovutils::OV_INVALID) {
1172 ovutils::eDest destL = (ovutils::eDest)indexL;
Saurabh Shahacf10202013-02-26 10:15:15 -08001173 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001174 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
Saurabh Shahacf10202013-02-26 10:15:15 -08001175 if (!ov.queueBuffer(fd, offset, destL)) {
1176 ALOGE("%s: queueBuffer failed for left mixer", __FUNCTION__);
1177 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001178 }
1179 }
1180
1181 //************* play right mixer **********
1182 if(indexR != ovutils::OV_INVALID) {
1183 ovutils::eDest destR = (ovutils::eDest)indexR;
Saurabh Shahacf10202013-02-26 10:15:15 -08001184 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001185 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
Saurabh Shahacf10202013-02-26 10:15:15 -08001186 if (!ov.queueBuffer(fd, offset, destR)) {
1187 ALOGE("%s: queueBuffer failed for right mixer", __FUNCTION__);
1188 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001189 }
1190 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001191
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001192 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1193 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001194
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001195 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001196}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001197}; //namespace
1198