blob: 2323030d807ca2d54c24c6d510b444357dbd1478 [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
419 if((cWidth/dWidth) > 4 || (cHeight/dHeight) > 4)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800420 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800421 }
422 return true;
423}
424
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800425void MDPComp::batchLayers() {
426 /* Idea is to keep as many contiguous non-updating(cached) layers in FB and
427 * send rest of them through MDP. NEVER mark an updating layer for caching.
428 * But cached ones can be marked for MDP*/
429
430 int maxBatchStart = -1;
431 int maxBatchCount = 0;
432
433 /* All or Nothing is cached. No batching needed */
434 if(!mCurrentFrame.fbCount ||
435 (mCurrentFrame.fbCount == mCurrentFrame.layerCount))
436 return;
437
438 /* Search for max number of contiguous (cached) layers */
439 int i = 0;
440 while (i < mCurrentFrame.layerCount) {
441 int count = 0;
442 while(mCurrentFrame.isFBComposed[i] && i < mCurrentFrame.layerCount) {
443 count++; i++;
444 }
445 if(count > maxBatchCount) {
446 maxBatchCount = count;
447 maxBatchStart = i - count;
448 }
449 if(i < mCurrentFrame.layerCount) i++;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800450 }
451
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800452 /* reset rest of the layers for MDP comp */
453 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
454 if(i != maxBatchStart){
455 mCurrentFrame.isFBComposed[i] = false;
456 } else {
457 i += maxBatchCount;
458 }
459 }
460
461 mCurrentFrame.fbCount = maxBatchCount;
462
463 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
464 mCurrentFrame.fbCount);
465}
Saurabh Shah85234ec2013-04-12 17:09:00 -0700466
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800467void MDPComp::updateLayerCache(hwc_context_t* ctx,
468 hwc_display_contents_1_t* list) {
469
470 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
471 int numCacheableLayers = 0;
472
473 if((list->flags & HWC_GEOMETRY_CHANGED) || (isSkipPresent(ctx, mDpy))) {
474 ALOGD_IF(isDebug(),"%s: No Caching: \
475 GEOMETRY change: %d SKIP present: %d", __FUNCTION__,
476 (list->flags & HWC_GEOMETRY_CHANGED),isSkipPresent(ctx, mDpy));
477 mCachedFrame.reset();
478 return;
479 }
480
481 for(int i = 0; i < numAppLayers; i++) {
482 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
483 numCacheableLayers++;
484 mCurrentFrame.isFBComposed[i] = true;
485 } else {
486 mCachedFrame.hnd[i] = list->hwLayers[i].handle;
487 }
488 }
489 mCurrentFrame.fbCount = numCacheableLayers;
490 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__, numCacheableLayers);
491}
492
493int MDPComp::getAvailablePipes(hwc_context_t* ctx) {
494 int numDMAPipes = qdutils::MDPVersion::getInstance().getDMAPipes();
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800495 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800496
497 int numAvailable = ov.availablePipes(mDpy);
498
499 //Reserve DMA for rotator
Saurabh Shah85234ec2013-04-12 17:09:00 -0700500 if(Overlay::getDMAMode() == Overlay::DMA_BLOCK_MODE)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800501 numAvailable -= numDMAPipes;
502
503 //Reserve pipe(s)for FB
504 if(mCurrentFrame.fbCount)
505 numAvailable -= pipesForFB();
506
507 return numAvailable;
508}
509
510void MDPComp::resetFrameForFB(hwc_context_t* ctx,
511 hwc_display_contents_1_t* list) {
512 mCurrentFrame.fbCount = mCurrentFrame.layerCount;
513 memset(&mCurrentFrame.isFBComposed, 1,
514 sizeof(mCurrentFrame.isFBComposed));
515 mCurrentFrame.needsRedraw = true;
516}
517
518void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list) {
519
520 int nYuvCount = ctx->listStats[mDpy].yuvCount;
521 for(int index = 0;index < nYuvCount; index++){
522 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
523 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
524
525 if(!isYUVDoable(ctx, layer)) {
526 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
527 mCurrentFrame.isFBComposed[nYuvIndex] = true;
528 mCurrentFrame.fbCount++;
529 }
530 } else {
531 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
532 mCurrentFrame.isFBComposed[nYuvIndex] = false;
533 mCurrentFrame.fbCount--;
534 }
535 }
536 }
537 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
538 mCurrentFrame.fbCount);
539}
540
541int MDPComp::programMDP(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
542 int fbZOrder = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800543
544 if(!allocLayerPipes(ctx, list)) {
545 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
546 goto fn_exit;
547 }
548
549 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
550 index++) {
551 if(!mCurrentFrame.isFBComposed[index]) {
552
553 int mdpIndex = mCurrentFrame.layerToMDP[index];
554 hwc_layer_1_t* layer = &list->hwLayers[index];
555
556 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
557 cur_pipe->zOrder = mdpNextZOrder++;
558
559 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
560 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
561 layer %d",__FUNCTION__, index);
562 goto fn_exit;
563 }
564 } else if(fbZOrder < 0) {
565 fbZOrder = mdpNextZOrder++;
566 };
567 }
568
569 return fbZOrder;
570
571 fn_exit:
572 //Complete fallback to FB
573 resetFrameForFB(ctx, list);
574 return 0;
575}
576
577int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800578
579 //reset old data
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800580 mCurrentFrame.reset();
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800581
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800582 if(!isFrameDoable(ctx)) {
583 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
584 __FUNCTION__);
585 return 0;
586 }
587
588 mCurrentFrame.layerCount = ctx->listStats[mDpy].numAppLayers;
589
590 //Iterate layer list for cached layers
591 updateLayerCache(ctx, list);
592
593 //Add YUV layers to cached list
594 updateYUV(ctx, list);
595
596 //Optimze for bypass
597 batchLayers();
598
599 //list is already parsed / batched for optimal mixed mode composition.
600 //Check whether layers marked for MDP Composition is actually doable.
601 if(!isFullFrameDoable(ctx, list)){
602 //All layers marked for MDP comp cannot be bypassed.
603 //Try to compose atleast YUV layers through MDP comp and let
604 //all the RGB layers compose in FB
605 resetFrameForFB(ctx, list);
606 updateYUV(ctx, list);
607 }
608
609 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
610 mCurrentFrame.fbCount;
611
612 if(mCurrentFrame.mdpCount) {
613 // populate layer and MDP maps
614 for(int idx = 0, mdpIdx = 0; idx < mCurrentFrame.layerCount; idx++) {
615 if(!mCurrentFrame.isFBComposed[idx]) {
616 mCurrentFrame.mdpToLayer[mdpIdx].listIndex = idx;
617 mCurrentFrame.layerToMDP[idx] = mdpIdx++;
618 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800619 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800620 //Acquire and Program MDP pipes
621 mCurrentFrame.fbZ = programMDP(ctx, list);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800622 }
623
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800624 /* Any change in composition types needs an FB refresh*/
625 if(mCurrentFrame.fbCount &&
626 ((mCurrentFrame.mdpCount != mCachedFrame.mdpCount) ||
627 (mCurrentFrame.fbCount != mCachedFrame.cacheCount) ||
628 !mCurrentFrame.mdpCount)) {
629 mCurrentFrame.needsRedraw = true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800630 }
631
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800632 //UpdateLayerFlags
633 setMDPCompLayerFlags(ctx, list);
634
635 if(isDebug()) {
636 android::String8 sDump("");
637 dump(sDump);
638 ALOGE("%s",sDump.string());
639 }
640
641 return mCurrentFrame.fbZ;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800642}
643
644//=============MDPCompLowRes===================================================
645
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700646/*
647 * Configures pipe(s) for MDP composition
648 */
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800649int MDPCompLowRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800650 PipeLayerPair& PipeLayerPair) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800651 MdpPipeInfoLowRes& mdp_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800652 *(static_cast<MdpPipeInfoLowRes*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -0800653 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
654 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
655 eIsFg isFg = IS_FG_OFF;
656 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700657
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800658 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
659 __FUNCTION__, layer, zOrder, dest);
660
661 return configureLowRes(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
662 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700663}
664
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800665int MDPCompLowRes::pipesNeeded(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800666 hwc_display_contents_1_t* list) {
667 return mCurrentFrame.mdpCount;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700668}
669
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800670bool MDPCompLowRes::allocLayerPipes(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800671 hwc_display_contents_1_t* list) {
672 if(isYuvPresent(ctx, mDpy)) {
673 int nYuvCount = ctx->listStats[mDpy].yuvCount;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700674
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800675 for(int index = 0; index < nYuvCount ; index ++) {
676 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500677
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800678 if(mCurrentFrame.isFBComposed[nYuvIndex])
679 continue;
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800680
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800681 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800682
683 int mdpIndex = mCurrentFrame.layerToMDP[nYuvIndex];
684
685 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800686 info.pipeInfo = new MdpPipeInfoLowRes;
Saurabh Shahacf10202013-02-26 10:15:15 -0800687 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800688 MdpPipeInfoLowRes& pipe_info = *(MdpPipeInfoLowRes*)info.pipeInfo;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800689
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800690 pipe_info.index = getMdpPipe(ctx, MDPCOMP_OV_VG);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800691 if(pipe_info.index == ovutils::OV_INVALID) {
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800692 ALOGD_IF(isDebug(), "%s: Unable to get pipe for Videos",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800693 __FUNCTION__);
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800694 return false;
695 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500696 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500697 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700698
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800699 for(int index = 0 ; index < mCurrentFrame.layerCount; index++ ) {
700 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800701 hwc_layer_1_t* layer = &list->hwLayers[index];
702 private_handle_t *hnd = (private_handle_t *)layer->handle;
703
704 if(isYuvBuffer(hnd))
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500705 continue;
706
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800707 int mdpIndex = mCurrentFrame.layerToMDP[index];
708
709 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800710 info.pipeInfo = new MdpPipeInfoLowRes;
Saurabh Shahacf10202013-02-26 10:15:15 -0800711 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800712 MdpPipeInfoLowRes& pipe_info = *(MdpPipeInfoLowRes*)info.pipeInfo;
713
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800714 ePipeType type = MDPCOMP_OV_ANY;
715
Saurabh Shah85234ec2013-04-12 17:09:00 -0700716 if(!qhwc::needsScaling(layer)
717 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
718 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800719 type = MDPCOMP_OV_DMA;
720 }
721
722 pipe_info.index = getMdpPipe(ctx, type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800723 if(pipe_info.index == ovutils::OV_INVALID) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500724 ALOGD_IF(isDebug(), "%s: Unable to get pipe for UI", __FUNCTION__);
725 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700726 }
727 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700728 return true;
729}
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700730
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800731bool MDPCompLowRes::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700732
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800733 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500734 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
735 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800736 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700737
738 if(!ctx || !list) {
739 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500740 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700741 }
742
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500743 /* reset Invalidator */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800744 if(idleInvalidator && mCurrentFrame.mdpCount)
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500745 idleInvalidator->markForSleep();
746
747 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800748 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700749
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800750 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
751 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700752 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800753 if(mCurrentFrame.isFBComposed[i]) continue;
754
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700755 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -0800756 private_handle_t *hnd = (private_handle_t *)layer->handle;
757 if(!hnd) {
758 ALOGE("%s handle null", __FUNCTION__);
759 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700760 }
761
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800762 int mdpIndex = mCurrentFrame.layerToMDP[i];
763
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800764 MdpPipeInfoLowRes& pipe_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800765 *(MdpPipeInfoLowRes*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800766 ovutils::eDest dest = pipe_info.index;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800767 if(dest == ovutils::OV_INVALID) {
768 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500769 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700770 }
771
Saurabh Shahacf10202013-02-26 10:15:15 -0800772 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
773 continue;
774 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700775
Saurabh Shahacf10202013-02-26 10:15:15 -0800776 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800777 using pipe: %d", __FUNCTION__, layer,
778 hnd, dest );
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700779
Saurabh Shahacf10202013-02-26 10:15:15 -0800780 int fd = hnd->fd;
781 uint32_t offset = hnd->offset;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800782 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -0800783 if(rot) {
784 if(!rot->queueBuffer(fd, offset))
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500785 return false;
Saurabh Shahacf10202013-02-26 10:15:15 -0800786 fd = rot->getDstMemId();
787 offset = rot->getDstOffset();
788 }
789
790 if (!ov.queueBuffer(fd, offset, dest)) {
791 ALOGE("%s: queueBuffer failed for external", __FUNCTION__);
792 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700793 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500794
795 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700796 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500797 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700798}
799
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800800//=============MDPCompHighRes===================================================
801
802int MDPCompHighRes::pipesNeeded(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800803 hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800804 int pipesNeeded = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800805 int hw_w = ctx->dpyAttr[mDpy].xres;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800806
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800807 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
808 if(!mCurrentFrame.isFBComposed[i]) {
809 hwc_layer_1_t* layer = &list->hwLayers[i];
810 hwc_rect_t dst = layer->displayFrame;
811 if(dst.left > hw_w/2) {
812 pipesNeeded++;
813 } else if(dst.right <= hw_w/2) {
814 pipesNeeded++;
815 } else {
816 pipesNeeded += 2;
817 }
818 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800819 }
820 return pipesNeeded;
821}
822
823bool MDPCompHighRes::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800824 MdpPipeInfoHighRes& pipe_info,
825 ePipeType type) {
826 int hw_w = ctx->dpyAttr[mDpy].xres;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800827
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800828 hwc_rect_t dst = layer->displayFrame;
829 if(dst.left > hw_w/2) {
830 pipe_info.lIndex = ovutils::OV_INVALID;
831 pipe_info.rIndex = getMdpPipe(ctx, type);
832 if(pipe_info.rIndex == ovutils::OV_INVALID)
833 return false;
834 } else if (dst.right <= hw_w/2) {
835 pipe_info.rIndex = ovutils::OV_INVALID;
836 pipe_info.lIndex = getMdpPipe(ctx, type);
837 if(pipe_info.lIndex == ovutils::OV_INVALID)
838 return false;
839 } else {
840 pipe_info.rIndex = getMdpPipe(ctx, type);
841 pipe_info.lIndex = getMdpPipe(ctx, type);
842 if(pipe_info.rIndex == ovutils::OV_INVALID ||
843 pipe_info.lIndex == ovutils::OV_INVALID)
844 return false;
845 }
846 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800847}
848
849bool MDPCompHighRes::allocLayerPipes(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800850 hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800851 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800852 int layer_count = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800853
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800854 if(isYuvPresent(ctx, mDpy)) {
855 int nYuvCount = ctx->listStats[mDpy].yuvCount;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800856
857 for(int index = 0; index < nYuvCount; index ++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800858 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800859 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800860 PipeLayerPair& info = mCurrentFrame.mdpToLayer[nYuvIndex];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800861 info.pipeInfo = new MdpPipeInfoHighRes;
Saurabh Shah9e3adb22013-03-26 11:16:27 -0700862 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800863 MdpPipeInfoHighRes& pipe_info = *(MdpPipeInfoHighRes*)info.pipeInfo;
864 if(!acquireMDPPipes(ctx, layer, pipe_info,MDPCOMP_OV_VG)) {
865 ALOGD_IF(isDebug(),"%s: Unable to get pipe for videos",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800866 __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800867 //TODO: windback pipebook data on fail
868 return false;
869 }
870 pipe_info.zOrder = nYuvIndex;
871 }
872 }
873
874 for(int index = 0 ; index < layer_count ; index++ ) {
875 hwc_layer_1_t* layer = &list->hwLayers[index];
876 private_handle_t *hnd = (private_handle_t *)layer->handle;
877
878 if(isYuvBuffer(hnd))
879 continue;
880
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800881 PipeLayerPair& info = mCurrentFrame.mdpToLayer[index];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800882 info.pipeInfo = new MdpPipeInfoHighRes;
Saurabh Shah9e3adb22013-03-26 11:16:27 -0700883 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800884 MdpPipeInfoHighRes& pipe_info = *(MdpPipeInfoHighRes*)info.pipeInfo;
885
886 ePipeType type = MDPCOMP_OV_ANY;
887
Saurabh Shah85234ec2013-04-12 17:09:00 -0700888 if(!qhwc::needsScaling(layer)
889 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
890 && ctx->mMDP.version >= qdutils::MDSS_V5)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800891 type = MDPCOMP_OV_DMA;
892
893 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
894 ALOGD_IF(isDebug(), "%s: Unable to get pipe for UI", __FUNCTION__);
895 //TODO: windback pipebook data on fail
896 return false;
897 }
898 pipe_info.zOrder = index;
899 }
900 return true;
901}
902/*
903 * Configures pipe(s) for MDP composition
904 */
905int MDPCompHighRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800906 PipeLayerPair& PipeLayerPair) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800907 MdpPipeInfoHighRes& mdp_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800908 *(static_cast<MdpPipeInfoHighRes*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -0800909 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
910 eIsFg isFg = IS_FG_OFF;
911 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
912 eDest lDest = mdp_info.lIndex;
913 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800914
915 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
916 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
917
918 return configureHighRes(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
919 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800920}
921
922bool MDPCompHighRes::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
923
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800924 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800925 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
926 return true;
927 }
928
929 if(!ctx || !list) {
930 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700931 return false;
932 }
933
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800934 /* reset Invalidator */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800935 if(idleInvalidator && mCurrentFrame.mdpCount)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800936 idleInvalidator->markForSleep();
937
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500938 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800939 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700940
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800941 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
942 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800943 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800944 if(mCurrentFrame.isFBComposed[i]) continue;
945
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800946 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -0800947 private_handle_t *hnd = (private_handle_t *)layer->handle;
948 if(!hnd) {
949 ALOGE("%s handle null", __FUNCTION__);
950 return false;
951 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800952
953 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
954 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700955 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700956
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800957 int mdpIndex = mCurrentFrame.layerToMDP[i];
958
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800959 MdpPipeInfoHighRes& pipe_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800960 *(MdpPipeInfoHighRes*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
961 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -0800962
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800963 ovutils::eDest indexL = pipe_info.lIndex;
964 ovutils::eDest indexR = pipe_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800965
Saurabh Shahacf10202013-02-26 10:15:15 -0800966 int fd = hnd->fd;
967 int offset = hnd->offset;
968
969 if(rot) {
970 rot->queueBuffer(fd, offset);
971 fd = rot->getDstMemId();
972 offset = rot->getDstOffset();
973 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700974
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800975 //************* play left mixer **********
976 if(indexL != ovutils::OV_INVALID) {
977 ovutils::eDest destL = (ovutils::eDest)indexL;
Saurabh Shahacf10202013-02-26 10:15:15 -0800978 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800979 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
Saurabh Shahacf10202013-02-26 10:15:15 -0800980 if (!ov.queueBuffer(fd, offset, destL)) {
981 ALOGE("%s: queueBuffer failed for left mixer", __FUNCTION__);
982 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800983 }
984 }
985
986 //************* play right mixer **********
987 if(indexR != ovutils::OV_INVALID) {
988 ovutils::eDest destR = (ovutils::eDest)indexR;
Saurabh Shahacf10202013-02-26 10:15:15 -0800989 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800990 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
Saurabh Shahacf10202013-02-26 10:15:15 -0800991 if (!ov.queueBuffer(fd, offset, destR)) {
992 ALOGE("%s: queueBuffer failed for right mixer", __FUNCTION__);
993 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800994 }
995 }
Saurabh Shahacf10202013-02-26 10:15:15 -0800996
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800997 layerProp[i].mFlags &= ~HWC_MDPCOMP;
998 }
Saurabh Shahacf10202013-02-26 10:15:15 -0800999
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001000 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001001}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001002}; //namespace
1003