blob: 0accf802e108824703f90b2810cbbc7de9686e7d [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 Sankaran85977e32013-02-25 17:06:08 -080058 dumpsys_log(buf,"HWC Map for Dpy: %s \n",
Jeykumar Sankaran27dee262013-08-01 17:09:54 -070059 (mDpy == 0) ? "\"PRIMARY\"" :
60 (mDpy == 1) ? "\"EXTERNAL\"" : "\"VIRTUAL\"");
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080061 dumpsys_log(buf,"PREV_FRAME: layerCount:%2d mdpCount:%2d \
62 cacheCount:%2d \n", mCachedFrame.layerCount,
63 mCachedFrame.mdpCount, mCachedFrame.cacheCount);
64 dumpsys_log(buf,"CURR_FRAME: layerCount:%2d mdpCount:%2d \
65 fbCount:%2d \n", mCurrentFrame.layerCount,
66 mCurrentFrame.mdpCount, mCurrentFrame.fbCount);
67 dumpsys_log(buf,"needsFBRedraw:%3s pipesUsed:%2d MaxPipesPerMixer: %d \n",
68 (mCurrentFrame.needsRedraw? "YES" : "NO"),
69 mCurrentFrame.mdpCount, sMaxPipesPerMixer);
70 dumpsys_log(buf," --------------------------------------------- \n");
71 dumpsys_log(buf," listIdx | cached? | mdpIndex | comptype | Z \n");
72 dumpsys_log(buf," --------------------------------------------- \n");
73 for(int index = 0; index < mCurrentFrame.layerCount; index++ )
74 dumpsys_log(buf," %7d | %7s | %8d | %9s | %2d \n",
75 index,
76 (mCurrentFrame.isFBComposed[index] ? "YES" : "NO"),
77 mCurrentFrame.layerToMDP[index],
78 (mCurrentFrame.isFBComposed[index] ?
79 (mCurrentFrame.needsRedraw ? "GLES" : "CACHE") : "MDP"),
80 (mCurrentFrame.isFBComposed[index] ? mCurrentFrame.fbZ :
81 mCurrentFrame.mdpToLayer[mCurrentFrame.layerToMDP[index]].pipeInfo->zOrder));
82 dumpsys_log(buf,"\n");
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080083}
84
85bool MDPComp::init(hwc_context_t *ctx) {
86
87 if(!ctx) {
88 ALOGE("%s: Invalid hwc context!!",__FUNCTION__);
89 return false;
90 }
91
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080092 char property[PROPERTY_VALUE_MAX];
93
94 sEnabled = false;
95 if((property_get("persist.hwc.mdpcomp.enable", property, NULL) > 0) &&
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080096 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
97 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080098 sEnabled = true;
Xiaoming Zhou944e02e2013-05-01 20:54:03 -040099 if(!setupBasePipe(ctx)) {
100 ALOGE("%s: Failed to setup primary base pipe", __FUNCTION__);
101 return false;
102 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800103 }
104
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700105 sEnableMixedMode = true;
106 if((property_get("debug.mdpcomp.mixedmode.disable", property, NULL) > 0) &&
107 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
108 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
109 sEnableMixedMode = false;
110 }
111
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800112 sDebugLogs = false;
113 if(property_get("debug.mdpcomp.logs", property, NULL) > 0) {
114 if(atoi(property) != 0)
115 sDebugLogs = true;
116 }
117
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800118 sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
Saurabh Shah85234ec2013-04-12 17:09:00 -0700119 if(property_get("debug.mdpcomp.maxpermixer", property, "-1") > 0) {
120 int val = atoi(property);
121 if(val >= 0)
122 sMaxPipesPerMixer = min(val, MAX_PIPES_PER_MIXER);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800123 }
124
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400125 if(ctx->mMDP.panel != MIPI_CMD_PANEL) {
126 // Idle invalidation is not necessary on command mode panels
127 long idle_timeout = DEFAULT_IDLE_TIME;
128 if(property_get("debug.mdpcomp.idletime", property, NULL) > 0) {
129 if(atoi(property) != 0)
130 idle_timeout = atoi(property);
131 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800132
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400133 //create Idle Invalidator only when not disabled through property
134 if(idle_timeout != -1)
135 idleInvalidator = IdleInvalidator::getInstance();
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800136
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400137 if(idleInvalidator == NULL) {
138 ALOGE("%s: failed to instantiate idleInvalidator object",
139 __FUNCTION__);
140 } else {
141 idleInvalidator->init(timeout_handler, ctx, idle_timeout);
142 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800143 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700144 return true;
145}
146
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700147void MDPComp::reset(const int& numLayers, hwc_display_contents_1_t* list) {
148 mCurrentFrame.reset(numLayers);
149 mCachedFrame.cacheAll(list);
150 mCachedFrame.updateCounts(mCurrentFrame);
151}
152
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700153void MDPComp::timeout_handler(void *udata) {
154 struct hwc_context_t* ctx = (struct hwc_context_t*)(udata);
155
156 if(!ctx) {
157 ALOGE("%s: received empty data in timer callback", __FUNCTION__);
158 return;
159 }
160
Jesse Hall3be78d92012-08-21 15:12:23 -0700161 if(!ctx->proc) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700162 ALOGE("%s: HWC proc not registered", __FUNCTION__);
163 return;
164 }
165 sIdleFallBack = true;
166 /* Trigger SF to redraw the current frame */
Jesse Hall3be78d92012-08-21 15:12:23 -0700167 ctx->proc->invalidate(ctx->proc);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700168}
169
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800170void MDPComp::setMDPCompLayerFlags(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800171 hwc_display_contents_1_t* list) {
172 LayerProp *layerProp = ctx->layerProp[mDpy];
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800173
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800174 for(int index = 0; index < ctx->listStats[mDpy].numAppLayers; index++) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800175 hwc_layer_1_t* layer = &(list->hwLayers[index]);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800176 if(!mCurrentFrame.isFBComposed[index]) {
177 layerProp[index].mFlags |= HWC_MDPCOMP;
178 layer->compositionType = HWC_OVERLAY;
179 layer->hints |= HWC_HINT_CLEAR_FB;
180 mCachedFrame.hnd[index] = NULL;
181 } else {
182 if(!mCurrentFrame.needsRedraw)
183 layer->compositionType = HWC_OVERLAY;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800184 }
185 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700186}
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500187
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800188/*
189 * Sets up BORDERFILL as default base pipe and detaches RGB0.
190 * Framebuffer is always updated using PLAY ioctl.
191 */
192bool MDPComp::setupBasePipe(hwc_context_t *ctx) {
193 const int dpy = HWC_DISPLAY_PRIMARY;
194 int fb_stride = ctx->dpyAttr[dpy].stride;
195 int fb_width = ctx->dpyAttr[dpy].xres;
196 int fb_height = ctx->dpyAttr[dpy].yres;
197 int fb_fd = ctx->dpyAttr[dpy].fd;
198
199 mdp_overlay ovInfo;
200 msmfb_overlay_data ovData;
201 memset(&ovInfo, 0, sizeof(mdp_overlay));
202 memset(&ovData, 0, sizeof(msmfb_overlay_data));
203
204 ovInfo.src.format = MDP_RGB_BORDERFILL;
205 ovInfo.src.width = fb_width;
206 ovInfo.src.height = fb_height;
207 ovInfo.src_rect.w = fb_width;
208 ovInfo.src_rect.h = fb_height;
209 ovInfo.dst_rect.w = fb_width;
210 ovInfo.dst_rect.h = fb_height;
211 ovInfo.id = MSMFB_NEW_REQUEST;
212
213 if (ioctl(fb_fd, MSMFB_OVERLAY_SET, &ovInfo) < 0) {
214 ALOGE("Failed to call ioctl MSMFB_OVERLAY_SET err=%s",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800215 strerror(errno));
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800216 return false;
217 }
218
219 ovData.id = ovInfo.id;
220 if (ioctl(fb_fd, MSMFB_OVERLAY_PLAY, &ovData) < 0) {
221 ALOGE("Failed to call ioctl MSMFB_OVERLAY_PLAY err=%s",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800222 strerror(errno));
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800223 return false;
224 }
225 return true;
226}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800227MDPComp::FrameInfo::FrameInfo() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700228 reset(0);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800229}
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800230
Saurabh Shahaa236822013-04-24 18:07:26 -0700231void MDPComp::FrameInfo::reset(const int& numLayers) {
232 for(int i = 0 ; i < MAX_PIPES_PER_MIXER && numLayers; i++ ) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800233 if(mdpToLayer[i].pipeInfo) {
234 delete mdpToLayer[i].pipeInfo;
235 mdpToLayer[i].pipeInfo = NULL;
236 //We dont own the rotator
237 mdpToLayer[i].rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800238 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800239 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800240
241 memset(&mdpToLayer, 0, sizeof(mdpToLayer));
242 memset(&layerToMDP, -1, sizeof(layerToMDP));
Saurabh Shahaa236822013-04-24 18:07:26 -0700243 memset(&isFBComposed, 1, sizeof(isFBComposed));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800244
Saurabh Shahaa236822013-04-24 18:07:26 -0700245 layerCount = numLayers;
246 fbCount = numLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800247 mdpCount = 0;
Saurabh Shah2f3895f2013-05-02 10:13:31 -0700248 needsRedraw = true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800249 fbZ = 0;
250}
251
Saurabh Shahaa236822013-04-24 18:07:26 -0700252void MDPComp::FrameInfo::map() {
253 // populate layer and MDP maps
254 int mdpIdx = 0;
255 for(int idx = 0; idx < layerCount; idx++) {
256 if(!isFBComposed[idx]) {
257 mdpToLayer[mdpIdx].listIndex = idx;
258 layerToMDP[idx] = mdpIdx++;
259 }
260 }
261}
262
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800263MDPComp::LayerCache::LayerCache() {
264 reset();
265}
266
267void MDPComp::LayerCache::reset() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700268 memset(&hnd, 0, sizeof(hnd));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800269 mdpCount = 0;
270 cacheCount = 0;
271 layerCount = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -0700272 fbZ = -1;
273}
274
275void MDPComp::LayerCache::cacheAll(hwc_display_contents_1_t* list) {
276 const int numAppLayers = list->numHwLayers - 1;
277 for(int i = 0; i < numAppLayers; i++) {
278 hnd[i] = list->hwLayers[i].handle;
279 }
280}
281
282void MDPComp::LayerCache::updateCounts(const FrameInfo& curFrame) {
283 mdpCount = curFrame.mdpCount;
284 cacheCount = curFrame.fbCount;
285 layerCount = curFrame.layerCount;
286 fbZ = curFrame.fbZ;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800287}
288
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530289bool MDPComp::isValidDimension(hwc_context_t *ctx, hwc_layer_1_t *layer) {
Saurabh Shah4fdde762013-04-30 18:47:33 -0700290 const int dpy = HWC_DISPLAY_PRIMARY;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800291 private_handle_t *hnd = (private_handle_t *)layer->handle;
292
293 if(!hnd) {
294 ALOGE("%s: layer handle is NULL", __FUNCTION__);
295 return false;
296 }
297
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800298 int hw_w = ctx->dpyAttr[mDpy].xres;
299 int hw_h = ctx->dpyAttr[mDpy].yres;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800300
Saurabh Shah4fdde762013-04-30 18:47:33 -0700301 hwc_rect_t crop = layer->sourceCrop;
302 hwc_rect_t dst = layer->displayFrame;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800303
304 if(dst.left < 0 || dst.top < 0 || dst.right > hw_w || dst.bottom > hw_h) {
Saurabh Shah4fdde762013-04-30 18:47:33 -0700305 hwc_rect_t scissor = {0, 0, hw_w, hw_h };
306 qhwc::calculate_crop_rects(crop, dst, scissor, layer->transform);
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800307 }
308
Saurabh Shah4fdde762013-04-30 18:47:33 -0700309 int crop_w = crop.right - crop.left;
310 int crop_h = crop.bottom - crop.top;
311 int dst_w = dst.right - dst.left;
312 int dst_h = dst.bottom - dst.top;
313 float w_dscale = ceilf((float)crop_w / (float)dst_w);
314 float h_dscale = ceilf((float)crop_h / (float)dst_h);
315
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800316 /* Workaround for MDP HW limitation in DSI command mode panels where
317 * FPS will not go beyond 30 if buffers on RGB pipes are of width or height
318 * less than 5 pixels
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530319 * There also is a HW limilation in MDP, minimum block size is 2x2
320 * Fallback to GPU if height is less than 2.
321 */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800322 if((crop_w < 5)||(crop_h < 5))
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800323 return false;
324
Saurabh Shah4fdde762013-04-30 18:47:33 -0700325 const uint32_t downscale =
326 qdutils::MDPVersion::getInstance().getMaxMDPDownscale();
327 if(ctx->mMDP.version >= qdutils::MDSS_V5) {
328 /* Workaround for downscales larger than 4x.
329 * Will be removed once decimator block is enabled for MDSS
330 */
331 if(!qdutils::MDPVersion::getInstance().supportsDecimation()) {
332 if(crop_w > MAX_DISPLAY_DIM || w_dscale > downscale ||
333 h_dscale > downscale)
334 return false;
335 } else {
336 if(w_dscale > 64 || h_dscale > 64)
337 return false;
338 }
339 } else { //A-family
340 if(w_dscale > downscale || h_dscale > downscale)
341 return false;
342 }
343
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800344 return true;
345}
346
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700347ovutils::eDest MDPComp::getMdpPipe(hwc_context_t *ctx, ePipeType type,
348 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800349 overlay::Overlay& ov = *ctx->mOverlay;
350 ovutils::eDest mdp_pipe = ovutils::OV_INVALID;
351
352 switch(type) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800353 case MDPCOMP_OV_DMA:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700354 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_DMA, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800355 if(mdp_pipe != ovutils::OV_INVALID) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800356 return mdp_pipe;
357 }
358 case MDPCOMP_OV_ANY:
359 case MDPCOMP_OV_RGB:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700360 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800361 if(mdp_pipe != ovutils::OV_INVALID) {
362 return mdp_pipe;
363 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800364
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800365 if(type == MDPCOMP_OV_RGB) {
366 //Requested only for RGB pipe
367 break;
368 }
369 case MDPCOMP_OV_VG:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700370 return ov.nextPipe(ovutils::OV_MDP_PIPE_VG, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800371 default:
372 ALOGE("%s: Invalid pipe type",__FUNCTION__);
373 return ovutils::OV_INVALID;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800374 };
375 return ovutils::OV_INVALID;
376}
377
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800378bool MDPComp::isFrameDoable(hwc_context_t *ctx) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700379 bool ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700380 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800381
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800382 if(!isEnabled()) {
383 ALOGD_IF(isDebug(),"%s: MDP Comp. not enabled.", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700384 ret = false;
Saurabh Shahd4e65852013-06-17 11:33:53 -0700385 } else if(qdutils::MDPVersion::getInstance().is8x26() &&
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700386 ctx->mVideoTransFlag && ctx->mVirtualDisplay->isConnected()) {
Saurabh Shahd4e65852013-06-17 11:33:53 -0700387 //1 Padding round to shift pipes across mixers
388 ALOGD_IF(isDebug(),"%s: MDP Comp. video transition padding round",
389 __FUNCTION__);
390 ret = false;
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700391 } else if(ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isConfiguring ||
392 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isConfiguring) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800393 ALOGD_IF( isDebug(),"%s: External Display connection is pending",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800394 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700395 ret = false;
Saurabh Shahaa236822013-04-24 18:07:26 -0700396 } else if(ctx->isPaddingRound) {
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700397 ctx->isPaddingRound = false;
398 ALOGD_IF(isDebug(), "%s: padding round",__FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700399 ret = false;
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700400 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700401 return ret;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800402}
403
404/* Checks for conditions where all the layers marked for MDP comp cannot be
405 * bypassed. On such conditions we try to bypass atleast YUV layers */
406bool MDPComp::isFullFrameDoable(hwc_context_t *ctx,
407 hwc_display_contents_1_t* list){
408
Saurabh Shahaa236822013-04-24 18:07:26 -0700409 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800410
Saurabh Shah2d998a92013-05-14 17:55:58 -0700411 if(sIdleFallBack) {
412 ALOGD_IF(isDebug(), "%s: Idle fallback dpy %d",__FUNCTION__, mDpy);
413 return false;
414 }
415
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800416 if(mDpy > HWC_DISPLAY_PRIMARY){
417 ALOGD_IF(isDebug(), "%s: Cannot support External display(s)",
418 __FUNCTION__);
419 return false;
420 }
421
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800422 if(isSkipPresent(ctx, mDpy)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700423 ALOGD_IF(isDebug(),"%s: SKIP present: %d",
424 __FUNCTION__,
425 isSkipPresent(ctx, mDpy));
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800426 return false;
427 }
428
Saurabh Shah9f084ad2013-05-02 11:28:09 -0700429 if(ctx->listStats[mDpy].needsAlphaScale
430 && ctx->mMDP.version < qdutils::MDSS_V5) {
431 ALOGD_IF(isDebug(), "%s: frame needs alpha downscaling",__FUNCTION__);
432 return false;
433 }
434
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800435 //MDP composition is not efficient if layer needs rotator.
436 for(int i = 0; i < numAppLayers; ++i) {
437 // As MDP h/w supports flip operation, use MDP comp only for
438 // 180 transforms. Fail for any transform involving 90 (90, 270).
439 hwc_layer_1_t* layer = &list->hwLayers[i];
440 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800441
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700442 if(layer->transform & HWC_TRANSFORM_ROT_90) {
443 if(!isYuvBuffer(hnd) ) {
444 ALOGD_IF(isDebug(), "%s: orientation involved",__FUNCTION__);
445 return false;
446 }else if(!canUseRotator(ctx, mDpy)) {
447 ALOGD_IF(isDebug(), "%s: no free DMA pipe",__FUNCTION__);
448 return false;
449 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800450 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700451 if(!isValidDimension(ctx,layer)) {
452 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
453 __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800454 return false;
455 }
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530456
457 //For 8x26 with panel width>1k, if RGB layer needs HFLIP fail mdp comp
458 // may not need it if Gfx pre-rotation can handle all flips & rotations
459 if(qdutils::MDPVersion::getInstance().is8x26() &&
460 (ctx->dpyAttr[mDpy].xres > 1024) &&
461 (layer->transform & HWC_TRANSFORM_FLIP_H) &&
462 (!isYuvBuffer(hnd)))
463 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800464 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700465
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700466 if(ctx->mAD->isDoable()) {
467 return false;
468 }
469
Saurabh Shahaa236822013-04-24 18:07:26 -0700470 //If all above hard conditions are met we can do full or partial MDP comp.
471 bool ret = false;
472 if(fullMDPComp(ctx, list)) {
473 ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700474 } else if(partialMDPComp(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700475 ret = true;
476 }
477 return ret;
478}
479
480bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
481 //Setup mCurrentFrame
482 mCurrentFrame.mdpCount = mCurrentFrame.layerCount;
483 mCurrentFrame.fbCount = 0;
484 mCurrentFrame.fbZ = -1;
485 memset(&mCurrentFrame.isFBComposed, 0, sizeof(mCurrentFrame.isFBComposed));
486
487 int mdpCount = mCurrentFrame.mdpCount;
488 if(mdpCount > sMaxPipesPerMixer) {
489 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
490 return false;
491 }
492
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700493 if(!arePipesAvailable(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700494 return false;
495 }
496
497 return true;
498}
499
500bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
501{
502 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700503
504 if(!sEnableMixedMode) {
505 //Mixed mode is disabled. No need to even try caching.
506 return false;
507 }
508
Saurabh Shahaa236822013-04-24 18:07:26 -0700509 //Setup mCurrentFrame
510 mCurrentFrame.reset(numAppLayers);
511 updateLayerCache(ctx, list);
512 updateYUV(ctx, list);
513 batchLayers(); //sets up fbZ also
514
515 int mdpCount = mCurrentFrame.mdpCount;
516 if(mdpCount > (sMaxPipesPerMixer - 1)) { // -1 since FB is used
517 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
518 return false;
519 }
520
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700521 if(!arePipesAvailable(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700522 return false;
523 }
524
525 return true;
526}
527
528bool MDPComp::isOnlyVideoDoable(hwc_context_t *ctx,
529 hwc_display_contents_1_t* list){
530 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
531 mCurrentFrame.reset(numAppLayers);
532 updateYUV(ctx, list);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700533 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700534 int fbNeeded = int(mCurrentFrame.fbCount != 0);
535
536 if(!isYuvPresent(ctx, mDpy)) {
537 return false;
538 }
539
Saurabh Shah4fdde762013-04-30 18:47:33 -0700540 if(!mdpCount)
541 return false;
542
Saurabh Shahaa236822013-04-24 18:07:26 -0700543 if(mdpCount > (sMaxPipesPerMixer - fbNeeded)) {
544 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
545 return false;
546 }
547
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700548 if(!arePipesAvailable(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700549 return false;
550 }
551
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800552 return true;
553}
554
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800555/* Checks for conditions where YUV layers cannot be bypassed */
556bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Saurabh Shahe2474082013-05-15 16:32:13 -0700557 bool extAnimBlockFeature = mDpy && ctx->listStats[mDpy].isDisplayAnimating;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800558
Saurabh Shahe2474082013-05-15 16:32:13 -0700559 if(isSkipLayer(layer) && !extAnimBlockFeature) {
560 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800561 return false;
562 }
563
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700564 if(layer->transform & HWC_TRANSFORM_ROT_90 && !canUseRotator(ctx,mDpy)) {
565 ALOGD_IF(isDebug(), "%s: no free DMA pipe",__FUNCTION__);
566 return false;
567 }
568
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800569 if(isSecuring(ctx, layer)) {
570 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
571 return false;
572 }
573
Saurabh Shah4fdde762013-04-30 18:47:33 -0700574 if(!isValidDimension(ctx, layer)) {
575 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
576 __FUNCTION__);
577 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800578 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700579
Naseer Ahmeddc61a972013-07-10 17:50:54 -0400580 if(layer->planeAlpha < 0xFF) {
581 ALOGD_IF(isDebug(), "%s: Cannot handle YUV layer with plane alpha\
582 in video only mode",
583 __FUNCTION__);
584 return false;
585 }
586
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800587 return true;
588}
589
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800590void MDPComp::batchLayers() {
591 /* Idea is to keep as many contiguous non-updating(cached) layers in FB and
592 * send rest of them through MDP. NEVER mark an updating layer for caching.
593 * But cached ones can be marked for MDP*/
594
595 int maxBatchStart = -1;
596 int maxBatchCount = 0;
597
598 /* All or Nothing is cached. No batching needed */
Saurabh Shahaa236822013-04-24 18:07:26 -0700599 if(!mCurrentFrame.fbCount) {
600 mCurrentFrame.fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800601 return;
Saurabh Shahaa236822013-04-24 18:07:26 -0700602 }
603 if(!mCurrentFrame.mdpCount) {
604 mCurrentFrame.fbZ = 0;
605 return;
606 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800607
608 /* Search for max number of contiguous (cached) layers */
609 int i = 0;
610 while (i < mCurrentFrame.layerCount) {
611 int count = 0;
612 while(mCurrentFrame.isFBComposed[i] && i < mCurrentFrame.layerCount) {
613 count++; i++;
614 }
615 if(count > maxBatchCount) {
616 maxBatchCount = count;
617 maxBatchStart = i - count;
Saurabh Shahaa236822013-04-24 18:07:26 -0700618 mCurrentFrame.fbZ = maxBatchStart;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800619 }
620 if(i < mCurrentFrame.layerCount) i++;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800621 }
622
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800623 /* reset rest of the layers for MDP comp */
624 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
625 if(i != maxBatchStart){
626 mCurrentFrame.isFBComposed[i] = false;
627 } else {
628 i += maxBatchCount;
629 }
630 }
631
632 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700633 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
634 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800635
636 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
637 mCurrentFrame.fbCount);
638}
Saurabh Shah85234ec2013-04-12 17:09:00 -0700639
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800640void MDPComp::updateLayerCache(hwc_context_t* ctx,
641 hwc_display_contents_1_t* list) {
642
643 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
644 int numCacheableLayers = 0;
645
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800646 for(int i = 0; i < numAppLayers; i++) {
647 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
648 numCacheableLayers++;
649 mCurrentFrame.isFBComposed[i] = true;
650 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -0700651 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800652 mCachedFrame.hnd[i] = list->hwLayers[i].handle;
653 }
654 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700655
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800656 mCurrentFrame.fbCount = numCacheableLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700657 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
658 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800659 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__, numCacheableLayers);
660}
661
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800662void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list) {
663
664 int nYuvCount = ctx->listStats[mDpy].yuvCount;
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700665 if(!nYuvCount && mDpy) {
666 //Reset "No animation on external display" related parameters.
667 ctx->mPrevCropVideo.left = ctx->mPrevCropVideo.top =
668 ctx->mPrevCropVideo.right = ctx->mPrevCropVideo.bottom = 0;
669 ctx->mPrevDestVideo.left = ctx->mPrevDestVideo.top =
670 ctx->mPrevDestVideo.right = ctx->mPrevDestVideo.bottom = 0;
671 ctx->mPrevTransformVideo = 0;
672 return;
673 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800674 for(int index = 0;index < nYuvCount; index++){
675 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
676 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
677
678 if(!isYUVDoable(ctx, layer)) {
679 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
680 mCurrentFrame.isFBComposed[nYuvIndex] = true;
681 mCurrentFrame.fbCount++;
682 }
683 } else {
684 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
685 mCurrentFrame.isFBComposed[nYuvIndex] = false;
686 mCurrentFrame.fbCount--;
687 }
688 }
689 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700690
691 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
692 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800693 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
694 mCurrentFrame.fbCount);
695}
696
Saurabh Shahaa236822013-04-24 18:07:26 -0700697bool MDPComp::programMDP(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800698 if(!allocLayerPipes(ctx, list)) {
699 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700700 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800701 }
702
Saurabh Shahaa236822013-04-24 18:07:26 -0700703 bool fbBatch = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800704 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700705 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800706 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800707 int mdpIndex = mCurrentFrame.layerToMDP[index];
708 hwc_layer_1_t* layer = &list->hwLayers[index];
709
710 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
711 cur_pipe->zOrder = mdpNextZOrder++;
712
713 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
714 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
715 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -0700716 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800717 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700718 } else if(fbBatch == false) {
719 mdpNextZOrder++;
720 fbBatch = true;
721 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800722 }
723
Saurabh Shahaa236822013-04-24 18:07:26 -0700724 return true;
725}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800726
Saurabh Shahaa236822013-04-24 18:07:26 -0700727bool MDPComp::programYUV(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
728 if(!allocLayerPipes(ctx, list)) {
729 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
730 return false;
731 }
732 //If we are in this block, it means we have yuv + rgb layers both
733 int mdpIdx = 0;
734 for (int index = 0; index < mCurrentFrame.layerCount; index++) {
735 if(!mCurrentFrame.isFBComposed[index]) {
736 hwc_layer_1_t* layer = &list->hwLayers[index];
737 int mdpIndex = mCurrentFrame.layerToMDP[index];
738 MdpPipeInfo* cur_pipe =
739 mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
740 cur_pipe->zOrder = mdpIdx++;
741
742 if(configure(ctx, layer,
743 mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
744 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
745 layer %d",__FUNCTION__, index);
746 return false;
747 }
748 }
749 }
750 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800751}
752
753int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700754 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -0700755
Saurabh Shahb39f8152013-08-22 10:21:44 -0700756 //reset old data
757 mCurrentFrame.reset(numLayers);
Prabhanjan Kandula088bd892013-07-02 23:47:13 +0530758
Saurabh Shahb39f8152013-08-22 10:21:44 -0700759 //number of app layers exceeds MAX_NUM_APP_LAYERS fall back to GPU
760 //do not cache the information for next draw cycle.
761 if(numLayers > MAX_NUM_APP_LAYERS) {
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530762 mCachedFrame.updateCounts(mCurrentFrame);
Saurabh Shahb39f8152013-08-22 10:21:44 -0700763 ALOGD_IF(isDebug(), "%s: Number of App layers exceeded the limit ",
764 __FUNCTION__);
765 return -1;
766 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800767
Saurabh Shahb39f8152013-08-22 10:21:44 -0700768 //Hard conditions, if not met, cannot do MDP comp
769 if(!isFrameDoable(ctx)) {
770 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
771 __FUNCTION__);
772 reset(numLayers, list);
773 return -1;
774 }
775
776 //Check whether layers marked for MDP Composition is actually doable.
777 if(isFullFrameDoable(ctx, list)) {
778 mCurrentFrame.map();
779 //Configure framebuffer first if applicable
780 if(mCurrentFrame.fbZ >= 0) {
781 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list,
782 mCurrentFrame.fbZ)) {
783 ALOGE("%s configure framebuffer failed", __func__);
784 reset(numLayers, list);
785 return -1;
786 }
787 }
788 //Acquire and Program MDP pipes
789 if(!programMDP(ctx, list)) {
790 reset(numLayers, list);
791 return -1;
792 } else { //Success
793 //Any change in composition types needs an FB refresh
794 mCurrentFrame.needsRedraw = false;
795 if(mCurrentFrame.fbCount &&
796 ((mCurrentFrame.mdpCount != mCachedFrame.mdpCount) ||
797 (mCurrentFrame.fbCount != mCachedFrame.cacheCount) ||
798 (mCurrentFrame.fbZ != mCachedFrame.fbZ) ||
799 (!mCurrentFrame.mdpCount) ||
800 (list->flags & HWC_GEOMETRY_CHANGED) ||
801 isSkipPresent(ctx, mDpy) ||
802 (mDpy > HWC_DISPLAY_PRIMARY))) {
803 mCurrentFrame.needsRedraw = true;
804 }
805 }
806 } else if(isOnlyVideoDoable(ctx, list)) {
807 //All layers marked for MDP comp cannot be bypassed.
808 //Try to compose atleast YUV layers through MDP comp and let
809 //all the RGB layers compose in FB
810 //Destination over
811 mCurrentFrame.fbZ = -1;
812 if(mCurrentFrame.fbCount)
813 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
814
815 mCurrentFrame.map();
816
817 //Configure framebuffer first if applicable
818 if(mCurrentFrame.fbZ >= 0) {
819 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, mCurrentFrame.fbZ)) {
820 ALOGE("%s configure framebuffer failed", __func__);
821 reset(numLayers, list);
822 return -1;
823 }
824 }
825 if(!programYUV(ctx, list)) {
826 reset(numLayers, list);
827 return -1;
828 }
829 } else {
830 reset(numLayers, list);
831 return -1;
832 }
833
834 //UpdateLayerFlags
835 setMDPCompLayerFlags(ctx, list);
836 mCachedFrame.updateCounts(mCurrentFrame);
837
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530838 // unlock it before calling dump function to avoid deadlock
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800839 if(isDebug()) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700840 ALOGD("GEOMETRY change: %d", (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800841 android::String8 sDump("");
842 dump(sDump);
843 ALOGE("%s",sDump.string());
844 }
845
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700846 return 0;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800847}
848
849//=============MDPCompLowRes===================================================
850
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700851/*
852 * Configures pipe(s) for MDP composition
853 */
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800854int MDPCompLowRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800855 PipeLayerPair& PipeLayerPair) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800856 MdpPipeInfoLowRes& mdp_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800857 *(static_cast<MdpPipeInfoLowRes*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -0800858 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
859 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
860 eIsFg isFg = IS_FG_OFF;
861 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700862
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800863 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
864 __FUNCTION__, layer, zOrder, dest);
865
866 return configureLowRes(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
867 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700868}
869
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700870bool MDPCompLowRes::arePipesAvailable(hwc_context_t *ctx,
871 hwc_display_contents_1_t* list) {
872 overlay::Overlay& ov = *ctx->mOverlay;
873 int numPipesNeeded = mCurrentFrame.mdpCount;
874 int availPipes = ov.availablePipes(mDpy, Overlay::MIXER_DEFAULT);
875
876 //Reserve pipe for FB
877 if(mCurrentFrame.fbCount)
878 availPipes -= 1;
879
880 if(numPipesNeeded > availPipes) {
881 ALOGD_IF(isDebug(), "%s: Insufficient pipes, dpy %d needed %d, avail %d",
882 __FUNCTION__, mDpy, numPipesNeeded, availPipes);
883 return false;
884 }
885
886 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700887}
888
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800889bool MDPCompLowRes::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700890 hwc_display_contents_1_t* list) {
891 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700892
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800893 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700894
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800895 hwc_layer_1_t* layer = &list->hwLayers[index];
896 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800897 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800898 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800899 info.pipeInfo = new MdpPipeInfoLowRes;
Saurabh Shahacf10202013-02-26 10:15:15 -0800900 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800901 MdpPipeInfoLowRes& pipe_info = *(MdpPipeInfoLowRes*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800902 ePipeType type = MDPCOMP_OV_ANY;
903
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700904 if(isYuvBuffer(hnd)) {
905 type = MDPCOMP_OV_VG;
Saurabh Shah8a117932013-05-23 12:48:13 -0700906 } else if(!qhwc::needsScaling(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -0700907 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
908 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800909 type = MDPCOMP_OV_DMA;
910 }
911
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700912 pipe_info.index = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800913 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700914 ALOGD_IF(isDebug(), "%s: Unable to get pipe type = %d",
915 __FUNCTION__, (int) type);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500916 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700917 }
918 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700919 return true;
920}
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700921
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800922bool MDPCompLowRes::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700923
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800924 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500925 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
926 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800927 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700928
929 if(!ctx || !list) {
930 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500931 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700932 }
933
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +0530934 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
935 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
936 return true;
937 }
938
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500939 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -0700940 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500941 idleInvalidator->markForSleep();
942
943 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800944 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700945
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800946 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
947 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700948 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800949 if(mCurrentFrame.isFBComposed[i]) continue;
950
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700951 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -0800952 private_handle_t *hnd = (private_handle_t *)layer->handle;
953 if(!hnd) {
954 ALOGE("%s handle null", __FUNCTION__);
955 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700956 }
957
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800958 int mdpIndex = mCurrentFrame.layerToMDP[i];
959
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800960 MdpPipeInfoLowRes& pipe_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800961 *(MdpPipeInfoLowRes*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800962 ovutils::eDest dest = pipe_info.index;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800963 if(dest == ovutils::OV_INVALID) {
964 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500965 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700966 }
967
Saurabh Shahacf10202013-02-26 10:15:15 -0800968 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
969 continue;
970 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700971
Saurabh Shahacf10202013-02-26 10:15:15 -0800972 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800973 using pipe: %d", __FUNCTION__, layer,
974 hnd, dest );
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700975
Saurabh Shahacf10202013-02-26 10:15:15 -0800976 int fd = hnd->fd;
977 uint32_t offset = hnd->offset;
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700978
979 if(ctx->mAD->isModeOn()) {
980 if(ctx->mAD->draw(ctx, fd, offset)) {
981 fd = ctx->mAD->getDstFd(ctx);
982 offset = ctx->mAD->getDstOffset(ctx);
983 }
984 }
985
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800986 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -0800987 if(rot) {
988 if(!rot->queueBuffer(fd, offset))
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500989 return false;
Saurabh Shahacf10202013-02-26 10:15:15 -0800990 fd = rot->getDstMemId();
991 offset = rot->getDstOffset();
992 }
993
994 if (!ov.queueBuffer(fd, offset, dest)) {
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +0530995 ALOGE("%s: queueBuffer failed for display:%d ", __FUNCTION__, mDpy);
Saurabh Shahacf10202013-02-26 10:15:15 -0800996 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700997 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500998
999 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001000 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001001 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001002}
1003
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001004//=============MDPCompHighRes===================================================
1005
1006int MDPCompHighRes::pipesNeeded(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001007 hwc_display_contents_1_t* list,
1008 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001009 int pipesNeeded = 0;
Saurabh Shah67a38c32013-06-10 16:23:15 -07001010 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001011
1012 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001013
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001014 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1015 if(!mCurrentFrame.isFBComposed[i]) {
1016 hwc_layer_1_t* layer = &list->hwLayers[i];
1017 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001018 if(mixer == Overlay::MIXER_LEFT && dst.left < lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001019 pipesNeeded++;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001020 } else if(mixer == Overlay::MIXER_RIGHT && dst.right > lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001021 pipesNeeded++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001022 }
1023 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001024 }
1025 return pipesNeeded;
1026}
1027
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001028bool MDPCompHighRes::arePipesAvailable(hwc_context_t *ctx,
1029 hwc_display_contents_1_t* list) {
1030 overlay::Overlay& ov = *ctx->mOverlay;
1031
1032 for(int i = 0; i < Overlay::MIXER_MAX; i++) {
1033 int numPipesNeeded = pipesNeeded(ctx, list, i);
1034 int availPipes = ov.availablePipes(mDpy, i);
1035
1036 //Reserve pipe(s)for FB
1037 if(mCurrentFrame.fbCount)
1038 availPipes -= 1;
1039
1040 if(numPipesNeeded > availPipes) {
1041 ALOGD_IF(isDebug(), "%s: Insufficient pipes for "
1042 "dpy %d mixer %d needed %d, avail %d",
1043 __FUNCTION__, mDpy, i, numPipesNeeded, availPipes);
1044 return false;
1045 }
1046 }
1047 return true;
1048}
1049
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001050bool MDPCompHighRes::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001051 MdpPipeInfoHighRes& pipe_info,
1052 ePipeType type) {
1053 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001054 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001055
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001056 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001057 pipe_info.lIndex = ovutils::OV_INVALID;
1058 pipe_info.rIndex = ovutils::OV_INVALID;
1059
1060 if (dst.left < lSplit) {
1061 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_LEFT);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001062 if(pipe_info.lIndex == ovutils::OV_INVALID)
1063 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001064 }
1065
1066 if(dst.right > lSplit) {
1067 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_RIGHT);
1068 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001069 return false;
1070 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001071
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001072 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001073}
1074
1075bool MDPCompHighRes::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001076 hwc_display_contents_1_t* list) {
1077 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001078
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001079 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001080
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001081 hwc_layer_1_t* layer = &list->hwLayers[index];
1082 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001083 int mdpIndex = mCurrentFrame.layerToMDP[index];
1084 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001085 info.pipeInfo = new MdpPipeInfoHighRes;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001086 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001087 MdpPipeInfoHighRes& pipe_info = *(MdpPipeInfoHighRes*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001088 ePipeType type = MDPCOMP_OV_ANY;
1089
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001090 if(isYuvBuffer(hnd)) {
1091 type = MDPCOMP_OV_VG;
Saurabh Shah8a117932013-05-23 12:48:13 -07001092 } else if(!qhwc::needsScaling(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001093 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001094 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001095 type = MDPCOMP_OV_DMA;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001096 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001097
1098 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001099 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type = %d",
1100 __FUNCTION__, (int) type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001101 return false;
1102 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001103 }
1104 return true;
1105}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001106
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001107/*
1108 * Configures pipe(s) for MDP composition
1109 */
1110int MDPCompHighRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001111 PipeLayerPair& PipeLayerPair) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001112 MdpPipeInfoHighRes& mdp_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001113 *(static_cast<MdpPipeInfoHighRes*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001114 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1115 eIsFg isFg = IS_FG_OFF;
1116 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1117 eDest lDest = mdp_info.lIndex;
1118 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001119
1120 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1121 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1122
1123 return configureHighRes(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
1124 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001125}
1126
1127bool MDPCompHighRes::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
1128
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001129 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001130 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1131 return true;
1132 }
1133
1134 if(!ctx || !list) {
1135 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001136 return false;
1137 }
1138
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301139 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1140 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1141 return true;
1142 }
1143
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001144 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001145 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001146 idleInvalidator->markForSleep();
1147
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001148 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001149 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001150
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001151 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1152 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001153 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001154 if(mCurrentFrame.isFBComposed[i]) continue;
1155
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001156 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001157 private_handle_t *hnd = (private_handle_t *)layer->handle;
1158 if(!hnd) {
1159 ALOGE("%s handle null", __FUNCTION__);
1160 return false;
1161 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001162
1163 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1164 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001165 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001166
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001167 int mdpIndex = mCurrentFrame.layerToMDP[i];
1168
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001169 MdpPipeInfoHighRes& pipe_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001170 *(MdpPipeInfoHighRes*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1171 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -08001172
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001173 ovutils::eDest indexL = pipe_info.lIndex;
1174 ovutils::eDest indexR = pipe_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001175
Saurabh Shahacf10202013-02-26 10:15:15 -08001176 int fd = hnd->fd;
1177 int offset = hnd->offset;
1178
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001179 if(ctx->mAD->isModeOn()) {
1180 if(ctx->mAD->draw(ctx, fd, offset)) {
1181 fd = ctx->mAD->getDstFd(ctx);
1182 offset = ctx->mAD->getDstOffset(ctx);
1183 }
1184 }
1185
Saurabh Shahacf10202013-02-26 10:15:15 -08001186 if(rot) {
1187 rot->queueBuffer(fd, offset);
1188 fd = rot->getDstMemId();
1189 offset = rot->getDstOffset();
1190 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001191
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001192 //************* play left mixer **********
1193 if(indexL != ovutils::OV_INVALID) {
1194 ovutils::eDest destL = (ovutils::eDest)indexL;
Saurabh Shahacf10202013-02-26 10:15:15 -08001195 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001196 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
Saurabh Shahacf10202013-02-26 10:15:15 -08001197 if (!ov.queueBuffer(fd, offset, destL)) {
1198 ALOGE("%s: queueBuffer failed for left mixer", __FUNCTION__);
1199 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001200 }
1201 }
1202
1203 //************* play right mixer **********
1204 if(indexR != ovutils::OV_INVALID) {
1205 ovutils::eDest destR = (ovutils::eDest)indexR;
Saurabh Shahacf10202013-02-26 10:15:15 -08001206 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001207 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
Saurabh Shahacf10202013-02-26 10:15:15 -08001208 if (!ov.queueBuffer(fd, offset, destR)) {
1209 ALOGE("%s: queueBuffer failed for right mixer", __FUNCTION__);
1210 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001211 }
1212 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001213
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001214 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1215 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001216
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001217 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001218}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001219}; //namespace
1220