blob: dbfb16b851f629672d7d45473f3bccab8d8018d3 [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{
Prabhanjan Kandula088bd892013-07-02 23:47:13 +053058 Locker::Autolock _l(mMdpCompLock);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080059 dumpsys_log(buf,"HWC Map for Dpy: %s \n",
Jeykumar Sankaran27dee262013-08-01 17:09:54 -070060 (mDpy == 0) ? "\"PRIMARY\"" :
61 (mDpy == 1) ? "\"EXTERNAL\"" : "\"VIRTUAL\"");
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080062 dumpsys_log(buf,"PREV_FRAME: layerCount:%2d mdpCount:%2d \
63 cacheCount:%2d \n", mCachedFrame.layerCount,
64 mCachedFrame.mdpCount, mCachedFrame.cacheCount);
65 dumpsys_log(buf,"CURR_FRAME: layerCount:%2d mdpCount:%2d \
66 fbCount:%2d \n", mCurrentFrame.layerCount,
67 mCurrentFrame.mdpCount, mCurrentFrame.fbCount);
68 dumpsys_log(buf,"needsFBRedraw:%3s pipesUsed:%2d MaxPipesPerMixer: %d \n",
69 (mCurrentFrame.needsRedraw? "YES" : "NO"),
70 mCurrentFrame.mdpCount, sMaxPipesPerMixer);
71 dumpsys_log(buf," --------------------------------------------- \n");
72 dumpsys_log(buf," listIdx | cached? | mdpIndex | comptype | Z \n");
73 dumpsys_log(buf," --------------------------------------------- \n");
74 for(int index = 0; index < mCurrentFrame.layerCount; index++ )
75 dumpsys_log(buf," %7d | %7s | %8d | %9s | %2d \n",
76 index,
77 (mCurrentFrame.isFBComposed[index] ? "YES" : "NO"),
78 mCurrentFrame.layerToMDP[index],
79 (mCurrentFrame.isFBComposed[index] ?
80 (mCurrentFrame.needsRedraw ? "GLES" : "CACHE") : "MDP"),
81 (mCurrentFrame.isFBComposed[index] ? mCurrentFrame.fbZ :
82 mCurrentFrame.mdpToLayer[mCurrentFrame.layerToMDP[index]].pipeInfo->zOrder));
83 dumpsys_log(buf,"\n");
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080084}
85
86bool MDPComp::init(hwc_context_t *ctx) {
87
88 if(!ctx) {
89 ALOGE("%s: Invalid hwc context!!",__FUNCTION__);
90 return false;
91 }
92
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080093 char property[PROPERTY_VALUE_MAX];
94
95 sEnabled = false;
96 if((property_get("persist.hwc.mdpcomp.enable", property, NULL) > 0) &&
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080097 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
98 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080099 sEnabled = true;
Xiaoming Zhou944e02e2013-05-01 20:54:03 -0400100 if(!setupBasePipe(ctx)) {
101 ALOGE("%s: Failed to setup primary base pipe", __FUNCTION__);
102 return false;
103 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800104 }
105
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700106 sEnableMixedMode = true;
107 if((property_get("debug.mdpcomp.mixedmode.disable", property, NULL) > 0) &&
108 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
109 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
110 sEnableMixedMode = false;
111 }
112
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800113 sDebugLogs = false;
114 if(property_get("debug.mdpcomp.logs", property, NULL) > 0) {
115 if(atoi(property) != 0)
116 sDebugLogs = true;
117 }
118
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800119 sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
Saurabh Shah85234ec2013-04-12 17:09:00 -0700120 if(property_get("debug.mdpcomp.maxpermixer", property, "-1") > 0) {
121 int val = atoi(property);
122 if(val >= 0)
123 sMaxPipesPerMixer = min(val, MAX_PIPES_PER_MIXER);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800124 }
125
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400126 if(ctx->mMDP.panel != MIPI_CMD_PANEL) {
127 // Idle invalidation is not necessary on command mode panels
128 long idle_timeout = DEFAULT_IDLE_TIME;
129 if(property_get("debug.mdpcomp.idletime", property, NULL) > 0) {
130 if(atoi(property) != 0)
131 idle_timeout = atoi(property);
132 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800133
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400134 //create Idle Invalidator only when not disabled through property
135 if(idle_timeout != -1)
136 idleInvalidator = IdleInvalidator::getInstance();
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800137
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400138 if(idleInvalidator == NULL) {
139 ALOGE("%s: failed to instantiate idleInvalidator object",
140 __FUNCTION__);
141 } else {
142 idleInvalidator->init(timeout_handler, ctx, idle_timeout);
143 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800144 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700145 return true;
146}
147
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700148void MDPComp::reset(const int& numLayers, hwc_display_contents_1_t* list) {
149 mCurrentFrame.reset(numLayers);
150 mCachedFrame.cacheAll(list);
151 mCachedFrame.updateCounts(mCurrentFrame);
152}
153
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700154void MDPComp::timeout_handler(void *udata) {
155 struct hwc_context_t* ctx = (struct hwc_context_t*)(udata);
156
157 if(!ctx) {
158 ALOGE("%s: received empty data in timer callback", __FUNCTION__);
159 return;
160 }
161
Jesse Hall3be78d92012-08-21 15:12:23 -0700162 if(!ctx->proc) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700163 ALOGE("%s: HWC proc not registered", __FUNCTION__);
164 return;
165 }
166 sIdleFallBack = true;
167 /* Trigger SF to redraw the current frame */
Jesse Hall3be78d92012-08-21 15:12:23 -0700168 ctx->proc->invalidate(ctx->proc);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700169}
170
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800171void MDPComp::setMDPCompLayerFlags(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800172 hwc_display_contents_1_t* list) {
173 LayerProp *layerProp = ctx->layerProp[mDpy];
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800174
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800175 for(int index = 0; index < ctx->listStats[mDpy].numAppLayers; index++) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800176 hwc_layer_1_t* layer = &(list->hwLayers[index]);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800177 if(!mCurrentFrame.isFBComposed[index]) {
178 layerProp[index].mFlags |= HWC_MDPCOMP;
179 layer->compositionType = HWC_OVERLAY;
180 layer->hints |= HWC_HINT_CLEAR_FB;
181 mCachedFrame.hnd[index] = NULL;
182 } else {
183 if(!mCurrentFrame.needsRedraw)
184 layer->compositionType = HWC_OVERLAY;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800185 }
186 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700187}
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500188
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800189/*
190 * Sets up BORDERFILL as default base pipe and detaches RGB0.
191 * Framebuffer is always updated using PLAY ioctl.
192 */
193bool MDPComp::setupBasePipe(hwc_context_t *ctx) {
194 const int dpy = HWC_DISPLAY_PRIMARY;
195 int fb_stride = ctx->dpyAttr[dpy].stride;
196 int fb_width = ctx->dpyAttr[dpy].xres;
197 int fb_height = ctx->dpyAttr[dpy].yres;
198 int fb_fd = ctx->dpyAttr[dpy].fd;
199
200 mdp_overlay ovInfo;
201 msmfb_overlay_data ovData;
202 memset(&ovInfo, 0, sizeof(mdp_overlay));
203 memset(&ovData, 0, sizeof(msmfb_overlay_data));
204
205 ovInfo.src.format = MDP_RGB_BORDERFILL;
206 ovInfo.src.width = fb_width;
207 ovInfo.src.height = fb_height;
208 ovInfo.src_rect.w = fb_width;
209 ovInfo.src_rect.h = fb_height;
210 ovInfo.dst_rect.w = fb_width;
211 ovInfo.dst_rect.h = fb_height;
212 ovInfo.id = MSMFB_NEW_REQUEST;
213
214 if (ioctl(fb_fd, MSMFB_OVERLAY_SET, &ovInfo) < 0) {
215 ALOGE("Failed to call ioctl MSMFB_OVERLAY_SET err=%s",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800216 strerror(errno));
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800217 return false;
218 }
219
220 ovData.id = ovInfo.id;
221 if (ioctl(fb_fd, MSMFB_OVERLAY_PLAY, &ovData) < 0) {
222 ALOGE("Failed to call ioctl MSMFB_OVERLAY_PLAY err=%s",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800223 strerror(errno));
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800224 return false;
225 }
226 return true;
227}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800228MDPComp::FrameInfo::FrameInfo() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700229 reset(0);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800230}
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800231
Saurabh Shahaa236822013-04-24 18:07:26 -0700232void MDPComp::FrameInfo::reset(const int& numLayers) {
233 for(int i = 0 ; i < MAX_PIPES_PER_MIXER && numLayers; i++ ) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800234 if(mdpToLayer[i].pipeInfo) {
235 delete mdpToLayer[i].pipeInfo;
236 mdpToLayer[i].pipeInfo = NULL;
237 //We dont own the rotator
238 mdpToLayer[i].rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800239 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800240 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800241
242 memset(&mdpToLayer, 0, sizeof(mdpToLayer));
243 memset(&layerToMDP, -1, sizeof(layerToMDP));
Saurabh Shahaa236822013-04-24 18:07:26 -0700244 memset(&isFBComposed, 1, sizeof(isFBComposed));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800245
Saurabh Shahaa236822013-04-24 18:07:26 -0700246 layerCount = numLayers;
247 fbCount = numLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800248 mdpCount = 0;
Saurabh Shah2f3895f2013-05-02 10:13:31 -0700249 needsRedraw = true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800250 fbZ = 0;
251}
252
Saurabh Shahaa236822013-04-24 18:07:26 -0700253void MDPComp::FrameInfo::map() {
254 // populate layer and MDP maps
255 int mdpIdx = 0;
256 for(int idx = 0; idx < layerCount; idx++) {
257 if(!isFBComposed[idx]) {
258 mdpToLayer[mdpIdx].listIndex = idx;
259 layerToMDP[idx] = mdpIdx++;
260 }
261 }
262}
263
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800264MDPComp::LayerCache::LayerCache() {
265 reset();
266}
267
268void MDPComp::LayerCache::reset() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700269 memset(&hnd, 0, sizeof(hnd));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800270 mdpCount = 0;
271 cacheCount = 0;
272 layerCount = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -0700273 fbZ = -1;
274}
275
276void MDPComp::LayerCache::cacheAll(hwc_display_contents_1_t* list) {
277 const int numAppLayers = list->numHwLayers - 1;
278 for(int i = 0; i < numAppLayers; i++) {
279 hnd[i] = list->hwLayers[i].handle;
280 }
281}
282
283void MDPComp::LayerCache::updateCounts(const FrameInfo& curFrame) {
284 mdpCount = curFrame.mdpCount;
285 cacheCount = curFrame.fbCount;
286 layerCount = curFrame.layerCount;
287 fbZ = curFrame.fbZ;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800288}
289
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530290bool MDPComp::isValidDimension(hwc_context_t *ctx, hwc_layer_1_t *layer) {
Saurabh Shah4fdde762013-04-30 18:47:33 -0700291 const int dpy = HWC_DISPLAY_PRIMARY;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800292 private_handle_t *hnd = (private_handle_t *)layer->handle;
293
294 if(!hnd) {
295 ALOGE("%s: layer handle is NULL", __FUNCTION__);
296 return false;
297 }
298
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800299 int hw_w = ctx->dpyAttr[mDpy].xres;
300 int hw_h = ctx->dpyAttr[mDpy].yres;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800301
Saurabh Shah4fdde762013-04-30 18:47:33 -0700302 hwc_rect_t crop = layer->sourceCrop;
303 hwc_rect_t dst = layer->displayFrame;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800304
305 if(dst.left < 0 || dst.top < 0 || dst.right > hw_w || dst.bottom > hw_h) {
Saurabh Shah4fdde762013-04-30 18:47:33 -0700306 hwc_rect_t scissor = {0, 0, hw_w, hw_h };
307 qhwc::calculate_crop_rects(crop, dst, scissor, layer->transform);
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800308 }
309
Saurabh Shah4fdde762013-04-30 18:47:33 -0700310 int crop_w = crop.right - crop.left;
311 int crop_h = crop.bottom - crop.top;
312 int dst_w = dst.right - dst.left;
313 int dst_h = dst.bottom - dst.top;
314 float w_dscale = ceilf((float)crop_w / (float)dst_w);
315 float h_dscale = ceilf((float)crop_h / (float)dst_h);
316
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800317 /* Workaround for MDP HW limitation in DSI command mode panels where
318 * FPS will not go beyond 30 if buffers on RGB pipes are of width or height
319 * less than 5 pixels
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530320 * There also is a HW limilation in MDP, minimum block size is 2x2
321 * Fallback to GPU if height is less than 2.
322 */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800323 if((crop_w < 5)||(crop_h < 5))
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800324 return false;
325
Saurabh Shah4fdde762013-04-30 18:47:33 -0700326 const uint32_t downscale =
327 qdutils::MDPVersion::getInstance().getMaxMDPDownscale();
328 if(ctx->mMDP.version >= qdutils::MDSS_V5) {
329 /* Workaround for downscales larger than 4x.
330 * Will be removed once decimator block is enabled for MDSS
331 */
332 if(!qdutils::MDPVersion::getInstance().supportsDecimation()) {
333 if(crop_w > MAX_DISPLAY_DIM || w_dscale > downscale ||
334 h_dscale > downscale)
335 return false;
336 } else {
337 if(w_dscale > 64 || h_dscale > 64)
338 return false;
339 }
340 } else { //A-family
341 if(w_dscale > downscale || h_dscale > downscale)
342 return false;
343 }
344
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800345 return true;
346}
347
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700348ovutils::eDest MDPComp::getMdpPipe(hwc_context_t *ctx, ePipeType type,
349 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800350 overlay::Overlay& ov = *ctx->mOverlay;
351 ovutils::eDest mdp_pipe = ovutils::OV_INVALID;
352
353 switch(type) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800354 case MDPCOMP_OV_DMA:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700355 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_DMA, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800356 if(mdp_pipe != ovutils::OV_INVALID) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800357 return mdp_pipe;
358 }
359 case MDPCOMP_OV_ANY:
360 case MDPCOMP_OV_RGB:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700361 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800362 if(mdp_pipe != ovutils::OV_INVALID) {
363 return mdp_pipe;
364 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800365
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800366 if(type == MDPCOMP_OV_RGB) {
367 //Requested only for RGB pipe
368 break;
369 }
370 case MDPCOMP_OV_VG:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700371 return ov.nextPipe(ovutils::OV_MDP_PIPE_VG, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800372 default:
373 ALOGE("%s: Invalid pipe type",__FUNCTION__);
374 return ovutils::OV_INVALID;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800375 };
376 return ovutils::OV_INVALID;
377}
378
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800379bool MDPComp::isFrameDoable(hwc_context_t *ctx) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700380 bool ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700381 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800382
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800383 if(!isEnabled()) {
384 ALOGD_IF(isDebug(),"%s: MDP Comp. not enabled.", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700385 ret = false;
Saurabh Shahd4e65852013-06-17 11:33:53 -0700386 } else if(qdutils::MDPVersion::getInstance().is8x26() &&
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700387 ctx->mVideoTransFlag && ctx->mVirtualDisplay->isConnected()) {
Saurabh Shahd4e65852013-06-17 11:33:53 -0700388 //1 Padding round to shift pipes across mixers
389 ALOGD_IF(isDebug(),"%s: MDP Comp. video transition padding round",
390 __FUNCTION__);
391 ret = false;
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700392 } else if(ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isConfiguring ||
393 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isConfiguring) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800394 ALOGD_IF( isDebug(),"%s: External Display connection is pending",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800395 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700396 ret = false;
Saurabh Shahaa236822013-04-24 18:07:26 -0700397 } else if(ctx->isPaddingRound) {
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700398 ctx->isPaddingRound = false;
399 ALOGD_IF(isDebug(), "%s: padding round",__FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700400 ret = false;
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700401 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700402 return ret;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800403}
404
405/* Checks for conditions where all the layers marked for MDP comp cannot be
406 * bypassed. On such conditions we try to bypass atleast YUV layers */
407bool MDPComp::isFullFrameDoable(hwc_context_t *ctx,
408 hwc_display_contents_1_t* list){
409
Saurabh Shahaa236822013-04-24 18:07:26 -0700410 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800411
Saurabh Shah2d998a92013-05-14 17:55:58 -0700412 if(sIdleFallBack) {
413 ALOGD_IF(isDebug(), "%s: Idle fallback dpy %d",__FUNCTION__, mDpy);
414 return false;
415 }
416
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800417 if(mDpy > HWC_DISPLAY_PRIMARY){
418 ALOGD_IF(isDebug(), "%s: Cannot support External display(s)",
419 __FUNCTION__);
420 return false;
421 }
422
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800423 if(isSkipPresent(ctx, mDpy)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700424 ALOGD_IF(isDebug(),"%s: SKIP present: %d",
425 __FUNCTION__,
426 isSkipPresent(ctx, mDpy));
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800427 return false;
428 }
429
Saurabh Shah9f084ad2013-05-02 11:28:09 -0700430 if(ctx->listStats[mDpy].needsAlphaScale
431 && ctx->mMDP.version < qdutils::MDSS_V5) {
432 ALOGD_IF(isDebug(), "%s: frame needs alpha downscaling",__FUNCTION__);
433 return false;
434 }
435
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800436 //MDP composition is not efficient if layer needs rotator.
437 for(int i = 0; i < numAppLayers; ++i) {
438 // As MDP h/w supports flip operation, use MDP comp only for
439 // 180 transforms. Fail for any transform involving 90 (90, 270).
440 hwc_layer_1_t* layer = &list->hwLayers[i];
441 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800442
Saurabh Shah4fdde762013-04-30 18:47:33 -0700443 if((layer->transform & HWC_TRANSFORM_ROT_90) && !isYuvBuffer(hnd)) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800444 ALOGD_IF(isDebug(), "%s: orientation involved",__FUNCTION__);
445 return false;
446 }
447
Saurabh Shah4fdde762013-04-30 18:47:33 -0700448 if(!isValidDimension(ctx,layer)) {
449 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
450 __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800451 return false;
452 }
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530453
454 //For 8x26 with panel width>1k, if RGB layer needs HFLIP fail mdp comp
455 // may not need it if Gfx pre-rotation can handle all flips & rotations
456 if(qdutils::MDPVersion::getInstance().is8x26() &&
457 (ctx->dpyAttr[mDpy].xres > 1024) &&
458 (layer->transform & HWC_TRANSFORM_FLIP_H) &&
459 (!isYuvBuffer(hnd)))
460 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800461 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700462
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700463 if(ctx->mAD->isDoable()) {
464 return false;
465 }
466
Saurabh Shahaa236822013-04-24 18:07:26 -0700467 //If all above hard conditions are met we can do full or partial MDP comp.
468 bool ret = false;
469 if(fullMDPComp(ctx, list)) {
470 ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700471 } else if(partialMDPComp(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700472 ret = true;
473 }
474 return ret;
475}
476
477bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
478 //Setup mCurrentFrame
479 mCurrentFrame.mdpCount = mCurrentFrame.layerCount;
480 mCurrentFrame.fbCount = 0;
481 mCurrentFrame.fbZ = -1;
482 memset(&mCurrentFrame.isFBComposed, 0, sizeof(mCurrentFrame.isFBComposed));
483
484 int mdpCount = mCurrentFrame.mdpCount;
485 if(mdpCount > sMaxPipesPerMixer) {
486 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
487 return false;
488 }
489
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700490 if(!arePipesAvailable(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700491 return false;
492 }
493
494 return true;
495}
496
497bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
498{
499 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700500
501 if(!sEnableMixedMode) {
502 //Mixed mode is disabled. No need to even try caching.
503 return false;
504 }
505
Saurabh Shahaa236822013-04-24 18:07:26 -0700506 //Setup mCurrentFrame
507 mCurrentFrame.reset(numAppLayers);
508 updateLayerCache(ctx, list);
509 updateYUV(ctx, list);
510 batchLayers(); //sets up fbZ also
511
512 int mdpCount = mCurrentFrame.mdpCount;
513 if(mdpCount > (sMaxPipesPerMixer - 1)) { // -1 since FB is used
514 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
515 return false;
516 }
517
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700518 if(!arePipesAvailable(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700519 return false;
520 }
521
522 return true;
523}
524
525bool MDPComp::isOnlyVideoDoable(hwc_context_t *ctx,
526 hwc_display_contents_1_t* list){
527 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
528 mCurrentFrame.reset(numAppLayers);
529 updateYUV(ctx, list);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700530 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700531 int fbNeeded = int(mCurrentFrame.fbCount != 0);
532
533 if(!isYuvPresent(ctx, mDpy)) {
534 return false;
535 }
536
Saurabh Shah4fdde762013-04-30 18:47:33 -0700537 if(!mdpCount)
538 return false;
539
Saurabh Shahaa236822013-04-24 18:07:26 -0700540 if(mdpCount > (sMaxPipesPerMixer - fbNeeded)) {
541 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
542 return false;
543 }
544
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700545 if(!arePipesAvailable(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700546 return false;
547 }
548
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800549 return true;
550}
551
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800552/* Checks for conditions where YUV layers cannot be bypassed */
553bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Saurabh Shahe2474082013-05-15 16:32:13 -0700554 bool extAnimBlockFeature = mDpy && ctx->listStats[mDpy].isDisplayAnimating;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800555
Saurabh Shahe2474082013-05-15 16:32:13 -0700556 if(isSkipLayer(layer) && !extAnimBlockFeature) {
557 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800558 return false;
559 }
560
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800561 if(isSecuring(ctx, layer)) {
562 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
563 return false;
564 }
565
Saurabh Shah4fdde762013-04-30 18:47:33 -0700566 if(!isValidDimension(ctx, layer)) {
567 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
568 __FUNCTION__);
569 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800570 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700571
Naseer Ahmeddc61a972013-07-10 17:50:54 -0400572 if(layer->planeAlpha < 0xFF) {
573 ALOGD_IF(isDebug(), "%s: Cannot handle YUV layer with plane alpha\
574 in video only mode",
575 __FUNCTION__);
576 return false;
577 }
578
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800579 return true;
580}
581
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800582void MDPComp::batchLayers() {
583 /* Idea is to keep as many contiguous non-updating(cached) layers in FB and
584 * send rest of them through MDP. NEVER mark an updating layer for caching.
585 * But cached ones can be marked for MDP*/
586
587 int maxBatchStart = -1;
588 int maxBatchCount = 0;
589
590 /* All or Nothing is cached. No batching needed */
Saurabh Shahaa236822013-04-24 18:07:26 -0700591 if(!mCurrentFrame.fbCount) {
592 mCurrentFrame.fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800593 return;
Saurabh Shahaa236822013-04-24 18:07:26 -0700594 }
595 if(!mCurrentFrame.mdpCount) {
596 mCurrentFrame.fbZ = 0;
597 return;
598 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800599
600 /* Search for max number of contiguous (cached) layers */
601 int i = 0;
602 while (i < mCurrentFrame.layerCount) {
603 int count = 0;
604 while(mCurrentFrame.isFBComposed[i] && i < mCurrentFrame.layerCount) {
605 count++; i++;
606 }
607 if(count > maxBatchCount) {
608 maxBatchCount = count;
609 maxBatchStart = i - count;
Saurabh Shahaa236822013-04-24 18:07:26 -0700610 mCurrentFrame.fbZ = maxBatchStart;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800611 }
612 if(i < mCurrentFrame.layerCount) i++;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800613 }
614
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800615 /* reset rest of the layers for MDP comp */
616 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
617 if(i != maxBatchStart){
618 mCurrentFrame.isFBComposed[i] = false;
619 } else {
620 i += maxBatchCount;
621 }
622 }
623
624 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700625 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
626 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800627
628 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
629 mCurrentFrame.fbCount);
630}
Saurabh Shah85234ec2013-04-12 17:09:00 -0700631
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800632void MDPComp::updateLayerCache(hwc_context_t* ctx,
633 hwc_display_contents_1_t* list) {
634
635 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
636 int numCacheableLayers = 0;
637
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800638 for(int i = 0; i < numAppLayers; i++) {
639 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
640 numCacheableLayers++;
641 mCurrentFrame.isFBComposed[i] = true;
642 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -0700643 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800644 mCachedFrame.hnd[i] = list->hwLayers[i].handle;
645 }
646 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700647
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800648 mCurrentFrame.fbCount = numCacheableLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700649 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
650 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800651 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__, numCacheableLayers);
652}
653
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800654void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list) {
655
656 int nYuvCount = ctx->listStats[mDpy].yuvCount;
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700657 if(!nYuvCount && mDpy) {
658 //Reset "No animation on external display" related parameters.
659 ctx->mPrevCropVideo.left = ctx->mPrevCropVideo.top =
660 ctx->mPrevCropVideo.right = ctx->mPrevCropVideo.bottom = 0;
661 ctx->mPrevDestVideo.left = ctx->mPrevDestVideo.top =
662 ctx->mPrevDestVideo.right = ctx->mPrevDestVideo.bottom = 0;
663 ctx->mPrevTransformVideo = 0;
664 return;
665 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800666 for(int index = 0;index < nYuvCount; index++){
667 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
668 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
669
670 if(!isYUVDoable(ctx, layer)) {
671 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
672 mCurrentFrame.isFBComposed[nYuvIndex] = true;
673 mCurrentFrame.fbCount++;
674 }
675 } else {
676 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
677 mCurrentFrame.isFBComposed[nYuvIndex] = false;
678 mCurrentFrame.fbCount--;
679 }
680 }
681 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700682
683 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
684 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800685 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
686 mCurrentFrame.fbCount);
687}
688
Saurabh Shahaa236822013-04-24 18:07:26 -0700689bool MDPComp::programMDP(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800690 if(!allocLayerPipes(ctx, list)) {
691 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700692 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800693 }
694
Saurabh Shahaa236822013-04-24 18:07:26 -0700695 bool fbBatch = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800696 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700697 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800698 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800699 int mdpIndex = mCurrentFrame.layerToMDP[index];
700 hwc_layer_1_t* layer = &list->hwLayers[index];
701
702 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
703 cur_pipe->zOrder = mdpNextZOrder++;
704
705 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
706 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
707 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -0700708 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800709 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700710 } else if(fbBatch == false) {
711 mdpNextZOrder++;
712 fbBatch = true;
713 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800714 }
715
Saurabh Shahaa236822013-04-24 18:07:26 -0700716 return true;
717}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800718
Saurabh Shahaa236822013-04-24 18:07:26 -0700719bool MDPComp::programYUV(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
720 if(!allocLayerPipes(ctx, list)) {
721 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
722 return false;
723 }
724 //If we are in this block, it means we have yuv + rgb layers both
725 int mdpIdx = 0;
726 for (int index = 0; index < mCurrentFrame.layerCount; index++) {
727 if(!mCurrentFrame.isFBComposed[index]) {
728 hwc_layer_1_t* layer = &list->hwLayers[index];
729 int mdpIndex = mCurrentFrame.layerToMDP[index];
730 MdpPipeInfo* cur_pipe =
731 mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
732 cur_pipe->zOrder = mdpIdx++;
733
734 if(configure(ctx, layer,
735 mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
736 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
737 layer %d",__FUNCTION__, index);
738 return false;
739 }
740 }
741 }
742 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800743}
744
745int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700746 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -0700747
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530748 { //LOCK SCOPE BEGIN
749 Locker::Autolock _l(mMdpCompLock);
Prabhanjan Kandula088bd892013-07-02 23:47:13 +0530750
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530751 //reset old data
Saurabh Shahaa236822013-04-24 18:07:26 -0700752 mCurrentFrame.reset(numLayers);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800753
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530754 //number of app layers exceeds MAX_NUM_APP_LAYERS fall back to GPU
755 //do not cache the information for next draw cycle.
756 if(numLayers > MAX_NUM_APP_LAYERS) {
757 mCachedFrame.updateCounts(mCurrentFrame);
758 ALOGD_IF(isDebug(), "%s: Number of App layers exceeded the limit ",
759 __FUNCTION__);
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700760 return -1;
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530761 }
762
763 //Hard conditions, if not met, cannot do MDP comp
764 if(!isFrameDoable(ctx)) {
765 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
766 __FUNCTION__);
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700767 reset(numLayers, list);
768 return -1;
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530769 }
770
771 //Check whether layers marked for MDP Composition is actually doable.
772 if(isFullFrameDoable(ctx, list)){
773 mCurrentFrame.map();
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700774 //Configure framebuffer first if applicable
775 if(mCurrentFrame.fbZ >= 0) {
776 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list,
777 mCurrentFrame.fbZ)) {
778 ALOGE("%s configure framebuffer failed", __func__);
779 reset(numLayers, list);
780 return -1;
781 }
782 }
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530783 //Acquire and Program MDP pipes
784 if(!programMDP(ctx, list)) {
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700785 reset(numLayers, list);
786 return -1;
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530787 } else { //Success
788 //Any change in composition types needs an FB refresh
789 mCurrentFrame.needsRedraw = false;
790 if(mCurrentFrame.fbCount &&
791 ((mCurrentFrame.mdpCount != mCachedFrame.mdpCount) ||
792 (mCurrentFrame.fbCount != mCachedFrame.cacheCount) ||
793 (mCurrentFrame.fbZ != mCachedFrame.fbZ) ||
794 (!mCurrentFrame.mdpCount) ||
795 (list->flags & HWC_GEOMETRY_CHANGED) ||
796 isSkipPresent(ctx, mDpy) ||
797 (mDpy > HWC_DISPLAY_PRIMARY))) {
798 mCurrentFrame.needsRedraw = true;
799 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700800 }
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530801 } else if(isOnlyVideoDoable(ctx, list)) {
802 //All layers marked for MDP comp cannot be bypassed.
803 //Try to compose atleast YUV layers through MDP comp and let
804 //all the RGB layers compose in FB
805 //Destination over
806 mCurrentFrame.fbZ = -1;
807 if(mCurrentFrame.fbCount)
808 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800809
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530810 mCurrentFrame.map();
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700811
812 //Configure framebuffer first if applicable
813 if(mCurrentFrame.fbZ >= 0) {
814 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, mCurrentFrame.fbZ)) {
815 ALOGE("%s configure framebuffer failed", __func__);
816 reset(numLayers, list);
817 return -1;
818 }
819 }
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530820 if(!programYUV(ctx, list)) {
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700821 reset(numLayers, list);
822 return -1;
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530823 }
824 } else {
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700825 reset(numLayers, list);
826 return -1;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800827 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800828
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530829 //UpdateLayerFlags
830 setMDPCompLayerFlags(ctx, list);
831 mCachedFrame.updateCounts(mCurrentFrame);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800832
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530833 } //LOCK SCOPE END. dump also need this lock.
834 // unlock it before calling dump function to avoid deadlock
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800835 if(isDebug()) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700836 ALOGD("GEOMETRY change: %d", (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800837 android::String8 sDump("");
838 dump(sDump);
839 ALOGE("%s",sDump.string());
840 }
841
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700842 return 0;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800843}
844
845//=============MDPCompLowRes===================================================
846
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700847/*
848 * Configures pipe(s) for MDP composition
849 */
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800850int MDPCompLowRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800851 PipeLayerPair& PipeLayerPair) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800852 MdpPipeInfoLowRes& mdp_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800853 *(static_cast<MdpPipeInfoLowRes*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -0800854 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
855 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
856 eIsFg isFg = IS_FG_OFF;
857 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700858
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800859 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
860 __FUNCTION__, layer, zOrder, dest);
861
862 return configureLowRes(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
863 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700864}
865
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700866bool MDPCompLowRes::arePipesAvailable(hwc_context_t *ctx,
867 hwc_display_contents_1_t* list) {
868 overlay::Overlay& ov = *ctx->mOverlay;
869 int numPipesNeeded = mCurrentFrame.mdpCount;
870 int availPipes = ov.availablePipes(mDpy, Overlay::MIXER_DEFAULT);
871
872 //Reserve pipe for FB
873 if(mCurrentFrame.fbCount)
874 availPipes -= 1;
875
876 if(numPipesNeeded > availPipes) {
877 ALOGD_IF(isDebug(), "%s: Insufficient pipes, dpy %d needed %d, avail %d",
878 __FUNCTION__, mDpy, numPipesNeeded, availPipes);
879 return false;
880 }
881
882 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700883}
884
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800885bool MDPCompLowRes::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700886 hwc_display_contents_1_t* list) {
887 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700888
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800889 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700890
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800891 hwc_layer_1_t* layer = &list->hwLayers[index];
892 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800893 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800894 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800895 info.pipeInfo = new MdpPipeInfoLowRes;
Saurabh Shahacf10202013-02-26 10:15:15 -0800896 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800897 MdpPipeInfoLowRes& pipe_info = *(MdpPipeInfoLowRes*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800898 ePipeType type = MDPCOMP_OV_ANY;
899
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700900 if(isYuvBuffer(hnd)) {
901 type = MDPCOMP_OV_VG;
Saurabh Shah8a117932013-05-23 12:48:13 -0700902 } else if(!qhwc::needsScaling(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -0700903 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
904 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800905 type = MDPCOMP_OV_DMA;
906 }
907
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700908 pipe_info.index = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800909 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700910 ALOGD_IF(isDebug(), "%s: Unable to get pipe type = %d",
911 __FUNCTION__, (int) type);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500912 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700913 }
914 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700915 return true;
916}
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700917
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800918bool MDPCompLowRes::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700919
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800920 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500921 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
922 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800923 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700924
925 if(!ctx || !list) {
926 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500927 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700928 }
929
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +0530930 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
931 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
932 return true;
933 }
934
Prabhanjan Kandula088bd892013-07-02 23:47:13 +0530935 Locker::Autolock _l(mMdpCompLock);
936
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500937 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -0700938 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500939 idleInvalidator->markForSleep();
940
941 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800942 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700943
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800944 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
945 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700946 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800947 if(mCurrentFrame.isFBComposed[i]) continue;
948
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700949 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -0800950 private_handle_t *hnd = (private_handle_t *)layer->handle;
951 if(!hnd) {
952 ALOGE("%s handle null", __FUNCTION__);
953 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700954 }
955
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800956 int mdpIndex = mCurrentFrame.layerToMDP[i];
957
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800958 MdpPipeInfoLowRes& pipe_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800959 *(MdpPipeInfoLowRes*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800960 ovutils::eDest dest = pipe_info.index;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800961 if(dest == ovutils::OV_INVALID) {
962 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500963 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700964 }
965
Saurabh Shahacf10202013-02-26 10:15:15 -0800966 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
967 continue;
968 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700969
Saurabh Shahacf10202013-02-26 10:15:15 -0800970 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800971 using pipe: %d", __FUNCTION__, layer,
972 hnd, dest );
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700973
Saurabh Shahacf10202013-02-26 10:15:15 -0800974 int fd = hnd->fd;
975 uint32_t offset = hnd->offset;
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700976
977 if(ctx->mAD->isModeOn()) {
978 if(ctx->mAD->draw(ctx, fd, offset)) {
979 fd = ctx->mAD->getDstFd(ctx);
980 offset = ctx->mAD->getDstOffset(ctx);
981 }
982 }
983
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800984 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -0800985 if(rot) {
986 if(!rot->queueBuffer(fd, offset))
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500987 return false;
Saurabh Shahacf10202013-02-26 10:15:15 -0800988 fd = rot->getDstMemId();
989 offset = rot->getDstOffset();
990 }
991
992 if (!ov.queueBuffer(fd, offset, dest)) {
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +0530993 ALOGE("%s: queueBuffer failed for display:%d ", __FUNCTION__, mDpy);
Saurabh Shahacf10202013-02-26 10:15:15 -0800994 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700995 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500996
997 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700998 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500999 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001000}
1001
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001002//=============MDPCompHighRes===================================================
1003
1004int MDPCompHighRes::pipesNeeded(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001005 hwc_display_contents_1_t* list,
1006 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001007 int pipesNeeded = 0;
Saurabh Shah67a38c32013-06-10 16:23:15 -07001008 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001009
1010 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001011
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001012 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1013 if(!mCurrentFrame.isFBComposed[i]) {
1014 hwc_layer_1_t* layer = &list->hwLayers[i];
1015 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001016 if(mixer == Overlay::MIXER_LEFT && dst.left < lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001017 pipesNeeded++;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001018 } else if(mixer == Overlay::MIXER_RIGHT && dst.right > lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001019 pipesNeeded++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001020 }
1021 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001022 }
1023 return pipesNeeded;
1024}
1025
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001026bool MDPCompHighRes::arePipesAvailable(hwc_context_t *ctx,
1027 hwc_display_contents_1_t* list) {
1028 overlay::Overlay& ov = *ctx->mOverlay;
1029
1030 for(int i = 0; i < Overlay::MIXER_MAX; i++) {
1031 int numPipesNeeded = pipesNeeded(ctx, list, i);
1032 int availPipes = ov.availablePipes(mDpy, i);
1033
1034 //Reserve pipe(s)for FB
1035 if(mCurrentFrame.fbCount)
1036 availPipes -= 1;
1037
1038 if(numPipesNeeded > availPipes) {
1039 ALOGD_IF(isDebug(), "%s: Insufficient pipes for "
1040 "dpy %d mixer %d needed %d, avail %d",
1041 __FUNCTION__, mDpy, i, numPipesNeeded, availPipes);
1042 return false;
1043 }
1044 }
1045 return true;
1046}
1047
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001048bool MDPCompHighRes::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001049 MdpPipeInfoHighRes& pipe_info,
1050 ePipeType type) {
1051 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001052 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001053
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001054 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001055 pipe_info.lIndex = ovutils::OV_INVALID;
1056 pipe_info.rIndex = ovutils::OV_INVALID;
1057
1058 if (dst.left < lSplit) {
1059 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_LEFT);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001060 if(pipe_info.lIndex == ovutils::OV_INVALID)
1061 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001062 }
1063
1064 if(dst.right > lSplit) {
1065 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_RIGHT);
1066 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001067 return false;
1068 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001069
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001070 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001071}
1072
1073bool MDPCompHighRes::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001074 hwc_display_contents_1_t* list) {
1075 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001076
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001077 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001078
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001079 hwc_layer_1_t* layer = &list->hwLayers[index];
1080 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001081 int mdpIndex = mCurrentFrame.layerToMDP[index];
1082 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001083 info.pipeInfo = new MdpPipeInfoHighRes;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001084 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001085 MdpPipeInfoHighRes& pipe_info = *(MdpPipeInfoHighRes*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001086 ePipeType type = MDPCOMP_OV_ANY;
1087
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001088 if(isYuvBuffer(hnd)) {
1089 type = MDPCOMP_OV_VG;
Saurabh Shah8a117932013-05-23 12:48:13 -07001090 } else if(!qhwc::needsScaling(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001091 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001092 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001093 type = MDPCOMP_OV_DMA;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001094 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001095
1096 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001097 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type = %d",
1098 __FUNCTION__, (int) type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001099 return false;
1100 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001101 }
1102 return true;
1103}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001104
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001105/*
1106 * Configures pipe(s) for MDP composition
1107 */
1108int MDPCompHighRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001109 PipeLayerPair& PipeLayerPair) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001110 MdpPipeInfoHighRes& mdp_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001111 *(static_cast<MdpPipeInfoHighRes*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001112 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1113 eIsFg isFg = IS_FG_OFF;
1114 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1115 eDest lDest = mdp_info.lIndex;
1116 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001117
1118 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1119 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1120
1121 return configureHighRes(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
1122 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001123}
1124
1125bool MDPCompHighRes::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
1126
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001127 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001128 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1129 return true;
1130 }
1131
1132 if(!ctx || !list) {
1133 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001134 return false;
1135 }
1136
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301137 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1138 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1139 return true;
1140 }
1141
Prabhanjan Kandula088bd892013-07-02 23:47:13 +05301142 Locker::Autolock _l(mMdpCompLock);
1143
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001144 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001145 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001146 idleInvalidator->markForSleep();
1147
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001148 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001149 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001150
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001151 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1152 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001153 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001154 if(mCurrentFrame.isFBComposed[i]) continue;
1155
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001156 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001157 private_handle_t *hnd = (private_handle_t *)layer->handle;
1158 if(!hnd) {
1159 ALOGE("%s handle null", __FUNCTION__);
1160 return false;
1161 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001162
1163 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1164 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001165 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001166
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001167 int mdpIndex = mCurrentFrame.layerToMDP[i];
1168
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001169 MdpPipeInfoHighRes& pipe_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001170 *(MdpPipeInfoHighRes*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1171 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -08001172
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001173 ovutils::eDest indexL = pipe_info.lIndex;
1174 ovutils::eDest indexR = pipe_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001175
Saurabh Shahacf10202013-02-26 10:15:15 -08001176 int fd = hnd->fd;
1177 int offset = hnd->offset;
1178
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001179 if(ctx->mAD->isModeOn()) {
1180 if(ctx->mAD->draw(ctx, fd, offset)) {
1181 fd = ctx->mAD->getDstFd(ctx);
1182 offset = ctx->mAD->getDstOffset(ctx);
1183 }
1184 }
1185
Saurabh Shahacf10202013-02-26 10:15:15 -08001186 if(rot) {
1187 rot->queueBuffer(fd, offset);
1188 fd = rot->getDstMemId();
1189 offset = rot->getDstOffset();
1190 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001191
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001192 //************* play left mixer **********
1193 if(indexL != ovutils::OV_INVALID) {
1194 ovutils::eDest destL = (ovutils::eDest)indexL;
Saurabh Shahacf10202013-02-26 10:15:15 -08001195 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001196 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
Saurabh Shahacf10202013-02-26 10:15:15 -08001197 if (!ov.queueBuffer(fd, offset, destL)) {
1198 ALOGE("%s: queueBuffer failed for left mixer", __FUNCTION__);
1199 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001200 }
1201 }
1202
1203 //************* play right mixer **********
1204 if(indexR != ovutils::OV_INVALID) {
1205 ovutils::eDest destR = (ovutils::eDest)indexR;
Saurabh Shahacf10202013-02-26 10:15:15 -08001206 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001207 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
Saurabh Shahacf10202013-02-26 10:15:15 -08001208 if (!ov.queueBuffer(fd, offset, destR)) {
1209 ALOGE("%s: queueBuffer failed for right mixer", __FUNCTION__);
1210 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001211 }
1212 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001213
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001214 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1215 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001216
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001217 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001218}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001219}; //namespace
1220