blob: 85450d275a38db8527994caa89fc292966762f4e [file] [log] [blame]
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001/*
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002 * Copyright (C) 2012-2013, The Linux Foundation. All rights reserved.
Naseer Ahmed7c958d42012-07-31 18:57:03 -07003 * Not a Contribution, Apache license notifications and license are retained
4 * for attribution purposes only.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
Saurabh Shah4fdde762013-04-30 18:47:33 -070019#include <math.h>
Naseer Ahmed7c958d42012-07-31 18:57:03 -070020#include "hwc_mdpcomp.h"
Naseer Ahmed54821fe2012-11-28 18:44:38 -050021#include <sys/ioctl.h>
Saurabh Shah56f610d2012-08-07 15:27:06 -070022#include "external.h"
Jeykumar Sankaran27dee262013-08-01 17:09:54 -070023#include "virtual.h"
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -080024#include "qdMetaData.h"
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -080025#include "mdp_version.h"
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -070026#include "hwc_fbupdate.h"
Saurabh Shaha9da08f2013-07-03 13:27:53 -070027#include "hwc_ad.h"
Saurabh Shahacf10202013-02-26 10:15:15 -080028#include <overlayRotator.h>
29
Saurabh Shah85234ec2013-04-12 17:09:00 -070030using namespace overlay;
Saurabh Shahbd2d0832013-04-04 14:33:08 -070031using namespace qdutils;
Saurabh Shahacf10202013-02-26 10:15:15 -080032using namespace overlay::utils;
33namespace ovutils = overlay::utils;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070034
Naseer Ahmed7c958d42012-07-31 18:57:03 -070035namespace qhwc {
36
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080037//==============MDPComp========================================================
38
Naseer Ahmed7c958d42012-07-31 18:57:03 -070039IdleInvalidator *MDPComp::idleInvalidator = NULL;
40bool MDPComp::sIdleFallBack = false;
41bool MDPComp::sDebugLogs = false;
Naseer Ahmed54821fe2012-11-28 18:44:38 -050042bool MDPComp::sEnabled = false;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -070043bool MDPComp::sEnableMixedMode = true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080044int MDPComp::sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070045
Saurabh Shah67a38c32013-06-10 16:23:15 -070046MDPComp* MDPComp::getObject(const int& width, const int& rightSplit,
47 const int& dpy) {
48 if(width > MAX_DISPLAY_DIM || rightSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080049 return new MDPCompHighRes(dpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080050 }
Saurabh Shah67a38c32013-06-10 16:23:15 -070051 return new MDPCompLowRes(dpy);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080052}
53
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080054MDPComp::MDPComp(int dpy):mDpy(dpy){};
55
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080056void MDPComp::dump(android::String8& buf)
57{
Jeykumar Sankaran3c6bb042013-08-15 14:01:04 -070058 if(mCurrentFrame.layerCount > MAX_NUM_APP_LAYERS)
59 return;
60
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080061 dumpsys_log(buf,"HWC Map for Dpy: %s \n",
Jeykumar Sankaran27dee262013-08-01 17:09:54 -070062 (mDpy == 0) ? "\"PRIMARY\"" :
63 (mDpy == 1) ? "\"EXTERNAL\"" : "\"VIRTUAL\"");
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080064 dumpsys_log(buf,"PREV_FRAME: layerCount:%2d mdpCount:%2d \
65 cacheCount:%2d \n", mCachedFrame.layerCount,
66 mCachedFrame.mdpCount, mCachedFrame.cacheCount);
67 dumpsys_log(buf,"CURR_FRAME: layerCount:%2d mdpCount:%2d \
68 fbCount:%2d \n", mCurrentFrame.layerCount,
69 mCurrentFrame.mdpCount, mCurrentFrame.fbCount);
70 dumpsys_log(buf,"needsFBRedraw:%3s pipesUsed:%2d MaxPipesPerMixer: %d \n",
71 (mCurrentFrame.needsRedraw? "YES" : "NO"),
72 mCurrentFrame.mdpCount, sMaxPipesPerMixer);
73 dumpsys_log(buf," --------------------------------------------- \n");
74 dumpsys_log(buf," listIdx | cached? | mdpIndex | comptype | Z \n");
75 dumpsys_log(buf," --------------------------------------------- \n");
76 for(int index = 0; index < mCurrentFrame.layerCount; index++ )
77 dumpsys_log(buf," %7d | %7s | %8d | %9s | %2d \n",
78 index,
79 (mCurrentFrame.isFBComposed[index] ? "YES" : "NO"),
80 mCurrentFrame.layerToMDP[index],
81 (mCurrentFrame.isFBComposed[index] ?
82 (mCurrentFrame.needsRedraw ? "GLES" : "CACHE") : "MDP"),
83 (mCurrentFrame.isFBComposed[index] ? mCurrentFrame.fbZ :
84 mCurrentFrame.mdpToLayer[mCurrentFrame.layerToMDP[index]].pipeInfo->zOrder));
85 dumpsys_log(buf,"\n");
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080086}
87
88bool MDPComp::init(hwc_context_t *ctx) {
89
90 if(!ctx) {
91 ALOGE("%s: Invalid hwc context!!",__FUNCTION__);
92 return false;
93 }
94
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080095 char property[PROPERTY_VALUE_MAX];
96
97 sEnabled = false;
98 if((property_get("persist.hwc.mdpcomp.enable", property, NULL) > 0) &&
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080099 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
100 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800101 sEnabled = true;
Xiaoming Zhou944e02e2013-05-01 20:54:03 -0400102 if(!setupBasePipe(ctx)) {
103 ALOGE("%s: Failed to setup primary base pipe", __FUNCTION__);
104 return false;
105 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800106 }
107
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700108 sEnableMixedMode = true;
109 if((property_get("debug.mdpcomp.mixedmode.disable", property, NULL) > 0) &&
110 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
111 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
112 sEnableMixedMode = false;
113 }
114
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800115 sDebugLogs = false;
116 if(property_get("debug.mdpcomp.logs", property, NULL) > 0) {
117 if(atoi(property) != 0)
118 sDebugLogs = true;
119 }
120
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800121 sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
Saurabh Shah85234ec2013-04-12 17:09:00 -0700122 if(property_get("debug.mdpcomp.maxpermixer", property, "-1") > 0) {
123 int val = atoi(property);
124 if(val >= 0)
125 sMaxPipesPerMixer = min(val, MAX_PIPES_PER_MIXER);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800126 }
127
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400128 if(ctx->mMDP.panel != MIPI_CMD_PANEL) {
129 // Idle invalidation is not necessary on command mode panels
130 long idle_timeout = DEFAULT_IDLE_TIME;
131 if(property_get("debug.mdpcomp.idletime", property, NULL) > 0) {
132 if(atoi(property) != 0)
133 idle_timeout = atoi(property);
134 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800135
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400136 //create Idle Invalidator only when not disabled through property
137 if(idle_timeout != -1)
138 idleInvalidator = IdleInvalidator::getInstance();
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800139
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400140 if(idleInvalidator == NULL) {
141 ALOGE("%s: failed to instantiate idleInvalidator object",
142 __FUNCTION__);
143 } else {
144 idleInvalidator->init(timeout_handler, ctx, idle_timeout);
145 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800146 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700147 return true;
148}
149
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700150void MDPComp::reset(const int& numLayers, hwc_display_contents_1_t* list) {
151 mCurrentFrame.reset(numLayers);
152 mCachedFrame.cacheAll(list);
153 mCachedFrame.updateCounts(mCurrentFrame);
154}
155
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700156void MDPComp::timeout_handler(void *udata) {
157 struct hwc_context_t* ctx = (struct hwc_context_t*)(udata);
158
159 if(!ctx) {
160 ALOGE("%s: received empty data in timer callback", __FUNCTION__);
161 return;
162 }
163
Jesse Hall3be78d92012-08-21 15:12:23 -0700164 if(!ctx->proc) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700165 ALOGE("%s: HWC proc not registered", __FUNCTION__);
166 return;
167 }
168 sIdleFallBack = true;
169 /* Trigger SF to redraw the current frame */
Jesse Hall3be78d92012-08-21 15:12:23 -0700170 ctx->proc->invalidate(ctx->proc);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700171}
172
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800173void MDPComp::setMDPCompLayerFlags(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800174 hwc_display_contents_1_t* list) {
175 LayerProp *layerProp = ctx->layerProp[mDpy];
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800176
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800177 for(int index = 0; index < ctx->listStats[mDpy].numAppLayers; index++) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800178 hwc_layer_1_t* layer = &(list->hwLayers[index]);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800179 if(!mCurrentFrame.isFBComposed[index]) {
180 layerProp[index].mFlags |= HWC_MDPCOMP;
181 layer->compositionType = HWC_OVERLAY;
182 layer->hints |= HWC_HINT_CLEAR_FB;
183 mCachedFrame.hnd[index] = NULL;
184 } else {
185 if(!mCurrentFrame.needsRedraw)
186 layer->compositionType = HWC_OVERLAY;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800187 }
188 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700189}
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500190
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800191/*
192 * Sets up BORDERFILL as default base pipe and detaches RGB0.
193 * Framebuffer is always updated using PLAY ioctl.
194 */
195bool MDPComp::setupBasePipe(hwc_context_t *ctx) {
196 const int dpy = HWC_DISPLAY_PRIMARY;
197 int fb_stride = ctx->dpyAttr[dpy].stride;
198 int fb_width = ctx->dpyAttr[dpy].xres;
199 int fb_height = ctx->dpyAttr[dpy].yres;
200 int fb_fd = ctx->dpyAttr[dpy].fd;
201
202 mdp_overlay ovInfo;
203 msmfb_overlay_data ovData;
204 memset(&ovInfo, 0, sizeof(mdp_overlay));
205 memset(&ovData, 0, sizeof(msmfb_overlay_data));
206
207 ovInfo.src.format = MDP_RGB_BORDERFILL;
208 ovInfo.src.width = fb_width;
209 ovInfo.src.height = fb_height;
210 ovInfo.src_rect.w = fb_width;
211 ovInfo.src_rect.h = fb_height;
212 ovInfo.dst_rect.w = fb_width;
213 ovInfo.dst_rect.h = fb_height;
214 ovInfo.id = MSMFB_NEW_REQUEST;
215
216 if (ioctl(fb_fd, MSMFB_OVERLAY_SET, &ovInfo) < 0) {
217 ALOGE("Failed to call ioctl MSMFB_OVERLAY_SET err=%s",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800218 strerror(errno));
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800219 return false;
220 }
221
222 ovData.id = ovInfo.id;
223 if (ioctl(fb_fd, MSMFB_OVERLAY_PLAY, &ovData) < 0) {
224 ALOGE("Failed to call ioctl MSMFB_OVERLAY_PLAY err=%s",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800225 strerror(errno));
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800226 return false;
227 }
228 return true;
229}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800230MDPComp::FrameInfo::FrameInfo() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700231 reset(0);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800232}
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800233
Saurabh Shahaa236822013-04-24 18:07:26 -0700234void MDPComp::FrameInfo::reset(const int& numLayers) {
235 for(int i = 0 ; i < MAX_PIPES_PER_MIXER && numLayers; i++ ) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800236 if(mdpToLayer[i].pipeInfo) {
237 delete mdpToLayer[i].pipeInfo;
238 mdpToLayer[i].pipeInfo = NULL;
239 //We dont own the rotator
240 mdpToLayer[i].rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800241 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800242 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800243
244 memset(&mdpToLayer, 0, sizeof(mdpToLayer));
245 memset(&layerToMDP, -1, sizeof(layerToMDP));
Saurabh Shahaa236822013-04-24 18:07:26 -0700246 memset(&isFBComposed, 1, sizeof(isFBComposed));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800247
Saurabh Shahaa236822013-04-24 18:07:26 -0700248 layerCount = numLayers;
249 fbCount = numLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800250 mdpCount = 0;
Saurabh Shah2f3895f2013-05-02 10:13:31 -0700251 needsRedraw = true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800252 fbZ = 0;
253}
254
Saurabh Shahaa236822013-04-24 18:07:26 -0700255void MDPComp::FrameInfo::map() {
256 // populate layer and MDP maps
257 int mdpIdx = 0;
258 for(int idx = 0; idx < layerCount; idx++) {
259 if(!isFBComposed[idx]) {
260 mdpToLayer[mdpIdx].listIndex = idx;
261 layerToMDP[idx] = mdpIdx++;
262 }
263 }
264}
265
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800266MDPComp::LayerCache::LayerCache() {
267 reset();
268}
269
270void MDPComp::LayerCache::reset() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700271 memset(&hnd, 0, sizeof(hnd));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800272 mdpCount = 0;
273 cacheCount = 0;
274 layerCount = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -0700275 fbZ = -1;
276}
277
278void MDPComp::LayerCache::cacheAll(hwc_display_contents_1_t* list) {
279 const int numAppLayers = list->numHwLayers - 1;
280 for(int i = 0; i < numAppLayers; i++) {
281 hnd[i] = list->hwLayers[i].handle;
282 }
283}
284
285void MDPComp::LayerCache::updateCounts(const FrameInfo& curFrame) {
286 mdpCount = curFrame.mdpCount;
287 cacheCount = curFrame.fbCount;
288 layerCount = curFrame.layerCount;
289 fbZ = curFrame.fbZ;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800290}
291
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530292bool MDPComp::isValidDimension(hwc_context_t *ctx, hwc_layer_1_t *layer) {
Saurabh Shah4fdde762013-04-30 18:47:33 -0700293 const int dpy = HWC_DISPLAY_PRIMARY;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800294 private_handle_t *hnd = (private_handle_t *)layer->handle;
295
296 if(!hnd) {
297 ALOGE("%s: layer handle is NULL", __FUNCTION__);
298 return false;
299 }
300
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800301 int hw_w = ctx->dpyAttr[mDpy].xres;
302 int hw_h = ctx->dpyAttr[mDpy].yres;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800303
Saurabh Shah4fdde762013-04-30 18:47:33 -0700304 hwc_rect_t crop = layer->sourceCrop;
305 hwc_rect_t dst = layer->displayFrame;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800306
307 if(dst.left < 0 || dst.top < 0 || dst.right > hw_w || dst.bottom > hw_h) {
Saurabh Shah4fdde762013-04-30 18:47:33 -0700308 hwc_rect_t scissor = {0, 0, hw_w, hw_h };
309 qhwc::calculate_crop_rects(crop, dst, scissor, layer->transform);
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800310 }
311
Saurabh Shah4fdde762013-04-30 18:47:33 -0700312 int crop_w = crop.right - crop.left;
313 int crop_h = crop.bottom - crop.top;
314 int dst_w = dst.right - dst.left;
315 int dst_h = dst.bottom - dst.top;
316 float w_dscale = ceilf((float)crop_w / (float)dst_w);
317 float h_dscale = ceilf((float)crop_h / (float)dst_h);
318
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800319 /* Workaround for MDP HW limitation in DSI command mode panels where
320 * FPS will not go beyond 30 if buffers on RGB pipes are of width or height
321 * less than 5 pixels
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530322 * There also is a HW limilation in MDP, minimum block size is 2x2
323 * Fallback to GPU if height is less than 2.
324 */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800325 if((crop_w < 5)||(crop_h < 5))
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800326 return false;
327
Saurabh Shah4fdde762013-04-30 18:47:33 -0700328 const uint32_t downscale =
329 qdutils::MDPVersion::getInstance().getMaxMDPDownscale();
330 if(ctx->mMDP.version >= qdutils::MDSS_V5) {
331 /* Workaround for downscales larger than 4x.
332 * Will be removed once decimator block is enabled for MDSS
333 */
334 if(!qdutils::MDPVersion::getInstance().supportsDecimation()) {
335 if(crop_w > MAX_DISPLAY_DIM || w_dscale > downscale ||
336 h_dscale > downscale)
337 return false;
338 } else {
339 if(w_dscale > 64 || h_dscale > 64)
340 return false;
341 }
342 } else { //A-family
343 if(w_dscale > downscale || h_dscale > downscale)
344 return false;
345 }
346
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800347 return true;
348}
349
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700350ovutils::eDest MDPComp::getMdpPipe(hwc_context_t *ctx, ePipeType type,
351 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800352 overlay::Overlay& ov = *ctx->mOverlay;
353 ovutils::eDest mdp_pipe = ovutils::OV_INVALID;
354
355 switch(type) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800356 case MDPCOMP_OV_DMA:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700357 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_DMA, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800358 if(mdp_pipe != ovutils::OV_INVALID) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800359 return mdp_pipe;
360 }
361 case MDPCOMP_OV_ANY:
362 case MDPCOMP_OV_RGB:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700363 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800364 if(mdp_pipe != ovutils::OV_INVALID) {
365 return mdp_pipe;
366 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800367
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800368 if(type == MDPCOMP_OV_RGB) {
369 //Requested only for RGB pipe
370 break;
371 }
372 case MDPCOMP_OV_VG:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700373 return ov.nextPipe(ovutils::OV_MDP_PIPE_VG, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800374 default:
375 ALOGE("%s: Invalid pipe type",__FUNCTION__);
376 return ovutils::OV_INVALID;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800377 };
378 return ovutils::OV_INVALID;
379}
380
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800381bool MDPComp::isFrameDoable(hwc_context_t *ctx) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700382 bool ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700383 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800384
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800385 if(!isEnabled()) {
386 ALOGD_IF(isDebug(),"%s: MDP Comp. not enabled.", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700387 ret = false;
Saurabh Shahd4e65852013-06-17 11:33:53 -0700388 } else if(qdutils::MDPVersion::getInstance().is8x26() &&
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700389 ctx->mVideoTransFlag && ctx->mVirtualDisplay->isConnected()) {
Saurabh Shahd4e65852013-06-17 11:33:53 -0700390 //1 Padding round to shift pipes across mixers
391 ALOGD_IF(isDebug(),"%s: MDP Comp. video transition padding round",
392 __FUNCTION__);
393 ret = false;
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700394 } else if(ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isConfiguring ||
395 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isConfiguring) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800396 ALOGD_IF( isDebug(),"%s: External Display connection is pending",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800397 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700398 ret = false;
Saurabh Shahaa236822013-04-24 18:07:26 -0700399 } else if(ctx->isPaddingRound) {
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700400 ctx->isPaddingRound = false;
401 ALOGD_IF(isDebug(), "%s: padding round",__FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700402 ret = false;
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700403 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700404 return ret;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800405}
406
407/* Checks for conditions where all the layers marked for MDP comp cannot be
408 * bypassed. On such conditions we try to bypass atleast YUV layers */
409bool MDPComp::isFullFrameDoable(hwc_context_t *ctx,
410 hwc_display_contents_1_t* list){
411
Saurabh Shahaa236822013-04-24 18:07:26 -0700412 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800413
Saurabh Shah2d998a92013-05-14 17:55:58 -0700414 if(sIdleFallBack) {
415 ALOGD_IF(isDebug(), "%s: Idle fallback dpy %d",__FUNCTION__, mDpy);
416 return false;
417 }
418
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800419 if(mDpy > HWC_DISPLAY_PRIMARY){
420 ALOGD_IF(isDebug(), "%s: Cannot support External display(s)",
421 __FUNCTION__);
422 return false;
423 }
424
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800425 if(isSkipPresent(ctx, mDpy)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700426 ALOGD_IF(isDebug(),"%s: SKIP present: %d",
427 __FUNCTION__,
428 isSkipPresent(ctx, mDpy));
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800429 return false;
430 }
431
Saurabh Shah9f084ad2013-05-02 11:28:09 -0700432 if(ctx->listStats[mDpy].needsAlphaScale
433 && ctx->mMDP.version < qdutils::MDSS_V5) {
434 ALOGD_IF(isDebug(), "%s: frame needs alpha downscaling",__FUNCTION__);
435 return false;
436 }
437
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800438 //MDP composition is not efficient if layer needs rotator.
439 for(int i = 0; i < numAppLayers; ++i) {
440 // As MDP h/w supports flip operation, use MDP comp only for
441 // 180 transforms. Fail for any transform involving 90 (90, 270).
442 hwc_layer_1_t* layer = &list->hwLayers[i];
443 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800444
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700445 if(layer->transform & HWC_TRANSFORM_ROT_90) {
446 if(!isYuvBuffer(hnd) ) {
447 ALOGD_IF(isDebug(), "%s: orientation involved",__FUNCTION__);
448 return false;
449 }else if(!canUseRotator(ctx, mDpy)) {
450 ALOGD_IF(isDebug(), "%s: no free DMA pipe",__FUNCTION__);
451 return false;
452 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800453 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700454 if(!isValidDimension(ctx,layer)) {
455 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
456 __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800457 return false;
458 }
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530459
460 //For 8x26 with panel width>1k, if RGB layer needs HFLIP fail mdp comp
461 // may not need it if Gfx pre-rotation can handle all flips & rotations
462 if(qdutils::MDPVersion::getInstance().is8x26() &&
463 (ctx->dpyAttr[mDpy].xres > 1024) &&
464 (layer->transform & HWC_TRANSFORM_FLIP_H) &&
465 (!isYuvBuffer(hnd)))
466 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800467 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700468
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700469 if(ctx->mAD->isDoable()) {
470 return false;
471 }
472
Saurabh Shahaa236822013-04-24 18:07:26 -0700473 //If all above hard conditions are met we can do full or partial MDP comp.
474 bool ret = false;
475 if(fullMDPComp(ctx, list)) {
476 ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700477 } else if(partialMDPComp(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700478 ret = true;
479 }
480 return ret;
481}
482
483bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
484 //Setup mCurrentFrame
485 mCurrentFrame.mdpCount = mCurrentFrame.layerCount;
486 mCurrentFrame.fbCount = 0;
487 mCurrentFrame.fbZ = -1;
488 memset(&mCurrentFrame.isFBComposed, 0, sizeof(mCurrentFrame.isFBComposed));
489
490 int mdpCount = mCurrentFrame.mdpCount;
491 if(mdpCount > sMaxPipesPerMixer) {
492 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
493 return false;
494 }
495
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700496 if(!arePipesAvailable(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700497 return false;
498 }
499
500 return true;
501}
502
503bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
504{
505 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700506
507 if(!sEnableMixedMode) {
508 //Mixed mode is disabled. No need to even try caching.
509 return false;
510 }
511
Saurabh Shahaa236822013-04-24 18:07:26 -0700512 //Setup mCurrentFrame
513 mCurrentFrame.reset(numAppLayers);
514 updateLayerCache(ctx, list);
515 updateYUV(ctx, list);
516 batchLayers(); //sets up fbZ also
517
518 int mdpCount = mCurrentFrame.mdpCount;
519 if(mdpCount > (sMaxPipesPerMixer - 1)) { // -1 since FB is used
520 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
521 return false;
522 }
523
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700524 if(!arePipesAvailable(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700525 return false;
526 }
527
528 return true;
529}
530
531bool MDPComp::isOnlyVideoDoable(hwc_context_t *ctx,
532 hwc_display_contents_1_t* list){
533 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
534 mCurrentFrame.reset(numAppLayers);
535 updateYUV(ctx, list);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700536 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700537 int fbNeeded = int(mCurrentFrame.fbCount != 0);
538
539 if(!isYuvPresent(ctx, mDpy)) {
540 return false;
541 }
542
Saurabh Shah4fdde762013-04-30 18:47:33 -0700543 if(!mdpCount)
544 return false;
545
Saurabh Shahaa236822013-04-24 18:07:26 -0700546 if(mdpCount > (sMaxPipesPerMixer - fbNeeded)) {
547 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
548 return false;
549 }
550
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700551 if(!arePipesAvailable(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700552 return false;
553 }
554
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800555 return true;
556}
557
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800558/* Checks for conditions where YUV layers cannot be bypassed */
559bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Saurabh Shahe2474082013-05-15 16:32:13 -0700560 bool extAnimBlockFeature = mDpy && ctx->listStats[mDpy].isDisplayAnimating;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800561
Saurabh Shahe2474082013-05-15 16:32:13 -0700562 if(isSkipLayer(layer) && !extAnimBlockFeature) {
563 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800564 return false;
565 }
566
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700567 if(layer->transform & HWC_TRANSFORM_ROT_90 && !canUseRotator(ctx,mDpy)) {
568 ALOGD_IF(isDebug(), "%s: no free DMA pipe",__FUNCTION__);
569 return false;
570 }
571
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800572 if(isSecuring(ctx, layer)) {
573 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
574 return false;
575 }
576
Saurabh Shah4fdde762013-04-30 18:47:33 -0700577 if(!isValidDimension(ctx, layer)) {
578 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
579 __FUNCTION__);
580 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800581 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700582
Naseer Ahmeddc61a972013-07-10 17:50:54 -0400583 if(layer->planeAlpha < 0xFF) {
584 ALOGD_IF(isDebug(), "%s: Cannot handle YUV layer with plane alpha\
585 in video only mode",
586 __FUNCTION__);
587 return false;
588 }
589
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800590 return true;
591}
592
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800593void MDPComp::batchLayers() {
594 /* Idea is to keep as many contiguous non-updating(cached) layers in FB and
595 * send rest of them through MDP. NEVER mark an updating layer for caching.
596 * But cached ones can be marked for MDP*/
597
598 int maxBatchStart = -1;
599 int maxBatchCount = 0;
600
601 /* All or Nothing is cached. No batching needed */
Saurabh Shahaa236822013-04-24 18:07:26 -0700602 if(!mCurrentFrame.fbCount) {
603 mCurrentFrame.fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800604 return;
Saurabh Shahaa236822013-04-24 18:07:26 -0700605 }
606 if(!mCurrentFrame.mdpCount) {
607 mCurrentFrame.fbZ = 0;
608 return;
609 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800610
611 /* Search for max number of contiguous (cached) layers */
612 int i = 0;
613 while (i < mCurrentFrame.layerCount) {
614 int count = 0;
615 while(mCurrentFrame.isFBComposed[i] && i < mCurrentFrame.layerCount) {
616 count++; i++;
617 }
618 if(count > maxBatchCount) {
619 maxBatchCount = count;
620 maxBatchStart = i - count;
Saurabh Shahaa236822013-04-24 18:07:26 -0700621 mCurrentFrame.fbZ = maxBatchStart;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800622 }
623 if(i < mCurrentFrame.layerCount) i++;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800624 }
625
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800626 /* reset rest of the layers for MDP comp */
627 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
628 if(i != maxBatchStart){
629 mCurrentFrame.isFBComposed[i] = false;
630 } else {
631 i += maxBatchCount;
632 }
633 }
634
635 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700636 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
637 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800638
639 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
640 mCurrentFrame.fbCount);
641}
Saurabh Shah85234ec2013-04-12 17:09:00 -0700642
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800643void MDPComp::updateLayerCache(hwc_context_t* ctx,
644 hwc_display_contents_1_t* list) {
645
646 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
647 int numCacheableLayers = 0;
648
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800649 for(int i = 0; i < numAppLayers; i++) {
650 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
651 numCacheableLayers++;
652 mCurrentFrame.isFBComposed[i] = true;
653 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -0700654 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800655 mCachedFrame.hnd[i] = list->hwLayers[i].handle;
656 }
657 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700658
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800659 mCurrentFrame.fbCount = numCacheableLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700660 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
661 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800662 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__, numCacheableLayers);
663}
664
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800665void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list) {
666
667 int nYuvCount = ctx->listStats[mDpy].yuvCount;
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700668 if(!nYuvCount && mDpy) {
669 //Reset "No animation on external display" related parameters.
670 ctx->mPrevCropVideo.left = ctx->mPrevCropVideo.top =
671 ctx->mPrevCropVideo.right = ctx->mPrevCropVideo.bottom = 0;
672 ctx->mPrevDestVideo.left = ctx->mPrevDestVideo.top =
673 ctx->mPrevDestVideo.right = ctx->mPrevDestVideo.bottom = 0;
674 ctx->mPrevTransformVideo = 0;
675 return;
676 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800677 for(int index = 0;index < nYuvCount; index++){
678 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
679 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
680
681 if(!isYUVDoable(ctx, layer)) {
682 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
683 mCurrentFrame.isFBComposed[nYuvIndex] = true;
684 mCurrentFrame.fbCount++;
685 }
686 } else {
687 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
688 mCurrentFrame.isFBComposed[nYuvIndex] = false;
689 mCurrentFrame.fbCount--;
690 }
691 }
692 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700693
694 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
695 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800696 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
697 mCurrentFrame.fbCount);
698}
699
Saurabh Shahaa236822013-04-24 18:07:26 -0700700bool MDPComp::programMDP(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800701 if(!allocLayerPipes(ctx, list)) {
702 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700703 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800704 }
705
Saurabh Shahaa236822013-04-24 18:07:26 -0700706 bool fbBatch = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800707 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700708 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800709 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800710 int mdpIndex = mCurrentFrame.layerToMDP[index];
711 hwc_layer_1_t* layer = &list->hwLayers[index];
712
713 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
714 cur_pipe->zOrder = mdpNextZOrder++;
715
716 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
717 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
718 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -0700719 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800720 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700721 } else if(fbBatch == false) {
722 mdpNextZOrder++;
723 fbBatch = true;
724 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800725 }
726
Saurabh Shahaa236822013-04-24 18:07:26 -0700727 return true;
728}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800729
Saurabh Shahaa236822013-04-24 18:07:26 -0700730bool MDPComp::programYUV(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
731 if(!allocLayerPipes(ctx, list)) {
732 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
733 return false;
734 }
735 //If we are in this block, it means we have yuv + rgb layers both
736 int mdpIdx = 0;
737 for (int index = 0; index < mCurrentFrame.layerCount; index++) {
738 if(!mCurrentFrame.isFBComposed[index]) {
739 hwc_layer_1_t* layer = &list->hwLayers[index];
740 int mdpIndex = mCurrentFrame.layerToMDP[index];
741 MdpPipeInfo* cur_pipe =
742 mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
743 cur_pipe->zOrder = mdpIdx++;
744
745 if(configure(ctx, layer,
746 mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
747 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
748 layer %d",__FUNCTION__, index);
749 return false;
750 }
751 }
752 }
753 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800754}
755
756int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700757 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -0700758
Saurabh Shahb39f8152013-08-22 10:21:44 -0700759 //reset old data
760 mCurrentFrame.reset(numLayers);
Prabhanjan Kandula088bd892013-07-02 23:47:13 +0530761
Saurabh Shahb39f8152013-08-22 10:21:44 -0700762 //number of app layers exceeds MAX_NUM_APP_LAYERS fall back to GPU
763 //do not cache the information for next draw cycle.
764 if(numLayers > MAX_NUM_APP_LAYERS) {
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530765 mCachedFrame.updateCounts(mCurrentFrame);
Saurabh Shahb39f8152013-08-22 10:21:44 -0700766 ALOGD_IF(isDebug(), "%s: Number of App layers exceeded the limit ",
767 __FUNCTION__);
768 return -1;
769 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800770
Saurabh Shahb39f8152013-08-22 10:21:44 -0700771 //Hard conditions, if not met, cannot do MDP comp
772 if(!isFrameDoable(ctx)) {
773 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
774 __FUNCTION__);
775 reset(numLayers, list);
776 return -1;
777 }
778
779 //Check whether layers marked for MDP Composition is actually doable.
780 if(isFullFrameDoable(ctx, list)) {
781 mCurrentFrame.map();
782 //Configure framebuffer first if applicable
783 if(mCurrentFrame.fbZ >= 0) {
784 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list,
785 mCurrentFrame.fbZ)) {
786 ALOGE("%s configure framebuffer failed", __func__);
787 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -0700788 ctx->mOverlay->clear(mDpy);
Saurabh Shahb39f8152013-08-22 10:21:44 -0700789 return -1;
790 }
791 }
792 //Acquire and Program MDP pipes
793 if(!programMDP(ctx, list)) {
794 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -0700795 ctx->mOverlay->clear(mDpy);
Saurabh Shahb39f8152013-08-22 10:21:44 -0700796 return -1;
797 } else { //Success
798 //Any change in composition types needs an FB refresh
799 mCurrentFrame.needsRedraw = false;
800 if(mCurrentFrame.fbCount &&
801 ((mCurrentFrame.mdpCount != mCachedFrame.mdpCount) ||
802 (mCurrentFrame.fbCount != mCachedFrame.cacheCount) ||
803 (mCurrentFrame.fbZ != mCachedFrame.fbZ) ||
804 (!mCurrentFrame.mdpCount) ||
805 (list->flags & HWC_GEOMETRY_CHANGED) ||
806 isSkipPresent(ctx, mDpy) ||
807 (mDpy > HWC_DISPLAY_PRIMARY))) {
808 mCurrentFrame.needsRedraw = true;
809 }
810 }
811 } else if(isOnlyVideoDoable(ctx, list)) {
812 //All layers marked for MDP comp cannot be bypassed.
813 //Try to compose atleast YUV layers through MDP comp and let
814 //all the RGB layers compose in FB
815 //Destination over
816 mCurrentFrame.fbZ = -1;
817 if(mCurrentFrame.fbCount)
818 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
819
820 mCurrentFrame.map();
821
822 //Configure framebuffer first if applicable
823 if(mCurrentFrame.fbZ >= 0) {
824 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, mCurrentFrame.fbZ)) {
825 ALOGE("%s configure framebuffer failed", __func__);
826 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -0700827 ctx->mOverlay->clear(mDpy);
Saurabh Shahb39f8152013-08-22 10:21:44 -0700828 return -1;
829 }
830 }
831 if(!programYUV(ctx, list)) {
832 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -0700833 ctx->mOverlay->clear(mDpy);
Saurabh Shahb39f8152013-08-22 10:21:44 -0700834 return -1;
835 }
836 } else {
837 reset(numLayers, list);
838 return -1;
839 }
840
841 //UpdateLayerFlags
842 setMDPCompLayerFlags(ctx, list);
843 mCachedFrame.updateCounts(mCurrentFrame);
844
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530845 // unlock it before calling dump function to avoid deadlock
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800846 if(isDebug()) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700847 ALOGD("GEOMETRY change: %d", (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800848 android::String8 sDump("");
849 dump(sDump);
850 ALOGE("%s",sDump.string());
851 }
852
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700853 return 0;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800854}
855
856//=============MDPCompLowRes===================================================
857
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700858/*
859 * Configures pipe(s) for MDP composition
860 */
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800861int MDPCompLowRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800862 PipeLayerPair& PipeLayerPair) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800863 MdpPipeInfoLowRes& mdp_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800864 *(static_cast<MdpPipeInfoLowRes*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -0800865 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
866 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
867 eIsFg isFg = IS_FG_OFF;
868 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700869
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800870 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
871 __FUNCTION__, layer, zOrder, dest);
872
873 return configureLowRes(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
874 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700875}
876
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700877bool MDPCompLowRes::arePipesAvailable(hwc_context_t *ctx,
878 hwc_display_contents_1_t* list) {
879 overlay::Overlay& ov = *ctx->mOverlay;
880 int numPipesNeeded = mCurrentFrame.mdpCount;
881 int availPipes = ov.availablePipes(mDpy, Overlay::MIXER_DEFAULT);
882
883 //Reserve pipe for FB
884 if(mCurrentFrame.fbCount)
885 availPipes -= 1;
886
887 if(numPipesNeeded > availPipes) {
888 ALOGD_IF(isDebug(), "%s: Insufficient pipes, dpy %d needed %d, avail %d",
889 __FUNCTION__, mDpy, numPipesNeeded, availPipes);
890 return false;
891 }
892
893 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700894}
895
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800896bool MDPCompLowRes::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700897 hwc_display_contents_1_t* list) {
898 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700899
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800900 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700901
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800902 hwc_layer_1_t* layer = &list->hwLayers[index];
903 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800904 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800905 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800906 info.pipeInfo = new MdpPipeInfoLowRes;
Saurabh Shahacf10202013-02-26 10:15:15 -0800907 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800908 MdpPipeInfoLowRes& pipe_info = *(MdpPipeInfoLowRes*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800909 ePipeType type = MDPCOMP_OV_ANY;
910
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700911 if(isYuvBuffer(hnd)) {
912 type = MDPCOMP_OV_VG;
Saurabh Shah8a117932013-05-23 12:48:13 -0700913 } else if(!qhwc::needsScaling(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -0700914 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
915 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800916 type = MDPCOMP_OV_DMA;
917 }
918
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700919 pipe_info.index = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800920 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700921 ALOGD_IF(isDebug(), "%s: Unable to get pipe type = %d",
922 __FUNCTION__, (int) type);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500923 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700924 }
925 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700926 return true;
927}
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700928
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800929bool MDPCompLowRes::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700930
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800931 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500932 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
933 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800934 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700935
936 if(!ctx || !list) {
937 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500938 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700939 }
940
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +0530941 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
942 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
943 return true;
944 }
945
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500946 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -0700947 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500948 idleInvalidator->markForSleep();
949
950 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800951 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700952
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800953 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
954 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700955 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800956 if(mCurrentFrame.isFBComposed[i]) continue;
957
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700958 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -0800959 private_handle_t *hnd = (private_handle_t *)layer->handle;
960 if(!hnd) {
961 ALOGE("%s handle null", __FUNCTION__);
962 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700963 }
964
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800965 int mdpIndex = mCurrentFrame.layerToMDP[i];
966
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800967 MdpPipeInfoLowRes& pipe_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800968 *(MdpPipeInfoLowRes*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800969 ovutils::eDest dest = pipe_info.index;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800970 if(dest == ovutils::OV_INVALID) {
971 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500972 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700973 }
974
Saurabh Shahacf10202013-02-26 10:15:15 -0800975 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
976 continue;
977 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700978
Saurabh Shahacf10202013-02-26 10:15:15 -0800979 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800980 using pipe: %d", __FUNCTION__, layer,
981 hnd, dest );
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700982
Saurabh Shahacf10202013-02-26 10:15:15 -0800983 int fd = hnd->fd;
984 uint32_t offset = hnd->offset;
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700985
986 if(ctx->mAD->isModeOn()) {
987 if(ctx->mAD->draw(ctx, fd, offset)) {
988 fd = ctx->mAD->getDstFd(ctx);
989 offset = ctx->mAD->getDstOffset(ctx);
990 }
991 }
992
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800993 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -0800994 if(rot) {
995 if(!rot->queueBuffer(fd, offset))
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500996 return false;
Saurabh Shahacf10202013-02-26 10:15:15 -0800997 fd = rot->getDstMemId();
998 offset = rot->getDstOffset();
999 }
1000
1001 if (!ov.queueBuffer(fd, offset, dest)) {
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301002 ALOGE("%s: queueBuffer failed for display:%d ", __FUNCTION__, mDpy);
Saurabh Shahacf10202013-02-26 10:15:15 -08001003 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001004 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001005
1006 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001007 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001008 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001009}
1010
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001011//=============MDPCompHighRes===================================================
1012
1013int MDPCompHighRes::pipesNeeded(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001014 hwc_display_contents_1_t* list,
1015 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001016 int pipesNeeded = 0;
Saurabh Shah67a38c32013-06-10 16:23:15 -07001017 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001018
1019 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001020
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001021 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1022 if(!mCurrentFrame.isFBComposed[i]) {
1023 hwc_layer_1_t* layer = &list->hwLayers[i];
1024 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001025 if(mixer == Overlay::MIXER_LEFT && dst.left < lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001026 pipesNeeded++;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001027 } else if(mixer == Overlay::MIXER_RIGHT && dst.right > lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001028 pipesNeeded++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001029 }
1030 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001031 }
1032 return pipesNeeded;
1033}
1034
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001035bool MDPCompHighRes::arePipesAvailable(hwc_context_t *ctx,
1036 hwc_display_contents_1_t* list) {
1037 overlay::Overlay& ov = *ctx->mOverlay;
1038
1039 for(int i = 0; i < Overlay::MIXER_MAX; i++) {
1040 int numPipesNeeded = pipesNeeded(ctx, list, i);
1041 int availPipes = ov.availablePipes(mDpy, i);
1042
1043 //Reserve pipe(s)for FB
1044 if(mCurrentFrame.fbCount)
1045 availPipes -= 1;
1046
1047 if(numPipesNeeded > availPipes) {
1048 ALOGD_IF(isDebug(), "%s: Insufficient pipes for "
1049 "dpy %d mixer %d needed %d, avail %d",
1050 __FUNCTION__, mDpy, i, numPipesNeeded, availPipes);
1051 return false;
1052 }
1053 }
1054 return true;
1055}
1056
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001057bool MDPCompHighRes::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001058 MdpPipeInfoHighRes& pipe_info,
1059 ePipeType type) {
1060 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001061 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001062
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001063 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001064 pipe_info.lIndex = ovutils::OV_INVALID;
1065 pipe_info.rIndex = ovutils::OV_INVALID;
1066
1067 if (dst.left < lSplit) {
1068 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_LEFT);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001069 if(pipe_info.lIndex == ovutils::OV_INVALID)
1070 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001071 }
1072
1073 if(dst.right > lSplit) {
1074 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_RIGHT);
1075 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001076 return false;
1077 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001078
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001079 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001080}
1081
1082bool MDPCompHighRes::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001083 hwc_display_contents_1_t* list) {
1084 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001085
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001086 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001087
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001088 hwc_layer_1_t* layer = &list->hwLayers[index];
1089 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001090 int mdpIndex = mCurrentFrame.layerToMDP[index];
1091 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001092 info.pipeInfo = new MdpPipeInfoHighRes;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001093 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001094 MdpPipeInfoHighRes& pipe_info = *(MdpPipeInfoHighRes*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001095 ePipeType type = MDPCOMP_OV_ANY;
1096
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001097 if(isYuvBuffer(hnd)) {
1098 type = MDPCOMP_OV_VG;
Saurabh Shah8a117932013-05-23 12:48:13 -07001099 } else if(!qhwc::needsScaling(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001100 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001101 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001102 type = MDPCOMP_OV_DMA;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001103 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001104
1105 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001106 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type = %d",
1107 __FUNCTION__, (int) type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001108 return false;
1109 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001110 }
1111 return true;
1112}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001113
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001114/*
1115 * Configures pipe(s) for MDP composition
1116 */
1117int MDPCompHighRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001118 PipeLayerPair& PipeLayerPair) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001119 MdpPipeInfoHighRes& mdp_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001120 *(static_cast<MdpPipeInfoHighRes*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001121 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1122 eIsFg isFg = IS_FG_OFF;
1123 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1124 eDest lDest = mdp_info.lIndex;
1125 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001126
1127 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1128 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1129
1130 return configureHighRes(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
1131 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001132}
1133
1134bool MDPCompHighRes::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
1135
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001136 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001137 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1138 return true;
1139 }
1140
1141 if(!ctx || !list) {
1142 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001143 return false;
1144 }
1145
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301146 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1147 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1148 return true;
1149 }
1150
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001151 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001152 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001153 idleInvalidator->markForSleep();
1154
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001155 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001156 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001157
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001158 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1159 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001160 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001161 if(mCurrentFrame.isFBComposed[i]) continue;
1162
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001163 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001164 private_handle_t *hnd = (private_handle_t *)layer->handle;
1165 if(!hnd) {
1166 ALOGE("%s handle null", __FUNCTION__);
1167 return false;
1168 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001169
1170 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1171 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001172 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001173
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001174 int mdpIndex = mCurrentFrame.layerToMDP[i];
1175
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001176 MdpPipeInfoHighRes& pipe_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001177 *(MdpPipeInfoHighRes*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1178 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -08001179
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001180 ovutils::eDest indexL = pipe_info.lIndex;
1181 ovutils::eDest indexR = pipe_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001182
Saurabh Shahacf10202013-02-26 10:15:15 -08001183 int fd = hnd->fd;
1184 int offset = hnd->offset;
1185
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001186 if(ctx->mAD->isModeOn()) {
1187 if(ctx->mAD->draw(ctx, fd, offset)) {
1188 fd = ctx->mAD->getDstFd(ctx);
1189 offset = ctx->mAD->getDstOffset(ctx);
1190 }
1191 }
1192
Saurabh Shahacf10202013-02-26 10:15:15 -08001193 if(rot) {
1194 rot->queueBuffer(fd, offset);
1195 fd = rot->getDstMemId();
1196 offset = rot->getDstOffset();
1197 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001198
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001199 //************* play left mixer **********
1200 if(indexL != ovutils::OV_INVALID) {
1201 ovutils::eDest destL = (ovutils::eDest)indexL;
Saurabh Shahacf10202013-02-26 10:15:15 -08001202 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001203 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
Saurabh Shahacf10202013-02-26 10:15:15 -08001204 if (!ov.queueBuffer(fd, offset, destL)) {
1205 ALOGE("%s: queueBuffer failed for left mixer", __FUNCTION__);
1206 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001207 }
1208 }
1209
1210 //************* play right mixer **********
1211 if(indexR != ovutils::OV_INVALID) {
1212 ovutils::eDest destR = (ovutils::eDest)indexR;
Saurabh Shahacf10202013-02-26 10:15:15 -08001213 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001214 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
Saurabh Shahacf10202013-02-26 10:15:15 -08001215 if (!ov.queueBuffer(fd, offset, destR)) {
1216 ALOGE("%s: queueBuffer failed for right mixer", __FUNCTION__);
1217 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001218 }
1219 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001220
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001221 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1222 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001223
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001224 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001225}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001226}; //namespace
1227