blob: eb46304dcf30c6e62cd7cbb2f6d2cc9bb5ee1735 [file] [log] [blame]
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001/*
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08002 * Copyright (C) 2012-2013, The Linux Foundation. All rights reserved.
Naseer Ahmed7c958d42012-07-31 18:57:03 -07003 * Not a Contribution, Apache license notifications and license are retained
4 * for attribution purposes only.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19#include "hwc_mdpcomp.h"
Naseer Ahmed54821fe2012-11-28 18:44:38 -050020#include <sys/ioctl.h>
Saurabh Shah56f610d2012-08-07 15:27:06 -070021#include "external.h"
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -080022#include "qdMetaData.h"
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -080023#include "mdp_version.h"
Saurabh Shahacf10202013-02-26 10:15:15 -080024#include <overlayRotator.h>
25
Saurabh Shah85234ec2013-04-12 17:09:00 -070026using namespace overlay;
Saurabh Shahbd2d0832013-04-04 14:33:08 -070027using namespace qdutils;
Saurabh Shahacf10202013-02-26 10:15:15 -080028using namespace overlay::utils;
29namespace ovutils = overlay::utils;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070030
Naseer Ahmed7c958d42012-07-31 18:57:03 -070031namespace qhwc {
32
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080033//==============MDPComp========================================================
34
Naseer Ahmed7c958d42012-07-31 18:57:03 -070035IdleInvalidator *MDPComp::idleInvalidator = NULL;
36bool MDPComp::sIdleFallBack = false;
37bool MDPComp::sDebugLogs = false;
Naseer Ahmed54821fe2012-11-28 18:44:38 -050038bool MDPComp::sEnabled = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080039int MDPComp::sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070040
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080041MDPComp* MDPComp::getObject(const int& width, int dpy) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080042 if(width <= MAX_DISPLAY_DIM) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080043 return new MDPCompLowRes(dpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080044 } else {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080045 return new MDPCompHighRes(dpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080046 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080047}
48
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080049MDPComp::MDPComp(int dpy):mDpy(dpy){};
50
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080051void MDPComp::dump(android::String8& buf)
52{
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080053 dumpsys_log(buf,"HWC Map for Dpy: %s \n",
54 mDpy ? "\"EXTERNAL\"" : "\"PRIMARY\"");
55 dumpsys_log(buf,"PREV_FRAME: layerCount:%2d mdpCount:%2d \
56 cacheCount:%2d \n", mCachedFrame.layerCount,
57 mCachedFrame.mdpCount, mCachedFrame.cacheCount);
58 dumpsys_log(buf,"CURR_FRAME: layerCount:%2d mdpCount:%2d \
59 fbCount:%2d \n", mCurrentFrame.layerCount,
60 mCurrentFrame.mdpCount, mCurrentFrame.fbCount);
61 dumpsys_log(buf,"needsFBRedraw:%3s pipesUsed:%2d MaxPipesPerMixer: %d \n",
62 (mCurrentFrame.needsRedraw? "YES" : "NO"),
63 mCurrentFrame.mdpCount, sMaxPipesPerMixer);
64 dumpsys_log(buf," --------------------------------------------- \n");
65 dumpsys_log(buf," listIdx | cached? | mdpIndex | comptype | Z \n");
66 dumpsys_log(buf," --------------------------------------------- \n");
67 for(int index = 0; index < mCurrentFrame.layerCount; index++ )
68 dumpsys_log(buf," %7d | %7s | %8d | %9s | %2d \n",
69 index,
70 (mCurrentFrame.isFBComposed[index] ? "YES" : "NO"),
71 mCurrentFrame.layerToMDP[index],
72 (mCurrentFrame.isFBComposed[index] ?
73 (mCurrentFrame.needsRedraw ? "GLES" : "CACHE") : "MDP"),
74 (mCurrentFrame.isFBComposed[index] ? mCurrentFrame.fbZ :
75 mCurrentFrame.mdpToLayer[mCurrentFrame.layerToMDP[index]].pipeInfo->zOrder));
76 dumpsys_log(buf,"\n");
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080077}
78
79bool MDPComp::init(hwc_context_t *ctx) {
80
81 if(!ctx) {
82 ALOGE("%s: Invalid hwc context!!",__FUNCTION__);
83 return false;
84 }
85
86 if(!setupBasePipe(ctx)) {
87 ALOGE("%s: Failed to setup primary base pipe", __FUNCTION__);
88 return false;
89 }
90
91 char property[PROPERTY_VALUE_MAX];
92
93 sEnabled = false;
94 if((property_get("persist.hwc.mdpcomp.enable", property, NULL) > 0) &&
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080095 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
96 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080097 sEnabled = true;
98 }
99
100 sDebugLogs = false;
101 if(property_get("debug.mdpcomp.logs", property, NULL) > 0) {
102 if(atoi(property) != 0)
103 sDebugLogs = true;
104 }
105
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800106 sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
Saurabh Shah85234ec2013-04-12 17:09:00 -0700107 if(property_get("debug.mdpcomp.maxpermixer", property, "-1") > 0) {
108 int val = atoi(property);
109 if(val >= 0)
110 sMaxPipesPerMixer = min(val, MAX_PIPES_PER_MIXER);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800111 }
112
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800113 unsigned long idle_timeout = DEFAULT_IDLE_TIME;
114 if(property_get("debug.mdpcomp.idletime", property, NULL) > 0) {
115 if(atoi(property) != 0)
116 idle_timeout = atoi(property);
117 }
118
119 //create Idle Invalidator
120 idleInvalidator = IdleInvalidator::getInstance();
121
122 if(idleInvalidator == NULL) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800123 ALOGE("%s: failed to instantiate idleInvalidator object", __FUNCTION__);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800124 } else {
125 idleInvalidator->init(timeout_handler, ctx, idle_timeout);
126 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700127 return true;
128}
129
130void MDPComp::timeout_handler(void *udata) {
131 struct hwc_context_t* ctx = (struct hwc_context_t*)(udata);
132
133 if(!ctx) {
134 ALOGE("%s: received empty data in timer callback", __FUNCTION__);
135 return;
136 }
137
Jesse Hall3be78d92012-08-21 15:12:23 -0700138 if(!ctx->proc) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700139 ALOGE("%s: HWC proc not registered", __FUNCTION__);
140 return;
141 }
142 sIdleFallBack = true;
143 /* Trigger SF to redraw the current frame */
Jesse Hall3be78d92012-08-21 15:12:23 -0700144 ctx->proc->invalidate(ctx->proc);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700145}
146
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800147void MDPComp::setMDPCompLayerFlags(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800148 hwc_display_contents_1_t* list) {
149 LayerProp *layerProp = ctx->layerProp[mDpy];
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800150
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800151 for(int index = 0; index < ctx->listStats[mDpy].numAppLayers; index++) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800152 hwc_layer_1_t* layer = &(list->hwLayers[index]);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800153 if(!mCurrentFrame.isFBComposed[index]) {
154 layerProp[index].mFlags |= HWC_MDPCOMP;
155 layer->compositionType = HWC_OVERLAY;
156 layer->hints |= HWC_HINT_CLEAR_FB;
157 mCachedFrame.hnd[index] = NULL;
158 } else {
159 if(!mCurrentFrame.needsRedraw)
160 layer->compositionType = HWC_OVERLAY;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800161 }
162 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700163}
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500164
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800165/*
166 * Sets up BORDERFILL as default base pipe and detaches RGB0.
167 * Framebuffer is always updated using PLAY ioctl.
168 */
169bool MDPComp::setupBasePipe(hwc_context_t *ctx) {
170 const int dpy = HWC_DISPLAY_PRIMARY;
171 int fb_stride = ctx->dpyAttr[dpy].stride;
172 int fb_width = ctx->dpyAttr[dpy].xres;
173 int fb_height = ctx->dpyAttr[dpy].yres;
174 int fb_fd = ctx->dpyAttr[dpy].fd;
175
176 mdp_overlay ovInfo;
177 msmfb_overlay_data ovData;
178 memset(&ovInfo, 0, sizeof(mdp_overlay));
179 memset(&ovData, 0, sizeof(msmfb_overlay_data));
180
181 ovInfo.src.format = MDP_RGB_BORDERFILL;
182 ovInfo.src.width = fb_width;
183 ovInfo.src.height = fb_height;
184 ovInfo.src_rect.w = fb_width;
185 ovInfo.src_rect.h = fb_height;
186 ovInfo.dst_rect.w = fb_width;
187 ovInfo.dst_rect.h = fb_height;
188 ovInfo.id = MSMFB_NEW_REQUEST;
189
190 if (ioctl(fb_fd, MSMFB_OVERLAY_SET, &ovInfo) < 0) {
191 ALOGE("Failed to call ioctl MSMFB_OVERLAY_SET err=%s",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800192 strerror(errno));
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800193 return false;
194 }
195
196 ovData.id = ovInfo.id;
197 if (ioctl(fb_fd, MSMFB_OVERLAY_PLAY, &ovData) < 0) {
198 ALOGE("Failed to call ioctl MSMFB_OVERLAY_PLAY err=%s",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800199 strerror(errno));
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800200 return false;
201 }
202 return true;
203}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800204MDPComp::FrameInfo::FrameInfo() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700205 reset(0);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800206}
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800207
Saurabh Shahaa236822013-04-24 18:07:26 -0700208void MDPComp::FrameInfo::reset(const int& numLayers) {
209 for(int i = 0 ; i < MAX_PIPES_PER_MIXER && numLayers; i++ ) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800210 if(mdpToLayer[i].pipeInfo) {
211 delete mdpToLayer[i].pipeInfo;
212 mdpToLayer[i].pipeInfo = NULL;
213 //We dont own the rotator
214 mdpToLayer[i].rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800215 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800216 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800217
218 memset(&mdpToLayer, 0, sizeof(mdpToLayer));
219 memset(&layerToMDP, -1, sizeof(layerToMDP));
Saurabh Shahaa236822013-04-24 18:07:26 -0700220 memset(&isFBComposed, 1, sizeof(isFBComposed));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800221
Saurabh Shahaa236822013-04-24 18:07:26 -0700222 layerCount = numLayers;
223 fbCount = numLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800224 mdpCount = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800225 needsRedraw = false;
226 fbZ = 0;
227}
228
Saurabh Shahaa236822013-04-24 18:07:26 -0700229void MDPComp::FrameInfo::map() {
230 // populate layer and MDP maps
231 int mdpIdx = 0;
232 for(int idx = 0; idx < layerCount; idx++) {
233 if(!isFBComposed[idx]) {
234 mdpToLayer[mdpIdx].listIndex = idx;
235 layerToMDP[idx] = mdpIdx++;
236 }
237 }
238}
239
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800240MDPComp::LayerCache::LayerCache() {
241 reset();
242}
243
244void MDPComp::LayerCache::reset() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700245 memset(&hnd, 0, sizeof(hnd));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800246 mdpCount = 0;
247 cacheCount = 0;
248 layerCount = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -0700249 fbZ = -1;
250}
251
252void MDPComp::LayerCache::cacheAll(hwc_display_contents_1_t* list) {
253 const int numAppLayers = list->numHwLayers - 1;
254 for(int i = 0; i < numAppLayers; i++) {
255 hnd[i] = list->hwLayers[i].handle;
256 }
257}
258
259void MDPComp::LayerCache::updateCounts(const FrameInfo& curFrame) {
260 mdpCount = curFrame.mdpCount;
261 cacheCount = curFrame.fbCount;
262 layerCount = curFrame.layerCount;
263 fbZ = curFrame.fbZ;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800264}
265
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800266bool MDPComp::isWidthValid(hwc_context_t *ctx, hwc_layer_1_t *layer) {
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800267
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800268 private_handle_t *hnd = (private_handle_t *)layer->handle;
269
270 if(!hnd) {
271 ALOGE("%s: layer handle is NULL", __FUNCTION__);
272 return false;
273 }
274
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800275 int hw_w = ctx->dpyAttr[mDpy].xres;
276 int hw_h = ctx->dpyAttr[mDpy].yres;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800277
278 hwc_rect_t sourceCrop = layer->sourceCrop;
279 hwc_rect_t displayFrame = layer->displayFrame;
280
281 hwc_rect_t crop = sourceCrop;
282 int crop_w = crop.right - crop.left;
283 int crop_h = crop.bottom - crop.top;
284
285 hwc_rect_t dst = displayFrame;
286 int dst_w = dst.right - dst.left;
287 int dst_h = dst.bottom - dst.top;
288
289 if(dst.left < 0 || dst.top < 0 || dst.right > hw_w || dst.bottom > hw_h) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800290 hwc_rect_t scissor = {0, 0, hw_w, hw_h };
291 qhwc::calculate_crop_rects(crop, dst, scissor, layer->transform);
292 crop_w = crop.right - crop.left;
293 crop_h = crop.bottom - crop.top;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800294 }
295
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800296 /* Workaround for MDP HW limitation in DSI command mode panels where
297 * FPS will not go beyond 30 if buffers on RGB pipes are of width or height
298 * less than 5 pixels
299 * */
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800300
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800301 if((crop_w < 5)||(crop_h < 5))
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800302 return false;
303
304 return true;
305}
306
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800307ovutils::eDest MDPComp::getMdpPipe(hwc_context_t *ctx, ePipeType type) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800308 overlay::Overlay& ov = *ctx->mOverlay;
309 ovutils::eDest mdp_pipe = ovutils::OV_INVALID;
310
311 switch(type) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800312 case MDPCOMP_OV_DMA:
313 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_DMA, mDpy);
314 if(mdp_pipe != ovutils::OV_INVALID) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800315 return mdp_pipe;
316 }
317 case MDPCOMP_OV_ANY:
318 case MDPCOMP_OV_RGB:
319 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy);
320 if(mdp_pipe != ovutils::OV_INVALID) {
321 return mdp_pipe;
322 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800323
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800324 if(type == MDPCOMP_OV_RGB) {
325 //Requested only for RGB pipe
326 break;
327 }
328 case MDPCOMP_OV_VG:
329 return ov.nextPipe(ovutils::OV_MDP_PIPE_VG, mDpy);
330 default:
331 ALOGE("%s: Invalid pipe type",__FUNCTION__);
332 return ovutils::OV_INVALID;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800333 };
334 return ovutils::OV_INVALID;
335}
336
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800337bool MDPComp::isFrameDoable(hwc_context_t *ctx) {
338 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700339 bool ret = true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800340
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800341 if(!isEnabled()) {
342 ALOGD_IF(isDebug(),"%s: MDP Comp. not enabled.", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700343 ret = false;
344 } else if(ctx->mExtDispConfiguring) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800345 ALOGD_IF( isDebug(),"%s: External Display connection is pending",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800346 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700347 ret = false;
348 } else if(ctx->listStats[mDpy].needsAlphaScale
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800349 && ctx->mMDP.version < qdutils::MDSS_V5) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800350 ALOGD_IF(isDebug(), "%s: frame needs alpha downscaling",__FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700351 ret = false;
352 } else if(ctx->isPaddingRound) {
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700353 ctx->isPaddingRound = false;
354 ALOGD_IF(isDebug(), "%s: padding round",__FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700355 ret = false;
356 } else if(sIdleFallBack) {
357 sIdleFallBack = false;
358 ALOGD_IF(isDebug(), "%s: idle fallback",__FUNCTION__);
359 ret = false;
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700360 }
361
Saurabh Shahaa236822013-04-24 18:07:26 -0700362 return ret;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800363}
364
365/* Checks for conditions where all the layers marked for MDP comp cannot be
366 * bypassed. On such conditions we try to bypass atleast YUV layers */
367bool MDPComp::isFullFrameDoable(hwc_context_t *ctx,
368 hwc_display_contents_1_t* list){
369
Saurabh Shahaa236822013-04-24 18:07:26 -0700370 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800371
372 if(mDpy > HWC_DISPLAY_PRIMARY){
373 ALOGD_IF(isDebug(), "%s: Cannot support External display(s)",
374 __FUNCTION__);
375 return false;
376 }
377
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800378 if(isSkipPresent(ctx, mDpy)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700379 ALOGD_IF(isDebug(),"%s: SKIP present: %d",
380 __FUNCTION__,
381 isSkipPresent(ctx, mDpy));
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800382 return false;
383 }
384
385 //MDP composition is not efficient if layer needs rotator.
386 for(int i = 0; i < numAppLayers; ++i) {
387 // As MDP h/w supports flip operation, use MDP comp only for
388 // 180 transforms. Fail for any transform involving 90 (90, 270).
389 hwc_layer_1_t* layer = &list->hwLayers[i];
390 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800391
392 if(layer->transform & HWC_TRANSFORM_ROT_90 && !isYuvBuffer(hnd)) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800393 ALOGD_IF(isDebug(), "%s: orientation involved",__FUNCTION__);
394 return false;
395 }
396
397 if(!isYuvBuffer(hnd) && !isWidthValid(ctx,layer)) {
398 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",__FUNCTION__);
399 return false;
400 }
401 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700402
403 //If all above hard conditions are met we can do full or partial MDP comp.
404 bool ret = false;
405 if(fullMDPComp(ctx, list)) {
406 ret = true;
407 } else if (partialMDPComp(ctx, list)) {
408 ret = true;
409 }
410 return ret;
411}
412
413bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
414 //Setup mCurrentFrame
415 mCurrentFrame.mdpCount = mCurrentFrame.layerCount;
416 mCurrentFrame.fbCount = 0;
417 mCurrentFrame.fbZ = -1;
418 memset(&mCurrentFrame.isFBComposed, 0, sizeof(mCurrentFrame.isFBComposed));
419
420 int mdpCount = mCurrentFrame.mdpCount;
421 if(mdpCount > sMaxPipesPerMixer) {
422 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
423 return false;
424 }
425
426 int numPipesNeeded = pipesNeeded(ctx, list);
427 int availPipes = getAvailablePipes(ctx);
428
429 if(numPipesNeeded > availPipes) {
430 ALOGD_IF(isDebug(), "%s: Insufficient MDP pipes, needed %d, avail %d",
431 __FUNCTION__, numPipesNeeded, availPipes);
432 return false;
433 }
434
435 return true;
436}
437
438bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
439{
440 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
441 //Setup mCurrentFrame
442 mCurrentFrame.reset(numAppLayers);
443 updateLayerCache(ctx, list);
444 updateYUV(ctx, list);
445 batchLayers(); //sets up fbZ also
446
447 int mdpCount = mCurrentFrame.mdpCount;
448 if(mdpCount > (sMaxPipesPerMixer - 1)) { // -1 since FB is used
449 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
450 return false;
451 }
452
453 int numPipesNeeded = pipesNeeded(ctx, list);
454 int availPipes = getAvailablePipes(ctx);
455
456 if(numPipesNeeded > availPipes) {
457 ALOGD_IF(isDebug(), "%s: Insufficient MDP pipes, needed %d, avail %d",
458 __FUNCTION__, numPipesNeeded, availPipes);
459 return false;
460 }
461
462 return true;
463}
464
465bool MDPComp::isOnlyVideoDoable(hwc_context_t *ctx,
466 hwc_display_contents_1_t* list){
467 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
468 mCurrentFrame.reset(numAppLayers);
469 updateYUV(ctx, list);
470 int mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount;
471 int fbNeeded = int(mCurrentFrame.fbCount != 0);
472
473 if(!isYuvPresent(ctx, mDpy)) {
474 return false;
475 }
476
477 if(mdpCount > (sMaxPipesPerMixer - fbNeeded)) {
478 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
479 return false;
480 }
481
482 int numPipesNeeded = pipesNeeded(ctx, list);
483 int availPipes = getAvailablePipes(ctx);
484 if(numPipesNeeded > availPipes) {
485 ALOGD_IF(isDebug(), "%s: Insufficient MDP pipes, needed %d, avail %d",
486 __FUNCTION__, numPipesNeeded, availPipes);
487 return false;
488 }
489
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800490 return true;
491}
492
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800493/* Checks for conditions where YUV layers cannot be bypassed */
494bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800495
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800496 if(isSkipLayer(layer)) {
497 ALOGE("%s: Unable to bypass skipped YUV", __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800498 return false;
499 }
500
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800501 if(isSecuring(ctx, layer)) {
502 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
503 return false;
504 }
505
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700506 if(!qdutils::MDPVersion::getInstance().supportsDecimation()) {
507 const uint32_t downscale =
508 qdutils::MDPVersion::getInstance().getMaxMDPDownscale();
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800509 hwc_rect_t crop = layer->sourceCrop;
510 hwc_rect_t dst = layer->displayFrame;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800511 int cWidth = crop.right - crop.left;
512 int cHeight = crop.bottom - crop.top;
513 int dWidth = dst.right - dst.left;
514 int dHeight = dst.bottom - dst.top;
515
Amara Venkata Mastan Manoj Kumar6fa86722013-04-12 17:11:14 -0700516 if(layer->transform & HAL_TRANSFORM_ROT_90) {
517 swap(cWidth, cHeight);
518 }
519
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700520 if(cWidth > MAX_DISPLAY_DIM || (cWidth/dWidth) > downscale ||
521 (cHeight/dHeight) > downscale)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800522 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800523 }
524 return true;
525}
526
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800527void MDPComp::batchLayers() {
528 /* Idea is to keep as many contiguous non-updating(cached) layers in FB and
529 * send rest of them through MDP. NEVER mark an updating layer for caching.
530 * But cached ones can be marked for MDP*/
531
532 int maxBatchStart = -1;
533 int maxBatchCount = 0;
534
535 /* All or Nothing is cached. No batching needed */
Saurabh Shahaa236822013-04-24 18:07:26 -0700536 if(!mCurrentFrame.fbCount) {
537 mCurrentFrame.fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800538 return;
Saurabh Shahaa236822013-04-24 18:07:26 -0700539 }
540 if(!mCurrentFrame.mdpCount) {
541 mCurrentFrame.fbZ = 0;
542 return;
543 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800544
545 /* Search for max number of contiguous (cached) layers */
546 int i = 0;
547 while (i < mCurrentFrame.layerCount) {
548 int count = 0;
549 while(mCurrentFrame.isFBComposed[i] && i < mCurrentFrame.layerCount) {
550 count++; i++;
551 }
552 if(count > maxBatchCount) {
553 maxBatchCount = count;
554 maxBatchStart = i - count;
Saurabh Shahaa236822013-04-24 18:07:26 -0700555 mCurrentFrame.fbZ = maxBatchStart;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800556 }
557 if(i < mCurrentFrame.layerCount) i++;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800558 }
559
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800560 /* reset rest of the layers for MDP comp */
561 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
562 if(i != maxBatchStart){
563 mCurrentFrame.isFBComposed[i] = false;
564 } else {
565 i += maxBatchCount;
566 }
567 }
568
569 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700570 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
571 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800572
573 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
574 mCurrentFrame.fbCount);
575}
Saurabh Shah85234ec2013-04-12 17:09:00 -0700576
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800577void MDPComp::updateLayerCache(hwc_context_t* ctx,
578 hwc_display_contents_1_t* list) {
579
580 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
581 int numCacheableLayers = 0;
582
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800583 for(int i = 0; i < numAppLayers; i++) {
584 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
585 numCacheableLayers++;
586 mCurrentFrame.isFBComposed[i] = true;
587 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -0700588 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800589 mCachedFrame.hnd[i] = list->hwLayers[i].handle;
590 }
591 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700592
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800593 mCurrentFrame.fbCount = numCacheableLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700594 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
595 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800596 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__, numCacheableLayers);
597}
598
599int MDPComp::getAvailablePipes(hwc_context_t* ctx) {
600 int numDMAPipes = qdutils::MDPVersion::getInstance().getDMAPipes();
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800601 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800602
603 int numAvailable = ov.availablePipes(mDpy);
604
605 //Reserve DMA for rotator
Saurabh Shah85234ec2013-04-12 17:09:00 -0700606 if(Overlay::getDMAMode() == Overlay::DMA_BLOCK_MODE)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800607 numAvailable -= numDMAPipes;
608
609 //Reserve pipe(s)for FB
610 if(mCurrentFrame.fbCount)
611 numAvailable -= pipesForFB();
612
613 return numAvailable;
614}
615
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800616void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list) {
617
618 int nYuvCount = ctx->listStats[mDpy].yuvCount;
619 for(int index = 0;index < nYuvCount; index++){
620 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
621 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
622
623 if(!isYUVDoable(ctx, layer)) {
624 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
625 mCurrentFrame.isFBComposed[nYuvIndex] = true;
626 mCurrentFrame.fbCount++;
627 }
628 } else {
629 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
630 mCurrentFrame.isFBComposed[nYuvIndex] = false;
631 mCurrentFrame.fbCount--;
632 }
633 }
634 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700635
636 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
637 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800638 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
639 mCurrentFrame.fbCount);
640}
641
Saurabh Shahaa236822013-04-24 18:07:26 -0700642bool MDPComp::programMDP(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800643 if(!allocLayerPipes(ctx, list)) {
644 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700645 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800646 }
647
Saurabh Shahaa236822013-04-24 18:07:26 -0700648 bool fbBatch = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800649 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700650 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800651 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800652 int mdpIndex = mCurrentFrame.layerToMDP[index];
653 hwc_layer_1_t* layer = &list->hwLayers[index];
654
655 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
656 cur_pipe->zOrder = mdpNextZOrder++;
657
658 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
659 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
660 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -0700661 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800662 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700663 } else if(fbBatch == false) {
664 mdpNextZOrder++;
665 fbBatch = true;
666 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800667 }
668
Saurabh Shahaa236822013-04-24 18:07:26 -0700669 return true;
670}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800671
Saurabh Shahaa236822013-04-24 18:07:26 -0700672bool MDPComp::programYUV(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
673 if(!allocLayerPipes(ctx, list)) {
674 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
675 return false;
676 }
677 //If we are in this block, it means we have yuv + rgb layers both
678 int mdpIdx = 0;
679 for (int index = 0; index < mCurrentFrame.layerCount; index++) {
680 if(!mCurrentFrame.isFBComposed[index]) {
681 hwc_layer_1_t* layer = &list->hwLayers[index];
682 int mdpIndex = mCurrentFrame.layerToMDP[index];
683 MdpPipeInfo* cur_pipe =
684 mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
685 cur_pipe->zOrder = mdpIdx++;
686
687 if(configure(ctx, layer,
688 mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
689 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
690 layer %d",__FUNCTION__, index);
691 return false;
692 }
693 }
694 }
695 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800696}
697
698int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800699
700 //reset old data
Saurabh Shahaa236822013-04-24 18:07:26 -0700701 const int numLayers = ctx->listStats[mDpy].numAppLayers;
702 mCurrentFrame.reset(numLayers);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800703
Saurabh Shahaa236822013-04-24 18:07:26 -0700704 //Hard conditions, if not met, cannot do MDP comp
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800705 if(!isFrameDoable(ctx)) {
706 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
707 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700708 mCurrentFrame.reset(numLayers);
709 mCachedFrame.cacheAll(list);
710 mCachedFrame.updateCounts(mCurrentFrame);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800711 return 0;
712 }
713
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800714 //Check whether layers marked for MDP Composition is actually doable.
Saurabh Shahaa236822013-04-24 18:07:26 -0700715 if(isFullFrameDoable(ctx, list)){
716 if(mCurrentFrame.mdpCount) {
717 mCurrentFrame.map();
718 //Acquire and Program MDP pipes
719 if(!programMDP(ctx, list)) {
720 mCurrentFrame.reset(numLayers);
721 mCachedFrame.cacheAll(list);
722 }
723 }
724 } else if(isOnlyVideoDoable(ctx, list)) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800725 //All layers marked for MDP comp cannot be bypassed.
726 //Try to compose atleast YUV layers through MDP comp and let
727 //all the RGB layers compose in FB
Saurabh Shahaa236822013-04-24 18:07:26 -0700728 //Destination over
729 mCurrentFrame.fbZ = -1;
730 if(mCurrentFrame.fbCount)
731 mCurrentFrame.fbZ = ctx->listStats[mDpy].yuvCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800732
Saurabh Shahaa236822013-04-24 18:07:26 -0700733 mCurrentFrame.map();
734 if(!programYUV(ctx, list)) {
735 mCurrentFrame.reset(numLayers);
736 mCachedFrame.cacheAll(list);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800737 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700738 } else {
739 mCurrentFrame.reset(numLayers);
740 mCachedFrame.cacheAll(list);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800741 }
742
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800743 /* Any change in composition types needs an FB refresh*/
744 if(mCurrentFrame.fbCount &&
Saurabh Shahaa236822013-04-24 18:07:26 -0700745 ((mCurrentFrame.mdpCount != mCachedFrame.mdpCount) ||
746 (mCurrentFrame.fbCount != mCachedFrame.cacheCount) ||
747 (mCurrentFrame.fbZ != mCachedFrame.fbZ) ||
748 (!mCurrentFrame.mdpCount) ||
749 (list->flags & HWC_GEOMETRY_CHANGED) ||
750 isSkipPresent(ctx, mDpy) ||
751 (mDpy > HWC_DISPLAY_PRIMARY))) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800752 mCurrentFrame.needsRedraw = true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800753 }
754
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800755 //UpdateLayerFlags
756 setMDPCompLayerFlags(ctx, list);
Saurabh Shahaa236822013-04-24 18:07:26 -0700757 mCachedFrame.updateCounts(mCurrentFrame);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800758
759 if(isDebug()) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700760 ALOGD("GEOMETRY change: %d", (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800761 android::String8 sDump("");
762 dump(sDump);
763 ALOGE("%s",sDump.string());
764 }
765
766 return mCurrentFrame.fbZ;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800767}
768
769//=============MDPCompLowRes===================================================
770
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700771/*
772 * Configures pipe(s) for MDP composition
773 */
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800774int MDPCompLowRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800775 PipeLayerPair& PipeLayerPair) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800776 MdpPipeInfoLowRes& mdp_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800777 *(static_cast<MdpPipeInfoLowRes*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -0800778 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
779 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
780 eIsFg isFg = IS_FG_OFF;
781 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700782
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800783 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
784 __FUNCTION__, layer, zOrder, dest);
785
786 return configureLowRes(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
787 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700788}
789
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800790int MDPCompLowRes::pipesNeeded(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800791 hwc_display_contents_1_t* list) {
792 return mCurrentFrame.mdpCount;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700793}
794
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800795bool MDPCompLowRes::allocLayerPipes(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800796 hwc_display_contents_1_t* list) {
797 if(isYuvPresent(ctx, mDpy)) {
798 int nYuvCount = ctx->listStats[mDpy].yuvCount;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700799
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800800 for(int index = 0; index < nYuvCount ; index ++) {
801 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500802
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800803 if(mCurrentFrame.isFBComposed[nYuvIndex])
804 continue;
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800805
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800806 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800807
808 int mdpIndex = mCurrentFrame.layerToMDP[nYuvIndex];
809
810 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800811 info.pipeInfo = new MdpPipeInfoLowRes;
Saurabh Shahacf10202013-02-26 10:15:15 -0800812 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800813 MdpPipeInfoLowRes& pipe_info = *(MdpPipeInfoLowRes*)info.pipeInfo;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800814
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800815 pipe_info.index = getMdpPipe(ctx, MDPCOMP_OV_VG);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800816 if(pipe_info.index == ovutils::OV_INVALID) {
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800817 ALOGD_IF(isDebug(), "%s: Unable to get pipe for Videos",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800818 __FUNCTION__);
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800819 return false;
820 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500821 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500822 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700823
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800824 for(int index = 0 ; index < mCurrentFrame.layerCount; index++ ) {
825 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800826 hwc_layer_1_t* layer = &list->hwLayers[index];
827 private_handle_t *hnd = (private_handle_t *)layer->handle;
828
829 if(isYuvBuffer(hnd))
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500830 continue;
831
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800832 int mdpIndex = mCurrentFrame.layerToMDP[index];
833
834 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800835 info.pipeInfo = new MdpPipeInfoLowRes;
Saurabh Shahacf10202013-02-26 10:15:15 -0800836 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800837 MdpPipeInfoLowRes& pipe_info = *(MdpPipeInfoLowRes*)info.pipeInfo;
838
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800839 ePipeType type = MDPCOMP_OV_ANY;
840
Saurabh Shah85234ec2013-04-12 17:09:00 -0700841 if(!qhwc::needsScaling(layer)
842 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
843 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800844 type = MDPCOMP_OV_DMA;
845 }
846
847 pipe_info.index = getMdpPipe(ctx, type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800848 if(pipe_info.index == ovutils::OV_INVALID) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500849 ALOGD_IF(isDebug(), "%s: Unable to get pipe for UI", __FUNCTION__);
850 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700851 }
852 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700853 return true;
854}
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700855
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800856bool MDPCompLowRes::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700857
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800858 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500859 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
860 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800861 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700862
863 if(!ctx || !list) {
864 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500865 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700866 }
867
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500868 /* reset Invalidator */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800869 if(idleInvalidator && mCurrentFrame.mdpCount)
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500870 idleInvalidator->markForSleep();
871
872 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800873 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700874
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800875 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
876 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700877 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800878 if(mCurrentFrame.isFBComposed[i]) continue;
879
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700880 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -0800881 private_handle_t *hnd = (private_handle_t *)layer->handle;
882 if(!hnd) {
883 ALOGE("%s handle null", __FUNCTION__);
884 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700885 }
886
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800887 int mdpIndex = mCurrentFrame.layerToMDP[i];
888
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800889 MdpPipeInfoLowRes& pipe_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800890 *(MdpPipeInfoLowRes*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800891 ovutils::eDest dest = pipe_info.index;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800892 if(dest == ovutils::OV_INVALID) {
893 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500894 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700895 }
896
Saurabh Shahacf10202013-02-26 10:15:15 -0800897 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
898 continue;
899 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700900
Saurabh Shahacf10202013-02-26 10:15:15 -0800901 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800902 using pipe: %d", __FUNCTION__, layer,
903 hnd, dest );
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700904
Saurabh Shahacf10202013-02-26 10:15:15 -0800905 int fd = hnd->fd;
906 uint32_t offset = hnd->offset;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800907 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -0800908 if(rot) {
909 if(!rot->queueBuffer(fd, offset))
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500910 return false;
Saurabh Shahacf10202013-02-26 10:15:15 -0800911 fd = rot->getDstMemId();
912 offset = rot->getDstOffset();
913 }
914
915 if (!ov.queueBuffer(fd, offset, dest)) {
916 ALOGE("%s: queueBuffer failed for external", __FUNCTION__);
917 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700918 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500919
920 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700921 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500922 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700923}
924
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800925//=============MDPCompHighRes===================================================
926
927int MDPCompHighRes::pipesNeeded(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800928 hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800929 int pipesNeeded = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800930 int hw_w = ctx->dpyAttr[mDpy].xres;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800931
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800932 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
933 if(!mCurrentFrame.isFBComposed[i]) {
934 hwc_layer_1_t* layer = &list->hwLayers[i];
935 hwc_rect_t dst = layer->displayFrame;
936 if(dst.left > hw_w/2) {
937 pipesNeeded++;
938 } else if(dst.right <= hw_w/2) {
939 pipesNeeded++;
940 } else {
941 pipesNeeded += 2;
942 }
943 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800944 }
945 return pipesNeeded;
946}
947
948bool MDPCompHighRes::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800949 MdpPipeInfoHighRes& pipe_info,
950 ePipeType type) {
951 int hw_w = ctx->dpyAttr[mDpy].xres;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800952
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800953 hwc_rect_t dst = layer->displayFrame;
954 if(dst.left > hw_w/2) {
955 pipe_info.lIndex = ovutils::OV_INVALID;
956 pipe_info.rIndex = getMdpPipe(ctx, type);
957 if(pipe_info.rIndex == ovutils::OV_INVALID)
958 return false;
959 } else if (dst.right <= hw_w/2) {
960 pipe_info.rIndex = ovutils::OV_INVALID;
961 pipe_info.lIndex = getMdpPipe(ctx, type);
962 if(pipe_info.lIndex == ovutils::OV_INVALID)
963 return false;
964 } else {
965 pipe_info.rIndex = getMdpPipe(ctx, type);
966 pipe_info.lIndex = getMdpPipe(ctx, type);
967 if(pipe_info.rIndex == ovutils::OV_INVALID ||
968 pipe_info.lIndex == ovutils::OV_INVALID)
969 return false;
970 }
971 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800972}
973
974bool MDPCompHighRes::allocLayerPipes(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800975 hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800976 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800977 int layer_count = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800978
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800979 if(isYuvPresent(ctx, mDpy)) {
980 int nYuvCount = ctx->listStats[mDpy].yuvCount;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800981
982 for(int index = 0; index < nYuvCount; index ++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800983 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800984 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800985 PipeLayerPair& info = mCurrentFrame.mdpToLayer[nYuvIndex];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800986 info.pipeInfo = new MdpPipeInfoHighRes;
Saurabh Shah9e3adb22013-03-26 11:16:27 -0700987 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800988 MdpPipeInfoHighRes& pipe_info = *(MdpPipeInfoHighRes*)info.pipeInfo;
989 if(!acquireMDPPipes(ctx, layer, pipe_info,MDPCOMP_OV_VG)) {
990 ALOGD_IF(isDebug(),"%s: Unable to get pipe for videos",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800991 __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800992 //TODO: windback pipebook data on fail
993 return false;
994 }
995 pipe_info.zOrder = nYuvIndex;
996 }
997 }
998
999 for(int index = 0 ; index < layer_count ; index++ ) {
1000 hwc_layer_1_t* layer = &list->hwLayers[index];
1001 private_handle_t *hnd = (private_handle_t *)layer->handle;
1002
1003 if(isYuvBuffer(hnd))
1004 continue;
1005
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001006 PipeLayerPair& info = mCurrentFrame.mdpToLayer[index];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001007 info.pipeInfo = new MdpPipeInfoHighRes;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001008 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001009 MdpPipeInfoHighRes& pipe_info = *(MdpPipeInfoHighRes*)info.pipeInfo;
1010
1011 ePipeType type = MDPCOMP_OV_ANY;
1012
Saurabh Shah85234ec2013-04-12 17:09:00 -07001013 if(!qhwc::needsScaling(layer)
1014 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
1015 && ctx->mMDP.version >= qdutils::MDSS_V5)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001016 type = MDPCOMP_OV_DMA;
1017
1018 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
1019 ALOGD_IF(isDebug(), "%s: Unable to get pipe for UI", __FUNCTION__);
1020 //TODO: windback pipebook data on fail
1021 return false;
1022 }
1023 pipe_info.zOrder = index;
1024 }
1025 return true;
1026}
1027/*
1028 * Configures pipe(s) for MDP composition
1029 */
1030int MDPCompHighRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001031 PipeLayerPair& PipeLayerPair) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001032 MdpPipeInfoHighRes& mdp_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001033 *(static_cast<MdpPipeInfoHighRes*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001034 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1035 eIsFg isFg = IS_FG_OFF;
1036 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1037 eDest lDest = mdp_info.lIndex;
1038 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001039
1040 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1041 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1042
1043 return configureHighRes(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
1044 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001045}
1046
1047bool MDPCompHighRes::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
1048
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001049 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001050 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1051 return true;
1052 }
1053
1054 if(!ctx || !list) {
1055 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001056 return false;
1057 }
1058
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001059 /* reset Invalidator */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001060 if(idleInvalidator && mCurrentFrame.mdpCount)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001061 idleInvalidator->markForSleep();
1062
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001063 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001064 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001065
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001066 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1067 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001068 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001069 if(mCurrentFrame.isFBComposed[i]) continue;
1070
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001071 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001072 private_handle_t *hnd = (private_handle_t *)layer->handle;
1073 if(!hnd) {
1074 ALOGE("%s handle null", __FUNCTION__);
1075 return false;
1076 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001077
1078 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1079 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001080 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001081
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001082 int mdpIndex = mCurrentFrame.layerToMDP[i];
1083
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001084 MdpPipeInfoHighRes& pipe_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001085 *(MdpPipeInfoHighRes*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1086 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -08001087
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001088 ovutils::eDest indexL = pipe_info.lIndex;
1089 ovutils::eDest indexR = pipe_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001090
Saurabh Shahacf10202013-02-26 10:15:15 -08001091 int fd = hnd->fd;
1092 int offset = hnd->offset;
1093
1094 if(rot) {
1095 rot->queueBuffer(fd, offset);
1096 fd = rot->getDstMemId();
1097 offset = rot->getDstOffset();
1098 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001099
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001100 //************* play left mixer **********
1101 if(indexL != ovutils::OV_INVALID) {
1102 ovutils::eDest destL = (ovutils::eDest)indexL;
Saurabh Shahacf10202013-02-26 10:15:15 -08001103 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001104 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
Saurabh Shahacf10202013-02-26 10:15:15 -08001105 if (!ov.queueBuffer(fd, offset, destL)) {
1106 ALOGE("%s: queueBuffer failed for left mixer", __FUNCTION__);
1107 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001108 }
1109 }
1110
1111 //************* play right mixer **********
1112 if(indexR != ovutils::OV_INVALID) {
1113 ovutils::eDest destR = (ovutils::eDest)indexR;
Saurabh Shahacf10202013-02-26 10:15:15 -08001114 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001115 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
Saurabh Shahacf10202013-02-26 10:15:15 -08001116 if (!ov.queueBuffer(fd, offset, destR)) {
1117 ALOGE("%s: queueBuffer failed for right mixer", __FUNCTION__);
1118 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001119 }
1120 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001121
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001122 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1123 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001124
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001125 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001126}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001127}; //namespace
1128