blob: 1d75a9c78726e5b99f34d52f1a0cbc445468a1e3 [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
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800571 return true;
572}
573
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800574void MDPComp::batchLayers() {
575 /* Idea is to keep as many contiguous non-updating(cached) layers in FB and
576 * send rest of them through MDP. NEVER mark an updating layer for caching.
577 * But cached ones can be marked for MDP*/
578
579 int maxBatchStart = -1;
580 int maxBatchCount = 0;
581
582 /* All or Nothing is cached. No batching needed */
Saurabh Shahaa236822013-04-24 18:07:26 -0700583 if(!mCurrentFrame.fbCount) {
584 mCurrentFrame.fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800585 return;
Saurabh Shahaa236822013-04-24 18:07:26 -0700586 }
587 if(!mCurrentFrame.mdpCount) {
588 mCurrentFrame.fbZ = 0;
589 return;
590 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800591
592 /* Search for max number of contiguous (cached) layers */
593 int i = 0;
594 while (i < mCurrentFrame.layerCount) {
595 int count = 0;
596 while(mCurrentFrame.isFBComposed[i] && i < mCurrentFrame.layerCount) {
597 count++; i++;
598 }
599 if(count > maxBatchCount) {
600 maxBatchCount = count;
601 maxBatchStart = i - count;
Saurabh Shahaa236822013-04-24 18:07:26 -0700602 mCurrentFrame.fbZ = maxBatchStart;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800603 }
604 if(i < mCurrentFrame.layerCount) i++;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800605 }
606
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800607 /* reset rest of the layers for MDP comp */
608 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
609 if(i != maxBatchStart){
610 mCurrentFrame.isFBComposed[i] = false;
611 } else {
612 i += maxBatchCount;
613 }
614 }
615
616 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700617 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
618 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800619
620 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
621 mCurrentFrame.fbCount);
622}
Saurabh Shah85234ec2013-04-12 17:09:00 -0700623
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800624void MDPComp::updateLayerCache(hwc_context_t* ctx,
625 hwc_display_contents_1_t* list) {
626
627 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
628 int numCacheableLayers = 0;
629
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800630 for(int i = 0; i < numAppLayers; i++) {
631 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
632 numCacheableLayers++;
633 mCurrentFrame.isFBComposed[i] = true;
634 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -0700635 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800636 mCachedFrame.hnd[i] = list->hwLayers[i].handle;
637 }
638 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700639
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800640 mCurrentFrame.fbCount = numCacheableLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700641 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
642 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800643 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__, numCacheableLayers);
644}
645
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800646void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list) {
647
648 int nYuvCount = ctx->listStats[mDpy].yuvCount;
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700649 if(!nYuvCount && mDpy) {
650 //Reset "No animation on external display" related parameters.
651 ctx->mPrevCropVideo.left = ctx->mPrevCropVideo.top =
652 ctx->mPrevCropVideo.right = ctx->mPrevCropVideo.bottom = 0;
653 ctx->mPrevDestVideo.left = ctx->mPrevDestVideo.top =
654 ctx->mPrevDestVideo.right = ctx->mPrevDestVideo.bottom = 0;
655 ctx->mPrevTransformVideo = 0;
656 return;
657 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800658 for(int index = 0;index < nYuvCount; index++){
659 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
660 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
661
662 if(!isYUVDoable(ctx, layer)) {
663 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
664 mCurrentFrame.isFBComposed[nYuvIndex] = true;
665 mCurrentFrame.fbCount++;
666 }
667 } else {
668 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
669 mCurrentFrame.isFBComposed[nYuvIndex] = false;
670 mCurrentFrame.fbCount--;
671 }
672 }
673 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700674
675 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
676 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800677 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
678 mCurrentFrame.fbCount);
679}
680
Saurabh Shahaa236822013-04-24 18:07:26 -0700681bool MDPComp::programMDP(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800682 if(!allocLayerPipes(ctx, list)) {
683 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700684 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800685 }
686
Saurabh Shahaa236822013-04-24 18:07:26 -0700687 bool fbBatch = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800688 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700689 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800690 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800691 int mdpIndex = mCurrentFrame.layerToMDP[index];
692 hwc_layer_1_t* layer = &list->hwLayers[index];
693
694 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
695 cur_pipe->zOrder = mdpNextZOrder++;
696
697 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
698 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
699 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -0700700 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800701 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700702 } else if(fbBatch == false) {
703 mdpNextZOrder++;
704 fbBatch = true;
705 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800706 }
707
Saurabh Shahaa236822013-04-24 18:07:26 -0700708 return true;
709}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800710
Saurabh Shahaa236822013-04-24 18:07:26 -0700711bool MDPComp::programYUV(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
712 if(!allocLayerPipes(ctx, list)) {
713 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
714 return false;
715 }
716 //If we are in this block, it means we have yuv + rgb layers both
717 int mdpIdx = 0;
718 for (int index = 0; index < mCurrentFrame.layerCount; index++) {
719 if(!mCurrentFrame.isFBComposed[index]) {
720 hwc_layer_1_t* layer = &list->hwLayers[index];
721 int mdpIndex = mCurrentFrame.layerToMDP[index];
722 MdpPipeInfo* cur_pipe =
723 mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
724 cur_pipe->zOrder = mdpIdx++;
725
726 if(configure(ctx, layer,
727 mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
728 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
729 layer %d",__FUNCTION__, index);
730 return false;
731 }
732 }
733 }
734 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800735}
736
737int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700738 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -0700739
Saurabh Shahb39f8152013-08-22 10:21:44 -0700740 //reset old data
741 mCurrentFrame.reset(numLayers);
Prabhanjan Kandula088bd892013-07-02 23:47:13 +0530742
Saurabh Shahb39f8152013-08-22 10:21:44 -0700743 //number of app layers exceeds MAX_NUM_APP_LAYERS fall back to GPU
744 //do not cache the information for next draw cycle.
745 if(numLayers > MAX_NUM_APP_LAYERS) {
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530746 mCachedFrame.updateCounts(mCurrentFrame);
Saurabh Shahb39f8152013-08-22 10:21:44 -0700747 ALOGD_IF(isDebug(), "%s: Number of App layers exceeded the limit ",
748 __FUNCTION__);
749 return -1;
750 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800751
Saurabh Shahb39f8152013-08-22 10:21:44 -0700752 //Hard conditions, if not met, cannot do MDP comp
753 if(!isFrameDoable(ctx)) {
754 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
755 __FUNCTION__);
756 reset(numLayers, list);
757 return -1;
758 }
759
760 //Check whether layers marked for MDP Composition is actually doable.
761 if(isFullFrameDoable(ctx, list)) {
762 mCurrentFrame.map();
763 //Configure framebuffer first if applicable
764 if(mCurrentFrame.fbZ >= 0) {
765 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list,
766 mCurrentFrame.fbZ)) {
767 ALOGE("%s configure framebuffer failed", __func__);
768 reset(numLayers, list);
769 return -1;
770 }
771 }
772 //Acquire and Program MDP pipes
773 if(!programMDP(ctx, list)) {
774 reset(numLayers, list);
775 return -1;
776 } else { //Success
777 //Any change in composition types needs an FB refresh
778 mCurrentFrame.needsRedraw = false;
779 if(mCurrentFrame.fbCount &&
780 ((mCurrentFrame.mdpCount != mCachedFrame.mdpCount) ||
781 (mCurrentFrame.fbCount != mCachedFrame.cacheCount) ||
782 (mCurrentFrame.fbZ != mCachedFrame.fbZ) ||
783 (!mCurrentFrame.mdpCount) ||
784 (list->flags & HWC_GEOMETRY_CHANGED) ||
785 isSkipPresent(ctx, mDpy) ||
786 (mDpy > HWC_DISPLAY_PRIMARY))) {
787 mCurrentFrame.needsRedraw = true;
788 }
789 }
790 } else if(isOnlyVideoDoable(ctx, list)) {
791 //All layers marked for MDP comp cannot be bypassed.
792 //Try to compose atleast YUV layers through MDP comp and let
793 //all the RGB layers compose in FB
794 //Destination over
795 mCurrentFrame.fbZ = -1;
796 if(mCurrentFrame.fbCount)
797 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
798
799 mCurrentFrame.map();
800
801 //Configure framebuffer first if applicable
802 if(mCurrentFrame.fbZ >= 0) {
803 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, mCurrentFrame.fbZ)) {
804 ALOGE("%s configure framebuffer failed", __func__);
805 reset(numLayers, list);
806 return -1;
807 }
808 }
809 if(!programYUV(ctx, list)) {
810 reset(numLayers, list);
811 return -1;
812 }
813 } else {
814 reset(numLayers, list);
815 return -1;
816 }
817
818 //UpdateLayerFlags
819 setMDPCompLayerFlags(ctx, list);
820 mCachedFrame.updateCounts(mCurrentFrame);
821
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530822 // unlock it before calling dump function to avoid deadlock
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800823 if(isDebug()) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700824 ALOGD("GEOMETRY change: %d", (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800825 android::String8 sDump("");
826 dump(sDump);
827 ALOGE("%s",sDump.string());
828 }
829
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700830 return 0;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800831}
832
833//=============MDPCompLowRes===================================================
834
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700835/*
836 * Configures pipe(s) for MDP composition
837 */
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800838int MDPCompLowRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800839 PipeLayerPair& PipeLayerPair) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800840 MdpPipeInfoLowRes& mdp_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800841 *(static_cast<MdpPipeInfoLowRes*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -0800842 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
843 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
844 eIsFg isFg = IS_FG_OFF;
845 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700846
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800847 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
848 __FUNCTION__, layer, zOrder, dest);
849
850 return configureLowRes(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
851 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700852}
853
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700854bool MDPCompLowRes::arePipesAvailable(hwc_context_t *ctx,
855 hwc_display_contents_1_t* list) {
856 overlay::Overlay& ov = *ctx->mOverlay;
857 int numPipesNeeded = mCurrentFrame.mdpCount;
858 int availPipes = ov.availablePipes(mDpy, Overlay::MIXER_DEFAULT);
859
860 //Reserve pipe for FB
861 if(mCurrentFrame.fbCount)
862 availPipes -= 1;
863
864 if(numPipesNeeded > availPipes) {
865 ALOGD_IF(isDebug(), "%s: Insufficient pipes, dpy %d needed %d, avail %d",
866 __FUNCTION__, mDpy, numPipesNeeded, availPipes);
867 return false;
868 }
869
870 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700871}
872
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800873bool MDPCompLowRes::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700874 hwc_display_contents_1_t* list) {
875 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700876
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800877 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700878
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800879 hwc_layer_1_t* layer = &list->hwLayers[index];
880 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800881 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800882 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800883 info.pipeInfo = new MdpPipeInfoLowRes;
Saurabh Shahacf10202013-02-26 10:15:15 -0800884 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800885 MdpPipeInfoLowRes& pipe_info = *(MdpPipeInfoLowRes*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800886 ePipeType type = MDPCOMP_OV_ANY;
887
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700888 if(isYuvBuffer(hnd)) {
889 type = MDPCOMP_OV_VG;
Saurabh Shah8a117932013-05-23 12:48:13 -0700890 } else if(!qhwc::needsScaling(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -0700891 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
892 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800893 type = MDPCOMP_OV_DMA;
894 }
895
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700896 pipe_info.index = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800897 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700898 ALOGD_IF(isDebug(), "%s: Unable to get pipe type = %d",
899 __FUNCTION__, (int) type);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500900 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700901 }
902 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700903 return true;
904}
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700905
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800906bool MDPCompLowRes::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700907
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800908 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500909 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
910 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800911 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700912
913 if(!ctx || !list) {
914 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500915 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700916 }
917
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +0530918 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
919 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
920 return true;
921 }
922
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500923 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -0700924 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500925 idleInvalidator->markForSleep();
926
927 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800928 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700929
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800930 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
931 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700932 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800933 if(mCurrentFrame.isFBComposed[i]) continue;
934
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700935 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -0800936 private_handle_t *hnd = (private_handle_t *)layer->handle;
937 if(!hnd) {
938 ALOGE("%s handle null", __FUNCTION__);
939 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700940 }
941
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800942 int mdpIndex = mCurrentFrame.layerToMDP[i];
943
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800944 MdpPipeInfoLowRes& pipe_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800945 *(MdpPipeInfoLowRes*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800946 ovutils::eDest dest = pipe_info.index;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800947 if(dest == ovutils::OV_INVALID) {
948 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500949 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700950 }
951
Saurabh Shahacf10202013-02-26 10:15:15 -0800952 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
953 continue;
954 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700955
Saurabh Shahacf10202013-02-26 10:15:15 -0800956 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800957 using pipe: %d", __FUNCTION__, layer,
958 hnd, dest );
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700959
Saurabh Shahacf10202013-02-26 10:15:15 -0800960 int fd = hnd->fd;
961 uint32_t offset = hnd->offset;
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700962
963 if(ctx->mAD->isModeOn()) {
964 if(ctx->mAD->draw(ctx, fd, offset)) {
965 fd = ctx->mAD->getDstFd(ctx);
966 offset = ctx->mAD->getDstOffset(ctx);
967 }
968 }
969
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800970 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -0800971 if(rot) {
972 if(!rot->queueBuffer(fd, offset))
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500973 return false;
Saurabh Shahacf10202013-02-26 10:15:15 -0800974 fd = rot->getDstMemId();
975 offset = rot->getDstOffset();
976 }
977
978 if (!ov.queueBuffer(fd, offset, dest)) {
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +0530979 ALOGE("%s: queueBuffer failed for display:%d ", __FUNCTION__, mDpy);
Saurabh Shahacf10202013-02-26 10:15:15 -0800980 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700981 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500982
983 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700984 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500985 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700986}
987
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800988//=============MDPCompHighRes===================================================
989
990int MDPCompHighRes::pipesNeeded(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700991 hwc_display_contents_1_t* list,
992 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800993 int pipesNeeded = 0;
Saurabh Shah67a38c32013-06-10 16:23:15 -0700994 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -0700995
996 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800997
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800998 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
999 if(!mCurrentFrame.isFBComposed[i]) {
1000 hwc_layer_1_t* layer = &list->hwLayers[i];
1001 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001002 if(mixer == Overlay::MIXER_LEFT && dst.left < lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001003 pipesNeeded++;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001004 } else if(mixer == Overlay::MIXER_RIGHT && dst.right > lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001005 pipesNeeded++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001006 }
1007 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001008 }
1009 return pipesNeeded;
1010}
1011
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001012bool MDPCompHighRes::arePipesAvailable(hwc_context_t *ctx,
1013 hwc_display_contents_1_t* list) {
1014 overlay::Overlay& ov = *ctx->mOverlay;
1015
1016 for(int i = 0; i < Overlay::MIXER_MAX; i++) {
1017 int numPipesNeeded = pipesNeeded(ctx, list, i);
1018 int availPipes = ov.availablePipes(mDpy, i);
1019
1020 //Reserve pipe(s)for FB
1021 if(mCurrentFrame.fbCount)
1022 availPipes -= 1;
1023
1024 if(numPipesNeeded > availPipes) {
1025 ALOGD_IF(isDebug(), "%s: Insufficient pipes for "
1026 "dpy %d mixer %d needed %d, avail %d",
1027 __FUNCTION__, mDpy, i, numPipesNeeded, availPipes);
1028 return false;
1029 }
1030 }
1031 return true;
1032}
1033
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001034bool MDPCompHighRes::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001035 MdpPipeInfoHighRes& pipe_info,
1036 ePipeType type) {
1037 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001038 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001039
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001040 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001041 pipe_info.lIndex = ovutils::OV_INVALID;
1042 pipe_info.rIndex = ovutils::OV_INVALID;
1043
1044 if (dst.left < lSplit) {
1045 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_LEFT);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001046 if(pipe_info.lIndex == ovutils::OV_INVALID)
1047 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001048 }
1049
1050 if(dst.right > lSplit) {
1051 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_RIGHT);
1052 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001053 return false;
1054 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001055
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001056 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001057}
1058
1059bool MDPCompHighRes::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001060 hwc_display_contents_1_t* list) {
1061 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001062
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001063 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001064
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001065 hwc_layer_1_t* layer = &list->hwLayers[index];
1066 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001067 int mdpIndex = mCurrentFrame.layerToMDP[index];
1068 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001069 info.pipeInfo = new MdpPipeInfoHighRes;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001070 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001071 MdpPipeInfoHighRes& pipe_info = *(MdpPipeInfoHighRes*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001072 ePipeType type = MDPCOMP_OV_ANY;
1073
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001074 if(isYuvBuffer(hnd)) {
1075 type = MDPCOMP_OV_VG;
Saurabh Shah8a117932013-05-23 12:48:13 -07001076 } else if(!qhwc::needsScaling(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001077 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001078 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001079 type = MDPCOMP_OV_DMA;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001080 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001081
1082 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001083 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type = %d",
1084 __FUNCTION__, (int) type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001085 return false;
1086 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001087 }
1088 return true;
1089}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001090
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001091/*
1092 * Configures pipe(s) for MDP composition
1093 */
1094int MDPCompHighRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001095 PipeLayerPair& PipeLayerPair) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001096 MdpPipeInfoHighRes& mdp_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001097 *(static_cast<MdpPipeInfoHighRes*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001098 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1099 eIsFg isFg = IS_FG_OFF;
1100 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1101 eDest lDest = mdp_info.lIndex;
1102 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001103
1104 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1105 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1106
1107 return configureHighRes(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
1108 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001109}
1110
1111bool MDPCompHighRes::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
1112
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001113 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001114 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1115 return true;
1116 }
1117
1118 if(!ctx || !list) {
1119 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001120 return false;
1121 }
1122
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301123 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1124 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1125 return true;
1126 }
1127
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001128 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001129 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001130 idleInvalidator->markForSleep();
1131
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001132 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001133 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001134
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001135 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1136 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001137 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001138 if(mCurrentFrame.isFBComposed[i]) continue;
1139
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001140 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001141 private_handle_t *hnd = (private_handle_t *)layer->handle;
1142 if(!hnd) {
1143 ALOGE("%s handle null", __FUNCTION__);
1144 return false;
1145 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001146
1147 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1148 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001149 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001150
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001151 int mdpIndex = mCurrentFrame.layerToMDP[i];
1152
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001153 MdpPipeInfoHighRes& pipe_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001154 *(MdpPipeInfoHighRes*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1155 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -08001156
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001157 ovutils::eDest indexL = pipe_info.lIndex;
1158 ovutils::eDest indexR = pipe_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001159
Saurabh Shahacf10202013-02-26 10:15:15 -08001160 int fd = hnd->fd;
1161 int offset = hnd->offset;
1162
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001163 if(ctx->mAD->isModeOn()) {
1164 if(ctx->mAD->draw(ctx, fd, offset)) {
1165 fd = ctx->mAD->getDstFd(ctx);
1166 offset = ctx->mAD->getDstOffset(ctx);
1167 }
1168 }
1169
Saurabh Shahacf10202013-02-26 10:15:15 -08001170 if(rot) {
1171 rot->queueBuffer(fd, offset);
1172 fd = rot->getDstMemId();
1173 offset = rot->getDstOffset();
1174 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001175
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001176 //************* play left mixer **********
1177 if(indexL != ovutils::OV_INVALID) {
1178 ovutils::eDest destL = (ovutils::eDest)indexL;
Saurabh Shahacf10202013-02-26 10:15:15 -08001179 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001180 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
Saurabh Shahacf10202013-02-26 10:15:15 -08001181 if (!ov.queueBuffer(fd, offset, destL)) {
1182 ALOGE("%s: queueBuffer failed for left mixer", __FUNCTION__);
1183 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001184 }
1185 }
1186
1187 //************* play right mixer **********
1188 if(indexR != ovutils::OV_INVALID) {
1189 ovutils::eDest destR = (ovutils::eDest)indexR;
Saurabh Shahacf10202013-02-26 10:15:15 -08001190 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001191 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
Saurabh Shahacf10202013-02-26 10:15:15 -08001192 if (!ov.queueBuffer(fd, offset, destR)) {
1193 ALOGE("%s: queueBuffer failed for right mixer", __FUNCTION__);
1194 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001195 }
1196 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001197
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001198 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1199 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001200
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001201 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001202}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001203}; //namespace
1204