blob: 81ccfedb1086364dad5cb991bd2191df0b8992ad [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
Saurabh Shah4fdde762013-04-30 18:47:33 -0700442 if((layer->transform & HWC_TRANSFORM_ROT_90) && !isYuvBuffer(hnd)) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800443 ALOGD_IF(isDebug(), "%s: orientation involved",__FUNCTION__);
444 return false;
445 }
446
Saurabh Shah4fdde762013-04-30 18:47:33 -0700447 if(!isValidDimension(ctx,layer)) {
448 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
449 __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800450 return false;
451 }
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530452
453 //For 8x26 with panel width>1k, if RGB layer needs HFLIP fail mdp comp
454 // may not need it if Gfx pre-rotation can handle all flips & rotations
455 if(qdutils::MDPVersion::getInstance().is8x26() &&
456 (ctx->dpyAttr[mDpy].xres > 1024) &&
457 (layer->transform & HWC_TRANSFORM_FLIP_H) &&
458 (!isYuvBuffer(hnd)))
459 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800460 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700461
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700462 if(ctx->mAD->isDoable()) {
463 return false;
464 }
465
Saurabh Shahaa236822013-04-24 18:07:26 -0700466 //If all above hard conditions are met we can do full or partial MDP comp.
467 bool ret = false;
468 if(fullMDPComp(ctx, list)) {
469 ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700470 } else if(partialMDPComp(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700471 ret = true;
472 }
473 return ret;
474}
475
476bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
477 //Setup mCurrentFrame
478 mCurrentFrame.mdpCount = mCurrentFrame.layerCount;
479 mCurrentFrame.fbCount = 0;
480 mCurrentFrame.fbZ = -1;
481 memset(&mCurrentFrame.isFBComposed, 0, sizeof(mCurrentFrame.isFBComposed));
482
483 int mdpCount = mCurrentFrame.mdpCount;
484 if(mdpCount > sMaxPipesPerMixer) {
485 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
486 return false;
487 }
488
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700489 if(!arePipesAvailable(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700490 return false;
491 }
492
493 return true;
494}
495
496bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
497{
498 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700499
500 if(!sEnableMixedMode) {
501 //Mixed mode is disabled. No need to even try caching.
502 return false;
503 }
504
Saurabh Shahaa236822013-04-24 18:07:26 -0700505 //Setup mCurrentFrame
506 mCurrentFrame.reset(numAppLayers);
507 updateLayerCache(ctx, list);
508 updateYUV(ctx, list);
509 batchLayers(); //sets up fbZ also
510
511 int mdpCount = mCurrentFrame.mdpCount;
512 if(mdpCount > (sMaxPipesPerMixer - 1)) { // -1 since FB is used
513 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
514 return false;
515 }
516
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700517 if(!arePipesAvailable(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700518 return false;
519 }
520
521 return true;
522}
523
524bool MDPComp::isOnlyVideoDoable(hwc_context_t *ctx,
525 hwc_display_contents_1_t* list){
526 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
527 mCurrentFrame.reset(numAppLayers);
528 updateYUV(ctx, list);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700529 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700530 int fbNeeded = int(mCurrentFrame.fbCount != 0);
531
532 if(!isYuvPresent(ctx, mDpy)) {
533 return false;
534 }
535
Saurabh Shah4fdde762013-04-30 18:47:33 -0700536 if(!mdpCount)
537 return false;
538
Saurabh Shahaa236822013-04-24 18:07:26 -0700539 if(mdpCount > (sMaxPipesPerMixer - fbNeeded)) {
540 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
541 return false;
542 }
543
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700544 if(!arePipesAvailable(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700545 return false;
546 }
547
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800548 return true;
549}
550
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800551/* Checks for conditions where YUV layers cannot be bypassed */
552bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Saurabh Shahe2474082013-05-15 16:32:13 -0700553 bool extAnimBlockFeature = mDpy && ctx->listStats[mDpy].isDisplayAnimating;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800554
Saurabh Shahe2474082013-05-15 16:32:13 -0700555 if(isSkipLayer(layer) && !extAnimBlockFeature) {
556 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800557 return false;
558 }
559
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800560 if(isSecuring(ctx, layer)) {
561 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
562 return false;
563 }
564
Saurabh Shah4fdde762013-04-30 18:47:33 -0700565 if(!isValidDimension(ctx, layer)) {
566 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
567 __FUNCTION__);
568 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800569 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700570
Naseer Ahmeddc61a972013-07-10 17:50:54 -0400571 if(layer->planeAlpha < 0xFF) {
572 ALOGD_IF(isDebug(), "%s: Cannot handle YUV layer with plane alpha\
573 in video only mode",
574 __FUNCTION__);
575 return false;
576 }
577
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800578 return true;
579}
580
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800581void MDPComp::batchLayers() {
582 /* Idea is to keep as many contiguous non-updating(cached) layers in FB and
583 * send rest of them through MDP. NEVER mark an updating layer for caching.
584 * But cached ones can be marked for MDP*/
585
586 int maxBatchStart = -1;
587 int maxBatchCount = 0;
588
589 /* All or Nothing is cached. No batching needed */
Saurabh Shahaa236822013-04-24 18:07:26 -0700590 if(!mCurrentFrame.fbCount) {
591 mCurrentFrame.fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800592 return;
Saurabh Shahaa236822013-04-24 18:07:26 -0700593 }
594 if(!mCurrentFrame.mdpCount) {
595 mCurrentFrame.fbZ = 0;
596 return;
597 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800598
599 /* Search for max number of contiguous (cached) layers */
600 int i = 0;
601 while (i < mCurrentFrame.layerCount) {
602 int count = 0;
603 while(mCurrentFrame.isFBComposed[i] && i < mCurrentFrame.layerCount) {
604 count++; i++;
605 }
606 if(count > maxBatchCount) {
607 maxBatchCount = count;
608 maxBatchStart = i - count;
Saurabh Shahaa236822013-04-24 18:07:26 -0700609 mCurrentFrame.fbZ = maxBatchStart;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800610 }
611 if(i < mCurrentFrame.layerCount) i++;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800612 }
613
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800614 /* reset rest of the layers for MDP comp */
615 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
616 if(i != maxBatchStart){
617 mCurrentFrame.isFBComposed[i] = false;
618 } else {
619 i += maxBatchCount;
620 }
621 }
622
623 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700624 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
625 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800626
627 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
628 mCurrentFrame.fbCount);
629}
Saurabh Shah85234ec2013-04-12 17:09:00 -0700630
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800631void MDPComp::updateLayerCache(hwc_context_t* ctx,
632 hwc_display_contents_1_t* list) {
633
634 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
635 int numCacheableLayers = 0;
636
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800637 for(int i = 0; i < numAppLayers; i++) {
638 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
639 numCacheableLayers++;
640 mCurrentFrame.isFBComposed[i] = true;
641 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -0700642 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800643 mCachedFrame.hnd[i] = list->hwLayers[i].handle;
644 }
645 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700646
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800647 mCurrentFrame.fbCount = numCacheableLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700648 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
649 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800650 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__, numCacheableLayers);
651}
652
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800653void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list) {
654
655 int nYuvCount = ctx->listStats[mDpy].yuvCount;
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700656 if(!nYuvCount && mDpy) {
657 //Reset "No animation on external display" related parameters.
658 ctx->mPrevCropVideo.left = ctx->mPrevCropVideo.top =
659 ctx->mPrevCropVideo.right = ctx->mPrevCropVideo.bottom = 0;
660 ctx->mPrevDestVideo.left = ctx->mPrevDestVideo.top =
661 ctx->mPrevDestVideo.right = ctx->mPrevDestVideo.bottom = 0;
662 ctx->mPrevTransformVideo = 0;
663 return;
664 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800665 for(int index = 0;index < nYuvCount; index++){
666 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
667 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
668
669 if(!isYUVDoable(ctx, layer)) {
670 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
671 mCurrentFrame.isFBComposed[nYuvIndex] = true;
672 mCurrentFrame.fbCount++;
673 }
674 } else {
675 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
676 mCurrentFrame.isFBComposed[nYuvIndex] = false;
677 mCurrentFrame.fbCount--;
678 }
679 }
680 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700681
682 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
683 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800684 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
685 mCurrentFrame.fbCount);
686}
687
Saurabh Shahaa236822013-04-24 18:07:26 -0700688bool MDPComp::programMDP(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800689 if(!allocLayerPipes(ctx, list)) {
690 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700691 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800692 }
693
Saurabh Shahaa236822013-04-24 18:07:26 -0700694 bool fbBatch = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800695 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700696 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800697 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800698 int mdpIndex = mCurrentFrame.layerToMDP[index];
699 hwc_layer_1_t* layer = &list->hwLayers[index];
700
701 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
702 cur_pipe->zOrder = mdpNextZOrder++;
703
704 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
705 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
706 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -0700707 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800708 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700709 } else if(fbBatch == false) {
710 mdpNextZOrder++;
711 fbBatch = true;
712 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800713 }
714
Saurabh Shahaa236822013-04-24 18:07:26 -0700715 return true;
716}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800717
Saurabh Shahaa236822013-04-24 18:07:26 -0700718bool MDPComp::programYUV(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
719 if(!allocLayerPipes(ctx, list)) {
720 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
721 return false;
722 }
723 //If we are in this block, it means we have yuv + rgb layers both
724 int mdpIdx = 0;
725 for (int index = 0; index < mCurrentFrame.layerCount; index++) {
726 if(!mCurrentFrame.isFBComposed[index]) {
727 hwc_layer_1_t* layer = &list->hwLayers[index];
728 int mdpIndex = mCurrentFrame.layerToMDP[index];
729 MdpPipeInfo* cur_pipe =
730 mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
731 cur_pipe->zOrder = mdpIdx++;
732
733 if(configure(ctx, layer,
734 mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
735 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
736 layer %d",__FUNCTION__, index);
737 return false;
738 }
739 }
740 }
741 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800742}
743
744int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700745 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -0700746
Saurabh Shahb39f8152013-08-22 10:21:44 -0700747 //reset old data
748 mCurrentFrame.reset(numLayers);
Prabhanjan Kandula088bd892013-07-02 23:47:13 +0530749
Saurabh Shahb39f8152013-08-22 10:21:44 -0700750 //number of app layers exceeds MAX_NUM_APP_LAYERS fall back to GPU
751 //do not cache the information for next draw cycle.
752 if(numLayers > MAX_NUM_APP_LAYERS) {
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530753 mCachedFrame.updateCounts(mCurrentFrame);
Saurabh Shahb39f8152013-08-22 10:21:44 -0700754 ALOGD_IF(isDebug(), "%s: Number of App layers exceeded the limit ",
755 __FUNCTION__);
756 return -1;
757 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800758
Saurabh Shahb39f8152013-08-22 10:21:44 -0700759 //Hard conditions, if not met, cannot do MDP comp
760 if(!isFrameDoable(ctx)) {
761 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
762 __FUNCTION__);
763 reset(numLayers, list);
764 return -1;
765 }
766
767 //Check whether layers marked for MDP Composition is actually doable.
768 if(isFullFrameDoable(ctx, list)) {
769 mCurrentFrame.map();
770 //Configure framebuffer first if applicable
771 if(mCurrentFrame.fbZ >= 0) {
772 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list,
773 mCurrentFrame.fbZ)) {
774 ALOGE("%s configure framebuffer failed", __func__);
775 reset(numLayers, list);
776 return -1;
777 }
778 }
779 //Acquire and Program MDP pipes
780 if(!programMDP(ctx, list)) {
781 reset(numLayers, list);
782 return -1;
783 } else { //Success
784 //Any change in composition types needs an FB refresh
785 mCurrentFrame.needsRedraw = false;
786 if(mCurrentFrame.fbCount &&
787 ((mCurrentFrame.mdpCount != mCachedFrame.mdpCount) ||
788 (mCurrentFrame.fbCount != mCachedFrame.cacheCount) ||
789 (mCurrentFrame.fbZ != mCachedFrame.fbZ) ||
790 (!mCurrentFrame.mdpCount) ||
791 (list->flags & HWC_GEOMETRY_CHANGED) ||
792 isSkipPresent(ctx, mDpy) ||
793 (mDpy > HWC_DISPLAY_PRIMARY))) {
794 mCurrentFrame.needsRedraw = true;
795 }
796 }
797 } else if(isOnlyVideoDoable(ctx, list)) {
798 //All layers marked for MDP comp cannot be bypassed.
799 //Try to compose atleast YUV layers through MDP comp and let
800 //all the RGB layers compose in FB
801 //Destination over
802 mCurrentFrame.fbZ = -1;
803 if(mCurrentFrame.fbCount)
804 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
805
806 mCurrentFrame.map();
807
808 //Configure framebuffer first if applicable
809 if(mCurrentFrame.fbZ >= 0) {
810 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, mCurrentFrame.fbZ)) {
811 ALOGE("%s configure framebuffer failed", __func__);
812 reset(numLayers, list);
813 return -1;
814 }
815 }
816 if(!programYUV(ctx, list)) {
817 reset(numLayers, list);
818 return -1;
819 }
820 } else {
821 reset(numLayers, list);
822 return -1;
823 }
824
825 //UpdateLayerFlags
826 setMDPCompLayerFlags(ctx, list);
827 mCachedFrame.updateCounts(mCurrentFrame);
828
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530829 // unlock it before calling dump function to avoid deadlock
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800830 if(isDebug()) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700831 ALOGD("GEOMETRY change: %d", (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800832 android::String8 sDump("");
833 dump(sDump);
834 ALOGE("%s",sDump.string());
835 }
836
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700837 return 0;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800838}
839
840//=============MDPCompLowRes===================================================
841
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700842/*
843 * Configures pipe(s) for MDP composition
844 */
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800845int MDPCompLowRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800846 PipeLayerPair& PipeLayerPair) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800847 MdpPipeInfoLowRes& mdp_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800848 *(static_cast<MdpPipeInfoLowRes*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -0800849 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
850 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
851 eIsFg isFg = IS_FG_OFF;
852 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700853
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800854 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
855 __FUNCTION__, layer, zOrder, dest);
856
857 return configureLowRes(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
858 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700859}
860
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700861bool MDPCompLowRes::arePipesAvailable(hwc_context_t *ctx,
862 hwc_display_contents_1_t* list) {
863 overlay::Overlay& ov = *ctx->mOverlay;
864 int numPipesNeeded = mCurrentFrame.mdpCount;
865 int availPipes = ov.availablePipes(mDpy, Overlay::MIXER_DEFAULT);
866
867 //Reserve pipe for FB
868 if(mCurrentFrame.fbCount)
869 availPipes -= 1;
870
871 if(numPipesNeeded > availPipes) {
872 ALOGD_IF(isDebug(), "%s: Insufficient pipes, dpy %d needed %d, avail %d",
873 __FUNCTION__, mDpy, numPipesNeeded, availPipes);
874 return false;
875 }
876
877 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700878}
879
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800880bool MDPCompLowRes::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700881 hwc_display_contents_1_t* list) {
882 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700883
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800884 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700885
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800886 hwc_layer_1_t* layer = &list->hwLayers[index];
887 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800888 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800889 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800890 info.pipeInfo = new MdpPipeInfoLowRes;
Saurabh Shahacf10202013-02-26 10:15:15 -0800891 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800892 MdpPipeInfoLowRes& pipe_info = *(MdpPipeInfoLowRes*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800893 ePipeType type = MDPCOMP_OV_ANY;
894
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700895 if(isYuvBuffer(hnd)) {
896 type = MDPCOMP_OV_VG;
Saurabh Shah8a117932013-05-23 12:48:13 -0700897 } else if(!qhwc::needsScaling(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -0700898 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
899 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800900 type = MDPCOMP_OV_DMA;
901 }
902
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700903 pipe_info.index = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800904 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700905 ALOGD_IF(isDebug(), "%s: Unable to get pipe type = %d",
906 __FUNCTION__, (int) type);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500907 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700908 }
909 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700910 return true;
911}
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700912
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800913bool MDPCompLowRes::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700914
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800915 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500916 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
917 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800918 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700919
920 if(!ctx || !list) {
921 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500922 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700923 }
924
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +0530925 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
926 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
927 return true;
928 }
929
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500930 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -0700931 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500932 idleInvalidator->markForSleep();
933
934 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800935 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700936
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800937 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
938 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700939 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800940 if(mCurrentFrame.isFBComposed[i]) continue;
941
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700942 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -0800943 private_handle_t *hnd = (private_handle_t *)layer->handle;
944 if(!hnd) {
945 ALOGE("%s handle null", __FUNCTION__);
946 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700947 }
948
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800949 int mdpIndex = mCurrentFrame.layerToMDP[i];
950
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800951 MdpPipeInfoLowRes& pipe_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800952 *(MdpPipeInfoLowRes*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800953 ovutils::eDest dest = pipe_info.index;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800954 if(dest == ovutils::OV_INVALID) {
955 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500956 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700957 }
958
Saurabh Shahacf10202013-02-26 10:15:15 -0800959 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
960 continue;
961 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700962
Saurabh Shahacf10202013-02-26 10:15:15 -0800963 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800964 using pipe: %d", __FUNCTION__, layer,
965 hnd, dest );
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700966
Saurabh Shahacf10202013-02-26 10:15:15 -0800967 int fd = hnd->fd;
968 uint32_t offset = hnd->offset;
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700969
970 if(ctx->mAD->isModeOn()) {
971 if(ctx->mAD->draw(ctx, fd, offset)) {
972 fd = ctx->mAD->getDstFd(ctx);
973 offset = ctx->mAD->getDstOffset(ctx);
974 }
975 }
976
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800977 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -0800978 if(rot) {
979 if(!rot->queueBuffer(fd, offset))
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500980 return false;
Saurabh Shahacf10202013-02-26 10:15:15 -0800981 fd = rot->getDstMemId();
982 offset = rot->getDstOffset();
983 }
984
985 if (!ov.queueBuffer(fd, offset, dest)) {
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +0530986 ALOGE("%s: queueBuffer failed for display:%d ", __FUNCTION__, mDpy);
Saurabh Shahacf10202013-02-26 10:15:15 -0800987 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700988 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500989
990 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700991 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500992 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700993}
994
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800995//=============MDPCompHighRes===================================================
996
997int MDPCompHighRes::pipesNeeded(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700998 hwc_display_contents_1_t* list,
999 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001000 int pipesNeeded = 0;
Saurabh Shah67a38c32013-06-10 16:23:15 -07001001 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001002
1003 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001004
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001005 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1006 if(!mCurrentFrame.isFBComposed[i]) {
1007 hwc_layer_1_t* layer = &list->hwLayers[i];
1008 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001009 if(mixer == Overlay::MIXER_LEFT && dst.left < lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001010 pipesNeeded++;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001011 } else if(mixer == Overlay::MIXER_RIGHT && dst.right > lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001012 pipesNeeded++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001013 }
1014 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001015 }
1016 return pipesNeeded;
1017}
1018
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001019bool MDPCompHighRes::arePipesAvailable(hwc_context_t *ctx,
1020 hwc_display_contents_1_t* list) {
1021 overlay::Overlay& ov = *ctx->mOverlay;
1022
1023 for(int i = 0; i < Overlay::MIXER_MAX; i++) {
1024 int numPipesNeeded = pipesNeeded(ctx, list, i);
1025 int availPipes = ov.availablePipes(mDpy, i);
1026
1027 //Reserve pipe(s)for FB
1028 if(mCurrentFrame.fbCount)
1029 availPipes -= 1;
1030
1031 if(numPipesNeeded > availPipes) {
1032 ALOGD_IF(isDebug(), "%s: Insufficient pipes for "
1033 "dpy %d mixer %d needed %d, avail %d",
1034 __FUNCTION__, mDpy, i, numPipesNeeded, availPipes);
1035 return false;
1036 }
1037 }
1038 return true;
1039}
1040
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001041bool MDPCompHighRes::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001042 MdpPipeInfoHighRes& pipe_info,
1043 ePipeType type) {
1044 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001045 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001046
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001047 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001048 pipe_info.lIndex = ovutils::OV_INVALID;
1049 pipe_info.rIndex = ovutils::OV_INVALID;
1050
1051 if (dst.left < lSplit) {
1052 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_LEFT);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001053 if(pipe_info.lIndex == ovutils::OV_INVALID)
1054 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001055 }
1056
1057 if(dst.right > lSplit) {
1058 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_RIGHT);
1059 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001060 return false;
1061 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001062
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001063 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001064}
1065
1066bool MDPCompHighRes::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001067 hwc_display_contents_1_t* list) {
1068 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001069
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001070 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001071
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001072 hwc_layer_1_t* layer = &list->hwLayers[index];
1073 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001074 int mdpIndex = mCurrentFrame.layerToMDP[index];
1075 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001076 info.pipeInfo = new MdpPipeInfoHighRes;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001077 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001078 MdpPipeInfoHighRes& pipe_info = *(MdpPipeInfoHighRes*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001079 ePipeType type = MDPCOMP_OV_ANY;
1080
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001081 if(isYuvBuffer(hnd)) {
1082 type = MDPCOMP_OV_VG;
Saurabh Shah8a117932013-05-23 12:48:13 -07001083 } else if(!qhwc::needsScaling(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001084 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001085 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001086 type = MDPCOMP_OV_DMA;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001087 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001088
1089 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001090 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type = %d",
1091 __FUNCTION__, (int) type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001092 return false;
1093 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001094 }
1095 return true;
1096}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001097
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001098/*
1099 * Configures pipe(s) for MDP composition
1100 */
1101int MDPCompHighRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001102 PipeLayerPair& PipeLayerPair) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001103 MdpPipeInfoHighRes& mdp_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001104 *(static_cast<MdpPipeInfoHighRes*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001105 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1106 eIsFg isFg = IS_FG_OFF;
1107 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1108 eDest lDest = mdp_info.lIndex;
1109 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001110
1111 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1112 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1113
1114 return configureHighRes(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
1115 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001116}
1117
1118bool MDPCompHighRes::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
1119
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001120 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001121 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1122 return true;
1123 }
1124
1125 if(!ctx || !list) {
1126 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001127 return false;
1128 }
1129
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301130 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1131 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1132 return true;
1133 }
1134
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001135 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001136 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001137 idleInvalidator->markForSleep();
1138
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001139 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001140 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001141
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001142 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1143 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001144 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001145 if(mCurrentFrame.isFBComposed[i]) continue;
1146
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001147 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001148 private_handle_t *hnd = (private_handle_t *)layer->handle;
1149 if(!hnd) {
1150 ALOGE("%s handle null", __FUNCTION__);
1151 return false;
1152 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001153
1154 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1155 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001156 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001157
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001158 int mdpIndex = mCurrentFrame.layerToMDP[i];
1159
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001160 MdpPipeInfoHighRes& pipe_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001161 *(MdpPipeInfoHighRes*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1162 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -08001163
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001164 ovutils::eDest indexL = pipe_info.lIndex;
1165 ovutils::eDest indexR = pipe_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001166
Saurabh Shahacf10202013-02-26 10:15:15 -08001167 int fd = hnd->fd;
1168 int offset = hnd->offset;
1169
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001170 if(ctx->mAD->isModeOn()) {
1171 if(ctx->mAD->draw(ctx, fd, offset)) {
1172 fd = ctx->mAD->getDstFd(ctx);
1173 offset = ctx->mAD->getDstOffset(ctx);
1174 }
1175 }
1176
Saurabh Shahacf10202013-02-26 10:15:15 -08001177 if(rot) {
1178 rot->queueBuffer(fd, offset);
1179 fd = rot->getDstMemId();
1180 offset = rot->getDstOffset();
1181 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001182
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001183 //************* play left mixer **********
1184 if(indexL != ovutils::OV_INVALID) {
1185 ovutils::eDest destL = (ovutils::eDest)indexL;
Saurabh Shahacf10202013-02-26 10:15:15 -08001186 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001187 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
Saurabh Shahacf10202013-02-26 10:15:15 -08001188 if (!ov.queueBuffer(fd, offset, destL)) {
1189 ALOGE("%s: queueBuffer failed for left mixer", __FUNCTION__);
1190 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001191 }
1192 }
1193
1194 //************* play right mixer **********
1195 if(indexR != ovutils::OV_INVALID) {
1196 ovutils::eDest destR = (ovutils::eDest)indexR;
Saurabh Shahacf10202013-02-26 10:15:15 -08001197 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001198 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
Saurabh Shahacf10202013-02-26 10:15:15 -08001199 if (!ov.queueBuffer(fd, offset, destR)) {
1200 ALOGE("%s: queueBuffer failed for right mixer", __FUNCTION__);
1201 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001202 }
1203 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001204
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001205 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1206 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001207
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001208 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001209}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001210}; //namespace
1211