blob: 0f34cd462cdc253ed839d6007393938802c730d1 [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
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800341ovutils::eDest MDPComp::getMdpPipe(hwc_context_t *ctx, ePipeType type) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800342 overlay::Overlay& ov = *ctx->mOverlay;
343 ovutils::eDest mdp_pipe = ovutils::OV_INVALID;
344
345 switch(type) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800346 case MDPCOMP_OV_DMA:
347 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_DMA, mDpy);
348 if(mdp_pipe != ovutils::OV_INVALID) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800349 return mdp_pipe;
350 }
351 case MDPCOMP_OV_ANY:
352 case MDPCOMP_OV_RGB:
353 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy);
354 if(mdp_pipe != ovutils::OV_INVALID) {
355 return mdp_pipe;
356 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800357
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800358 if(type == MDPCOMP_OV_RGB) {
359 //Requested only for RGB pipe
360 break;
361 }
362 case MDPCOMP_OV_VG:
363 return ov.nextPipe(ovutils::OV_MDP_PIPE_VG, mDpy);
364 default:
365 ALOGE("%s: Invalid pipe type",__FUNCTION__);
366 return ovutils::OV_INVALID;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800367 };
368 return ovutils::OV_INVALID;
369}
370
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800371bool MDPComp::isFrameDoable(hwc_context_t *ctx) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700372 bool ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700373 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800374
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800375 if(!isEnabled()) {
376 ALOGD_IF(isDebug(),"%s: MDP Comp. not enabled.", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700377 ret = false;
Saurabh Shahd4e65852013-06-17 11:33:53 -0700378 } else if(qdutils::MDPVersion::getInstance().is8x26() &&
379 ctx->mVideoTransFlag &&
380 ctx->mExtDisplay->isExternalConnected()) {
381 //1 Padding round to shift pipes across mixers
382 ALOGD_IF(isDebug(),"%s: MDP Comp. video transition padding round",
383 __FUNCTION__);
384 ret = false;
Saurabh Shahaa236822013-04-24 18:07:26 -0700385 } else if(ctx->mExtDispConfiguring) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800386 ALOGD_IF( isDebug(),"%s: External Display connection is pending",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800387 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700388 ret = false;
Saurabh Shahaa236822013-04-24 18:07:26 -0700389 } else if(ctx->isPaddingRound) {
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700390 ctx->isPaddingRound = false;
391 ALOGD_IF(isDebug(), "%s: padding round",__FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700392 ret = false;
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700393 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700394 return ret;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800395}
396
397/* Checks for conditions where all the layers marked for MDP comp cannot be
398 * bypassed. On such conditions we try to bypass atleast YUV layers */
399bool MDPComp::isFullFrameDoable(hwc_context_t *ctx,
400 hwc_display_contents_1_t* list){
401
Saurabh Shahaa236822013-04-24 18:07:26 -0700402 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800403
Saurabh Shah2d998a92013-05-14 17:55:58 -0700404 if(sIdleFallBack) {
405 ALOGD_IF(isDebug(), "%s: Idle fallback dpy %d",__FUNCTION__, mDpy);
406 return false;
407 }
408
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800409 if(mDpy > HWC_DISPLAY_PRIMARY){
410 ALOGD_IF(isDebug(), "%s: Cannot support External display(s)",
411 __FUNCTION__);
412 return false;
413 }
414
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800415 if(isSkipPresent(ctx, mDpy)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700416 ALOGD_IF(isDebug(),"%s: SKIP present: %d",
417 __FUNCTION__,
418 isSkipPresent(ctx, mDpy));
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800419 return false;
420 }
421
Saurabh Shah9f084ad2013-05-02 11:28:09 -0700422 if(ctx->listStats[mDpy].needsAlphaScale
423 && ctx->mMDP.version < qdutils::MDSS_V5) {
424 ALOGD_IF(isDebug(), "%s: frame needs alpha downscaling",__FUNCTION__);
425 return false;
426 }
427
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800428 //MDP composition is not efficient if layer needs rotator.
429 for(int i = 0; i < numAppLayers; ++i) {
430 // As MDP h/w supports flip operation, use MDP comp only for
431 // 180 transforms. Fail for any transform involving 90 (90, 270).
432 hwc_layer_1_t* layer = &list->hwLayers[i];
433 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800434
Saurabh Shah4fdde762013-04-30 18:47:33 -0700435 if((layer->transform & HWC_TRANSFORM_ROT_90) && !isYuvBuffer(hnd)) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800436 ALOGD_IF(isDebug(), "%s: orientation involved",__FUNCTION__);
437 return false;
438 }
439
Saurabh Shah4fdde762013-04-30 18:47:33 -0700440 if(!isValidDimension(ctx,layer)) {
441 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
442 __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800443 return false;
444 }
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530445
446 //For 8x26 with panel width>1k, if RGB layer needs HFLIP fail mdp comp
447 // may not need it if Gfx pre-rotation can handle all flips & rotations
448 if(qdutils::MDPVersion::getInstance().is8x26() &&
449 (ctx->dpyAttr[mDpy].xres > 1024) &&
450 (layer->transform & HWC_TRANSFORM_FLIP_H) &&
451 (!isYuvBuffer(hnd)))
452 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800453 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700454
455 //If all above hard conditions are met we can do full or partial MDP comp.
456 bool ret = false;
457 if(fullMDPComp(ctx, list)) {
458 ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700459 } else if(partialMDPComp(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700460 ret = true;
461 }
462 return ret;
463}
464
465bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
466 //Setup mCurrentFrame
467 mCurrentFrame.mdpCount = mCurrentFrame.layerCount;
468 mCurrentFrame.fbCount = 0;
469 mCurrentFrame.fbZ = -1;
470 memset(&mCurrentFrame.isFBComposed, 0, sizeof(mCurrentFrame.isFBComposed));
471
472 int mdpCount = mCurrentFrame.mdpCount;
473 if(mdpCount > sMaxPipesPerMixer) {
474 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
475 return false;
476 }
477
478 int numPipesNeeded = pipesNeeded(ctx, list);
479 int availPipes = getAvailablePipes(ctx);
480
481 if(numPipesNeeded > availPipes) {
482 ALOGD_IF(isDebug(), "%s: Insufficient MDP pipes, needed %d, avail %d",
483 __FUNCTION__, numPipesNeeded, availPipes);
484 return false;
485 }
486
487 return true;
488}
489
490bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
491{
492 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700493
494 if(!sEnableMixedMode) {
495 //Mixed mode is disabled. No need to even try caching.
496 return false;
497 }
498
Saurabh Shahaa236822013-04-24 18:07:26 -0700499 //Setup mCurrentFrame
500 mCurrentFrame.reset(numAppLayers);
501 updateLayerCache(ctx, list);
502 updateYUV(ctx, list);
503 batchLayers(); //sets up fbZ also
504
505 int mdpCount = mCurrentFrame.mdpCount;
506 if(mdpCount > (sMaxPipesPerMixer - 1)) { // -1 since FB is used
507 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
508 return false;
509 }
510
511 int numPipesNeeded = pipesNeeded(ctx, list);
512 int availPipes = getAvailablePipes(ctx);
513
514 if(numPipesNeeded > availPipes) {
515 ALOGD_IF(isDebug(), "%s: Insufficient MDP pipes, needed %d, avail %d",
516 __FUNCTION__, numPipesNeeded, availPipes);
517 return false;
518 }
519
520 return true;
521}
522
523bool MDPComp::isOnlyVideoDoable(hwc_context_t *ctx,
524 hwc_display_contents_1_t* list){
525 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
526 mCurrentFrame.reset(numAppLayers);
527 updateYUV(ctx, list);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700528 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700529 int fbNeeded = int(mCurrentFrame.fbCount != 0);
530
531 if(!isYuvPresent(ctx, mDpy)) {
532 return false;
533 }
534
Saurabh Shah4fdde762013-04-30 18:47:33 -0700535 if(!mdpCount)
536 return false;
537
Saurabh Shahaa236822013-04-24 18:07:26 -0700538 if(mdpCount > (sMaxPipesPerMixer - fbNeeded)) {
539 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
540 return false;
541 }
542
543 int numPipesNeeded = pipesNeeded(ctx, list);
544 int availPipes = getAvailablePipes(ctx);
545 if(numPipesNeeded > availPipes) {
546 ALOGD_IF(isDebug(), "%s: Insufficient MDP pipes, needed %d, avail %d",
547 __FUNCTION__, numPipesNeeded, availPipes);
548 return false;
549 }
550
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800551 return true;
552}
553
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800554/* Checks for conditions where YUV layers cannot be bypassed */
555bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Saurabh Shahe2474082013-05-15 16:32:13 -0700556 bool extAnimBlockFeature = mDpy && ctx->listStats[mDpy].isDisplayAnimating;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800557
Saurabh Shahe2474082013-05-15 16:32:13 -0700558 if(isSkipLayer(layer) && !extAnimBlockFeature) {
559 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800560 return false;
561 }
562
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800563 if(isSecuring(ctx, layer)) {
564 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
565 return false;
566 }
567
Saurabh Shah4fdde762013-04-30 18:47:33 -0700568 if(!isValidDimension(ctx, layer)) {
569 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
570 __FUNCTION__);
571 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800572 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700573
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800574 return true;
575}
576
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800577void MDPComp::batchLayers() {
578 /* Idea is to keep as many contiguous non-updating(cached) layers in FB and
579 * send rest of them through MDP. NEVER mark an updating layer for caching.
580 * But cached ones can be marked for MDP*/
581
582 int maxBatchStart = -1;
583 int maxBatchCount = 0;
584
585 /* All or Nothing is cached. No batching needed */
Saurabh Shahaa236822013-04-24 18:07:26 -0700586 if(!mCurrentFrame.fbCount) {
587 mCurrentFrame.fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800588 return;
Saurabh Shahaa236822013-04-24 18:07:26 -0700589 }
590 if(!mCurrentFrame.mdpCount) {
591 mCurrentFrame.fbZ = 0;
592 return;
593 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800594
595 /* Search for max number of contiguous (cached) layers */
596 int i = 0;
597 while (i < mCurrentFrame.layerCount) {
598 int count = 0;
599 while(mCurrentFrame.isFBComposed[i] && i < mCurrentFrame.layerCount) {
600 count++; i++;
601 }
602 if(count > maxBatchCount) {
603 maxBatchCount = count;
604 maxBatchStart = i - count;
Saurabh Shahaa236822013-04-24 18:07:26 -0700605 mCurrentFrame.fbZ = maxBatchStart;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800606 }
607 if(i < mCurrentFrame.layerCount) i++;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800608 }
609
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800610 /* reset rest of the layers for MDP comp */
611 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
612 if(i != maxBatchStart){
613 mCurrentFrame.isFBComposed[i] = false;
614 } else {
615 i += maxBatchCount;
616 }
617 }
618
619 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700620 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
621 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800622
623 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
624 mCurrentFrame.fbCount);
625}
Saurabh Shah85234ec2013-04-12 17:09:00 -0700626
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800627void MDPComp::updateLayerCache(hwc_context_t* ctx,
628 hwc_display_contents_1_t* list) {
629
630 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
631 int numCacheableLayers = 0;
632
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800633 for(int i = 0; i < numAppLayers; i++) {
634 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
635 numCacheableLayers++;
636 mCurrentFrame.isFBComposed[i] = true;
637 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -0700638 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800639 mCachedFrame.hnd[i] = list->hwLayers[i].handle;
640 }
641 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700642
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800643 mCurrentFrame.fbCount = numCacheableLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700644 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
645 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800646 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__, numCacheableLayers);
647}
648
649int MDPComp::getAvailablePipes(hwc_context_t* ctx) {
650 int numDMAPipes = qdutils::MDPVersion::getInstance().getDMAPipes();
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800651 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800652
653 int numAvailable = ov.availablePipes(mDpy);
654
655 //Reserve DMA for rotator
Saurabh Shah85234ec2013-04-12 17:09:00 -0700656 if(Overlay::getDMAMode() == Overlay::DMA_BLOCK_MODE)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800657 numAvailable -= numDMAPipes;
658
659 //Reserve pipe(s)for FB
660 if(mCurrentFrame.fbCount)
661 numAvailable -= pipesForFB();
662
663 return numAvailable;
664}
665
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800666void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list) {
667
668 int nYuvCount = ctx->listStats[mDpy].yuvCount;
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700669 if(!nYuvCount && mDpy) {
670 //Reset "No animation on external display" related parameters.
671 ctx->mPrevCropVideo.left = ctx->mPrevCropVideo.top =
672 ctx->mPrevCropVideo.right = ctx->mPrevCropVideo.bottom = 0;
673 ctx->mPrevDestVideo.left = ctx->mPrevDestVideo.top =
674 ctx->mPrevDestVideo.right = ctx->mPrevDestVideo.bottom = 0;
675 ctx->mPrevTransformVideo = 0;
676 return;
677 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800678 for(int index = 0;index < nYuvCount; index++){
679 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
680 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
681
682 if(!isYUVDoable(ctx, layer)) {
683 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
684 mCurrentFrame.isFBComposed[nYuvIndex] = true;
685 mCurrentFrame.fbCount++;
686 }
687 } else {
688 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
689 mCurrentFrame.isFBComposed[nYuvIndex] = false;
690 mCurrentFrame.fbCount--;
691 }
692 }
693 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700694
695 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
696 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800697 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
698 mCurrentFrame.fbCount);
699}
700
Saurabh Shahaa236822013-04-24 18:07:26 -0700701bool MDPComp::programMDP(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800702 if(!allocLayerPipes(ctx, list)) {
703 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700704 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800705 }
706
Saurabh Shahaa236822013-04-24 18:07:26 -0700707 bool fbBatch = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800708 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700709 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800710 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800711 int mdpIndex = mCurrentFrame.layerToMDP[index];
712 hwc_layer_1_t* layer = &list->hwLayers[index];
713
714 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
715 cur_pipe->zOrder = mdpNextZOrder++;
716
717 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
718 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
719 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -0700720 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800721 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700722 } else if(fbBatch == false) {
723 mdpNextZOrder++;
724 fbBatch = true;
725 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800726 }
727
Saurabh Shahaa236822013-04-24 18:07:26 -0700728 return true;
729}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800730
Saurabh Shahaa236822013-04-24 18:07:26 -0700731bool MDPComp::programYUV(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
732 if(!allocLayerPipes(ctx, list)) {
733 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
734 return false;
735 }
736 //If we are in this block, it means we have yuv + rgb layers both
737 int mdpIdx = 0;
738 for (int index = 0; index < mCurrentFrame.layerCount; index++) {
739 if(!mCurrentFrame.isFBComposed[index]) {
740 hwc_layer_1_t* layer = &list->hwLayers[index];
741 int mdpIndex = mCurrentFrame.layerToMDP[index];
742 MdpPipeInfo* cur_pipe =
743 mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
744 cur_pipe->zOrder = mdpIdx++;
745
746 if(configure(ctx, layer,
747 mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
748 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
749 layer %d",__FUNCTION__, index);
750 return false;
751 }
752 }
753 }
754 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800755}
756
757int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700758 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -0700759
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530760 { //LOCK SCOPE BEGIN
761 Locker::Autolock _l(mMdpCompLock);
Prabhanjan Kandula088bd892013-07-02 23:47:13 +0530762
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530763 //reset old data
Saurabh Shahaa236822013-04-24 18:07:26 -0700764 mCurrentFrame.reset(numLayers);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800765
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530766 //number of app layers exceeds MAX_NUM_APP_LAYERS fall back to GPU
767 //do not cache the information for next draw cycle.
768 if(numLayers > MAX_NUM_APP_LAYERS) {
769 mCachedFrame.updateCounts(mCurrentFrame);
770 ALOGD_IF(isDebug(), "%s: Number of App layers exceeded the limit ",
771 __FUNCTION__);
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700772 return -1;
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530773 }
774
775 //Hard conditions, if not met, cannot do MDP comp
776 if(!isFrameDoable(ctx)) {
777 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
778 __FUNCTION__);
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700779 reset(numLayers, list);
780 return -1;
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530781 }
782
783 //Check whether layers marked for MDP Composition is actually doable.
784 if(isFullFrameDoable(ctx, list)){
785 mCurrentFrame.map();
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700786 //Configure framebuffer first if applicable
787 if(mCurrentFrame.fbZ >= 0) {
788 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list,
789 mCurrentFrame.fbZ)) {
790 ALOGE("%s configure framebuffer failed", __func__);
791 reset(numLayers, list);
792 return -1;
793 }
794 }
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530795 //Acquire and Program MDP pipes
796 if(!programMDP(ctx, list)) {
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700797 reset(numLayers, list);
798 return -1;
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530799 } else { //Success
800 //Any change in composition types needs an FB refresh
801 mCurrentFrame.needsRedraw = false;
802 if(mCurrentFrame.fbCount &&
803 ((mCurrentFrame.mdpCount != mCachedFrame.mdpCount) ||
804 (mCurrentFrame.fbCount != mCachedFrame.cacheCount) ||
805 (mCurrentFrame.fbZ != mCachedFrame.fbZ) ||
806 (!mCurrentFrame.mdpCount) ||
807 (list->flags & HWC_GEOMETRY_CHANGED) ||
808 isSkipPresent(ctx, mDpy) ||
809 (mDpy > HWC_DISPLAY_PRIMARY))) {
810 mCurrentFrame.needsRedraw = true;
811 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700812 }
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530813 } else if(isOnlyVideoDoable(ctx, list)) {
814 //All layers marked for MDP comp cannot be bypassed.
815 //Try to compose atleast YUV layers through MDP comp and let
816 //all the RGB layers compose in FB
817 //Destination over
818 mCurrentFrame.fbZ = -1;
819 if(mCurrentFrame.fbCount)
820 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800821
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530822 mCurrentFrame.map();
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700823
824 //Configure framebuffer first if applicable
825 if(mCurrentFrame.fbZ >= 0) {
826 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, mCurrentFrame.fbZ)) {
827 ALOGE("%s configure framebuffer failed", __func__);
828 reset(numLayers, list);
829 return -1;
830 }
831 }
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530832 if(!programYUV(ctx, list)) {
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700833 reset(numLayers, list);
834 return -1;
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530835 }
836 } else {
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700837 reset(numLayers, list);
838 return -1;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800839 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800840
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530841 //UpdateLayerFlags
842 setMDPCompLayerFlags(ctx, list);
843 mCachedFrame.updateCounts(mCurrentFrame);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800844
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530845 } //LOCK SCOPE END. dump also need this lock.
846 // unlock it before calling dump function to avoid deadlock
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800847 if(isDebug()) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700848 ALOGD("GEOMETRY change: %d", (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800849 android::String8 sDump("");
850 dump(sDump);
851 ALOGE("%s",sDump.string());
852 }
853
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700854 return 0;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800855}
856
857//=============MDPCompLowRes===================================================
858
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700859/*
860 * Configures pipe(s) for MDP composition
861 */
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800862int MDPCompLowRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800863 PipeLayerPair& PipeLayerPair) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800864 MdpPipeInfoLowRes& mdp_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800865 *(static_cast<MdpPipeInfoLowRes*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -0800866 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
867 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
868 eIsFg isFg = IS_FG_OFF;
869 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700870
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800871 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
872 __FUNCTION__, layer, zOrder, dest);
873
874 return configureLowRes(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
875 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700876}
877
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800878int MDPCompLowRes::pipesNeeded(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800879 hwc_display_contents_1_t* list) {
880 return mCurrentFrame.mdpCount;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700881}
882
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800883bool MDPCompLowRes::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700884 hwc_display_contents_1_t* list) {
885 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700886
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800887 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700888
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800889 hwc_layer_1_t* layer = &list->hwLayers[index];
890 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800891 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800892 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800893 info.pipeInfo = new MdpPipeInfoLowRes;
Saurabh Shahacf10202013-02-26 10:15:15 -0800894 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800895 MdpPipeInfoLowRes& pipe_info = *(MdpPipeInfoLowRes*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800896 ePipeType type = MDPCOMP_OV_ANY;
897
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700898 if(isYuvBuffer(hnd)) {
899 type = MDPCOMP_OV_VG;
Saurabh Shah8a117932013-05-23 12:48:13 -0700900 } else if(!qhwc::needsScaling(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -0700901 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
902 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800903 type = MDPCOMP_OV_DMA;
904 }
905
906 pipe_info.index = getMdpPipe(ctx, type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800907 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700908 ALOGD_IF(isDebug(), "%s: Unable to get pipe type = %d",
909 __FUNCTION__, (int) type);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500910 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700911 }
912 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700913 return true;
914}
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700915
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800916bool MDPCompLowRes::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700917
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800918 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500919 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
920 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800921 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700922
923 if(!ctx || !list) {
924 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500925 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700926 }
927
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +0530928 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
929 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
930 return true;
931 }
932
Prabhanjan Kandula088bd892013-07-02 23:47:13 +0530933 Locker::Autolock _l(mMdpCompLock);
934
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500935 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -0700936 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500937 idleInvalidator->markForSleep();
938
939 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800940 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700941
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800942 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
943 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700944 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800945 if(mCurrentFrame.isFBComposed[i]) continue;
946
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700947 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -0800948 private_handle_t *hnd = (private_handle_t *)layer->handle;
949 if(!hnd) {
950 ALOGE("%s handle null", __FUNCTION__);
951 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700952 }
953
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800954 int mdpIndex = mCurrentFrame.layerToMDP[i];
955
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800956 MdpPipeInfoLowRes& pipe_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800957 *(MdpPipeInfoLowRes*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800958 ovutils::eDest dest = pipe_info.index;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800959 if(dest == ovutils::OV_INVALID) {
960 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500961 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700962 }
963
Saurabh Shahacf10202013-02-26 10:15:15 -0800964 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
965 continue;
966 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700967
Saurabh Shahacf10202013-02-26 10:15:15 -0800968 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800969 using pipe: %d", __FUNCTION__, layer,
970 hnd, dest );
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700971
Saurabh Shahacf10202013-02-26 10:15:15 -0800972 int fd = hnd->fd;
973 uint32_t offset = hnd->offset;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800974 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -0800975 if(rot) {
976 if(!rot->queueBuffer(fd, offset))
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500977 return false;
Saurabh Shahacf10202013-02-26 10:15:15 -0800978 fd = rot->getDstMemId();
979 offset = rot->getDstOffset();
980 }
981
982 if (!ov.queueBuffer(fd, offset, dest)) {
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +0530983 ALOGE("%s: queueBuffer failed for display:%d ", __FUNCTION__, mDpy);
Saurabh Shahacf10202013-02-26 10:15:15 -0800984 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700985 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500986
987 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700988 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500989 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700990}
991
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800992//=============MDPCompHighRes===================================================
993
994int MDPCompHighRes::pipesNeeded(hwc_context_t *ctx,
Saurabh Shah67a38c32013-06-10 16:23:15 -0700995 hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800996 int pipesNeeded = 0;
Saurabh Shah67a38c32013-06-10 16:23:15 -0700997 const int xres = ctx->dpyAttr[mDpy].xres;
998 //Default even split for all displays with high res
999 int lSplit = xres / 2;
1000 if(mDpy == HWC_DISPLAY_PRIMARY &&
1001 qdutils::MDPVersion::getInstance().getLeftSplit()) {
1002 //Override if split published by driver for primary
1003 lSplit = qdutils::MDPVersion::getInstance().getLeftSplit();
1004 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001005
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001006 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1007 if(!mCurrentFrame.isFBComposed[i]) {
1008 hwc_layer_1_t* layer = &list->hwLayers[i];
1009 hwc_rect_t dst = layer->displayFrame;
Saurabh Shah67a38c32013-06-10 16:23:15 -07001010 if(dst.left > lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001011 pipesNeeded++;
Saurabh Shah67a38c32013-06-10 16:23:15 -07001012 } else if(dst.right <= lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001013 pipesNeeded++;
1014 } else {
1015 pipesNeeded += 2;
1016 }
1017 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001018 }
1019 return pipesNeeded;
1020}
1021
1022bool MDPCompHighRes::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001023 MdpPipeInfoHighRes& pipe_info,
1024 ePipeType type) {
1025 const int xres = ctx->dpyAttr[mDpy].xres;
1026 //Default even split for all displays with high res
1027 int lSplit = xres / 2;
1028 if(mDpy == HWC_DISPLAY_PRIMARY &&
1029 qdutils::MDPVersion::getInstance().getLeftSplit()) {
1030 //Override if split published by driver for primary
1031 lSplit = qdutils::MDPVersion::getInstance().getLeftSplit();
1032 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001033
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001034 hwc_rect_t dst = layer->displayFrame;
Saurabh Shah67a38c32013-06-10 16:23:15 -07001035 if(dst.left > lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001036 pipe_info.lIndex = ovutils::OV_INVALID;
1037 pipe_info.rIndex = getMdpPipe(ctx, type);
1038 if(pipe_info.rIndex == ovutils::OV_INVALID)
1039 return false;
Saurabh Shah67a38c32013-06-10 16:23:15 -07001040 } else if (dst.right <= lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001041 pipe_info.rIndex = ovutils::OV_INVALID;
1042 pipe_info.lIndex = getMdpPipe(ctx, type);
1043 if(pipe_info.lIndex == ovutils::OV_INVALID)
1044 return false;
1045 } else {
1046 pipe_info.rIndex = getMdpPipe(ctx, type);
1047 pipe_info.lIndex = getMdpPipe(ctx, type);
1048 if(pipe_info.rIndex == ovutils::OV_INVALID ||
1049 pipe_info.lIndex == ovutils::OV_INVALID)
1050 return false;
1051 }
1052 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001053}
1054
1055bool MDPCompHighRes::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001056 hwc_display_contents_1_t* list) {
1057 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001058
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001059 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001060
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001061 hwc_layer_1_t* layer = &list->hwLayers[index];
1062 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001063 int mdpIndex = mCurrentFrame.layerToMDP[index];
1064 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001065 info.pipeInfo = new MdpPipeInfoHighRes;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001066 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001067 MdpPipeInfoHighRes& pipe_info = *(MdpPipeInfoHighRes*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001068 ePipeType type = MDPCOMP_OV_ANY;
1069
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001070 if(isYuvBuffer(hnd)) {
1071 type = MDPCOMP_OV_VG;
Saurabh Shah8a117932013-05-23 12:48:13 -07001072 } else if(!qhwc::needsScaling(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001073 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001074 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001075 type = MDPCOMP_OV_DMA;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001076 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001077
1078 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001079 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type = %d",
1080 __FUNCTION__, (int) type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001081 return false;
1082 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001083 }
1084 return true;
1085}
1086/*
1087 * Configures pipe(s) for MDP composition
1088 */
1089int MDPCompHighRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001090 PipeLayerPair& PipeLayerPair) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001091 MdpPipeInfoHighRes& mdp_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001092 *(static_cast<MdpPipeInfoHighRes*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001093 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1094 eIsFg isFg = IS_FG_OFF;
1095 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1096 eDest lDest = mdp_info.lIndex;
1097 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001098
1099 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1100 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1101
1102 return configureHighRes(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
1103 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001104}
1105
1106bool MDPCompHighRes::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
1107
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001108 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001109 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1110 return true;
1111 }
1112
1113 if(!ctx || !list) {
1114 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001115 return false;
1116 }
1117
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301118 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1119 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1120 return true;
1121 }
1122
Prabhanjan Kandula088bd892013-07-02 23:47:13 +05301123 Locker::Autolock _l(mMdpCompLock);
1124
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001125 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001126 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001127 idleInvalidator->markForSleep();
1128
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001129 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001130 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001131
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001132 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1133 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001134 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001135 if(mCurrentFrame.isFBComposed[i]) continue;
1136
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001137 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001138 private_handle_t *hnd = (private_handle_t *)layer->handle;
1139 if(!hnd) {
1140 ALOGE("%s handle null", __FUNCTION__);
1141 return false;
1142 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001143
1144 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1145 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001146 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001147
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001148 int mdpIndex = mCurrentFrame.layerToMDP[i];
1149
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001150 MdpPipeInfoHighRes& pipe_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001151 *(MdpPipeInfoHighRes*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1152 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -08001153
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001154 ovutils::eDest indexL = pipe_info.lIndex;
1155 ovutils::eDest indexR = pipe_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001156
Saurabh Shahacf10202013-02-26 10:15:15 -08001157 int fd = hnd->fd;
1158 int offset = hnd->offset;
1159
1160 if(rot) {
1161 rot->queueBuffer(fd, offset);
1162 fd = rot->getDstMemId();
1163 offset = rot->getDstOffset();
1164 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001165
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001166 //************* play left mixer **********
1167 if(indexL != ovutils::OV_INVALID) {
1168 ovutils::eDest destL = (ovutils::eDest)indexL;
Saurabh Shahacf10202013-02-26 10:15:15 -08001169 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001170 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
Saurabh Shahacf10202013-02-26 10:15:15 -08001171 if (!ov.queueBuffer(fd, offset, destL)) {
1172 ALOGE("%s: queueBuffer failed for left mixer", __FUNCTION__);
1173 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001174 }
1175 }
1176
1177 //************* play right mixer **********
1178 if(indexR != ovutils::OV_INVALID) {
1179 ovutils::eDest destR = (ovutils::eDest)indexR;
Saurabh Shahacf10202013-02-26 10:15:15 -08001180 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001181 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
Saurabh Shahacf10202013-02-26 10:15:15 -08001182 if (!ov.queueBuffer(fd, offset, destR)) {
1183 ALOGE("%s: queueBuffer failed for right mixer", __FUNCTION__);
1184 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001185 }
1186 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001187
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001188 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1189 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001190
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001191 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001192}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001193}; //namespace
1194