blob: cfc25588abfe3c131ffae49a264dd14bbb05222e [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
19#include "hwc_mdpcomp.h"
Naseer Ahmed54821fe2012-11-28 18:44:38 -050020#include <sys/ioctl.h>
Saurabh Shah56f610d2012-08-07 15:27:06 -070021#include "external.h"
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -080022#include "qdMetaData.h"
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -080023#include "mdp_version.h"
Saurabh Shahacf10202013-02-26 10:15:15 -080024#include <overlayRotator.h>
25
Saurabh Shah85234ec2013-04-12 17:09:00 -070026using namespace overlay;
Saurabh Shahbd2d0832013-04-04 14:33:08 -070027using namespace qdutils;
Saurabh Shahacf10202013-02-26 10:15:15 -080028using namespace overlay::utils;
29namespace ovutils = overlay::utils;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070030
Naseer Ahmed7c958d42012-07-31 18:57:03 -070031namespace qhwc {
32
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080033//==============MDPComp========================================================
34
Naseer Ahmed7c958d42012-07-31 18:57:03 -070035IdleInvalidator *MDPComp::idleInvalidator = NULL;
36bool MDPComp::sIdleFallBack = false;
37bool MDPComp::sDebugLogs = false;
Naseer Ahmed54821fe2012-11-28 18:44:38 -050038bool MDPComp::sEnabled = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080039int MDPComp::sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070040
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080041MDPComp* MDPComp::getObject(const int& width, int dpy) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080042 if(width <= MAX_DISPLAY_DIM) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080043 return new MDPCompLowRes(dpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080044 } else {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080045 return new MDPCompHighRes(dpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080046 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080047}
48
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080049MDPComp::MDPComp(int dpy):mDpy(dpy){};
50
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080051void MDPComp::dump(android::String8& buf)
52{
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080053 dumpsys_log(buf,"HWC Map for Dpy: %s \n",
54 mDpy ? "\"EXTERNAL\"" : "\"PRIMARY\"");
55 dumpsys_log(buf,"PREV_FRAME: layerCount:%2d mdpCount:%2d \
56 cacheCount:%2d \n", mCachedFrame.layerCount,
57 mCachedFrame.mdpCount, mCachedFrame.cacheCount);
58 dumpsys_log(buf,"CURR_FRAME: layerCount:%2d mdpCount:%2d \
59 fbCount:%2d \n", mCurrentFrame.layerCount,
60 mCurrentFrame.mdpCount, mCurrentFrame.fbCount);
61 dumpsys_log(buf,"needsFBRedraw:%3s pipesUsed:%2d MaxPipesPerMixer: %d \n",
62 (mCurrentFrame.needsRedraw? "YES" : "NO"),
63 mCurrentFrame.mdpCount, sMaxPipesPerMixer);
64 dumpsys_log(buf," --------------------------------------------- \n");
65 dumpsys_log(buf," listIdx | cached? | mdpIndex | comptype | Z \n");
66 dumpsys_log(buf," --------------------------------------------- \n");
67 for(int index = 0; index < mCurrentFrame.layerCount; index++ )
68 dumpsys_log(buf," %7d | %7s | %8d | %9s | %2d \n",
69 index,
70 (mCurrentFrame.isFBComposed[index] ? "YES" : "NO"),
71 mCurrentFrame.layerToMDP[index],
72 (mCurrentFrame.isFBComposed[index] ?
73 (mCurrentFrame.needsRedraw ? "GLES" : "CACHE") : "MDP"),
74 (mCurrentFrame.isFBComposed[index] ? mCurrentFrame.fbZ :
75 mCurrentFrame.mdpToLayer[mCurrentFrame.layerToMDP[index]].pipeInfo->zOrder));
76 dumpsys_log(buf,"\n");
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080077}
78
79bool MDPComp::init(hwc_context_t *ctx) {
80
81 if(!ctx) {
82 ALOGE("%s: Invalid hwc context!!",__FUNCTION__);
83 return false;
84 }
85
86 if(!setupBasePipe(ctx)) {
87 ALOGE("%s: Failed to setup primary base pipe", __FUNCTION__);
88 return false;
89 }
90
91 char property[PROPERTY_VALUE_MAX];
92
93 sEnabled = false;
94 if((property_get("persist.hwc.mdpcomp.enable", property, NULL) > 0) &&
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080095 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
96 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080097 sEnabled = true;
98 }
99
100 sDebugLogs = false;
101 if(property_get("debug.mdpcomp.logs", property, NULL) > 0) {
102 if(atoi(property) != 0)
103 sDebugLogs = true;
104 }
105
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800106 sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
Saurabh Shah85234ec2013-04-12 17:09:00 -0700107 if(property_get("debug.mdpcomp.maxpermixer", property, "-1") > 0) {
108 int val = atoi(property);
109 if(val >= 0)
110 sMaxPipesPerMixer = min(val, MAX_PIPES_PER_MIXER);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800111 }
112
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800113 unsigned long idle_timeout = DEFAULT_IDLE_TIME;
114 if(property_get("debug.mdpcomp.idletime", property, NULL) > 0) {
115 if(atoi(property) != 0)
116 idle_timeout = atoi(property);
117 }
118
119 //create Idle Invalidator
120 idleInvalidator = IdleInvalidator::getInstance();
121
122 if(idleInvalidator == NULL) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800123 ALOGE("%s: failed to instantiate idleInvalidator object", __FUNCTION__);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800124 } else {
125 idleInvalidator->init(timeout_handler, ctx, idle_timeout);
126 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700127 return true;
128}
129
130void MDPComp::timeout_handler(void *udata) {
131 struct hwc_context_t* ctx = (struct hwc_context_t*)(udata);
132
133 if(!ctx) {
134 ALOGE("%s: received empty data in timer callback", __FUNCTION__);
135 return;
136 }
137
Jesse Hall3be78d92012-08-21 15:12:23 -0700138 if(!ctx->proc) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700139 ALOGE("%s: HWC proc not registered", __FUNCTION__);
140 return;
141 }
142 sIdleFallBack = true;
143 /* Trigger SF to redraw the current frame */
Jesse Hall3be78d92012-08-21 15:12:23 -0700144 ctx->proc->invalidate(ctx->proc);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700145}
146
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800147void MDPComp::setMDPCompLayerFlags(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800148 hwc_display_contents_1_t* list) {
149 LayerProp *layerProp = ctx->layerProp[mDpy];
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800150
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800151 for(int index = 0; index < ctx->listStats[mDpy].numAppLayers; index++) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800152 hwc_layer_1_t* layer = &(list->hwLayers[index]);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800153 if(!mCurrentFrame.isFBComposed[index]) {
154 layerProp[index].mFlags |= HWC_MDPCOMP;
155 layer->compositionType = HWC_OVERLAY;
156 layer->hints |= HWC_HINT_CLEAR_FB;
157 mCachedFrame.hnd[index] = NULL;
158 } else {
159 if(!mCurrentFrame.needsRedraw)
160 layer->compositionType = HWC_OVERLAY;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800161 }
162 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800163 mCachedFrame.mdpCount = mCurrentFrame.mdpCount;
164 mCachedFrame.cacheCount = mCurrentFrame.fbCount;
165 mCachedFrame.layerCount = ctx->listStats[mDpy].numAppLayers;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700166}
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500167
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800168/*
169 * Sets up BORDERFILL as default base pipe and detaches RGB0.
170 * Framebuffer is always updated using PLAY ioctl.
171 */
172bool MDPComp::setupBasePipe(hwc_context_t *ctx) {
173 const int dpy = HWC_DISPLAY_PRIMARY;
174 int fb_stride = ctx->dpyAttr[dpy].stride;
175 int fb_width = ctx->dpyAttr[dpy].xres;
176 int fb_height = ctx->dpyAttr[dpy].yres;
177 int fb_fd = ctx->dpyAttr[dpy].fd;
178
179 mdp_overlay ovInfo;
180 msmfb_overlay_data ovData;
181 memset(&ovInfo, 0, sizeof(mdp_overlay));
182 memset(&ovData, 0, sizeof(msmfb_overlay_data));
183
184 ovInfo.src.format = MDP_RGB_BORDERFILL;
185 ovInfo.src.width = fb_width;
186 ovInfo.src.height = fb_height;
187 ovInfo.src_rect.w = fb_width;
188 ovInfo.src_rect.h = fb_height;
189 ovInfo.dst_rect.w = fb_width;
190 ovInfo.dst_rect.h = fb_height;
191 ovInfo.id = MSMFB_NEW_REQUEST;
192
193 if (ioctl(fb_fd, MSMFB_OVERLAY_SET, &ovInfo) < 0) {
194 ALOGE("Failed to call ioctl MSMFB_OVERLAY_SET err=%s",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800195 strerror(errno));
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800196 return false;
197 }
198
199 ovData.id = ovInfo.id;
200 if (ioctl(fb_fd, MSMFB_OVERLAY_PLAY, &ovData) < 0) {
201 ALOGE("Failed to call ioctl MSMFB_OVERLAY_PLAY err=%s",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800202 strerror(errno));
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800203 return false;
204 }
205 return true;
206}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800207MDPComp::FrameInfo::FrameInfo() {
208 layerCount = 0;
209 reset();
210}
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800211
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800212void MDPComp::FrameInfo::reset() {
213
214 for(int i = 0 ; i < MAX_PIPES_PER_MIXER && layerCount; i++ ) {
215 if(mdpToLayer[i].pipeInfo) {
216 delete mdpToLayer[i].pipeInfo;
217 mdpToLayer[i].pipeInfo = NULL;
218 //We dont own the rotator
219 mdpToLayer[i].rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800220 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800221 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800222
223 memset(&mdpToLayer, 0, sizeof(mdpToLayer));
224 memset(&layerToMDP, -1, sizeof(layerToMDP));
225 memset(&isFBComposed, 0, sizeof(isFBComposed));
226
227 layerCount = 0;
228 mdpCount = 0;
229 fbCount = 0;
230 needsRedraw = false;
231 fbZ = 0;
232}
233
234MDPComp::LayerCache::LayerCache() {
235 reset();
236}
237
238void MDPComp::LayerCache::reset() {
239 memset(&hnd, 0, sizeof(buffer_handle_t));
240 mdpCount = 0;
241 cacheCount = 0;
242 layerCount = 0;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800243}
244
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800245bool MDPComp::isWidthValid(hwc_context_t *ctx, hwc_layer_1_t *layer) {
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800246
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800247 private_handle_t *hnd = (private_handle_t *)layer->handle;
248
249 if(!hnd) {
250 ALOGE("%s: layer handle is NULL", __FUNCTION__);
251 return false;
252 }
253
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800254 int hw_w = ctx->dpyAttr[mDpy].xres;
255 int hw_h = ctx->dpyAttr[mDpy].yres;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800256
257 hwc_rect_t sourceCrop = layer->sourceCrop;
258 hwc_rect_t displayFrame = layer->displayFrame;
259
260 hwc_rect_t crop = sourceCrop;
261 int crop_w = crop.right - crop.left;
262 int crop_h = crop.bottom - crop.top;
263
264 hwc_rect_t dst = displayFrame;
265 int dst_w = dst.right - dst.left;
266 int dst_h = dst.bottom - dst.top;
267
268 if(dst.left < 0 || dst.top < 0 || dst.right > hw_w || dst.bottom > hw_h) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800269 hwc_rect_t scissor = {0, 0, hw_w, hw_h };
270 qhwc::calculate_crop_rects(crop, dst, scissor, layer->transform);
271 crop_w = crop.right - crop.left;
272 crop_h = crop.bottom - crop.top;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800273 }
274
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800275 /* Workaround for MDP HW limitation in DSI command mode panels where
276 * FPS will not go beyond 30 if buffers on RGB pipes are of width or height
277 * less than 5 pixels
278 * */
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800279
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800280 if((crop_w < 5)||(crop_h < 5))
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800281 return false;
282
283 return true;
284}
285
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800286ovutils::eDest MDPComp::getMdpPipe(hwc_context_t *ctx, ePipeType type) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800287 overlay::Overlay& ov = *ctx->mOverlay;
288 ovutils::eDest mdp_pipe = ovutils::OV_INVALID;
289
290 switch(type) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800291 case MDPCOMP_OV_DMA:
292 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_DMA, mDpy);
293 if(mdp_pipe != ovutils::OV_INVALID) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800294 return mdp_pipe;
295 }
296 case MDPCOMP_OV_ANY:
297 case MDPCOMP_OV_RGB:
298 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy);
299 if(mdp_pipe != ovutils::OV_INVALID) {
300 return mdp_pipe;
301 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800302
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800303 if(type == MDPCOMP_OV_RGB) {
304 //Requested only for RGB pipe
305 break;
306 }
307 case MDPCOMP_OV_VG:
308 return ov.nextPipe(ovutils::OV_MDP_PIPE_VG, mDpy);
309 default:
310 ALOGE("%s: Invalid pipe type",__FUNCTION__);
311 return ovutils::OV_INVALID;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800312 };
313 return ovutils::OV_INVALID;
314}
315
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800316bool MDPComp::isFrameDoable(hwc_context_t *ctx) {
317 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800318
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800319 if(!isEnabled()) {
320 ALOGD_IF(isDebug(),"%s: MDP Comp. not enabled.", __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800321 return false;
322 }
323
324 if(ctx->mExtDispConfiguring) {
325 ALOGD_IF( isDebug(),"%s: External Display connection is pending",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800326 __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800327 return false;
328 }
329
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800330 if(ctx->listStats[mDpy].needsAlphaScale
331 && ctx->mMDP.version < qdutils::MDSS_V5) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800332 ALOGD_IF(isDebug(), "%s: frame needs alpha downscaling",__FUNCTION__);
333 return false;
334 }
335
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700336 if(ctx->isPaddingRound) {
337 ctx->isPaddingRound = false;
338 ALOGD_IF(isDebug(), "%s: padding round",__FUNCTION__);
339 return false;
340 }
341
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800342 return true;
343}
344
345/* Checks for conditions where all the layers marked for MDP comp cannot be
346 * bypassed. On such conditions we try to bypass atleast YUV layers */
347bool MDPComp::isFullFrameDoable(hwc_context_t *ctx,
348 hwc_display_contents_1_t* list){
349
350 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
351 int mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount;
352 int fbNeeded = int(mCurrentFrame.fbCount != 0);
353
354 if(mDpy > HWC_DISPLAY_PRIMARY){
355 ALOGD_IF(isDebug(), "%s: Cannot support External display(s)",
356 __FUNCTION__);
357 return false;
358 }
359
Saurabh Shah85234ec2013-04-12 17:09:00 -0700360 if(mdpCount > (sMaxPipesPerMixer - fbNeeded)) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800361 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
362 return false;
363 }
364
365 if(pipesNeeded(ctx, list) > getAvailablePipes(ctx)) {
366 ALOGD_IF(isDebug(), "%s: Insufficient MDP pipes",__FUNCTION__);
367 return false;
368 }
369
370 if(isSkipPresent(ctx, mDpy)) {
371 ALOGD_IF(isDebug(), "%s: Skip layers present",__FUNCTION__);
372 return false;
373 }
374
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800375 //FB composition on idle timeout
376 if(sIdleFallBack) {
377 sIdleFallBack = false;
378 ALOGD_IF(isDebug(), "%s: idle fallback",__FUNCTION__);
379 return false;
380 }
381
382 //MDP composition is not efficient if layer needs rotator.
383 for(int i = 0; i < numAppLayers; ++i) {
384 // As MDP h/w supports flip operation, use MDP comp only for
385 // 180 transforms. Fail for any transform involving 90 (90, 270).
386 hwc_layer_1_t* layer = &list->hwLayers[i];
387 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800388
389 if(layer->transform & HWC_TRANSFORM_ROT_90 && !isYuvBuffer(hnd)) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800390 ALOGD_IF(isDebug(), "%s: orientation involved",__FUNCTION__);
391 return false;
392 }
393
394 if(!isYuvBuffer(hnd) && !isWidthValid(ctx,layer)) {
395 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",__FUNCTION__);
396 return false;
397 }
398 }
399 return true;
400}
401
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800402/* Checks for conditions where YUV layers cannot be bypassed */
403bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800404
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800405 if(isSkipLayer(layer)) {
406 ALOGE("%s: Unable to bypass skipped YUV", __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800407 return false;
408 }
409
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800410 if(isSecuring(ctx, layer)) {
411 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
412 return false;
413 }
414
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700415 if(!qdutils::MDPVersion::getInstance().supportsDecimation()) {
416 const uint32_t downscale =
417 qdutils::MDPVersion::getInstance().getMaxMDPDownscale();
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800418 hwc_rect_t crop = layer->sourceCrop;
419 hwc_rect_t dst = layer->displayFrame;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800420 int cWidth = crop.right - crop.left;
421 int cHeight = crop.bottom - crop.top;
422 int dWidth = dst.right - dst.left;
423 int dHeight = dst.bottom - dst.top;
424
Amara Venkata Mastan Manoj Kumar6fa86722013-04-12 17:11:14 -0700425 if(layer->transform & HAL_TRANSFORM_ROT_90) {
426 swap(cWidth, cHeight);
427 }
428
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700429 if(cWidth > MAX_DISPLAY_DIM || (cWidth/dWidth) > downscale ||
430 (cHeight/dHeight) > downscale)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800431 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800432 }
433 return true;
434}
435
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800436void MDPComp::batchLayers() {
437 /* Idea is to keep as many contiguous non-updating(cached) layers in FB and
438 * send rest of them through MDP. NEVER mark an updating layer for caching.
439 * But cached ones can be marked for MDP*/
440
441 int maxBatchStart = -1;
442 int maxBatchCount = 0;
443
444 /* All or Nothing is cached. No batching needed */
445 if(!mCurrentFrame.fbCount ||
446 (mCurrentFrame.fbCount == mCurrentFrame.layerCount))
447 return;
448
449 /* Search for max number of contiguous (cached) layers */
450 int i = 0;
451 while (i < mCurrentFrame.layerCount) {
452 int count = 0;
453 while(mCurrentFrame.isFBComposed[i] && i < mCurrentFrame.layerCount) {
454 count++; i++;
455 }
456 if(count > maxBatchCount) {
457 maxBatchCount = count;
458 maxBatchStart = i - count;
459 }
460 if(i < mCurrentFrame.layerCount) i++;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800461 }
462
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800463 /* reset rest of the layers for MDP comp */
464 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
465 if(i != maxBatchStart){
466 mCurrentFrame.isFBComposed[i] = false;
467 } else {
468 i += maxBatchCount;
469 }
470 }
471
472 mCurrentFrame.fbCount = maxBatchCount;
473
474 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
475 mCurrentFrame.fbCount);
476}
Saurabh Shah85234ec2013-04-12 17:09:00 -0700477
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800478void MDPComp::updateLayerCache(hwc_context_t* ctx,
479 hwc_display_contents_1_t* list) {
480
481 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
482 int numCacheableLayers = 0;
483
484 if((list->flags & HWC_GEOMETRY_CHANGED) || (isSkipPresent(ctx, mDpy))) {
485 ALOGD_IF(isDebug(),"%s: No Caching: \
486 GEOMETRY change: %d SKIP present: %d", __FUNCTION__,
487 (list->flags & HWC_GEOMETRY_CHANGED),isSkipPresent(ctx, mDpy));
488 mCachedFrame.reset();
489 return;
490 }
491
492 for(int i = 0; i < numAppLayers; i++) {
493 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
494 numCacheableLayers++;
495 mCurrentFrame.isFBComposed[i] = true;
496 } else {
497 mCachedFrame.hnd[i] = list->hwLayers[i].handle;
498 }
499 }
500 mCurrentFrame.fbCount = numCacheableLayers;
501 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__, numCacheableLayers);
502}
503
504int MDPComp::getAvailablePipes(hwc_context_t* ctx) {
505 int numDMAPipes = qdutils::MDPVersion::getInstance().getDMAPipes();
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800506 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800507
508 int numAvailable = ov.availablePipes(mDpy);
509
510 //Reserve DMA for rotator
Saurabh Shah85234ec2013-04-12 17:09:00 -0700511 if(Overlay::getDMAMode() == Overlay::DMA_BLOCK_MODE)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800512 numAvailable -= numDMAPipes;
513
514 //Reserve pipe(s)for FB
515 if(mCurrentFrame.fbCount)
516 numAvailable -= pipesForFB();
517
518 return numAvailable;
519}
520
521void MDPComp::resetFrameForFB(hwc_context_t* ctx,
522 hwc_display_contents_1_t* list) {
523 mCurrentFrame.fbCount = mCurrentFrame.layerCount;
524 memset(&mCurrentFrame.isFBComposed, 1,
525 sizeof(mCurrentFrame.isFBComposed));
526 mCurrentFrame.needsRedraw = true;
527}
528
529void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list) {
530
531 int nYuvCount = ctx->listStats[mDpy].yuvCount;
532 for(int index = 0;index < nYuvCount; index++){
533 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
534 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
535
536 if(!isYUVDoable(ctx, layer)) {
537 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
538 mCurrentFrame.isFBComposed[nYuvIndex] = true;
539 mCurrentFrame.fbCount++;
540 }
541 } else {
542 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
543 mCurrentFrame.isFBComposed[nYuvIndex] = false;
544 mCurrentFrame.fbCount--;
545 }
546 }
547 }
548 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
549 mCurrentFrame.fbCount);
550}
551
552int MDPComp::programMDP(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
553 int fbZOrder = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800554
555 if(!allocLayerPipes(ctx, list)) {
556 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
557 goto fn_exit;
558 }
559
560 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
561 index++) {
562 if(!mCurrentFrame.isFBComposed[index]) {
563
564 int mdpIndex = mCurrentFrame.layerToMDP[index];
565 hwc_layer_1_t* layer = &list->hwLayers[index];
566
567 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
568 cur_pipe->zOrder = mdpNextZOrder++;
569
570 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
571 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
572 layer %d",__FUNCTION__, index);
573 goto fn_exit;
574 }
575 } else if(fbZOrder < 0) {
576 fbZOrder = mdpNextZOrder++;
577 };
578 }
579
580 return fbZOrder;
581
582 fn_exit:
583 //Complete fallback to FB
584 resetFrameForFB(ctx, list);
585 return 0;
586}
587
588int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800589
590 //reset old data
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800591 mCurrentFrame.reset();
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800592
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800593 if(!isFrameDoable(ctx)) {
594 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
595 __FUNCTION__);
596 return 0;
597 }
598
599 mCurrentFrame.layerCount = ctx->listStats[mDpy].numAppLayers;
600
601 //Iterate layer list for cached layers
602 updateLayerCache(ctx, list);
603
604 //Add YUV layers to cached list
605 updateYUV(ctx, list);
606
607 //Optimze for bypass
608 batchLayers();
609
610 //list is already parsed / batched for optimal mixed mode composition.
611 //Check whether layers marked for MDP Composition is actually doable.
612 if(!isFullFrameDoable(ctx, list)){
613 //All layers marked for MDP comp cannot be bypassed.
614 //Try to compose atleast YUV layers through MDP comp and let
615 //all the RGB layers compose in FB
616 resetFrameForFB(ctx, list);
617 updateYUV(ctx, list);
618 }
619
620 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
621 mCurrentFrame.fbCount;
622
623 if(mCurrentFrame.mdpCount) {
624 // populate layer and MDP maps
625 for(int idx = 0, mdpIdx = 0; idx < mCurrentFrame.layerCount; idx++) {
626 if(!mCurrentFrame.isFBComposed[idx]) {
627 mCurrentFrame.mdpToLayer[mdpIdx].listIndex = idx;
628 mCurrentFrame.layerToMDP[idx] = mdpIdx++;
629 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800630 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800631 //Acquire and Program MDP pipes
632 mCurrentFrame.fbZ = programMDP(ctx, list);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800633 }
634
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800635 /* Any change in composition types needs an FB refresh*/
636 if(mCurrentFrame.fbCount &&
637 ((mCurrentFrame.mdpCount != mCachedFrame.mdpCount) ||
638 (mCurrentFrame.fbCount != mCachedFrame.cacheCount) ||
639 !mCurrentFrame.mdpCount)) {
640 mCurrentFrame.needsRedraw = true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800641 }
642
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800643 //UpdateLayerFlags
644 setMDPCompLayerFlags(ctx, list);
645
646 if(isDebug()) {
647 android::String8 sDump("");
648 dump(sDump);
649 ALOGE("%s",sDump.string());
650 }
651
652 return mCurrentFrame.fbZ;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800653}
654
655//=============MDPCompLowRes===================================================
656
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700657/*
658 * Configures pipe(s) for MDP composition
659 */
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800660int MDPCompLowRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800661 PipeLayerPair& PipeLayerPair) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800662 MdpPipeInfoLowRes& mdp_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800663 *(static_cast<MdpPipeInfoLowRes*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -0800664 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
665 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
666 eIsFg isFg = IS_FG_OFF;
667 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700668
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800669 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
670 __FUNCTION__, layer, zOrder, dest);
671
672 return configureLowRes(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
673 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700674}
675
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800676int MDPCompLowRes::pipesNeeded(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800677 hwc_display_contents_1_t* list) {
678 return mCurrentFrame.mdpCount;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700679}
680
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800681bool MDPCompLowRes::allocLayerPipes(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800682 hwc_display_contents_1_t* list) {
683 if(isYuvPresent(ctx, mDpy)) {
684 int nYuvCount = ctx->listStats[mDpy].yuvCount;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700685
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800686 for(int index = 0; index < nYuvCount ; index ++) {
687 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500688
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800689 if(mCurrentFrame.isFBComposed[nYuvIndex])
690 continue;
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800691
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800692 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800693
694 int mdpIndex = mCurrentFrame.layerToMDP[nYuvIndex];
695
696 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800697 info.pipeInfo = new MdpPipeInfoLowRes;
Saurabh Shahacf10202013-02-26 10:15:15 -0800698 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800699 MdpPipeInfoLowRes& pipe_info = *(MdpPipeInfoLowRes*)info.pipeInfo;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800700
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800701 pipe_info.index = getMdpPipe(ctx, MDPCOMP_OV_VG);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800702 if(pipe_info.index == ovutils::OV_INVALID) {
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800703 ALOGD_IF(isDebug(), "%s: Unable to get pipe for Videos",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800704 __FUNCTION__);
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800705 return false;
706 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500707 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500708 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700709
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800710 for(int index = 0 ; index < mCurrentFrame.layerCount; index++ ) {
711 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800712 hwc_layer_1_t* layer = &list->hwLayers[index];
713 private_handle_t *hnd = (private_handle_t *)layer->handle;
714
715 if(isYuvBuffer(hnd))
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500716 continue;
717
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800718 int mdpIndex = mCurrentFrame.layerToMDP[index];
719
720 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800721 info.pipeInfo = new MdpPipeInfoLowRes;
Saurabh Shahacf10202013-02-26 10:15:15 -0800722 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800723 MdpPipeInfoLowRes& pipe_info = *(MdpPipeInfoLowRes*)info.pipeInfo;
724
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800725 ePipeType type = MDPCOMP_OV_ANY;
726
Saurabh Shah85234ec2013-04-12 17:09:00 -0700727 if(!qhwc::needsScaling(layer)
728 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
729 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800730 type = MDPCOMP_OV_DMA;
731 }
732
733 pipe_info.index = getMdpPipe(ctx, type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800734 if(pipe_info.index == ovutils::OV_INVALID) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500735 ALOGD_IF(isDebug(), "%s: Unable to get pipe for UI", __FUNCTION__);
736 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700737 }
738 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700739 return true;
740}
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700741
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800742bool MDPCompLowRes::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700743
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800744 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500745 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
746 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800747 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700748
749 if(!ctx || !list) {
750 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500751 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700752 }
753
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500754 /* reset Invalidator */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800755 if(idleInvalidator && mCurrentFrame.mdpCount)
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500756 idleInvalidator->markForSleep();
757
758 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800759 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700760
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800761 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
762 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700763 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800764 if(mCurrentFrame.isFBComposed[i]) continue;
765
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700766 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -0800767 private_handle_t *hnd = (private_handle_t *)layer->handle;
768 if(!hnd) {
769 ALOGE("%s handle null", __FUNCTION__);
770 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700771 }
772
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800773 int mdpIndex = mCurrentFrame.layerToMDP[i];
774
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800775 MdpPipeInfoLowRes& pipe_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800776 *(MdpPipeInfoLowRes*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800777 ovutils::eDest dest = pipe_info.index;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800778 if(dest == ovutils::OV_INVALID) {
779 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500780 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700781 }
782
Saurabh Shahacf10202013-02-26 10:15:15 -0800783 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
784 continue;
785 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700786
Saurabh Shahacf10202013-02-26 10:15:15 -0800787 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800788 using pipe: %d", __FUNCTION__, layer,
789 hnd, dest );
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700790
Saurabh Shahacf10202013-02-26 10:15:15 -0800791 int fd = hnd->fd;
792 uint32_t offset = hnd->offset;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800793 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -0800794 if(rot) {
795 if(!rot->queueBuffer(fd, offset))
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500796 return false;
Saurabh Shahacf10202013-02-26 10:15:15 -0800797 fd = rot->getDstMemId();
798 offset = rot->getDstOffset();
799 }
800
801 if (!ov.queueBuffer(fd, offset, dest)) {
802 ALOGE("%s: queueBuffer failed for external", __FUNCTION__);
803 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700804 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500805
806 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700807 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500808 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700809}
810
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800811//=============MDPCompHighRes===================================================
812
813int MDPCompHighRes::pipesNeeded(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800814 hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800815 int pipesNeeded = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800816 int hw_w = ctx->dpyAttr[mDpy].xres;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800817
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800818 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
819 if(!mCurrentFrame.isFBComposed[i]) {
820 hwc_layer_1_t* layer = &list->hwLayers[i];
821 hwc_rect_t dst = layer->displayFrame;
822 if(dst.left > hw_w/2) {
823 pipesNeeded++;
824 } else if(dst.right <= hw_w/2) {
825 pipesNeeded++;
826 } else {
827 pipesNeeded += 2;
828 }
829 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800830 }
831 return pipesNeeded;
832}
833
834bool MDPCompHighRes::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800835 MdpPipeInfoHighRes& pipe_info,
836 ePipeType type) {
837 int hw_w = ctx->dpyAttr[mDpy].xres;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800838
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800839 hwc_rect_t dst = layer->displayFrame;
840 if(dst.left > hw_w/2) {
841 pipe_info.lIndex = ovutils::OV_INVALID;
842 pipe_info.rIndex = getMdpPipe(ctx, type);
843 if(pipe_info.rIndex == ovutils::OV_INVALID)
844 return false;
845 } else if (dst.right <= hw_w/2) {
846 pipe_info.rIndex = ovutils::OV_INVALID;
847 pipe_info.lIndex = getMdpPipe(ctx, type);
848 if(pipe_info.lIndex == ovutils::OV_INVALID)
849 return false;
850 } else {
851 pipe_info.rIndex = getMdpPipe(ctx, type);
852 pipe_info.lIndex = getMdpPipe(ctx, type);
853 if(pipe_info.rIndex == ovutils::OV_INVALID ||
854 pipe_info.lIndex == ovutils::OV_INVALID)
855 return false;
856 }
857 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800858}
859
860bool MDPCompHighRes::allocLayerPipes(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800861 hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800862 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800863 int layer_count = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800864
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800865 if(isYuvPresent(ctx, mDpy)) {
866 int nYuvCount = ctx->listStats[mDpy].yuvCount;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800867
868 for(int index = 0; index < nYuvCount; index ++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800869 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800870 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800871 PipeLayerPair& info = mCurrentFrame.mdpToLayer[nYuvIndex];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800872 info.pipeInfo = new MdpPipeInfoHighRes;
Saurabh Shah9e3adb22013-03-26 11:16:27 -0700873 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800874 MdpPipeInfoHighRes& pipe_info = *(MdpPipeInfoHighRes*)info.pipeInfo;
875 if(!acquireMDPPipes(ctx, layer, pipe_info,MDPCOMP_OV_VG)) {
876 ALOGD_IF(isDebug(),"%s: Unable to get pipe for videos",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800877 __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800878 //TODO: windback pipebook data on fail
879 return false;
880 }
881 pipe_info.zOrder = nYuvIndex;
882 }
883 }
884
885 for(int index = 0 ; index < layer_count ; index++ ) {
886 hwc_layer_1_t* layer = &list->hwLayers[index];
887 private_handle_t *hnd = (private_handle_t *)layer->handle;
888
889 if(isYuvBuffer(hnd))
890 continue;
891
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800892 PipeLayerPair& info = mCurrentFrame.mdpToLayer[index];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800893 info.pipeInfo = new MdpPipeInfoHighRes;
Saurabh Shah9e3adb22013-03-26 11:16:27 -0700894 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800895 MdpPipeInfoHighRes& pipe_info = *(MdpPipeInfoHighRes*)info.pipeInfo;
896
897 ePipeType type = MDPCOMP_OV_ANY;
898
Saurabh Shah85234ec2013-04-12 17:09:00 -0700899 if(!qhwc::needsScaling(layer)
900 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
901 && ctx->mMDP.version >= qdutils::MDSS_V5)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800902 type = MDPCOMP_OV_DMA;
903
904 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
905 ALOGD_IF(isDebug(), "%s: Unable to get pipe for UI", __FUNCTION__);
906 //TODO: windback pipebook data on fail
907 return false;
908 }
909 pipe_info.zOrder = index;
910 }
911 return true;
912}
913/*
914 * Configures pipe(s) for MDP composition
915 */
916int MDPCompHighRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800917 PipeLayerPair& PipeLayerPair) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800918 MdpPipeInfoHighRes& mdp_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800919 *(static_cast<MdpPipeInfoHighRes*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -0800920 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
921 eIsFg isFg = IS_FG_OFF;
922 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
923 eDest lDest = mdp_info.lIndex;
924 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800925
926 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
927 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
928
929 return configureHighRes(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
930 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800931}
932
933bool MDPCompHighRes::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
934
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800935 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800936 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
937 return true;
938 }
939
940 if(!ctx || !list) {
941 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700942 return false;
943 }
944
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800945 /* reset Invalidator */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800946 if(idleInvalidator && mCurrentFrame.mdpCount)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800947 idleInvalidator->markForSleep();
948
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500949 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800950 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700951
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800952 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
953 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800954 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800955 if(mCurrentFrame.isFBComposed[i]) continue;
956
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800957 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -0800958 private_handle_t *hnd = (private_handle_t *)layer->handle;
959 if(!hnd) {
960 ALOGE("%s handle null", __FUNCTION__);
961 return false;
962 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800963
964 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
965 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700966 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700967
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800968 int mdpIndex = mCurrentFrame.layerToMDP[i];
969
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800970 MdpPipeInfoHighRes& pipe_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800971 *(MdpPipeInfoHighRes*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
972 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -0800973
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800974 ovutils::eDest indexL = pipe_info.lIndex;
975 ovutils::eDest indexR = pipe_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800976
Saurabh Shahacf10202013-02-26 10:15:15 -0800977 int fd = hnd->fd;
978 int offset = hnd->offset;
979
980 if(rot) {
981 rot->queueBuffer(fd, offset);
982 fd = rot->getDstMemId();
983 offset = rot->getDstOffset();
984 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700985
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800986 //************* play left mixer **********
987 if(indexL != ovutils::OV_INVALID) {
988 ovutils::eDest destL = (ovutils::eDest)indexL;
Saurabh Shahacf10202013-02-26 10:15:15 -0800989 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800990 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
Saurabh Shahacf10202013-02-26 10:15:15 -0800991 if (!ov.queueBuffer(fd, offset, destL)) {
992 ALOGE("%s: queueBuffer failed for left mixer", __FUNCTION__);
993 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800994 }
995 }
996
997 //************* play right mixer **********
998 if(indexR != ovutils::OV_INVALID) {
999 ovutils::eDest destR = (ovutils::eDest)indexR;
Saurabh Shahacf10202013-02-26 10:15:15 -08001000 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001001 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
Saurabh Shahacf10202013-02-26 10:15:15 -08001002 if (!ov.queueBuffer(fd, offset, destR)) {
1003 ALOGE("%s: queueBuffer failed for right mixer", __FUNCTION__);
1004 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001005 }
1006 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001007
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001008 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1009 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001010
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001011 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001012}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001013}; //namespace
1014