blob: b81eb5e0f2250bc4b921fd5b272e0de8ed26096f [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 Shahacf10202013-02-26 10:15:15 -080027using 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;
Saurabh Shah85234ec2013-04-12 17:09:00 -0700106 if(property_get("debug.mdpcomp.maxpermixer", property, "-1") > 0) {
107 int val = atoi(property);
108 if(val >= 0)
109 sMaxPipesPerMixer = min(val, MAX_PIPES_PER_MIXER);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800110 }
111
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800112 unsigned long idle_timeout = DEFAULT_IDLE_TIME;
113 if(property_get("debug.mdpcomp.idletime", property, NULL) > 0) {
114 if(atoi(property) != 0)
115 idle_timeout = atoi(property);
116 }
117
118 //create Idle Invalidator
119 idleInvalidator = IdleInvalidator::getInstance();
120
121 if(idleInvalidator == NULL) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800122 ALOGE("%s: failed to instantiate idleInvalidator object", __FUNCTION__);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800123 } else {
124 idleInvalidator->init(timeout_handler, ctx, idle_timeout);
125 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700126 return true;
127}
128
129void MDPComp::timeout_handler(void *udata) {
130 struct hwc_context_t* ctx = (struct hwc_context_t*)(udata);
131
132 if(!ctx) {
133 ALOGE("%s: received empty data in timer callback", __FUNCTION__);
134 return;
135 }
136
Jesse Hall3be78d92012-08-21 15:12:23 -0700137 if(!ctx->proc) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700138 ALOGE("%s: HWC proc not registered", __FUNCTION__);
139 return;
140 }
141 sIdleFallBack = true;
142 /* Trigger SF to redraw the current frame */
Jesse Hall3be78d92012-08-21 15:12:23 -0700143 ctx->proc->invalidate(ctx->proc);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700144}
145
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800146void MDPComp::setMDPCompLayerFlags(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800147 hwc_display_contents_1_t* list) {
148 LayerProp *layerProp = ctx->layerProp[mDpy];
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800149
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800150 for(int index = 0; index < ctx->listStats[mDpy].numAppLayers; index++) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800151 hwc_layer_1_t* layer = &(list->hwLayers[index]);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800152 if(!mCurrentFrame.isFBComposed[index]) {
153 layerProp[index].mFlags |= HWC_MDPCOMP;
154 layer->compositionType = HWC_OVERLAY;
155 layer->hints |= HWC_HINT_CLEAR_FB;
156 mCachedFrame.hnd[index] = NULL;
157 } else {
158 if(!mCurrentFrame.needsRedraw)
159 layer->compositionType = HWC_OVERLAY;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800160 }
161 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800162 mCachedFrame.mdpCount = mCurrentFrame.mdpCount;
163 mCachedFrame.cacheCount = mCurrentFrame.fbCount;
164 mCachedFrame.layerCount = ctx->listStats[mDpy].numAppLayers;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700165}
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500166
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800167/*
168 * Sets up BORDERFILL as default base pipe and detaches RGB0.
169 * Framebuffer is always updated using PLAY ioctl.
170 */
171bool MDPComp::setupBasePipe(hwc_context_t *ctx) {
172 const int dpy = HWC_DISPLAY_PRIMARY;
173 int fb_stride = ctx->dpyAttr[dpy].stride;
174 int fb_width = ctx->dpyAttr[dpy].xres;
175 int fb_height = ctx->dpyAttr[dpy].yres;
176 int fb_fd = ctx->dpyAttr[dpy].fd;
177
178 mdp_overlay ovInfo;
179 msmfb_overlay_data ovData;
180 memset(&ovInfo, 0, sizeof(mdp_overlay));
181 memset(&ovData, 0, sizeof(msmfb_overlay_data));
182
183 ovInfo.src.format = MDP_RGB_BORDERFILL;
184 ovInfo.src.width = fb_width;
185 ovInfo.src.height = fb_height;
186 ovInfo.src_rect.w = fb_width;
187 ovInfo.src_rect.h = fb_height;
188 ovInfo.dst_rect.w = fb_width;
189 ovInfo.dst_rect.h = fb_height;
190 ovInfo.id = MSMFB_NEW_REQUEST;
191
192 if (ioctl(fb_fd, MSMFB_OVERLAY_SET, &ovInfo) < 0) {
193 ALOGE("Failed to call ioctl MSMFB_OVERLAY_SET err=%s",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800194 strerror(errno));
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800195 return false;
196 }
197
198 ovData.id = ovInfo.id;
199 if (ioctl(fb_fd, MSMFB_OVERLAY_PLAY, &ovData) < 0) {
200 ALOGE("Failed to call ioctl MSMFB_OVERLAY_PLAY err=%s",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800201 strerror(errno));
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800202 return false;
203 }
204 return true;
205}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800206MDPComp::FrameInfo::FrameInfo() {
207 layerCount = 0;
208 reset();
209}
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800210
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800211void MDPComp::FrameInfo::reset() {
212
213 for(int i = 0 ; i < MAX_PIPES_PER_MIXER && layerCount; i++ ) {
214 if(mdpToLayer[i].pipeInfo) {
215 delete mdpToLayer[i].pipeInfo;
216 mdpToLayer[i].pipeInfo = NULL;
217 //We dont own the rotator
218 mdpToLayer[i].rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800219 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800220 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800221
222 memset(&mdpToLayer, 0, sizeof(mdpToLayer));
223 memset(&layerToMDP, -1, sizeof(layerToMDP));
224 memset(&isFBComposed, 0, sizeof(isFBComposed));
225
226 layerCount = 0;
227 mdpCount = 0;
228 fbCount = 0;
229 needsRedraw = false;
230 fbZ = 0;
231}
232
233MDPComp::LayerCache::LayerCache() {
234 reset();
235}
236
237void MDPComp::LayerCache::reset() {
238 memset(&hnd, 0, sizeof(buffer_handle_t));
239 mdpCount = 0;
240 cacheCount = 0;
241 layerCount = 0;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800242}
243
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800244bool MDPComp::isWidthValid(hwc_context_t *ctx, hwc_layer_1_t *layer) {
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800245
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800246 private_handle_t *hnd = (private_handle_t *)layer->handle;
247
248 if(!hnd) {
249 ALOGE("%s: layer handle is NULL", __FUNCTION__);
250 return false;
251 }
252
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800253 int hw_w = ctx->dpyAttr[mDpy].xres;
254 int hw_h = ctx->dpyAttr[mDpy].yres;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800255
256 hwc_rect_t sourceCrop = layer->sourceCrop;
257 hwc_rect_t displayFrame = layer->displayFrame;
258
259 hwc_rect_t crop = sourceCrop;
260 int crop_w = crop.right - crop.left;
261 int crop_h = crop.bottom - crop.top;
262
263 hwc_rect_t dst = displayFrame;
264 int dst_w = dst.right - dst.left;
265 int dst_h = dst.bottom - dst.top;
266
267 if(dst.left < 0 || dst.top < 0 || dst.right > hw_w || dst.bottom > hw_h) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800268 hwc_rect_t scissor = {0, 0, hw_w, hw_h };
269 qhwc::calculate_crop_rects(crop, dst, scissor, layer->transform);
270 crop_w = crop.right - crop.left;
271 crop_h = crop.bottom - crop.top;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800272 }
273
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800274 /* Workaround for MDP HW limitation in DSI command mode panels where
275 * FPS will not go beyond 30 if buffers on RGB pipes are of width or height
276 * less than 5 pixels
277 * */
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800278
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800279 if((crop_w < 5)||(crop_h < 5))
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800280 return false;
281
282 return true;
283}
284
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800285ovutils::eDest MDPComp::getMdpPipe(hwc_context_t *ctx, ePipeType type) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800286 overlay::Overlay& ov = *ctx->mOverlay;
287 ovutils::eDest mdp_pipe = ovutils::OV_INVALID;
288
289 switch(type) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800290 case MDPCOMP_OV_DMA:
291 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_DMA, mDpy);
292 if(mdp_pipe != ovutils::OV_INVALID) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800293 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
Saurabh Shah85234ec2013-04-12 17:09:00 -0700353 if(mdpCount > (sMaxPipesPerMixer - fbNeeded)) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800354 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(isSecuring(ctx, layer)) {
404 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
405 return false;
406 }
407
408 /* Workaround for downscales larger than 4x. Will be removed once decimator
409 * block is enabled for MDSS*/
410 if(ctx->mMDP.version == qdutils::MDSS_V5) {
411 hwc_rect_t crop = layer->sourceCrop;
412 hwc_rect_t dst = layer->displayFrame;
413
414 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
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800423 if((cWidth/dWidth) > 4 || (cHeight/dHeight) > 4)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800424 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800425 }
426 return true;
427}
428
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800429void MDPComp::batchLayers() {
430 /* Idea is to keep as many contiguous non-updating(cached) layers in FB and
431 * send rest of them through MDP. NEVER mark an updating layer for caching.
432 * But cached ones can be marked for MDP*/
433
434 int maxBatchStart = -1;
435 int maxBatchCount = 0;
436
437 /* All or Nothing is cached. No batching needed */
438 if(!mCurrentFrame.fbCount ||
439 (mCurrentFrame.fbCount == mCurrentFrame.layerCount))
440 return;
441
442 /* Search for max number of contiguous (cached) layers */
443 int i = 0;
444 while (i < mCurrentFrame.layerCount) {
445 int count = 0;
446 while(mCurrentFrame.isFBComposed[i] && i < mCurrentFrame.layerCount) {
447 count++; i++;
448 }
449 if(count > maxBatchCount) {
450 maxBatchCount = count;
451 maxBatchStart = i - count;
452 }
453 if(i < mCurrentFrame.layerCount) i++;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800454 }
455
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800456 /* reset rest of the layers for MDP comp */
457 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
458 if(i != maxBatchStart){
459 mCurrentFrame.isFBComposed[i] = false;
460 } else {
461 i += maxBatchCount;
462 }
463 }
464
465 mCurrentFrame.fbCount = maxBatchCount;
466
467 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
468 mCurrentFrame.fbCount);
469}
Saurabh Shah85234ec2013-04-12 17:09:00 -0700470
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800471void 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
Saurabh Shah85234ec2013-04-12 17:09:00 -0700504 if(Overlay::getDMAMode() == Overlay::DMA_BLOCK_MODE)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800505 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;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800547
548 if(!allocLayerPipes(ctx, list)) {
549 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
550 goto fn_exit;
551 }
552
553 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
554 index++) {
555 if(!mCurrentFrame.isFBComposed[index]) {
556
557 int mdpIndex = mCurrentFrame.layerToMDP[index];
558 hwc_layer_1_t* layer = &list->hwLayers[index];
559
560 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
561 cur_pipe->zOrder = mdpNextZOrder++;
562
563 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
564 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
565 layer %d",__FUNCTION__, index);
566 goto fn_exit;
567 }
568 } else if(fbZOrder < 0) {
569 fbZOrder = mdpNextZOrder++;
570 };
571 }
572
573 return fbZOrder;
574
575 fn_exit:
576 //Complete fallback to FB
577 resetFrameForFB(ctx, list);
578 return 0;
579}
580
581int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800582
583 //reset old data
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800584 mCurrentFrame.reset();
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800585
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800586 if(!isFrameDoable(ctx)) {
587 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
588 __FUNCTION__);
589 return 0;
590 }
591
592 mCurrentFrame.layerCount = ctx->listStats[mDpy].numAppLayers;
593
594 //Iterate layer list for cached layers
595 updateLayerCache(ctx, list);
596
597 //Add YUV layers to cached list
598 updateYUV(ctx, list);
599
600 //Optimze for bypass
601 batchLayers();
602
603 //list is already parsed / batched for optimal mixed mode composition.
604 //Check whether layers marked for MDP Composition is actually doable.
605 if(!isFullFrameDoable(ctx, list)){
606 //All layers marked for MDP comp cannot be bypassed.
607 //Try to compose atleast YUV layers through MDP comp and let
608 //all the RGB layers compose in FB
609 resetFrameForFB(ctx, list);
610 updateYUV(ctx, list);
611 }
612
613 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
614 mCurrentFrame.fbCount;
615
616 if(mCurrentFrame.mdpCount) {
617 // populate layer and MDP maps
618 for(int idx = 0, mdpIdx = 0; idx < mCurrentFrame.layerCount; idx++) {
619 if(!mCurrentFrame.isFBComposed[idx]) {
620 mCurrentFrame.mdpToLayer[mdpIdx].listIndex = idx;
621 mCurrentFrame.layerToMDP[idx] = mdpIdx++;
622 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800623 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800624 //Acquire and Program MDP pipes
625 mCurrentFrame.fbZ = programMDP(ctx, list);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800626 }
627
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800628 /* Any change in composition types needs an FB refresh*/
629 if(mCurrentFrame.fbCount &&
630 ((mCurrentFrame.mdpCount != mCachedFrame.mdpCount) ||
631 (mCurrentFrame.fbCount != mCachedFrame.cacheCount) ||
632 !mCurrentFrame.mdpCount)) {
633 mCurrentFrame.needsRedraw = true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800634 }
635
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800636 //UpdateLayerFlags
637 setMDPCompLayerFlags(ctx, list);
638
639 if(isDebug()) {
640 android::String8 sDump("");
641 dump(sDump);
642 ALOGE("%s",sDump.string());
643 }
644
645 return mCurrentFrame.fbZ;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800646}
647
648//=============MDPCompLowRes===================================================
649
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700650/*
651 * Configures pipe(s) for MDP composition
652 */
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800653int MDPCompLowRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800654 PipeLayerPair& PipeLayerPair) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800655 MdpPipeInfoLowRes& mdp_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800656 *(static_cast<MdpPipeInfoLowRes*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -0800657 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
658 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
659 eIsFg isFg = IS_FG_OFF;
660 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700661
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800662 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
663 __FUNCTION__, layer, zOrder, dest);
664
665 return configureLowRes(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
666 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700667}
668
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800669int MDPCompLowRes::pipesNeeded(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800670 hwc_display_contents_1_t* list) {
671 return mCurrentFrame.mdpCount;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700672}
673
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800674bool MDPCompLowRes::allocLayerPipes(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800675 hwc_display_contents_1_t* list) {
676 if(isYuvPresent(ctx, mDpy)) {
677 int nYuvCount = ctx->listStats[mDpy].yuvCount;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700678
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800679 for(int index = 0; index < nYuvCount ; index ++) {
680 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500681
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800682 if(mCurrentFrame.isFBComposed[nYuvIndex])
683 continue;
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800684
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800685 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800686
687 int mdpIndex = mCurrentFrame.layerToMDP[nYuvIndex];
688
689 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800690 info.pipeInfo = new MdpPipeInfoLowRes;
Saurabh Shahacf10202013-02-26 10:15:15 -0800691 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800692 MdpPipeInfoLowRes& pipe_info = *(MdpPipeInfoLowRes*)info.pipeInfo;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800693
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800694 pipe_info.index = getMdpPipe(ctx, MDPCOMP_OV_VG);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800695 if(pipe_info.index == ovutils::OV_INVALID) {
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800696 ALOGD_IF(isDebug(), "%s: Unable to get pipe for Videos",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800697 __FUNCTION__);
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800698 return false;
699 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500700 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500701 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700702
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800703 for(int index = 0 ; index < mCurrentFrame.layerCount; index++ ) {
704 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800705 hwc_layer_1_t* layer = &list->hwLayers[index];
706 private_handle_t *hnd = (private_handle_t *)layer->handle;
707
708 if(isYuvBuffer(hnd))
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500709 continue;
710
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800711 int mdpIndex = mCurrentFrame.layerToMDP[index];
712
713 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800714 info.pipeInfo = new MdpPipeInfoLowRes;
Saurabh Shahacf10202013-02-26 10:15:15 -0800715 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800716 MdpPipeInfoLowRes& pipe_info = *(MdpPipeInfoLowRes*)info.pipeInfo;
717
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800718 ePipeType type = MDPCOMP_OV_ANY;
719
Saurabh Shah85234ec2013-04-12 17:09:00 -0700720 if(!qhwc::needsScaling(layer)
721 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
722 && 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
Saurabh Shah85234ec2013-04-12 17:09:00 -0700892 if(!qhwc::needsScaling(layer)
893 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
894 && ctx->mMDP.version >= qdutils::MDSS_V5)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800895 type = MDPCOMP_OV_DMA;
896
897 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
898 ALOGD_IF(isDebug(), "%s: Unable to get pipe for UI", __FUNCTION__);
899 //TODO: windback pipebook data on fail
900 return false;
901 }
902 pipe_info.zOrder = index;
903 }
904 return true;
905}
906/*
907 * Configures pipe(s) for MDP composition
908 */
909int MDPCompHighRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800910 PipeLayerPair& PipeLayerPair) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800911 MdpPipeInfoHighRes& mdp_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800912 *(static_cast<MdpPipeInfoHighRes*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -0800913 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
914 eIsFg isFg = IS_FG_OFF;
915 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
916 eDest lDest = mdp_info.lIndex;
917 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800918
919 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
920 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
921
922 return configureHighRes(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
923 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800924}
925
926bool MDPCompHighRes::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
927
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800928 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800929 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
930 return true;
931 }
932
933 if(!ctx || !list) {
934 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700935 return false;
936 }
937
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800938 /* reset Invalidator */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800939 if(idleInvalidator && mCurrentFrame.mdpCount)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800940 idleInvalidator->markForSleep();
941
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500942 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800943 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700944
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800945 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
946 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800947 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800948 if(mCurrentFrame.isFBComposed[i]) continue;
949
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800950 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -0800951 private_handle_t *hnd = (private_handle_t *)layer->handle;
952 if(!hnd) {
953 ALOGE("%s handle null", __FUNCTION__);
954 return false;
955 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800956
957 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
958 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700959 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700960
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800961 int mdpIndex = mCurrentFrame.layerToMDP[i];
962
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800963 MdpPipeInfoHighRes& pipe_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800964 *(MdpPipeInfoHighRes*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
965 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -0800966
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800967 ovutils::eDest indexL = pipe_info.lIndex;
968 ovutils::eDest indexR = pipe_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800969
Saurabh Shahacf10202013-02-26 10:15:15 -0800970 int fd = hnd->fd;
971 int offset = hnd->offset;
972
973 if(rot) {
974 rot->queueBuffer(fd, offset);
975 fd = rot->getDstMemId();
976 offset = rot->getDstOffset();
977 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700978
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800979 //************* play left mixer **********
980 if(indexL != ovutils::OV_INVALID) {
981 ovutils::eDest destL = (ovutils::eDest)indexL;
Saurabh Shahacf10202013-02-26 10:15:15 -0800982 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800983 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
Saurabh Shahacf10202013-02-26 10:15:15 -0800984 if (!ov.queueBuffer(fd, offset, destL)) {
985 ALOGE("%s: queueBuffer failed for left mixer", __FUNCTION__);
986 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800987 }
988 }
989
990 //************* play right mixer **********
991 if(indexR != ovutils::OV_INVALID) {
992 ovutils::eDest destR = (ovutils::eDest)indexR;
Saurabh Shahacf10202013-02-26 10:15:15 -0800993 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800994 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
Saurabh Shahacf10202013-02-26 10:15:15 -0800995 if (!ov.queueBuffer(fd, offset, destR)) {
996 ALOGE("%s: queueBuffer failed for right mixer", __FUNCTION__);
997 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800998 }
999 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001000
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001001 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1002 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001003
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001004 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001005}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001006}; //namespace
1007