blob: e97d7690fd6a47254640d77f844cece7cee5e189 [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
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800572 return true;
573}
574
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800575void MDPComp::batchLayers() {
576 /* Idea is to keep as many contiguous non-updating(cached) layers in FB and
577 * send rest of them through MDP. NEVER mark an updating layer for caching.
578 * But cached ones can be marked for MDP*/
579
580 int maxBatchStart = -1;
581 int maxBatchCount = 0;
582
583 /* All or Nothing is cached. No batching needed */
Saurabh Shahaa236822013-04-24 18:07:26 -0700584 if(!mCurrentFrame.fbCount) {
585 mCurrentFrame.fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800586 return;
Saurabh Shahaa236822013-04-24 18:07:26 -0700587 }
588 if(!mCurrentFrame.mdpCount) {
589 mCurrentFrame.fbZ = 0;
590 return;
591 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800592
593 /* Search for max number of contiguous (cached) layers */
594 int i = 0;
595 while (i < mCurrentFrame.layerCount) {
596 int count = 0;
597 while(mCurrentFrame.isFBComposed[i] && i < mCurrentFrame.layerCount) {
598 count++; i++;
599 }
600 if(count > maxBatchCount) {
601 maxBatchCount = count;
602 maxBatchStart = i - count;
Saurabh Shahaa236822013-04-24 18:07:26 -0700603 mCurrentFrame.fbZ = maxBatchStart;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800604 }
605 if(i < mCurrentFrame.layerCount) i++;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800606 }
607
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800608 /* reset rest of the layers for MDP comp */
609 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
610 if(i != maxBatchStart){
611 mCurrentFrame.isFBComposed[i] = false;
612 } else {
613 i += maxBatchCount;
614 }
615 }
616
617 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700618 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
619 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800620
621 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
622 mCurrentFrame.fbCount);
623}
Saurabh Shah85234ec2013-04-12 17:09:00 -0700624
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800625void MDPComp::updateLayerCache(hwc_context_t* ctx,
626 hwc_display_contents_1_t* list) {
627
628 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
629 int numCacheableLayers = 0;
630
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800631 for(int i = 0; i < numAppLayers; i++) {
632 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
633 numCacheableLayers++;
634 mCurrentFrame.isFBComposed[i] = true;
635 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -0700636 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800637 mCachedFrame.hnd[i] = list->hwLayers[i].handle;
638 }
639 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700640
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800641 mCurrentFrame.fbCount = numCacheableLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700642 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
643 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800644 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__, numCacheableLayers);
645}
646
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800647void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list) {
648
649 int nYuvCount = ctx->listStats[mDpy].yuvCount;
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700650 if(!nYuvCount && mDpy) {
651 //Reset "No animation on external display" related parameters.
652 ctx->mPrevCropVideo.left = ctx->mPrevCropVideo.top =
653 ctx->mPrevCropVideo.right = ctx->mPrevCropVideo.bottom = 0;
654 ctx->mPrevDestVideo.left = ctx->mPrevDestVideo.top =
655 ctx->mPrevDestVideo.right = ctx->mPrevDestVideo.bottom = 0;
656 ctx->mPrevTransformVideo = 0;
657 return;
658 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800659 for(int index = 0;index < nYuvCount; index++){
660 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
661 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
662
663 if(!isYUVDoable(ctx, layer)) {
664 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
665 mCurrentFrame.isFBComposed[nYuvIndex] = true;
666 mCurrentFrame.fbCount++;
667 }
668 } else {
669 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
670 mCurrentFrame.isFBComposed[nYuvIndex] = false;
671 mCurrentFrame.fbCount--;
672 }
673 }
674 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700675
676 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
677 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800678 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
679 mCurrentFrame.fbCount);
680}
681
Saurabh Shahaa236822013-04-24 18:07:26 -0700682bool MDPComp::programMDP(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800683 if(!allocLayerPipes(ctx, list)) {
684 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700685 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800686 }
687
Saurabh Shahaa236822013-04-24 18:07:26 -0700688 bool fbBatch = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800689 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700690 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800691 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800692 int mdpIndex = mCurrentFrame.layerToMDP[index];
693 hwc_layer_1_t* layer = &list->hwLayers[index];
694
695 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
696 cur_pipe->zOrder = mdpNextZOrder++;
697
698 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
699 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
700 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -0700701 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800702 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700703 } else if(fbBatch == false) {
704 mdpNextZOrder++;
705 fbBatch = true;
706 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800707 }
708
Saurabh Shahaa236822013-04-24 18:07:26 -0700709 return true;
710}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800711
Saurabh Shahaa236822013-04-24 18:07:26 -0700712bool MDPComp::programYUV(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
713 if(!allocLayerPipes(ctx, list)) {
714 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
715 return false;
716 }
717 //If we are in this block, it means we have yuv + rgb layers both
718 int mdpIdx = 0;
719 for (int index = 0; index < mCurrentFrame.layerCount; index++) {
720 if(!mCurrentFrame.isFBComposed[index]) {
721 hwc_layer_1_t* layer = &list->hwLayers[index];
722 int mdpIndex = mCurrentFrame.layerToMDP[index];
723 MdpPipeInfo* cur_pipe =
724 mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
725 cur_pipe->zOrder = mdpIdx++;
726
727 if(configure(ctx, layer,
728 mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
729 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
730 layer %d",__FUNCTION__, index);
731 return false;
732 }
733 }
734 }
735 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800736}
737
738int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700739 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -0700740
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530741 { //LOCK SCOPE BEGIN
742 Locker::Autolock _l(mMdpCompLock);
Prabhanjan Kandula088bd892013-07-02 23:47:13 +0530743
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530744 //reset old data
Saurabh Shahaa236822013-04-24 18:07:26 -0700745 mCurrentFrame.reset(numLayers);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800746
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530747 //number of app layers exceeds MAX_NUM_APP_LAYERS fall back to GPU
748 //do not cache the information for next draw cycle.
749 if(numLayers > MAX_NUM_APP_LAYERS) {
750 mCachedFrame.updateCounts(mCurrentFrame);
751 ALOGD_IF(isDebug(), "%s: Number of App layers exceeded the limit ",
752 __FUNCTION__);
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700753 return -1;
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530754 }
755
756 //Hard conditions, if not met, cannot do MDP comp
757 if(!isFrameDoable(ctx)) {
758 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
759 __FUNCTION__);
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700760 reset(numLayers, list);
761 return -1;
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530762 }
763
764 //Check whether layers marked for MDP Composition is actually doable.
765 if(isFullFrameDoable(ctx, list)){
766 mCurrentFrame.map();
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700767 //Configure framebuffer first if applicable
768 if(mCurrentFrame.fbZ >= 0) {
769 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list,
770 mCurrentFrame.fbZ)) {
771 ALOGE("%s configure framebuffer failed", __func__);
772 reset(numLayers, list);
773 return -1;
774 }
775 }
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530776 //Acquire and Program MDP pipes
777 if(!programMDP(ctx, list)) {
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700778 reset(numLayers, list);
779 return -1;
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530780 } else { //Success
781 //Any change in composition types needs an FB refresh
782 mCurrentFrame.needsRedraw = false;
783 if(mCurrentFrame.fbCount &&
784 ((mCurrentFrame.mdpCount != mCachedFrame.mdpCount) ||
785 (mCurrentFrame.fbCount != mCachedFrame.cacheCount) ||
786 (mCurrentFrame.fbZ != mCachedFrame.fbZ) ||
787 (!mCurrentFrame.mdpCount) ||
788 (list->flags & HWC_GEOMETRY_CHANGED) ||
789 isSkipPresent(ctx, mDpy) ||
790 (mDpy > HWC_DISPLAY_PRIMARY))) {
791 mCurrentFrame.needsRedraw = true;
792 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700793 }
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530794 } else if(isOnlyVideoDoable(ctx, list)) {
795 //All layers marked for MDP comp cannot be bypassed.
796 //Try to compose atleast YUV layers through MDP comp and let
797 //all the RGB layers compose in FB
798 //Destination over
799 mCurrentFrame.fbZ = -1;
800 if(mCurrentFrame.fbCount)
801 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800802
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530803 mCurrentFrame.map();
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700804
805 //Configure framebuffer first if applicable
806 if(mCurrentFrame.fbZ >= 0) {
807 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, mCurrentFrame.fbZ)) {
808 ALOGE("%s configure framebuffer failed", __func__);
809 reset(numLayers, list);
810 return -1;
811 }
812 }
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530813 if(!programYUV(ctx, list)) {
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700814 reset(numLayers, list);
815 return -1;
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530816 }
817 } else {
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700818 reset(numLayers, list);
819 return -1;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800820 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800821
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530822 //UpdateLayerFlags
823 setMDPCompLayerFlags(ctx, list);
824 mCachedFrame.updateCounts(mCurrentFrame);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800825
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530826 } //LOCK SCOPE END. dump also need this lock.
827 // unlock it before calling dump function to avoid deadlock
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800828 if(isDebug()) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700829 ALOGD("GEOMETRY change: %d", (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800830 android::String8 sDump("");
831 dump(sDump);
832 ALOGE("%s",sDump.string());
833 }
834
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700835 return 0;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800836}
837
838//=============MDPCompLowRes===================================================
839
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700840/*
841 * Configures pipe(s) for MDP composition
842 */
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800843int MDPCompLowRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800844 PipeLayerPair& PipeLayerPair) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800845 MdpPipeInfoLowRes& mdp_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800846 *(static_cast<MdpPipeInfoLowRes*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -0800847 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
848 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
849 eIsFg isFg = IS_FG_OFF;
850 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700851
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800852 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
853 __FUNCTION__, layer, zOrder, dest);
854
855 return configureLowRes(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
856 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700857}
858
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700859bool MDPCompLowRes::arePipesAvailable(hwc_context_t *ctx,
860 hwc_display_contents_1_t* list) {
861 overlay::Overlay& ov = *ctx->mOverlay;
862 int numPipesNeeded = mCurrentFrame.mdpCount;
863 int availPipes = ov.availablePipes(mDpy, Overlay::MIXER_DEFAULT);
864
865 //Reserve pipe for FB
866 if(mCurrentFrame.fbCount)
867 availPipes -= 1;
868
869 if(numPipesNeeded > availPipes) {
870 ALOGD_IF(isDebug(), "%s: Insufficient pipes, dpy %d needed %d, avail %d",
871 __FUNCTION__, mDpy, numPipesNeeded, availPipes);
872 return false;
873 }
874
875 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700876}
877
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800878bool MDPCompLowRes::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700879 hwc_display_contents_1_t* list) {
880 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700881
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800882 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700883
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800884 hwc_layer_1_t* layer = &list->hwLayers[index];
885 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800886 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800887 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800888 info.pipeInfo = new MdpPipeInfoLowRes;
Saurabh Shahacf10202013-02-26 10:15:15 -0800889 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800890 MdpPipeInfoLowRes& pipe_info = *(MdpPipeInfoLowRes*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800891 ePipeType type = MDPCOMP_OV_ANY;
892
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700893 if(isYuvBuffer(hnd)) {
894 type = MDPCOMP_OV_VG;
Saurabh Shah8a117932013-05-23 12:48:13 -0700895 } else if(!qhwc::needsScaling(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -0700896 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
897 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800898 type = MDPCOMP_OV_DMA;
899 }
900
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700901 pipe_info.index = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800902 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700903 ALOGD_IF(isDebug(), "%s: Unable to get pipe type = %d",
904 __FUNCTION__, (int) type);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500905 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700906 }
907 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700908 return true;
909}
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700910
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800911bool MDPCompLowRes::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700912
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800913 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500914 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
915 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800916 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700917
918 if(!ctx || !list) {
919 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500920 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700921 }
922
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +0530923 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
924 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
925 return true;
926 }
927
Prabhanjan Kandula088bd892013-07-02 23:47:13 +0530928 Locker::Autolock _l(mMdpCompLock);
929
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500930 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -0700931 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500932 idleInvalidator->markForSleep();
933
934 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800935 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700936
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800937 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
938 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700939 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800940 if(mCurrentFrame.isFBComposed[i]) continue;
941
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700942 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -0800943 private_handle_t *hnd = (private_handle_t *)layer->handle;
944 if(!hnd) {
945 ALOGE("%s handle null", __FUNCTION__);
946 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700947 }
948
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800949 int mdpIndex = mCurrentFrame.layerToMDP[i];
950
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800951 MdpPipeInfoLowRes& pipe_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800952 *(MdpPipeInfoLowRes*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800953 ovutils::eDest dest = pipe_info.index;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800954 if(dest == ovutils::OV_INVALID) {
955 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500956 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700957 }
958
Saurabh Shahacf10202013-02-26 10:15:15 -0800959 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
960 continue;
961 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700962
Saurabh Shahacf10202013-02-26 10:15:15 -0800963 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800964 using pipe: %d", __FUNCTION__, layer,
965 hnd, dest );
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700966
Saurabh Shahacf10202013-02-26 10:15:15 -0800967 int fd = hnd->fd;
968 uint32_t offset = hnd->offset;
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700969
970 if(ctx->mAD->isModeOn()) {
971 if(ctx->mAD->draw(ctx, fd, offset)) {
972 fd = ctx->mAD->getDstFd(ctx);
973 offset = ctx->mAD->getDstOffset(ctx);
974 }
975 }
976
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800977 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -0800978 if(rot) {
979 if(!rot->queueBuffer(fd, offset))
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500980 return false;
Saurabh Shahacf10202013-02-26 10:15:15 -0800981 fd = rot->getDstMemId();
982 offset = rot->getDstOffset();
983 }
984
985 if (!ov.queueBuffer(fd, offset, dest)) {
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +0530986 ALOGE("%s: queueBuffer failed for display:%d ", __FUNCTION__, mDpy);
Saurabh Shahacf10202013-02-26 10:15:15 -0800987 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700988 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500989
990 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700991 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500992 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700993}
994
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800995//=============MDPCompHighRes===================================================
996
997int MDPCompHighRes::pipesNeeded(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700998 hwc_display_contents_1_t* list,
999 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001000 int pipesNeeded = 0;
Saurabh Shah67a38c32013-06-10 16:23:15 -07001001 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001002
1003 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001004
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001005 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1006 if(!mCurrentFrame.isFBComposed[i]) {
1007 hwc_layer_1_t* layer = &list->hwLayers[i];
1008 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001009 if(mixer == Overlay::MIXER_LEFT && dst.left < lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001010 pipesNeeded++;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001011 } else if(mixer == Overlay::MIXER_RIGHT && dst.right > lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001012 pipesNeeded++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001013 }
1014 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001015 }
1016 return pipesNeeded;
1017}
1018
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001019bool MDPCompHighRes::arePipesAvailable(hwc_context_t *ctx,
1020 hwc_display_contents_1_t* list) {
1021 overlay::Overlay& ov = *ctx->mOverlay;
1022
1023 for(int i = 0; i < Overlay::MIXER_MAX; i++) {
1024 int numPipesNeeded = pipesNeeded(ctx, list, i);
1025 int availPipes = ov.availablePipes(mDpy, i);
1026
1027 //Reserve pipe(s)for FB
1028 if(mCurrentFrame.fbCount)
1029 availPipes -= 1;
1030
1031 if(numPipesNeeded > availPipes) {
1032 ALOGD_IF(isDebug(), "%s: Insufficient pipes for "
1033 "dpy %d mixer %d needed %d, avail %d",
1034 __FUNCTION__, mDpy, i, numPipesNeeded, availPipes);
1035 return false;
1036 }
1037 }
1038 return true;
1039}
1040
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001041bool MDPCompHighRes::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001042 MdpPipeInfoHighRes& pipe_info,
1043 ePipeType type) {
1044 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001045 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001046
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001047 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001048 pipe_info.lIndex = ovutils::OV_INVALID;
1049 pipe_info.rIndex = ovutils::OV_INVALID;
1050
1051 if (dst.left < lSplit) {
1052 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_LEFT);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001053 if(pipe_info.lIndex == ovutils::OV_INVALID)
1054 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001055 }
1056
1057 if(dst.right > lSplit) {
1058 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_RIGHT);
1059 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001060 return false;
1061 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001062
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001063 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001064}
1065
1066bool MDPCompHighRes::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001067 hwc_display_contents_1_t* list) {
1068 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001069
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001070 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001071
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001072 hwc_layer_1_t* layer = &list->hwLayers[index];
1073 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001074 int mdpIndex = mCurrentFrame.layerToMDP[index];
1075 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001076 info.pipeInfo = new MdpPipeInfoHighRes;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001077 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001078 MdpPipeInfoHighRes& pipe_info = *(MdpPipeInfoHighRes*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001079 ePipeType type = MDPCOMP_OV_ANY;
1080
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001081 if(isYuvBuffer(hnd)) {
1082 type = MDPCOMP_OV_VG;
Saurabh Shah8a117932013-05-23 12:48:13 -07001083 } else if(!qhwc::needsScaling(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001084 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001085 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001086 type = MDPCOMP_OV_DMA;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001087 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001088
1089 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001090 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type = %d",
1091 __FUNCTION__, (int) type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001092 return false;
1093 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001094 }
1095 return true;
1096}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001097
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001098/*
1099 * Configures pipe(s) for MDP composition
1100 */
1101int MDPCompHighRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001102 PipeLayerPair& PipeLayerPair) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001103 MdpPipeInfoHighRes& mdp_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001104 *(static_cast<MdpPipeInfoHighRes*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001105 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1106 eIsFg isFg = IS_FG_OFF;
1107 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1108 eDest lDest = mdp_info.lIndex;
1109 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001110
1111 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1112 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1113
1114 return configureHighRes(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
1115 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001116}
1117
1118bool MDPCompHighRes::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
1119
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001120 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001121 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1122 return true;
1123 }
1124
1125 if(!ctx || !list) {
1126 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001127 return false;
1128 }
1129
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301130 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1131 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1132 return true;
1133 }
1134
Prabhanjan Kandula088bd892013-07-02 23:47:13 +05301135 Locker::Autolock _l(mMdpCompLock);
1136
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001137 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001138 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001139 idleInvalidator->markForSleep();
1140
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001141 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001142 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001143
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001144 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1145 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001146 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001147 if(mCurrentFrame.isFBComposed[i]) continue;
1148
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001149 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001150 private_handle_t *hnd = (private_handle_t *)layer->handle;
1151 if(!hnd) {
1152 ALOGE("%s handle null", __FUNCTION__);
1153 return false;
1154 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001155
1156 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1157 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001158 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001159
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001160 int mdpIndex = mCurrentFrame.layerToMDP[i];
1161
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001162 MdpPipeInfoHighRes& pipe_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001163 *(MdpPipeInfoHighRes*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1164 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -08001165
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001166 ovutils::eDest indexL = pipe_info.lIndex;
1167 ovutils::eDest indexR = pipe_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001168
Saurabh Shahacf10202013-02-26 10:15:15 -08001169 int fd = hnd->fd;
1170 int offset = hnd->offset;
1171
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001172 if(ctx->mAD->isModeOn()) {
1173 if(ctx->mAD->draw(ctx, fd, offset)) {
1174 fd = ctx->mAD->getDstFd(ctx);
1175 offset = ctx->mAD->getDstOffset(ctx);
1176 }
1177 }
1178
Saurabh Shahacf10202013-02-26 10:15:15 -08001179 if(rot) {
1180 rot->queueBuffer(fd, offset);
1181 fd = rot->getDstMemId();
1182 offset = rot->getDstOffset();
1183 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001184
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001185 //************* play left mixer **********
1186 if(indexL != ovutils::OV_INVALID) {
1187 ovutils::eDest destL = (ovutils::eDest)indexL;
Saurabh Shahacf10202013-02-26 10:15:15 -08001188 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001189 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
Saurabh Shahacf10202013-02-26 10:15:15 -08001190 if (!ov.queueBuffer(fd, offset, destL)) {
1191 ALOGE("%s: queueBuffer failed for left mixer", __FUNCTION__);
1192 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001193 }
1194 }
1195
1196 //************* play right mixer **********
1197 if(indexR != ovutils::OV_INVALID) {
1198 ovutils::eDest destR = (ovutils::eDest)indexR;
Saurabh Shahacf10202013-02-26 10:15:15 -08001199 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001200 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
Saurabh Shahacf10202013-02-26 10:15:15 -08001201 if (!ov.queueBuffer(fd, offset, destR)) {
1202 ALOGE("%s: queueBuffer failed for right mixer", __FUNCTION__);
1203 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001204 }
1205 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001206
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001207 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1208 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001209
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001210 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001211}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001212}; //namespace
1213