blob: d7366fb57b7caa28d62bac0b95b3f871b6f260ea [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"
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -080023#include "qdMetaData.h"
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -080024#include "mdp_version.h"
Saurabh Shahacf10202013-02-26 10:15:15 -080025#include <overlayRotator.h>
26
Saurabh Shah85234ec2013-04-12 17:09:00 -070027using namespace overlay;
Saurabh Shahbd2d0832013-04-04 14:33:08 -070028using namespace qdutils;
Saurabh Shahacf10202013-02-26 10:15:15 -080029using namespace overlay::utils;
30namespace ovutils = overlay::utils;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070031
Naseer Ahmed7c958d42012-07-31 18:57:03 -070032namespace qhwc {
33
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080034//==============MDPComp========================================================
35
Naseer Ahmed7c958d42012-07-31 18:57:03 -070036IdleInvalidator *MDPComp::idleInvalidator = NULL;
37bool MDPComp::sIdleFallBack = false;
38bool MDPComp::sDebugLogs = false;
Naseer Ahmed54821fe2012-11-28 18:44:38 -050039bool MDPComp::sEnabled = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080040int MDPComp::sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070041
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080042MDPComp* MDPComp::getObject(const int& width, int dpy) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080043 if(width <= MAX_DISPLAY_DIM) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080044 return new MDPCompLowRes(dpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080045 } else {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080046 return new MDPCompHighRes(dpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080047 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080048}
49
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080050MDPComp::MDPComp(int dpy):mDpy(dpy){};
51
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080052void MDPComp::dump(android::String8& buf)
53{
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080054 dumpsys_log(buf,"HWC Map for Dpy: %s \n",
55 mDpy ? "\"EXTERNAL\"" : "\"PRIMARY\"");
56 dumpsys_log(buf,"PREV_FRAME: layerCount:%2d mdpCount:%2d \
57 cacheCount:%2d \n", mCachedFrame.layerCount,
58 mCachedFrame.mdpCount, mCachedFrame.cacheCount);
59 dumpsys_log(buf,"CURR_FRAME: layerCount:%2d mdpCount:%2d \
60 fbCount:%2d \n", mCurrentFrame.layerCount,
61 mCurrentFrame.mdpCount, mCurrentFrame.fbCount);
62 dumpsys_log(buf,"needsFBRedraw:%3s pipesUsed:%2d MaxPipesPerMixer: %d \n",
63 (mCurrentFrame.needsRedraw? "YES" : "NO"),
64 mCurrentFrame.mdpCount, sMaxPipesPerMixer);
65 dumpsys_log(buf," --------------------------------------------- \n");
66 dumpsys_log(buf," listIdx | cached? | mdpIndex | comptype | Z \n");
67 dumpsys_log(buf," --------------------------------------------- \n");
68 for(int index = 0; index < mCurrentFrame.layerCount; index++ )
69 dumpsys_log(buf," %7d | %7s | %8d | %9s | %2d \n",
70 index,
71 (mCurrentFrame.isFBComposed[index] ? "YES" : "NO"),
72 mCurrentFrame.layerToMDP[index],
73 (mCurrentFrame.isFBComposed[index] ?
74 (mCurrentFrame.needsRedraw ? "GLES" : "CACHE") : "MDP"),
75 (mCurrentFrame.isFBComposed[index] ? mCurrentFrame.fbZ :
76 mCurrentFrame.mdpToLayer[mCurrentFrame.layerToMDP[index]].pipeInfo->zOrder));
77 dumpsys_log(buf,"\n");
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080078}
79
80bool MDPComp::init(hwc_context_t *ctx) {
81
82 if(!ctx) {
83 ALOGE("%s: Invalid hwc context!!",__FUNCTION__);
84 return false;
85 }
86
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080087 char property[PROPERTY_VALUE_MAX];
88
89 sEnabled = false;
90 if((property_get("persist.hwc.mdpcomp.enable", property, NULL) > 0) &&
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080091 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
92 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080093 sEnabled = true;
Xiaoming Zhou944e02e2013-05-01 20:54:03 -040094 if(!setupBasePipe(ctx)) {
95 ALOGE("%s: Failed to setup primary base pipe", __FUNCTION__);
96 return false;
97 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080098 }
99
100 sDebugLogs = false;
101 if(property_get("debug.mdpcomp.logs", property, NULL) > 0) {
102 if(atoi(property) != 0)
103 sDebugLogs = true;
104 }
105
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800106 sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
Saurabh Shah85234ec2013-04-12 17:09:00 -0700107 if(property_get("debug.mdpcomp.maxpermixer", property, "-1") > 0) {
108 int val = atoi(property);
109 if(val >= 0)
110 sMaxPipesPerMixer = min(val, MAX_PIPES_PER_MIXER);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800111 }
112
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800113 unsigned long idle_timeout = DEFAULT_IDLE_TIME;
114 if(property_get("debug.mdpcomp.idletime", property, NULL) > 0) {
115 if(atoi(property) != 0)
116 idle_timeout = atoi(property);
117 }
118
119 //create Idle Invalidator
120 idleInvalidator = IdleInvalidator::getInstance();
121
122 if(idleInvalidator == NULL) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800123 ALOGE("%s: failed to instantiate idleInvalidator object", __FUNCTION__);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800124 } else {
125 idleInvalidator->init(timeout_handler, ctx, idle_timeout);
126 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700127 return true;
128}
129
130void MDPComp::timeout_handler(void *udata) {
131 struct hwc_context_t* ctx = (struct hwc_context_t*)(udata);
132
133 if(!ctx) {
134 ALOGE("%s: received empty data in timer callback", __FUNCTION__);
135 return;
136 }
137
Jesse Hall3be78d92012-08-21 15:12:23 -0700138 if(!ctx->proc) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700139 ALOGE("%s: HWC proc not registered", __FUNCTION__);
140 return;
141 }
142 sIdleFallBack = true;
143 /* Trigger SF to redraw the current frame */
Jesse Hall3be78d92012-08-21 15:12:23 -0700144 ctx->proc->invalidate(ctx->proc);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700145}
146
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800147void MDPComp::setMDPCompLayerFlags(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800148 hwc_display_contents_1_t* list) {
149 LayerProp *layerProp = ctx->layerProp[mDpy];
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800150
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800151 for(int index = 0; index < ctx->listStats[mDpy].numAppLayers; index++) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800152 hwc_layer_1_t* layer = &(list->hwLayers[index]);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800153 if(!mCurrentFrame.isFBComposed[index]) {
154 layerProp[index].mFlags |= HWC_MDPCOMP;
155 layer->compositionType = HWC_OVERLAY;
156 layer->hints |= HWC_HINT_CLEAR_FB;
157 mCachedFrame.hnd[index] = NULL;
158 } else {
159 if(!mCurrentFrame.needsRedraw)
160 layer->compositionType = HWC_OVERLAY;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800161 }
162 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700163}
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500164
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800165/*
166 * Sets up BORDERFILL as default base pipe and detaches RGB0.
167 * Framebuffer is always updated using PLAY ioctl.
168 */
169bool MDPComp::setupBasePipe(hwc_context_t *ctx) {
170 const int dpy = HWC_DISPLAY_PRIMARY;
171 int fb_stride = ctx->dpyAttr[dpy].stride;
172 int fb_width = ctx->dpyAttr[dpy].xres;
173 int fb_height = ctx->dpyAttr[dpy].yres;
174 int fb_fd = ctx->dpyAttr[dpy].fd;
175
176 mdp_overlay ovInfo;
177 msmfb_overlay_data ovData;
178 memset(&ovInfo, 0, sizeof(mdp_overlay));
179 memset(&ovData, 0, sizeof(msmfb_overlay_data));
180
181 ovInfo.src.format = MDP_RGB_BORDERFILL;
182 ovInfo.src.width = fb_width;
183 ovInfo.src.height = fb_height;
184 ovInfo.src_rect.w = fb_width;
185 ovInfo.src_rect.h = fb_height;
186 ovInfo.dst_rect.w = fb_width;
187 ovInfo.dst_rect.h = fb_height;
188 ovInfo.id = MSMFB_NEW_REQUEST;
189
190 if (ioctl(fb_fd, MSMFB_OVERLAY_SET, &ovInfo) < 0) {
191 ALOGE("Failed to call ioctl MSMFB_OVERLAY_SET err=%s",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800192 strerror(errno));
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800193 return false;
194 }
195
196 ovData.id = ovInfo.id;
197 if (ioctl(fb_fd, MSMFB_OVERLAY_PLAY, &ovData) < 0) {
198 ALOGE("Failed to call ioctl MSMFB_OVERLAY_PLAY err=%s",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800199 strerror(errno));
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800200 return false;
201 }
202 return true;
203}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800204MDPComp::FrameInfo::FrameInfo() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700205 reset(0);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800206}
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800207
Saurabh Shahaa236822013-04-24 18:07:26 -0700208void MDPComp::FrameInfo::reset(const int& numLayers) {
209 for(int i = 0 ; i < MAX_PIPES_PER_MIXER && numLayers; i++ ) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800210 if(mdpToLayer[i].pipeInfo) {
211 delete mdpToLayer[i].pipeInfo;
212 mdpToLayer[i].pipeInfo = NULL;
213 //We dont own the rotator
214 mdpToLayer[i].rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800215 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800216 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800217
218 memset(&mdpToLayer, 0, sizeof(mdpToLayer));
219 memset(&layerToMDP, -1, sizeof(layerToMDP));
Saurabh Shahaa236822013-04-24 18:07:26 -0700220 memset(&isFBComposed, 1, sizeof(isFBComposed));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800221
Saurabh Shahaa236822013-04-24 18:07:26 -0700222 layerCount = numLayers;
223 fbCount = numLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800224 mdpCount = 0;
Saurabh Shah2f3895f2013-05-02 10:13:31 -0700225 needsRedraw = true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800226 fbZ = 0;
227}
228
Saurabh Shahaa236822013-04-24 18:07:26 -0700229void MDPComp::FrameInfo::map() {
230 // populate layer and MDP maps
231 int mdpIdx = 0;
232 for(int idx = 0; idx < layerCount; idx++) {
233 if(!isFBComposed[idx]) {
234 mdpToLayer[mdpIdx].listIndex = idx;
235 layerToMDP[idx] = mdpIdx++;
236 }
237 }
238}
239
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800240MDPComp::LayerCache::LayerCache() {
241 reset();
242}
243
244void MDPComp::LayerCache::reset() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700245 memset(&hnd, 0, sizeof(hnd));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800246 mdpCount = 0;
247 cacheCount = 0;
248 layerCount = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -0700249 fbZ = -1;
250}
251
252void MDPComp::LayerCache::cacheAll(hwc_display_contents_1_t* list) {
253 const int numAppLayers = list->numHwLayers - 1;
254 for(int i = 0; i < numAppLayers; i++) {
255 hnd[i] = list->hwLayers[i].handle;
256 }
257}
258
259void MDPComp::LayerCache::updateCounts(const FrameInfo& curFrame) {
260 mdpCount = curFrame.mdpCount;
261 cacheCount = curFrame.fbCount;
262 layerCount = curFrame.layerCount;
263 fbZ = curFrame.fbZ;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800264}
265
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530266bool MDPComp::isValidDimension(hwc_context_t *ctx, hwc_layer_1_t *layer) {
Saurabh Shah4fdde762013-04-30 18:47:33 -0700267 const int dpy = HWC_DISPLAY_PRIMARY;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800268 private_handle_t *hnd = (private_handle_t *)layer->handle;
269
270 if(!hnd) {
271 ALOGE("%s: layer handle is NULL", __FUNCTION__);
272 return false;
273 }
274
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800275 int hw_w = ctx->dpyAttr[mDpy].xres;
276 int hw_h = ctx->dpyAttr[mDpy].yres;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800277
Saurabh Shah4fdde762013-04-30 18:47:33 -0700278 hwc_rect_t crop = layer->sourceCrop;
279 hwc_rect_t dst = layer->displayFrame;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800280
281 if(dst.left < 0 || dst.top < 0 || dst.right > hw_w || dst.bottom > hw_h) {
Saurabh Shah4fdde762013-04-30 18:47:33 -0700282 hwc_rect_t scissor = {0, 0, hw_w, hw_h };
283 qhwc::calculate_crop_rects(crop, dst, scissor, layer->transform);
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800284 }
285
Saurabh Shah4fdde762013-04-30 18:47:33 -0700286 int crop_w = crop.right - crop.left;
287 int crop_h = crop.bottom - crop.top;
288 int dst_w = dst.right - dst.left;
289 int dst_h = dst.bottom - dst.top;
290 float w_dscale = ceilf((float)crop_w / (float)dst_w);
291 float h_dscale = ceilf((float)crop_h / (float)dst_h);
292
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800293 /* Workaround for MDP HW limitation in DSI command mode panels where
294 * FPS will not go beyond 30 if buffers on RGB pipes are of width or height
295 * less than 5 pixels
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530296 * There also is a HW limilation in MDP, minimum block size is 2x2
297 * Fallback to GPU if height is less than 2.
298 */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800299 if((crop_w < 5)||(crop_h < 5))
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800300 return false;
301
Saurabh Shah4fdde762013-04-30 18:47:33 -0700302 const uint32_t downscale =
303 qdutils::MDPVersion::getInstance().getMaxMDPDownscale();
304 if(ctx->mMDP.version >= qdutils::MDSS_V5) {
305 /* Workaround for downscales larger than 4x.
306 * Will be removed once decimator block is enabled for MDSS
307 */
308 if(!qdutils::MDPVersion::getInstance().supportsDecimation()) {
309 if(crop_w > MAX_DISPLAY_DIM || w_dscale > downscale ||
310 h_dscale > downscale)
311 return false;
312 } else {
313 if(w_dscale > 64 || h_dscale > 64)
314 return false;
315 }
316 } else { //A-family
317 if(w_dscale > downscale || h_dscale > downscale)
318 return false;
319 }
320
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800321 return true;
322}
323
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800324ovutils::eDest MDPComp::getMdpPipe(hwc_context_t *ctx, ePipeType type) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800325 overlay::Overlay& ov = *ctx->mOverlay;
326 ovutils::eDest mdp_pipe = ovutils::OV_INVALID;
327
328 switch(type) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800329 case MDPCOMP_OV_DMA:
330 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_DMA, mDpy);
331 if(mdp_pipe != ovutils::OV_INVALID) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800332 return mdp_pipe;
333 }
334 case MDPCOMP_OV_ANY:
335 case MDPCOMP_OV_RGB:
336 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy);
337 if(mdp_pipe != ovutils::OV_INVALID) {
338 return mdp_pipe;
339 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800340
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800341 if(type == MDPCOMP_OV_RGB) {
342 //Requested only for RGB pipe
343 break;
344 }
345 case MDPCOMP_OV_VG:
346 return ov.nextPipe(ovutils::OV_MDP_PIPE_VG, mDpy);
347 default:
348 ALOGE("%s: Invalid pipe type",__FUNCTION__);
349 return ovutils::OV_INVALID;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800350 };
351 return ovutils::OV_INVALID;
352}
353
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800354bool MDPComp::isFrameDoable(hwc_context_t *ctx) {
355 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700356 bool ret = true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800357
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800358 if(!isEnabled()) {
359 ALOGD_IF(isDebug(),"%s: MDP Comp. not enabled.", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700360 ret = false;
361 } else if(ctx->mExtDispConfiguring) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800362 ALOGD_IF( isDebug(),"%s: External Display connection is pending",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800363 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700364 ret = false;
Saurabh Shahaa236822013-04-24 18:07:26 -0700365 } else if(ctx->isPaddingRound) {
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700366 ctx->isPaddingRound = false;
367 ALOGD_IF(isDebug(), "%s: padding round",__FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700368 ret = false;
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700369 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700370 return ret;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800371}
372
373/* Checks for conditions where all the layers marked for MDP comp cannot be
374 * bypassed. On such conditions we try to bypass atleast YUV layers */
375bool MDPComp::isFullFrameDoable(hwc_context_t *ctx,
376 hwc_display_contents_1_t* list){
377
Saurabh Shahaa236822013-04-24 18:07:26 -0700378 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800379
Saurabh Shah2d998a92013-05-14 17:55:58 -0700380 if(sIdleFallBack) {
381 ALOGD_IF(isDebug(), "%s: Idle fallback dpy %d",__FUNCTION__, mDpy);
382 return false;
383 }
384
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800385 if(mDpy > HWC_DISPLAY_PRIMARY){
386 ALOGD_IF(isDebug(), "%s: Cannot support External display(s)",
387 __FUNCTION__);
388 return false;
389 }
390
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800391 if(isSkipPresent(ctx, mDpy)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700392 ALOGD_IF(isDebug(),"%s: SKIP present: %d",
393 __FUNCTION__,
394 isSkipPresent(ctx, mDpy));
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800395 return false;
396 }
397
Saurabh Shah9f084ad2013-05-02 11:28:09 -0700398 if(ctx->listStats[mDpy].needsAlphaScale
399 && ctx->mMDP.version < qdutils::MDSS_V5) {
400 ALOGD_IF(isDebug(), "%s: frame needs alpha downscaling",__FUNCTION__);
401 return false;
402 }
403
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800404 //MDP composition is not efficient if layer needs rotator.
405 for(int i = 0; i < numAppLayers; ++i) {
406 // As MDP h/w supports flip operation, use MDP comp only for
407 // 180 transforms. Fail for any transform involving 90 (90, 270).
408 hwc_layer_1_t* layer = &list->hwLayers[i];
409 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800410
Saurabh Shah4fdde762013-04-30 18:47:33 -0700411 if((layer->transform & HWC_TRANSFORM_ROT_90) && !isYuvBuffer(hnd)) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800412 ALOGD_IF(isDebug(), "%s: orientation involved",__FUNCTION__);
413 return false;
414 }
415
Saurabh Shah4fdde762013-04-30 18:47:33 -0700416 if(!isValidDimension(ctx,layer)) {
417 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
418 __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800419 return false;
420 }
421 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700422
423 //If all above hard conditions are met we can do full or partial MDP comp.
424 bool ret = false;
425 if(fullMDPComp(ctx, list)) {
426 ret = true;
427 } else if (partialMDPComp(ctx, list)) {
428 ret = true;
429 }
430 return ret;
431}
432
433bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
434 //Setup mCurrentFrame
435 mCurrentFrame.mdpCount = mCurrentFrame.layerCount;
436 mCurrentFrame.fbCount = 0;
437 mCurrentFrame.fbZ = -1;
438 memset(&mCurrentFrame.isFBComposed, 0, sizeof(mCurrentFrame.isFBComposed));
439
440 int mdpCount = mCurrentFrame.mdpCount;
441 if(mdpCount > sMaxPipesPerMixer) {
442 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
443 return false;
444 }
445
446 int numPipesNeeded = pipesNeeded(ctx, list);
447 int availPipes = getAvailablePipes(ctx);
448
449 if(numPipesNeeded > availPipes) {
450 ALOGD_IF(isDebug(), "%s: Insufficient MDP pipes, needed %d, avail %d",
451 __FUNCTION__, numPipesNeeded, availPipes);
452 return false;
453 }
454
455 return true;
456}
457
458bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
459{
460 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
461 //Setup mCurrentFrame
462 mCurrentFrame.reset(numAppLayers);
463 updateLayerCache(ctx, list);
464 updateYUV(ctx, list);
465 batchLayers(); //sets up fbZ also
466
467 int mdpCount = mCurrentFrame.mdpCount;
468 if(mdpCount > (sMaxPipesPerMixer - 1)) { // -1 since FB is used
469 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
470 return false;
471 }
472
473 int numPipesNeeded = pipesNeeded(ctx, list);
474 int availPipes = getAvailablePipes(ctx);
475
476 if(numPipesNeeded > availPipes) {
477 ALOGD_IF(isDebug(), "%s: Insufficient MDP pipes, needed %d, avail %d",
478 __FUNCTION__, numPipesNeeded, availPipes);
479 return false;
480 }
481
482 return true;
483}
484
485bool MDPComp::isOnlyVideoDoable(hwc_context_t *ctx,
486 hwc_display_contents_1_t* list){
487 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
488 mCurrentFrame.reset(numAppLayers);
489 updateYUV(ctx, list);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700490 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700491 int fbNeeded = int(mCurrentFrame.fbCount != 0);
492
493 if(!isYuvPresent(ctx, mDpy)) {
494 return false;
495 }
496
Saurabh Shah4fdde762013-04-30 18:47:33 -0700497 if(!mdpCount)
498 return false;
499
Saurabh Shahaa236822013-04-24 18:07:26 -0700500 if(mdpCount > (sMaxPipesPerMixer - fbNeeded)) {
501 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
502 return false;
503 }
504
505 int numPipesNeeded = pipesNeeded(ctx, list);
506 int availPipes = getAvailablePipes(ctx);
507 if(numPipesNeeded > availPipes) {
508 ALOGD_IF(isDebug(), "%s: Insufficient MDP pipes, needed %d, avail %d",
509 __FUNCTION__, numPipesNeeded, availPipes);
510 return false;
511 }
512
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800513 return true;
514}
515
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800516/* Checks for conditions where YUV layers cannot be bypassed */
517bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Saurabh Shahe2474082013-05-15 16:32:13 -0700518 bool extAnimBlockFeature = mDpy && ctx->listStats[mDpy].isDisplayAnimating;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800519
Saurabh Shahe2474082013-05-15 16:32:13 -0700520 if(isSkipLayer(layer) && !extAnimBlockFeature) {
521 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800522 return false;
523 }
524
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800525 if(isSecuring(ctx, layer)) {
526 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
527 return false;
528 }
529
Saurabh Shah4fdde762013-04-30 18:47:33 -0700530 if(!isValidDimension(ctx, layer)) {
531 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
532 __FUNCTION__);
533 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800534 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700535
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800536 return true;
537}
538
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800539void MDPComp::batchLayers() {
540 /* Idea is to keep as many contiguous non-updating(cached) layers in FB and
541 * send rest of them through MDP. NEVER mark an updating layer for caching.
542 * But cached ones can be marked for MDP*/
543
544 int maxBatchStart = -1;
545 int maxBatchCount = 0;
546
547 /* All or Nothing is cached. No batching needed */
Saurabh Shahaa236822013-04-24 18:07:26 -0700548 if(!mCurrentFrame.fbCount) {
549 mCurrentFrame.fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800550 return;
Saurabh Shahaa236822013-04-24 18:07:26 -0700551 }
552 if(!mCurrentFrame.mdpCount) {
553 mCurrentFrame.fbZ = 0;
554 return;
555 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800556
557 /* Search for max number of contiguous (cached) layers */
558 int i = 0;
559 while (i < mCurrentFrame.layerCount) {
560 int count = 0;
561 while(mCurrentFrame.isFBComposed[i] && i < mCurrentFrame.layerCount) {
562 count++; i++;
563 }
564 if(count > maxBatchCount) {
565 maxBatchCount = count;
566 maxBatchStart = i - count;
Saurabh Shahaa236822013-04-24 18:07:26 -0700567 mCurrentFrame.fbZ = maxBatchStart;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800568 }
569 if(i < mCurrentFrame.layerCount) i++;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800570 }
571
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800572 /* reset rest of the layers for MDP comp */
573 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
574 if(i != maxBatchStart){
575 mCurrentFrame.isFBComposed[i] = false;
576 } else {
577 i += maxBatchCount;
578 }
579 }
580
581 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700582 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
583 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800584
585 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
586 mCurrentFrame.fbCount);
587}
Saurabh Shah85234ec2013-04-12 17:09:00 -0700588
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800589void MDPComp::updateLayerCache(hwc_context_t* ctx,
590 hwc_display_contents_1_t* list) {
591
592 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
593 int numCacheableLayers = 0;
594
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800595 for(int i = 0; i < numAppLayers; i++) {
596 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
597 numCacheableLayers++;
598 mCurrentFrame.isFBComposed[i] = true;
599 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -0700600 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800601 mCachedFrame.hnd[i] = list->hwLayers[i].handle;
602 }
603 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700604
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800605 mCurrentFrame.fbCount = numCacheableLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700606 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
607 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800608 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__, numCacheableLayers);
609}
610
611int MDPComp::getAvailablePipes(hwc_context_t* ctx) {
612 int numDMAPipes = qdutils::MDPVersion::getInstance().getDMAPipes();
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800613 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800614
615 int numAvailable = ov.availablePipes(mDpy);
616
617 //Reserve DMA for rotator
Saurabh Shah85234ec2013-04-12 17:09:00 -0700618 if(Overlay::getDMAMode() == Overlay::DMA_BLOCK_MODE)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800619 numAvailable -= numDMAPipes;
620
621 //Reserve pipe(s)for FB
622 if(mCurrentFrame.fbCount)
623 numAvailable -= pipesForFB();
624
625 return numAvailable;
626}
627
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800628void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list) {
629
630 int nYuvCount = ctx->listStats[mDpy].yuvCount;
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700631 if(!nYuvCount && mDpy) {
632 //Reset "No animation on external display" related parameters.
633 ctx->mPrevCropVideo.left = ctx->mPrevCropVideo.top =
634 ctx->mPrevCropVideo.right = ctx->mPrevCropVideo.bottom = 0;
635 ctx->mPrevDestVideo.left = ctx->mPrevDestVideo.top =
636 ctx->mPrevDestVideo.right = ctx->mPrevDestVideo.bottom = 0;
637 ctx->mPrevTransformVideo = 0;
638 return;
639 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800640 for(int index = 0;index < nYuvCount; index++){
641 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
642 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
643
644 if(!isYUVDoable(ctx, layer)) {
645 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
646 mCurrentFrame.isFBComposed[nYuvIndex] = true;
647 mCurrentFrame.fbCount++;
648 }
649 } else {
650 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
651 mCurrentFrame.isFBComposed[nYuvIndex] = false;
652 mCurrentFrame.fbCount--;
653 }
654 }
655 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700656
657 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
658 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800659 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
660 mCurrentFrame.fbCount);
661}
662
Saurabh Shahaa236822013-04-24 18:07:26 -0700663bool MDPComp::programMDP(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800664 if(!allocLayerPipes(ctx, list)) {
665 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700666 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800667 }
668
Saurabh Shahaa236822013-04-24 18:07:26 -0700669 bool fbBatch = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800670 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700671 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800672 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800673 int mdpIndex = mCurrentFrame.layerToMDP[index];
674 hwc_layer_1_t* layer = &list->hwLayers[index];
675
676 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
677 cur_pipe->zOrder = mdpNextZOrder++;
678
679 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
680 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
681 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -0700682 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800683 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700684 } else if(fbBatch == false) {
685 mdpNextZOrder++;
686 fbBatch = true;
687 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800688 }
689
Saurabh Shahaa236822013-04-24 18:07:26 -0700690 return true;
691}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800692
Saurabh Shahaa236822013-04-24 18:07:26 -0700693bool MDPComp::programYUV(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
694 if(!allocLayerPipes(ctx, list)) {
695 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
696 return false;
697 }
698 //If we are in this block, it means we have yuv + rgb layers both
699 int mdpIdx = 0;
700 for (int index = 0; index < mCurrentFrame.layerCount; index++) {
701 if(!mCurrentFrame.isFBComposed[index]) {
702 hwc_layer_1_t* layer = &list->hwLayers[index];
703 int mdpIndex = mCurrentFrame.layerToMDP[index];
704 MdpPipeInfo* cur_pipe =
705 mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
706 cur_pipe->zOrder = mdpIdx++;
707
708 if(configure(ctx, layer,
709 mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
710 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
711 layer %d",__FUNCTION__, index);
712 return false;
713 }
714 }
715 }
716 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800717}
718
719int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800720
Saurabh Shahaa236822013-04-24 18:07:26 -0700721 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -0700722
723 //number of app layers exceeds MAX_NUM_APP_LAYERS fall back to GPU
724 //do not cache the information for next draw cycle.
725 if(numLayers > MAX_NUM_APP_LAYERS) {
726 ALOGD_IF(isDebug(), "%s: Number of App layers exceeded the limit ",
727 __FUNCTION__);
728 return 0;
729 }
730 //reset old data
Saurabh Shahaa236822013-04-24 18:07:26 -0700731 mCurrentFrame.reset(numLayers);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800732
Saurabh Shahaa236822013-04-24 18:07:26 -0700733 //Hard conditions, if not met, cannot do MDP comp
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800734 if(!isFrameDoable(ctx)) {
735 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
736 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700737 mCurrentFrame.reset(numLayers);
738 mCachedFrame.cacheAll(list);
739 mCachedFrame.updateCounts(mCurrentFrame);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800740 return 0;
741 }
742
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800743 //Check whether layers marked for MDP Composition is actually doable.
Saurabh Shahaa236822013-04-24 18:07:26 -0700744 if(isFullFrameDoable(ctx, list)){
Saurabh Shah2f3895f2013-05-02 10:13:31 -0700745 mCurrentFrame.map();
746 //Acquire and Program MDP pipes
747 if(!programMDP(ctx, list)) {
748 mCurrentFrame.reset(numLayers);
749 mCachedFrame.cacheAll(list);
750 } else { //Success
751 //Any change in composition types needs an FB refresh
752 mCurrentFrame.needsRedraw = false;
753 if(mCurrentFrame.fbCount &&
754 ((mCurrentFrame.mdpCount != mCachedFrame.mdpCount) ||
755 (mCurrentFrame.fbCount != mCachedFrame.cacheCount) ||
756 (mCurrentFrame.fbZ != mCachedFrame.fbZ) ||
757 (!mCurrentFrame.mdpCount) ||
758 (list->flags & HWC_GEOMETRY_CHANGED) ||
759 isSkipPresent(ctx, mDpy) ||
760 (mDpy > HWC_DISPLAY_PRIMARY))) {
761 mCurrentFrame.needsRedraw = true;
Saurabh Shahaa236822013-04-24 18:07:26 -0700762 }
763 }
764 } else if(isOnlyVideoDoable(ctx, list)) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800765 //All layers marked for MDP comp cannot be bypassed.
766 //Try to compose atleast YUV layers through MDP comp and let
767 //all the RGB layers compose in FB
Saurabh Shahaa236822013-04-24 18:07:26 -0700768 //Destination over
769 mCurrentFrame.fbZ = -1;
770 if(mCurrentFrame.fbCount)
771 mCurrentFrame.fbZ = ctx->listStats[mDpy].yuvCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800772
Saurabh Shahaa236822013-04-24 18:07:26 -0700773 mCurrentFrame.map();
774 if(!programYUV(ctx, list)) {
775 mCurrentFrame.reset(numLayers);
776 mCachedFrame.cacheAll(list);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800777 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700778 } else {
779 mCurrentFrame.reset(numLayers);
780 mCachedFrame.cacheAll(list);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800781 }
782
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800783 //UpdateLayerFlags
784 setMDPCompLayerFlags(ctx, list);
Saurabh Shahaa236822013-04-24 18:07:26 -0700785 mCachedFrame.updateCounts(mCurrentFrame);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800786
787 if(isDebug()) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700788 ALOGD("GEOMETRY change: %d", (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800789 android::String8 sDump("");
790 dump(sDump);
791 ALOGE("%s",sDump.string());
792 }
793
794 return mCurrentFrame.fbZ;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800795}
796
797//=============MDPCompLowRes===================================================
798
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700799/*
800 * Configures pipe(s) for MDP composition
801 */
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800802int MDPCompLowRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800803 PipeLayerPair& PipeLayerPair) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800804 MdpPipeInfoLowRes& mdp_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800805 *(static_cast<MdpPipeInfoLowRes*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -0800806 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
807 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
808 eIsFg isFg = IS_FG_OFF;
809 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700810
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800811 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
812 __FUNCTION__, layer, zOrder, dest);
813
814 return configureLowRes(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
815 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700816}
817
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800818int MDPCompLowRes::pipesNeeded(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800819 hwc_display_contents_1_t* list) {
820 return mCurrentFrame.mdpCount;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700821}
822
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800823bool MDPCompLowRes::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700824 hwc_display_contents_1_t* list) {
825 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700826
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800827 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700828
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800829 hwc_layer_1_t* layer = &list->hwLayers[index];
830 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800831 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800832 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800833 info.pipeInfo = new MdpPipeInfoLowRes;
Saurabh Shahacf10202013-02-26 10:15:15 -0800834 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800835 MdpPipeInfoLowRes& pipe_info = *(MdpPipeInfoLowRes*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800836 ePipeType type = MDPCOMP_OV_ANY;
837
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700838 if(isYuvBuffer(hnd)) {
839 type = MDPCOMP_OV_VG;
Saurabh Shah8a117932013-05-23 12:48:13 -0700840 } else if(!qhwc::needsScaling(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -0700841 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
842 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800843 type = MDPCOMP_OV_DMA;
844 }
845
846 pipe_info.index = getMdpPipe(ctx, type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800847 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700848 ALOGD_IF(isDebug(), "%s: Unable to get pipe type = %d",
849 __FUNCTION__, (int) type);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500850 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700851 }
852 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700853 return true;
854}
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700855
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800856bool MDPCompLowRes::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700857
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800858 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500859 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
860 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800861 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700862
863 if(!ctx || !list) {
864 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500865 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700866 }
867
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500868 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -0700869 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500870 idleInvalidator->markForSleep();
871
872 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800873 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700874
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800875 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
876 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700877 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800878 if(mCurrentFrame.isFBComposed[i]) continue;
879
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700880 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -0800881 private_handle_t *hnd = (private_handle_t *)layer->handle;
882 if(!hnd) {
883 ALOGE("%s handle null", __FUNCTION__);
884 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700885 }
886
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800887 int mdpIndex = mCurrentFrame.layerToMDP[i];
888
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800889 MdpPipeInfoLowRes& pipe_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800890 *(MdpPipeInfoLowRes*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800891 ovutils::eDest dest = pipe_info.index;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800892 if(dest == ovutils::OV_INVALID) {
893 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500894 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700895 }
896
Saurabh Shahacf10202013-02-26 10:15:15 -0800897 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
898 continue;
899 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700900
Saurabh Shahacf10202013-02-26 10:15:15 -0800901 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800902 using pipe: %d", __FUNCTION__, layer,
903 hnd, dest );
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700904
Saurabh Shahacf10202013-02-26 10:15:15 -0800905 int fd = hnd->fd;
906 uint32_t offset = hnd->offset;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800907 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -0800908 if(rot) {
909 if(!rot->queueBuffer(fd, offset))
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500910 return false;
Saurabh Shahacf10202013-02-26 10:15:15 -0800911 fd = rot->getDstMemId();
912 offset = rot->getDstOffset();
913 }
914
915 if (!ov.queueBuffer(fd, offset, dest)) {
916 ALOGE("%s: queueBuffer failed for external", __FUNCTION__);
917 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700918 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500919
920 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700921 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500922 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700923}
924
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800925//=============MDPCompHighRes===================================================
926
927int MDPCompHighRes::pipesNeeded(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800928 hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800929 int pipesNeeded = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800930 int hw_w = ctx->dpyAttr[mDpy].xres;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800931
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800932 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
933 if(!mCurrentFrame.isFBComposed[i]) {
934 hwc_layer_1_t* layer = &list->hwLayers[i];
935 hwc_rect_t dst = layer->displayFrame;
936 if(dst.left > hw_w/2) {
937 pipesNeeded++;
938 } else if(dst.right <= hw_w/2) {
939 pipesNeeded++;
940 } else {
941 pipesNeeded += 2;
942 }
943 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800944 }
945 return pipesNeeded;
946}
947
948bool MDPCompHighRes::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800949 MdpPipeInfoHighRes& pipe_info,
950 ePipeType type) {
951 int hw_w = ctx->dpyAttr[mDpy].xres;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800952
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800953 hwc_rect_t dst = layer->displayFrame;
954 if(dst.left > hw_w/2) {
955 pipe_info.lIndex = ovutils::OV_INVALID;
956 pipe_info.rIndex = getMdpPipe(ctx, type);
957 if(pipe_info.rIndex == ovutils::OV_INVALID)
958 return false;
959 } else if (dst.right <= hw_w/2) {
960 pipe_info.rIndex = ovutils::OV_INVALID;
961 pipe_info.lIndex = getMdpPipe(ctx, type);
962 if(pipe_info.lIndex == ovutils::OV_INVALID)
963 return false;
964 } else {
965 pipe_info.rIndex = getMdpPipe(ctx, type);
966 pipe_info.lIndex = getMdpPipe(ctx, type);
967 if(pipe_info.rIndex == ovutils::OV_INVALID ||
968 pipe_info.lIndex == ovutils::OV_INVALID)
969 return false;
970 }
971 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800972}
973
974bool MDPCompHighRes::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700975 hwc_display_contents_1_t* list) {
976 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800977
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700978 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800979
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800980 hwc_layer_1_t* layer = &list->hwLayers[index];
981 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800982 PipeLayerPair& info = mCurrentFrame.mdpToLayer[index];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800983 info.pipeInfo = new MdpPipeInfoHighRes;
Saurabh Shah9e3adb22013-03-26 11:16:27 -0700984 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800985 MdpPipeInfoHighRes& pipe_info = *(MdpPipeInfoHighRes*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800986 ePipeType type = MDPCOMP_OV_ANY;
987
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700988 if(isYuvBuffer(hnd)) {
989 type = MDPCOMP_OV_VG;
Saurabh Shah8a117932013-05-23 12:48:13 -0700990 } else if(!qhwc::needsScaling(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -0700991 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700992 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800993 type = MDPCOMP_OV_DMA;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700994 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800995
996 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700997 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type = %d",
998 __FUNCTION__, (int) type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800999 return false;
1000 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001001 }
1002 return true;
1003}
1004/*
1005 * Configures pipe(s) for MDP composition
1006 */
1007int MDPCompHighRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001008 PipeLayerPair& PipeLayerPair) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001009 MdpPipeInfoHighRes& mdp_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001010 *(static_cast<MdpPipeInfoHighRes*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001011 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1012 eIsFg isFg = IS_FG_OFF;
1013 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1014 eDest lDest = mdp_info.lIndex;
1015 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001016
1017 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1018 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1019
1020 return configureHighRes(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
1021 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001022}
1023
1024bool MDPCompHighRes::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
1025
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001026 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001027 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1028 return true;
1029 }
1030
1031 if(!ctx || !list) {
1032 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001033 return false;
1034 }
1035
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001036 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001037 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001038 idleInvalidator->markForSleep();
1039
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001040 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001041 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001042
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001043 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1044 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001045 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001046 if(mCurrentFrame.isFBComposed[i]) continue;
1047
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001048 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001049 private_handle_t *hnd = (private_handle_t *)layer->handle;
1050 if(!hnd) {
1051 ALOGE("%s handle null", __FUNCTION__);
1052 return false;
1053 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001054
1055 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1056 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001057 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001058
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001059 int mdpIndex = mCurrentFrame.layerToMDP[i];
1060
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001061 MdpPipeInfoHighRes& pipe_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001062 *(MdpPipeInfoHighRes*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1063 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -08001064
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001065 ovutils::eDest indexL = pipe_info.lIndex;
1066 ovutils::eDest indexR = pipe_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001067
Saurabh Shahacf10202013-02-26 10:15:15 -08001068 int fd = hnd->fd;
1069 int offset = hnd->offset;
1070
1071 if(rot) {
1072 rot->queueBuffer(fd, offset);
1073 fd = rot->getDstMemId();
1074 offset = rot->getDstOffset();
1075 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001076
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001077 //************* play left mixer **********
1078 if(indexL != ovutils::OV_INVALID) {
1079 ovutils::eDest destL = (ovutils::eDest)indexL;
Saurabh Shahacf10202013-02-26 10:15:15 -08001080 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001081 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
Saurabh Shahacf10202013-02-26 10:15:15 -08001082 if (!ov.queueBuffer(fd, offset, destL)) {
1083 ALOGE("%s: queueBuffer failed for left mixer", __FUNCTION__);
1084 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001085 }
1086 }
1087
1088 //************* play right mixer **********
1089 if(indexR != ovutils::OV_INVALID) {
1090 ovutils::eDest destR = (ovutils::eDest)indexR;
Saurabh Shahacf10202013-02-26 10:15:15 -08001091 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001092 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
Saurabh Shahacf10202013-02-26 10:15:15 -08001093 if (!ov.queueBuffer(fd, offset, destR)) {
1094 ALOGE("%s: queueBuffer failed for right mixer", __FUNCTION__);
1095 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001096 }
1097 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001098
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001099 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1100 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001101
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001102 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001103}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001104}; //namespace
1105