blob: 69775649a42bc99f8b3e76e679d05323989d5b92 [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) {
371 sIdleFallBack = false;
372 ALOGD_IF(isDebug(), "%s: idle fallback",__FUNCTION__);
373 ret = false;
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700374 }
375
Saurabh Shahaa236822013-04-24 18:07:26 -0700376 return ret;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800377}
378
379/* Checks for conditions where all the layers marked for MDP comp cannot be
380 * bypassed. On such conditions we try to bypass atleast YUV layers */
381bool MDPComp::isFullFrameDoable(hwc_context_t *ctx,
382 hwc_display_contents_1_t* list){
383
Saurabh Shahaa236822013-04-24 18:07:26 -0700384 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800385
386 if(mDpy > HWC_DISPLAY_PRIMARY){
387 ALOGD_IF(isDebug(), "%s: Cannot support External display(s)",
388 __FUNCTION__);
389 return false;
390 }
391
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800392 if(isSkipPresent(ctx, mDpy)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700393 ALOGD_IF(isDebug(),"%s: SKIP present: %d",
394 __FUNCTION__,
395 isSkipPresent(ctx, mDpy));
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800396 return false;
397 }
398
Saurabh Shah9f084ad2013-05-02 11:28:09 -0700399 if(ctx->listStats[mDpy].needsAlphaScale
400 && ctx->mMDP.version < qdutils::MDSS_V5) {
401 ALOGD_IF(isDebug(), "%s: frame needs alpha downscaling",__FUNCTION__);
402 return false;
403 }
404
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800405 //MDP composition is not efficient if layer needs rotator.
406 for(int i = 0; i < numAppLayers; ++i) {
407 // As MDP h/w supports flip operation, use MDP comp only for
408 // 180 transforms. Fail for any transform involving 90 (90, 270).
409 hwc_layer_1_t* layer = &list->hwLayers[i];
410 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800411
Saurabh Shah4fdde762013-04-30 18:47:33 -0700412 if((layer->transform & HWC_TRANSFORM_ROT_90) && !isYuvBuffer(hnd)) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800413 ALOGD_IF(isDebug(), "%s: orientation involved",__FUNCTION__);
414 return false;
415 }
416
Saurabh Shah4fdde762013-04-30 18:47:33 -0700417 if(!isValidDimension(ctx,layer)) {
418 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
419 __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800420 return false;
421 }
422 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700423
424 //If all above hard conditions are met we can do full or partial MDP comp.
425 bool ret = false;
426 if(fullMDPComp(ctx, list)) {
427 ret = true;
428 } else if (partialMDPComp(ctx, list)) {
429 ret = true;
430 }
431 return ret;
432}
433
434bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
435 //Setup mCurrentFrame
436 mCurrentFrame.mdpCount = mCurrentFrame.layerCount;
437 mCurrentFrame.fbCount = 0;
438 mCurrentFrame.fbZ = -1;
439 memset(&mCurrentFrame.isFBComposed, 0, sizeof(mCurrentFrame.isFBComposed));
440
441 int mdpCount = mCurrentFrame.mdpCount;
442 if(mdpCount > sMaxPipesPerMixer) {
443 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
444 return false;
445 }
446
447 int numPipesNeeded = pipesNeeded(ctx, list);
448 int availPipes = getAvailablePipes(ctx);
449
450 if(numPipesNeeded > availPipes) {
451 ALOGD_IF(isDebug(), "%s: Insufficient MDP pipes, needed %d, avail %d",
452 __FUNCTION__, numPipesNeeded, availPipes);
453 return false;
454 }
455
456 return true;
457}
458
459bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
460{
461 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
462 //Setup mCurrentFrame
463 mCurrentFrame.reset(numAppLayers);
464 updateLayerCache(ctx, list);
465 updateYUV(ctx, list);
466 batchLayers(); //sets up fbZ also
467
468 int mdpCount = mCurrentFrame.mdpCount;
469 if(mdpCount > (sMaxPipesPerMixer - 1)) { // -1 since FB is used
470 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
471 return false;
472 }
473
474 int numPipesNeeded = pipesNeeded(ctx, list);
475 int availPipes = getAvailablePipes(ctx);
476
477 if(numPipesNeeded > availPipes) {
478 ALOGD_IF(isDebug(), "%s: Insufficient MDP pipes, needed %d, avail %d",
479 __FUNCTION__, numPipesNeeded, availPipes);
480 return false;
481 }
482
483 return true;
484}
485
486bool MDPComp::isOnlyVideoDoable(hwc_context_t *ctx,
487 hwc_display_contents_1_t* list){
488 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
489 mCurrentFrame.reset(numAppLayers);
490 updateYUV(ctx, list);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700491 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700492 int fbNeeded = int(mCurrentFrame.fbCount != 0);
493
494 if(!isYuvPresent(ctx, mDpy)) {
495 return false;
496 }
497
Saurabh Shah4fdde762013-04-30 18:47:33 -0700498 if(!mdpCount)
499 return false;
500
Saurabh Shahaa236822013-04-24 18:07:26 -0700501 if(mdpCount > (sMaxPipesPerMixer - fbNeeded)) {
502 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
503 return false;
504 }
505
506 int numPipesNeeded = pipesNeeded(ctx, list);
507 int availPipes = getAvailablePipes(ctx);
508 if(numPipesNeeded > availPipes) {
509 ALOGD_IF(isDebug(), "%s: Insufficient MDP pipes, needed %d, avail %d",
510 __FUNCTION__, numPipesNeeded, availPipes);
511 return false;
512 }
513
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800514 return true;
515}
516
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800517/* Checks for conditions where YUV layers cannot be bypassed */
518bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800519
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800520 if(isSkipLayer(layer)) {
521 ALOGE("%s: Unable to bypass skipped YUV", __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800522 return false;
523 }
524
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800525 if(isSecuring(ctx, layer)) {
526 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
527 return false;
528 }
529
Saurabh Shah4fdde762013-04-30 18:47:33 -0700530 if(!isValidDimension(ctx, layer)) {
531 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
532 __FUNCTION__);
533 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800534 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700535
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800536 return true;
537}
538
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800539void MDPComp::batchLayers() {
540 /* Idea is to keep as many contiguous non-updating(cached) layers in FB and
541 * send rest of them through MDP. NEVER mark an updating layer for caching.
542 * But cached ones can be marked for MDP*/
543
544 int maxBatchStart = -1;
545 int maxBatchCount = 0;
546
547 /* All or Nothing is cached. No batching needed */
Saurabh Shahaa236822013-04-24 18:07:26 -0700548 if(!mCurrentFrame.fbCount) {
549 mCurrentFrame.fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800550 return;
Saurabh Shahaa236822013-04-24 18:07:26 -0700551 }
552 if(!mCurrentFrame.mdpCount) {
553 mCurrentFrame.fbZ = 0;
554 return;
555 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800556
557 /* Search for max number of contiguous (cached) layers */
558 int i = 0;
559 while (i < mCurrentFrame.layerCount) {
560 int count = 0;
561 while(mCurrentFrame.isFBComposed[i] && i < mCurrentFrame.layerCount) {
562 count++; i++;
563 }
564 if(count > maxBatchCount) {
565 maxBatchCount = count;
566 maxBatchStart = i - count;
Saurabh Shahaa236822013-04-24 18:07:26 -0700567 mCurrentFrame.fbZ = maxBatchStart;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800568 }
569 if(i < mCurrentFrame.layerCount) i++;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800570 }
571
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800572 /* reset rest of the layers for MDP comp */
573 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
574 if(i != maxBatchStart){
575 mCurrentFrame.isFBComposed[i] = false;
576 } else {
577 i += maxBatchCount;
578 }
579 }
580
581 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700582 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
583 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800584
585 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
586 mCurrentFrame.fbCount);
587}
Saurabh Shah85234ec2013-04-12 17:09:00 -0700588
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800589void MDPComp::updateLayerCache(hwc_context_t* ctx,
590 hwc_display_contents_1_t* list) {
591
592 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
593 int numCacheableLayers = 0;
594
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800595 for(int i = 0; i < numAppLayers; i++) {
596 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
597 numCacheableLayers++;
598 mCurrentFrame.isFBComposed[i] = true;
599 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -0700600 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800601 mCachedFrame.hnd[i] = list->hwLayers[i].handle;
602 }
603 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700604
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800605 mCurrentFrame.fbCount = numCacheableLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700606 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
607 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800608 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__, numCacheableLayers);
609}
610
611int MDPComp::getAvailablePipes(hwc_context_t* ctx) {
612 int numDMAPipes = qdutils::MDPVersion::getInstance().getDMAPipes();
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800613 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800614
615 int numAvailable = ov.availablePipes(mDpy);
616
617 //Reserve DMA for rotator
Saurabh Shah85234ec2013-04-12 17:09:00 -0700618 if(Overlay::getDMAMode() == Overlay::DMA_BLOCK_MODE)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800619 numAvailable -= numDMAPipes;
620
621 //Reserve pipe(s)for FB
622 if(mCurrentFrame.fbCount)
623 numAvailable -= pipesForFB();
624
625 return numAvailable;
626}
627
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800628void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list) {
629
630 int nYuvCount = ctx->listStats[mDpy].yuvCount;
631 for(int index = 0;index < nYuvCount; index++){
632 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
633 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
634
635 if(!isYUVDoable(ctx, layer)) {
636 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
637 mCurrentFrame.isFBComposed[nYuvIndex] = true;
638 mCurrentFrame.fbCount++;
639 }
640 } else {
641 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
642 mCurrentFrame.isFBComposed[nYuvIndex] = false;
643 mCurrentFrame.fbCount--;
644 }
645 }
646 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700647
648 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
649 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800650 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
651 mCurrentFrame.fbCount);
652}
653
Saurabh Shahaa236822013-04-24 18:07:26 -0700654bool MDPComp::programMDP(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800655 if(!allocLayerPipes(ctx, list)) {
656 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700657 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800658 }
659
Saurabh Shahaa236822013-04-24 18:07:26 -0700660 bool fbBatch = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800661 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700662 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800663 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800664 int mdpIndex = mCurrentFrame.layerToMDP[index];
665 hwc_layer_1_t* layer = &list->hwLayers[index];
666
667 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
668 cur_pipe->zOrder = mdpNextZOrder++;
669
670 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
671 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
672 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -0700673 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800674 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700675 } else if(fbBatch == false) {
676 mdpNextZOrder++;
677 fbBatch = true;
678 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800679 }
680
Saurabh Shahaa236822013-04-24 18:07:26 -0700681 return true;
682}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800683
Saurabh Shahaa236822013-04-24 18:07:26 -0700684bool MDPComp::programYUV(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
685 if(!allocLayerPipes(ctx, list)) {
686 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
687 return false;
688 }
689 //If we are in this block, it means we have yuv + rgb layers both
690 int mdpIdx = 0;
691 for (int index = 0; index < mCurrentFrame.layerCount; index++) {
692 if(!mCurrentFrame.isFBComposed[index]) {
693 hwc_layer_1_t* layer = &list->hwLayers[index];
694 int mdpIndex = mCurrentFrame.layerToMDP[index];
695 MdpPipeInfo* cur_pipe =
696 mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
697 cur_pipe->zOrder = mdpIdx++;
698
699 if(configure(ctx, layer,
700 mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
701 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
702 layer %d",__FUNCTION__, index);
703 return false;
704 }
705 }
706 }
707 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800708}
709
710int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800711
712 //reset old data
Saurabh Shahaa236822013-04-24 18:07:26 -0700713 const int numLayers = ctx->listStats[mDpy].numAppLayers;
714 mCurrentFrame.reset(numLayers);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800715
Saurabh Shahaa236822013-04-24 18:07:26 -0700716 //Hard conditions, if not met, cannot do MDP comp
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800717 if(!isFrameDoable(ctx)) {
718 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
719 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700720 mCurrentFrame.reset(numLayers);
721 mCachedFrame.cacheAll(list);
722 mCachedFrame.updateCounts(mCurrentFrame);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800723 return 0;
724 }
725
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800726 //Check whether layers marked for MDP Composition is actually doable.
Saurabh Shahaa236822013-04-24 18:07:26 -0700727 if(isFullFrameDoable(ctx, list)){
Saurabh Shah2f3895f2013-05-02 10:13:31 -0700728 mCurrentFrame.map();
729 //Acquire and Program MDP pipes
730 if(!programMDP(ctx, list)) {
731 mCurrentFrame.reset(numLayers);
732 mCachedFrame.cacheAll(list);
733 } else { //Success
734 //Any change in composition types needs an FB refresh
735 mCurrentFrame.needsRedraw = false;
736 if(mCurrentFrame.fbCount &&
737 ((mCurrentFrame.mdpCount != mCachedFrame.mdpCount) ||
738 (mCurrentFrame.fbCount != mCachedFrame.cacheCount) ||
739 (mCurrentFrame.fbZ != mCachedFrame.fbZ) ||
740 (!mCurrentFrame.mdpCount) ||
741 (list->flags & HWC_GEOMETRY_CHANGED) ||
742 isSkipPresent(ctx, mDpy) ||
743 (mDpy > HWC_DISPLAY_PRIMARY))) {
744 mCurrentFrame.needsRedraw = true;
Saurabh Shahaa236822013-04-24 18:07:26 -0700745 }
746 }
747 } else if(isOnlyVideoDoable(ctx, list)) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800748 //All layers marked for MDP comp cannot be bypassed.
749 //Try to compose atleast YUV layers through MDP comp and let
750 //all the RGB layers compose in FB
Saurabh Shahaa236822013-04-24 18:07:26 -0700751 //Destination over
752 mCurrentFrame.fbZ = -1;
753 if(mCurrentFrame.fbCount)
754 mCurrentFrame.fbZ = ctx->listStats[mDpy].yuvCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800755
Saurabh Shahaa236822013-04-24 18:07:26 -0700756 mCurrentFrame.map();
757 if(!programYUV(ctx, list)) {
758 mCurrentFrame.reset(numLayers);
759 mCachedFrame.cacheAll(list);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800760 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700761 } else {
762 mCurrentFrame.reset(numLayers);
763 mCachedFrame.cacheAll(list);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800764 }
765
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800766 //UpdateLayerFlags
767 setMDPCompLayerFlags(ctx, list);
Saurabh Shahaa236822013-04-24 18:07:26 -0700768 mCachedFrame.updateCounts(mCurrentFrame);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800769
770 if(isDebug()) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700771 ALOGD("GEOMETRY change: %d", (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800772 android::String8 sDump("");
773 dump(sDump);
774 ALOGE("%s",sDump.string());
775 }
776
777 return mCurrentFrame.fbZ;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800778}
779
780//=============MDPCompLowRes===================================================
781
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700782/*
783 * Configures pipe(s) for MDP composition
784 */
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800785int MDPCompLowRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800786 PipeLayerPair& PipeLayerPair) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800787 MdpPipeInfoLowRes& mdp_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800788 *(static_cast<MdpPipeInfoLowRes*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -0800789 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
790 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
791 eIsFg isFg = IS_FG_OFF;
792 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700793
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800794 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
795 __FUNCTION__, layer, zOrder, dest);
796
797 return configureLowRes(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
798 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700799}
800
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800801int MDPCompLowRes::pipesNeeded(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800802 hwc_display_contents_1_t* list) {
803 return mCurrentFrame.mdpCount;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700804}
805
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800806bool MDPCompLowRes::allocLayerPipes(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800807 hwc_display_contents_1_t* list) {
808 if(isYuvPresent(ctx, mDpy)) {
809 int nYuvCount = ctx->listStats[mDpy].yuvCount;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700810
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800811 for(int index = 0; index < nYuvCount ; index ++) {
812 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500813
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800814 if(mCurrentFrame.isFBComposed[nYuvIndex])
815 continue;
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800816
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800817 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800818
819 int mdpIndex = mCurrentFrame.layerToMDP[nYuvIndex];
820
821 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800822 info.pipeInfo = new MdpPipeInfoLowRes;
Saurabh Shahacf10202013-02-26 10:15:15 -0800823 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800824 MdpPipeInfoLowRes& pipe_info = *(MdpPipeInfoLowRes*)info.pipeInfo;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800825
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800826 pipe_info.index = getMdpPipe(ctx, MDPCOMP_OV_VG);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800827 if(pipe_info.index == ovutils::OV_INVALID) {
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800828 ALOGD_IF(isDebug(), "%s: Unable to get pipe for Videos",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800829 __FUNCTION__);
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800830 return false;
831 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500832 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500833 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700834
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800835 for(int index = 0 ; index < mCurrentFrame.layerCount; index++ ) {
836 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800837 hwc_layer_1_t* layer = &list->hwLayers[index];
838 private_handle_t *hnd = (private_handle_t *)layer->handle;
839
840 if(isYuvBuffer(hnd))
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500841 continue;
842
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800843 int mdpIndex = mCurrentFrame.layerToMDP[index];
844
845 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800846 info.pipeInfo = new MdpPipeInfoLowRes;
Saurabh Shahacf10202013-02-26 10:15:15 -0800847 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800848 MdpPipeInfoLowRes& pipe_info = *(MdpPipeInfoLowRes*)info.pipeInfo;
849
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800850 ePipeType type = MDPCOMP_OV_ANY;
851
Saurabh Shah85234ec2013-04-12 17:09:00 -0700852 if(!qhwc::needsScaling(layer)
853 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
854 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800855 type = MDPCOMP_OV_DMA;
856 }
857
858 pipe_info.index = getMdpPipe(ctx, type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800859 if(pipe_info.index == ovutils::OV_INVALID) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500860 ALOGD_IF(isDebug(), "%s: Unable to get pipe for UI", __FUNCTION__);
861 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700862 }
863 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700864 return true;
865}
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700866
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800867bool MDPCompLowRes::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700868
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800869 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500870 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
871 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800872 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700873
874 if(!ctx || !list) {
875 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500876 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700877 }
878
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500879 /* reset Invalidator */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800880 if(idleInvalidator && mCurrentFrame.mdpCount)
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500881 idleInvalidator->markForSleep();
882
883 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800884 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700885
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800886 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
887 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700888 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800889 if(mCurrentFrame.isFBComposed[i]) continue;
890
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700891 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -0800892 private_handle_t *hnd = (private_handle_t *)layer->handle;
893 if(!hnd) {
894 ALOGE("%s handle null", __FUNCTION__);
895 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700896 }
897
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800898 int mdpIndex = mCurrentFrame.layerToMDP[i];
899
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800900 MdpPipeInfoLowRes& pipe_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800901 *(MdpPipeInfoLowRes*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800902 ovutils::eDest dest = pipe_info.index;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800903 if(dest == ovutils::OV_INVALID) {
904 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500905 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700906 }
907
Saurabh Shahacf10202013-02-26 10:15:15 -0800908 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
909 continue;
910 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700911
Saurabh Shahacf10202013-02-26 10:15:15 -0800912 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800913 using pipe: %d", __FUNCTION__, layer,
914 hnd, dest );
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700915
Saurabh Shahacf10202013-02-26 10:15:15 -0800916 int fd = hnd->fd;
917 uint32_t offset = hnd->offset;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800918 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -0800919 if(rot) {
920 if(!rot->queueBuffer(fd, offset))
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500921 return false;
Saurabh Shahacf10202013-02-26 10:15:15 -0800922 fd = rot->getDstMemId();
923 offset = rot->getDstOffset();
924 }
925
926 if (!ov.queueBuffer(fd, offset, dest)) {
927 ALOGE("%s: queueBuffer failed for external", __FUNCTION__);
928 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700929 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500930
931 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700932 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500933 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700934}
935
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800936//=============MDPCompHighRes===================================================
937
938int MDPCompHighRes::pipesNeeded(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800939 hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800940 int pipesNeeded = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800941 int hw_w = ctx->dpyAttr[mDpy].xres;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800942
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800943 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
944 if(!mCurrentFrame.isFBComposed[i]) {
945 hwc_layer_1_t* layer = &list->hwLayers[i];
946 hwc_rect_t dst = layer->displayFrame;
947 if(dst.left > hw_w/2) {
948 pipesNeeded++;
949 } else if(dst.right <= hw_w/2) {
950 pipesNeeded++;
951 } else {
952 pipesNeeded += 2;
953 }
954 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800955 }
956 return pipesNeeded;
957}
958
959bool MDPCompHighRes::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800960 MdpPipeInfoHighRes& pipe_info,
961 ePipeType type) {
962 int hw_w = ctx->dpyAttr[mDpy].xres;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800963
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800964 hwc_rect_t dst = layer->displayFrame;
965 if(dst.left > hw_w/2) {
966 pipe_info.lIndex = ovutils::OV_INVALID;
967 pipe_info.rIndex = getMdpPipe(ctx, type);
968 if(pipe_info.rIndex == ovutils::OV_INVALID)
969 return false;
970 } else if (dst.right <= hw_w/2) {
971 pipe_info.rIndex = ovutils::OV_INVALID;
972 pipe_info.lIndex = getMdpPipe(ctx, type);
973 if(pipe_info.lIndex == ovutils::OV_INVALID)
974 return false;
975 } else {
976 pipe_info.rIndex = getMdpPipe(ctx, type);
977 pipe_info.lIndex = getMdpPipe(ctx, type);
978 if(pipe_info.rIndex == ovutils::OV_INVALID ||
979 pipe_info.lIndex == ovutils::OV_INVALID)
980 return false;
981 }
982 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800983}
984
985bool MDPCompHighRes::allocLayerPipes(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800986 hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800987 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800988 int layer_count = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800989
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800990 if(isYuvPresent(ctx, mDpy)) {
991 int nYuvCount = ctx->listStats[mDpy].yuvCount;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800992
993 for(int index = 0; index < nYuvCount; index ++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800994 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800995 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800996 PipeLayerPair& info = mCurrentFrame.mdpToLayer[nYuvIndex];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800997 info.pipeInfo = new MdpPipeInfoHighRes;
Saurabh Shah9e3adb22013-03-26 11:16:27 -0700998 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800999 MdpPipeInfoHighRes& pipe_info = *(MdpPipeInfoHighRes*)info.pipeInfo;
1000 if(!acquireMDPPipes(ctx, layer, pipe_info,MDPCOMP_OV_VG)) {
1001 ALOGD_IF(isDebug(),"%s: Unable to get pipe for videos",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001002 __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001003 //TODO: windback pipebook data on fail
1004 return false;
1005 }
1006 pipe_info.zOrder = nYuvIndex;
1007 }
1008 }
1009
1010 for(int index = 0 ; index < layer_count ; index++ ) {
1011 hwc_layer_1_t* layer = &list->hwLayers[index];
1012 private_handle_t *hnd = (private_handle_t *)layer->handle;
1013
1014 if(isYuvBuffer(hnd))
1015 continue;
1016
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001017 PipeLayerPair& info = mCurrentFrame.mdpToLayer[index];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001018 info.pipeInfo = new MdpPipeInfoHighRes;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001019 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001020 MdpPipeInfoHighRes& pipe_info = *(MdpPipeInfoHighRes*)info.pipeInfo;
1021
1022 ePipeType type = MDPCOMP_OV_ANY;
1023
Saurabh Shah85234ec2013-04-12 17:09:00 -07001024 if(!qhwc::needsScaling(layer)
1025 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
1026 && ctx->mMDP.version >= qdutils::MDSS_V5)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001027 type = MDPCOMP_OV_DMA;
1028
1029 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
1030 ALOGD_IF(isDebug(), "%s: Unable to get pipe for UI", __FUNCTION__);
1031 //TODO: windback pipebook data on fail
1032 return false;
1033 }
1034 pipe_info.zOrder = index;
1035 }
1036 return true;
1037}
1038/*
1039 * Configures pipe(s) for MDP composition
1040 */
1041int MDPCompHighRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001042 PipeLayerPair& PipeLayerPair) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001043 MdpPipeInfoHighRes& mdp_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001044 *(static_cast<MdpPipeInfoHighRes*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001045 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1046 eIsFg isFg = IS_FG_OFF;
1047 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1048 eDest lDest = mdp_info.lIndex;
1049 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001050
1051 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1052 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1053
1054 return configureHighRes(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
1055 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001056}
1057
1058bool MDPCompHighRes::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
1059
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001060 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001061 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1062 return true;
1063 }
1064
1065 if(!ctx || !list) {
1066 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001067 return false;
1068 }
1069
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001070 /* reset Invalidator */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001071 if(idleInvalidator && mCurrentFrame.mdpCount)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001072 idleInvalidator->markForSleep();
1073
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001074 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001075 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001076
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001077 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1078 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001079 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001080 if(mCurrentFrame.isFBComposed[i]) continue;
1081
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001082 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001083 private_handle_t *hnd = (private_handle_t *)layer->handle;
1084 if(!hnd) {
1085 ALOGE("%s handle null", __FUNCTION__);
1086 return false;
1087 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001088
1089 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1090 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001091 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001092
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001093 int mdpIndex = mCurrentFrame.layerToMDP[i];
1094
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001095 MdpPipeInfoHighRes& pipe_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001096 *(MdpPipeInfoHighRes*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1097 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -08001098
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001099 ovutils::eDest indexL = pipe_info.lIndex;
1100 ovutils::eDest indexR = pipe_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001101
Saurabh Shahacf10202013-02-26 10:15:15 -08001102 int fd = hnd->fd;
1103 int offset = hnd->offset;
1104
1105 if(rot) {
1106 rot->queueBuffer(fd, offset);
1107 fd = rot->getDstMemId();
1108 offset = rot->getDstOffset();
1109 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001110
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001111 //************* play left mixer **********
1112 if(indexL != ovutils::OV_INVALID) {
1113 ovutils::eDest destL = (ovutils::eDest)indexL;
Saurabh Shahacf10202013-02-26 10:15:15 -08001114 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001115 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
Saurabh Shahacf10202013-02-26 10:15:15 -08001116 if (!ov.queueBuffer(fd, offset, destL)) {
1117 ALOGE("%s: queueBuffer failed for left mixer", __FUNCTION__);
1118 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001119 }
1120 }
1121
1122 //************* play right mixer **********
1123 if(indexR != ovutils::OV_INVALID) {
1124 ovutils::eDest destR = (ovutils::eDest)indexR;
Saurabh Shahacf10202013-02-26 10:15:15 -08001125 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001126 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
Saurabh Shahacf10202013-02-26 10:15:15 -08001127 if (!ov.queueBuffer(fd, offset, destR)) {
1128 ALOGE("%s: queueBuffer failed for right mixer", __FUNCTION__);
1129 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001130 }
1131 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001132
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001133 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1134 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001135
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001136 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001137}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001138}; //namespace
1139