blob: 1158a162196aa4cd1dd569208babc9f262efd436 [file] [log] [blame]
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001/*
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002 * Copyright (C) 2012-2013, The Linux Foundation. All rights reserved.
Naseer Ahmed7c958d42012-07-31 18:57:03 -07003 * Not a Contribution, Apache license notifications and license are retained
4 * for attribution purposes only.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
Saurabh Shah4fdde762013-04-30 18:47:33 -070019#include <math.h>
Naseer Ahmed7c958d42012-07-31 18:57:03 -070020#include "hwc_mdpcomp.h"
Naseer Ahmed54821fe2012-11-28 18:44:38 -050021#include <sys/ioctl.h>
Saurabh Shah56f610d2012-08-07 15:27:06 -070022#include "external.h"
Jeykumar Sankaran27dee262013-08-01 17:09:54 -070023#include "virtual.h"
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -080024#include "qdMetaData.h"
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -080025#include "mdp_version.h"
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -070026#include "hwc_fbupdate.h"
Saurabh Shaha9da08f2013-07-03 13:27:53 -070027#include "hwc_ad.h"
Saurabh Shahacf10202013-02-26 10:15:15 -080028#include <overlayRotator.h>
29
Saurabh Shah85234ec2013-04-12 17:09:00 -070030using namespace overlay;
Saurabh Shahbd2d0832013-04-04 14:33:08 -070031using namespace qdutils;
Saurabh Shahacf10202013-02-26 10:15:15 -080032using namespace overlay::utils;
33namespace ovutils = overlay::utils;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070034
Naseer Ahmed7c958d42012-07-31 18:57:03 -070035namespace qhwc {
36
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080037//==============MDPComp========================================================
38
Naseer Ahmed7c958d42012-07-31 18:57:03 -070039IdleInvalidator *MDPComp::idleInvalidator = NULL;
40bool MDPComp::sIdleFallBack = false;
41bool MDPComp::sDebugLogs = false;
Naseer Ahmed54821fe2012-11-28 18:44:38 -050042bool MDPComp::sEnabled = false;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -070043bool MDPComp::sEnableMixedMode = true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080044int MDPComp::sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070045
Saurabh Shah67a38c32013-06-10 16:23:15 -070046MDPComp* MDPComp::getObject(const int& width, const int& rightSplit,
47 const int& dpy) {
48 if(width > MAX_DISPLAY_DIM || rightSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080049 return new MDPCompHighRes(dpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080050 }
Saurabh Shah67a38c32013-06-10 16:23:15 -070051 return new MDPCompLowRes(dpy);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080052}
53
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080054MDPComp::MDPComp(int dpy):mDpy(dpy){};
55
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080056void MDPComp::dump(android::String8& buf)
57{
Jeykumar Sankaran3c6bb042013-08-15 14:01:04 -070058 if(mCurrentFrame.layerCount > MAX_NUM_APP_LAYERS)
59 return;
60
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080061 dumpsys_log(buf,"HWC Map for Dpy: %s \n",
Jeykumar Sankaran27dee262013-08-01 17:09:54 -070062 (mDpy == 0) ? "\"PRIMARY\"" :
63 (mDpy == 1) ? "\"EXTERNAL\"" : "\"VIRTUAL\"");
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080064 dumpsys_log(buf,"PREV_FRAME: layerCount:%2d mdpCount:%2d \
65 cacheCount:%2d \n", mCachedFrame.layerCount,
66 mCachedFrame.mdpCount, mCachedFrame.cacheCount);
67 dumpsys_log(buf,"CURR_FRAME: layerCount:%2d mdpCount:%2d \
68 fbCount:%2d \n", mCurrentFrame.layerCount,
69 mCurrentFrame.mdpCount, mCurrentFrame.fbCount);
70 dumpsys_log(buf,"needsFBRedraw:%3s pipesUsed:%2d MaxPipesPerMixer: %d \n",
71 (mCurrentFrame.needsRedraw? "YES" : "NO"),
72 mCurrentFrame.mdpCount, sMaxPipesPerMixer);
73 dumpsys_log(buf," --------------------------------------------- \n");
74 dumpsys_log(buf," listIdx | cached? | mdpIndex | comptype | Z \n");
75 dumpsys_log(buf," --------------------------------------------- \n");
76 for(int index = 0; index < mCurrentFrame.layerCount; index++ )
77 dumpsys_log(buf," %7d | %7s | %8d | %9s | %2d \n",
78 index,
79 (mCurrentFrame.isFBComposed[index] ? "YES" : "NO"),
80 mCurrentFrame.layerToMDP[index],
81 (mCurrentFrame.isFBComposed[index] ?
82 (mCurrentFrame.needsRedraw ? "GLES" : "CACHE") : "MDP"),
83 (mCurrentFrame.isFBComposed[index] ? mCurrentFrame.fbZ :
84 mCurrentFrame.mdpToLayer[mCurrentFrame.layerToMDP[index]].pipeInfo->zOrder));
85 dumpsys_log(buf,"\n");
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080086}
87
88bool MDPComp::init(hwc_context_t *ctx) {
89
90 if(!ctx) {
91 ALOGE("%s: Invalid hwc context!!",__FUNCTION__);
92 return false;
93 }
94
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080095 char property[PROPERTY_VALUE_MAX];
96
97 sEnabled = false;
98 if((property_get("persist.hwc.mdpcomp.enable", property, NULL) > 0) &&
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080099 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
100 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800101 sEnabled = true;
Xiaoming Zhou944e02e2013-05-01 20:54:03 -0400102 if(!setupBasePipe(ctx)) {
103 ALOGE("%s: Failed to setup primary base pipe", __FUNCTION__);
104 return false;
105 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800106 }
107
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700108 sEnableMixedMode = true;
109 if((property_get("debug.mdpcomp.mixedmode.disable", property, NULL) > 0) &&
110 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
111 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
112 sEnableMixedMode = false;
113 }
114
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800115 sDebugLogs = false;
116 if(property_get("debug.mdpcomp.logs", property, NULL) > 0) {
117 if(atoi(property) != 0)
118 sDebugLogs = true;
119 }
120
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800121 sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
Saurabh Shah85234ec2013-04-12 17:09:00 -0700122 if(property_get("debug.mdpcomp.maxpermixer", property, "-1") > 0) {
123 int val = atoi(property);
124 if(val >= 0)
125 sMaxPipesPerMixer = min(val, MAX_PIPES_PER_MIXER);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800126 }
127
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400128 if(ctx->mMDP.panel != MIPI_CMD_PANEL) {
129 // Idle invalidation is not necessary on command mode panels
130 long idle_timeout = DEFAULT_IDLE_TIME;
131 if(property_get("debug.mdpcomp.idletime", property, NULL) > 0) {
132 if(atoi(property) != 0)
133 idle_timeout = atoi(property);
134 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800135
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400136 //create Idle Invalidator only when not disabled through property
137 if(idle_timeout != -1)
138 idleInvalidator = IdleInvalidator::getInstance();
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800139
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400140 if(idleInvalidator == NULL) {
141 ALOGE("%s: failed to instantiate idleInvalidator object",
142 __FUNCTION__);
143 } else {
144 idleInvalidator->init(timeout_handler, ctx, idle_timeout);
145 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800146 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700147 return true;
148}
149
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700150void MDPComp::reset(const int& numLayers, hwc_display_contents_1_t* list) {
151 mCurrentFrame.reset(numLayers);
152 mCachedFrame.cacheAll(list);
153 mCachedFrame.updateCounts(mCurrentFrame);
154}
155
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700156void MDPComp::timeout_handler(void *udata) {
157 struct hwc_context_t* ctx = (struct hwc_context_t*)(udata);
158
159 if(!ctx) {
160 ALOGE("%s: received empty data in timer callback", __FUNCTION__);
161 return;
162 }
163
Jesse Hall3be78d92012-08-21 15:12:23 -0700164 if(!ctx->proc) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700165 ALOGE("%s: HWC proc not registered", __FUNCTION__);
166 return;
167 }
168 sIdleFallBack = true;
169 /* Trigger SF to redraw the current frame */
Jesse Hall3be78d92012-08-21 15:12:23 -0700170 ctx->proc->invalidate(ctx->proc);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700171}
172
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800173void MDPComp::setMDPCompLayerFlags(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800174 hwc_display_contents_1_t* list) {
175 LayerProp *layerProp = ctx->layerProp[mDpy];
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800176
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800177 for(int index = 0; index < ctx->listStats[mDpy].numAppLayers; index++) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800178 hwc_layer_1_t* layer = &(list->hwLayers[index]);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800179 if(!mCurrentFrame.isFBComposed[index]) {
180 layerProp[index].mFlags |= HWC_MDPCOMP;
181 layer->compositionType = HWC_OVERLAY;
182 layer->hints |= HWC_HINT_CLEAR_FB;
183 mCachedFrame.hnd[index] = NULL;
184 } else {
185 if(!mCurrentFrame.needsRedraw)
186 layer->compositionType = HWC_OVERLAY;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800187 }
188 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700189}
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500190
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800191/*
192 * Sets up BORDERFILL as default base pipe and detaches RGB0.
193 * Framebuffer is always updated using PLAY ioctl.
194 */
195bool MDPComp::setupBasePipe(hwc_context_t *ctx) {
196 const int dpy = HWC_DISPLAY_PRIMARY;
197 int fb_stride = ctx->dpyAttr[dpy].stride;
198 int fb_width = ctx->dpyAttr[dpy].xres;
199 int fb_height = ctx->dpyAttr[dpy].yres;
200 int fb_fd = ctx->dpyAttr[dpy].fd;
201
202 mdp_overlay ovInfo;
203 msmfb_overlay_data ovData;
204 memset(&ovInfo, 0, sizeof(mdp_overlay));
205 memset(&ovData, 0, sizeof(msmfb_overlay_data));
206
207 ovInfo.src.format = MDP_RGB_BORDERFILL;
208 ovInfo.src.width = fb_width;
209 ovInfo.src.height = fb_height;
210 ovInfo.src_rect.w = fb_width;
211 ovInfo.src_rect.h = fb_height;
212 ovInfo.dst_rect.w = fb_width;
213 ovInfo.dst_rect.h = fb_height;
214 ovInfo.id = MSMFB_NEW_REQUEST;
215
216 if (ioctl(fb_fd, MSMFB_OVERLAY_SET, &ovInfo) < 0) {
217 ALOGE("Failed to call ioctl MSMFB_OVERLAY_SET err=%s",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800218 strerror(errno));
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800219 return false;
220 }
221
222 ovData.id = ovInfo.id;
223 if (ioctl(fb_fd, MSMFB_OVERLAY_PLAY, &ovData) < 0) {
224 ALOGE("Failed to call ioctl MSMFB_OVERLAY_PLAY err=%s",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800225 strerror(errno));
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800226 return false;
227 }
228 return true;
229}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800230MDPComp::FrameInfo::FrameInfo() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700231 reset(0);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800232}
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800233
Saurabh Shahaa236822013-04-24 18:07:26 -0700234void MDPComp::FrameInfo::reset(const int& numLayers) {
235 for(int i = 0 ; i < MAX_PIPES_PER_MIXER && numLayers; i++ ) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800236 if(mdpToLayer[i].pipeInfo) {
237 delete mdpToLayer[i].pipeInfo;
238 mdpToLayer[i].pipeInfo = NULL;
239 //We dont own the rotator
240 mdpToLayer[i].rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800241 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800242 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800243
244 memset(&mdpToLayer, 0, sizeof(mdpToLayer));
245 memset(&layerToMDP, -1, sizeof(layerToMDP));
Saurabh Shahaa236822013-04-24 18:07:26 -0700246 memset(&isFBComposed, 1, sizeof(isFBComposed));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800247
Saurabh Shahaa236822013-04-24 18:07:26 -0700248 layerCount = numLayers;
249 fbCount = numLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800250 mdpCount = 0;
Saurabh Shah2f3895f2013-05-02 10:13:31 -0700251 needsRedraw = true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800252 fbZ = 0;
253}
254
Saurabh Shahaa236822013-04-24 18:07:26 -0700255void MDPComp::FrameInfo::map() {
256 // populate layer and MDP maps
257 int mdpIdx = 0;
258 for(int idx = 0; idx < layerCount; idx++) {
259 if(!isFBComposed[idx]) {
260 mdpToLayer[mdpIdx].listIndex = idx;
261 layerToMDP[idx] = mdpIdx++;
262 }
263 }
264}
265
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800266MDPComp::LayerCache::LayerCache() {
267 reset();
268}
269
270void MDPComp::LayerCache::reset() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700271 memset(&hnd, 0, sizeof(hnd));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800272 mdpCount = 0;
273 cacheCount = 0;
274 layerCount = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -0700275 fbZ = -1;
276}
277
278void MDPComp::LayerCache::cacheAll(hwc_display_contents_1_t* list) {
279 const int numAppLayers = list->numHwLayers - 1;
280 for(int i = 0; i < numAppLayers; i++) {
281 hnd[i] = list->hwLayers[i].handle;
282 }
283}
284
285void MDPComp::LayerCache::updateCounts(const FrameInfo& curFrame) {
286 mdpCount = curFrame.mdpCount;
287 cacheCount = curFrame.fbCount;
288 layerCount = curFrame.layerCount;
289 fbZ = curFrame.fbZ;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800290}
291
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530292bool MDPComp::isValidDimension(hwc_context_t *ctx, hwc_layer_1_t *layer) {
Saurabh Shah4fdde762013-04-30 18:47:33 -0700293 const int dpy = HWC_DISPLAY_PRIMARY;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800294 private_handle_t *hnd = (private_handle_t *)layer->handle;
295
296 if(!hnd) {
297 ALOGE("%s: layer handle is NULL", __FUNCTION__);
298 return false;
299 }
300
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800301 int hw_w = ctx->dpyAttr[mDpy].xres;
302 int hw_h = ctx->dpyAttr[mDpy].yres;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800303
Saurabh Shah4fdde762013-04-30 18:47:33 -0700304 hwc_rect_t crop = layer->sourceCrop;
305 hwc_rect_t dst = layer->displayFrame;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800306
307 if(dst.left < 0 || dst.top < 0 || dst.right > hw_w || dst.bottom > hw_h) {
Saurabh Shah4fdde762013-04-30 18:47:33 -0700308 hwc_rect_t scissor = {0, 0, hw_w, hw_h };
309 qhwc::calculate_crop_rects(crop, dst, scissor, layer->transform);
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800310 }
311
Saurabh Shah4fdde762013-04-30 18:47:33 -0700312 int crop_w = crop.right - crop.left;
313 int crop_h = crop.bottom - crop.top;
314 int dst_w = dst.right - dst.left;
315 int dst_h = dst.bottom - dst.top;
316 float w_dscale = ceilf((float)crop_w / (float)dst_w);
317 float h_dscale = ceilf((float)crop_h / (float)dst_h);
318
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800319 /* Workaround for MDP HW limitation in DSI command mode panels where
320 * FPS will not go beyond 30 if buffers on RGB pipes are of width or height
321 * less than 5 pixels
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530322 * There also is a HW limilation in MDP, minimum block size is 2x2
323 * Fallback to GPU if height is less than 2.
324 */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800325 if((crop_w < 5)||(crop_h < 5))
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800326 return false;
327
Saurabh Shah4fdde762013-04-30 18:47:33 -0700328 const uint32_t downscale =
329 qdutils::MDPVersion::getInstance().getMaxMDPDownscale();
330 if(ctx->mMDP.version >= qdutils::MDSS_V5) {
331 /* Workaround for downscales larger than 4x.
332 * Will be removed once decimator block is enabled for MDSS
333 */
334 if(!qdutils::MDPVersion::getInstance().supportsDecimation()) {
335 if(crop_w > MAX_DISPLAY_DIM || w_dscale > downscale ||
336 h_dscale > downscale)
337 return false;
338 } else {
339 if(w_dscale > 64 || h_dscale > 64)
340 return false;
341 }
342 } else { //A-family
343 if(w_dscale > downscale || h_dscale > downscale)
344 return false;
345 }
346
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800347 return true;
348}
349
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700350ovutils::eDest MDPComp::getMdpPipe(hwc_context_t *ctx, ePipeType type,
351 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800352 overlay::Overlay& ov = *ctx->mOverlay;
353 ovutils::eDest mdp_pipe = ovutils::OV_INVALID;
354
355 switch(type) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800356 case MDPCOMP_OV_DMA:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700357 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_DMA, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800358 if(mdp_pipe != ovutils::OV_INVALID) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800359 return mdp_pipe;
360 }
361 case MDPCOMP_OV_ANY:
362 case MDPCOMP_OV_RGB:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700363 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800364 if(mdp_pipe != ovutils::OV_INVALID) {
365 return mdp_pipe;
366 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800367
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800368 if(type == MDPCOMP_OV_RGB) {
369 //Requested only for RGB pipe
370 break;
371 }
372 case MDPCOMP_OV_VG:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700373 return ov.nextPipe(ovutils::OV_MDP_PIPE_VG, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800374 default:
375 ALOGE("%s: Invalid pipe type",__FUNCTION__);
376 return ovutils::OV_INVALID;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800377 };
378 return ovutils::OV_INVALID;
379}
380
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800381bool MDPComp::isFrameDoable(hwc_context_t *ctx) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700382 bool ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700383 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800384
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800385 if(!isEnabled()) {
386 ALOGD_IF(isDebug(),"%s: MDP Comp. not enabled.", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700387 ret = false;
Saurabh Shahd4e65852013-06-17 11:33:53 -0700388 } else if(qdutils::MDPVersion::getInstance().is8x26() &&
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700389 ctx->mVideoTransFlag && ctx->mVirtualDisplay->isConnected()) {
Saurabh Shahd4e65852013-06-17 11:33:53 -0700390 //1 Padding round to shift pipes across mixers
391 ALOGD_IF(isDebug(),"%s: MDP Comp. video transition padding round",
392 __FUNCTION__);
393 ret = false;
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700394 } else if(ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isConfiguring ||
395 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isConfiguring) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800396 ALOGD_IF( isDebug(),"%s: External Display connection is pending",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800397 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700398 ret = false;
Saurabh Shahaa236822013-04-24 18:07:26 -0700399 } else if(ctx->isPaddingRound) {
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700400 ctx->isPaddingRound = false;
401 ALOGD_IF(isDebug(), "%s: padding round",__FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700402 ret = false;
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700403 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700404 return ret;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800405}
406
407/* Checks for conditions where all the layers marked for MDP comp cannot be
408 * bypassed. On such conditions we try to bypass atleast YUV layers */
409bool MDPComp::isFullFrameDoable(hwc_context_t *ctx,
410 hwc_display_contents_1_t* list){
411
Saurabh Shahaa236822013-04-24 18:07:26 -0700412 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800413
Saurabh Shah2d998a92013-05-14 17:55:58 -0700414 if(sIdleFallBack) {
415 ALOGD_IF(isDebug(), "%s: Idle fallback dpy %d",__FUNCTION__, mDpy);
416 return false;
417 }
418
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800419 if(mDpy > HWC_DISPLAY_PRIMARY){
420 ALOGD_IF(isDebug(), "%s: Cannot support External display(s)",
421 __FUNCTION__);
422 return false;
423 }
424
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800425 if(isSkipPresent(ctx, mDpy)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700426 ALOGD_IF(isDebug(),"%s: SKIP present: %d",
427 __FUNCTION__,
428 isSkipPresent(ctx, mDpy));
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800429 return false;
430 }
431
Saurabh Shah9f084ad2013-05-02 11:28:09 -0700432 if(ctx->listStats[mDpy].needsAlphaScale
433 && ctx->mMDP.version < qdutils::MDSS_V5) {
434 ALOGD_IF(isDebug(), "%s: frame needs alpha downscaling",__FUNCTION__);
435 return false;
436 }
437
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800438 //MDP composition is not efficient if layer needs rotator.
439 for(int i = 0; i < numAppLayers; ++i) {
440 // As MDP h/w supports flip operation, use MDP comp only for
441 // 180 transforms. Fail for any transform involving 90 (90, 270).
442 hwc_layer_1_t* layer = &list->hwLayers[i];
443 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800444
Saurabh Shah4fdde762013-04-30 18:47:33 -0700445 if((layer->transform & HWC_TRANSFORM_ROT_90) && !isYuvBuffer(hnd)) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800446 ALOGD_IF(isDebug(), "%s: orientation involved",__FUNCTION__);
447 return false;
448 }
449
Saurabh Shah4fdde762013-04-30 18:47:33 -0700450 if(!isValidDimension(ctx,layer)) {
451 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
452 __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800453 return false;
454 }
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530455
456 //For 8x26 with panel width>1k, if RGB layer needs HFLIP fail mdp comp
457 // may not need it if Gfx pre-rotation can handle all flips & rotations
458 if(qdutils::MDPVersion::getInstance().is8x26() &&
459 (ctx->dpyAttr[mDpy].xres > 1024) &&
460 (layer->transform & HWC_TRANSFORM_FLIP_H) &&
461 (!isYuvBuffer(hnd)))
462 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800463 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700464
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700465 if(ctx->mAD->isDoable()) {
466 return false;
467 }
468
Saurabh Shahaa236822013-04-24 18:07:26 -0700469 //If all above hard conditions are met we can do full or partial MDP comp.
470 bool ret = false;
471 if(fullMDPComp(ctx, list)) {
472 ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700473 } else if(partialMDPComp(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700474 ret = true;
475 }
476 return ret;
477}
478
479bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
480 //Setup mCurrentFrame
481 mCurrentFrame.mdpCount = mCurrentFrame.layerCount;
482 mCurrentFrame.fbCount = 0;
483 mCurrentFrame.fbZ = -1;
484 memset(&mCurrentFrame.isFBComposed, 0, sizeof(mCurrentFrame.isFBComposed));
485
486 int mdpCount = mCurrentFrame.mdpCount;
487 if(mdpCount > sMaxPipesPerMixer) {
488 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
489 return false;
490 }
491
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700492 if(!arePipesAvailable(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700493 return false;
494 }
495
496 return true;
497}
498
499bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
500{
501 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700502
503 if(!sEnableMixedMode) {
504 //Mixed mode is disabled. No need to even try caching.
505 return false;
506 }
507
Saurabh Shahaa236822013-04-24 18:07:26 -0700508 //Setup mCurrentFrame
509 mCurrentFrame.reset(numAppLayers);
510 updateLayerCache(ctx, list);
511 updateYUV(ctx, list);
512 batchLayers(); //sets up fbZ also
513
514 int mdpCount = mCurrentFrame.mdpCount;
515 if(mdpCount > (sMaxPipesPerMixer - 1)) { // -1 since FB is used
516 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
517 return false;
518 }
519
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700520 if(!arePipesAvailable(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700521 return false;
522 }
523
524 return true;
525}
526
527bool MDPComp::isOnlyVideoDoable(hwc_context_t *ctx,
528 hwc_display_contents_1_t* list){
529 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
530 mCurrentFrame.reset(numAppLayers);
531 updateYUV(ctx, list);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700532 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700533 int fbNeeded = int(mCurrentFrame.fbCount != 0);
534
535 if(!isYuvPresent(ctx, mDpy)) {
536 return false;
537 }
538
Saurabh Shah4fdde762013-04-30 18:47:33 -0700539 if(!mdpCount)
540 return false;
541
Saurabh Shahaa236822013-04-24 18:07:26 -0700542 if(mdpCount > (sMaxPipesPerMixer - fbNeeded)) {
543 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
544 return false;
545 }
546
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700547 if(!arePipesAvailable(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700548 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
Naseer Ahmeddc61a972013-07-10 17:50:54 -0400574 if(layer->planeAlpha < 0xFF) {
575 ALOGD_IF(isDebug(), "%s: Cannot handle YUV layer with plane alpha\
576 in video only mode",
577 __FUNCTION__);
578 return false;
579 }
580
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800581 return true;
582}
583
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800584void MDPComp::batchLayers() {
585 /* Idea is to keep as many contiguous non-updating(cached) layers in FB and
586 * send rest of them through MDP. NEVER mark an updating layer for caching.
587 * But cached ones can be marked for MDP*/
588
589 int maxBatchStart = -1;
590 int maxBatchCount = 0;
591
592 /* All or Nothing is cached. No batching needed */
Saurabh Shahaa236822013-04-24 18:07:26 -0700593 if(!mCurrentFrame.fbCount) {
594 mCurrentFrame.fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800595 return;
Saurabh Shahaa236822013-04-24 18:07:26 -0700596 }
597 if(!mCurrentFrame.mdpCount) {
598 mCurrentFrame.fbZ = 0;
599 return;
600 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800601
602 /* Search for max number of contiguous (cached) layers */
603 int i = 0;
604 while (i < mCurrentFrame.layerCount) {
605 int count = 0;
606 while(mCurrentFrame.isFBComposed[i] && i < mCurrentFrame.layerCount) {
607 count++; i++;
608 }
609 if(count > maxBatchCount) {
610 maxBatchCount = count;
611 maxBatchStart = i - count;
Saurabh Shahaa236822013-04-24 18:07:26 -0700612 mCurrentFrame.fbZ = maxBatchStart;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800613 }
614 if(i < mCurrentFrame.layerCount) i++;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800615 }
616
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800617 /* reset rest of the layers for MDP comp */
618 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
619 if(i != maxBatchStart){
620 mCurrentFrame.isFBComposed[i] = false;
621 } else {
622 i += maxBatchCount;
623 }
624 }
625
626 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700627 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
628 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800629
630 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
631 mCurrentFrame.fbCount);
632}
Saurabh Shah85234ec2013-04-12 17:09:00 -0700633
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800634void MDPComp::updateLayerCache(hwc_context_t* ctx,
635 hwc_display_contents_1_t* list) {
636
637 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
638 int numCacheableLayers = 0;
639
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800640 for(int i = 0; i < numAppLayers; i++) {
641 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
642 numCacheableLayers++;
643 mCurrentFrame.isFBComposed[i] = true;
644 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -0700645 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800646 mCachedFrame.hnd[i] = list->hwLayers[i].handle;
647 }
648 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700649
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800650 mCurrentFrame.fbCount = numCacheableLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700651 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
652 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800653 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__, numCacheableLayers);
654}
655
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800656void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list) {
657
658 int nYuvCount = ctx->listStats[mDpy].yuvCount;
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700659 if(!nYuvCount && mDpy) {
660 //Reset "No animation on external display" related parameters.
661 ctx->mPrevCropVideo.left = ctx->mPrevCropVideo.top =
662 ctx->mPrevCropVideo.right = ctx->mPrevCropVideo.bottom = 0;
663 ctx->mPrevDestVideo.left = ctx->mPrevDestVideo.top =
664 ctx->mPrevDestVideo.right = ctx->mPrevDestVideo.bottom = 0;
665 ctx->mPrevTransformVideo = 0;
666 return;
667 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800668 for(int index = 0;index < nYuvCount; index++){
669 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
670 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
671
672 if(!isYUVDoable(ctx, layer)) {
673 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
674 mCurrentFrame.isFBComposed[nYuvIndex] = true;
675 mCurrentFrame.fbCount++;
676 }
677 } else {
678 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
679 mCurrentFrame.isFBComposed[nYuvIndex] = false;
680 mCurrentFrame.fbCount--;
681 }
682 }
683 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700684
685 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
686 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800687 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
688 mCurrentFrame.fbCount);
689}
690
Saurabh Shahaa236822013-04-24 18:07:26 -0700691bool MDPComp::programMDP(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800692 if(!allocLayerPipes(ctx, list)) {
693 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700694 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800695 }
696
Saurabh Shahaa236822013-04-24 18:07:26 -0700697 bool fbBatch = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800698 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700699 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800700 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800701 int mdpIndex = mCurrentFrame.layerToMDP[index];
702 hwc_layer_1_t* layer = &list->hwLayers[index];
703
704 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
705 cur_pipe->zOrder = mdpNextZOrder++;
706
707 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
708 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
709 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -0700710 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800711 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700712 } else if(fbBatch == false) {
713 mdpNextZOrder++;
714 fbBatch = true;
715 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800716 }
717
Saurabh Shahaa236822013-04-24 18:07:26 -0700718 return true;
719}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800720
Saurabh Shahaa236822013-04-24 18:07:26 -0700721bool MDPComp::programYUV(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
722 if(!allocLayerPipes(ctx, list)) {
723 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
724 return false;
725 }
726 //If we are in this block, it means we have yuv + rgb layers both
727 int mdpIdx = 0;
728 for (int index = 0; index < mCurrentFrame.layerCount; index++) {
729 if(!mCurrentFrame.isFBComposed[index]) {
730 hwc_layer_1_t* layer = &list->hwLayers[index];
731 int mdpIndex = mCurrentFrame.layerToMDP[index];
732 MdpPipeInfo* cur_pipe =
733 mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
734 cur_pipe->zOrder = mdpIdx++;
735
736 if(configure(ctx, layer,
737 mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
738 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
739 layer %d",__FUNCTION__, index);
740 return false;
741 }
742 }
743 }
744 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800745}
746
747int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700748 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -0700749
Saurabh Shahb39f8152013-08-22 10:21:44 -0700750 //reset old data
751 mCurrentFrame.reset(numLayers);
Prabhanjan Kandula088bd892013-07-02 23:47:13 +0530752
Saurabh Shahb39f8152013-08-22 10:21:44 -0700753 //number of app layers exceeds MAX_NUM_APP_LAYERS fall back to GPU
754 //do not cache the information for next draw cycle.
755 if(numLayers > MAX_NUM_APP_LAYERS) {
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530756 mCachedFrame.updateCounts(mCurrentFrame);
Saurabh Shahb39f8152013-08-22 10:21:44 -0700757 ALOGD_IF(isDebug(), "%s: Number of App layers exceeded the limit ",
758 __FUNCTION__);
759 return -1;
760 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800761
Saurabh Shahb39f8152013-08-22 10:21:44 -0700762 //Hard conditions, if not met, cannot do MDP comp
763 if(!isFrameDoable(ctx)) {
764 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
765 __FUNCTION__);
766 reset(numLayers, list);
767 return -1;
768 }
769
770 //Check whether layers marked for MDP Composition is actually doable.
771 if(isFullFrameDoable(ctx, list)) {
772 mCurrentFrame.map();
773 //Configure framebuffer first if applicable
774 if(mCurrentFrame.fbZ >= 0) {
775 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list,
776 mCurrentFrame.fbZ)) {
777 ALOGE("%s configure framebuffer failed", __func__);
778 reset(numLayers, list);
779 return -1;
780 }
781 }
782 //Acquire and Program MDP pipes
783 if(!programMDP(ctx, list)) {
784 reset(numLayers, list);
785 return -1;
786 } else { //Success
787 //Any change in composition types needs an FB refresh
788 mCurrentFrame.needsRedraw = false;
789 if(mCurrentFrame.fbCount &&
790 ((mCurrentFrame.mdpCount != mCachedFrame.mdpCount) ||
791 (mCurrentFrame.fbCount != mCachedFrame.cacheCount) ||
792 (mCurrentFrame.fbZ != mCachedFrame.fbZ) ||
793 (!mCurrentFrame.mdpCount) ||
794 (list->flags & HWC_GEOMETRY_CHANGED) ||
795 isSkipPresent(ctx, mDpy) ||
796 (mDpy > HWC_DISPLAY_PRIMARY))) {
797 mCurrentFrame.needsRedraw = true;
798 }
799 }
800 } else if(isOnlyVideoDoable(ctx, list)) {
801 //All layers marked for MDP comp cannot be bypassed.
802 //Try to compose atleast YUV layers through MDP comp and let
803 //all the RGB layers compose in FB
804 //Destination over
805 mCurrentFrame.fbZ = -1;
806 if(mCurrentFrame.fbCount)
807 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
808
809 mCurrentFrame.map();
810
811 //Configure framebuffer first if applicable
812 if(mCurrentFrame.fbZ >= 0) {
813 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, mCurrentFrame.fbZ)) {
814 ALOGE("%s configure framebuffer failed", __func__);
815 reset(numLayers, list);
816 return -1;
817 }
818 }
819 if(!programYUV(ctx, list)) {
820 reset(numLayers, list);
821 return -1;
822 }
823 } else {
824 reset(numLayers, list);
825 return -1;
826 }
827
828 //UpdateLayerFlags
829 setMDPCompLayerFlags(ctx, list);
830 mCachedFrame.updateCounts(mCurrentFrame);
831
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530832 // unlock it before calling dump function to avoid deadlock
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800833 if(isDebug()) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700834 ALOGD("GEOMETRY change: %d", (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800835 android::String8 sDump("");
836 dump(sDump);
837 ALOGE("%s",sDump.string());
838 }
839
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700840 return 0;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800841}
842
843//=============MDPCompLowRes===================================================
844
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700845/*
846 * Configures pipe(s) for MDP composition
847 */
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800848int MDPCompLowRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800849 PipeLayerPair& PipeLayerPair) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800850 MdpPipeInfoLowRes& mdp_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800851 *(static_cast<MdpPipeInfoLowRes*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -0800852 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
853 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
854 eIsFg isFg = IS_FG_OFF;
855 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700856
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800857 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
858 __FUNCTION__, layer, zOrder, dest);
859
860 return configureLowRes(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
861 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700862}
863
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700864bool MDPCompLowRes::arePipesAvailable(hwc_context_t *ctx,
865 hwc_display_contents_1_t* list) {
866 overlay::Overlay& ov = *ctx->mOverlay;
867 int numPipesNeeded = mCurrentFrame.mdpCount;
868 int availPipes = ov.availablePipes(mDpy, Overlay::MIXER_DEFAULT);
869
870 //Reserve pipe for FB
871 if(mCurrentFrame.fbCount)
872 availPipes -= 1;
873
874 if(numPipesNeeded > availPipes) {
875 ALOGD_IF(isDebug(), "%s: Insufficient pipes, dpy %d needed %d, avail %d",
876 __FUNCTION__, mDpy, numPipesNeeded, availPipes);
877 return false;
878 }
879
880 return true;
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
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700906 pipe_info.index = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
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
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500933 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -0700934 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500935 idleInvalidator->markForSleep();
936
937 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800938 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700939
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800940 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
941 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700942 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800943 if(mCurrentFrame.isFBComposed[i]) continue;
944
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700945 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -0800946 private_handle_t *hnd = (private_handle_t *)layer->handle;
947 if(!hnd) {
948 ALOGE("%s handle null", __FUNCTION__);
949 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700950 }
951
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800952 int mdpIndex = mCurrentFrame.layerToMDP[i];
953
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800954 MdpPipeInfoLowRes& pipe_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800955 *(MdpPipeInfoLowRes*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800956 ovutils::eDest dest = pipe_info.index;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800957 if(dest == ovutils::OV_INVALID) {
958 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500959 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700960 }
961
Saurabh Shahacf10202013-02-26 10:15:15 -0800962 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
963 continue;
964 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700965
Saurabh Shahacf10202013-02-26 10:15:15 -0800966 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800967 using pipe: %d", __FUNCTION__, layer,
968 hnd, dest );
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700969
Saurabh Shahacf10202013-02-26 10:15:15 -0800970 int fd = hnd->fd;
971 uint32_t offset = hnd->offset;
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700972
973 if(ctx->mAD->isModeOn()) {
974 if(ctx->mAD->draw(ctx, fd, offset)) {
975 fd = ctx->mAD->getDstFd(ctx);
976 offset = ctx->mAD->getDstOffset(ctx);
977 }
978 }
979
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800980 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -0800981 if(rot) {
982 if(!rot->queueBuffer(fd, offset))
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500983 return false;
Saurabh Shahacf10202013-02-26 10:15:15 -0800984 fd = rot->getDstMemId();
985 offset = rot->getDstOffset();
986 }
987
988 if (!ov.queueBuffer(fd, offset, dest)) {
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +0530989 ALOGE("%s: queueBuffer failed for display:%d ", __FUNCTION__, mDpy);
Saurabh Shahacf10202013-02-26 10:15:15 -0800990 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700991 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500992
993 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700994 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500995 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700996}
997
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800998//=============MDPCompHighRes===================================================
999
1000int MDPCompHighRes::pipesNeeded(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001001 hwc_display_contents_1_t* list,
1002 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001003 int pipesNeeded = 0;
Saurabh Shah67a38c32013-06-10 16:23:15 -07001004 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001005
1006 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001007
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001008 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1009 if(!mCurrentFrame.isFBComposed[i]) {
1010 hwc_layer_1_t* layer = &list->hwLayers[i];
1011 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001012 if(mixer == Overlay::MIXER_LEFT && dst.left < lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001013 pipesNeeded++;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001014 } else if(mixer == Overlay::MIXER_RIGHT && dst.right > lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001015 pipesNeeded++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001016 }
1017 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001018 }
1019 return pipesNeeded;
1020}
1021
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001022bool MDPCompHighRes::arePipesAvailable(hwc_context_t *ctx,
1023 hwc_display_contents_1_t* list) {
1024 overlay::Overlay& ov = *ctx->mOverlay;
1025
1026 for(int i = 0; i < Overlay::MIXER_MAX; i++) {
1027 int numPipesNeeded = pipesNeeded(ctx, list, i);
1028 int availPipes = ov.availablePipes(mDpy, i);
1029
1030 //Reserve pipe(s)for FB
1031 if(mCurrentFrame.fbCount)
1032 availPipes -= 1;
1033
1034 if(numPipesNeeded > availPipes) {
1035 ALOGD_IF(isDebug(), "%s: Insufficient pipes for "
1036 "dpy %d mixer %d needed %d, avail %d",
1037 __FUNCTION__, mDpy, i, numPipesNeeded, availPipes);
1038 return false;
1039 }
1040 }
1041 return true;
1042}
1043
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001044bool MDPCompHighRes::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001045 MdpPipeInfoHighRes& pipe_info,
1046 ePipeType type) {
1047 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001048 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001049
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001050 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001051 pipe_info.lIndex = ovutils::OV_INVALID;
1052 pipe_info.rIndex = ovutils::OV_INVALID;
1053
1054 if (dst.left < lSplit) {
1055 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_LEFT);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001056 if(pipe_info.lIndex == ovutils::OV_INVALID)
1057 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001058 }
1059
1060 if(dst.right > lSplit) {
1061 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_RIGHT);
1062 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001063 return false;
1064 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001065
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001066 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001067}
1068
1069bool MDPCompHighRes::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001070 hwc_display_contents_1_t* list) {
1071 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001072
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001073 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001074
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001075 hwc_layer_1_t* layer = &list->hwLayers[index];
1076 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001077 int mdpIndex = mCurrentFrame.layerToMDP[index];
1078 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001079 info.pipeInfo = new MdpPipeInfoHighRes;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001080 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001081 MdpPipeInfoHighRes& pipe_info = *(MdpPipeInfoHighRes*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001082 ePipeType type = MDPCOMP_OV_ANY;
1083
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001084 if(isYuvBuffer(hnd)) {
1085 type = MDPCOMP_OV_VG;
Saurabh Shah8a117932013-05-23 12:48:13 -07001086 } else if(!qhwc::needsScaling(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001087 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001088 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001089 type = MDPCOMP_OV_DMA;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001090 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001091
1092 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001093 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type = %d",
1094 __FUNCTION__, (int) type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001095 return false;
1096 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001097 }
1098 return true;
1099}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001100
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001101/*
1102 * Configures pipe(s) for MDP composition
1103 */
1104int MDPCompHighRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001105 PipeLayerPair& PipeLayerPair) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001106 MdpPipeInfoHighRes& mdp_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001107 *(static_cast<MdpPipeInfoHighRes*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001108 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1109 eIsFg isFg = IS_FG_OFF;
1110 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1111 eDest lDest = mdp_info.lIndex;
1112 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001113
1114 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1115 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1116
1117 return configureHighRes(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
1118 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001119}
1120
1121bool MDPCompHighRes::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
1122
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001123 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001124 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1125 return true;
1126 }
1127
1128 if(!ctx || !list) {
1129 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001130 return false;
1131 }
1132
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301133 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1134 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1135 return true;
1136 }
1137
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001138 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001139 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001140 idleInvalidator->markForSleep();
1141
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001142 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001143 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001144
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001145 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1146 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001147 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001148 if(mCurrentFrame.isFBComposed[i]) continue;
1149
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001150 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001151 private_handle_t *hnd = (private_handle_t *)layer->handle;
1152 if(!hnd) {
1153 ALOGE("%s handle null", __FUNCTION__);
1154 return false;
1155 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001156
1157 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1158 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001159 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001160
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001161 int mdpIndex = mCurrentFrame.layerToMDP[i];
1162
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001163 MdpPipeInfoHighRes& pipe_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001164 *(MdpPipeInfoHighRes*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1165 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -08001166
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001167 ovutils::eDest indexL = pipe_info.lIndex;
1168 ovutils::eDest indexR = pipe_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001169
Saurabh Shahacf10202013-02-26 10:15:15 -08001170 int fd = hnd->fd;
1171 int offset = hnd->offset;
1172
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001173 if(ctx->mAD->isModeOn()) {
1174 if(ctx->mAD->draw(ctx, fd, offset)) {
1175 fd = ctx->mAD->getDstFd(ctx);
1176 offset = ctx->mAD->getDstOffset(ctx);
1177 }
1178 }
1179
Saurabh Shahacf10202013-02-26 10:15:15 -08001180 if(rot) {
1181 rot->queueBuffer(fd, offset);
1182 fd = rot->getDstMemId();
1183 offset = rot->getDstOffset();
1184 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001185
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001186 //************* play left mixer **********
1187 if(indexL != ovutils::OV_INVALID) {
1188 ovutils::eDest destL = (ovutils::eDest)indexL;
Saurabh Shahacf10202013-02-26 10:15:15 -08001189 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001190 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
Saurabh Shahacf10202013-02-26 10:15:15 -08001191 if (!ov.queueBuffer(fd, offset, destL)) {
1192 ALOGE("%s: queueBuffer failed for left mixer", __FUNCTION__);
1193 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001194 }
1195 }
1196
1197 //************* play right mixer **********
1198 if(indexR != ovutils::OV_INVALID) {
1199 ovutils::eDest destR = (ovutils::eDest)indexR;
Saurabh Shahacf10202013-02-26 10:15:15 -08001200 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001201 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
Saurabh Shahacf10202013-02-26 10:15:15 -08001202 if (!ov.queueBuffer(fd, offset, destR)) {
1203 ALOGE("%s: queueBuffer failed for right mixer", __FUNCTION__);
1204 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001205 }
1206 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001207
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001208 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1209 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001210
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001211 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001212}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001213}; //namespace
1214