blob: 8935041e94524e7034267e37cadcb9524ac9499d [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
26using overlay::Rotator;
27using namespace overlay::utils;
28namespace ovutils = overlay::utils;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070029
Naseer Ahmed7c958d42012-07-31 18:57:03 -070030namespace qhwc {
31
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080032//==============MDPComp========================================================
33
Naseer Ahmed7c958d42012-07-31 18:57:03 -070034IdleInvalidator *MDPComp::idleInvalidator = NULL;
35bool MDPComp::sIdleFallBack = false;
36bool MDPComp::sDebugLogs = false;
Naseer Ahmed54821fe2012-11-28 18:44:38 -050037bool MDPComp::sEnabled = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080038int MDPComp::sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070039
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080040MDPComp* MDPComp::getObject(const int& width, int dpy) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080041 if(width <= MAX_DISPLAY_DIM) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080042 return new MDPCompLowRes(dpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080043 } else {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080044 return new MDPCompHighRes(dpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080045 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080046}
47
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080048MDPComp::MDPComp(int dpy):mDpy(dpy){};
49
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080050void MDPComp::dump(android::String8& buf)
51{
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080052 dumpsys_log(buf,"HWC Map for Dpy: %s \n",
53 mDpy ? "\"EXTERNAL\"" : "\"PRIMARY\"");
54 dumpsys_log(buf,"PREV_FRAME: layerCount:%2d mdpCount:%2d \
55 cacheCount:%2d \n", mCachedFrame.layerCount,
56 mCachedFrame.mdpCount, mCachedFrame.cacheCount);
57 dumpsys_log(buf,"CURR_FRAME: layerCount:%2d mdpCount:%2d \
58 fbCount:%2d \n", mCurrentFrame.layerCount,
59 mCurrentFrame.mdpCount, mCurrentFrame.fbCount);
60 dumpsys_log(buf,"needsFBRedraw:%3s pipesUsed:%2d MaxPipesPerMixer: %d \n",
61 (mCurrentFrame.needsRedraw? "YES" : "NO"),
62 mCurrentFrame.mdpCount, sMaxPipesPerMixer);
63 dumpsys_log(buf," --------------------------------------------- \n");
64 dumpsys_log(buf," listIdx | cached? | mdpIndex | comptype | Z \n");
65 dumpsys_log(buf," --------------------------------------------- \n");
66 for(int index = 0; index < mCurrentFrame.layerCount; index++ )
67 dumpsys_log(buf," %7d | %7s | %8d | %9s | %2d \n",
68 index,
69 (mCurrentFrame.isFBComposed[index] ? "YES" : "NO"),
70 mCurrentFrame.layerToMDP[index],
71 (mCurrentFrame.isFBComposed[index] ?
72 (mCurrentFrame.needsRedraw ? "GLES" : "CACHE") : "MDP"),
73 (mCurrentFrame.isFBComposed[index] ? mCurrentFrame.fbZ :
74 mCurrentFrame.mdpToLayer[mCurrentFrame.layerToMDP[index]].pipeInfo->zOrder));
75 dumpsys_log(buf,"\n");
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080076}
77
78bool MDPComp::init(hwc_context_t *ctx) {
79
80 if(!ctx) {
81 ALOGE("%s: Invalid hwc context!!",__FUNCTION__);
82 return false;
83 }
84
85 if(!setupBasePipe(ctx)) {
86 ALOGE("%s: Failed to setup primary base pipe", __FUNCTION__);
87 return false;
88 }
89
90 char property[PROPERTY_VALUE_MAX];
91
92 sEnabled = false;
93 if((property_get("persist.hwc.mdpcomp.enable", property, NULL) > 0) &&
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080094 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
95 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080096 sEnabled = true;
97 }
98
99 sDebugLogs = false;
100 if(property_get("debug.mdpcomp.logs", property, NULL) > 0) {
101 if(atoi(property) != 0)
102 sDebugLogs = true;
103 }
104
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800105 sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
106 if(property_get("debug.mdpcomp.maxpermixer", property, NULL) > 0) {
107 if(atoi(property) != 0)
108 sMaxPipesPerMixer = true;
109 }
110
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800111 unsigned long idle_timeout = DEFAULT_IDLE_TIME;
112 if(property_get("debug.mdpcomp.idletime", property, NULL) > 0) {
113 if(atoi(property) != 0)
114 idle_timeout = atoi(property);
115 }
116
117 //create Idle Invalidator
118 idleInvalidator = IdleInvalidator::getInstance();
119
120 if(idleInvalidator == NULL) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800121 ALOGE("%s: failed to instantiate idleInvalidator object", __FUNCTION__);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800122 } else {
123 idleInvalidator->init(timeout_handler, ctx, idle_timeout);
124 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700125 return true;
126}
127
128void MDPComp::timeout_handler(void *udata) {
129 struct hwc_context_t* ctx = (struct hwc_context_t*)(udata);
130
131 if(!ctx) {
132 ALOGE("%s: received empty data in timer callback", __FUNCTION__);
133 return;
134 }
135
Jesse Hall3be78d92012-08-21 15:12:23 -0700136 if(!ctx->proc) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700137 ALOGE("%s: HWC proc not registered", __FUNCTION__);
138 return;
139 }
140 sIdleFallBack = true;
141 /* Trigger SF to redraw the current frame */
Jesse Hall3be78d92012-08-21 15:12:23 -0700142 ctx->proc->invalidate(ctx->proc);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700143}
144
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800145void MDPComp::setMDPCompLayerFlags(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800146 hwc_display_contents_1_t* list) {
147 LayerProp *layerProp = ctx->layerProp[mDpy];
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800148
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800149 for(int index = 0; index < ctx->listStats[mDpy].numAppLayers; index++) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800150 hwc_layer_1_t* layer = &(list->hwLayers[index]);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800151 if(!mCurrentFrame.isFBComposed[index]) {
152 layerProp[index].mFlags |= HWC_MDPCOMP;
153 layer->compositionType = HWC_OVERLAY;
154 layer->hints |= HWC_HINT_CLEAR_FB;
155 mCachedFrame.hnd[index] = NULL;
156 } else {
157 if(!mCurrentFrame.needsRedraw)
158 layer->compositionType = HWC_OVERLAY;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800159 }
160 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800161 mCachedFrame.mdpCount = mCurrentFrame.mdpCount;
162 mCachedFrame.cacheCount = mCurrentFrame.fbCount;
163 mCachedFrame.layerCount = ctx->listStats[mDpy].numAppLayers;
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() {
206 layerCount = 0;
207 reset();
208}
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800209
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800210void MDPComp::FrameInfo::reset() {
211
212 for(int i = 0 ; i < MAX_PIPES_PER_MIXER && layerCount; i++ ) {
213 if(mdpToLayer[i].pipeInfo) {
214 delete mdpToLayer[i].pipeInfo;
215 mdpToLayer[i].pipeInfo = NULL;
216 //We dont own the rotator
217 mdpToLayer[i].rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800218 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800219 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800220
221 memset(&mdpToLayer, 0, sizeof(mdpToLayer));
222 memset(&layerToMDP, -1, sizeof(layerToMDP));
223 memset(&isFBComposed, 0, sizeof(isFBComposed));
224
225 layerCount = 0;
226 mdpCount = 0;
227 fbCount = 0;
228 needsRedraw = false;
229 fbZ = 0;
230}
231
232MDPComp::LayerCache::LayerCache() {
233 reset();
234}
235
236void MDPComp::LayerCache::reset() {
237 memset(&hnd, 0, sizeof(buffer_handle_t));
238 mdpCount = 0;
239 cacheCount = 0;
240 layerCount = 0;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800241}
242
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800243bool MDPComp::isWidthValid(hwc_context_t *ctx, hwc_layer_1_t *layer) {
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800244
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800245 private_handle_t *hnd = (private_handle_t *)layer->handle;
246
247 if(!hnd) {
248 ALOGE("%s: layer handle is NULL", __FUNCTION__);
249 return false;
250 }
251
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800252 int hw_w = ctx->dpyAttr[mDpy].xres;
253 int hw_h = ctx->dpyAttr[mDpy].yres;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800254
255 hwc_rect_t sourceCrop = layer->sourceCrop;
256 hwc_rect_t displayFrame = layer->displayFrame;
257
258 hwc_rect_t crop = sourceCrop;
259 int crop_w = crop.right - crop.left;
260 int crop_h = crop.bottom - crop.top;
261
262 hwc_rect_t dst = displayFrame;
263 int dst_w = dst.right - dst.left;
264 int dst_h = dst.bottom - dst.top;
265
266 if(dst.left < 0 || dst.top < 0 || dst.right > hw_w || dst.bottom > hw_h) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800267 hwc_rect_t scissor = {0, 0, hw_w, hw_h };
268 qhwc::calculate_crop_rects(crop, dst, scissor, layer->transform);
269 crop_w = crop.right - crop.left;
270 crop_h = crop.bottom - crop.top;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800271 }
272
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800273 /* Workaround for MDP HW limitation in DSI command mode panels where
274 * FPS will not go beyond 30 if buffers on RGB pipes are of width or height
275 * less than 5 pixels
276 * */
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800277
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800278 if((crop_w < 5)||(crop_h < 5))
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800279 return false;
280
281 return true;
282}
283
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800284ovutils::eDest MDPComp::getMdpPipe(hwc_context_t *ctx, ePipeType type) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800285 overlay::Overlay& ov = *ctx->mOverlay;
286 ovutils::eDest mdp_pipe = ovutils::OV_INVALID;
287
288 switch(type) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800289 case MDPCOMP_OV_DMA:
290 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_DMA, mDpy);
291 if(mdp_pipe != ovutils::OV_INVALID) {
292 ctx->mDMAInUse = true;
293 return mdp_pipe;
294 }
295 case MDPCOMP_OV_ANY:
296 case MDPCOMP_OV_RGB:
297 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy);
298 if(mdp_pipe != ovutils::OV_INVALID) {
299 return mdp_pipe;
300 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800301
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800302 if(type == MDPCOMP_OV_RGB) {
303 //Requested only for RGB pipe
304 break;
305 }
306 case MDPCOMP_OV_VG:
307 return ov.nextPipe(ovutils::OV_MDP_PIPE_VG, mDpy);
308 default:
309 ALOGE("%s: Invalid pipe type",__FUNCTION__);
310 return ovutils::OV_INVALID;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800311 };
312 return ovutils::OV_INVALID;
313}
314
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800315bool MDPComp::isFrameDoable(hwc_context_t *ctx) {
316 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800317
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800318 if(!isEnabled()) {
319 ALOGD_IF(isDebug(),"%s: MDP Comp. not enabled.", __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800320 return false;
321 }
322
323 if(ctx->mExtDispConfiguring) {
324 ALOGD_IF( isDebug(),"%s: External Display connection is pending",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800325 __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800326 return false;
327 }
328
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800329 if(ctx->listStats[mDpy].needsAlphaScale
330 && ctx->mMDP.version < qdutils::MDSS_V5) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800331 ALOGD_IF(isDebug(), "%s: frame needs alpha downscaling",__FUNCTION__);
332 return false;
333 }
334
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800335 return true;
336}
337
338/* Checks for conditions where all the layers marked for MDP comp cannot be
339 * bypassed. On such conditions we try to bypass atleast YUV layers */
340bool MDPComp::isFullFrameDoable(hwc_context_t *ctx,
341 hwc_display_contents_1_t* list){
342
343 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
344 int mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount;
345 int fbNeeded = int(mCurrentFrame.fbCount != 0);
346
347 if(mDpy > HWC_DISPLAY_PRIMARY){
348 ALOGD_IF(isDebug(), "%s: Cannot support External display(s)",
349 __FUNCTION__);
350 return false;
351 }
352
353 if(mdpCount > (sMaxPipesPerMixer-fbNeeded)) {
354 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
355 return false;
356 }
357
358 if(pipesNeeded(ctx, list) > getAvailablePipes(ctx)) {
359 ALOGD_IF(isDebug(), "%s: Insufficient MDP pipes",__FUNCTION__);
360 return false;
361 }
362
363 if(isSkipPresent(ctx, mDpy)) {
364 ALOGD_IF(isDebug(), "%s: Skip layers present",__FUNCTION__);
365 return false;
366 }
367
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800368 //FB composition on idle timeout
369 if(sIdleFallBack) {
370 sIdleFallBack = false;
371 ALOGD_IF(isDebug(), "%s: idle fallback",__FUNCTION__);
372 return false;
373 }
374
375 //MDP composition is not efficient if layer needs rotator.
376 for(int i = 0; i < numAppLayers; ++i) {
377 // As MDP h/w supports flip operation, use MDP comp only for
378 // 180 transforms. Fail for any transform involving 90 (90, 270).
379 hwc_layer_1_t* layer = &list->hwLayers[i];
380 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800381
382 if(layer->transform & HWC_TRANSFORM_ROT_90 && !isYuvBuffer(hnd)) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800383 ALOGD_IF(isDebug(), "%s: orientation involved",__FUNCTION__);
384 return false;
385 }
386
387 if(!isYuvBuffer(hnd) && !isWidthValid(ctx,layer)) {
388 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",__FUNCTION__);
389 return false;
390 }
391 }
392 return true;
393}
394
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800395/* Checks for conditions where YUV layers cannot be bypassed */
396bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800397
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800398 if(isSkipLayer(layer)) {
399 ALOGE("%s: Unable to bypass skipped YUV", __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800400 return false;
401 }
402
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800403 if(ctx->mNeedsRotator && ctx->mDMAInUse) {
404 ALOGE("%s: No DMA for Rotator",__FUNCTION__);
405 return false;
406 }
407
408 if(isSecuring(ctx, layer)) {
409 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
410 return false;
411 }
412
413 /* Workaround for downscales larger than 4x. Will be removed once decimator
414 * block is enabled for MDSS*/
415 if(ctx->mMDP.version == qdutils::MDSS_V5) {
416 hwc_rect_t crop = layer->sourceCrop;
417 hwc_rect_t dst = layer->displayFrame;
418
419 int cWidth = crop.right - crop.left;
420 int cHeight = crop.bottom - crop.top;
421 int dWidth = dst.right - dst.left;
422 int dHeight = dst.bottom - dst.top;
423
Amara Venkata Mastan Manoj Kumar6fa86722013-04-12 17:11:14 -0700424 if(layer->transform & HAL_TRANSFORM_ROT_90) {
425 swap(cWidth, cHeight);
426 }
427
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800428 if((cWidth/dWidth) > 4 || (cHeight/dHeight) > 4)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800429 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800430 }
431 return true;
432}
433
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800434void MDPComp::batchLayers() {
435 /* Idea is to keep as many contiguous non-updating(cached) layers in FB and
436 * send rest of them through MDP. NEVER mark an updating layer for caching.
437 * But cached ones can be marked for MDP*/
438
439 int maxBatchStart = -1;
440 int maxBatchCount = 0;
441
442 /* All or Nothing is cached. No batching needed */
443 if(!mCurrentFrame.fbCount ||
444 (mCurrentFrame.fbCount == mCurrentFrame.layerCount))
445 return;
446
447 /* Search for max number of contiguous (cached) layers */
448 int i = 0;
449 while (i < mCurrentFrame.layerCount) {
450 int count = 0;
451 while(mCurrentFrame.isFBComposed[i] && i < mCurrentFrame.layerCount) {
452 count++; i++;
453 }
454 if(count > maxBatchCount) {
455 maxBatchCount = count;
456 maxBatchStart = i - count;
457 }
458 if(i < mCurrentFrame.layerCount) i++;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800459 }
460
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800461 /* reset rest of the layers for MDP comp */
462 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
463 if(i != maxBatchStart){
464 mCurrentFrame.isFBComposed[i] = false;
465 } else {
466 i += maxBatchCount;
467 }
468 }
469
470 mCurrentFrame.fbCount = maxBatchCount;
471
472 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
473 mCurrentFrame.fbCount);
474}
475void MDPComp::updateLayerCache(hwc_context_t* ctx,
476 hwc_display_contents_1_t* list) {
477
478 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
479 int numCacheableLayers = 0;
480
481 if((list->flags & HWC_GEOMETRY_CHANGED) || (isSkipPresent(ctx, mDpy))) {
482 ALOGD_IF(isDebug(),"%s: No Caching: \
483 GEOMETRY change: %d SKIP present: %d", __FUNCTION__,
484 (list->flags & HWC_GEOMETRY_CHANGED),isSkipPresent(ctx, mDpy));
485 mCachedFrame.reset();
486 return;
487 }
488
489 for(int i = 0; i < numAppLayers; i++) {
490 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
491 numCacheableLayers++;
492 mCurrentFrame.isFBComposed[i] = true;
493 } else {
494 mCachedFrame.hnd[i] = list->hwLayers[i].handle;
495 }
496 }
497 mCurrentFrame.fbCount = numCacheableLayers;
498 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__, numCacheableLayers);
499}
500
501int MDPComp::getAvailablePipes(hwc_context_t* ctx) {
502 int numDMAPipes = qdutils::MDPVersion::getInstance().getDMAPipes();
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800503 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800504
505 int numAvailable = ov.availablePipes(mDpy);
506
507 //Reserve DMA for rotator
508 if(ctx->mNeedsRotator)
509 numAvailable -= numDMAPipes;
510
511 //Reserve pipe(s)for FB
512 if(mCurrentFrame.fbCount)
513 numAvailable -= pipesForFB();
514
515 return numAvailable;
516}
517
518void MDPComp::resetFrameForFB(hwc_context_t* ctx,
519 hwc_display_contents_1_t* list) {
520 mCurrentFrame.fbCount = mCurrentFrame.layerCount;
521 memset(&mCurrentFrame.isFBComposed, 1,
522 sizeof(mCurrentFrame.isFBComposed));
523 mCurrentFrame.needsRedraw = true;
524}
525
526void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list) {
527
528 int nYuvCount = ctx->listStats[mDpy].yuvCount;
529 for(int index = 0;index < nYuvCount; index++){
530 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
531 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
532
533 if(!isYUVDoable(ctx, layer)) {
534 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
535 mCurrentFrame.isFBComposed[nYuvIndex] = true;
536 mCurrentFrame.fbCount++;
537 }
538 } else {
539 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
540 mCurrentFrame.isFBComposed[nYuvIndex] = false;
541 mCurrentFrame.fbCount--;
542 }
543 }
544 }
545 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
546 mCurrentFrame.fbCount);
547}
548
549int MDPComp::programMDP(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
550 int fbZOrder = -1;
551 ctx->mDMAInUse = false;
552
553 if(!allocLayerPipes(ctx, list)) {
554 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
555 goto fn_exit;
556 }
557
558 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
559 index++) {
560 if(!mCurrentFrame.isFBComposed[index]) {
561
562 int mdpIndex = mCurrentFrame.layerToMDP[index];
563 hwc_layer_1_t* layer = &list->hwLayers[index];
564
565 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
566 cur_pipe->zOrder = mdpNextZOrder++;
567
568 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
569 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
570 layer %d",__FUNCTION__, index);
571 goto fn_exit;
572 }
573 } else if(fbZOrder < 0) {
574 fbZOrder = mdpNextZOrder++;
575 };
576 }
577
578 return fbZOrder;
579
580 fn_exit:
581 //Complete fallback to FB
582 resetFrameForFB(ctx, list);
583 return 0;
584}
585
586int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800587
588 //reset old data
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800589 mCurrentFrame.reset();
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800590
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800591 if(!isFrameDoable(ctx)) {
592 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
593 __FUNCTION__);
594 return 0;
595 }
596
597 mCurrentFrame.layerCount = ctx->listStats[mDpy].numAppLayers;
598
599 //Iterate layer list for cached layers
600 updateLayerCache(ctx, list);
601
602 //Add YUV layers to cached list
603 updateYUV(ctx, list);
604
605 //Optimze for bypass
606 batchLayers();
607
608 //list is already parsed / batched for optimal mixed mode composition.
609 //Check whether layers marked for MDP Composition is actually doable.
610 if(!isFullFrameDoable(ctx, list)){
611 //All layers marked for MDP comp cannot be bypassed.
612 //Try to compose atleast YUV layers through MDP comp and let
613 //all the RGB layers compose in FB
614 resetFrameForFB(ctx, list);
615 updateYUV(ctx, list);
616 }
617
618 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
619 mCurrentFrame.fbCount;
620
621 if(mCurrentFrame.mdpCount) {
622 // populate layer and MDP maps
623 for(int idx = 0, mdpIdx = 0; idx < mCurrentFrame.layerCount; idx++) {
624 if(!mCurrentFrame.isFBComposed[idx]) {
625 mCurrentFrame.mdpToLayer[mdpIdx].listIndex = idx;
626 mCurrentFrame.layerToMDP[idx] = mdpIdx++;
627 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800628 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800629 //Acquire and Program MDP pipes
630 mCurrentFrame.fbZ = programMDP(ctx, list);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800631 }
632
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800633 /* Any change in composition types needs an FB refresh*/
634 if(mCurrentFrame.fbCount &&
635 ((mCurrentFrame.mdpCount != mCachedFrame.mdpCount) ||
636 (mCurrentFrame.fbCount != mCachedFrame.cacheCount) ||
637 !mCurrentFrame.mdpCount)) {
638 mCurrentFrame.needsRedraw = true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800639 }
640
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800641 //UpdateLayerFlags
642 setMDPCompLayerFlags(ctx, list);
643
644 if(isDebug()) {
645 android::String8 sDump("");
646 dump(sDump);
647 ALOGE("%s",sDump.string());
648 }
649
650 return mCurrentFrame.fbZ;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800651}
652
653//=============MDPCompLowRes===================================================
654
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700655/*
656 * Configures pipe(s) for MDP composition
657 */
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800658int MDPCompLowRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800659 PipeLayerPair& PipeLayerPair) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800660 MdpPipeInfoLowRes& mdp_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800661 *(static_cast<MdpPipeInfoLowRes*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -0800662 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
663 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
664 eIsFg isFg = IS_FG_OFF;
665 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700666
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800667 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
668 __FUNCTION__, layer, zOrder, dest);
669
670 return configureLowRes(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
671 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700672}
673
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800674int MDPCompLowRes::pipesNeeded(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800675 hwc_display_contents_1_t* list) {
676 return mCurrentFrame.mdpCount;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700677}
678
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800679bool MDPCompLowRes::allocLayerPipes(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800680 hwc_display_contents_1_t* list) {
681 if(isYuvPresent(ctx, mDpy)) {
682 int nYuvCount = ctx->listStats[mDpy].yuvCount;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700683
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800684 for(int index = 0; index < nYuvCount ; index ++) {
685 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500686
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800687 if(mCurrentFrame.isFBComposed[nYuvIndex])
688 continue;
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800689
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800690 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800691
692 int mdpIndex = mCurrentFrame.layerToMDP[nYuvIndex];
693
694 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800695 info.pipeInfo = new MdpPipeInfoLowRes;
Saurabh Shahacf10202013-02-26 10:15:15 -0800696 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800697 MdpPipeInfoLowRes& pipe_info = *(MdpPipeInfoLowRes*)info.pipeInfo;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800698
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800699 pipe_info.index = getMdpPipe(ctx, MDPCOMP_OV_VG);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800700 if(pipe_info.index == ovutils::OV_INVALID) {
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800701 ALOGD_IF(isDebug(), "%s: Unable to get pipe for Videos",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800702 __FUNCTION__);
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800703 return false;
704 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500705 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500706 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700707
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800708 for(int index = 0 ; index < mCurrentFrame.layerCount; index++ ) {
709 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800710 hwc_layer_1_t* layer = &list->hwLayers[index];
711 private_handle_t *hnd = (private_handle_t *)layer->handle;
712
713 if(isYuvBuffer(hnd))
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500714 continue;
715
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800716 int mdpIndex = mCurrentFrame.layerToMDP[index];
717
718 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800719 info.pipeInfo = new MdpPipeInfoLowRes;
Saurabh Shahacf10202013-02-26 10:15:15 -0800720 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800721 MdpPipeInfoLowRes& pipe_info = *(MdpPipeInfoLowRes*)info.pipeInfo;
722
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800723 ePipeType type = MDPCOMP_OV_ANY;
724
725 if(!qhwc::needsScaling(layer) && !ctx->mNeedsRotator
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800726 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800727 type = MDPCOMP_OV_DMA;
728 }
729
730 pipe_info.index = getMdpPipe(ctx, type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800731 if(pipe_info.index == ovutils::OV_INVALID) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500732 ALOGD_IF(isDebug(), "%s: Unable to get pipe for UI", __FUNCTION__);
733 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700734 }
735 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700736 return true;
737}
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700738
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800739bool MDPCompLowRes::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700740
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800741 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500742 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
743 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800744 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700745
746 if(!ctx || !list) {
747 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500748 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700749 }
750
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500751 /* reset Invalidator */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800752 if(idleInvalidator && mCurrentFrame.mdpCount)
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500753 idleInvalidator->markForSleep();
754
755 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800756 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700757
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800758 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
759 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700760 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800761 if(mCurrentFrame.isFBComposed[i]) continue;
762
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700763 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -0800764 private_handle_t *hnd = (private_handle_t *)layer->handle;
765 if(!hnd) {
766 ALOGE("%s handle null", __FUNCTION__);
767 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700768 }
769
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800770 int mdpIndex = mCurrentFrame.layerToMDP[i];
771
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800772 MdpPipeInfoLowRes& pipe_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800773 *(MdpPipeInfoLowRes*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800774 ovutils::eDest dest = pipe_info.index;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800775 if(dest == ovutils::OV_INVALID) {
776 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500777 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700778 }
779
Saurabh Shahacf10202013-02-26 10:15:15 -0800780 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
781 continue;
782 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700783
Saurabh Shahacf10202013-02-26 10:15:15 -0800784 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800785 using pipe: %d", __FUNCTION__, layer,
786 hnd, dest );
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700787
Saurabh Shahacf10202013-02-26 10:15:15 -0800788 int fd = hnd->fd;
789 uint32_t offset = hnd->offset;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800790 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -0800791 if(rot) {
792 if(!rot->queueBuffer(fd, offset))
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500793 return false;
Saurabh Shahacf10202013-02-26 10:15:15 -0800794 fd = rot->getDstMemId();
795 offset = rot->getDstOffset();
796 }
797
798 if (!ov.queueBuffer(fd, offset, dest)) {
799 ALOGE("%s: queueBuffer failed for external", __FUNCTION__);
800 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700801 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500802
803 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700804 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500805 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700806}
807
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800808//=============MDPCompHighRes===================================================
809
810int MDPCompHighRes::pipesNeeded(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800811 hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800812 int pipesNeeded = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800813 int hw_w = ctx->dpyAttr[mDpy].xres;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800814
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800815 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
816 if(!mCurrentFrame.isFBComposed[i]) {
817 hwc_layer_1_t* layer = &list->hwLayers[i];
818 hwc_rect_t dst = layer->displayFrame;
819 if(dst.left > hw_w/2) {
820 pipesNeeded++;
821 } else if(dst.right <= hw_w/2) {
822 pipesNeeded++;
823 } else {
824 pipesNeeded += 2;
825 }
826 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800827 }
828 return pipesNeeded;
829}
830
831bool MDPCompHighRes::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800832 MdpPipeInfoHighRes& pipe_info,
833 ePipeType type) {
834 int hw_w = ctx->dpyAttr[mDpy].xres;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800835
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800836 hwc_rect_t dst = layer->displayFrame;
837 if(dst.left > hw_w/2) {
838 pipe_info.lIndex = ovutils::OV_INVALID;
839 pipe_info.rIndex = getMdpPipe(ctx, type);
840 if(pipe_info.rIndex == ovutils::OV_INVALID)
841 return false;
842 } else if (dst.right <= hw_w/2) {
843 pipe_info.rIndex = ovutils::OV_INVALID;
844 pipe_info.lIndex = getMdpPipe(ctx, type);
845 if(pipe_info.lIndex == ovutils::OV_INVALID)
846 return false;
847 } else {
848 pipe_info.rIndex = getMdpPipe(ctx, type);
849 pipe_info.lIndex = getMdpPipe(ctx, type);
850 if(pipe_info.rIndex == ovutils::OV_INVALID ||
851 pipe_info.lIndex == ovutils::OV_INVALID)
852 return false;
853 }
854 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800855}
856
857bool MDPCompHighRes::allocLayerPipes(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800858 hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800859 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800860 int layer_count = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800861
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800862 if(isYuvPresent(ctx, mDpy)) {
863 int nYuvCount = ctx->listStats[mDpy].yuvCount;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800864
865 for(int index = 0; index < nYuvCount; index ++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800866 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800867 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800868 PipeLayerPair& info = mCurrentFrame.mdpToLayer[nYuvIndex];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800869 info.pipeInfo = new MdpPipeInfoHighRes;
Saurabh Shah9e3adb22013-03-26 11:16:27 -0700870 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800871 MdpPipeInfoHighRes& pipe_info = *(MdpPipeInfoHighRes*)info.pipeInfo;
872 if(!acquireMDPPipes(ctx, layer, pipe_info,MDPCOMP_OV_VG)) {
873 ALOGD_IF(isDebug(),"%s: Unable to get pipe for videos",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800874 __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800875 //TODO: windback pipebook data on fail
876 return false;
877 }
878 pipe_info.zOrder = nYuvIndex;
879 }
880 }
881
882 for(int index = 0 ; index < layer_count ; index++ ) {
883 hwc_layer_1_t* layer = &list->hwLayers[index];
884 private_handle_t *hnd = (private_handle_t *)layer->handle;
885
886 if(isYuvBuffer(hnd))
887 continue;
888
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800889 PipeLayerPair& info = mCurrentFrame.mdpToLayer[index];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800890 info.pipeInfo = new MdpPipeInfoHighRes;
Saurabh Shah9e3adb22013-03-26 11:16:27 -0700891 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800892 MdpPipeInfoHighRes& pipe_info = *(MdpPipeInfoHighRes*)info.pipeInfo;
893
894 ePipeType type = MDPCOMP_OV_ANY;
895
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800896 if(!qhwc::needsScaling(layer) && !ctx->mNeedsRotator
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800897 && ctx->mMDP.version >= qdutils::MDSS_V5)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800898 type = MDPCOMP_OV_DMA;
899
900 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
901 ALOGD_IF(isDebug(), "%s: Unable to get pipe for UI", __FUNCTION__);
902 //TODO: windback pipebook data on fail
903 return false;
904 }
905 pipe_info.zOrder = index;
906 }
907 return true;
908}
909/*
910 * Configures pipe(s) for MDP composition
911 */
912int MDPCompHighRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800913 PipeLayerPair& PipeLayerPair) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800914 MdpPipeInfoHighRes& mdp_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800915 *(static_cast<MdpPipeInfoHighRes*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -0800916 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
917 eIsFg isFg = IS_FG_OFF;
918 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
919 eDest lDest = mdp_info.lIndex;
920 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800921
922 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
923 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
924
925 return configureHighRes(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
926 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800927}
928
929bool MDPCompHighRes::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
930
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800931 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800932 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
933 return true;
934 }
935
936 if(!ctx || !list) {
937 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700938 return false;
939 }
940
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800941 /* reset Invalidator */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800942 if(idleInvalidator && mCurrentFrame.mdpCount)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800943 idleInvalidator->markForSleep();
944
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500945 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800946 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700947
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800948 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
949 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800950 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800951 if(mCurrentFrame.isFBComposed[i]) continue;
952
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800953 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -0800954 private_handle_t *hnd = (private_handle_t *)layer->handle;
955 if(!hnd) {
956 ALOGE("%s handle null", __FUNCTION__);
957 return false;
958 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800959
960 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
961 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700962 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700963
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800964 int mdpIndex = mCurrentFrame.layerToMDP[i];
965
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800966 MdpPipeInfoHighRes& pipe_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800967 *(MdpPipeInfoHighRes*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
968 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -0800969
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800970 ovutils::eDest indexL = pipe_info.lIndex;
971 ovutils::eDest indexR = pipe_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800972
Saurabh Shahacf10202013-02-26 10:15:15 -0800973 int fd = hnd->fd;
974 int offset = hnd->offset;
975
976 if(rot) {
977 rot->queueBuffer(fd, offset);
978 fd = rot->getDstMemId();
979 offset = rot->getDstOffset();
980 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700981
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800982 //************* play left mixer **********
983 if(indexL != ovutils::OV_INVALID) {
984 ovutils::eDest destL = (ovutils::eDest)indexL;
Saurabh Shahacf10202013-02-26 10:15:15 -0800985 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800986 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
Saurabh Shahacf10202013-02-26 10:15:15 -0800987 if (!ov.queueBuffer(fd, offset, destL)) {
988 ALOGE("%s: queueBuffer failed for left mixer", __FUNCTION__);
989 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800990 }
991 }
992
993 //************* play right mixer **********
994 if(indexR != ovutils::OV_INVALID) {
995 ovutils::eDest destR = (ovutils::eDest)indexR;
Saurabh Shahacf10202013-02-26 10:15:15 -0800996 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800997 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
Saurabh Shahacf10202013-02-26 10:15:15 -0800998 if (!ov.queueBuffer(fd, offset, destR)) {
999 ALOGE("%s: queueBuffer failed for right mixer", __FUNCTION__);
1000 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001001 }
1002 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001003
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001004 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1005 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001006
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001007 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001008}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001009}; //namespace
1010