blob: 77234d16aea6d7c8b6d7d3ed23cfa665a497925a [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
Saurabh Shah4fdde762013-04-30 18:47:33 -070019#include <math.h>
Naseer Ahmed7c958d42012-07-31 18:57:03 -070020#include "hwc_mdpcomp.h"
Naseer Ahmed54821fe2012-11-28 18:44:38 -050021#include <sys/ioctl.h>
Saurabh Shah56f610d2012-08-07 15:27:06 -070022#include "external.h"
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -080023#include "qdMetaData.h"
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -080024#include "mdp_version.h"
Saurabh Shahacf10202013-02-26 10:15:15 -080025#include <overlayRotator.h>
26
Saurabh Shah85234ec2013-04-12 17:09:00 -070027using namespace overlay;
Saurabh Shahbd2d0832013-04-04 14:33:08 -070028using namespace qdutils;
Saurabh Shahacf10202013-02-26 10:15:15 -080029using namespace overlay::utils;
30namespace ovutils = overlay::utils;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070031
Naseer Ahmed7c958d42012-07-31 18:57:03 -070032namespace qhwc {
33
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080034//==============MDPComp========================================================
35
Naseer Ahmed7c958d42012-07-31 18:57:03 -070036IdleInvalidator *MDPComp::idleInvalidator = NULL;
37bool MDPComp::sIdleFallBack = false;
38bool MDPComp::sDebugLogs = false;
Naseer Ahmed54821fe2012-11-28 18:44:38 -050039bool MDPComp::sEnabled = false;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -070040bool MDPComp::sEnableMixedMode = true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080041int MDPComp::sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070042
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080043MDPComp* MDPComp::getObject(const int& width, int dpy) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080044 if(width <= MAX_DISPLAY_DIM) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080045 return new MDPCompLowRes(dpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080046 } else {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080047 return new MDPCompHighRes(dpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080048 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080049}
50
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080051MDPComp::MDPComp(int dpy):mDpy(dpy){};
52
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080053void MDPComp::dump(android::String8& buf)
54{
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080055 dumpsys_log(buf,"HWC Map for Dpy: %s \n",
56 mDpy ? "\"EXTERNAL\"" : "\"PRIMARY\"");
57 dumpsys_log(buf,"PREV_FRAME: layerCount:%2d mdpCount:%2d \
58 cacheCount:%2d \n", mCachedFrame.layerCount,
59 mCachedFrame.mdpCount, mCachedFrame.cacheCount);
60 dumpsys_log(buf,"CURR_FRAME: layerCount:%2d mdpCount:%2d \
61 fbCount:%2d \n", mCurrentFrame.layerCount,
62 mCurrentFrame.mdpCount, mCurrentFrame.fbCount);
63 dumpsys_log(buf,"needsFBRedraw:%3s pipesUsed:%2d MaxPipesPerMixer: %d \n",
64 (mCurrentFrame.needsRedraw? "YES" : "NO"),
65 mCurrentFrame.mdpCount, sMaxPipesPerMixer);
66 dumpsys_log(buf," --------------------------------------------- \n");
67 dumpsys_log(buf," listIdx | cached? | mdpIndex | comptype | Z \n");
68 dumpsys_log(buf," --------------------------------------------- \n");
69 for(int index = 0; index < mCurrentFrame.layerCount; index++ )
70 dumpsys_log(buf," %7d | %7s | %8d | %9s | %2d \n",
71 index,
72 (mCurrentFrame.isFBComposed[index] ? "YES" : "NO"),
73 mCurrentFrame.layerToMDP[index],
74 (mCurrentFrame.isFBComposed[index] ?
75 (mCurrentFrame.needsRedraw ? "GLES" : "CACHE") : "MDP"),
76 (mCurrentFrame.isFBComposed[index] ? mCurrentFrame.fbZ :
77 mCurrentFrame.mdpToLayer[mCurrentFrame.layerToMDP[index]].pipeInfo->zOrder));
78 dumpsys_log(buf,"\n");
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080079}
80
81bool MDPComp::init(hwc_context_t *ctx) {
82
83 if(!ctx) {
84 ALOGE("%s: Invalid hwc context!!",__FUNCTION__);
85 return false;
86 }
87
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080088 char property[PROPERTY_VALUE_MAX];
89
90 sEnabled = false;
91 if((property_get("persist.hwc.mdpcomp.enable", property, NULL) > 0) &&
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080092 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
93 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080094 sEnabled = true;
Xiaoming Zhou944e02e2013-05-01 20:54:03 -040095 if(!setupBasePipe(ctx)) {
96 ALOGE("%s: Failed to setup primary base pipe", __FUNCTION__);
97 return false;
98 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080099 }
100
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700101 sEnableMixedMode = true;
102 if((property_get("debug.mdpcomp.mixedmode.disable", property, NULL) > 0) &&
103 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
104 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
105 sEnableMixedMode = false;
106 }
107
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800108 sDebugLogs = false;
109 if(property_get("debug.mdpcomp.logs", property, NULL) > 0) {
110 if(atoi(property) != 0)
111 sDebugLogs = true;
112 }
113
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800114 sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
Saurabh Shah85234ec2013-04-12 17:09:00 -0700115 if(property_get("debug.mdpcomp.maxpermixer", property, "-1") > 0) {
116 int val = atoi(property);
117 if(val >= 0)
118 sMaxPipesPerMixer = min(val, MAX_PIPES_PER_MIXER);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800119 }
120
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800121 unsigned long idle_timeout = DEFAULT_IDLE_TIME;
122 if(property_get("debug.mdpcomp.idletime", property, NULL) > 0) {
123 if(atoi(property) != 0)
124 idle_timeout = atoi(property);
125 }
126
127 //create Idle Invalidator
128 idleInvalidator = IdleInvalidator::getInstance();
129
130 if(idleInvalidator == NULL) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800131 ALOGE("%s: failed to instantiate idleInvalidator object", __FUNCTION__);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800132 } else {
133 idleInvalidator->init(timeout_handler, ctx, idle_timeout);
134 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700135 return true;
136}
137
138void MDPComp::timeout_handler(void *udata) {
139 struct hwc_context_t* ctx = (struct hwc_context_t*)(udata);
140
141 if(!ctx) {
142 ALOGE("%s: received empty data in timer callback", __FUNCTION__);
143 return;
144 }
145
Jesse Hall3be78d92012-08-21 15:12:23 -0700146 if(!ctx->proc) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700147 ALOGE("%s: HWC proc not registered", __FUNCTION__);
148 return;
149 }
150 sIdleFallBack = true;
151 /* Trigger SF to redraw the current frame */
Jesse Hall3be78d92012-08-21 15:12:23 -0700152 ctx->proc->invalidate(ctx->proc);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700153}
154
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800155void MDPComp::setMDPCompLayerFlags(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800156 hwc_display_contents_1_t* list) {
157 LayerProp *layerProp = ctx->layerProp[mDpy];
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800158
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800159 for(int index = 0; index < ctx->listStats[mDpy].numAppLayers; index++) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800160 hwc_layer_1_t* layer = &(list->hwLayers[index]);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800161 if(!mCurrentFrame.isFBComposed[index]) {
162 layerProp[index].mFlags |= HWC_MDPCOMP;
163 layer->compositionType = HWC_OVERLAY;
164 layer->hints |= HWC_HINT_CLEAR_FB;
165 mCachedFrame.hnd[index] = NULL;
166 } else {
167 if(!mCurrentFrame.needsRedraw)
168 layer->compositionType = HWC_OVERLAY;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800169 }
170 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700171}
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500172
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800173/*
174 * Sets up BORDERFILL as default base pipe and detaches RGB0.
175 * Framebuffer is always updated using PLAY ioctl.
176 */
177bool MDPComp::setupBasePipe(hwc_context_t *ctx) {
178 const int dpy = HWC_DISPLAY_PRIMARY;
179 int fb_stride = ctx->dpyAttr[dpy].stride;
180 int fb_width = ctx->dpyAttr[dpy].xres;
181 int fb_height = ctx->dpyAttr[dpy].yres;
182 int fb_fd = ctx->dpyAttr[dpy].fd;
183
184 mdp_overlay ovInfo;
185 msmfb_overlay_data ovData;
186 memset(&ovInfo, 0, sizeof(mdp_overlay));
187 memset(&ovData, 0, sizeof(msmfb_overlay_data));
188
189 ovInfo.src.format = MDP_RGB_BORDERFILL;
190 ovInfo.src.width = fb_width;
191 ovInfo.src.height = fb_height;
192 ovInfo.src_rect.w = fb_width;
193 ovInfo.src_rect.h = fb_height;
194 ovInfo.dst_rect.w = fb_width;
195 ovInfo.dst_rect.h = fb_height;
196 ovInfo.id = MSMFB_NEW_REQUEST;
197
198 if (ioctl(fb_fd, MSMFB_OVERLAY_SET, &ovInfo) < 0) {
199 ALOGE("Failed to call ioctl MSMFB_OVERLAY_SET err=%s",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800200 strerror(errno));
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800201 return false;
202 }
203
204 ovData.id = ovInfo.id;
205 if (ioctl(fb_fd, MSMFB_OVERLAY_PLAY, &ovData) < 0) {
206 ALOGE("Failed to call ioctl MSMFB_OVERLAY_PLAY err=%s",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800207 strerror(errno));
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800208 return false;
209 }
210 return true;
211}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800212MDPComp::FrameInfo::FrameInfo() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700213 reset(0);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800214}
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800215
Saurabh Shahaa236822013-04-24 18:07:26 -0700216void MDPComp::FrameInfo::reset(const int& numLayers) {
217 for(int i = 0 ; i < MAX_PIPES_PER_MIXER && numLayers; i++ ) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800218 if(mdpToLayer[i].pipeInfo) {
219 delete mdpToLayer[i].pipeInfo;
220 mdpToLayer[i].pipeInfo = NULL;
221 //We dont own the rotator
222 mdpToLayer[i].rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800223 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800224 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800225
226 memset(&mdpToLayer, 0, sizeof(mdpToLayer));
227 memset(&layerToMDP, -1, sizeof(layerToMDP));
Saurabh Shahaa236822013-04-24 18:07:26 -0700228 memset(&isFBComposed, 1, sizeof(isFBComposed));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800229
Saurabh Shahaa236822013-04-24 18:07:26 -0700230 layerCount = numLayers;
231 fbCount = numLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800232 mdpCount = 0;
Saurabh Shah2f3895f2013-05-02 10:13:31 -0700233 needsRedraw = true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800234 fbZ = 0;
235}
236
Saurabh Shahaa236822013-04-24 18:07:26 -0700237void MDPComp::FrameInfo::map() {
238 // populate layer and MDP maps
239 int mdpIdx = 0;
240 for(int idx = 0; idx < layerCount; idx++) {
241 if(!isFBComposed[idx]) {
242 mdpToLayer[mdpIdx].listIndex = idx;
243 layerToMDP[idx] = mdpIdx++;
244 }
245 }
246}
247
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800248MDPComp::LayerCache::LayerCache() {
249 reset();
250}
251
252void MDPComp::LayerCache::reset() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700253 memset(&hnd, 0, sizeof(hnd));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800254 mdpCount = 0;
255 cacheCount = 0;
256 layerCount = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -0700257 fbZ = -1;
258}
259
260void MDPComp::LayerCache::cacheAll(hwc_display_contents_1_t* list) {
261 const int numAppLayers = list->numHwLayers - 1;
262 for(int i = 0; i < numAppLayers; i++) {
263 hnd[i] = list->hwLayers[i].handle;
264 }
265}
266
267void MDPComp::LayerCache::updateCounts(const FrameInfo& curFrame) {
268 mdpCount = curFrame.mdpCount;
269 cacheCount = curFrame.fbCount;
270 layerCount = curFrame.layerCount;
271 fbZ = curFrame.fbZ;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800272}
273
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530274bool MDPComp::isValidDimension(hwc_context_t *ctx, hwc_layer_1_t *layer) {
Saurabh Shah4fdde762013-04-30 18:47:33 -0700275 const int dpy = HWC_DISPLAY_PRIMARY;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800276 private_handle_t *hnd = (private_handle_t *)layer->handle;
277
278 if(!hnd) {
279 ALOGE("%s: layer handle is NULL", __FUNCTION__);
280 return false;
281 }
282
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800283 int hw_w = ctx->dpyAttr[mDpy].xres;
284 int hw_h = ctx->dpyAttr[mDpy].yres;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800285
Saurabh Shah4fdde762013-04-30 18:47:33 -0700286 hwc_rect_t crop = layer->sourceCrop;
287 hwc_rect_t dst = layer->displayFrame;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800288
289 if(dst.left < 0 || dst.top < 0 || dst.right > hw_w || dst.bottom > hw_h) {
Saurabh Shah4fdde762013-04-30 18:47:33 -0700290 hwc_rect_t scissor = {0, 0, hw_w, hw_h };
291 qhwc::calculate_crop_rects(crop, dst, scissor, layer->transform);
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800292 }
293
Saurabh Shah4fdde762013-04-30 18:47:33 -0700294 int crop_w = crop.right - crop.left;
295 int crop_h = crop.bottom - crop.top;
296 int dst_w = dst.right - dst.left;
297 int dst_h = dst.bottom - dst.top;
298 float w_dscale = ceilf((float)crop_w / (float)dst_w);
299 float h_dscale = ceilf((float)crop_h / (float)dst_h);
300
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800301 /* Workaround for MDP HW limitation in DSI command mode panels where
302 * FPS will not go beyond 30 if buffers on RGB pipes are of width or height
303 * less than 5 pixels
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530304 * There also is a HW limilation in MDP, minimum block size is 2x2
305 * Fallback to GPU if height is less than 2.
306 */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800307 if((crop_w < 5)||(crop_h < 5))
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800308 return false;
309
Saurabh Shah4fdde762013-04-30 18:47:33 -0700310 const uint32_t downscale =
311 qdutils::MDPVersion::getInstance().getMaxMDPDownscale();
312 if(ctx->mMDP.version >= qdutils::MDSS_V5) {
313 /* Workaround for downscales larger than 4x.
314 * Will be removed once decimator block is enabled for MDSS
315 */
316 if(!qdutils::MDPVersion::getInstance().supportsDecimation()) {
317 if(crop_w > MAX_DISPLAY_DIM || w_dscale > downscale ||
318 h_dscale > downscale)
319 return false;
320 } else {
321 if(w_dscale > 64 || h_dscale > 64)
322 return false;
323 }
324 } else { //A-family
325 if(w_dscale > downscale || h_dscale > downscale)
326 return false;
327 }
328
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800329 return true;
330}
331
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800332ovutils::eDest MDPComp::getMdpPipe(hwc_context_t *ctx, ePipeType type) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800333 overlay::Overlay& ov = *ctx->mOverlay;
334 ovutils::eDest mdp_pipe = ovutils::OV_INVALID;
335
336 switch(type) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800337 case MDPCOMP_OV_DMA:
338 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_DMA, mDpy);
339 if(mdp_pipe != ovutils::OV_INVALID) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800340 return mdp_pipe;
341 }
342 case MDPCOMP_OV_ANY:
343 case MDPCOMP_OV_RGB:
344 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy);
345 if(mdp_pipe != ovutils::OV_INVALID) {
346 return mdp_pipe;
347 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800348
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800349 if(type == MDPCOMP_OV_RGB) {
350 //Requested only for RGB pipe
351 break;
352 }
353 case MDPCOMP_OV_VG:
354 return ov.nextPipe(ovutils::OV_MDP_PIPE_VG, mDpy);
355 default:
356 ALOGE("%s: Invalid pipe type",__FUNCTION__);
357 return ovutils::OV_INVALID;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800358 };
359 return ovutils::OV_INVALID;
360}
361
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800362bool MDPComp::isFrameDoable(hwc_context_t *ctx) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700363 bool ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700364 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800365
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800366 if(!isEnabled()) {
367 ALOGD_IF(isDebug(),"%s: MDP Comp. not enabled.", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700368 ret = false;
369 } else if(ctx->mExtDispConfiguring) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800370 ALOGD_IF( isDebug(),"%s: External Display connection is pending",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800371 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700372 ret = false;
Saurabh Shahaa236822013-04-24 18:07:26 -0700373 } else if(ctx->isPaddingRound) {
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700374 ctx->isPaddingRound = false;
375 ALOGD_IF(isDebug(), "%s: padding round",__FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700376 ret = false;
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700377 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700378 return ret;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800379}
380
381/* Checks for conditions where all the layers marked for MDP comp cannot be
382 * bypassed. On such conditions we try to bypass atleast YUV layers */
383bool MDPComp::isFullFrameDoable(hwc_context_t *ctx,
384 hwc_display_contents_1_t* list){
385
Saurabh Shahaa236822013-04-24 18:07:26 -0700386 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800387
Saurabh Shah2d998a92013-05-14 17:55:58 -0700388 if(sIdleFallBack) {
389 ALOGD_IF(isDebug(), "%s: Idle fallback dpy %d",__FUNCTION__, mDpy);
390 return false;
391 }
392
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800393 if(mDpy > HWC_DISPLAY_PRIMARY){
394 ALOGD_IF(isDebug(), "%s: Cannot support External display(s)",
395 __FUNCTION__);
396 return false;
397 }
398
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800399 if(isSkipPresent(ctx, mDpy)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700400 ALOGD_IF(isDebug(),"%s: SKIP present: %d",
401 __FUNCTION__,
402 isSkipPresent(ctx, mDpy));
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800403 return false;
404 }
405
Saurabh Shah9f084ad2013-05-02 11:28:09 -0700406 if(ctx->listStats[mDpy].needsAlphaScale
407 && ctx->mMDP.version < qdutils::MDSS_V5) {
408 ALOGD_IF(isDebug(), "%s: frame needs alpha downscaling",__FUNCTION__);
409 return false;
410 }
411
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800412 //MDP composition is not efficient if layer needs rotator.
413 for(int i = 0; i < numAppLayers; ++i) {
414 // As MDP h/w supports flip operation, use MDP comp only for
415 // 180 transforms. Fail for any transform involving 90 (90, 270).
416 hwc_layer_1_t* layer = &list->hwLayers[i];
417 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800418
Saurabh Shah4fdde762013-04-30 18:47:33 -0700419 if((layer->transform & HWC_TRANSFORM_ROT_90) && !isYuvBuffer(hnd)) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800420 ALOGD_IF(isDebug(), "%s: orientation involved",__FUNCTION__);
421 return false;
422 }
423
Saurabh Shah4fdde762013-04-30 18:47:33 -0700424 if(!isValidDimension(ctx,layer)) {
425 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
426 __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800427 return false;
428 }
429 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700430
431 //If all above hard conditions are met we can do full or partial MDP comp.
432 bool ret = false;
433 if(fullMDPComp(ctx, list)) {
434 ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700435 } else if(partialMDPComp(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700436 ret = true;
437 }
438 return ret;
439}
440
441bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
442 //Setup mCurrentFrame
443 mCurrentFrame.mdpCount = mCurrentFrame.layerCount;
444 mCurrentFrame.fbCount = 0;
445 mCurrentFrame.fbZ = -1;
446 memset(&mCurrentFrame.isFBComposed, 0, sizeof(mCurrentFrame.isFBComposed));
447
448 int mdpCount = mCurrentFrame.mdpCount;
449 if(mdpCount > sMaxPipesPerMixer) {
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::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
467{
468 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700469
470 if(!sEnableMixedMode) {
471 //Mixed mode is disabled. No need to even try caching.
472 return false;
473 }
474
Saurabh Shahaa236822013-04-24 18:07:26 -0700475 //Setup mCurrentFrame
476 mCurrentFrame.reset(numAppLayers);
477 updateLayerCache(ctx, list);
478 updateYUV(ctx, list);
479 batchLayers(); //sets up fbZ also
480
481 int mdpCount = mCurrentFrame.mdpCount;
482 if(mdpCount > (sMaxPipesPerMixer - 1)) { // -1 since FB is used
483 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
484 return false;
485 }
486
487 int numPipesNeeded = pipesNeeded(ctx, list);
488 int availPipes = getAvailablePipes(ctx);
489
490 if(numPipesNeeded > availPipes) {
491 ALOGD_IF(isDebug(), "%s: Insufficient MDP pipes, needed %d, avail %d",
492 __FUNCTION__, numPipesNeeded, availPipes);
493 return false;
494 }
495
496 return true;
497}
498
499bool MDPComp::isOnlyVideoDoable(hwc_context_t *ctx,
500 hwc_display_contents_1_t* list){
501 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
502 mCurrentFrame.reset(numAppLayers);
503 updateYUV(ctx, list);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700504 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700505 int fbNeeded = int(mCurrentFrame.fbCount != 0);
506
507 if(!isYuvPresent(ctx, mDpy)) {
508 return false;
509 }
510
Saurabh Shah4fdde762013-04-30 18:47:33 -0700511 if(!mdpCount)
512 return false;
513
Saurabh Shahaa236822013-04-24 18:07:26 -0700514 if(mdpCount > (sMaxPipesPerMixer - fbNeeded)) {
515 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
516 return false;
517 }
518
519 int numPipesNeeded = pipesNeeded(ctx, list);
520 int availPipes = getAvailablePipes(ctx);
521 if(numPipesNeeded > availPipes) {
522 ALOGD_IF(isDebug(), "%s: Insufficient MDP pipes, needed %d, avail %d",
523 __FUNCTION__, numPipesNeeded, availPipes);
524 return false;
525 }
526
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800527 return true;
528}
529
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800530/* Checks for conditions where YUV layers cannot be bypassed */
531bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Saurabh Shahe2474082013-05-15 16:32:13 -0700532 bool extAnimBlockFeature = mDpy && ctx->listStats[mDpy].isDisplayAnimating;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800533
Saurabh Shahe2474082013-05-15 16:32:13 -0700534 if(isSkipLayer(layer) && !extAnimBlockFeature) {
535 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800536 return false;
537 }
538
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800539 if(isSecuring(ctx, layer)) {
540 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
541 return false;
542 }
543
Saurabh Shah4fdde762013-04-30 18:47:33 -0700544 if(!isValidDimension(ctx, layer)) {
545 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
546 __FUNCTION__);
547 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800548 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700549
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800550 return true;
551}
552
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800553void MDPComp::batchLayers() {
554 /* Idea is to keep as many contiguous non-updating(cached) layers in FB and
555 * send rest of them through MDP. NEVER mark an updating layer for caching.
556 * But cached ones can be marked for MDP*/
557
558 int maxBatchStart = -1;
559 int maxBatchCount = 0;
560
561 /* All or Nothing is cached. No batching needed */
Saurabh Shahaa236822013-04-24 18:07:26 -0700562 if(!mCurrentFrame.fbCount) {
563 mCurrentFrame.fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800564 return;
Saurabh Shahaa236822013-04-24 18:07:26 -0700565 }
566 if(!mCurrentFrame.mdpCount) {
567 mCurrentFrame.fbZ = 0;
568 return;
569 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800570
571 /* Search for max number of contiguous (cached) layers */
572 int i = 0;
573 while (i < mCurrentFrame.layerCount) {
574 int count = 0;
575 while(mCurrentFrame.isFBComposed[i] && i < mCurrentFrame.layerCount) {
576 count++; i++;
577 }
578 if(count > maxBatchCount) {
579 maxBatchCount = count;
580 maxBatchStart = i - count;
Saurabh Shahaa236822013-04-24 18:07:26 -0700581 mCurrentFrame.fbZ = maxBatchStart;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800582 }
583 if(i < mCurrentFrame.layerCount) i++;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800584 }
585
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800586 /* reset rest of the layers for MDP comp */
587 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
588 if(i != maxBatchStart){
589 mCurrentFrame.isFBComposed[i] = false;
590 } else {
591 i += maxBatchCount;
592 }
593 }
594
595 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700596 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
597 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800598
599 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
600 mCurrentFrame.fbCount);
601}
Saurabh Shah85234ec2013-04-12 17:09:00 -0700602
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800603void MDPComp::updateLayerCache(hwc_context_t* ctx,
604 hwc_display_contents_1_t* list) {
605
606 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
607 int numCacheableLayers = 0;
608
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800609 for(int i = 0; i < numAppLayers; i++) {
610 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
611 numCacheableLayers++;
612 mCurrentFrame.isFBComposed[i] = true;
613 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -0700614 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800615 mCachedFrame.hnd[i] = list->hwLayers[i].handle;
616 }
617 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700618
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800619 mCurrentFrame.fbCount = numCacheableLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700620 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
621 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800622 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__, numCacheableLayers);
623}
624
625int MDPComp::getAvailablePipes(hwc_context_t* ctx) {
626 int numDMAPipes = qdutils::MDPVersion::getInstance().getDMAPipes();
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800627 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800628
629 int numAvailable = ov.availablePipes(mDpy);
630
631 //Reserve DMA for rotator
Saurabh Shah85234ec2013-04-12 17:09:00 -0700632 if(Overlay::getDMAMode() == Overlay::DMA_BLOCK_MODE)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800633 numAvailable -= numDMAPipes;
634
635 //Reserve pipe(s)for FB
636 if(mCurrentFrame.fbCount)
637 numAvailable -= pipesForFB();
638
639 return numAvailable;
640}
641
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800642void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list) {
643
644 int nYuvCount = ctx->listStats[mDpy].yuvCount;
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700645 if(!nYuvCount && mDpy) {
646 //Reset "No animation on external display" related parameters.
647 ctx->mPrevCropVideo.left = ctx->mPrevCropVideo.top =
648 ctx->mPrevCropVideo.right = ctx->mPrevCropVideo.bottom = 0;
649 ctx->mPrevDestVideo.left = ctx->mPrevDestVideo.top =
650 ctx->mPrevDestVideo.right = ctx->mPrevDestVideo.bottom = 0;
651 ctx->mPrevTransformVideo = 0;
652 return;
653 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800654 for(int index = 0;index < nYuvCount; index++){
655 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
656 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
657
658 if(!isYUVDoable(ctx, layer)) {
659 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
660 mCurrentFrame.isFBComposed[nYuvIndex] = true;
661 mCurrentFrame.fbCount++;
662 }
663 } else {
664 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
665 mCurrentFrame.isFBComposed[nYuvIndex] = false;
666 mCurrentFrame.fbCount--;
667 }
668 }
669 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700670
671 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
672 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800673 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
674 mCurrentFrame.fbCount);
675}
676
Saurabh Shahaa236822013-04-24 18:07:26 -0700677bool MDPComp::programMDP(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800678 if(!allocLayerPipes(ctx, list)) {
679 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700680 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800681 }
682
Saurabh Shahaa236822013-04-24 18:07:26 -0700683 bool fbBatch = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800684 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700685 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800686 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800687 int mdpIndex = mCurrentFrame.layerToMDP[index];
688 hwc_layer_1_t* layer = &list->hwLayers[index];
689
690 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
691 cur_pipe->zOrder = mdpNextZOrder++;
692
693 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
694 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
695 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -0700696 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800697 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700698 } else if(fbBatch == false) {
699 mdpNextZOrder++;
700 fbBatch = true;
701 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800702 }
703
Saurabh Shahaa236822013-04-24 18:07:26 -0700704 return true;
705}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800706
Saurabh Shahaa236822013-04-24 18:07:26 -0700707bool MDPComp::programYUV(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
708 if(!allocLayerPipes(ctx, list)) {
709 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
710 return false;
711 }
712 //If we are in this block, it means we have yuv + rgb layers both
713 int mdpIdx = 0;
714 for (int index = 0; index < mCurrentFrame.layerCount; index++) {
715 if(!mCurrentFrame.isFBComposed[index]) {
716 hwc_layer_1_t* layer = &list->hwLayers[index];
717 int mdpIndex = mCurrentFrame.layerToMDP[index];
718 MdpPipeInfo* cur_pipe =
719 mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
720 cur_pipe->zOrder = mdpIdx++;
721
722 if(configure(ctx, layer,
723 mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
724 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
725 layer %d",__FUNCTION__, index);
726 return false;
727 }
728 }
729 }
730 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800731}
732
733int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800734
Saurabh Shahaa236822013-04-24 18:07:26 -0700735 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -0700736
737 //number of app layers exceeds MAX_NUM_APP_LAYERS fall back to GPU
738 //do not cache the information for next draw cycle.
739 if(numLayers > MAX_NUM_APP_LAYERS) {
740 ALOGD_IF(isDebug(), "%s: Number of App layers exceeded the limit ",
741 __FUNCTION__);
742 return 0;
743 }
744 //reset old data
Saurabh Shahaa236822013-04-24 18:07:26 -0700745 mCurrentFrame.reset(numLayers);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800746
Saurabh Shahaa236822013-04-24 18:07:26 -0700747 //Hard conditions, if not met, cannot do MDP comp
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800748 if(!isFrameDoable(ctx)) {
749 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
750 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700751 mCurrentFrame.reset(numLayers);
752 mCachedFrame.cacheAll(list);
753 mCachedFrame.updateCounts(mCurrentFrame);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800754 return 0;
755 }
756
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800757 //Check whether layers marked for MDP Composition is actually doable.
Saurabh Shahaa236822013-04-24 18:07:26 -0700758 if(isFullFrameDoable(ctx, list)){
Saurabh Shah2f3895f2013-05-02 10:13:31 -0700759 mCurrentFrame.map();
760 //Acquire and Program MDP pipes
761 if(!programMDP(ctx, list)) {
762 mCurrentFrame.reset(numLayers);
763 mCachedFrame.cacheAll(list);
764 } else { //Success
765 //Any change in composition types needs an FB refresh
766 mCurrentFrame.needsRedraw = false;
767 if(mCurrentFrame.fbCount &&
768 ((mCurrentFrame.mdpCount != mCachedFrame.mdpCount) ||
769 (mCurrentFrame.fbCount != mCachedFrame.cacheCount) ||
770 (mCurrentFrame.fbZ != mCachedFrame.fbZ) ||
771 (!mCurrentFrame.mdpCount) ||
772 (list->flags & HWC_GEOMETRY_CHANGED) ||
773 isSkipPresent(ctx, mDpy) ||
774 (mDpy > HWC_DISPLAY_PRIMARY))) {
775 mCurrentFrame.needsRedraw = true;
Saurabh Shahaa236822013-04-24 18:07:26 -0700776 }
777 }
778 } else if(isOnlyVideoDoable(ctx, list)) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800779 //All layers marked for MDP comp cannot be bypassed.
780 //Try to compose atleast YUV layers through MDP comp and let
781 //all the RGB layers compose in FB
Saurabh Shahaa236822013-04-24 18:07:26 -0700782 //Destination over
783 mCurrentFrame.fbZ = -1;
784 if(mCurrentFrame.fbCount)
Saurabh Shahe8e76272013-06-12 16:08:06 -0700785 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800786
Saurabh Shahaa236822013-04-24 18:07:26 -0700787 mCurrentFrame.map();
788 if(!programYUV(ctx, list)) {
789 mCurrentFrame.reset(numLayers);
790 mCachedFrame.cacheAll(list);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800791 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700792 } else {
793 mCurrentFrame.reset(numLayers);
794 mCachedFrame.cacheAll(list);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800795 }
796
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800797 //UpdateLayerFlags
798 setMDPCompLayerFlags(ctx, list);
Saurabh Shahaa236822013-04-24 18:07:26 -0700799 mCachedFrame.updateCounts(mCurrentFrame);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800800
801 if(isDebug()) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700802 ALOGD("GEOMETRY change: %d", (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800803 android::String8 sDump("");
804 dump(sDump);
805 ALOGE("%s",sDump.string());
806 }
807
808 return mCurrentFrame.fbZ;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800809}
810
811//=============MDPCompLowRes===================================================
812
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700813/*
814 * Configures pipe(s) for MDP composition
815 */
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800816int MDPCompLowRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800817 PipeLayerPair& PipeLayerPair) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800818 MdpPipeInfoLowRes& mdp_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800819 *(static_cast<MdpPipeInfoLowRes*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -0800820 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
821 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
822 eIsFg isFg = IS_FG_OFF;
823 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700824
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800825 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
826 __FUNCTION__, layer, zOrder, dest);
827
828 return configureLowRes(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
829 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700830}
831
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800832int MDPCompLowRes::pipesNeeded(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800833 hwc_display_contents_1_t* list) {
834 return mCurrentFrame.mdpCount;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700835}
836
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800837bool MDPCompLowRes::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700838 hwc_display_contents_1_t* list) {
839 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700840
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800841 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700842
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800843 hwc_layer_1_t* layer = &list->hwLayers[index];
844 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800845 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800846 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800847 info.pipeInfo = new MdpPipeInfoLowRes;
Saurabh Shahacf10202013-02-26 10:15:15 -0800848 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800849 MdpPipeInfoLowRes& pipe_info = *(MdpPipeInfoLowRes*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800850 ePipeType type = MDPCOMP_OV_ANY;
851
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700852 if(isYuvBuffer(hnd)) {
853 type = MDPCOMP_OV_VG;
Saurabh Shah8a117932013-05-23 12:48:13 -0700854 } else if(!qhwc::needsScaling(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -0700855 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
856 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800857 type = MDPCOMP_OV_DMA;
858 }
859
860 pipe_info.index = getMdpPipe(ctx, type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800861 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700862 ALOGD_IF(isDebug(), "%s: Unable to get pipe type = %d",
863 __FUNCTION__, (int) type);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500864 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700865 }
866 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700867 return true;
868}
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700869
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800870bool MDPCompLowRes::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700871
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800872 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500873 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
874 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800875 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700876
877 if(!ctx || !list) {
878 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500879 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700880 }
881
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500882 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -0700883 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500884 idleInvalidator->markForSleep();
885
886 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800887 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700888
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800889 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
890 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700891 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800892 if(mCurrentFrame.isFBComposed[i]) continue;
893
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700894 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -0800895 private_handle_t *hnd = (private_handle_t *)layer->handle;
896 if(!hnd) {
897 ALOGE("%s handle null", __FUNCTION__);
898 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700899 }
900
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800901 int mdpIndex = mCurrentFrame.layerToMDP[i];
902
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800903 MdpPipeInfoLowRes& pipe_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800904 *(MdpPipeInfoLowRes*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800905 ovutils::eDest dest = pipe_info.index;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800906 if(dest == ovutils::OV_INVALID) {
907 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500908 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700909 }
910
Saurabh Shahacf10202013-02-26 10:15:15 -0800911 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
912 continue;
913 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700914
Saurabh Shahacf10202013-02-26 10:15:15 -0800915 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800916 using pipe: %d", __FUNCTION__, layer,
917 hnd, dest );
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700918
Saurabh Shahacf10202013-02-26 10:15:15 -0800919 int fd = hnd->fd;
920 uint32_t offset = hnd->offset;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800921 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -0800922 if(rot) {
923 if(!rot->queueBuffer(fd, offset))
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500924 return false;
Saurabh Shahacf10202013-02-26 10:15:15 -0800925 fd = rot->getDstMemId();
926 offset = rot->getDstOffset();
927 }
928
929 if (!ov.queueBuffer(fd, offset, dest)) {
930 ALOGE("%s: queueBuffer failed for external", __FUNCTION__);
931 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700932 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500933
934 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700935 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500936 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700937}
938
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800939//=============MDPCompHighRes===================================================
940
941int MDPCompHighRes::pipesNeeded(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800942 hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800943 int pipesNeeded = 0;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800944 int hw_w = ctx->dpyAttr[mDpy].xres;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800945
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800946 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
947 if(!mCurrentFrame.isFBComposed[i]) {
948 hwc_layer_1_t* layer = &list->hwLayers[i];
949 hwc_rect_t dst = layer->displayFrame;
950 if(dst.left > hw_w/2) {
951 pipesNeeded++;
952 } else if(dst.right <= hw_w/2) {
953 pipesNeeded++;
954 } else {
955 pipesNeeded += 2;
956 }
957 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800958 }
959 return pipesNeeded;
960}
961
962bool MDPCompHighRes::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800963 MdpPipeInfoHighRes& pipe_info,
964 ePipeType type) {
965 int hw_w = ctx->dpyAttr[mDpy].xres;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800966
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800967 hwc_rect_t dst = layer->displayFrame;
968 if(dst.left > hw_w/2) {
969 pipe_info.lIndex = ovutils::OV_INVALID;
970 pipe_info.rIndex = getMdpPipe(ctx, type);
971 if(pipe_info.rIndex == ovutils::OV_INVALID)
972 return false;
973 } else if (dst.right <= hw_w/2) {
974 pipe_info.rIndex = ovutils::OV_INVALID;
975 pipe_info.lIndex = getMdpPipe(ctx, type);
976 if(pipe_info.lIndex == ovutils::OV_INVALID)
977 return false;
978 } else {
979 pipe_info.rIndex = getMdpPipe(ctx, type);
980 pipe_info.lIndex = getMdpPipe(ctx, type);
981 if(pipe_info.rIndex == ovutils::OV_INVALID ||
982 pipe_info.lIndex == ovutils::OV_INVALID)
983 return false;
984 }
985 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800986}
987
988bool MDPCompHighRes::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700989 hwc_display_contents_1_t* list) {
990 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800991
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700992 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800993
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800994 hwc_layer_1_t* layer = &list->hwLayers[index];
995 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shah0d65dbe2013-06-06 18:33:16 -0700996 int mdpIndex = mCurrentFrame.layerToMDP[index];
997 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800998 info.pipeInfo = new MdpPipeInfoHighRes;
Saurabh Shah9e3adb22013-03-26 11:16:27 -0700999 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001000 MdpPipeInfoHighRes& pipe_info = *(MdpPipeInfoHighRes*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001001 ePipeType type = MDPCOMP_OV_ANY;
1002
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001003 if(isYuvBuffer(hnd)) {
1004 type = MDPCOMP_OV_VG;
Saurabh Shah8a117932013-05-23 12:48:13 -07001005 } else if(!qhwc::needsScaling(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001006 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001007 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001008 type = MDPCOMP_OV_DMA;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001009 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001010
1011 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001012 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type = %d",
1013 __FUNCTION__, (int) type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001014 return false;
1015 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001016 }
1017 return true;
1018}
1019/*
1020 * Configures pipe(s) for MDP composition
1021 */
1022int MDPCompHighRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001023 PipeLayerPair& PipeLayerPair) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001024 MdpPipeInfoHighRes& mdp_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001025 *(static_cast<MdpPipeInfoHighRes*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001026 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1027 eIsFg isFg = IS_FG_OFF;
1028 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1029 eDest lDest = mdp_info.lIndex;
1030 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001031
1032 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1033 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1034
1035 return configureHighRes(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
1036 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001037}
1038
1039bool MDPCompHighRes::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
1040
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001041 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001042 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1043 return true;
1044 }
1045
1046 if(!ctx || !list) {
1047 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001048 return false;
1049 }
1050
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001051 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001052 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001053 idleInvalidator->markForSleep();
1054
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001055 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001056 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001057
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001058 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1059 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001060 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001061 if(mCurrentFrame.isFBComposed[i]) continue;
1062
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001063 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001064 private_handle_t *hnd = (private_handle_t *)layer->handle;
1065 if(!hnd) {
1066 ALOGE("%s handle null", __FUNCTION__);
1067 return false;
1068 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001069
1070 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1071 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001072 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001073
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001074 int mdpIndex = mCurrentFrame.layerToMDP[i];
1075
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001076 MdpPipeInfoHighRes& pipe_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001077 *(MdpPipeInfoHighRes*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1078 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -08001079
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001080 ovutils::eDest indexL = pipe_info.lIndex;
1081 ovutils::eDest indexR = pipe_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001082
Saurabh Shahacf10202013-02-26 10:15:15 -08001083 int fd = hnd->fd;
1084 int offset = hnd->offset;
1085
1086 if(rot) {
1087 rot->queueBuffer(fd, offset);
1088 fd = rot->getDstMemId();
1089 offset = rot->getDstOffset();
1090 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001091
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001092 //************* play left mixer **********
1093 if(indexL != ovutils::OV_INVALID) {
1094 ovutils::eDest destL = (ovutils::eDest)indexL;
Saurabh Shahacf10202013-02-26 10:15:15 -08001095 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001096 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
Saurabh Shahacf10202013-02-26 10:15:15 -08001097 if (!ov.queueBuffer(fd, offset, destL)) {
1098 ALOGE("%s: queueBuffer failed for left mixer", __FUNCTION__);
1099 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001100 }
1101 }
1102
1103 //************* play right mixer **********
1104 if(indexR != ovutils::OV_INVALID) {
1105 ovutils::eDest destR = (ovutils::eDest)indexR;
Saurabh Shahacf10202013-02-26 10:15:15 -08001106 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001107 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
Saurabh Shahacf10202013-02-26 10:15:15 -08001108 if (!ov.queueBuffer(fd, offset, destR)) {
1109 ALOGE("%s: queueBuffer failed for right mixer", __FUNCTION__);
1110 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001111 }
1112 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001113
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001114 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1115 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001116
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001117 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001118}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001119}; //namespace
1120