blob: 6381f59fe2ede6c5a9861e4f79c0af8cfab76a9c [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
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800336 return true;
337}
338
339/* Checks for conditions where all the layers marked for MDP comp cannot be
340 * bypassed. On such conditions we try to bypass atleast YUV layers */
341bool MDPComp::isFullFrameDoable(hwc_context_t *ctx,
342 hwc_display_contents_1_t* list){
343
344 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
345 int mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount;
346 int fbNeeded = int(mCurrentFrame.fbCount != 0);
347
348 if(mDpy > HWC_DISPLAY_PRIMARY){
349 ALOGD_IF(isDebug(), "%s: Cannot support External display(s)",
350 __FUNCTION__);
351 return false;
352 }
353
Saurabh Shah85234ec2013-04-12 17:09:00 -0700354 if(mdpCount > (sMaxPipesPerMixer - fbNeeded)) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800355 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
356 return false;
357 }
358
359 if(pipesNeeded(ctx, list) > getAvailablePipes(ctx)) {
360 ALOGD_IF(isDebug(), "%s: Insufficient MDP pipes",__FUNCTION__);
361 return false;
362 }
363
364 if(isSkipPresent(ctx, mDpy)) {
365 ALOGD_IF(isDebug(), "%s: Skip layers present",__FUNCTION__);
366 return false;
367 }
368
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800369 //FB composition on idle timeout
370 if(sIdleFallBack) {
371 sIdleFallBack = false;
372 ALOGD_IF(isDebug(), "%s: idle fallback",__FUNCTION__);
373 return false;
374 }
375
376 //MDP composition is not efficient if layer needs rotator.
377 for(int i = 0; i < numAppLayers; ++i) {
378 // As MDP h/w supports flip operation, use MDP comp only for
379 // 180 transforms. Fail for any transform involving 90 (90, 270).
380 hwc_layer_1_t* layer = &list->hwLayers[i];
381 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800382
383 if(layer->transform & HWC_TRANSFORM_ROT_90 && !isYuvBuffer(hnd)) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800384 ALOGD_IF(isDebug(), "%s: orientation involved",__FUNCTION__);
385 return false;
386 }
387
388 if(!isYuvBuffer(hnd) && !isWidthValid(ctx,layer)) {
389 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",__FUNCTION__);
390 return false;
391 }
392 }
393 return true;
394}
395
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800396/* Checks for conditions where YUV layers cannot be bypassed */
397bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800398
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800399 if(isSkipLayer(layer)) {
400 ALOGE("%s: Unable to bypass skipped YUV", __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800401 return false;
402 }
403
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800404 if(isSecuring(ctx, layer)) {
405 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
406 return false;
407 }
408
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700409 if(!qdutils::MDPVersion::getInstance().supportsDecimation()) {
410 const uint32_t downscale =
411 qdutils::MDPVersion::getInstance().getMaxMDPDownscale();
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800412 hwc_rect_t crop = layer->sourceCrop;
413 hwc_rect_t dst = layer->displayFrame;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800414 int cWidth = crop.right - crop.left;
415 int cHeight = crop.bottom - crop.top;
416 int dWidth = dst.right - dst.left;
417 int dHeight = dst.bottom - dst.top;
418
Amara Venkata Mastan Manoj Kumar6fa86722013-04-12 17:11:14 -0700419 if(layer->transform & HAL_TRANSFORM_ROT_90) {
420 swap(cWidth, cHeight);
421 }
422
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700423 if(cWidth > MAX_DISPLAY_DIM || (cWidth/dWidth) > downscale ||
424 (cHeight/dHeight) > downscale)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800425 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800426 }
427 return true;
428}
429
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800430void MDPComp::batchLayers() {
431 /* Idea is to keep as many contiguous non-updating(cached) layers in FB and
432 * send rest of them through MDP. NEVER mark an updating layer for caching.
433 * But cached ones can be marked for MDP*/
434
435 int maxBatchStart = -1;
436 int maxBatchCount = 0;
437
438 /* All or Nothing is cached. No batching needed */
439 if(!mCurrentFrame.fbCount ||
440 (mCurrentFrame.fbCount == mCurrentFrame.layerCount))
441 return;
442
443 /* Search for max number of contiguous (cached) layers */
444 int i = 0;
445 while (i < mCurrentFrame.layerCount) {
446 int count = 0;
447 while(mCurrentFrame.isFBComposed[i] && i < mCurrentFrame.layerCount) {
448 count++; i++;
449 }
450 if(count > maxBatchCount) {
451 maxBatchCount = count;
452 maxBatchStart = i - count;
453 }
454 if(i < mCurrentFrame.layerCount) i++;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800455 }
456
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800457 /* reset rest of the layers for MDP comp */
458 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
459 if(i != maxBatchStart){
460 mCurrentFrame.isFBComposed[i] = false;
461 } else {
462 i += maxBatchCount;
463 }
464 }
465
466 mCurrentFrame.fbCount = maxBatchCount;
467
468 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
469 mCurrentFrame.fbCount);
470}
Saurabh Shah85234ec2013-04-12 17:09:00 -0700471
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800472void MDPComp::updateLayerCache(hwc_context_t* ctx,
473 hwc_display_contents_1_t* list) {
474
475 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
476 int numCacheableLayers = 0;
477
478 if((list->flags & HWC_GEOMETRY_CHANGED) || (isSkipPresent(ctx, mDpy))) {
479 ALOGD_IF(isDebug(),"%s: No Caching: \
480 GEOMETRY change: %d SKIP present: %d", __FUNCTION__,
481 (list->flags & HWC_GEOMETRY_CHANGED),isSkipPresent(ctx, mDpy));
482 mCachedFrame.reset();
483 return;
484 }
485
486 for(int i = 0; i < numAppLayers; i++) {
487 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
488 numCacheableLayers++;
489 mCurrentFrame.isFBComposed[i] = true;
490 } else {
491 mCachedFrame.hnd[i] = list->hwLayers[i].handle;
492 }
493 }
494 mCurrentFrame.fbCount = numCacheableLayers;
495 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__, numCacheableLayers);
496}
497
498int MDPComp::getAvailablePipes(hwc_context_t* ctx) {
499 int numDMAPipes = qdutils::MDPVersion::getInstance().getDMAPipes();
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800500 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800501
502 int numAvailable = ov.availablePipes(mDpy);
503
504 //Reserve DMA for rotator
Saurabh Shah85234ec2013-04-12 17:09:00 -0700505 if(Overlay::getDMAMode() == Overlay::DMA_BLOCK_MODE)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800506 numAvailable -= numDMAPipes;
507
508 //Reserve pipe(s)for FB
509 if(mCurrentFrame.fbCount)
510 numAvailable -= pipesForFB();
511
512 return numAvailable;
513}
514
515void MDPComp::resetFrameForFB(hwc_context_t* ctx,
516 hwc_display_contents_1_t* list) {
517 mCurrentFrame.fbCount = mCurrentFrame.layerCount;
518 memset(&mCurrentFrame.isFBComposed, 1,
519 sizeof(mCurrentFrame.isFBComposed));
520 mCurrentFrame.needsRedraw = true;
521}
522
523void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list) {
524
525 int nYuvCount = ctx->listStats[mDpy].yuvCount;
526 for(int index = 0;index < nYuvCount; index++){
527 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
528 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
529
530 if(!isYUVDoable(ctx, layer)) {
531 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
532 mCurrentFrame.isFBComposed[nYuvIndex] = true;
533 mCurrentFrame.fbCount++;
534 }
535 } else {
536 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
537 mCurrentFrame.isFBComposed[nYuvIndex] = false;
538 mCurrentFrame.fbCount--;
539 }
540 }
541 }
542 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
543 mCurrentFrame.fbCount);
544}
545
546int MDPComp::programMDP(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
547 int fbZOrder = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800548
549 if(!allocLayerPipes(ctx, list)) {
550 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
551 goto fn_exit;
552 }
553
554 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
555 index++) {
556 if(!mCurrentFrame.isFBComposed[index]) {
557
558 int mdpIndex = mCurrentFrame.layerToMDP[index];
559 hwc_layer_1_t* layer = &list->hwLayers[index];
560
561 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
562 cur_pipe->zOrder = mdpNextZOrder++;
563
564 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
565 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
566 layer %d",__FUNCTION__, index);
567 goto fn_exit;
568 }
569 } else if(fbZOrder < 0) {
570 fbZOrder = mdpNextZOrder++;
571 };
572 }
573
574 return fbZOrder;
575
576 fn_exit:
577 //Complete fallback to FB
578 resetFrameForFB(ctx, list);
579 return 0;
580}
581
582int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800583
584 //reset old data
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800585 mCurrentFrame.reset();
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800586
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800587 if(!isFrameDoable(ctx)) {
588 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
589 __FUNCTION__);
590 return 0;
591 }
592
593 mCurrentFrame.layerCount = ctx->listStats[mDpy].numAppLayers;
594
595 //Iterate layer list for cached layers
596 updateLayerCache(ctx, list);
597
598 //Add YUV layers to cached list
599 updateYUV(ctx, list);
600
601 //Optimze for bypass
602 batchLayers();
603
604 //list is already parsed / batched for optimal mixed mode composition.
605 //Check whether layers marked for MDP Composition is actually doable.
606 if(!isFullFrameDoable(ctx, list)){
607 //All layers marked for MDP comp cannot be bypassed.
608 //Try to compose atleast YUV layers through MDP comp and let
609 //all the RGB layers compose in FB
610 resetFrameForFB(ctx, list);
611 updateYUV(ctx, list);
612 }
613
614 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
615 mCurrentFrame.fbCount;
616
617 if(mCurrentFrame.mdpCount) {
618 // populate layer and MDP maps
619 for(int idx = 0, mdpIdx = 0; idx < mCurrentFrame.layerCount; idx++) {
620 if(!mCurrentFrame.isFBComposed[idx]) {
621 mCurrentFrame.mdpToLayer[mdpIdx].listIndex = idx;
622 mCurrentFrame.layerToMDP[idx] = mdpIdx++;
623 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800624 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800625 //Acquire and Program MDP pipes
626 mCurrentFrame.fbZ = programMDP(ctx, list);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800627 }
628
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800629 /* Any change in composition types needs an FB refresh*/
630 if(mCurrentFrame.fbCount &&
631 ((mCurrentFrame.mdpCount != mCachedFrame.mdpCount) ||
632 (mCurrentFrame.fbCount != mCachedFrame.cacheCount) ||
633 !mCurrentFrame.mdpCount)) {
634 mCurrentFrame.needsRedraw = true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800635 }
636
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800637 //UpdateLayerFlags
638 setMDPCompLayerFlags(ctx, list);
639
640 if(isDebug()) {
641 android::String8 sDump("");
642 dump(sDump);
643 ALOGE("%s",sDump.string());
644 }
645
646 return mCurrentFrame.fbZ;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800647}
648
649//=============MDPCompLowRes===================================================
650
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700651/*
652 * Configures pipe(s) for MDP composition
653 */
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800654int MDPCompLowRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800655 PipeLayerPair& PipeLayerPair) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800656 MdpPipeInfoLowRes& mdp_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800657 *(static_cast<MdpPipeInfoLowRes*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -0800658 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
659 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
660 eIsFg isFg = IS_FG_OFF;
661 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700662
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800663 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
664 __FUNCTION__, layer, zOrder, dest);
665
666 return configureLowRes(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
667 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700668}
669
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800670int MDPCompLowRes::pipesNeeded(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800671 hwc_display_contents_1_t* list) {
672 return mCurrentFrame.mdpCount;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700673}
674
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800675bool MDPCompLowRes::allocLayerPipes(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800676 hwc_display_contents_1_t* list) {
677 if(isYuvPresent(ctx, mDpy)) {
678 int nYuvCount = ctx->listStats[mDpy].yuvCount;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700679
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800680 for(int index = 0; index < nYuvCount ; index ++) {
681 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500682
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800683 if(mCurrentFrame.isFBComposed[nYuvIndex])
684 continue;
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800685
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800686 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800687
688 int mdpIndex = mCurrentFrame.layerToMDP[nYuvIndex];
689
690 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800691 info.pipeInfo = new MdpPipeInfoLowRes;
Saurabh Shahacf10202013-02-26 10:15:15 -0800692 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800693 MdpPipeInfoLowRes& pipe_info = *(MdpPipeInfoLowRes*)info.pipeInfo;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800694
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800695 pipe_info.index = getMdpPipe(ctx, MDPCOMP_OV_VG);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800696 if(pipe_info.index == ovutils::OV_INVALID) {
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800697 ALOGD_IF(isDebug(), "%s: Unable to get pipe for Videos",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800698 __FUNCTION__);
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800699 return false;
700 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500701 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500702 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700703
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800704 for(int index = 0 ; index < mCurrentFrame.layerCount; index++ ) {
705 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800706 hwc_layer_1_t* layer = &list->hwLayers[index];
707 private_handle_t *hnd = (private_handle_t *)layer->handle;
708
709 if(isYuvBuffer(hnd))
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500710 continue;
711
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800712 int mdpIndex = mCurrentFrame.layerToMDP[index];
713
714 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800715 info.pipeInfo = new MdpPipeInfoLowRes;
Saurabh Shahacf10202013-02-26 10:15:15 -0800716 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800717 MdpPipeInfoLowRes& pipe_info = *(MdpPipeInfoLowRes*)info.pipeInfo;
718
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800719 ePipeType type = MDPCOMP_OV_ANY;
720
Saurabh Shah85234ec2013-04-12 17:09:00 -0700721 if(!qhwc::needsScaling(layer)
722 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
723 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800724 type = MDPCOMP_OV_DMA;
725 }
726
727 pipe_info.index = getMdpPipe(ctx, type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800728 if(pipe_info.index == ovutils::OV_INVALID) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500729 ALOGD_IF(isDebug(), "%s: Unable to get pipe for UI", __FUNCTION__);
730 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700731 }
732 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700733 return true;
734}
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700735
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800736bool MDPCompLowRes::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700737
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800738 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500739 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
740 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800741 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700742
743 if(!ctx || !list) {
744 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500745 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700746 }
747
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500748 /* reset Invalidator */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800749 if(idleInvalidator && mCurrentFrame.mdpCount)
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500750 idleInvalidator->markForSleep();
751
752 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800753 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700754
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800755 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
756 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700757 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800758 if(mCurrentFrame.isFBComposed[i]) continue;
759
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700760 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -0800761 private_handle_t *hnd = (private_handle_t *)layer->handle;
762 if(!hnd) {
763 ALOGE("%s handle null", __FUNCTION__);
764 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700765 }
766
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800767 int mdpIndex = mCurrentFrame.layerToMDP[i];
768
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800769 MdpPipeInfoLowRes& pipe_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800770 *(MdpPipeInfoLowRes*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800771 ovutils::eDest dest = pipe_info.index;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800772 if(dest == ovutils::OV_INVALID) {
773 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500774 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700775 }
776
Saurabh Shahacf10202013-02-26 10:15:15 -0800777 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
778 continue;
779 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700780
Saurabh Shahacf10202013-02-26 10:15:15 -0800781 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800782 using pipe: %d", __FUNCTION__, layer,
783 hnd, dest );
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700784
Saurabh Shahacf10202013-02-26 10:15:15 -0800785 int fd = hnd->fd;
786 uint32_t offset = hnd->offset;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800787 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -0800788 if(rot) {
789 if(!rot->queueBuffer(fd, offset))
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500790 return false;
Saurabh Shahacf10202013-02-26 10:15:15 -0800791 fd = rot->getDstMemId();
792 offset = rot->getDstOffset();
793 }
794
795 if (!ov.queueBuffer(fd, offset, dest)) {
796 ALOGE("%s: queueBuffer failed for external", __FUNCTION__);
797 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700798 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500799
800 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700801 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500802 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700803}
804
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800805//=============MDPCompHighRes===================================================
806
807int MDPCompHighRes::pipesNeeded(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800808 hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800809 int pipesNeeded = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800810 int hw_w = ctx->dpyAttr[mDpy].xres;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800811
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800812 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
813 if(!mCurrentFrame.isFBComposed[i]) {
814 hwc_layer_1_t* layer = &list->hwLayers[i];
815 hwc_rect_t dst = layer->displayFrame;
816 if(dst.left > hw_w/2) {
817 pipesNeeded++;
818 } else if(dst.right <= hw_w/2) {
819 pipesNeeded++;
820 } else {
821 pipesNeeded += 2;
822 }
823 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800824 }
825 return pipesNeeded;
826}
827
828bool MDPCompHighRes::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800829 MdpPipeInfoHighRes& pipe_info,
830 ePipeType type) {
831 int hw_w = ctx->dpyAttr[mDpy].xres;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800832
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800833 hwc_rect_t dst = layer->displayFrame;
834 if(dst.left > hw_w/2) {
835 pipe_info.lIndex = ovutils::OV_INVALID;
836 pipe_info.rIndex = getMdpPipe(ctx, type);
837 if(pipe_info.rIndex == ovutils::OV_INVALID)
838 return false;
839 } else if (dst.right <= hw_w/2) {
840 pipe_info.rIndex = ovutils::OV_INVALID;
841 pipe_info.lIndex = getMdpPipe(ctx, type);
842 if(pipe_info.lIndex == ovutils::OV_INVALID)
843 return false;
844 } else {
845 pipe_info.rIndex = getMdpPipe(ctx, type);
846 pipe_info.lIndex = getMdpPipe(ctx, type);
847 if(pipe_info.rIndex == ovutils::OV_INVALID ||
848 pipe_info.lIndex == ovutils::OV_INVALID)
849 return false;
850 }
851 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800852}
853
854bool MDPCompHighRes::allocLayerPipes(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800855 hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800856 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800857 int layer_count = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800858
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800859 if(isYuvPresent(ctx, mDpy)) {
860 int nYuvCount = ctx->listStats[mDpy].yuvCount;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800861
862 for(int index = 0; index < nYuvCount; index ++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800863 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800864 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800865 PipeLayerPair& info = mCurrentFrame.mdpToLayer[nYuvIndex];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800866 info.pipeInfo = new MdpPipeInfoHighRes;
Saurabh Shah9e3adb22013-03-26 11:16:27 -0700867 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800868 MdpPipeInfoHighRes& pipe_info = *(MdpPipeInfoHighRes*)info.pipeInfo;
869 if(!acquireMDPPipes(ctx, layer, pipe_info,MDPCOMP_OV_VG)) {
870 ALOGD_IF(isDebug(),"%s: Unable to get pipe for videos",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800871 __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800872 //TODO: windback pipebook data on fail
873 return false;
874 }
875 pipe_info.zOrder = nYuvIndex;
876 }
877 }
878
879 for(int index = 0 ; index < layer_count ; index++ ) {
880 hwc_layer_1_t* layer = &list->hwLayers[index];
881 private_handle_t *hnd = (private_handle_t *)layer->handle;
882
883 if(isYuvBuffer(hnd))
884 continue;
885
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800886 PipeLayerPair& info = mCurrentFrame.mdpToLayer[index];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800887 info.pipeInfo = new MdpPipeInfoHighRes;
Saurabh Shah9e3adb22013-03-26 11:16:27 -0700888 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800889 MdpPipeInfoHighRes& pipe_info = *(MdpPipeInfoHighRes*)info.pipeInfo;
890
891 ePipeType type = MDPCOMP_OV_ANY;
892
Saurabh Shah85234ec2013-04-12 17:09:00 -0700893 if(!qhwc::needsScaling(layer)
894 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
895 && ctx->mMDP.version >= qdutils::MDSS_V5)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800896 type = MDPCOMP_OV_DMA;
897
898 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
899 ALOGD_IF(isDebug(), "%s: Unable to get pipe for UI", __FUNCTION__);
900 //TODO: windback pipebook data on fail
901 return false;
902 }
903 pipe_info.zOrder = index;
904 }
905 return true;
906}
907/*
908 * Configures pipe(s) for MDP composition
909 */
910int MDPCompHighRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800911 PipeLayerPair& PipeLayerPair) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800912 MdpPipeInfoHighRes& mdp_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800913 *(static_cast<MdpPipeInfoHighRes*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -0800914 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
915 eIsFg isFg = IS_FG_OFF;
916 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
917 eDest lDest = mdp_info.lIndex;
918 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800919
920 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
921 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
922
923 return configureHighRes(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
924 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800925}
926
927bool MDPCompHighRes::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
928
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800929 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800930 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
931 return true;
932 }
933
934 if(!ctx || !list) {
935 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700936 return false;
937 }
938
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800939 /* reset Invalidator */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800940 if(idleInvalidator && mCurrentFrame.mdpCount)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800941 idleInvalidator->markForSleep();
942
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500943 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800944 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700945
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800946 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
947 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800948 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800949 if(mCurrentFrame.isFBComposed[i]) continue;
950
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800951 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -0800952 private_handle_t *hnd = (private_handle_t *)layer->handle;
953 if(!hnd) {
954 ALOGE("%s handle null", __FUNCTION__);
955 return false;
956 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800957
958 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
959 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700960 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700961
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800962 int mdpIndex = mCurrentFrame.layerToMDP[i];
963
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800964 MdpPipeInfoHighRes& pipe_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800965 *(MdpPipeInfoHighRes*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
966 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -0800967
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800968 ovutils::eDest indexL = pipe_info.lIndex;
969 ovutils::eDest indexR = pipe_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800970
Saurabh Shahacf10202013-02-26 10:15:15 -0800971 int fd = hnd->fd;
972 int offset = hnd->offset;
973
974 if(rot) {
975 rot->queueBuffer(fd, offset);
976 fd = rot->getDstMemId();
977 offset = rot->getDstOffset();
978 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700979
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800980 //************* play left mixer **********
981 if(indexL != ovutils::OV_INVALID) {
982 ovutils::eDest destL = (ovutils::eDest)indexL;
Saurabh Shahacf10202013-02-26 10:15:15 -0800983 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800984 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
Saurabh Shahacf10202013-02-26 10:15:15 -0800985 if (!ov.queueBuffer(fd, offset, destL)) {
986 ALOGE("%s: queueBuffer failed for left mixer", __FUNCTION__);
987 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800988 }
989 }
990
991 //************* play right mixer **********
992 if(indexR != ovutils::OV_INVALID) {
993 ovutils::eDest destR = (ovutils::eDest)indexR;
Saurabh Shahacf10202013-02-26 10:15:15 -0800994 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800995 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
Saurabh Shahacf10202013-02-26 10:15:15 -0800996 if (!ov.queueBuffer(fd, offset, destR)) {
997 ALOGE("%s: queueBuffer failed for right mixer", __FUNCTION__);
998 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800999 }
1000 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001001
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001002 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1003 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001004
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001005 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001006}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001007}; //namespace
1008