blob: 496050591c69ec51a167590f5f7a4d29d9965066 [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
Zohaib Alamd9743242013-07-19 16:07:34 -0400124 long idle_timeout = DEFAULT_IDLE_TIME;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800125 if(property_get("debug.mdpcomp.idletime", property, NULL) > 0) {
126 if(atoi(property) != 0)
127 idle_timeout = atoi(property);
128 }
129
Zohaib Alamd9743242013-07-19 16:07:34 -0400130 //create Idle Invalidator only when not disabled through property
131 if(idle_timeout != -1)
132 idleInvalidator = IdleInvalidator::getInstance();
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800133
134 if(idleInvalidator == NULL) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800135 ALOGE("%s: failed to instantiate idleInvalidator object", __FUNCTION__);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800136 } else {
137 idleInvalidator->init(timeout_handler, ctx, idle_timeout);
138 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700139 return true;
140}
141
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700142void MDPComp::reset(const int& numLayers, hwc_display_contents_1_t* list) {
143 mCurrentFrame.reset(numLayers);
144 mCachedFrame.cacheAll(list);
145 mCachedFrame.updateCounts(mCurrentFrame);
146}
147
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700148void MDPComp::timeout_handler(void *udata) {
149 struct hwc_context_t* ctx = (struct hwc_context_t*)(udata);
150
151 if(!ctx) {
152 ALOGE("%s: received empty data in timer callback", __FUNCTION__);
153 return;
154 }
155
Jesse Hall3be78d92012-08-21 15:12:23 -0700156 if(!ctx->proc) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700157 ALOGE("%s: HWC proc not registered", __FUNCTION__);
158 return;
159 }
160 sIdleFallBack = true;
161 /* Trigger SF to redraw the current frame */
Jesse Hall3be78d92012-08-21 15:12:23 -0700162 ctx->proc->invalidate(ctx->proc);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700163}
164
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800165void MDPComp::setMDPCompLayerFlags(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800166 hwc_display_contents_1_t* list) {
167 LayerProp *layerProp = ctx->layerProp[mDpy];
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800168
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800169 for(int index = 0; index < ctx->listStats[mDpy].numAppLayers; index++) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800170 hwc_layer_1_t* layer = &(list->hwLayers[index]);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800171 if(!mCurrentFrame.isFBComposed[index]) {
172 layerProp[index].mFlags |= HWC_MDPCOMP;
173 layer->compositionType = HWC_OVERLAY;
174 layer->hints |= HWC_HINT_CLEAR_FB;
175 mCachedFrame.hnd[index] = NULL;
176 } else {
177 if(!mCurrentFrame.needsRedraw)
178 layer->compositionType = HWC_OVERLAY;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800179 }
180 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700181}
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500182
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800183/*
184 * Sets up BORDERFILL as default base pipe and detaches RGB0.
185 * Framebuffer is always updated using PLAY ioctl.
186 */
187bool MDPComp::setupBasePipe(hwc_context_t *ctx) {
188 const int dpy = HWC_DISPLAY_PRIMARY;
189 int fb_stride = ctx->dpyAttr[dpy].stride;
190 int fb_width = ctx->dpyAttr[dpy].xres;
191 int fb_height = ctx->dpyAttr[dpy].yres;
192 int fb_fd = ctx->dpyAttr[dpy].fd;
193
194 mdp_overlay ovInfo;
195 msmfb_overlay_data ovData;
196 memset(&ovInfo, 0, sizeof(mdp_overlay));
197 memset(&ovData, 0, sizeof(msmfb_overlay_data));
198
199 ovInfo.src.format = MDP_RGB_BORDERFILL;
200 ovInfo.src.width = fb_width;
201 ovInfo.src.height = fb_height;
202 ovInfo.src_rect.w = fb_width;
203 ovInfo.src_rect.h = fb_height;
204 ovInfo.dst_rect.w = fb_width;
205 ovInfo.dst_rect.h = fb_height;
206 ovInfo.id = MSMFB_NEW_REQUEST;
207
208 if (ioctl(fb_fd, MSMFB_OVERLAY_SET, &ovInfo) < 0) {
209 ALOGE("Failed to call ioctl MSMFB_OVERLAY_SET err=%s",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800210 strerror(errno));
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800211 return false;
212 }
213
214 ovData.id = ovInfo.id;
215 if (ioctl(fb_fd, MSMFB_OVERLAY_PLAY, &ovData) < 0) {
216 ALOGE("Failed to call ioctl MSMFB_OVERLAY_PLAY err=%s",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800217 strerror(errno));
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800218 return false;
219 }
220 return true;
221}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800222MDPComp::FrameInfo::FrameInfo() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700223 reset(0);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800224}
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800225
Saurabh Shahaa236822013-04-24 18:07:26 -0700226void MDPComp::FrameInfo::reset(const int& numLayers) {
227 for(int i = 0 ; i < MAX_PIPES_PER_MIXER && numLayers; i++ ) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800228 if(mdpToLayer[i].pipeInfo) {
229 delete mdpToLayer[i].pipeInfo;
230 mdpToLayer[i].pipeInfo = NULL;
231 //We dont own the rotator
232 mdpToLayer[i].rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800233 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800234 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800235
236 memset(&mdpToLayer, 0, sizeof(mdpToLayer));
237 memset(&layerToMDP, -1, sizeof(layerToMDP));
Saurabh Shahaa236822013-04-24 18:07:26 -0700238 memset(&isFBComposed, 1, sizeof(isFBComposed));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800239
Saurabh Shahaa236822013-04-24 18:07:26 -0700240 layerCount = numLayers;
241 fbCount = numLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800242 mdpCount = 0;
Saurabh Shah2f3895f2013-05-02 10:13:31 -0700243 needsRedraw = true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800244 fbZ = 0;
245}
246
Saurabh Shahaa236822013-04-24 18:07:26 -0700247void MDPComp::FrameInfo::map() {
248 // populate layer and MDP maps
249 int mdpIdx = 0;
250 for(int idx = 0; idx < layerCount; idx++) {
251 if(!isFBComposed[idx]) {
252 mdpToLayer[mdpIdx].listIndex = idx;
253 layerToMDP[idx] = mdpIdx++;
254 }
255 }
256}
257
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800258MDPComp::LayerCache::LayerCache() {
259 reset();
260}
261
262void MDPComp::LayerCache::reset() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700263 memset(&hnd, 0, sizeof(hnd));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800264 mdpCount = 0;
265 cacheCount = 0;
266 layerCount = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -0700267 fbZ = -1;
268}
269
270void MDPComp::LayerCache::cacheAll(hwc_display_contents_1_t* list) {
271 const int numAppLayers = list->numHwLayers - 1;
272 for(int i = 0; i < numAppLayers; i++) {
273 hnd[i] = list->hwLayers[i].handle;
274 }
275}
276
277void MDPComp::LayerCache::updateCounts(const FrameInfo& curFrame) {
278 mdpCount = curFrame.mdpCount;
279 cacheCount = curFrame.fbCount;
280 layerCount = curFrame.layerCount;
281 fbZ = curFrame.fbZ;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800282}
283
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530284bool MDPComp::isValidDimension(hwc_context_t *ctx, hwc_layer_1_t *layer) {
Saurabh Shah4fdde762013-04-30 18:47:33 -0700285 const int dpy = HWC_DISPLAY_PRIMARY;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800286 private_handle_t *hnd = (private_handle_t *)layer->handle;
287
288 if(!hnd) {
289 ALOGE("%s: layer handle is NULL", __FUNCTION__);
290 return false;
291 }
292
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800293 int hw_w = ctx->dpyAttr[mDpy].xres;
294 int hw_h = ctx->dpyAttr[mDpy].yres;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800295
Saurabh Shah4fdde762013-04-30 18:47:33 -0700296 hwc_rect_t crop = layer->sourceCrop;
297 hwc_rect_t dst = layer->displayFrame;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800298
299 if(dst.left < 0 || dst.top < 0 || dst.right > hw_w || dst.bottom > hw_h) {
Saurabh Shah4fdde762013-04-30 18:47:33 -0700300 hwc_rect_t scissor = {0, 0, hw_w, hw_h };
301 qhwc::calculate_crop_rects(crop, dst, scissor, layer->transform);
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800302 }
303
Saurabh Shah4fdde762013-04-30 18:47:33 -0700304 int crop_w = crop.right - crop.left;
305 int crop_h = crop.bottom - crop.top;
306 int dst_w = dst.right - dst.left;
307 int dst_h = dst.bottom - dst.top;
308 float w_dscale = ceilf((float)crop_w / (float)dst_w);
309 float h_dscale = ceilf((float)crop_h / (float)dst_h);
310
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800311 /* Workaround for MDP HW limitation in DSI command mode panels where
312 * FPS will not go beyond 30 if buffers on RGB pipes are of width or height
313 * less than 5 pixels
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530314 * There also is a HW limilation in MDP, minimum block size is 2x2
315 * Fallback to GPU if height is less than 2.
316 */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800317 if((crop_w < 5)||(crop_h < 5))
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800318 return false;
319
Saurabh Shah4fdde762013-04-30 18:47:33 -0700320 const uint32_t downscale =
321 qdutils::MDPVersion::getInstance().getMaxMDPDownscale();
322 if(ctx->mMDP.version >= qdutils::MDSS_V5) {
323 /* Workaround for downscales larger than 4x.
324 * Will be removed once decimator block is enabled for MDSS
325 */
326 if(!qdutils::MDPVersion::getInstance().supportsDecimation()) {
327 if(crop_w > MAX_DISPLAY_DIM || w_dscale > downscale ||
328 h_dscale > downscale)
329 return false;
330 } else {
331 if(w_dscale > 64 || h_dscale > 64)
332 return false;
333 }
334 } else { //A-family
335 if(w_dscale > downscale || h_dscale > downscale)
336 return false;
337 }
338
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800339 return true;
340}
341
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700342ovutils::eDest MDPComp::getMdpPipe(hwc_context_t *ctx, ePipeType type,
343 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800344 overlay::Overlay& ov = *ctx->mOverlay;
345 ovutils::eDest mdp_pipe = ovutils::OV_INVALID;
346
347 switch(type) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800348 case MDPCOMP_OV_DMA:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700349 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_DMA, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800350 if(mdp_pipe != ovutils::OV_INVALID) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800351 return mdp_pipe;
352 }
353 case MDPCOMP_OV_ANY:
354 case MDPCOMP_OV_RGB:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700355 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800356 if(mdp_pipe != ovutils::OV_INVALID) {
357 return mdp_pipe;
358 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800359
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800360 if(type == MDPCOMP_OV_RGB) {
361 //Requested only for RGB pipe
362 break;
363 }
364 case MDPCOMP_OV_VG:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700365 return ov.nextPipe(ovutils::OV_MDP_PIPE_VG, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800366 default:
367 ALOGE("%s: Invalid pipe type",__FUNCTION__);
368 return ovutils::OV_INVALID;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800369 };
370 return ovutils::OV_INVALID;
371}
372
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800373bool MDPComp::isFrameDoable(hwc_context_t *ctx) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700374 bool ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700375 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800376
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800377 if(!isEnabled()) {
378 ALOGD_IF(isDebug(),"%s: MDP Comp. not enabled.", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700379 ret = false;
Saurabh Shahd4e65852013-06-17 11:33:53 -0700380 } else if(qdutils::MDPVersion::getInstance().is8x26() &&
381 ctx->mVideoTransFlag &&
382 ctx->mExtDisplay->isExternalConnected()) {
383 //1 Padding round to shift pipes across mixers
384 ALOGD_IF(isDebug(),"%s: MDP Comp. video transition padding round",
385 __FUNCTION__);
386 ret = false;
Saurabh Shahaa236822013-04-24 18:07:26 -0700387 } else if(ctx->mExtDispConfiguring) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800388 ALOGD_IF( isDebug(),"%s: External Display connection is pending",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800389 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700390 ret = false;
Saurabh Shahaa236822013-04-24 18:07:26 -0700391 } else if(ctx->isPaddingRound) {
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700392 ctx->isPaddingRound = false;
393 ALOGD_IF(isDebug(), "%s: padding round",__FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700394 ret = false;
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700395 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700396 return ret;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800397}
398
399/* Checks for conditions where all the layers marked for MDP comp cannot be
400 * bypassed. On such conditions we try to bypass atleast YUV layers */
401bool MDPComp::isFullFrameDoable(hwc_context_t *ctx,
402 hwc_display_contents_1_t* list){
403
Saurabh Shahaa236822013-04-24 18:07:26 -0700404 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800405
Saurabh Shah2d998a92013-05-14 17:55:58 -0700406 if(sIdleFallBack) {
407 ALOGD_IF(isDebug(), "%s: Idle fallback dpy %d",__FUNCTION__, mDpy);
408 return false;
409 }
410
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800411 if(mDpy > HWC_DISPLAY_PRIMARY){
412 ALOGD_IF(isDebug(), "%s: Cannot support External display(s)",
413 __FUNCTION__);
414 return false;
415 }
416
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800417 if(isSkipPresent(ctx, mDpy)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700418 ALOGD_IF(isDebug(),"%s: SKIP present: %d",
419 __FUNCTION__,
420 isSkipPresent(ctx, mDpy));
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800421 return false;
422 }
423
Saurabh Shah9f084ad2013-05-02 11:28:09 -0700424 if(ctx->listStats[mDpy].needsAlphaScale
425 && ctx->mMDP.version < qdutils::MDSS_V5) {
426 ALOGD_IF(isDebug(), "%s: frame needs alpha downscaling",__FUNCTION__);
427 return false;
428 }
429
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800430 //MDP composition is not efficient if layer needs rotator.
431 for(int i = 0; i < numAppLayers; ++i) {
432 // As MDP h/w supports flip operation, use MDP comp only for
433 // 180 transforms. Fail for any transform involving 90 (90, 270).
434 hwc_layer_1_t* layer = &list->hwLayers[i];
435 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800436
Saurabh Shah4fdde762013-04-30 18:47:33 -0700437 if((layer->transform & HWC_TRANSFORM_ROT_90) && !isYuvBuffer(hnd)) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800438 ALOGD_IF(isDebug(), "%s: orientation involved",__FUNCTION__);
439 return false;
440 }
441
Saurabh Shah4fdde762013-04-30 18:47:33 -0700442 if(!isValidDimension(ctx,layer)) {
443 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
444 __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800445 return false;
446 }
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530447
448 //For 8x26 with panel width>1k, if RGB layer needs HFLIP fail mdp comp
449 // may not need it if Gfx pre-rotation can handle all flips & rotations
450 if(qdutils::MDPVersion::getInstance().is8x26() &&
451 (ctx->dpyAttr[mDpy].xres > 1024) &&
452 (layer->transform & HWC_TRANSFORM_FLIP_H) &&
453 (!isYuvBuffer(hnd)))
454 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800455 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700456
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700457 if(ctx->mAD->isDoable()) {
458 return false;
459 }
460
Saurabh Shahaa236822013-04-24 18:07:26 -0700461 //If all above hard conditions are met we can do full or partial MDP comp.
462 bool ret = false;
463 if(fullMDPComp(ctx, list)) {
464 ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700465 } else if(partialMDPComp(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700466 ret = true;
467 }
468 return ret;
469}
470
471bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
472 //Setup mCurrentFrame
473 mCurrentFrame.mdpCount = mCurrentFrame.layerCount;
474 mCurrentFrame.fbCount = 0;
475 mCurrentFrame.fbZ = -1;
476 memset(&mCurrentFrame.isFBComposed, 0, sizeof(mCurrentFrame.isFBComposed));
477
478 int mdpCount = mCurrentFrame.mdpCount;
479 if(mdpCount > sMaxPipesPerMixer) {
480 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
481 return false;
482 }
483
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700484 if(!arePipesAvailable(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700485 return false;
486 }
487
488 return true;
489}
490
491bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
492{
493 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700494
495 if(!sEnableMixedMode) {
496 //Mixed mode is disabled. No need to even try caching.
497 return false;
498 }
499
Saurabh Shahaa236822013-04-24 18:07:26 -0700500 //Setup mCurrentFrame
501 mCurrentFrame.reset(numAppLayers);
502 updateLayerCache(ctx, list);
503 updateYUV(ctx, list);
504 batchLayers(); //sets up fbZ also
505
506 int mdpCount = mCurrentFrame.mdpCount;
507 if(mdpCount > (sMaxPipesPerMixer - 1)) { // -1 since FB is used
508 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
509 return false;
510 }
511
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700512 if(!arePipesAvailable(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700513 return false;
514 }
515
516 return true;
517}
518
519bool MDPComp::isOnlyVideoDoable(hwc_context_t *ctx,
520 hwc_display_contents_1_t* list){
521 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
522 mCurrentFrame.reset(numAppLayers);
523 updateYUV(ctx, list);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700524 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700525 int fbNeeded = int(mCurrentFrame.fbCount != 0);
526
527 if(!isYuvPresent(ctx, mDpy)) {
528 return false;
529 }
530
Saurabh Shah4fdde762013-04-30 18:47:33 -0700531 if(!mdpCount)
532 return false;
533
Saurabh Shahaa236822013-04-24 18:07:26 -0700534 if(mdpCount > (sMaxPipesPerMixer - fbNeeded)) {
535 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
536 return false;
537 }
538
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700539 if(!arePipesAvailable(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700540 return false;
541 }
542
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800543 return true;
544}
545
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800546/* Checks for conditions where YUV layers cannot be bypassed */
547bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Saurabh Shahe2474082013-05-15 16:32:13 -0700548 bool extAnimBlockFeature = mDpy && ctx->listStats[mDpy].isDisplayAnimating;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800549
Saurabh Shahe2474082013-05-15 16:32:13 -0700550 if(isSkipLayer(layer) && !extAnimBlockFeature) {
551 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800552 return false;
553 }
554
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800555 if(isSecuring(ctx, layer)) {
556 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
557 return false;
558 }
559
Saurabh Shah4fdde762013-04-30 18:47:33 -0700560 if(!isValidDimension(ctx, layer)) {
561 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
562 __FUNCTION__);
563 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800564 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700565
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800566 return true;
567}
568
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800569void MDPComp::batchLayers() {
570 /* Idea is to keep as many contiguous non-updating(cached) layers in FB and
571 * send rest of them through MDP. NEVER mark an updating layer for caching.
572 * But cached ones can be marked for MDP*/
573
574 int maxBatchStart = -1;
575 int maxBatchCount = 0;
576
577 /* All or Nothing is cached. No batching needed */
Saurabh Shahaa236822013-04-24 18:07:26 -0700578 if(!mCurrentFrame.fbCount) {
579 mCurrentFrame.fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800580 return;
Saurabh Shahaa236822013-04-24 18:07:26 -0700581 }
582 if(!mCurrentFrame.mdpCount) {
583 mCurrentFrame.fbZ = 0;
584 return;
585 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800586
587 /* Search for max number of contiguous (cached) layers */
588 int i = 0;
589 while (i < mCurrentFrame.layerCount) {
590 int count = 0;
591 while(mCurrentFrame.isFBComposed[i] && i < mCurrentFrame.layerCount) {
592 count++; i++;
593 }
594 if(count > maxBatchCount) {
595 maxBatchCount = count;
596 maxBatchStart = i - count;
Saurabh Shahaa236822013-04-24 18:07:26 -0700597 mCurrentFrame.fbZ = maxBatchStart;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800598 }
599 if(i < mCurrentFrame.layerCount) i++;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800600 }
601
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800602 /* reset rest of the layers for MDP comp */
603 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
604 if(i != maxBatchStart){
605 mCurrentFrame.isFBComposed[i] = false;
606 } else {
607 i += maxBatchCount;
608 }
609 }
610
611 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700612 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
613 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800614
615 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
616 mCurrentFrame.fbCount);
617}
Saurabh Shah85234ec2013-04-12 17:09:00 -0700618
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800619void MDPComp::updateLayerCache(hwc_context_t* ctx,
620 hwc_display_contents_1_t* list) {
621
622 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
623 int numCacheableLayers = 0;
624
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800625 for(int i = 0; i < numAppLayers; i++) {
626 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
627 numCacheableLayers++;
628 mCurrentFrame.isFBComposed[i] = true;
629 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -0700630 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800631 mCachedFrame.hnd[i] = list->hwLayers[i].handle;
632 }
633 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700634
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800635 mCurrentFrame.fbCount = numCacheableLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700636 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
637 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800638 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__, numCacheableLayers);
639}
640
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800641void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list) {
642
643 int nYuvCount = ctx->listStats[mDpy].yuvCount;
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700644 if(!nYuvCount && mDpy) {
645 //Reset "No animation on external display" related parameters.
646 ctx->mPrevCropVideo.left = ctx->mPrevCropVideo.top =
647 ctx->mPrevCropVideo.right = ctx->mPrevCropVideo.bottom = 0;
648 ctx->mPrevDestVideo.left = ctx->mPrevDestVideo.top =
649 ctx->mPrevDestVideo.right = ctx->mPrevDestVideo.bottom = 0;
650 ctx->mPrevTransformVideo = 0;
651 return;
652 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800653 for(int index = 0;index < nYuvCount; index++){
654 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
655 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
656
657 if(!isYUVDoable(ctx, layer)) {
658 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
659 mCurrentFrame.isFBComposed[nYuvIndex] = true;
660 mCurrentFrame.fbCount++;
661 }
662 } else {
663 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
664 mCurrentFrame.isFBComposed[nYuvIndex] = false;
665 mCurrentFrame.fbCount--;
666 }
667 }
668 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700669
670 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
671 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800672 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
673 mCurrentFrame.fbCount);
674}
675
Saurabh Shahaa236822013-04-24 18:07:26 -0700676bool MDPComp::programMDP(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800677 if(!allocLayerPipes(ctx, list)) {
678 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700679 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800680 }
681
Saurabh Shahaa236822013-04-24 18:07:26 -0700682 bool fbBatch = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800683 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700684 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800685 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800686 int mdpIndex = mCurrentFrame.layerToMDP[index];
687 hwc_layer_1_t* layer = &list->hwLayers[index];
688
689 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
690 cur_pipe->zOrder = mdpNextZOrder++;
691
692 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
693 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
694 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -0700695 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800696 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700697 } else if(fbBatch == false) {
698 mdpNextZOrder++;
699 fbBatch = true;
700 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800701 }
702
Saurabh Shahaa236822013-04-24 18:07:26 -0700703 return true;
704}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800705
Saurabh Shahaa236822013-04-24 18:07:26 -0700706bool MDPComp::programYUV(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
707 if(!allocLayerPipes(ctx, list)) {
708 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
709 return false;
710 }
711 //If we are in this block, it means we have yuv + rgb layers both
712 int mdpIdx = 0;
713 for (int index = 0; index < mCurrentFrame.layerCount; index++) {
714 if(!mCurrentFrame.isFBComposed[index]) {
715 hwc_layer_1_t* layer = &list->hwLayers[index];
716 int mdpIndex = mCurrentFrame.layerToMDP[index];
717 MdpPipeInfo* cur_pipe =
718 mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
719 cur_pipe->zOrder = mdpIdx++;
720
721 if(configure(ctx, layer,
722 mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
723 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
724 layer %d",__FUNCTION__, index);
725 return false;
726 }
727 }
728 }
729 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800730}
731
732int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700733 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -0700734
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530735 { //LOCK SCOPE BEGIN
736 Locker::Autolock _l(mMdpCompLock);
Prabhanjan Kandula088bd892013-07-02 23:47:13 +0530737
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530738 //reset old data
Saurabh Shahaa236822013-04-24 18:07:26 -0700739 mCurrentFrame.reset(numLayers);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800740
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530741 //number of app layers exceeds MAX_NUM_APP_LAYERS fall back to GPU
742 //do not cache the information for next draw cycle.
743 if(numLayers > MAX_NUM_APP_LAYERS) {
744 mCachedFrame.updateCounts(mCurrentFrame);
745 ALOGD_IF(isDebug(), "%s: Number of App layers exceeded the limit ",
746 __FUNCTION__);
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700747 return -1;
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530748 }
749
750 //Hard conditions, if not met, cannot do MDP comp
751 if(!isFrameDoable(ctx)) {
752 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
753 __FUNCTION__);
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700754 reset(numLayers, list);
755 return -1;
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530756 }
757
758 //Check whether layers marked for MDP Composition is actually doable.
759 if(isFullFrameDoable(ctx, list)){
760 mCurrentFrame.map();
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700761 //Configure framebuffer first if applicable
762 if(mCurrentFrame.fbZ >= 0) {
763 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list,
764 mCurrentFrame.fbZ)) {
765 ALOGE("%s configure framebuffer failed", __func__);
766 reset(numLayers, list);
767 return -1;
768 }
769 }
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530770 //Acquire and Program MDP pipes
771 if(!programMDP(ctx, list)) {
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700772 reset(numLayers, list);
773 return -1;
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530774 } else { //Success
775 //Any change in composition types needs an FB refresh
776 mCurrentFrame.needsRedraw = false;
777 if(mCurrentFrame.fbCount &&
778 ((mCurrentFrame.mdpCount != mCachedFrame.mdpCount) ||
779 (mCurrentFrame.fbCount != mCachedFrame.cacheCount) ||
780 (mCurrentFrame.fbZ != mCachedFrame.fbZ) ||
781 (!mCurrentFrame.mdpCount) ||
782 (list->flags & HWC_GEOMETRY_CHANGED) ||
783 isSkipPresent(ctx, mDpy) ||
784 (mDpy > HWC_DISPLAY_PRIMARY))) {
785 mCurrentFrame.needsRedraw = true;
786 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700787 }
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530788 } else if(isOnlyVideoDoable(ctx, list)) {
789 //All layers marked for MDP comp cannot be bypassed.
790 //Try to compose atleast YUV layers through MDP comp and let
791 //all the RGB layers compose in FB
792 //Destination over
793 mCurrentFrame.fbZ = -1;
794 if(mCurrentFrame.fbCount)
795 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800796
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530797 mCurrentFrame.map();
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700798
799 //Configure framebuffer first if applicable
800 if(mCurrentFrame.fbZ >= 0) {
801 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, mCurrentFrame.fbZ)) {
802 ALOGE("%s configure framebuffer failed", __func__);
803 reset(numLayers, list);
804 return -1;
805 }
806 }
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530807 if(!programYUV(ctx, list)) {
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700808 reset(numLayers, list);
809 return -1;
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530810 }
811 } else {
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700812 reset(numLayers, list);
813 return -1;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800814 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800815
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530816 //UpdateLayerFlags
817 setMDPCompLayerFlags(ctx, list);
818 mCachedFrame.updateCounts(mCurrentFrame);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800819
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530820 } //LOCK SCOPE END. dump also need this lock.
821 // unlock it before calling dump function to avoid deadlock
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800822 if(isDebug()) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700823 ALOGD("GEOMETRY change: %d", (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800824 android::String8 sDump("");
825 dump(sDump);
826 ALOGE("%s",sDump.string());
827 }
828
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700829 return 0;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800830}
831
832//=============MDPCompLowRes===================================================
833
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700834/*
835 * Configures pipe(s) for MDP composition
836 */
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800837int MDPCompLowRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800838 PipeLayerPair& PipeLayerPair) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800839 MdpPipeInfoLowRes& mdp_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800840 *(static_cast<MdpPipeInfoLowRes*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -0800841 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
842 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
843 eIsFg isFg = IS_FG_OFF;
844 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700845
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800846 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
847 __FUNCTION__, layer, zOrder, dest);
848
849 return configureLowRes(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
850 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700851}
852
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700853bool MDPCompLowRes::arePipesAvailable(hwc_context_t *ctx,
854 hwc_display_contents_1_t* list) {
855 overlay::Overlay& ov = *ctx->mOverlay;
856 int numPipesNeeded = mCurrentFrame.mdpCount;
857 int availPipes = ov.availablePipes(mDpy, Overlay::MIXER_DEFAULT);
858
859 //Reserve pipe for FB
860 if(mCurrentFrame.fbCount)
861 availPipes -= 1;
862
863 if(numPipesNeeded > availPipes) {
864 ALOGD_IF(isDebug(), "%s: Insufficient pipes, dpy %d needed %d, avail %d",
865 __FUNCTION__, mDpy, numPipesNeeded, availPipes);
866 return false;
867 }
868
869 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700870}
871
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800872bool MDPCompLowRes::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700873 hwc_display_contents_1_t* list) {
874 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700875
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800876 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700877
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800878 hwc_layer_1_t* layer = &list->hwLayers[index];
879 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800880 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800881 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800882 info.pipeInfo = new MdpPipeInfoLowRes;
Saurabh Shahacf10202013-02-26 10:15:15 -0800883 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800884 MdpPipeInfoLowRes& pipe_info = *(MdpPipeInfoLowRes*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800885 ePipeType type = MDPCOMP_OV_ANY;
886
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700887 if(isYuvBuffer(hnd)) {
888 type = MDPCOMP_OV_VG;
Saurabh Shah8a117932013-05-23 12:48:13 -0700889 } else if(!qhwc::needsScaling(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -0700890 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
891 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800892 type = MDPCOMP_OV_DMA;
893 }
894
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700895 pipe_info.index = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800896 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700897 ALOGD_IF(isDebug(), "%s: Unable to get pipe type = %d",
898 __FUNCTION__, (int) type);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500899 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700900 }
901 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700902 return true;
903}
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700904
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800905bool MDPCompLowRes::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700906
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800907 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500908 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
909 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800910 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700911
912 if(!ctx || !list) {
913 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500914 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700915 }
916
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +0530917 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
918 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
919 return true;
920 }
921
Prabhanjan Kandula088bd892013-07-02 23:47:13 +0530922 Locker::Autolock _l(mMdpCompLock);
923
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500924 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -0700925 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500926 idleInvalidator->markForSleep();
927
928 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800929 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700930
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800931 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
932 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700933 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800934 if(mCurrentFrame.isFBComposed[i]) continue;
935
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700936 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -0800937 private_handle_t *hnd = (private_handle_t *)layer->handle;
938 if(!hnd) {
939 ALOGE("%s handle null", __FUNCTION__);
940 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700941 }
942
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800943 int mdpIndex = mCurrentFrame.layerToMDP[i];
944
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800945 MdpPipeInfoLowRes& pipe_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800946 *(MdpPipeInfoLowRes*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800947 ovutils::eDest dest = pipe_info.index;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800948 if(dest == ovutils::OV_INVALID) {
949 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500950 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700951 }
952
Saurabh Shahacf10202013-02-26 10:15:15 -0800953 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
954 continue;
955 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700956
Saurabh Shahacf10202013-02-26 10:15:15 -0800957 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800958 using pipe: %d", __FUNCTION__, layer,
959 hnd, dest );
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700960
Saurabh Shahacf10202013-02-26 10:15:15 -0800961 int fd = hnd->fd;
962 uint32_t offset = hnd->offset;
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700963
964 if(ctx->mAD->isModeOn()) {
965 if(ctx->mAD->draw(ctx, fd, offset)) {
966 fd = ctx->mAD->getDstFd(ctx);
967 offset = ctx->mAD->getDstOffset(ctx);
968 }
969 }
970
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800971 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -0800972 if(rot) {
973 if(!rot->queueBuffer(fd, offset))
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500974 return false;
Saurabh Shahacf10202013-02-26 10:15:15 -0800975 fd = rot->getDstMemId();
976 offset = rot->getDstOffset();
977 }
978
979 if (!ov.queueBuffer(fd, offset, dest)) {
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +0530980 ALOGE("%s: queueBuffer failed for display:%d ", __FUNCTION__, mDpy);
Saurabh Shahacf10202013-02-26 10:15:15 -0800981 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700982 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500983
984 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700985 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500986 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700987}
988
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800989//=============MDPCompHighRes===================================================
990
991int MDPCompHighRes::pipesNeeded(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700992 hwc_display_contents_1_t* list,
993 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800994 int pipesNeeded = 0;
Saurabh Shah67a38c32013-06-10 16:23:15 -0700995 const int xres = ctx->dpyAttr[mDpy].xres;
996 //Default even split for all displays with high res
997 int lSplit = xres / 2;
998 if(mDpy == HWC_DISPLAY_PRIMARY &&
999 qdutils::MDPVersion::getInstance().getLeftSplit()) {
1000 //Override if split published by driver for primary
1001 lSplit = qdutils::MDPVersion::getInstance().getLeftSplit();
1002 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001003
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001004 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1005 if(!mCurrentFrame.isFBComposed[i]) {
1006 hwc_layer_1_t* layer = &list->hwLayers[i];
1007 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001008 if(mixer == Overlay::MIXER_LEFT && dst.left < lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001009 pipesNeeded++;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001010 } else if(mixer == Overlay::MIXER_RIGHT && dst.right > lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001011 pipesNeeded++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001012 }
1013 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001014 }
1015 return pipesNeeded;
1016}
1017
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001018bool MDPCompHighRes::arePipesAvailable(hwc_context_t *ctx,
1019 hwc_display_contents_1_t* list) {
1020 overlay::Overlay& ov = *ctx->mOverlay;
1021
1022 for(int i = 0; i < Overlay::MIXER_MAX; i++) {
1023 int numPipesNeeded = pipesNeeded(ctx, list, i);
1024 int availPipes = ov.availablePipes(mDpy, i);
1025
1026 //Reserve pipe(s)for FB
1027 if(mCurrentFrame.fbCount)
1028 availPipes -= 1;
1029
1030 if(numPipesNeeded > availPipes) {
1031 ALOGD_IF(isDebug(), "%s: Insufficient pipes for "
1032 "dpy %d mixer %d needed %d, avail %d",
1033 __FUNCTION__, mDpy, i, numPipesNeeded, availPipes);
1034 return false;
1035 }
1036 }
1037 return true;
1038}
1039
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001040bool MDPCompHighRes::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001041 MdpPipeInfoHighRes& pipe_info,
1042 ePipeType type) {
1043 const int xres = ctx->dpyAttr[mDpy].xres;
1044 //Default even split for all displays with high res
1045 int lSplit = xres / 2;
1046 if(mDpy == HWC_DISPLAY_PRIMARY &&
1047 qdutils::MDPVersion::getInstance().getLeftSplit()) {
1048 //Override if split published by driver for primary
1049 lSplit = qdutils::MDPVersion::getInstance().getLeftSplit();
1050 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001051
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001052 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001053 pipe_info.lIndex = ovutils::OV_INVALID;
1054 pipe_info.rIndex = ovutils::OV_INVALID;
1055
1056 if (dst.left < lSplit) {
1057 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_LEFT);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001058 if(pipe_info.lIndex == ovutils::OV_INVALID)
1059 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001060 }
1061
1062 if(dst.right > lSplit) {
1063 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_RIGHT);
1064 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001065 return false;
1066 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001067
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001068 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001069}
1070
1071bool MDPCompHighRes::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001072 hwc_display_contents_1_t* list) {
1073 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001074
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001075 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001076
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001077 hwc_layer_1_t* layer = &list->hwLayers[index];
1078 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001079 int mdpIndex = mCurrentFrame.layerToMDP[index];
1080 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001081 info.pipeInfo = new MdpPipeInfoHighRes;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001082 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001083 MdpPipeInfoHighRes& pipe_info = *(MdpPipeInfoHighRes*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001084 ePipeType type = MDPCOMP_OV_ANY;
1085
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001086 if(isYuvBuffer(hnd)) {
1087 type = MDPCOMP_OV_VG;
Saurabh Shah8a117932013-05-23 12:48:13 -07001088 } else if(!qhwc::needsScaling(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001089 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001090 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001091 type = MDPCOMP_OV_DMA;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001092 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001093
1094 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001095 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type = %d",
1096 __FUNCTION__, (int) type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001097 return false;
1098 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001099 }
1100 return true;
1101}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001102
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001103/*
1104 * Configures pipe(s) for MDP composition
1105 */
1106int MDPCompHighRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001107 PipeLayerPair& PipeLayerPair) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001108 MdpPipeInfoHighRes& mdp_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001109 *(static_cast<MdpPipeInfoHighRes*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001110 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1111 eIsFg isFg = IS_FG_OFF;
1112 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1113 eDest lDest = mdp_info.lIndex;
1114 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001115
1116 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1117 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1118
1119 return configureHighRes(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
1120 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001121}
1122
1123bool MDPCompHighRes::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
1124
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001125 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001126 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1127 return true;
1128 }
1129
1130 if(!ctx || !list) {
1131 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001132 return false;
1133 }
1134
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301135 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1136 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1137 return true;
1138 }
1139
Prabhanjan Kandula088bd892013-07-02 23:47:13 +05301140 Locker::Autolock _l(mMdpCompLock);
1141
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001142 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001143 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001144 idleInvalidator->markForSleep();
1145
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001146 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001147 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001148
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001149 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1150 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001151 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001152 if(mCurrentFrame.isFBComposed[i]) continue;
1153
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001154 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001155 private_handle_t *hnd = (private_handle_t *)layer->handle;
1156 if(!hnd) {
1157 ALOGE("%s handle null", __FUNCTION__);
1158 return false;
1159 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001160
1161 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1162 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001163 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001164
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001165 int mdpIndex = mCurrentFrame.layerToMDP[i];
1166
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001167 MdpPipeInfoHighRes& pipe_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001168 *(MdpPipeInfoHighRes*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1169 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -08001170
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001171 ovutils::eDest indexL = pipe_info.lIndex;
1172 ovutils::eDest indexR = pipe_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001173
Saurabh Shahacf10202013-02-26 10:15:15 -08001174 int fd = hnd->fd;
1175 int offset = hnd->offset;
1176
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001177 if(ctx->mAD->isModeOn()) {
1178 if(ctx->mAD->draw(ctx, fd, offset)) {
1179 fd = ctx->mAD->getDstFd(ctx);
1180 offset = ctx->mAD->getDstOffset(ctx);
1181 }
1182 }
1183
Saurabh Shahacf10202013-02-26 10:15:15 -08001184 if(rot) {
1185 rot->queueBuffer(fd, offset);
1186 fd = rot->getDstMemId();
1187 offset = rot->getDstOffset();
1188 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001189
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001190 //************* play left mixer **********
1191 if(indexL != ovutils::OV_INVALID) {
1192 ovutils::eDest destL = (ovutils::eDest)indexL;
Saurabh Shahacf10202013-02-26 10:15:15 -08001193 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001194 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
Saurabh Shahacf10202013-02-26 10:15:15 -08001195 if (!ov.queueBuffer(fd, offset, destL)) {
1196 ALOGE("%s: queueBuffer failed for left mixer", __FUNCTION__);
1197 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001198 }
1199 }
1200
1201 //************* play right mixer **********
1202 if(indexR != ovutils::OV_INVALID) {
1203 ovutils::eDest destR = (ovutils::eDest)indexR;
Saurabh Shahacf10202013-02-26 10:15:15 -08001204 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001205 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
Saurabh Shahacf10202013-02-26 10:15:15 -08001206 if (!ov.queueBuffer(fd, offset, destR)) {
1207 ALOGE("%s: queueBuffer failed for right mixer", __FUNCTION__);
1208 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001209 }
1210 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001211
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001212 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1213 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001214
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001215 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001216}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001217}; //namespace
1218