blob: 30178a0c439736cf11ac945f1e1703f0d163d252 [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
424 if((cWidth/dWidth) > 4 || (cHeight/dHeight) > 4)
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}
471void MDPComp::updateLayerCache(hwc_context_t* ctx,
472 hwc_display_contents_1_t* list) {
473
474 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
475 int numCacheableLayers = 0;
476
477 if((list->flags & HWC_GEOMETRY_CHANGED) || (isSkipPresent(ctx, mDpy))) {
478 ALOGD_IF(isDebug(),"%s: No Caching: \
479 GEOMETRY change: %d SKIP present: %d", __FUNCTION__,
480 (list->flags & HWC_GEOMETRY_CHANGED),isSkipPresent(ctx, mDpy));
481 mCachedFrame.reset();
482 return;
483 }
484
485 for(int i = 0; i < numAppLayers; i++) {
486 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
487 numCacheableLayers++;
488 mCurrentFrame.isFBComposed[i] = true;
489 } else {
490 mCachedFrame.hnd[i] = list->hwLayers[i].handle;
491 }
492 }
493 mCurrentFrame.fbCount = numCacheableLayers;
494 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__, numCacheableLayers);
495}
496
497int MDPComp::getAvailablePipes(hwc_context_t* ctx) {
498 int numDMAPipes = qdutils::MDPVersion::getInstance().getDMAPipes();
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800499 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800500
501 int numAvailable = ov.availablePipes(mDpy);
502
503 //Reserve DMA for rotator
504 if(ctx->mNeedsRotator)
505 numAvailable -= numDMAPipes;
506
507 //Reserve pipe(s)for FB
508 if(mCurrentFrame.fbCount)
509 numAvailable -= pipesForFB();
510
511 return numAvailable;
512}
513
514void MDPComp::resetFrameForFB(hwc_context_t* ctx,
515 hwc_display_contents_1_t* list) {
516 mCurrentFrame.fbCount = mCurrentFrame.layerCount;
517 memset(&mCurrentFrame.isFBComposed, 1,
518 sizeof(mCurrentFrame.isFBComposed));
519 mCurrentFrame.needsRedraw = true;
520}
521
522void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list) {
523
524 int nYuvCount = ctx->listStats[mDpy].yuvCount;
525 for(int index = 0;index < nYuvCount; index++){
526 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
527 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
528
529 if(!isYUVDoable(ctx, layer)) {
530 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
531 mCurrentFrame.isFBComposed[nYuvIndex] = true;
532 mCurrentFrame.fbCount++;
533 }
534 } else {
535 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
536 mCurrentFrame.isFBComposed[nYuvIndex] = false;
537 mCurrentFrame.fbCount--;
538 }
539 }
540 }
541 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
542 mCurrentFrame.fbCount);
543}
544
545int MDPComp::programMDP(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
546 int fbZOrder = -1;
547 ctx->mDMAInUse = false;
548
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
721 if(!qhwc::needsScaling(layer) && !ctx->mNeedsRotator
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800722 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800723 type = MDPCOMP_OV_DMA;
724 }
725
726 pipe_info.index = getMdpPipe(ctx, type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800727 if(pipe_info.index == ovutils::OV_INVALID) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500728 ALOGD_IF(isDebug(), "%s: Unable to get pipe for UI", __FUNCTION__);
729 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700730 }
731 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700732 return true;
733}
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700734
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800735bool MDPCompLowRes::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700736
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800737 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500738 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
739 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800740 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700741
742 if(!ctx || !list) {
743 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500744 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700745 }
746
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500747 /* reset Invalidator */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800748 if(idleInvalidator && mCurrentFrame.mdpCount)
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500749 idleInvalidator->markForSleep();
750
751 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800752 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700753
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800754 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
755 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700756 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800757 if(mCurrentFrame.isFBComposed[i]) continue;
758
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700759 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -0800760 private_handle_t *hnd = (private_handle_t *)layer->handle;
761 if(!hnd) {
762 ALOGE("%s handle null", __FUNCTION__);
763 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700764 }
765
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800766 int mdpIndex = mCurrentFrame.layerToMDP[i];
767
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800768 MdpPipeInfoLowRes& pipe_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800769 *(MdpPipeInfoLowRes*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800770 ovutils::eDest dest = pipe_info.index;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800771 if(dest == ovutils::OV_INVALID) {
772 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500773 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700774 }
775
Saurabh Shahacf10202013-02-26 10:15:15 -0800776 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
777 continue;
778 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700779
Saurabh Shahacf10202013-02-26 10:15:15 -0800780 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800781 using pipe: %d", __FUNCTION__, layer,
782 hnd, dest );
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700783
Saurabh Shahacf10202013-02-26 10:15:15 -0800784 int fd = hnd->fd;
785 uint32_t offset = hnd->offset;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800786 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -0800787 if(rot) {
788 if(!rot->queueBuffer(fd, offset))
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500789 return false;
Saurabh Shahacf10202013-02-26 10:15:15 -0800790 fd = rot->getDstMemId();
791 offset = rot->getDstOffset();
792 }
793
794 if (!ov.queueBuffer(fd, offset, dest)) {
795 ALOGE("%s: queueBuffer failed for external", __FUNCTION__);
796 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700797 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500798
799 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700800 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500801 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700802}
803
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800804//=============MDPCompHighRes===================================================
805
806int MDPCompHighRes::pipesNeeded(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800807 hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800808 int pipesNeeded = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800809 int hw_w = ctx->dpyAttr[mDpy].xres;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800810
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800811 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
812 if(!mCurrentFrame.isFBComposed[i]) {
813 hwc_layer_1_t* layer = &list->hwLayers[i];
814 hwc_rect_t dst = layer->displayFrame;
815 if(dst.left > hw_w/2) {
816 pipesNeeded++;
817 } else if(dst.right <= hw_w/2) {
818 pipesNeeded++;
819 } else {
820 pipesNeeded += 2;
821 }
822 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800823 }
824 return pipesNeeded;
825}
826
827bool MDPCompHighRes::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800828 MdpPipeInfoHighRes& pipe_info,
829 ePipeType type) {
830 int hw_w = ctx->dpyAttr[mDpy].xres;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800831
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800832 hwc_rect_t dst = layer->displayFrame;
833 if(dst.left > hw_w/2) {
834 pipe_info.lIndex = ovutils::OV_INVALID;
835 pipe_info.rIndex = getMdpPipe(ctx, type);
836 if(pipe_info.rIndex == ovutils::OV_INVALID)
837 return false;
838 } else if (dst.right <= hw_w/2) {
839 pipe_info.rIndex = ovutils::OV_INVALID;
840 pipe_info.lIndex = getMdpPipe(ctx, type);
841 if(pipe_info.lIndex == ovutils::OV_INVALID)
842 return false;
843 } else {
844 pipe_info.rIndex = getMdpPipe(ctx, type);
845 pipe_info.lIndex = getMdpPipe(ctx, type);
846 if(pipe_info.rIndex == ovutils::OV_INVALID ||
847 pipe_info.lIndex == ovutils::OV_INVALID)
848 return false;
849 }
850 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800851}
852
853bool MDPCompHighRes::allocLayerPipes(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800854 hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800855 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800856 int layer_count = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800857
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800858 if(isYuvPresent(ctx, mDpy)) {
859 int nYuvCount = ctx->listStats[mDpy].yuvCount;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800860
861 for(int index = 0; index < nYuvCount; index ++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800862 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800863 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800864 PipeLayerPair& info = mCurrentFrame.mdpToLayer[nYuvIndex];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800865 info.pipeInfo = new MdpPipeInfoHighRes;
Saurabh Shah9e3adb22013-03-26 11:16:27 -0700866 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800867 MdpPipeInfoHighRes& pipe_info = *(MdpPipeInfoHighRes*)info.pipeInfo;
868 if(!acquireMDPPipes(ctx, layer, pipe_info,MDPCOMP_OV_VG)) {
869 ALOGD_IF(isDebug(),"%s: Unable to get pipe for videos",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800870 __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800871 //TODO: windback pipebook data on fail
872 return false;
873 }
874 pipe_info.zOrder = nYuvIndex;
875 }
876 }
877
878 for(int index = 0 ; index < layer_count ; index++ ) {
879 hwc_layer_1_t* layer = &list->hwLayers[index];
880 private_handle_t *hnd = (private_handle_t *)layer->handle;
881
882 if(isYuvBuffer(hnd))
883 continue;
884
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800885 PipeLayerPair& info = mCurrentFrame.mdpToLayer[index];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800886 info.pipeInfo = new MdpPipeInfoHighRes;
Saurabh Shah9e3adb22013-03-26 11:16:27 -0700887 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800888 MdpPipeInfoHighRes& pipe_info = *(MdpPipeInfoHighRes*)info.pipeInfo;
889
890 ePipeType type = MDPCOMP_OV_ANY;
891
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800892 if(!qhwc::needsScaling(layer) && !ctx->mNeedsRotator
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800893 && ctx->mMDP.version >= qdutils::MDSS_V5)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800894 type = MDPCOMP_OV_DMA;
895
896 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
897 ALOGD_IF(isDebug(), "%s: Unable to get pipe for UI", __FUNCTION__);
898 //TODO: windback pipebook data on fail
899 return false;
900 }
901 pipe_info.zOrder = index;
902 }
903 return true;
904}
905/*
906 * Configures pipe(s) for MDP composition
907 */
908int MDPCompHighRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800909 PipeLayerPair& PipeLayerPair) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800910 MdpPipeInfoHighRes& mdp_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800911 *(static_cast<MdpPipeInfoHighRes*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -0800912 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
913 eIsFg isFg = IS_FG_OFF;
914 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
915 eDest lDest = mdp_info.lIndex;
916 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800917
918 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
919 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
920
921 return configureHighRes(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
922 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800923}
924
925bool MDPCompHighRes::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
926
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800927 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800928 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
929 return true;
930 }
931
932 if(!ctx || !list) {
933 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700934 return false;
935 }
936
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800937 /* reset Invalidator */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800938 if(idleInvalidator && mCurrentFrame.mdpCount)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800939 idleInvalidator->markForSleep();
940
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500941 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800942 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700943
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800944 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
945 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800946 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800947 if(mCurrentFrame.isFBComposed[i]) continue;
948
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800949 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -0800950 private_handle_t *hnd = (private_handle_t *)layer->handle;
951 if(!hnd) {
952 ALOGE("%s handle null", __FUNCTION__);
953 return false;
954 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800955
956 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
957 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700958 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700959
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800960 int mdpIndex = mCurrentFrame.layerToMDP[i];
961
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800962 MdpPipeInfoHighRes& pipe_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800963 *(MdpPipeInfoHighRes*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
964 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -0800965
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800966 ovutils::eDest indexL = pipe_info.lIndex;
967 ovutils::eDest indexR = pipe_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800968
Saurabh Shahacf10202013-02-26 10:15:15 -0800969 int fd = hnd->fd;
970 int offset = hnd->offset;
971
972 if(rot) {
973 rot->queueBuffer(fd, offset);
974 fd = rot->getDstMemId();
975 offset = rot->getDstOffset();
976 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700977
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800978 //************* play left mixer **********
979 if(indexL != ovutils::OV_INVALID) {
980 ovutils::eDest destL = (ovutils::eDest)indexL;
Saurabh Shahacf10202013-02-26 10:15:15 -0800981 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800982 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
Saurabh Shahacf10202013-02-26 10:15:15 -0800983 if (!ov.queueBuffer(fd, offset, destL)) {
984 ALOGE("%s: queueBuffer failed for left mixer", __FUNCTION__);
985 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800986 }
987 }
988
989 //************* play right mixer **********
990 if(indexR != ovutils::OV_INVALID) {
991 ovutils::eDest destR = (ovutils::eDest)indexR;
Saurabh Shahacf10202013-02-26 10:15:15 -0800992 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800993 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
Saurabh Shahacf10202013-02-26 10:15:15 -0800994 if (!ov.queueBuffer(fd, offset, destR)) {
995 ALOGE("%s: queueBuffer failed for right mixer", __FUNCTION__);
996 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800997 }
998 }
Saurabh Shahacf10202013-02-26 10:15:15 -0800999
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001000 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1001 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001002
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001003 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001004}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001005}; //namespace
1006