blob: 8ccf3629fea96de5ab87ae02babf98904ad45ae6 [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;
369 } else if(sIdleFallBack) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700370 ALOGD_IF(isDebug(), "%s: idle fallback",__FUNCTION__);
371 ret = false;
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700372 }
373
Saurabh Shahaa236822013-04-24 18:07:26 -0700374 return ret;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800375}
376
377/* Checks for conditions where all the layers marked for MDP comp cannot be
378 * bypassed. On such conditions we try to bypass atleast YUV layers */
379bool MDPComp::isFullFrameDoable(hwc_context_t *ctx,
380 hwc_display_contents_1_t* list){
381
Saurabh Shahaa236822013-04-24 18:07:26 -0700382 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800383
384 if(mDpy > HWC_DISPLAY_PRIMARY){
385 ALOGD_IF(isDebug(), "%s: Cannot support External display(s)",
386 __FUNCTION__);
387 return false;
388 }
389
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800390 if(isSkipPresent(ctx, mDpy)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700391 ALOGD_IF(isDebug(),"%s: SKIP present: %d",
392 __FUNCTION__,
393 isSkipPresent(ctx, mDpy));
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800394 return false;
395 }
396
Saurabh Shah9f084ad2013-05-02 11:28:09 -0700397 if(ctx->listStats[mDpy].needsAlphaScale
398 && ctx->mMDP.version < qdutils::MDSS_V5) {
399 ALOGD_IF(isDebug(), "%s: frame needs alpha downscaling",__FUNCTION__);
400 return false;
401 }
402
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800403 //MDP composition is not efficient if layer needs rotator.
404 for(int i = 0; i < numAppLayers; ++i) {
405 // As MDP h/w supports flip operation, use MDP comp only for
406 // 180 transforms. Fail for any transform involving 90 (90, 270).
407 hwc_layer_1_t* layer = &list->hwLayers[i];
408 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800409
Saurabh Shah4fdde762013-04-30 18:47:33 -0700410 if((layer->transform & HWC_TRANSFORM_ROT_90) && !isYuvBuffer(hnd)) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800411 ALOGD_IF(isDebug(), "%s: orientation involved",__FUNCTION__);
412 return false;
413 }
414
Saurabh Shah4fdde762013-04-30 18:47:33 -0700415 if(!isValidDimension(ctx,layer)) {
416 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
417 __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800418 return false;
419 }
420 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700421
422 //If all above hard conditions are met we can do full or partial MDP comp.
423 bool ret = false;
424 if(fullMDPComp(ctx, list)) {
425 ret = true;
426 } else if (partialMDPComp(ctx, list)) {
427 ret = true;
428 }
429 return ret;
430}
431
432bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
433 //Setup mCurrentFrame
434 mCurrentFrame.mdpCount = mCurrentFrame.layerCount;
435 mCurrentFrame.fbCount = 0;
436 mCurrentFrame.fbZ = -1;
437 memset(&mCurrentFrame.isFBComposed, 0, sizeof(mCurrentFrame.isFBComposed));
438
439 int mdpCount = mCurrentFrame.mdpCount;
440 if(mdpCount > sMaxPipesPerMixer) {
441 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
442 return false;
443 }
444
445 int numPipesNeeded = pipesNeeded(ctx, list);
446 int availPipes = getAvailablePipes(ctx);
447
448 if(numPipesNeeded > availPipes) {
449 ALOGD_IF(isDebug(), "%s: Insufficient MDP pipes, needed %d, avail %d",
450 __FUNCTION__, numPipesNeeded, availPipes);
451 return false;
452 }
453
454 return true;
455}
456
457bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
458{
459 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
460 //Setup mCurrentFrame
461 mCurrentFrame.reset(numAppLayers);
462 updateLayerCache(ctx, list);
463 updateYUV(ctx, list);
464 batchLayers(); //sets up fbZ also
465
466 int mdpCount = mCurrentFrame.mdpCount;
467 if(mdpCount > (sMaxPipesPerMixer - 1)) { // -1 since FB is used
468 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
469 return false;
470 }
471
472 int numPipesNeeded = pipesNeeded(ctx, list);
473 int availPipes = getAvailablePipes(ctx);
474
475 if(numPipesNeeded > availPipes) {
476 ALOGD_IF(isDebug(), "%s: Insufficient MDP pipes, needed %d, avail %d",
477 __FUNCTION__, numPipesNeeded, availPipes);
478 return false;
479 }
480
481 return true;
482}
483
484bool MDPComp::isOnlyVideoDoable(hwc_context_t *ctx,
485 hwc_display_contents_1_t* list){
486 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
487 mCurrentFrame.reset(numAppLayers);
488 updateYUV(ctx, list);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700489 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700490 int fbNeeded = int(mCurrentFrame.fbCount != 0);
491
492 if(!isYuvPresent(ctx, mDpy)) {
493 return false;
494 }
495
Saurabh Shah4fdde762013-04-30 18:47:33 -0700496 if(!mdpCount)
497 return false;
498
Saurabh Shahaa236822013-04-24 18:07:26 -0700499 if(mdpCount > (sMaxPipesPerMixer - fbNeeded)) {
500 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
501 return false;
502 }
503
504 int numPipesNeeded = pipesNeeded(ctx, list);
505 int availPipes = getAvailablePipes(ctx);
506 if(numPipesNeeded > availPipes) {
507 ALOGD_IF(isDebug(), "%s: Insufficient MDP pipes, needed %d, avail %d",
508 __FUNCTION__, numPipesNeeded, availPipes);
509 return false;
510 }
511
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800512 return true;
513}
514
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800515/* Checks for conditions where YUV layers cannot be bypassed */
516bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800517
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800518 if(isSkipLayer(layer)) {
519 ALOGE("%s: Unable to bypass skipped YUV", __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800520 return false;
521 }
522
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800523 if(isSecuring(ctx, layer)) {
524 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
525 return false;
526 }
527
Saurabh Shah4fdde762013-04-30 18:47:33 -0700528 if(!isValidDimension(ctx, layer)) {
529 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
530 __FUNCTION__);
531 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800532 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700533
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800534 return true;
535}
536
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800537void MDPComp::batchLayers() {
538 /* Idea is to keep as many contiguous non-updating(cached) layers in FB and
539 * send rest of them through MDP. NEVER mark an updating layer for caching.
540 * But cached ones can be marked for MDP*/
541
542 int maxBatchStart = -1;
543 int maxBatchCount = 0;
544
545 /* All or Nothing is cached. No batching needed */
Saurabh Shahaa236822013-04-24 18:07:26 -0700546 if(!mCurrentFrame.fbCount) {
547 mCurrentFrame.fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800548 return;
Saurabh Shahaa236822013-04-24 18:07:26 -0700549 }
550 if(!mCurrentFrame.mdpCount) {
551 mCurrentFrame.fbZ = 0;
552 return;
553 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800554
555 /* Search for max number of contiguous (cached) layers */
556 int i = 0;
557 while (i < mCurrentFrame.layerCount) {
558 int count = 0;
559 while(mCurrentFrame.isFBComposed[i] && i < mCurrentFrame.layerCount) {
560 count++; i++;
561 }
562 if(count > maxBatchCount) {
563 maxBatchCount = count;
564 maxBatchStart = i - count;
Saurabh Shahaa236822013-04-24 18:07:26 -0700565 mCurrentFrame.fbZ = maxBatchStart;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800566 }
567 if(i < mCurrentFrame.layerCount) i++;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800568 }
569
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800570 /* reset rest of the layers for MDP comp */
571 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
572 if(i != maxBatchStart){
573 mCurrentFrame.isFBComposed[i] = false;
574 } else {
575 i += maxBatchCount;
576 }
577 }
578
579 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700580 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
581 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800582
583 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
584 mCurrentFrame.fbCount);
585}
Saurabh Shah85234ec2013-04-12 17:09:00 -0700586
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800587void MDPComp::updateLayerCache(hwc_context_t* ctx,
588 hwc_display_contents_1_t* list) {
589
590 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
591 int numCacheableLayers = 0;
592
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800593 for(int i = 0; i < numAppLayers; i++) {
594 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
595 numCacheableLayers++;
596 mCurrentFrame.isFBComposed[i] = true;
597 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -0700598 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800599 mCachedFrame.hnd[i] = list->hwLayers[i].handle;
600 }
601 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700602
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800603 mCurrentFrame.fbCount = numCacheableLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700604 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
605 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800606 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__, numCacheableLayers);
607}
608
609int MDPComp::getAvailablePipes(hwc_context_t* ctx) {
610 int numDMAPipes = qdutils::MDPVersion::getInstance().getDMAPipes();
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800611 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800612
613 int numAvailable = ov.availablePipes(mDpy);
614
615 //Reserve DMA for rotator
Saurabh Shah85234ec2013-04-12 17:09:00 -0700616 if(Overlay::getDMAMode() == Overlay::DMA_BLOCK_MODE)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800617 numAvailable -= numDMAPipes;
618
619 //Reserve pipe(s)for FB
620 if(mCurrentFrame.fbCount)
621 numAvailable -= pipesForFB();
622
623 return numAvailable;
624}
625
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800626void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list) {
627
628 int nYuvCount = ctx->listStats[mDpy].yuvCount;
629 for(int index = 0;index < nYuvCount; index++){
630 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
631 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
632
633 if(!isYUVDoable(ctx, layer)) {
634 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
635 mCurrentFrame.isFBComposed[nYuvIndex] = true;
636 mCurrentFrame.fbCount++;
637 }
638 } else {
639 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
640 mCurrentFrame.isFBComposed[nYuvIndex] = false;
641 mCurrentFrame.fbCount--;
642 }
643 }
644 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700645
646 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
647 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800648 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
649 mCurrentFrame.fbCount);
650}
651
Saurabh Shahaa236822013-04-24 18:07:26 -0700652bool MDPComp::programMDP(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800653 if(!allocLayerPipes(ctx, list)) {
654 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700655 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800656 }
657
Saurabh Shahaa236822013-04-24 18:07:26 -0700658 bool fbBatch = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800659 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700660 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800661 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800662 int mdpIndex = mCurrentFrame.layerToMDP[index];
663 hwc_layer_1_t* layer = &list->hwLayers[index];
664
665 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
666 cur_pipe->zOrder = mdpNextZOrder++;
667
668 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
669 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
670 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -0700671 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800672 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700673 } else if(fbBatch == false) {
674 mdpNextZOrder++;
675 fbBatch = true;
676 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800677 }
678
Saurabh Shahaa236822013-04-24 18:07:26 -0700679 return true;
680}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800681
Saurabh Shahaa236822013-04-24 18:07:26 -0700682bool MDPComp::programYUV(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
683 if(!allocLayerPipes(ctx, list)) {
684 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
685 return false;
686 }
687 //If we are in this block, it means we have yuv + rgb layers both
688 int mdpIdx = 0;
689 for (int index = 0; index < mCurrentFrame.layerCount; index++) {
690 if(!mCurrentFrame.isFBComposed[index]) {
691 hwc_layer_1_t* layer = &list->hwLayers[index];
692 int mdpIndex = mCurrentFrame.layerToMDP[index];
693 MdpPipeInfo* cur_pipe =
694 mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
695 cur_pipe->zOrder = mdpIdx++;
696
697 if(configure(ctx, layer,
698 mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
699 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
700 layer %d",__FUNCTION__, index);
701 return false;
702 }
703 }
704 }
705 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800706}
707
708int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800709
710 //reset old data
Saurabh Shahaa236822013-04-24 18:07:26 -0700711 const int numLayers = ctx->listStats[mDpy].numAppLayers;
712 mCurrentFrame.reset(numLayers);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800713
Saurabh Shahaa236822013-04-24 18:07:26 -0700714 //Hard conditions, if not met, cannot do MDP comp
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800715 if(!isFrameDoable(ctx)) {
716 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
717 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700718 mCurrentFrame.reset(numLayers);
719 mCachedFrame.cacheAll(list);
720 mCachedFrame.updateCounts(mCurrentFrame);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800721 return 0;
722 }
723
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800724 //Check whether layers marked for MDP Composition is actually doable.
Saurabh Shahaa236822013-04-24 18:07:26 -0700725 if(isFullFrameDoable(ctx, list)){
Saurabh Shah2f3895f2013-05-02 10:13:31 -0700726 mCurrentFrame.map();
727 //Acquire and Program MDP pipes
728 if(!programMDP(ctx, list)) {
729 mCurrentFrame.reset(numLayers);
730 mCachedFrame.cacheAll(list);
731 } else { //Success
732 //Any change in composition types needs an FB refresh
733 mCurrentFrame.needsRedraw = false;
734 if(mCurrentFrame.fbCount &&
735 ((mCurrentFrame.mdpCount != mCachedFrame.mdpCount) ||
736 (mCurrentFrame.fbCount != mCachedFrame.cacheCount) ||
737 (mCurrentFrame.fbZ != mCachedFrame.fbZ) ||
738 (!mCurrentFrame.mdpCount) ||
739 (list->flags & HWC_GEOMETRY_CHANGED) ||
740 isSkipPresent(ctx, mDpy) ||
741 (mDpy > HWC_DISPLAY_PRIMARY))) {
742 mCurrentFrame.needsRedraw = true;
Saurabh Shahaa236822013-04-24 18:07:26 -0700743 }
744 }
745 } else if(isOnlyVideoDoable(ctx, list)) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800746 //All layers marked for MDP comp cannot be bypassed.
747 //Try to compose atleast YUV layers through MDP comp and let
748 //all the RGB layers compose in FB
Saurabh Shahaa236822013-04-24 18:07:26 -0700749 //Destination over
750 mCurrentFrame.fbZ = -1;
751 if(mCurrentFrame.fbCount)
752 mCurrentFrame.fbZ = ctx->listStats[mDpy].yuvCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800753
Saurabh Shahaa236822013-04-24 18:07:26 -0700754 mCurrentFrame.map();
755 if(!programYUV(ctx, list)) {
756 mCurrentFrame.reset(numLayers);
757 mCachedFrame.cacheAll(list);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800758 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700759 } else {
760 mCurrentFrame.reset(numLayers);
761 mCachedFrame.cacheAll(list);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800762 }
763
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800764 //UpdateLayerFlags
765 setMDPCompLayerFlags(ctx, list);
Saurabh Shahaa236822013-04-24 18:07:26 -0700766 mCachedFrame.updateCounts(mCurrentFrame);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800767
768 if(isDebug()) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700769 ALOGD("GEOMETRY change: %d", (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800770 android::String8 sDump("");
771 dump(sDump);
772 ALOGE("%s",sDump.string());
773 }
774
775 return mCurrentFrame.fbZ;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800776}
777
778//=============MDPCompLowRes===================================================
779
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700780/*
781 * Configures pipe(s) for MDP composition
782 */
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800783int MDPCompLowRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800784 PipeLayerPair& PipeLayerPair) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800785 MdpPipeInfoLowRes& mdp_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800786 *(static_cast<MdpPipeInfoLowRes*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -0800787 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
788 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
789 eIsFg isFg = IS_FG_OFF;
790 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700791
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800792 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
793 __FUNCTION__, layer, zOrder, dest);
794
795 return configureLowRes(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
796 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700797}
798
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800799int MDPCompLowRes::pipesNeeded(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800800 hwc_display_contents_1_t* list) {
801 return mCurrentFrame.mdpCount;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700802}
803
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800804bool MDPCompLowRes::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700805 hwc_display_contents_1_t* list) {
806 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700807
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800808 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700809
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800810 hwc_layer_1_t* layer = &list->hwLayers[index];
811 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800812 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800813 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800814 info.pipeInfo = new MdpPipeInfoLowRes;
Saurabh Shahacf10202013-02-26 10:15:15 -0800815 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800816 MdpPipeInfoLowRes& pipe_info = *(MdpPipeInfoLowRes*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800817 ePipeType type = MDPCOMP_OV_ANY;
818
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700819 if(isYuvBuffer(hnd)) {
820 type = MDPCOMP_OV_VG;
821 } else if(!qhwc::needsScaling(layer)
Saurabh Shah85234ec2013-04-12 17:09:00 -0700822 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
823 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800824 type = MDPCOMP_OV_DMA;
825 }
826
827 pipe_info.index = getMdpPipe(ctx, type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800828 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700829 ALOGD_IF(isDebug(), "%s: Unable to get pipe type = %d",
830 __FUNCTION__, (int) type);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500831 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700832 }
833 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700834 return true;
835}
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700836
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800837bool MDPCompLowRes::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700838
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800839 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500840 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
841 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800842 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700843
844 if(!ctx || !list) {
845 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500846 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700847 }
848
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500849 /* reset Invalidator */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800850 if(idleInvalidator && mCurrentFrame.mdpCount)
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500851 idleInvalidator->markForSleep();
852
853 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800854 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700855
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800856 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
857 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700858 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800859 if(mCurrentFrame.isFBComposed[i]) continue;
860
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700861 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -0800862 private_handle_t *hnd = (private_handle_t *)layer->handle;
863 if(!hnd) {
864 ALOGE("%s handle null", __FUNCTION__);
865 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700866 }
867
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800868 int mdpIndex = mCurrentFrame.layerToMDP[i];
869
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800870 MdpPipeInfoLowRes& pipe_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800871 *(MdpPipeInfoLowRes*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800872 ovutils::eDest dest = pipe_info.index;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800873 if(dest == ovutils::OV_INVALID) {
874 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500875 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700876 }
877
Saurabh Shahacf10202013-02-26 10:15:15 -0800878 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
879 continue;
880 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700881
Saurabh Shahacf10202013-02-26 10:15:15 -0800882 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800883 using pipe: %d", __FUNCTION__, layer,
884 hnd, dest );
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700885
Saurabh Shahacf10202013-02-26 10:15:15 -0800886 int fd = hnd->fd;
887 uint32_t offset = hnd->offset;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800888 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -0800889 if(rot) {
890 if(!rot->queueBuffer(fd, offset))
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500891 return false;
Saurabh Shahacf10202013-02-26 10:15:15 -0800892 fd = rot->getDstMemId();
893 offset = rot->getDstOffset();
894 }
895
896 if (!ov.queueBuffer(fd, offset, dest)) {
897 ALOGE("%s: queueBuffer failed for external", __FUNCTION__);
898 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700899 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500900
901 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700902 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500903 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700904}
905
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800906//=============MDPCompHighRes===================================================
907
908int MDPCompHighRes::pipesNeeded(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800909 hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800910 int pipesNeeded = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800911 int hw_w = ctx->dpyAttr[mDpy].xres;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800912
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800913 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
914 if(!mCurrentFrame.isFBComposed[i]) {
915 hwc_layer_1_t* layer = &list->hwLayers[i];
916 hwc_rect_t dst = layer->displayFrame;
917 if(dst.left > hw_w/2) {
918 pipesNeeded++;
919 } else if(dst.right <= hw_w/2) {
920 pipesNeeded++;
921 } else {
922 pipesNeeded += 2;
923 }
924 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800925 }
926 return pipesNeeded;
927}
928
929bool MDPCompHighRes::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800930 MdpPipeInfoHighRes& pipe_info,
931 ePipeType type) {
932 int hw_w = ctx->dpyAttr[mDpy].xres;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800933
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800934 hwc_rect_t dst = layer->displayFrame;
935 if(dst.left > hw_w/2) {
936 pipe_info.lIndex = ovutils::OV_INVALID;
937 pipe_info.rIndex = getMdpPipe(ctx, type);
938 if(pipe_info.rIndex == ovutils::OV_INVALID)
939 return false;
940 } else if (dst.right <= hw_w/2) {
941 pipe_info.rIndex = ovutils::OV_INVALID;
942 pipe_info.lIndex = getMdpPipe(ctx, type);
943 if(pipe_info.lIndex == ovutils::OV_INVALID)
944 return false;
945 } else {
946 pipe_info.rIndex = getMdpPipe(ctx, type);
947 pipe_info.lIndex = getMdpPipe(ctx, type);
948 if(pipe_info.rIndex == ovutils::OV_INVALID ||
949 pipe_info.lIndex == ovutils::OV_INVALID)
950 return false;
951 }
952 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800953}
954
955bool MDPCompHighRes::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700956 hwc_display_contents_1_t* list) {
957 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800958
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700959 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800960
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800961 hwc_layer_1_t* layer = &list->hwLayers[index];
962 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800963 PipeLayerPair& info = mCurrentFrame.mdpToLayer[index];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800964 info.pipeInfo = new MdpPipeInfoHighRes;
Saurabh Shah9e3adb22013-03-26 11:16:27 -0700965 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800966 MdpPipeInfoHighRes& pipe_info = *(MdpPipeInfoHighRes*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800967 ePipeType type = MDPCOMP_OV_ANY;
968
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700969 if(isYuvBuffer(hnd)) {
970 type = MDPCOMP_OV_VG;
971 } else if(!qhwc::needsScaling(layer)
Saurabh Shah85234ec2013-04-12 17:09:00 -0700972 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700973 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800974 type = MDPCOMP_OV_DMA;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700975 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800976
977 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700978 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type = %d",
979 __FUNCTION__, (int) type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800980 return false;
981 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800982 }
983 return true;
984}
985/*
986 * Configures pipe(s) for MDP composition
987 */
988int MDPCompHighRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800989 PipeLayerPair& PipeLayerPair) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800990 MdpPipeInfoHighRes& mdp_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800991 *(static_cast<MdpPipeInfoHighRes*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -0800992 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
993 eIsFg isFg = IS_FG_OFF;
994 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
995 eDest lDest = mdp_info.lIndex;
996 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800997
998 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
999 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1000
1001 return configureHighRes(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
1002 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001003}
1004
1005bool MDPCompHighRes::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
1006
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001007 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001008 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1009 return true;
1010 }
1011
1012 if(!ctx || !list) {
1013 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001014 return false;
1015 }
1016
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001017 /* reset Invalidator */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001018 if(idleInvalidator && mCurrentFrame.mdpCount)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001019 idleInvalidator->markForSleep();
1020
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001021 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001022 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001023
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001024 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1025 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001026 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001027 if(mCurrentFrame.isFBComposed[i]) continue;
1028
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001029 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001030 private_handle_t *hnd = (private_handle_t *)layer->handle;
1031 if(!hnd) {
1032 ALOGE("%s handle null", __FUNCTION__);
1033 return false;
1034 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001035
1036 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1037 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001038 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001039
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001040 int mdpIndex = mCurrentFrame.layerToMDP[i];
1041
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001042 MdpPipeInfoHighRes& pipe_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001043 *(MdpPipeInfoHighRes*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1044 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -08001045
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001046 ovutils::eDest indexL = pipe_info.lIndex;
1047 ovutils::eDest indexR = pipe_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001048
Saurabh Shahacf10202013-02-26 10:15:15 -08001049 int fd = hnd->fd;
1050 int offset = hnd->offset;
1051
1052 if(rot) {
1053 rot->queueBuffer(fd, offset);
1054 fd = rot->getDstMemId();
1055 offset = rot->getDstOffset();
1056 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001057
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001058 //************* play left mixer **********
1059 if(indexL != ovutils::OV_INVALID) {
1060 ovutils::eDest destL = (ovutils::eDest)indexL;
Saurabh Shahacf10202013-02-26 10:15:15 -08001061 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001062 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
Saurabh Shahacf10202013-02-26 10:15:15 -08001063 if (!ov.queueBuffer(fd, offset, destL)) {
1064 ALOGE("%s: queueBuffer failed for left mixer", __FUNCTION__);
1065 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001066 }
1067 }
1068
1069 //************* play right mixer **********
1070 if(indexR != ovutils::OV_INVALID) {
1071 ovutils::eDest destR = (ovutils::eDest)indexR;
Saurabh Shahacf10202013-02-26 10:15:15 -08001072 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001073 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
Saurabh Shahacf10202013-02-26 10:15:15 -08001074 if (!ov.queueBuffer(fd, offset, destR)) {
1075 ALOGE("%s: queueBuffer failed for right mixer", __FUNCTION__);
1076 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001077 }
1078 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001079
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001080 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1081 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001082
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001083 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001084}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001085}; //namespace
1086