blob: f9f76c76be37f9cf04b1bc932ba3b7a419cd5828 [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
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530266bool MDPComp::isValidDimension(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
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530299 * There also is a HW limilation in MDP, minimum block size is 2x2
300 * Fallback to GPU if height is less than 2.
301 */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800302 if((crop_w < 5)||(crop_h < 5))
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800303 return false;
304
305 return true;
306}
307
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800308ovutils::eDest MDPComp::getMdpPipe(hwc_context_t *ctx, ePipeType type) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800309 overlay::Overlay& ov = *ctx->mOverlay;
310 ovutils::eDest mdp_pipe = ovutils::OV_INVALID;
311
312 switch(type) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800313 case MDPCOMP_OV_DMA:
314 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_DMA, mDpy);
315 if(mdp_pipe != ovutils::OV_INVALID) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800316 return mdp_pipe;
317 }
318 case MDPCOMP_OV_ANY:
319 case MDPCOMP_OV_RGB:
320 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy);
321 if(mdp_pipe != ovutils::OV_INVALID) {
322 return mdp_pipe;
323 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800324
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800325 if(type == MDPCOMP_OV_RGB) {
326 //Requested only for RGB pipe
327 break;
328 }
329 case MDPCOMP_OV_VG:
330 return ov.nextPipe(ovutils::OV_MDP_PIPE_VG, mDpy);
331 default:
332 ALOGE("%s: Invalid pipe type",__FUNCTION__);
333 return ovutils::OV_INVALID;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800334 };
335 return ovutils::OV_INVALID;
336}
337
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800338bool MDPComp::isFrameDoable(hwc_context_t *ctx) {
339 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700340 bool ret = true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800341
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800342 if(!isEnabled()) {
343 ALOGD_IF(isDebug(),"%s: MDP Comp. not enabled.", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700344 ret = false;
345 } else if(ctx->mExtDispConfiguring) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800346 ALOGD_IF( isDebug(),"%s: External Display connection is pending",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800347 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700348 ret = false;
349 } else if(ctx->listStats[mDpy].needsAlphaScale
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800350 && ctx->mMDP.version < qdutils::MDSS_V5) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800351 ALOGD_IF(isDebug(), "%s: frame needs alpha downscaling",__FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700352 ret = false;
353 } else if(ctx->isPaddingRound) {
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700354 ctx->isPaddingRound = false;
355 ALOGD_IF(isDebug(), "%s: padding round",__FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700356 ret = false;
357 } else if(sIdleFallBack) {
358 sIdleFallBack = false;
359 ALOGD_IF(isDebug(), "%s: idle fallback",__FUNCTION__);
360 ret = false;
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700361 }
362
Saurabh Shahaa236822013-04-24 18:07:26 -0700363 return ret;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800364}
365
366/* Checks for conditions where all the layers marked for MDP comp cannot be
367 * bypassed. On such conditions we try to bypass atleast YUV layers */
368bool MDPComp::isFullFrameDoable(hwc_context_t *ctx,
369 hwc_display_contents_1_t* list){
370
Saurabh Shahaa236822013-04-24 18:07:26 -0700371 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800372
373 if(mDpy > HWC_DISPLAY_PRIMARY){
374 ALOGD_IF(isDebug(), "%s: Cannot support External display(s)",
375 __FUNCTION__);
376 return false;
377 }
378
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800379 if(isSkipPresent(ctx, mDpy)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700380 ALOGD_IF(isDebug(),"%s: SKIP present: %d",
381 __FUNCTION__,
382 isSkipPresent(ctx, mDpy));
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800383 return false;
384 }
385
386 //MDP composition is not efficient if layer needs rotator.
387 for(int i = 0; i < numAppLayers; ++i) {
388 // As MDP h/w supports flip operation, use MDP comp only for
389 // 180 transforms. Fail for any transform involving 90 (90, 270).
390 hwc_layer_1_t* layer = &list->hwLayers[i];
391 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800392
393 if(layer->transform & HWC_TRANSFORM_ROT_90 && !isYuvBuffer(hnd)) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800394 ALOGD_IF(isDebug(), "%s: orientation involved",__FUNCTION__);
395 return false;
396 }
397
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530398 if(!isYuvBuffer(hnd) && !isValidDimension(ctx,layer)) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800399 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",__FUNCTION__);
400 return false;
401 }
402 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700403
404 //If all above hard conditions are met we can do full or partial MDP comp.
405 bool ret = false;
406 if(fullMDPComp(ctx, list)) {
407 ret = true;
408 } else if (partialMDPComp(ctx, list)) {
409 ret = true;
410 }
411 return ret;
412}
413
414bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
415 //Setup mCurrentFrame
416 mCurrentFrame.mdpCount = mCurrentFrame.layerCount;
417 mCurrentFrame.fbCount = 0;
418 mCurrentFrame.fbZ = -1;
419 memset(&mCurrentFrame.isFBComposed, 0, sizeof(mCurrentFrame.isFBComposed));
420
421 int mdpCount = mCurrentFrame.mdpCount;
422 if(mdpCount > sMaxPipesPerMixer) {
423 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
424 return false;
425 }
426
427 int numPipesNeeded = pipesNeeded(ctx, list);
428 int availPipes = getAvailablePipes(ctx);
429
430 if(numPipesNeeded > availPipes) {
431 ALOGD_IF(isDebug(), "%s: Insufficient MDP pipes, needed %d, avail %d",
432 __FUNCTION__, numPipesNeeded, availPipes);
433 return false;
434 }
435
436 return true;
437}
438
439bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
440{
441 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
442 //Setup mCurrentFrame
443 mCurrentFrame.reset(numAppLayers);
444 updateLayerCache(ctx, list);
445 updateYUV(ctx, list);
446 batchLayers(); //sets up fbZ also
447
448 int mdpCount = mCurrentFrame.mdpCount;
449 if(mdpCount > (sMaxPipesPerMixer - 1)) { // -1 since FB is used
450 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
451 return false;
452 }
453
454 int numPipesNeeded = pipesNeeded(ctx, list);
455 int availPipes = getAvailablePipes(ctx);
456
457 if(numPipesNeeded > availPipes) {
458 ALOGD_IF(isDebug(), "%s: Insufficient MDP pipes, needed %d, avail %d",
459 __FUNCTION__, numPipesNeeded, availPipes);
460 return false;
461 }
462
463 return true;
464}
465
466bool MDPComp::isOnlyVideoDoable(hwc_context_t *ctx,
467 hwc_display_contents_1_t* list){
468 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
469 mCurrentFrame.reset(numAppLayers);
470 updateYUV(ctx, list);
471 int mdpCount = mCurrentFrame.layerCount - mCurrentFrame.fbCount;
472 int fbNeeded = int(mCurrentFrame.fbCount != 0);
473
474 if(!isYuvPresent(ctx, mDpy)) {
475 return false;
476 }
477
478 if(mdpCount > (sMaxPipesPerMixer - fbNeeded)) {
479 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
480 return false;
481 }
482
483 int numPipesNeeded = pipesNeeded(ctx, list);
484 int availPipes = getAvailablePipes(ctx);
485 if(numPipesNeeded > availPipes) {
486 ALOGD_IF(isDebug(), "%s: Insufficient MDP pipes, needed %d, avail %d",
487 __FUNCTION__, numPipesNeeded, availPipes);
488 return false;
489 }
490
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800491 return true;
492}
493
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800494/* Checks for conditions where YUV layers cannot be bypassed */
495bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800496
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800497 if(isSkipLayer(layer)) {
498 ALOGE("%s: Unable to bypass skipped YUV", __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800499 return false;
500 }
501
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800502 if(isSecuring(ctx, layer)) {
503 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
504 return false;
505 }
506
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700507 if(!qdutils::MDPVersion::getInstance().supportsDecimation()) {
508 const uint32_t downscale =
509 qdutils::MDPVersion::getInstance().getMaxMDPDownscale();
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800510 hwc_rect_t crop = layer->sourceCrop;
511 hwc_rect_t dst = layer->displayFrame;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800512 int cWidth = crop.right - crop.left;
513 int cHeight = crop.bottom - crop.top;
514 int dWidth = dst.right - dst.left;
515 int dHeight = dst.bottom - dst.top;
516
Amara Venkata Mastan Manoj Kumar6fa86722013-04-12 17:11:14 -0700517 if(layer->transform & HAL_TRANSFORM_ROT_90) {
518 swap(cWidth, cHeight);
519 }
520
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700521 if(cWidth > MAX_DISPLAY_DIM || (cWidth/dWidth) > downscale ||
522 (cHeight/dHeight) > downscale)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800523 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800524 }
525 return true;
526}
527
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800528void MDPComp::batchLayers() {
529 /* Idea is to keep as many contiguous non-updating(cached) layers in FB and
530 * send rest of them through MDP. NEVER mark an updating layer for caching.
531 * But cached ones can be marked for MDP*/
532
533 int maxBatchStart = -1;
534 int maxBatchCount = 0;
535
536 /* All or Nothing is cached. No batching needed */
Saurabh Shahaa236822013-04-24 18:07:26 -0700537 if(!mCurrentFrame.fbCount) {
538 mCurrentFrame.fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800539 return;
Saurabh Shahaa236822013-04-24 18:07:26 -0700540 }
541 if(!mCurrentFrame.mdpCount) {
542 mCurrentFrame.fbZ = 0;
543 return;
544 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800545
546 /* Search for max number of contiguous (cached) layers */
547 int i = 0;
548 while (i < mCurrentFrame.layerCount) {
549 int count = 0;
550 while(mCurrentFrame.isFBComposed[i] && i < mCurrentFrame.layerCount) {
551 count++; i++;
552 }
553 if(count > maxBatchCount) {
554 maxBatchCount = count;
555 maxBatchStart = i - count;
Saurabh Shahaa236822013-04-24 18:07:26 -0700556 mCurrentFrame.fbZ = maxBatchStart;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800557 }
558 if(i < mCurrentFrame.layerCount) i++;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800559 }
560
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800561 /* reset rest of the layers for MDP comp */
562 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
563 if(i != maxBatchStart){
564 mCurrentFrame.isFBComposed[i] = false;
565 } else {
566 i += maxBatchCount;
567 }
568 }
569
570 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700571 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
572 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800573
574 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
575 mCurrentFrame.fbCount);
576}
Saurabh Shah85234ec2013-04-12 17:09:00 -0700577
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800578void MDPComp::updateLayerCache(hwc_context_t* ctx,
579 hwc_display_contents_1_t* list) {
580
581 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
582 int numCacheableLayers = 0;
583
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800584 for(int i = 0; i < numAppLayers; i++) {
585 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
586 numCacheableLayers++;
587 mCurrentFrame.isFBComposed[i] = true;
588 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -0700589 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800590 mCachedFrame.hnd[i] = list->hwLayers[i].handle;
591 }
592 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700593
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800594 mCurrentFrame.fbCount = numCacheableLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700595 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
596 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800597 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__, numCacheableLayers);
598}
599
600int MDPComp::getAvailablePipes(hwc_context_t* ctx) {
601 int numDMAPipes = qdutils::MDPVersion::getInstance().getDMAPipes();
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800602 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800603
604 int numAvailable = ov.availablePipes(mDpy);
605
606 //Reserve DMA for rotator
Saurabh Shah85234ec2013-04-12 17:09:00 -0700607 if(Overlay::getDMAMode() == Overlay::DMA_BLOCK_MODE)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800608 numAvailable -= numDMAPipes;
609
610 //Reserve pipe(s)for FB
611 if(mCurrentFrame.fbCount)
612 numAvailable -= pipesForFB();
613
614 return numAvailable;
615}
616
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800617void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list) {
618
619 int nYuvCount = ctx->listStats[mDpy].yuvCount;
620 for(int index = 0;index < nYuvCount; index++){
621 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
622 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
623
624 if(!isYUVDoable(ctx, layer)) {
625 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
626 mCurrentFrame.isFBComposed[nYuvIndex] = true;
627 mCurrentFrame.fbCount++;
628 }
629 } else {
630 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
631 mCurrentFrame.isFBComposed[nYuvIndex] = false;
632 mCurrentFrame.fbCount--;
633 }
634 }
635 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700636
637 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
638 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800639 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
640 mCurrentFrame.fbCount);
641}
642
Saurabh Shahaa236822013-04-24 18:07:26 -0700643bool MDPComp::programMDP(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800644 if(!allocLayerPipes(ctx, list)) {
645 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700646 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800647 }
648
Saurabh Shahaa236822013-04-24 18:07:26 -0700649 bool fbBatch = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800650 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700651 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800652 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800653 int mdpIndex = mCurrentFrame.layerToMDP[index];
654 hwc_layer_1_t* layer = &list->hwLayers[index];
655
656 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
657 cur_pipe->zOrder = mdpNextZOrder++;
658
659 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
660 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
661 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -0700662 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800663 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700664 } else if(fbBatch == false) {
665 mdpNextZOrder++;
666 fbBatch = true;
667 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800668 }
669
Saurabh Shahaa236822013-04-24 18:07:26 -0700670 return true;
671}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800672
Saurabh Shahaa236822013-04-24 18:07:26 -0700673bool MDPComp::programYUV(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
674 if(!allocLayerPipes(ctx, list)) {
675 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
676 return false;
677 }
678 //If we are in this block, it means we have yuv + rgb layers both
679 int mdpIdx = 0;
680 for (int index = 0; index < mCurrentFrame.layerCount; index++) {
681 if(!mCurrentFrame.isFBComposed[index]) {
682 hwc_layer_1_t* layer = &list->hwLayers[index];
683 int mdpIndex = mCurrentFrame.layerToMDP[index];
684 MdpPipeInfo* cur_pipe =
685 mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
686 cur_pipe->zOrder = mdpIdx++;
687
688 if(configure(ctx, layer,
689 mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
690 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
691 layer %d",__FUNCTION__, index);
692 return false;
693 }
694 }
695 }
696 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800697}
698
699int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800700
701 //reset old data
Saurabh Shahaa236822013-04-24 18:07:26 -0700702 const int numLayers = ctx->listStats[mDpy].numAppLayers;
703 mCurrentFrame.reset(numLayers);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800704
Saurabh Shahaa236822013-04-24 18:07:26 -0700705 //Hard conditions, if not met, cannot do MDP comp
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800706 if(!isFrameDoable(ctx)) {
707 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
708 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700709 mCurrentFrame.reset(numLayers);
710 mCachedFrame.cacheAll(list);
711 mCachedFrame.updateCounts(mCurrentFrame);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800712 return 0;
713 }
714
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800715 //Check whether layers marked for MDP Composition is actually doable.
Saurabh Shahaa236822013-04-24 18:07:26 -0700716 if(isFullFrameDoable(ctx, list)){
717 if(mCurrentFrame.mdpCount) {
718 mCurrentFrame.map();
719 //Acquire and Program MDP pipes
720 if(!programMDP(ctx, list)) {
721 mCurrentFrame.reset(numLayers);
722 mCachedFrame.cacheAll(list);
723 }
724 }
725 } else if(isOnlyVideoDoable(ctx, list)) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800726 //All layers marked for MDP comp cannot be bypassed.
727 //Try to compose atleast YUV layers through MDP comp and let
728 //all the RGB layers compose in FB
Saurabh Shahaa236822013-04-24 18:07:26 -0700729 //Destination over
730 mCurrentFrame.fbZ = -1;
731 if(mCurrentFrame.fbCount)
732 mCurrentFrame.fbZ = ctx->listStats[mDpy].yuvCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800733
Saurabh Shahaa236822013-04-24 18:07:26 -0700734 mCurrentFrame.map();
735 if(!programYUV(ctx, list)) {
736 mCurrentFrame.reset(numLayers);
737 mCachedFrame.cacheAll(list);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800738 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700739 } else {
740 mCurrentFrame.reset(numLayers);
741 mCachedFrame.cacheAll(list);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800742 }
743
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800744 /* Any change in composition types needs an FB refresh*/
745 if(mCurrentFrame.fbCount &&
Saurabh Shahaa236822013-04-24 18:07:26 -0700746 ((mCurrentFrame.mdpCount != mCachedFrame.mdpCount) ||
747 (mCurrentFrame.fbCount != mCachedFrame.cacheCount) ||
748 (mCurrentFrame.fbZ != mCachedFrame.fbZ) ||
749 (!mCurrentFrame.mdpCount) ||
750 (list->flags & HWC_GEOMETRY_CHANGED) ||
751 isSkipPresent(ctx, mDpy) ||
752 (mDpy > HWC_DISPLAY_PRIMARY))) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800753 mCurrentFrame.needsRedraw = true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800754 }
755
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800756 //UpdateLayerFlags
757 setMDPCompLayerFlags(ctx, list);
Saurabh Shahaa236822013-04-24 18:07:26 -0700758 mCachedFrame.updateCounts(mCurrentFrame);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800759
760 if(isDebug()) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700761 ALOGD("GEOMETRY change: %d", (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800762 android::String8 sDump("");
763 dump(sDump);
764 ALOGE("%s",sDump.string());
765 }
766
767 return mCurrentFrame.fbZ;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800768}
769
770//=============MDPCompLowRes===================================================
771
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700772/*
773 * Configures pipe(s) for MDP composition
774 */
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800775int MDPCompLowRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800776 PipeLayerPair& PipeLayerPair) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800777 MdpPipeInfoLowRes& mdp_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800778 *(static_cast<MdpPipeInfoLowRes*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -0800779 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
780 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
781 eIsFg isFg = IS_FG_OFF;
782 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700783
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800784 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
785 __FUNCTION__, layer, zOrder, dest);
786
787 return configureLowRes(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
788 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700789}
790
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800791int MDPCompLowRes::pipesNeeded(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800792 hwc_display_contents_1_t* list) {
793 return mCurrentFrame.mdpCount;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700794}
795
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800796bool MDPCompLowRes::allocLayerPipes(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800797 hwc_display_contents_1_t* list) {
798 if(isYuvPresent(ctx, mDpy)) {
799 int nYuvCount = ctx->listStats[mDpy].yuvCount;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700800
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800801 for(int index = 0; index < nYuvCount ; index ++) {
802 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500803
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800804 if(mCurrentFrame.isFBComposed[nYuvIndex])
805 continue;
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800806
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800807 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800808
809 int mdpIndex = mCurrentFrame.layerToMDP[nYuvIndex];
810
811 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800812 info.pipeInfo = new MdpPipeInfoLowRes;
Saurabh Shahacf10202013-02-26 10:15:15 -0800813 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800814 MdpPipeInfoLowRes& pipe_info = *(MdpPipeInfoLowRes*)info.pipeInfo;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800815
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800816 pipe_info.index = getMdpPipe(ctx, MDPCOMP_OV_VG);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800817 if(pipe_info.index == ovutils::OV_INVALID) {
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800818 ALOGD_IF(isDebug(), "%s: Unable to get pipe for Videos",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800819 __FUNCTION__);
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800820 return false;
821 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500822 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500823 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700824
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800825 for(int index = 0 ; index < mCurrentFrame.layerCount; index++ ) {
826 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800827 hwc_layer_1_t* layer = &list->hwLayers[index];
828 private_handle_t *hnd = (private_handle_t *)layer->handle;
829
830 if(isYuvBuffer(hnd))
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500831 continue;
832
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800833 int mdpIndex = mCurrentFrame.layerToMDP[index];
834
835 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800836 info.pipeInfo = new MdpPipeInfoLowRes;
Saurabh Shahacf10202013-02-26 10:15:15 -0800837 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800838 MdpPipeInfoLowRes& pipe_info = *(MdpPipeInfoLowRes*)info.pipeInfo;
839
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800840 ePipeType type = MDPCOMP_OV_ANY;
841
Saurabh Shah85234ec2013-04-12 17:09:00 -0700842 if(!qhwc::needsScaling(layer)
843 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
844 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800845 type = MDPCOMP_OV_DMA;
846 }
847
848 pipe_info.index = getMdpPipe(ctx, type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800849 if(pipe_info.index == ovutils::OV_INVALID) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500850 ALOGD_IF(isDebug(), "%s: Unable to get pipe for UI", __FUNCTION__);
851 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700852 }
853 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700854 return true;
855}
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700856
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800857bool MDPCompLowRes::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700858
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800859 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500860 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
861 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800862 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700863
864 if(!ctx || !list) {
865 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500866 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700867 }
868
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500869 /* reset Invalidator */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800870 if(idleInvalidator && mCurrentFrame.mdpCount)
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500871 idleInvalidator->markForSleep();
872
873 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800874 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700875
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800876 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
877 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700878 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800879 if(mCurrentFrame.isFBComposed[i]) continue;
880
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700881 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -0800882 private_handle_t *hnd = (private_handle_t *)layer->handle;
883 if(!hnd) {
884 ALOGE("%s handle null", __FUNCTION__);
885 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700886 }
887
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800888 int mdpIndex = mCurrentFrame.layerToMDP[i];
889
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800890 MdpPipeInfoLowRes& pipe_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800891 *(MdpPipeInfoLowRes*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800892 ovutils::eDest dest = pipe_info.index;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800893 if(dest == ovutils::OV_INVALID) {
894 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500895 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700896 }
897
Saurabh Shahacf10202013-02-26 10:15:15 -0800898 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
899 continue;
900 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700901
Saurabh Shahacf10202013-02-26 10:15:15 -0800902 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800903 using pipe: %d", __FUNCTION__, layer,
904 hnd, dest );
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700905
Saurabh Shahacf10202013-02-26 10:15:15 -0800906 int fd = hnd->fd;
907 uint32_t offset = hnd->offset;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800908 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -0800909 if(rot) {
910 if(!rot->queueBuffer(fd, offset))
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500911 return false;
Saurabh Shahacf10202013-02-26 10:15:15 -0800912 fd = rot->getDstMemId();
913 offset = rot->getDstOffset();
914 }
915
916 if (!ov.queueBuffer(fd, offset, dest)) {
917 ALOGE("%s: queueBuffer failed for external", __FUNCTION__);
918 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700919 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500920
921 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700922 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500923 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700924}
925
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800926//=============MDPCompHighRes===================================================
927
928int MDPCompHighRes::pipesNeeded(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800929 hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800930 int pipesNeeded = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800931 int hw_w = ctx->dpyAttr[mDpy].xres;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800932
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800933 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
934 if(!mCurrentFrame.isFBComposed[i]) {
935 hwc_layer_1_t* layer = &list->hwLayers[i];
936 hwc_rect_t dst = layer->displayFrame;
937 if(dst.left > hw_w/2) {
938 pipesNeeded++;
939 } else if(dst.right <= hw_w/2) {
940 pipesNeeded++;
941 } else {
942 pipesNeeded += 2;
943 }
944 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800945 }
946 return pipesNeeded;
947}
948
949bool MDPCompHighRes::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800950 MdpPipeInfoHighRes& pipe_info,
951 ePipeType type) {
952 int hw_w = ctx->dpyAttr[mDpy].xres;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800953
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800954 hwc_rect_t dst = layer->displayFrame;
955 if(dst.left > hw_w/2) {
956 pipe_info.lIndex = ovutils::OV_INVALID;
957 pipe_info.rIndex = getMdpPipe(ctx, type);
958 if(pipe_info.rIndex == ovutils::OV_INVALID)
959 return false;
960 } else if (dst.right <= hw_w/2) {
961 pipe_info.rIndex = ovutils::OV_INVALID;
962 pipe_info.lIndex = getMdpPipe(ctx, type);
963 if(pipe_info.lIndex == ovutils::OV_INVALID)
964 return false;
965 } else {
966 pipe_info.rIndex = getMdpPipe(ctx, type);
967 pipe_info.lIndex = getMdpPipe(ctx, type);
968 if(pipe_info.rIndex == ovutils::OV_INVALID ||
969 pipe_info.lIndex == ovutils::OV_INVALID)
970 return false;
971 }
972 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800973}
974
975bool MDPCompHighRes::allocLayerPipes(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800976 hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800977 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800978 int layer_count = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800979
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800980 if(isYuvPresent(ctx, mDpy)) {
981 int nYuvCount = ctx->listStats[mDpy].yuvCount;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800982
983 for(int index = 0; index < nYuvCount; index ++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800984 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800985 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800986 PipeLayerPair& info = mCurrentFrame.mdpToLayer[nYuvIndex];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800987 info.pipeInfo = new MdpPipeInfoHighRes;
Saurabh Shah9e3adb22013-03-26 11:16:27 -0700988 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800989 MdpPipeInfoHighRes& pipe_info = *(MdpPipeInfoHighRes*)info.pipeInfo;
990 if(!acquireMDPPipes(ctx, layer, pipe_info,MDPCOMP_OV_VG)) {
991 ALOGD_IF(isDebug(),"%s: Unable to get pipe for videos",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800992 __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800993 //TODO: windback pipebook data on fail
994 return false;
995 }
996 pipe_info.zOrder = nYuvIndex;
997 }
998 }
999
1000 for(int index = 0 ; index < layer_count ; index++ ) {
1001 hwc_layer_1_t* layer = &list->hwLayers[index];
1002 private_handle_t *hnd = (private_handle_t *)layer->handle;
1003
1004 if(isYuvBuffer(hnd))
1005 continue;
1006
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001007 PipeLayerPair& info = mCurrentFrame.mdpToLayer[index];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001008 info.pipeInfo = new MdpPipeInfoHighRes;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001009 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001010 MdpPipeInfoHighRes& pipe_info = *(MdpPipeInfoHighRes*)info.pipeInfo;
1011
1012 ePipeType type = MDPCOMP_OV_ANY;
1013
Saurabh Shah85234ec2013-04-12 17:09:00 -07001014 if(!qhwc::needsScaling(layer)
1015 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
1016 && ctx->mMDP.version >= qdutils::MDSS_V5)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001017 type = MDPCOMP_OV_DMA;
1018
1019 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
1020 ALOGD_IF(isDebug(), "%s: Unable to get pipe for UI", __FUNCTION__);
1021 //TODO: windback pipebook data on fail
1022 return false;
1023 }
1024 pipe_info.zOrder = index;
1025 }
1026 return true;
1027}
1028/*
1029 * Configures pipe(s) for MDP composition
1030 */
1031int MDPCompHighRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001032 PipeLayerPair& PipeLayerPair) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001033 MdpPipeInfoHighRes& mdp_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001034 *(static_cast<MdpPipeInfoHighRes*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001035 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1036 eIsFg isFg = IS_FG_OFF;
1037 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1038 eDest lDest = mdp_info.lIndex;
1039 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001040
1041 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1042 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1043
1044 return configureHighRes(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
1045 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001046}
1047
1048bool MDPCompHighRes::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
1049
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001050 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001051 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1052 return true;
1053 }
1054
1055 if(!ctx || !list) {
1056 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001057 return false;
1058 }
1059
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001060 /* reset Invalidator */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001061 if(idleInvalidator && mCurrentFrame.mdpCount)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001062 idleInvalidator->markForSleep();
1063
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001064 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001065 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001066
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001067 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1068 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001069 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001070 if(mCurrentFrame.isFBComposed[i]) continue;
1071
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001072 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001073 private_handle_t *hnd = (private_handle_t *)layer->handle;
1074 if(!hnd) {
1075 ALOGE("%s handle null", __FUNCTION__);
1076 return false;
1077 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001078
1079 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1080 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001081 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001082
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001083 int mdpIndex = mCurrentFrame.layerToMDP[i];
1084
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001085 MdpPipeInfoHighRes& pipe_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001086 *(MdpPipeInfoHighRes*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1087 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -08001088
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001089 ovutils::eDest indexL = pipe_info.lIndex;
1090 ovutils::eDest indexR = pipe_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001091
Saurabh Shahacf10202013-02-26 10:15:15 -08001092 int fd = hnd->fd;
1093 int offset = hnd->offset;
1094
1095 if(rot) {
1096 rot->queueBuffer(fd, offset);
1097 fd = rot->getDstMemId();
1098 offset = rot->getDstOffset();
1099 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001100
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001101 //************* play left mixer **********
1102 if(indexL != ovutils::OV_INVALID) {
1103 ovutils::eDest destL = (ovutils::eDest)indexL;
Saurabh Shahacf10202013-02-26 10:15:15 -08001104 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001105 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
Saurabh Shahacf10202013-02-26 10:15:15 -08001106 if (!ov.queueBuffer(fd, offset, destL)) {
1107 ALOGE("%s: queueBuffer failed for left mixer", __FUNCTION__);
1108 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001109 }
1110 }
1111
1112 //************* play right mixer **********
1113 if(indexR != ovutils::OV_INVALID) {
1114 ovutils::eDest destR = (ovutils::eDest)indexR;
Saurabh Shahacf10202013-02-26 10:15:15 -08001115 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001116 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
Saurabh Shahacf10202013-02-26 10:15:15 -08001117 if (!ov.queueBuffer(fd, offset, destR)) {
1118 ALOGE("%s: queueBuffer failed for right mixer", __FUNCTION__);
1119 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001120 }
1121 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001122
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001123 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1124 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001125
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001126 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001127}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001128}; //namespace
1129