blob: f2217b9070864163ed0a95f192039bf933926b9d [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
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700445 if(layer->transform & HWC_TRANSFORM_ROT_90) {
446 if(!isYuvBuffer(hnd) ) {
447 ALOGD_IF(isDebug(), "%s: orientation involved",__FUNCTION__);
448 return false;
449 }else if(!canUseRotator(ctx, mDpy)) {
450 ALOGD_IF(isDebug(), "%s: no free DMA pipe",__FUNCTION__);
451 return false;
452 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800453 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700454 if(!isValidDimension(ctx,layer)) {
455 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
456 __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800457 return false;
458 }
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530459
460 //For 8x26 with panel width>1k, if RGB layer needs HFLIP fail mdp comp
461 // may not need it if Gfx pre-rotation can handle all flips & rotations
462 if(qdutils::MDPVersion::getInstance().is8x26() &&
463 (ctx->dpyAttr[mDpy].xres > 1024) &&
464 (layer->transform & HWC_TRANSFORM_FLIP_H) &&
465 (!isYuvBuffer(hnd)))
466 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800467 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700468
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700469 if(ctx->mAD->isDoable()) {
470 return false;
471 }
472
Saurabh Shahaa236822013-04-24 18:07:26 -0700473 //If all above hard conditions are met we can do full or partial MDP comp.
474 bool ret = false;
475 if(fullMDPComp(ctx, list)) {
476 ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700477 } else if(partialMDPComp(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700478 ret = true;
479 }
480 return ret;
481}
482
483bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
484 //Setup mCurrentFrame
485 mCurrentFrame.mdpCount = mCurrentFrame.layerCount;
486 mCurrentFrame.fbCount = 0;
487 mCurrentFrame.fbZ = -1;
488 memset(&mCurrentFrame.isFBComposed, 0, sizeof(mCurrentFrame.isFBComposed));
489
490 int mdpCount = mCurrentFrame.mdpCount;
491 if(mdpCount > sMaxPipesPerMixer) {
492 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
493 return false;
494 }
495
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700496 if(!arePipesAvailable(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700497 return false;
498 }
499
500 return true;
501}
502
503bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
504{
505 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700506
507 if(!sEnableMixedMode) {
508 //Mixed mode is disabled. No need to even try caching.
509 return false;
510 }
511
Saurabh Shahaa236822013-04-24 18:07:26 -0700512 //Setup mCurrentFrame
513 mCurrentFrame.reset(numAppLayers);
514 updateLayerCache(ctx, list);
515 updateYUV(ctx, list);
516 batchLayers(); //sets up fbZ also
517
518 int mdpCount = mCurrentFrame.mdpCount;
519 if(mdpCount > (sMaxPipesPerMixer - 1)) { // -1 since FB is used
520 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
521 return false;
522 }
523
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700524 if(!arePipesAvailable(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700525 return false;
526 }
527
528 return true;
529}
530
531bool MDPComp::isOnlyVideoDoable(hwc_context_t *ctx,
532 hwc_display_contents_1_t* list){
533 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
534 mCurrentFrame.reset(numAppLayers);
535 updateYUV(ctx, list);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700536 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700537 int fbNeeded = int(mCurrentFrame.fbCount != 0);
538
539 if(!isYuvPresent(ctx, mDpy)) {
540 return false;
541 }
542
Saurabh Shah4fdde762013-04-30 18:47:33 -0700543 if(!mdpCount)
544 return false;
545
Saurabh Shahaa236822013-04-24 18:07:26 -0700546 if(mdpCount > (sMaxPipesPerMixer - fbNeeded)) {
547 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
548 return false;
549 }
550
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700551 if(!arePipesAvailable(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700552 return false;
553 }
554
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800555 return true;
556}
557
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800558/* Checks for conditions where YUV layers cannot be bypassed */
559bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Saurabh Shahe2474082013-05-15 16:32:13 -0700560 bool extAnimBlockFeature = mDpy && ctx->listStats[mDpy].isDisplayAnimating;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800561
Saurabh Shahe2474082013-05-15 16:32:13 -0700562 if(isSkipLayer(layer) && !extAnimBlockFeature) {
563 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800564 return false;
565 }
566
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700567 if(layer->transform & HWC_TRANSFORM_ROT_90 && !canUseRotator(ctx,mDpy)) {
568 ALOGD_IF(isDebug(), "%s: no free DMA pipe",__FUNCTION__);
569 return false;
570 }
571
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800572 if(isSecuring(ctx, layer)) {
573 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
574 return false;
575 }
576
Saurabh Shah4fdde762013-04-30 18:47:33 -0700577 if(!isValidDimension(ctx, layer)) {
578 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
579 __FUNCTION__);
580 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800581 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700582
Naseer Ahmeddc61a972013-07-10 17:50:54 -0400583 if(layer->planeAlpha < 0xFF) {
584 ALOGD_IF(isDebug(), "%s: Cannot handle YUV layer with plane alpha\
585 in video only mode",
586 __FUNCTION__);
587 return false;
588 }
589
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800590 return true;
591}
592
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800593void MDPComp::batchLayers() {
594 /* Idea is to keep as many contiguous non-updating(cached) layers in FB and
595 * send rest of them through MDP. NEVER mark an updating layer for caching.
596 * But cached ones can be marked for MDP*/
597
598 int maxBatchStart = -1;
599 int maxBatchCount = 0;
600
601 /* All or Nothing is cached. No batching needed */
Saurabh Shahaa236822013-04-24 18:07:26 -0700602 if(!mCurrentFrame.fbCount) {
603 mCurrentFrame.fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800604 return;
Saurabh Shahaa236822013-04-24 18:07:26 -0700605 }
606 if(!mCurrentFrame.mdpCount) {
607 mCurrentFrame.fbZ = 0;
608 return;
609 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800610
611 /* Search for max number of contiguous (cached) layers */
612 int i = 0;
613 while (i < mCurrentFrame.layerCount) {
614 int count = 0;
615 while(mCurrentFrame.isFBComposed[i] && i < mCurrentFrame.layerCount) {
616 count++; i++;
617 }
618 if(count > maxBatchCount) {
619 maxBatchCount = count;
620 maxBatchStart = i - count;
Saurabh Shahaa236822013-04-24 18:07:26 -0700621 mCurrentFrame.fbZ = maxBatchStart;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800622 }
623 if(i < mCurrentFrame.layerCount) i++;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800624 }
625
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800626 /* reset rest of the layers for MDP comp */
627 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
628 if(i != maxBatchStart){
629 mCurrentFrame.isFBComposed[i] = false;
630 } else {
631 i += maxBatchCount;
632 }
633 }
634
635 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700636 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
637 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800638
639 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
640 mCurrentFrame.fbCount);
641}
Saurabh Shah85234ec2013-04-12 17:09:00 -0700642
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800643void MDPComp::updateLayerCache(hwc_context_t* ctx,
644 hwc_display_contents_1_t* list) {
645
646 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
647 int numCacheableLayers = 0;
648
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800649 for(int i = 0; i < numAppLayers; i++) {
650 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
651 numCacheableLayers++;
652 mCurrentFrame.isFBComposed[i] = true;
653 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -0700654 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800655 mCachedFrame.hnd[i] = list->hwLayers[i].handle;
656 }
657 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700658
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800659 mCurrentFrame.fbCount = numCacheableLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700660 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
661 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800662 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__, numCacheableLayers);
663}
664
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800665void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list) {
666
667 int nYuvCount = ctx->listStats[mDpy].yuvCount;
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700668 if(!nYuvCount && mDpy) {
669 //Reset "No animation on external display" related parameters.
670 ctx->mPrevCropVideo.left = ctx->mPrevCropVideo.top =
671 ctx->mPrevCropVideo.right = ctx->mPrevCropVideo.bottom = 0;
672 ctx->mPrevDestVideo.left = ctx->mPrevDestVideo.top =
673 ctx->mPrevDestVideo.right = ctx->mPrevDestVideo.bottom = 0;
674 ctx->mPrevTransformVideo = 0;
675 return;
676 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800677 for(int index = 0;index < nYuvCount; index++){
678 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
679 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
680
681 if(!isYUVDoable(ctx, layer)) {
682 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
683 mCurrentFrame.isFBComposed[nYuvIndex] = true;
684 mCurrentFrame.fbCount++;
685 }
686 } else {
687 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
688 mCurrentFrame.isFBComposed[nYuvIndex] = false;
689 mCurrentFrame.fbCount--;
690 }
691 }
692 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700693
694 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
695 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800696 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
697 mCurrentFrame.fbCount);
698}
699
Saurabh Shahaa236822013-04-24 18:07:26 -0700700bool MDPComp::programMDP(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800701 if(!allocLayerPipes(ctx, list)) {
702 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700703 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800704 }
705
Saurabh Shahaa236822013-04-24 18:07:26 -0700706 bool fbBatch = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800707 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700708 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800709 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800710 int mdpIndex = mCurrentFrame.layerToMDP[index];
711 hwc_layer_1_t* layer = &list->hwLayers[index];
712
713 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
714 cur_pipe->zOrder = mdpNextZOrder++;
715
716 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
717 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
718 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -0700719 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800720 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700721 } else if(fbBatch == false) {
722 mdpNextZOrder++;
723 fbBatch = true;
724 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800725 }
726
Saurabh Shahaa236822013-04-24 18:07:26 -0700727 return true;
728}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800729
Saurabh Shahaa236822013-04-24 18:07:26 -0700730bool MDPComp::programYUV(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
731 if(!allocLayerPipes(ctx, list)) {
732 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
733 return false;
734 }
735 //If we are in this block, it means we have yuv + rgb layers both
736 int mdpIdx = 0;
737 for (int index = 0; index < mCurrentFrame.layerCount; index++) {
738 if(!mCurrentFrame.isFBComposed[index]) {
739 hwc_layer_1_t* layer = &list->hwLayers[index];
740 int mdpIndex = mCurrentFrame.layerToMDP[index];
741 MdpPipeInfo* cur_pipe =
742 mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
743 cur_pipe->zOrder = mdpIdx++;
744
745 if(configure(ctx, layer,
746 mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
747 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
748 layer %d",__FUNCTION__, index);
749 return false;
750 }
751 }
752 }
753 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800754}
755
756int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700757 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -0700758
Saurabh Shahb39f8152013-08-22 10:21:44 -0700759 //reset old data
760 mCurrentFrame.reset(numLayers);
Prabhanjan Kandula088bd892013-07-02 23:47:13 +0530761
Saurabh Shahb39f8152013-08-22 10:21:44 -0700762 //number of app layers exceeds MAX_NUM_APP_LAYERS fall back to GPU
763 //do not cache the information for next draw cycle.
764 if(numLayers > MAX_NUM_APP_LAYERS) {
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530765 mCachedFrame.updateCounts(mCurrentFrame);
Saurabh Shahb39f8152013-08-22 10:21:44 -0700766 ALOGD_IF(isDebug(), "%s: Number of App layers exceeded the limit ",
767 __FUNCTION__);
768 return -1;
769 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800770
Saurabh Shahb39f8152013-08-22 10:21:44 -0700771 //Hard conditions, if not met, cannot do MDP comp
772 if(!isFrameDoable(ctx)) {
773 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
774 __FUNCTION__);
775 reset(numLayers, list);
776 return -1;
777 }
778
779 //Check whether layers marked for MDP Composition is actually doable.
780 if(isFullFrameDoable(ctx, list)) {
781 mCurrentFrame.map();
782 //Configure framebuffer first if applicable
783 if(mCurrentFrame.fbZ >= 0) {
784 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list,
785 mCurrentFrame.fbZ)) {
786 ALOGE("%s configure framebuffer failed", __func__);
787 reset(numLayers, list);
788 return -1;
789 }
790 }
791 //Acquire and Program MDP pipes
792 if(!programMDP(ctx, list)) {
793 reset(numLayers, list);
794 return -1;
795 } else { //Success
796 //Any change in composition types needs an FB refresh
797 mCurrentFrame.needsRedraw = false;
798 if(mCurrentFrame.fbCount &&
799 ((mCurrentFrame.mdpCount != mCachedFrame.mdpCount) ||
800 (mCurrentFrame.fbCount != mCachedFrame.cacheCount) ||
801 (mCurrentFrame.fbZ != mCachedFrame.fbZ) ||
802 (!mCurrentFrame.mdpCount) ||
803 (list->flags & HWC_GEOMETRY_CHANGED) ||
804 isSkipPresent(ctx, mDpy) ||
805 (mDpy > HWC_DISPLAY_PRIMARY))) {
806 mCurrentFrame.needsRedraw = true;
807 }
808 }
809 } else if(isOnlyVideoDoable(ctx, list)) {
810 //All layers marked for MDP comp cannot be bypassed.
811 //Try to compose atleast YUV layers through MDP comp and let
812 //all the RGB layers compose in FB
813 //Destination over
814 mCurrentFrame.fbZ = -1;
815 if(mCurrentFrame.fbCount)
816 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
817
818 mCurrentFrame.map();
819
820 //Configure framebuffer first if applicable
821 if(mCurrentFrame.fbZ >= 0) {
822 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, mCurrentFrame.fbZ)) {
823 ALOGE("%s configure framebuffer failed", __func__);
824 reset(numLayers, list);
825 return -1;
826 }
827 }
828 if(!programYUV(ctx, list)) {
829 reset(numLayers, list);
830 return -1;
831 }
832 } else {
833 reset(numLayers, list);
834 return -1;
835 }
836
837 //UpdateLayerFlags
838 setMDPCompLayerFlags(ctx, list);
839 mCachedFrame.updateCounts(mCurrentFrame);
840
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530841 // unlock it before calling dump function to avoid deadlock
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800842 if(isDebug()) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700843 ALOGD("GEOMETRY change: %d", (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800844 android::String8 sDump("");
845 dump(sDump);
846 ALOGE("%s",sDump.string());
847 }
848
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700849 return 0;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800850}
851
852//=============MDPCompLowRes===================================================
853
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700854/*
855 * Configures pipe(s) for MDP composition
856 */
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800857int MDPCompLowRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800858 PipeLayerPair& PipeLayerPair) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800859 MdpPipeInfoLowRes& mdp_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800860 *(static_cast<MdpPipeInfoLowRes*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -0800861 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
862 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
863 eIsFg isFg = IS_FG_OFF;
864 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700865
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800866 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
867 __FUNCTION__, layer, zOrder, dest);
868
869 return configureLowRes(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
870 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700871}
872
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700873bool MDPCompLowRes::arePipesAvailable(hwc_context_t *ctx,
874 hwc_display_contents_1_t* list) {
875 overlay::Overlay& ov = *ctx->mOverlay;
876 int numPipesNeeded = mCurrentFrame.mdpCount;
877 int availPipes = ov.availablePipes(mDpy, Overlay::MIXER_DEFAULT);
878
879 //Reserve pipe for FB
880 if(mCurrentFrame.fbCount)
881 availPipes -= 1;
882
883 if(numPipesNeeded > availPipes) {
884 ALOGD_IF(isDebug(), "%s: Insufficient pipes, dpy %d needed %d, avail %d",
885 __FUNCTION__, mDpy, numPipesNeeded, availPipes);
886 return false;
887 }
888
889 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700890}
891
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800892bool MDPCompLowRes::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700893 hwc_display_contents_1_t* list) {
894 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700895
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800896 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700897
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800898 hwc_layer_1_t* layer = &list->hwLayers[index];
899 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800900 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800901 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800902 info.pipeInfo = new MdpPipeInfoLowRes;
Saurabh Shahacf10202013-02-26 10:15:15 -0800903 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800904 MdpPipeInfoLowRes& pipe_info = *(MdpPipeInfoLowRes*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800905 ePipeType type = MDPCOMP_OV_ANY;
906
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700907 if(isYuvBuffer(hnd)) {
908 type = MDPCOMP_OV_VG;
Saurabh Shah8a117932013-05-23 12:48:13 -0700909 } else if(!qhwc::needsScaling(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -0700910 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
911 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800912 type = MDPCOMP_OV_DMA;
913 }
914
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700915 pipe_info.index = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800916 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700917 ALOGD_IF(isDebug(), "%s: Unable to get pipe type = %d",
918 __FUNCTION__, (int) type);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500919 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700920 }
921 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700922 return true;
923}
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700924
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800925bool MDPCompLowRes::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700926
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800927 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500928 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
929 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800930 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700931
932 if(!ctx || !list) {
933 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500934 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700935 }
936
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +0530937 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
938 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
939 return true;
940 }
941
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500942 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -0700943 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500944 idleInvalidator->markForSleep();
945
946 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800947 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700948
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800949 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
950 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700951 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800952 if(mCurrentFrame.isFBComposed[i]) continue;
953
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700954 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -0800955 private_handle_t *hnd = (private_handle_t *)layer->handle;
956 if(!hnd) {
957 ALOGE("%s handle null", __FUNCTION__);
958 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700959 }
960
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800961 int mdpIndex = mCurrentFrame.layerToMDP[i];
962
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800963 MdpPipeInfoLowRes& pipe_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800964 *(MdpPipeInfoLowRes*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800965 ovutils::eDest dest = pipe_info.index;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800966 if(dest == ovutils::OV_INVALID) {
967 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500968 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700969 }
970
Saurabh Shahacf10202013-02-26 10:15:15 -0800971 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
972 continue;
973 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700974
Saurabh Shahacf10202013-02-26 10:15:15 -0800975 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800976 using pipe: %d", __FUNCTION__, layer,
977 hnd, dest );
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700978
Saurabh Shahacf10202013-02-26 10:15:15 -0800979 int fd = hnd->fd;
980 uint32_t offset = hnd->offset;
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700981
982 if(ctx->mAD->isModeOn()) {
983 if(ctx->mAD->draw(ctx, fd, offset)) {
984 fd = ctx->mAD->getDstFd(ctx);
985 offset = ctx->mAD->getDstOffset(ctx);
986 }
987 }
988
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800989 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -0800990 if(rot) {
991 if(!rot->queueBuffer(fd, offset))
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500992 return false;
Saurabh Shahacf10202013-02-26 10:15:15 -0800993 fd = rot->getDstMemId();
994 offset = rot->getDstOffset();
995 }
996
997 if (!ov.queueBuffer(fd, offset, dest)) {
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +0530998 ALOGE("%s: queueBuffer failed for display:%d ", __FUNCTION__, mDpy);
Saurabh Shahacf10202013-02-26 10:15:15 -0800999 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001000 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001001
1002 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001003 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001004 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001005}
1006
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001007//=============MDPCompHighRes===================================================
1008
1009int MDPCompHighRes::pipesNeeded(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001010 hwc_display_contents_1_t* list,
1011 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001012 int pipesNeeded = 0;
Saurabh Shah67a38c32013-06-10 16:23:15 -07001013 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001014
1015 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001016
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001017 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1018 if(!mCurrentFrame.isFBComposed[i]) {
1019 hwc_layer_1_t* layer = &list->hwLayers[i];
1020 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001021 if(mixer == Overlay::MIXER_LEFT && dst.left < lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001022 pipesNeeded++;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001023 } else if(mixer == Overlay::MIXER_RIGHT && dst.right > lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001024 pipesNeeded++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001025 }
1026 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001027 }
1028 return pipesNeeded;
1029}
1030
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001031bool MDPCompHighRes::arePipesAvailable(hwc_context_t *ctx,
1032 hwc_display_contents_1_t* list) {
1033 overlay::Overlay& ov = *ctx->mOverlay;
1034
1035 for(int i = 0; i < Overlay::MIXER_MAX; i++) {
1036 int numPipesNeeded = pipesNeeded(ctx, list, i);
1037 int availPipes = ov.availablePipes(mDpy, i);
1038
1039 //Reserve pipe(s)for FB
1040 if(mCurrentFrame.fbCount)
1041 availPipes -= 1;
1042
1043 if(numPipesNeeded > availPipes) {
1044 ALOGD_IF(isDebug(), "%s: Insufficient pipes for "
1045 "dpy %d mixer %d needed %d, avail %d",
1046 __FUNCTION__, mDpy, i, numPipesNeeded, availPipes);
1047 return false;
1048 }
1049 }
1050 return true;
1051}
1052
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001053bool MDPCompHighRes::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001054 MdpPipeInfoHighRes& pipe_info,
1055 ePipeType type) {
1056 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001057 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001058
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001059 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001060 pipe_info.lIndex = ovutils::OV_INVALID;
1061 pipe_info.rIndex = ovutils::OV_INVALID;
1062
1063 if (dst.left < lSplit) {
1064 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_LEFT);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001065 if(pipe_info.lIndex == ovutils::OV_INVALID)
1066 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001067 }
1068
1069 if(dst.right > lSplit) {
1070 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_RIGHT);
1071 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001072 return false;
1073 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001074
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001075 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001076}
1077
1078bool MDPCompHighRes::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001079 hwc_display_contents_1_t* list) {
1080 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001081
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001082 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001083
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001084 hwc_layer_1_t* layer = &list->hwLayers[index];
1085 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001086 int mdpIndex = mCurrentFrame.layerToMDP[index];
1087 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001088 info.pipeInfo = new MdpPipeInfoHighRes;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001089 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001090 MdpPipeInfoHighRes& pipe_info = *(MdpPipeInfoHighRes*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001091 ePipeType type = MDPCOMP_OV_ANY;
1092
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001093 if(isYuvBuffer(hnd)) {
1094 type = MDPCOMP_OV_VG;
Saurabh Shah8a117932013-05-23 12:48:13 -07001095 } else if(!qhwc::needsScaling(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001096 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001097 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001098 type = MDPCOMP_OV_DMA;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001099 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001100
1101 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001102 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type = %d",
1103 __FUNCTION__, (int) type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001104 return false;
1105 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001106 }
1107 return true;
1108}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001109
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001110/*
1111 * Configures pipe(s) for MDP composition
1112 */
1113int MDPCompHighRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001114 PipeLayerPair& PipeLayerPair) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001115 MdpPipeInfoHighRes& mdp_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001116 *(static_cast<MdpPipeInfoHighRes*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001117 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1118 eIsFg isFg = IS_FG_OFF;
1119 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1120 eDest lDest = mdp_info.lIndex;
1121 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001122
1123 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1124 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1125
1126 return configureHighRes(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
1127 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001128}
1129
1130bool MDPCompHighRes::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
1131
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001132 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001133 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1134 return true;
1135 }
1136
1137 if(!ctx || !list) {
1138 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001139 return false;
1140 }
1141
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301142 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1143 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1144 return true;
1145 }
1146
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001147 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001148 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001149 idleInvalidator->markForSleep();
1150
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001151 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001152 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001153
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001154 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1155 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001156 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001157 if(mCurrentFrame.isFBComposed[i]) continue;
1158
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001159 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001160 private_handle_t *hnd = (private_handle_t *)layer->handle;
1161 if(!hnd) {
1162 ALOGE("%s handle null", __FUNCTION__);
1163 return false;
1164 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001165
1166 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1167 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001168 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001169
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001170 int mdpIndex = mCurrentFrame.layerToMDP[i];
1171
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001172 MdpPipeInfoHighRes& pipe_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001173 *(MdpPipeInfoHighRes*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1174 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -08001175
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001176 ovutils::eDest indexL = pipe_info.lIndex;
1177 ovutils::eDest indexR = pipe_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001178
Saurabh Shahacf10202013-02-26 10:15:15 -08001179 int fd = hnd->fd;
1180 int offset = hnd->offset;
1181
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001182 if(ctx->mAD->isModeOn()) {
1183 if(ctx->mAD->draw(ctx, fd, offset)) {
1184 fd = ctx->mAD->getDstFd(ctx);
1185 offset = ctx->mAD->getDstOffset(ctx);
1186 }
1187 }
1188
Saurabh Shahacf10202013-02-26 10:15:15 -08001189 if(rot) {
1190 rot->queueBuffer(fd, offset);
1191 fd = rot->getDstMemId();
1192 offset = rot->getDstOffset();
1193 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001194
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001195 //************* play left mixer **********
1196 if(indexL != ovutils::OV_INVALID) {
1197 ovutils::eDest destL = (ovutils::eDest)indexL;
Saurabh Shahacf10202013-02-26 10:15:15 -08001198 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001199 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
Saurabh Shahacf10202013-02-26 10:15:15 -08001200 if (!ov.queueBuffer(fd, offset, destL)) {
1201 ALOGE("%s: queueBuffer failed for left mixer", __FUNCTION__);
1202 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001203 }
1204 }
1205
1206 //************* play right mixer **********
1207 if(indexR != ovutils::OV_INVALID) {
1208 ovutils::eDest destR = (ovutils::eDest)indexR;
Saurabh Shahacf10202013-02-26 10:15:15 -08001209 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001210 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
Saurabh Shahacf10202013-02-26 10:15:15 -08001211 if (!ov.queueBuffer(fd, offset, destR)) {
1212 ALOGE("%s: queueBuffer failed for right mixer", __FUNCTION__);
1213 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001214 }
1215 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001216
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001217 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1218 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001219
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001220 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001221}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001222}; //namespace
1223