blob: 3d351d0f7aeb41caf815f69d5e64a4c63d5b8f03 [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
87 if(!setupBasePipe(ctx)) {
88 ALOGE("%s: Failed to setup primary base pipe", __FUNCTION__);
89 return false;
90 }
91
92 char property[PROPERTY_VALUE_MAX];
93
94 sEnabled = false;
95 if((property_get("persist.hwc.mdpcomp.enable", property, NULL) > 0) &&
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080096 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
97 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080098 sEnabled = true;
99 }
100
101 sDebugLogs = false;
102 if(property_get("debug.mdpcomp.logs", property, NULL) > 0) {
103 if(atoi(property) != 0)
104 sDebugLogs = true;
105 }
106
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800107 sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
Saurabh Shah85234ec2013-04-12 17:09:00 -0700108 if(property_get("debug.mdpcomp.maxpermixer", property, "-1") > 0) {
109 int val = atoi(property);
110 if(val >= 0)
111 sMaxPipesPerMixer = min(val, MAX_PIPES_PER_MIXER);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800112 }
113
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800114 unsigned long idle_timeout = DEFAULT_IDLE_TIME;
115 if(property_get("debug.mdpcomp.idletime", property, NULL) > 0) {
116 if(atoi(property) != 0)
117 idle_timeout = atoi(property);
118 }
119
120 //create Idle Invalidator
121 idleInvalidator = IdleInvalidator::getInstance();
122
123 if(idleInvalidator == NULL) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800124 ALOGE("%s: failed to instantiate idleInvalidator object", __FUNCTION__);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800125 } else {
126 idleInvalidator->init(timeout_handler, ctx, idle_timeout);
127 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700128 return true;
129}
130
131void MDPComp::timeout_handler(void *udata) {
132 struct hwc_context_t* ctx = (struct hwc_context_t*)(udata);
133
134 if(!ctx) {
135 ALOGE("%s: received empty data in timer callback", __FUNCTION__);
136 return;
137 }
138
Jesse Hall3be78d92012-08-21 15:12:23 -0700139 if(!ctx->proc) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700140 ALOGE("%s: HWC proc not registered", __FUNCTION__);
141 return;
142 }
143 sIdleFallBack = true;
144 /* Trigger SF to redraw the current frame */
Jesse Hall3be78d92012-08-21 15:12:23 -0700145 ctx->proc->invalidate(ctx->proc);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700146}
147
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800148void MDPComp::setMDPCompLayerFlags(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800149 hwc_display_contents_1_t* list) {
150 LayerProp *layerProp = ctx->layerProp[mDpy];
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800151
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800152 for(int index = 0; index < ctx->listStats[mDpy].numAppLayers; index++) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800153 hwc_layer_1_t* layer = &(list->hwLayers[index]);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800154 if(!mCurrentFrame.isFBComposed[index]) {
155 layerProp[index].mFlags |= HWC_MDPCOMP;
156 layer->compositionType = HWC_OVERLAY;
157 layer->hints |= HWC_HINT_CLEAR_FB;
158 mCachedFrame.hnd[index] = NULL;
159 } else {
160 if(!mCurrentFrame.needsRedraw)
161 layer->compositionType = HWC_OVERLAY;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800162 }
163 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700164}
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500165
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800166/*
167 * Sets up BORDERFILL as default base pipe and detaches RGB0.
168 * Framebuffer is always updated using PLAY ioctl.
169 */
170bool MDPComp::setupBasePipe(hwc_context_t *ctx) {
171 const int dpy = HWC_DISPLAY_PRIMARY;
172 int fb_stride = ctx->dpyAttr[dpy].stride;
173 int fb_width = ctx->dpyAttr[dpy].xres;
174 int fb_height = ctx->dpyAttr[dpy].yres;
175 int fb_fd = ctx->dpyAttr[dpy].fd;
176
177 mdp_overlay ovInfo;
178 msmfb_overlay_data ovData;
179 memset(&ovInfo, 0, sizeof(mdp_overlay));
180 memset(&ovData, 0, sizeof(msmfb_overlay_data));
181
182 ovInfo.src.format = MDP_RGB_BORDERFILL;
183 ovInfo.src.width = fb_width;
184 ovInfo.src.height = fb_height;
185 ovInfo.src_rect.w = fb_width;
186 ovInfo.src_rect.h = fb_height;
187 ovInfo.dst_rect.w = fb_width;
188 ovInfo.dst_rect.h = fb_height;
189 ovInfo.id = MSMFB_NEW_REQUEST;
190
191 if (ioctl(fb_fd, MSMFB_OVERLAY_SET, &ovInfo) < 0) {
192 ALOGE("Failed to call ioctl MSMFB_OVERLAY_SET err=%s",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800193 strerror(errno));
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800194 return false;
195 }
196
197 ovData.id = ovInfo.id;
198 if (ioctl(fb_fd, MSMFB_OVERLAY_PLAY, &ovData) < 0) {
199 ALOGE("Failed to call ioctl MSMFB_OVERLAY_PLAY err=%s",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800200 strerror(errno));
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800201 return false;
202 }
203 return true;
204}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800205MDPComp::FrameInfo::FrameInfo() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700206 reset(0);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800207}
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800208
Saurabh Shahaa236822013-04-24 18:07:26 -0700209void MDPComp::FrameInfo::reset(const int& numLayers) {
210 for(int i = 0 ; i < MAX_PIPES_PER_MIXER && numLayers; i++ ) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800211 if(mdpToLayer[i].pipeInfo) {
212 delete mdpToLayer[i].pipeInfo;
213 mdpToLayer[i].pipeInfo = NULL;
214 //We dont own the rotator
215 mdpToLayer[i].rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800216 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800217 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800218
219 memset(&mdpToLayer, 0, sizeof(mdpToLayer));
220 memset(&layerToMDP, -1, sizeof(layerToMDP));
Saurabh Shahaa236822013-04-24 18:07:26 -0700221 memset(&isFBComposed, 1, sizeof(isFBComposed));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800222
Saurabh Shahaa236822013-04-24 18:07:26 -0700223 layerCount = numLayers;
224 fbCount = numLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800225 mdpCount = 0;
Saurabh Shah2f3895f2013-05-02 10:13:31 -0700226 needsRedraw = true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800227 fbZ = 0;
228}
229
Saurabh Shahaa236822013-04-24 18:07:26 -0700230void MDPComp::FrameInfo::map() {
231 // populate layer and MDP maps
232 int mdpIdx = 0;
233 for(int idx = 0; idx < layerCount; idx++) {
234 if(!isFBComposed[idx]) {
235 mdpToLayer[mdpIdx].listIndex = idx;
236 layerToMDP[idx] = mdpIdx++;
237 }
238 }
239}
240
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800241MDPComp::LayerCache::LayerCache() {
242 reset();
243}
244
245void MDPComp::LayerCache::reset() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700246 memset(&hnd, 0, sizeof(hnd));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800247 mdpCount = 0;
248 cacheCount = 0;
249 layerCount = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -0700250 fbZ = -1;
251}
252
253void MDPComp::LayerCache::cacheAll(hwc_display_contents_1_t* list) {
254 const int numAppLayers = list->numHwLayers - 1;
255 for(int i = 0; i < numAppLayers; i++) {
256 hnd[i] = list->hwLayers[i].handle;
257 }
258}
259
260void MDPComp::LayerCache::updateCounts(const FrameInfo& curFrame) {
261 mdpCount = curFrame.mdpCount;
262 cacheCount = curFrame.fbCount;
263 layerCount = curFrame.layerCount;
264 fbZ = curFrame.fbZ;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800265}
266
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530267bool MDPComp::isValidDimension(hwc_context_t *ctx, hwc_layer_1_t *layer) {
Saurabh Shah4fdde762013-04-30 18:47:33 -0700268 const int dpy = HWC_DISPLAY_PRIMARY;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800269 private_handle_t *hnd = (private_handle_t *)layer->handle;
270
271 if(!hnd) {
272 ALOGE("%s: layer handle is NULL", __FUNCTION__);
273 return false;
274 }
275
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800276 int hw_w = ctx->dpyAttr[mDpy].xres;
277 int hw_h = ctx->dpyAttr[mDpy].yres;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800278
Saurabh Shah4fdde762013-04-30 18:47:33 -0700279 hwc_rect_t crop = layer->sourceCrop;
280 hwc_rect_t dst = layer->displayFrame;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800281
282 if(dst.left < 0 || dst.top < 0 || dst.right > hw_w || dst.bottom > hw_h) {
Saurabh Shah4fdde762013-04-30 18:47:33 -0700283 hwc_rect_t scissor = {0, 0, hw_w, hw_h };
284 qhwc::calculate_crop_rects(crop, dst, scissor, layer->transform);
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800285 }
286
Saurabh Shah4fdde762013-04-30 18:47:33 -0700287 int crop_w = crop.right - crop.left;
288 int crop_h = crop.bottom - crop.top;
289 int dst_w = dst.right - dst.left;
290 int dst_h = dst.bottom - dst.top;
291 float w_dscale = ceilf((float)crop_w / (float)dst_w);
292 float h_dscale = ceilf((float)crop_h / (float)dst_h);
293
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800294 /* Workaround for MDP HW limitation in DSI command mode panels where
295 * FPS will not go beyond 30 if buffers on RGB pipes are of width or height
296 * less than 5 pixels
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530297 * There also is a HW limilation in MDP, minimum block size is 2x2
298 * Fallback to GPU if height is less than 2.
299 */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800300 if((crop_w < 5)||(crop_h < 5))
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800301 return false;
302
Saurabh Shah4fdde762013-04-30 18:47:33 -0700303 const uint32_t downscale =
304 qdutils::MDPVersion::getInstance().getMaxMDPDownscale();
305 if(ctx->mMDP.version >= qdutils::MDSS_V5) {
306 /* Workaround for downscales larger than 4x.
307 * Will be removed once decimator block is enabled for MDSS
308 */
309 if(!qdutils::MDPVersion::getInstance().supportsDecimation()) {
310 if(crop_w > MAX_DISPLAY_DIM || w_dscale > downscale ||
311 h_dscale > downscale)
312 return false;
313 } else {
314 if(w_dscale > 64 || h_dscale > 64)
315 return false;
316 }
317 } else { //A-family
318 if(w_dscale > downscale || h_dscale > downscale)
319 return false;
320 }
321
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800322 return true;
323}
324
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800325ovutils::eDest MDPComp::getMdpPipe(hwc_context_t *ctx, ePipeType type) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800326 overlay::Overlay& ov = *ctx->mOverlay;
327 ovutils::eDest mdp_pipe = ovutils::OV_INVALID;
328
329 switch(type) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800330 case MDPCOMP_OV_DMA:
331 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_DMA, mDpy);
332 if(mdp_pipe != ovutils::OV_INVALID) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800333 return mdp_pipe;
334 }
335 case MDPCOMP_OV_ANY:
336 case MDPCOMP_OV_RGB:
337 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy);
338 if(mdp_pipe != ovutils::OV_INVALID) {
339 return mdp_pipe;
340 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800341
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800342 if(type == MDPCOMP_OV_RGB) {
343 //Requested only for RGB pipe
344 break;
345 }
346 case MDPCOMP_OV_VG:
347 return ov.nextPipe(ovutils::OV_MDP_PIPE_VG, mDpy);
348 default:
349 ALOGE("%s: Invalid pipe type",__FUNCTION__);
350 return ovutils::OV_INVALID;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800351 };
352 return ovutils::OV_INVALID;
353}
354
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800355bool MDPComp::isFrameDoable(hwc_context_t *ctx) {
356 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700357 bool ret = true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800358
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800359 if(!isEnabled()) {
360 ALOGD_IF(isDebug(),"%s: MDP Comp. not enabled.", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700361 ret = false;
362 } else if(ctx->mExtDispConfiguring) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800363 ALOGD_IF( isDebug(),"%s: External Display connection is pending",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800364 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700365 ret = false;
Saurabh Shahaa236822013-04-24 18:07:26 -0700366 } else if(ctx->isPaddingRound) {
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700367 ctx->isPaddingRound = false;
368 ALOGD_IF(isDebug(), "%s: padding round",__FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700369 ret = false;
370 } else if(sIdleFallBack) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700371 ALOGD_IF(isDebug(), "%s: idle fallback",__FUNCTION__);
372 ret = false;
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700373 }
374
Saurabh Shahaa236822013-04-24 18:07:26 -0700375 return ret;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800376}
377
378/* Checks for conditions where all the layers marked for MDP comp cannot be
379 * bypassed. On such conditions we try to bypass atleast YUV layers */
380bool MDPComp::isFullFrameDoable(hwc_context_t *ctx,
381 hwc_display_contents_1_t* list){
382
Saurabh Shahaa236822013-04-24 18:07:26 -0700383 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800384
385 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) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800518
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800519 if(isSkipLayer(layer)) {
520 ALOGE("%s: Unable to bypass skipped YUV", __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800521 return false;
522 }
523
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800524 if(isSecuring(ctx, layer)) {
525 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
526 return false;
527 }
528
Saurabh Shah4fdde762013-04-30 18:47:33 -0700529 if(!isValidDimension(ctx, layer)) {
530 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
531 __FUNCTION__);
532 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800533 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700534
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800535 return true;
536}
537
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800538void MDPComp::batchLayers() {
539 /* Idea is to keep as many contiguous non-updating(cached) layers in FB and
540 * send rest of them through MDP. NEVER mark an updating layer for caching.
541 * But cached ones can be marked for MDP*/
542
543 int maxBatchStart = -1;
544 int maxBatchCount = 0;
545
546 /* All or Nothing is cached. No batching needed */
Saurabh Shahaa236822013-04-24 18:07:26 -0700547 if(!mCurrentFrame.fbCount) {
548 mCurrentFrame.fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800549 return;
Saurabh Shahaa236822013-04-24 18:07:26 -0700550 }
551 if(!mCurrentFrame.mdpCount) {
552 mCurrentFrame.fbZ = 0;
553 return;
554 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800555
556 /* Search for max number of contiguous (cached) layers */
557 int i = 0;
558 while (i < mCurrentFrame.layerCount) {
559 int count = 0;
560 while(mCurrentFrame.isFBComposed[i] && i < mCurrentFrame.layerCount) {
561 count++; i++;
562 }
563 if(count > maxBatchCount) {
564 maxBatchCount = count;
565 maxBatchStart = i - count;
Saurabh Shahaa236822013-04-24 18:07:26 -0700566 mCurrentFrame.fbZ = maxBatchStart;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800567 }
568 if(i < mCurrentFrame.layerCount) i++;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800569 }
570
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800571 /* reset rest of the layers for MDP comp */
572 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
573 if(i != maxBatchStart){
574 mCurrentFrame.isFBComposed[i] = false;
575 } else {
576 i += maxBatchCount;
577 }
578 }
579
580 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700581 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
582 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800583
584 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
585 mCurrentFrame.fbCount);
586}
Saurabh Shah85234ec2013-04-12 17:09:00 -0700587
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800588void MDPComp::updateLayerCache(hwc_context_t* ctx,
589 hwc_display_contents_1_t* list) {
590
591 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
592 int numCacheableLayers = 0;
593
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800594 for(int i = 0; i < numAppLayers; i++) {
595 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
596 numCacheableLayers++;
597 mCurrentFrame.isFBComposed[i] = true;
598 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -0700599 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800600 mCachedFrame.hnd[i] = list->hwLayers[i].handle;
601 }
602 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700603
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800604 mCurrentFrame.fbCount = numCacheableLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700605 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
606 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800607 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__, numCacheableLayers);
608}
609
610int MDPComp::getAvailablePipes(hwc_context_t* ctx) {
611 int numDMAPipes = qdutils::MDPVersion::getInstance().getDMAPipes();
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800612 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800613
614 int numAvailable = ov.availablePipes(mDpy);
615
616 //Reserve DMA for rotator
Saurabh Shah85234ec2013-04-12 17:09:00 -0700617 if(Overlay::getDMAMode() == Overlay::DMA_BLOCK_MODE)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800618 numAvailable -= numDMAPipes;
619
620 //Reserve pipe(s)for FB
621 if(mCurrentFrame.fbCount)
622 numAvailable -= pipesForFB();
623
624 return numAvailable;
625}
626
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800627void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list) {
628
629 int nYuvCount = ctx->listStats[mDpy].yuvCount;
630 for(int index = 0;index < nYuvCount; index++){
631 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
632 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
633
634 if(!isYUVDoable(ctx, layer)) {
635 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
636 mCurrentFrame.isFBComposed[nYuvIndex] = true;
637 mCurrentFrame.fbCount++;
638 }
639 } else {
640 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
641 mCurrentFrame.isFBComposed[nYuvIndex] = false;
642 mCurrentFrame.fbCount--;
643 }
644 }
645 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700646
647 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
648 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800649 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
650 mCurrentFrame.fbCount);
651}
652
Saurabh Shahaa236822013-04-24 18:07:26 -0700653bool MDPComp::programMDP(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800654 if(!allocLayerPipes(ctx, list)) {
655 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700656 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800657 }
658
Saurabh Shahaa236822013-04-24 18:07:26 -0700659 bool fbBatch = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800660 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700661 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800662 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800663 int mdpIndex = mCurrentFrame.layerToMDP[index];
664 hwc_layer_1_t* layer = &list->hwLayers[index];
665
666 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
667 cur_pipe->zOrder = mdpNextZOrder++;
668
669 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
670 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
671 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -0700672 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800673 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700674 } else if(fbBatch == false) {
675 mdpNextZOrder++;
676 fbBatch = true;
677 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800678 }
679
Saurabh Shahaa236822013-04-24 18:07:26 -0700680 return true;
681}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800682
Saurabh Shahaa236822013-04-24 18:07:26 -0700683bool MDPComp::programYUV(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
684 if(!allocLayerPipes(ctx, list)) {
685 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
686 return false;
687 }
688 //If we are in this block, it means we have yuv + rgb layers both
689 int mdpIdx = 0;
690 for (int index = 0; index < mCurrentFrame.layerCount; index++) {
691 if(!mCurrentFrame.isFBComposed[index]) {
692 hwc_layer_1_t* layer = &list->hwLayers[index];
693 int mdpIndex = mCurrentFrame.layerToMDP[index];
694 MdpPipeInfo* cur_pipe =
695 mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
696 cur_pipe->zOrder = mdpIdx++;
697
698 if(configure(ctx, layer,
699 mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
700 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
701 layer %d",__FUNCTION__, index);
702 return false;
703 }
704 }
705 }
706 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800707}
708
709int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800710
711 //reset old data
Saurabh Shahaa236822013-04-24 18:07:26 -0700712 const int numLayers = ctx->listStats[mDpy].numAppLayers;
713 mCurrentFrame.reset(numLayers);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800714
Saurabh Shahaa236822013-04-24 18:07:26 -0700715 //Hard conditions, if not met, cannot do MDP comp
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800716 if(!isFrameDoable(ctx)) {
717 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
718 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700719 mCurrentFrame.reset(numLayers);
720 mCachedFrame.cacheAll(list);
721 mCachedFrame.updateCounts(mCurrentFrame);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800722 return 0;
723 }
724
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800725 //Check whether layers marked for MDP Composition is actually doable.
Saurabh Shahaa236822013-04-24 18:07:26 -0700726 if(isFullFrameDoable(ctx, list)){
Saurabh Shah2f3895f2013-05-02 10:13:31 -0700727 mCurrentFrame.map();
728 //Acquire and Program MDP pipes
729 if(!programMDP(ctx, list)) {
730 mCurrentFrame.reset(numLayers);
731 mCachedFrame.cacheAll(list);
732 } else { //Success
733 //Any change in composition types needs an FB refresh
734 mCurrentFrame.needsRedraw = false;
735 if(mCurrentFrame.fbCount &&
736 ((mCurrentFrame.mdpCount != mCachedFrame.mdpCount) ||
737 (mCurrentFrame.fbCount != mCachedFrame.cacheCount) ||
738 (mCurrentFrame.fbZ != mCachedFrame.fbZ) ||
739 (!mCurrentFrame.mdpCount) ||
740 (list->flags & HWC_GEOMETRY_CHANGED) ||
741 isSkipPresent(ctx, mDpy) ||
742 (mDpy > HWC_DISPLAY_PRIMARY))) {
743 mCurrentFrame.needsRedraw = true;
Saurabh Shahaa236822013-04-24 18:07:26 -0700744 }
745 }
746 } else if(isOnlyVideoDoable(ctx, list)) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800747 //All layers marked for MDP comp cannot be bypassed.
748 //Try to compose atleast YUV layers through MDP comp and let
749 //all the RGB layers compose in FB
Saurabh Shahaa236822013-04-24 18:07:26 -0700750 //Destination over
751 mCurrentFrame.fbZ = -1;
752 if(mCurrentFrame.fbCount)
753 mCurrentFrame.fbZ = ctx->listStats[mDpy].yuvCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800754
Saurabh Shahaa236822013-04-24 18:07:26 -0700755 mCurrentFrame.map();
756 if(!programYUV(ctx, list)) {
757 mCurrentFrame.reset(numLayers);
758 mCachedFrame.cacheAll(list);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800759 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700760 } else {
761 mCurrentFrame.reset(numLayers);
762 mCachedFrame.cacheAll(list);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800763 }
764
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800765 //UpdateLayerFlags
766 setMDPCompLayerFlags(ctx, list);
Saurabh Shahaa236822013-04-24 18:07:26 -0700767 mCachedFrame.updateCounts(mCurrentFrame);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800768
769 if(isDebug()) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700770 ALOGD("GEOMETRY change: %d", (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800771 android::String8 sDump("");
772 dump(sDump);
773 ALOGE("%s",sDump.string());
774 }
775
776 return mCurrentFrame.fbZ;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800777}
778
779//=============MDPCompLowRes===================================================
780
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700781/*
782 * Configures pipe(s) for MDP composition
783 */
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800784int MDPCompLowRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800785 PipeLayerPair& PipeLayerPair) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800786 MdpPipeInfoLowRes& mdp_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800787 *(static_cast<MdpPipeInfoLowRes*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -0800788 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
789 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
790 eIsFg isFg = IS_FG_OFF;
791 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700792
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800793 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
794 __FUNCTION__, layer, zOrder, dest);
795
796 return configureLowRes(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
797 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700798}
799
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800800int MDPCompLowRes::pipesNeeded(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800801 hwc_display_contents_1_t* list) {
802 return mCurrentFrame.mdpCount;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700803}
804
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800805bool MDPCompLowRes::allocLayerPipes(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800806 hwc_display_contents_1_t* list) {
807 if(isYuvPresent(ctx, mDpy)) {
808 int nYuvCount = ctx->listStats[mDpy].yuvCount;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700809
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800810 for(int index = 0; index < nYuvCount ; index ++) {
811 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500812
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800813 if(mCurrentFrame.isFBComposed[nYuvIndex])
814 continue;
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800815
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800816 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800817
818 int mdpIndex = mCurrentFrame.layerToMDP[nYuvIndex];
819
820 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800821 info.pipeInfo = new MdpPipeInfoLowRes;
Saurabh Shahacf10202013-02-26 10:15:15 -0800822 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800823 MdpPipeInfoLowRes& pipe_info = *(MdpPipeInfoLowRes*)info.pipeInfo;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800824
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800825 pipe_info.index = getMdpPipe(ctx, MDPCOMP_OV_VG);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800826 if(pipe_info.index == ovutils::OV_INVALID) {
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800827 ALOGD_IF(isDebug(), "%s: Unable to get pipe for Videos",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800828 __FUNCTION__);
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800829 return false;
830 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500831 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500832 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700833
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800834 for(int index = 0 ; index < mCurrentFrame.layerCount; index++ ) {
835 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800836 hwc_layer_1_t* layer = &list->hwLayers[index];
837 private_handle_t *hnd = (private_handle_t *)layer->handle;
838
839 if(isYuvBuffer(hnd))
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500840 continue;
841
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800842 int mdpIndex = mCurrentFrame.layerToMDP[index];
843
844 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800845 info.pipeInfo = new MdpPipeInfoLowRes;
Saurabh Shahacf10202013-02-26 10:15:15 -0800846 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800847 MdpPipeInfoLowRes& pipe_info = *(MdpPipeInfoLowRes*)info.pipeInfo;
848
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800849 ePipeType type = MDPCOMP_OV_ANY;
850
Saurabh Shah85234ec2013-04-12 17:09:00 -0700851 if(!qhwc::needsScaling(layer)
852 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
853 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800854 type = MDPCOMP_OV_DMA;
855 }
856
857 pipe_info.index = getMdpPipe(ctx, type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800858 if(pipe_info.index == ovutils::OV_INVALID) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500859 ALOGD_IF(isDebug(), "%s: Unable to get pipe for UI", __FUNCTION__);
860 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700861 }
862 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700863 return true;
864}
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700865
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800866bool MDPCompLowRes::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700867
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800868 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500869 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
870 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800871 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700872
873 if(!ctx || !list) {
874 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500875 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700876 }
877
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500878 /* reset Invalidator */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800879 if(idleInvalidator && mCurrentFrame.mdpCount)
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500880 idleInvalidator->markForSleep();
881
882 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800883 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700884
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800885 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
886 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700887 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800888 if(mCurrentFrame.isFBComposed[i]) continue;
889
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700890 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -0800891 private_handle_t *hnd = (private_handle_t *)layer->handle;
892 if(!hnd) {
893 ALOGE("%s handle null", __FUNCTION__);
894 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700895 }
896
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800897 int mdpIndex = mCurrentFrame.layerToMDP[i];
898
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800899 MdpPipeInfoLowRes& pipe_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800900 *(MdpPipeInfoLowRes*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800901 ovutils::eDest dest = pipe_info.index;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800902 if(dest == ovutils::OV_INVALID) {
903 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500904 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700905 }
906
Saurabh Shahacf10202013-02-26 10:15:15 -0800907 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
908 continue;
909 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700910
Saurabh Shahacf10202013-02-26 10:15:15 -0800911 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800912 using pipe: %d", __FUNCTION__, layer,
913 hnd, dest );
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700914
Saurabh Shahacf10202013-02-26 10:15:15 -0800915 int fd = hnd->fd;
916 uint32_t offset = hnd->offset;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800917 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -0800918 if(rot) {
919 if(!rot->queueBuffer(fd, offset))
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500920 return false;
Saurabh Shahacf10202013-02-26 10:15:15 -0800921 fd = rot->getDstMemId();
922 offset = rot->getDstOffset();
923 }
924
925 if (!ov.queueBuffer(fd, offset, dest)) {
926 ALOGE("%s: queueBuffer failed for external", __FUNCTION__);
927 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700928 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500929
930 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700931 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500932 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700933}
934
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800935//=============MDPCompHighRes===================================================
936
937int MDPCompHighRes::pipesNeeded(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800938 hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800939 int pipesNeeded = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800940 int hw_w = ctx->dpyAttr[mDpy].xres;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800941
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800942 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
943 if(!mCurrentFrame.isFBComposed[i]) {
944 hwc_layer_1_t* layer = &list->hwLayers[i];
945 hwc_rect_t dst = layer->displayFrame;
946 if(dst.left > hw_w/2) {
947 pipesNeeded++;
948 } else if(dst.right <= hw_w/2) {
949 pipesNeeded++;
950 } else {
951 pipesNeeded += 2;
952 }
953 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800954 }
955 return pipesNeeded;
956}
957
958bool MDPCompHighRes::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800959 MdpPipeInfoHighRes& pipe_info,
960 ePipeType type) {
961 int hw_w = ctx->dpyAttr[mDpy].xres;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800962
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800963 hwc_rect_t dst = layer->displayFrame;
964 if(dst.left > hw_w/2) {
965 pipe_info.lIndex = ovutils::OV_INVALID;
966 pipe_info.rIndex = getMdpPipe(ctx, type);
967 if(pipe_info.rIndex == ovutils::OV_INVALID)
968 return false;
969 } else if (dst.right <= hw_w/2) {
970 pipe_info.rIndex = ovutils::OV_INVALID;
971 pipe_info.lIndex = getMdpPipe(ctx, type);
972 if(pipe_info.lIndex == ovutils::OV_INVALID)
973 return false;
974 } else {
975 pipe_info.rIndex = getMdpPipe(ctx, type);
976 pipe_info.lIndex = getMdpPipe(ctx, type);
977 if(pipe_info.rIndex == ovutils::OV_INVALID ||
978 pipe_info.lIndex == ovutils::OV_INVALID)
979 return false;
980 }
981 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800982}
983
984bool MDPCompHighRes::allocLayerPipes(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800985 hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800986 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800987 int layer_count = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800988
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800989 if(isYuvPresent(ctx, mDpy)) {
990 int nYuvCount = ctx->listStats[mDpy].yuvCount;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800991
992 for(int index = 0; index < nYuvCount; index ++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800993 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800994 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800995 PipeLayerPair& info = mCurrentFrame.mdpToLayer[nYuvIndex];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800996 info.pipeInfo = new MdpPipeInfoHighRes;
Saurabh Shah9e3adb22013-03-26 11:16:27 -0700997 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800998 MdpPipeInfoHighRes& pipe_info = *(MdpPipeInfoHighRes*)info.pipeInfo;
999 if(!acquireMDPPipes(ctx, layer, pipe_info,MDPCOMP_OV_VG)) {
1000 ALOGD_IF(isDebug(),"%s: Unable to get pipe for videos",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001001 __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001002 //TODO: windback pipebook data on fail
1003 return false;
1004 }
1005 pipe_info.zOrder = nYuvIndex;
1006 }
1007 }
1008
1009 for(int index = 0 ; index < layer_count ; index++ ) {
1010 hwc_layer_1_t* layer = &list->hwLayers[index];
1011 private_handle_t *hnd = (private_handle_t *)layer->handle;
1012
1013 if(isYuvBuffer(hnd))
1014 continue;
1015
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001016 PipeLayerPair& info = mCurrentFrame.mdpToLayer[index];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001017 info.pipeInfo = new MdpPipeInfoHighRes;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001018 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001019 MdpPipeInfoHighRes& pipe_info = *(MdpPipeInfoHighRes*)info.pipeInfo;
1020
1021 ePipeType type = MDPCOMP_OV_ANY;
1022
Saurabh Shah85234ec2013-04-12 17:09:00 -07001023 if(!qhwc::needsScaling(layer)
1024 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
1025 && ctx->mMDP.version >= qdutils::MDSS_V5)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001026 type = MDPCOMP_OV_DMA;
1027
1028 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
1029 ALOGD_IF(isDebug(), "%s: Unable to get pipe for UI", __FUNCTION__);
1030 //TODO: windback pipebook data on fail
1031 return false;
1032 }
1033 pipe_info.zOrder = index;
1034 }
1035 return true;
1036}
1037/*
1038 * Configures pipe(s) for MDP composition
1039 */
1040int MDPCompHighRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001041 PipeLayerPair& PipeLayerPair) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001042 MdpPipeInfoHighRes& mdp_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001043 *(static_cast<MdpPipeInfoHighRes*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001044 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1045 eIsFg isFg = IS_FG_OFF;
1046 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1047 eDest lDest = mdp_info.lIndex;
1048 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001049
1050 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1051 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1052
1053 return configureHighRes(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
1054 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001055}
1056
1057bool MDPCompHighRes::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
1058
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001059 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001060 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1061 return true;
1062 }
1063
1064 if(!ctx || !list) {
1065 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001066 return false;
1067 }
1068
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001069 /* reset Invalidator */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001070 if(idleInvalidator && mCurrentFrame.mdpCount)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001071 idleInvalidator->markForSleep();
1072
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001073 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001074 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001075
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001076 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1077 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001078 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001079 if(mCurrentFrame.isFBComposed[i]) continue;
1080
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001081 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001082 private_handle_t *hnd = (private_handle_t *)layer->handle;
1083 if(!hnd) {
1084 ALOGE("%s handle null", __FUNCTION__);
1085 return false;
1086 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001087
1088 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1089 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001090 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001091
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001092 int mdpIndex = mCurrentFrame.layerToMDP[i];
1093
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001094 MdpPipeInfoHighRes& pipe_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001095 *(MdpPipeInfoHighRes*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1096 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -08001097
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001098 ovutils::eDest indexL = pipe_info.lIndex;
1099 ovutils::eDest indexR = pipe_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001100
Saurabh Shahacf10202013-02-26 10:15:15 -08001101 int fd = hnd->fd;
1102 int offset = hnd->offset;
1103
1104 if(rot) {
1105 rot->queueBuffer(fd, offset);
1106 fd = rot->getDstMemId();
1107 offset = rot->getDstOffset();
1108 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001109
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001110 //************* play left mixer **********
1111 if(indexL != ovutils::OV_INVALID) {
1112 ovutils::eDest destL = (ovutils::eDest)indexL;
Saurabh Shahacf10202013-02-26 10:15:15 -08001113 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001114 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
Saurabh Shahacf10202013-02-26 10:15:15 -08001115 if (!ov.queueBuffer(fd, offset, destL)) {
1116 ALOGE("%s: queueBuffer failed for left mixer", __FUNCTION__);
1117 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001118 }
1119 }
1120
1121 //************* play right mixer **********
1122 if(indexR != ovutils::OV_INVALID) {
1123 ovutils::eDest destR = (ovutils::eDest)indexR;
Saurabh Shahacf10202013-02-26 10:15:15 -08001124 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001125 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
Saurabh Shahacf10202013-02-26 10:15:15 -08001126 if (!ov.queueBuffer(fd, offset, destR)) {
1127 ALOGE("%s: queueBuffer failed for right mixer", __FUNCTION__);
1128 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001129 }
1130 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001131
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001132 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1133 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001134
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001135 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001136}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001137}; //namespace
1138