blob: 3e983f3861a722f1900bc43fab31f2f71446707b [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"
Jeykumar Sankaran27dee262013-08-01 17:09:54 -070023#include "virtual.h"
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -080024#include "qdMetaData.h"
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -080025#include "mdp_version.h"
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -070026#include "hwc_fbupdate.h"
Saurabh Shaha9da08f2013-07-03 13:27:53 -070027#include "hwc_ad.h"
Saurabh Shahacf10202013-02-26 10:15:15 -080028#include <overlayRotator.h>
29
Saurabh Shah85234ec2013-04-12 17:09:00 -070030using namespace overlay;
Saurabh Shahbd2d0832013-04-04 14:33:08 -070031using namespace qdutils;
Saurabh Shahacf10202013-02-26 10:15:15 -080032using namespace overlay::utils;
33namespace ovutils = overlay::utils;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070034
Naseer Ahmed7c958d42012-07-31 18:57:03 -070035namespace qhwc {
36
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080037//==============MDPComp========================================================
38
Naseer Ahmed7c958d42012-07-31 18:57:03 -070039IdleInvalidator *MDPComp::idleInvalidator = NULL;
40bool MDPComp::sIdleFallBack = false;
41bool MDPComp::sDebugLogs = false;
Naseer Ahmed54821fe2012-11-28 18:44:38 -050042bool MDPComp::sEnabled = false;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -070043bool MDPComp::sEnableMixedMode = true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080044int MDPComp::sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
Saurabh Shah8c5c8522013-08-29 17:32:49 -070045float MDPComp::sMaxBw = 2.3f;
46uint32_t MDPComp::sCompBytesClaimed = 0;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070047
Saurabh Shah88e4d272013-09-03 13:31:29 -070048MDPComp* MDPComp::getObject(hwc_context_t *ctx, const int& dpy) {
49 if(isDisplaySplit(ctx, dpy)) {
50 return new MDPCompSplit(dpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080051 }
Saurabh Shah88e4d272013-09-03 13:31:29 -070052 return new MDPCompNonSplit(dpy);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080053}
54
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080055MDPComp::MDPComp(int dpy):mDpy(dpy){};
56
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080057void MDPComp::dump(android::String8& buf)
58{
Jeykumar Sankaran3c6bb042013-08-15 14:01:04 -070059 if(mCurrentFrame.layerCount > MAX_NUM_APP_LAYERS)
60 return;
61
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080062 dumpsys_log(buf,"HWC Map for Dpy: %s \n",
Jeykumar Sankaran27dee262013-08-01 17:09:54 -070063 (mDpy == 0) ? "\"PRIMARY\"" :
64 (mDpy == 1) ? "\"EXTERNAL\"" : "\"VIRTUAL\"");
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080065 dumpsys_log(buf,"PREV_FRAME: layerCount:%2d mdpCount:%2d \
66 cacheCount:%2d \n", mCachedFrame.layerCount,
67 mCachedFrame.mdpCount, mCachedFrame.cacheCount);
68 dumpsys_log(buf,"CURR_FRAME: layerCount:%2d mdpCount:%2d \
69 fbCount:%2d \n", mCurrentFrame.layerCount,
70 mCurrentFrame.mdpCount, mCurrentFrame.fbCount);
71 dumpsys_log(buf,"needsFBRedraw:%3s pipesUsed:%2d MaxPipesPerMixer: %d \n",
72 (mCurrentFrame.needsRedraw? "YES" : "NO"),
73 mCurrentFrame.mdpCount, sMaxPipesPerMixer);
74 dumpsys_log(buf," --------------------------------------------- \n");
75 dumpsys_log(buf," listIdx | cached? | mdpIndex | comptype | Z \n");
76 dumpsys_log(buf," --------------------------------------------- \n");
77 for(int index = 0; index < mCurrentFrame.layerCount; index++ )
78 dumpsys_log(buf," %7d | %7s | %8d | %9s | %2d \n",
79 index,
80 (mCurrentFrame.isFBComposed[index] ? "YES" : "NO"),
81 mCurrentFrame.layerToMDP[index],
82 (mCurrentFrame.isFBComposed[index] ?
83 (mCurrentFrame.needsRedraw ? "GLES" : "CACHE") : "MDP"),
84 (mCurrentFrame.isFBComposed[index] ? mCurrentFrame.fbZ :
85 mCurrentFrame.mdpToLayer[mCurrentFrame.layerToMDP[index]].pipeInfo->zOrder));
86 dumpsys_log(buf,"\n");
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080087}
88
89bool MDPComp::init(hwc_context_t *ctx) {
90
91 if(!ctx) {
92 ALOGE("%s: Invalid hwc context!!",__FUNCTION__);
93 return false;
94 }
95
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080096 char property[PROPERTY_VALUE_MAX];
97
98 sEnabled = false;
99 if((property_get("persist.hwc.mdpcomp.enable", property, NULL) > 0) &&
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800100 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
101 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800102 sEnabled = true;
Xiaoming Zhou944e02e2013-05-01 20:54:03 -0400103 if(!setupBasePipe(ctx)) {
104 ALOGE("%s: Failed to setup primary base pipe", __FUNCTION__);
105 return false;
106 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800107 }
108
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700109 sEnableMixedMode = true;
110 if((property_get("debug.mdpcomp.mixedmode.disable", property, NULL) > 0) &&
111 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
112 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
113 sEnableMixedMode = false;
114 }
115
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800116 sDebugLogs = false;
117 if(property_get("debug.mdpcomp.logs", property, NULL) > 0) {
118 if(atoi(property) != 0)
119 sDebugLogs = true;
120 }
121
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800122 sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
Saurabh Shah85234ec2013-04-12 17:09:00 -0700123 if(property_get("debug.mdpcomp.maxpermixer", property, "-1") > 0) {
124 int val = atoi(property);
125 if(val >= 0)
126 sMaxPipesPerMixer = min(val, MAX_PIPES_PER_MIXER);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800127 }
128
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700129 if(property_get("debug.mdpcomp.bw", property, "0") > 0) {
130 float val = atof(property);
131 if(val > 0.0f) {
132 sMaxBw = val;
133 }
134 }
135
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400136 if(ctx->mMDP.panel != MIPI_CMD_PANEL) {
137 // Idle invalidation is not necessary on command mode panels
138 long idle_timeout = DEFAULT_IDLE_TIME;
139 if(property_get("debug.mdpcomp.idletime", property, NULL) > 0) {
140 if(atoi(property) != 0)
141 idle_timeout = atoi(property);
142 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800143
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400144 //create Idle Invalidator only when not disabled through property
145 if(idle_timeout != -1)
146 idleInvalidator = IdleInvalidator::getInstance();
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800147
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400148 if(idleInvalidator == NULL) {
149 ALOGE("%s: failed to instantiate idleInvalidator object",
150 __FUNCTION__);
151 } else {
152 idleInvalidator->init(timeout_handler, ctx, idle_timeout);
153 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800154 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700155 return true;
156}
157
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700158void MDPComp::reset(const int& numLayers, hwc_display_contents_1_t* list) {
159 mCurrentFrame.reset(numLayers);
160 mCachedFrame.cacheAll(list);
161 mCachedFrame.updateCounts(mCurrentFrame);
162}
163
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700164void MDPComp::timeout_handler(void *udata) {
165 struct hwc_context_t* ctx = (struct hwc_context_t*)(udata);
166
167 if(!ctx) {
168 ALOGE("%s: received empty data in timer callback", __FUNCTION__);
169 return;
170 }
171
Jesse Hall3be78d92012-08-21 15:12:23 -0700172 if(!ctx->proc) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700173 ALOGE("%s: HWC proc not registered", __FUNCTION__);
174 return;
175 }
176 sIdleFallBack = true;
177 /* Trigger SF to redraw the current frame */
Jesse Hall3be78d92012-08-21 15:12:23 -0700178 ctx->proc->invalidate(ctx->proc);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700179}
180
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800181void MDPComp::setMDPCompLayerFlags(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800182 hwc_display_contents_1_t* list) {
183 LayerProp *layerProp = ctx->layerProp[mDpy];
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800184
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800185 for(int index = 0; index < ctx->listStats[mDpy].numAppLayers; index++) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800186 hwc_layer_1_t* layer = &(list->hwLayers[index]);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800187 if(!mCurrentFrame.isFBComposed[index]) {
188 layerProp[index].mFlags |= HWC_MDPCOMP;
189 layer->compositionType = HWC_OVERLAY;
190 layer->hints |= HWC_HINT_CLEAR_FB;
191 mCachedFrame.hnd[index] = NULL;
192 } else {
193 if(!mCurrentFrame.needsRedraw)
194 layer->compositionType = HWC_OVERLAY;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800195 }
196 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700197}
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500198
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800199/*
200 * Sets up BORDERFILL as default base pipe and detaches RGB0.
201 * Framebuffer is always updated using PLAY ioctl.
202 */
203bool MDPComp::setupBasePipe(hwc_context_t *ctx) {
204 const int dpy = HWC_DISPLAY_PRIMARY;
205 int fb_stride = ctx->dpyAttr[dpy].stride;
206 int fb_width = ctx->dpyAttr[dpy].xres;
207 int fb_height = ctx->dpyAttr[dpy].yres;
208 int fb_fd = ctx->dpyAttr[dpy].fd;
209
210 mdp_overlay ovInfo;
211 msmfb_overlay_data ovData;
212 memset(&ovInfo, 0, sizeof(mdp_overlay));
213 memset(&ovData, 0, sizeof(msmfb_overlay_data));
214
215 ovInfo.src.format = MDP_RGB_BORDERFILL;
216 ovInfo.src.width = fb_width;
217 ovInfo.src.height = fb_height;
218 ovInfo.src_rect.w = fb_width;
219 ovInfo.src_rect.h = fb_height;
220 ovInfo.dst_rect.w = fb_width;
221 ovInfo.dst_rect.h = fb_height;
222 ovInfo.id = MSMFB_NEW_REQUEST;
223
224 if (ioctl(fb_fd, MSMFB_OVERLAY_SET, &ovInfo) < 0) {
225 ALOGE("Failed to call ioctl MSMFB_OVERLAY_SET err=%s",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800226 strerror(errno));
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800227 return false;
228 }
229
230 ovData.id = ovInfo.id;
231 if (ioctl(fb_fd, MSMFB_OVERLAY_PLAY, &ovData) < 0) {
232 ALOGE("Failed to call ioctl MSMFB_OVERLAY_PLAY err=%s",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800233 strerror(errno));
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800234 return false;
235 }
236 return true;
237}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800238MDPComp::FrameInfo::FrameInfo() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700239 reset(0);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800240}
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800241
Saurabh Shahaa236822013-04-24 18:07:26 -0700242void MDPComp::FrameInfo::reset(const int& numLayers) {
243 for(int i = 0 ; i < MAX_PIPES_PER_MIXER && numLayers; i++ ) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800244 if(mdpToLayer[i].pipeInfo) {
245 delete mdpToLayer[i].pipeInfo;
246 mdpToLayer[i].pipeInfo = NULL;
247 //We dont own the rotator
248 mdpToLayer[i].rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800249 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800250 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800251
252 memset(&mdpToLayer, 0, sizeof(mdpToLayer));
253 memset(&layerToMDP, -1, sizeof(layerToMDP));
Saurabh Shahaa236822013-04-24 18:07:26 -0700254 memset(&isFBComposed, 1, sizeof(isFBComposed));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800255
Saurabh Shahaa236822013-04-24 18:07:26 -0700256 layerCount = numLayers;
257 fbCount = numLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800258 mdpCount = 0;
Saurabh Shah2f3895f2013-05-02 10:13:31 -0700259 needsRedraw = true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800260 fbZ = 0;
261}
262
Saurabh Shahaa236822013-04-24 18:07:26 -0700263void MDPComp::FrameInfo::map() {
264 // populate layer and MDP maps
265 int mdpIdx = 0;
266 for(int idx = 0; idx < layerCount; idx++) {
267 if(!isFBComposed[idx]) {
268 mdpToLayer[mdpIdx].listIndex = idx;
269 layerToMDP[idx] = mdpIdx++;
270 }
271 }
272}
273
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800274MDPComp::LayerCache::LayerCache() {
275 reset();
276}
277
278void MDPComp::LayerCache::reset() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700279 memset(&hnd, 0, sizeof(hnd));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800280 mdpCount = 0;
281 cacheCount = 0;
282 layerCount = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -0700283 fbZ = -1;
284}
285
286void MDPComp::LayerCache::cacheAll(hwc_display_contents_1_t* list) {
287 const int numAppLayers = list->numHwLayers - 1;
288 for(int i = 0; i < numAppLayers; i++) {
289 hnd[i] = list->hwLayers[i].handle;
290 }
291}
292
293void MDPComp::LayerCache::updateCounts(const FrameInfo& curFrame) {
294 mdpCount = curFrame.mdpCount;
295 cacheCount = curFrame.fbCount;
296 layerCount = curFrame.layerCount;
297 fbZ = curFrame.fbZ;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800298}
299
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530300bool MDPComp::isValidDimension(hwc_context_t *ctx, hwc_layer_1_t *layer) {
Saurabh Shah4fdde762013-04-30 18:47:33 -0700301 const int dpy = HWC_DISPLAY_PRIMARY;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800302 private_handle_t *hnd = (private_handle_t *)layer->handle;
303
304 if(!hnd) {
305 ALOGE("%s: layer handle is NULL", __FUNCTION__);
306 return false;
307 }
308
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800309 int hw_w = ctx->dpyAttr[mDpy].xres;
310 int hw_h = ctx->dpyAttr[mDpy].yres;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800311
Saurabh Shah4fdde762013-04-30 18:47:33 -0700312 hwc_rect_t crop = layer->sourceCrop;
313 hwc_rect_t dst = layer->displayFrame;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800314
315 if(dst.left < 0 || dst.top < 0 || dst.right > hw_w || dst.bottom > hw_h) {
Saurabh Shah4fdde762013-04-30 18:47:33 -0700316 hwc_rect_t scissor = {0, 0, hw_w, hw_h };
317 qhwc::calculate_crop_rects(crop, dst, scissor, layer->transform);
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800318 }
319
Saurabh Shah4fdde762013-04-30 18:47:33 -0700320 int crop_w = crop.right - crop.left;
321 int crop_h = crop.bottom - crop.top;
322 int dst_w = dst.right - dst.left;
323 int dst_h = dst.bottom - dst.top;
324 float w_dscale = ceilf((float)crop_w / (float)dst_w);
325 float h_dscale = ceilf((float)crop_h / (float)dst_h);
326
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800327 /* Workaround for MDP HW limitation in DSI command mode panels where
328 * FPS will not go beyond 30 if buffers on RGB pipes are of width or height
329 * less than 5 pixels
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530330 * There also is a HW limilation in MDP, minimum block size is 2x2
331 * Fallback to GPU if height is less than 2.
332 */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800333 if((crop_w < 5)||(crop_h < 5))
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800334 return false;
335
Saurabh Shah4fdde762013-04-30 18:47:33 -0700336 const uint32_t downscale =
337 qdutils::MDPVersion::getInstance().getMaxMDPDownscale();
338 if(ctx->mMDP.version >= qdutils::MDSS_V5) {
339 /* Workaround for downscales larger than 4x.
340 * Will be removed once decimator block is enabled for MDSS
341 */
342 if(!qdutils::MDPVersion::getInstance().supportsDecimation()) {
343 if(crop_w > MAX_DISPLAY_DIM || w_dscale > downscale ||
344 h_dscale > downscale)
345 return false;
346 } else {
347 if(w_dscale > 64 || h_dscale > 64)
348 return false;
349 }
350 } else { //A-family
351 if(w_dscale > downscale || h_dscale > downscale)
352 return false;
353 }
354
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800355 return true;
356}
357
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700358ovutils::eDest MDPComp::getMdpPipe(hwc_context_t *ctx, ePipeType type,
359 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800360 overlay::Overlay& ov = *ctx->mOverlay;
361 ovutils::eDest mdp_pipe = ovutils::OV_INVALID;
362
363 switch(type) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800364 case MDPCOMP_OV_DMA:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700365 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_DMA, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800366 if(mdp_pipe != ovutils::OV_INVALID) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800367 return mdp_pipe;
368 }
369 case MDPCOMP_OV_ANY:
370 case MDPCOMP_OV_RGB:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700371 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800372 if(mdp_pipe != ovutils::OV_INVALID) {
373 return mdp_pipe;
374 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800375
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800376 if(type == MDPCOMP_OV_RGB) {
377 //Requested only for RGB pipe
378 break;
379 }
380 case MDPCOMP_OV_VG:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700381 return ov.nextPipe(ovutils::OV_MDP_PIPE_VG, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800382 default:
383 ALOGE("%s: Invalid pipe type",__FUNCTION__);
384 return ovutils::OV_INVALID;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800385 };
386 return ovutils::OV_INVALID;
387}
388
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800389bool MDPComp::isFrameDoable(hwc_context_t *ctx) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700390 bool ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700391 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800392
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800393 if(!isEnabled()) {
394 ALOGD_IF(isDebug(),"%s: MDP Comp. not enabled.", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700395 ret = false;
Saurabh Shahd4e65852013-06-17 11:33:53 -0700396 } else if(qdutils::MDPVersion::getInstance().is8x26() &&
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700397 ctx->mVideoTransFlag && ctx->mVirtualDisplay->isConnected()) {
Saurabh Shahd4e65852013-06-17 11:33:53 -0700398 //1 Padding round to shift pipes across mixers
399 ALOGD_IF(isDebug(),"%s: MDP Comp. video transition padding round",
400 __FUNCTION__);
401 ret = false;
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700402 } else if(ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isConfiguring ||
403 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isConfiguring) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800404 ALOGD_IF( isDebug(),"%s: External Display connection is pending",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800405 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700406 ret = false;
Saurabh Shahaa236822013-04-24 18:07:26 -0700407 } else if(ctx->isPaddingRound) {
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700408 ctx->isPaddingRound = false;
409 ALOGD_IF(isDebug(), "%s: padding round",__FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700410 ret = false;
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700411 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700412 return ret;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800413}
414
415/* Checks for conditions where all the layers marked for MDP comp cannot be
416 * bypassed. On such conditions we try to bypass atleast YUV layers */
417bool MDPComp::isFullFrameDoable(hwc_context_t *ctx,
418 hwc_display_contents_1_t* list){
419
Saurabh Shahaa236822013-04-24 18:07:26 -0700420 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800421
Saurabh Shah2d998a92013-05-14 17:55:58 -0700422 if(sIdleFallBack) {
423 ALOGD_IF(isDebug(), "%s: Idle fallback dpy %d",__FUNCTION__, mDpy);
424 return false;
425 }
426
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800427 if(mDpy > HWC_DISPLAY_PRIMARY){
428 ALOGD_IF(isDebug(), "%s: Cannot support External display(s)",
429 __FUNCTION__);
430 return false;
431 }
432
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800433 if(isSkipPresent(ctx, mDpy)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700434 ALOGD_IF(isDebug(),"%s: SKIP present: %d",
435 __FUNCTION__,
436 isSkipPresent(ctx, mDpy));
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800437 return false;
438 }
439
Saurabh Shah9f084ad2013-05-02 11:28:09 -0700440 if(ctx->listStats[mDpy].needsAlphaScale
441 && ctx->mMDP.version < qdutils::MDSS_V5) {
442 ALOGD_IF(isDebug(), "%s: frame needs alpha downscaling",__FUNCTION__);
443 return false;
444 }
445
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800446 //MDP composition is not efficient if layer needs rotator.
447 for(int i = 0; i < numAppLayers; ++i) {
448 // As MDP h/w supports flip operation, use MDP comp only for
449 // 180 transforms. Fail for any transform involving 90 (90, 270).
450 hwc_layer_1_t* layer = &list->hwLayers[i];
451 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800452
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700453 if(layer->transform & HWC_TRANSFORM_ROT_90) {
454 if(!isYuvBuffer(hnd) ) {
455 ALOGD_IF(isDebug(), "%s: orientation involved",__FUNCTION__);
456 return false;
457 }else if(!canUseRotator(ctx, mDpy)) {
458 ALOGD_IF(isDebug(), "%s: no free DMA pipe",__FUNCTION__);
459 return false;
460 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800461 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700462 if(!isValidDimension(ctx,layer)) {
463 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
464 __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800465 return false;
466 }
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530467
468 //For 8x26 with panel width>1k, if RGB layer needs HFLIP fail mdp comp
469 // may not need it if Gfx pre-rotation can handle all flips & rotations
470 if(qdutils::MDPVersion::getInstance().is8x26() &&
471 (ctx->dpyAttr[mDpy].xres > 1024) &&
472 (layer->transform & HWC_TRANSFORM_FLIP_H) &&
473 (!isYuvBuffer(hnd)))
474 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800475 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700476
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700477 if(ctx->mAD->isDoable()) {
478 return false;
479 }
480
Saurabh Shahaa236822013-04-24 18:07:26 -0700481 //If all above hard conditions are met we can do full or partial MDP comp.
482 bool ret = false;
483 if(fullMDPComp(ctx, list)) {
484 ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700485 } else if(partialMDPComp(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700486 ret = true;
487 }
488 return ret;
489}
490
491bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
492 //Setup mCurrentFrame
493 mCurrentFrame.mdpCount = mCurrentFrame.layerCount;
494 mCurrentFrame.fbCount = 0;
495 mCurrentFrame.fbZ = -1;
496 memset(&mCurrentFrame.isFBComposed, 0, sizeof(mCurrentFrame.isFBComposed));
497
498 int mdpCount = mCurrentFrame.mdpCount;
499 if(mdpCount > sMaxPipesPerMixer) {
500 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
501 return false;
502 }
503
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700504 if(!arePipesAvailable(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700505 return false;
506 }
507
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700508 uint32_t size = calcMDPBytesRead(ctx, list);
509 if(!bandwidthCheck(ctx, size)) {
510 ALOGD_IF(isDebug(), "%s: Exceeds bandwidth",__FUNCTION__);
511 return false;
512 }
513
Saurabh Shahaa236822013-04-24 18:07:26 -0700514 return true;
515}
516
517bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
518{
519 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700520
521 if(!sEnableMixedMode) {
522 //Mixed mode is disabled. No need to even try caching.
523 return false;
524 }
525
Saurabh Shahaa236822013-04-24 18:07:26 -0700526 //Setup mCurrentFrame
527 mCurrentFrame.reset(numAppLayers);
528 updateLayerCache(ctx, list);
529 updateYUV(ctx, list);
530 batchLayers(); //sets up fbZ also
531
532 int mdpCount = mCurrentFrame.mdpCount;
533 if(mdpCount > (sMaxPipesPerMixer - 1)) { // -1 since FB is used
534 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
535 return false;
536 }
537
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700538 if(!arePipesAvailable(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700539 return false;
540 }
541
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700542 uint32_t size = calcMDPBytesRead(ctx, list);
543 if(!bandwidthCheck(ctx, size)) {
544 ALOGD_IF(isDebug(), "%s: Exceeds bandwidth",__FUNCTION__);
545 return false;
546 }
547
Saurabh Shahaa236822013-04-24 18:07:26 -0700548 return true;
549}
550
551bool MDPComp::isOnlyVideoDoable(hwc_context_t *ctx,
552 hwc_display_contents_1_t* list){
553 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
554 mCurrentFrame.reset(numAppLayers);
555 updateYUV(ctx, list);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700556 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700557 int fbNeeded = int(mCurrentFrame.fbCount != 0);
558
559 if(!isYuvPresent(ctx, mDpy)) {
560 return false;
561 }
562
Saurabh Shah4fdde762013-04-30 18:47:33 -0700563 if(!mdpCount)
564 return false;
565
Saurabh Shahaa236822013-04-24 18:07:26 -0700566 if(mdpCount > (sMaxPipesPerMixer - fbNeeded)) {
567 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
568 return false;
569 }
570
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700571 if(!arePipesAvailable(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700572 return false;
573 }
574
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700575 uint32_t size = calcMDPBytesRead(ctx, list);
576 if(!bandwidthCheck(ctx, size)) {
577 ALOGD_IF(isDebug(), "%s: Exceeds bandwidth",__FUNCTION__);
578 return false;
579 }
580
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800581 return true;
582}
583
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800584/* Checks for conditions where YUV layers cannot be bypassed */
585bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Saurabh Shahe2474082013-05-15 16:32:13 -0700586 bool extAnimBlockFeature = mDpy && ctx->listStats[mDpy].isDisplayAnimating;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800587
Saurabh Shahe2474082013-05-15 16:32:13 -0700588 if(isSkipLayer(layer) && !extAnimBlockFeature) {
589 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800590 return false;
591 }
592
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700593 if(layer->transform & HWC_TRANSFORM_ROT_90 && !canUseRotator(ctx,mDpy)) {
594 ALOGD_IF(isDebug(), "%s: no free DMA pipe",__FUNCTION__);
595 return false;
596 }
597
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800598 if(isSecuring(ctx, layer)) {
599 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
600 return false;
601 }
602
Saurabh Shah4fdde762013-04-30 18:47:33 -0700603 if(!isValidDimension(ctx, layer)) {
604 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
605 __FUNCTION__);
606 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800607 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700608
Naseer Ahmeddc61a972013-07-10 17:50:54 -0400609 if(layer->planeAlpha < 0xFF) {
610 ALOGD_IF(isDebug(), "%s: Cannot handle YUV layer with plane alpha\
611 in video only mode",
612 __FUNCTION__);
613 return false;
614 }
615
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800616 return true;
617}
618
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800619void MDPComp::batchLayers() {
620 /* Idea is to keep as many contiguous non-updating(cached) layers in FB and
621 * send rest of them through MDP. NEVER mark an updating layer for caching.
622 * But cached ones can be marked for MDP*/
623
624 int maxBatchStart = -1;
625 int maxBatchCount = 0;
626
627 /* All or Nothing is cached. No batching needed */
Saurabh Shahaa236822013-04-24 18:07:26 -0700628 if(!mCurrentFrame.fbCount) {
629 mCurrentFrame.fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800630 return;
Saurabh Shahaa236822013-04-24 18:07:26 -0700631 }
632 if(!mCurrentFrame.mdpCount) {
633 mCurrentFrame.fbZ = 0;
634 return;
635 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800636
637 /* Search for max number of contiguous (cached) layers */
638 int i = 0;
639 while (i < mCurrentFrame.layerCount) {
640 int count = 0;
641 while(mCurrentFrame.isFBComposed[i] && i < mCurrentFrame.layerCount) {
642 count++; i++;
643 }
644 if(count > maxBatchCount) {
645 maxBatchCount = count;
646 maxBatchStart = i - count;
Saurabh Shahaa236822013-04-24 18:07:26 -0700647 mCurrentFrame.fbZ = maxBatchStart;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800648 }
649 if(i < mCurrentFrame.layerCount) i++;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800650 }
651
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800652 /* reset rest of the layers for MDP comp */
653 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
654 if(i != maxBatchStart){
655 mCurrentFrame.isFBComposed[i] = false;
656 } else {
657 i += maxBatchCount;
658 }
659 }
660
661 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700662 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
663 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800664
665 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
666 mCurrentFrame.fbCount);
667}
Saurabh Shah85234ec2013-04-12 17:09:00 -0700668
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800669void MDPComp::updateLayerCache(hwc_context_t* ctx,
670 hwc_display_contents_1_t* list) {
671
672 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
673 int numCacheableLayers = 0;
674
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800675 for(int i = 0; i < numAppLayers; i++) {
676 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
677 numCacheableLayers++;
678 mCurrentFrame.isFBComposed[i] = true;
679 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -0700680 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800681 mCachedFrame.hnd[i] = list->hwLayers[i].handle;
682 }
683 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700684
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800685 mCurrentFrame.fbCount = numCacheableLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700686 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
687 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800688 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__, numCacheableLayers);
689}
690
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800691void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list) {
692
693 int nYuvCount = ctx->listStats[mDpy].yuvCount;
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700694 if(!nYuvCount && mDpy) {
695 //Reset "No animation on external display" related parameters.
696 ctx->mPrevCropVideo.left = ctx->mPrevCropVideo.top =
697 ctx->mPrevCropVideo.right = ctx->mPrevCropVideo.bottom = 0;
698 ctx->mPrevDestVideo.left = ctx->mPrevDestVideo.top =
699 ctx->mPrevDestVideo.right = ctx->mPrevDestVideo.bottom = 0;
700 ctx->mPrevTransformVideo = 0;
701 return;
702 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800703 for(int index = 0;index < nYuvCount; index++){
704 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
705 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
706
707 if(!isYUVDoable(ctx, layer)) {
708 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
709 mCurrentFrame.isFBComposed[nYuvIndex] = true;
710 mCurrentFrame.fbCount++;
711 }
712 } else {
713 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
714 mCurrentFrame.isFBComposed[nYuvIndex] = false;
715 mCurrentFrame.fbCount--;
716 }
717 }
718 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700719
720 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
721 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800722 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
723 mCurrentFrame.fbCount);
724}
725
Saurabh Shahaa236822013-04-24 18:07:26 -0700726bool MDPComp::programMDP(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800727 if(!allocLayerPipes(ctx, list)) {
728 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700729 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800730 }
731
Saurabh Shahaa236822013-04-24 18:07:26 -0700732 bool fbBatch = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800733 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700734 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800735 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800736 int mdpIndex = mCurrentFrame.layerToMDP[index];
737 hwc_layer_1_t* layer = &list->hwLayers[index];
738
739 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
740 cur_pipe->zOrder = mdpNextZOrder++;
741
742 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
743 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
744 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -0700745 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800746 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700747 } else if(fbBatch == false) {
748 mdpNextZOrder++;
749 fbBatch = true;
750 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800751 }
752
Saurabh Shahaa236822013-04-24 18:07:26 -0700753 return true;
754}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800755
Saurabh Shahaa236822013-04-24 18:07:26 -0700756bool MDPComp::programYUV(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
757 if(!allocLayerPipes(ctx, list)) {
758 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
759 return false;
760 }
761 //If we are in this block, it means we have yuv + rgb layers both
762 int mdpIdx = 0;
763 for (int index = 0; index < mCurrentFrame.layerCount; index++) {
764 if(!mCurrentFrame.isFBComposed[index]) {
765 hwc_layer_1_t* layer = &list->hwLayers[index];
766 int mdpIndex = mCurrentFrame.layerToMDP[index];
767 MdpPipeInfo* cur_pipe =
768 mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
769 cur_pipe->zOrder = mdpIdx++;
770
771 if(configure(ctx, layer,
772 mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
773 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
774 layer %d",__FUNCTION__, index);
775 return false;
776 }
777 }
778 }
779 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800780}
781
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700782uint32_t MDPComp::calcMDPBytesRead(hwc_context_t *ctx,
783 hwc_display_contents_1_t* list) {
784 uint32_t size = 0;
785
786 for (uint32_t i = 0; i < list->numHwLayers - 1; i++) {
787 if(!mCurrentFrame.isFBComposed[i]) {
788 hwc_layer_1_t* layer = &list->hwLayers[i];
789 private_handle_t *hnd = (private_handle_t *)layer->handle;
790 hwc_rect_t crop = layer->sourceCrop;
791 float bpp = ((float)hnd->size) / (hnd->width * hnd->height);
792 size += bpp * ((crop.right - crop.left) *
793 (crop.bottom - crop.top));
794 }
795 }
796
797 if(mCurrentFrame.fbCount) {
798 hwc_layer_1_t* layer = &list->hwLayers[list->numHwLayers - 1];
799 private_handle_t *hnd = (private_handle_t *)layer->handle;
800 size += hnd->size;
801 }
802
803 return size;
804}
805
806bool MDPComp::bandwidthCheck(hwc_context_t *ctx, const uint32_t& size) {
807 //Will be added for other targets if we run into bandwidth issues and when
808 //we have profiling data to set an upper limit.
809 if(qdutils::MDPVersion::getInstance().is8x74v2()) {
810 const uint32_t ONE_GIG = 1024 * 1024 * 1024;
811 double panelRefRate =
812 1000000000.0 / ctx->dpyAttr[mDpy].vsync_period;
813 if((size + sCompBytesClaimed) > ((sMaxBw / panelRefRate) * ONE_GIG)) {
814 return false;
815 }
816 }
817 return true;
818}
819
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800820int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700821 int ret = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -0700822 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -0700823
Saurabh Shahb39f8152013-08-22 10:21:44 -0700824 //reset old data
825 mCurrentFrame.reset(numLayers);
Prabhanjan Kandula088bd892013-07-02 23:47:13 +0530826
Saurabh Shahb39f8152013-08-22 10:21:44 -0700827 //number of app layers exceeds MAX_NUM_APP_LAYERS fall back to GPU
828 //do not cache the information for next draw cycle.
829 if(numLayers > MAX_NUM_APP_LAYERS) {
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530830 mCachedFrame.updateCounts(mCurrentFrame);
Saurabh Shahb39f8152013-08-22 10:21:44 -0700831 ALOGD_IF(isDebug(), "%s: Number of App layers exceeded the limit ",
832 __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700833 ret = -1;
834 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -0700835 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800836
Saurabh Shahb39f8152013-08-22 10:21:44 -0700837 //Hard conditions, if not met, cannot do MDP comp
838 if(!isFrameDoable(ctx)) {
839 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
840 __FUNCTION__);
841 reset(numLayers, list);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700842 ret = -1;
843 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -0700844 }
845
846 //Check whether layers marked for MDP Composition is actually doable.
847 if(isFullFrameDoable(ctx, list)) {
848 mCurrentFrame.map();
849 //Configure framebuffer first if applicable
850 if(mCurrentFrame.fbZ >= 0) {
851 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list,
852 mCurrentFrame.fbZ)) {
853 ALOGE("%s configure framebuffer failed", __func__);
854 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -0700855 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700856 ret = -1;
857 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -0700858 }
859 }
860 //Acquire and Program MDP pipes
861 if(!programMDP(ctx, list)) {
862 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -0700863 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700864 ret = -1;
865 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -0700866 } else { //Success
867 //Any change in composition types needs an FB refresh
868 mCurrentFrame.needsRedraw = false;
869 if(mCurrentFrame.fbCount &&
870 ((mCurrentFrame.mdpCount != mCachedFrame.mdpCount) ||
871 (mCurrentFrame.fbCount != mCachedFrame.cacheCount) ||
872 (mCurrentFrame.fbZ != mCachedFrame.fbZ) ||
873 (!mCurrentFrame.mdpCount) ||
874 (list->flags & HWC_GEOMETRY_CHANGED) ||
875 isSkipPresent(ctx, mDpy) ||
876 (mDpy > HWC_DISPLAY_PRIMARY))) {
877 mCurrentFrame.needsRedraw = true;
878 }
879 }
880 } else if(isOnlyVideoDoable(ctx, list)) {
881 //All layers marked for MDP comp cannot be bypassed.
882 //Try to compose atleast YUV layers through MDP comp and let
883 //all the RGB layers compose in FB
884 //Destination over
885 mCurrentFrame.fbZ = -1;
886 if(mCurrentFrame.fbCount)
887 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
888
889 mCurrentFrame.map();
890
891 //Configure framebuffer first if applicable
892 if(mCurrentFrame.fbZ >= 0) {
893 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, mCurrentFrame.fbZ)) {
894 ALOGE("%s configure framebuffer failed", __func__);
895 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -0700896 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700897 ret = -1;
898 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -0700899 }
900 }
901 if(!programYUV(ctx, list)) {
902 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -0700903 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700904 ret = -1;
905 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -0700906 }
907 } else {
908 reset(numLayers, list);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700909 ret = -1;
910 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -0700911 }
912
913 //UpdateLayerFlags
914 setMDPCompLayerFlags(ctx, list);
915 mCachedFrame.updateCounts(mCurrentFrame);
916
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530917 // unlock it before calling dump function to avoid deadlock
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800918 if(isDebug()) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700919 ALOGD("GEOMETRY change: %d", (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800920 android::String8 sDump("");
921 dump(sDump);
922 ALOGE("%s",sDump.string());
923 }
924
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700925exit:
926 sCompBytesClaimed += calcMDPBytesRead(ctx, list);
927 return ret;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800928}
929
Saurabh Shah88e4d272013-09-03 13:31:29 -0700930//=============MDPCompNonSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800931
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700932/*
933 * Configures pipe(s) for MDP composition
934 */
Saurabh Shah88e4d272013-09-03 13:31:29 -0700935int MDPCompNonSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800936 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -0700937 MdpPipeInfoNonSplit& mdp_info =
938 *(static_cast<MdpPipeInfoNonSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -0800939 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
940 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
941 eIsFg isFg = IS_FG_OFF;
942 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700943
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800944 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
945 __FUNCTION__, layer, zOrder, dest);
946
Saurabh Shah88e4d272013-09-03 13:31:29 -0700947 return configureNonSplit(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800948 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700949}
950
Saurabh Shah88e4d272013-09-03 13:31:29 -0700951bool MDPCompNonSplit::arePipesAvailable(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700952 hwc_display_contents_1_t* list) {
953 overlay::Overlay& ov = *ctx->mOverlay;
954 int numPipesNeeded = mCurrentFrame.mdpCount;
955 int availPipes = ov.availablePipes(mDpy, Overlay::MIXER_DEFAULT);
956
957 //Reserve pipe for FB
958 if(mCurrentFrame.fbCount)
959 availPipes -= 1;
960
961 if(numPipesNeeded > availPipes) {
962 ALOGD_IF(isDebug(), "%s: Insufficient pipes, dpy %d needed %d, avail %d",
963 __FUNCTION__, mDpy, numPipesNeeded, availPipes);
964 return false;
965 }
966
967 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700968}
969
Saurabh Shah88e4d272013-09-03 13:31:29 -0700970bool MDPCompNonSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700971 hwc_display_contents_1_t* list) {
972 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700973
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800974 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700975
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800976 hwc_layer_1_t* layer = &list->hwLayers[index];
977 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800978 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800979 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -0700980 info.pipeInfo = new MdpPipeInfoNonSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -0800981 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -0700982 MdpPipeInfoNonSplit& pipe_info = *(MdpPipeInfoNonSplit*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800983 ePipeType type = MDPCOMP_OV_ANY;
984
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700985 if(isYuvBuffer(hnd)) {
986 type = MDPCOMP_OV_VG;
Saurabh Shah8a117932013-05-23 12:48:13 -0700987 } else if(!qhwc::needsScaling(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -0700988 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
989 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800990 type = MDPCOMP_OV_DMA;
991 }
992
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700993 pipe_info.index = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800994 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700995 ALOGD_IF(isDebug(), "%s: Unable to get pipe type = %d",
996 __FUNCTION__, (int) type);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500997 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700998 }
999 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001000 return true;
1001}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001002
Saurabh Shah88e4d272013-09-03 13:31:29 -07001003bool MDPCompNonSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001004
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001005 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001006 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1007 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -08001008 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001009
1010 if(!ctx || !list) {
1011 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001012 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001013 }
1014
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301015 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1016 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1017 return true;
1018 }
1019
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001020 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001021 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001022 idleInvalidator->markForSleep();
1023
1024 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001025 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001026
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001027 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1028 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001029 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001030 if(mCurrentFrame.isFBComposed[i]) continue;
1031
Naseer Ahmed5b6708a2012-08-02 13:46:08 -07001032 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001033 private_handle_t *hnd = (private_handle_t *)layer->handle;
1034 if(!hnd) {
1035 ALOGE("%s handle null", __FUNCTION__);
1036 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001037 }
1038
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001039 int mdpIndex = mCurrentFrame.layerToMDP[i];
1040
Saurabh Shah88e4d272013-09-03 13:31:29 -07001041 MdpPipeInfoNonSplit& pipe_info =
1042 *(MdpPipeInfoNonSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001043 ovutils::eDest dest = pipe_info.index;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001044 if(dest == ovutils::OV_INVALID) {
1045 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001046 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001047 }
1048
Saurabh Shahacf10202013-02-26 10:15:15 -08001049 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1050 continue;
1051 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001052
Saurabh Shahacf10202013-02-26 10:15:15 -08001053 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001054 using pipe: %d", __FUNCTION__, layer,
1055 hnd, dest );
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001056
Saurabh Shahacf10202013-02-26 10:15:15 -08001057 int fd = hnd->fd;
1058 uint32_t offset = hnd->offset;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001059
1060 if(ctx->mAD->isModeOn()) {
1061 if(ctx->mAD->draw(ctx, fd, offset)) {
1062 fd = ctx->mAD->getDstFd(ctx);
1063 offset = ctx->mAD->getDstOffset(ctx);
1064 }
1065 }
1066
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001067 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -08001068 if(rot) {
1069 if(!rot->queueBuffer(fd, offset))
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001070 return false;
Saurabh Shahacf10202013-02-26 10:15:15 -08001071 fd = rot->getDstMemId();
1072 offset = rot->getDstOffset();
1073 }
1074
1075 if (!ov.queueBuffer(fd, offset, dest)) {
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301076 ALOGE("%s: queueBuffer failed for display:%d ", __FUNCTION__, mDpy);
Saurabh Shahacf10202013-02-26 10:15:15 -08001077 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001078 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001079
1080 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001081 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001082 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001083}
1084
Saurabh Shah88e4d272013-09-03 13:31:29 -07001085//=============MDPCompSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001086
Saurabh Shah88e4d272013-09-03 13:31:29 -07001087int MDPCompSplit::pipesNeeded(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001088 hwc_display_contents_1_t* list,
1089 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001090 int pipesNeeded = 0;
Saurabh Shah67a38c32013-06-10 16:23:15 -07001091 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001092
1093 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001094
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001095 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1096 if(!mCurrentFrame.isFBComposed[i]) {
1097 hwc_layer_1_t* layer = &list->hwLayers[i];
1098 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001099 if(mixer == Overlay::MIXER_LEFT && dst.left < lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001100 pipesNeeded++;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001101 } else if(mixer == Overlay::MIXER_RIGHT && dst.right > lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001102 pipesNeeded++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001103 }
1104 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001105 }
1106 return pipesNeeded;
1107}
1108
Saurabh Shah88e4d272013-09-03 13:31:29 -07001109bool MDPCompSplit::arePipesAvailable(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001110 hwc_display_contents_1_t* list) {
1111 overlay::Overlay& ov = *ctx->mOverlay;
1112
1113 for(int i = 0; i < Overlay::MIXER_MAX; i++) {
1114 int numPipesNeeded = pipesNeeded(ctx, list, i);
1115 int availPipes = ov.availablePipes(mDpy, i);
1116
1117 //Reserve pipe(s)for FB
1118 if(mCurrentFrame.fbCount)
1119 availPipes -= 1;
1120
1121 if(numPipesNeeded > availPipes) {
1122 ALOGD_IF(isDebug(), "%s: Insufficient pipes for "
1123 "dpy %d mixer %d needed %d, avail %d",
1124 __FUNCTION__, mDpy, i, numPipesNeeded, availPipes);
1125 return false;
1126 }
1127 }
1128 return true;
1129}
1130
Saurabh Shah88e4d272013-09-03 13:31:29 -07001131bool MDPCompSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
1132 MdpPipeInfoSplit& pipe_info,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001133 ePipeType type) {
1134 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001135 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001136
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001137 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001138 pipe_info.lIndex = ovutils::OV_INVALID;
1139 pipe_info.rIndex = ovutils::OV_INVALID;
1140
1141 if (dst.left < lSplit) {
1142 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_LEFT);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001143 if(pipe_info.lIndex == ovutils::OV_INVALID)
1144 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001145 }
1146
1147 if(dst.right > lSplit) {
1148 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_RIGHT);
1149 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001150 return false;
1151 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001152
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001153 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001154}
1155
Saurabh Shah88e4d272013-09-03 13:31:29 -07001156bool MDPCompSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001157 hwc_display_contents_1_t* list) {
1158 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001159
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001160 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001161
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001162 hwc_layer_1_t* layer = &list->hwLayers[index];
1163 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001164 int mdpIndex = mCurrentFrame.layerToMDP[index];
1165 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001166 info.pipeInfo = new MdpPipeInfoSplit;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001167 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001168 MdpPipeInfoSplit& pipe_info = *(MdpPipeInfoSplit*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001169 ePipeType type = MDPCOMP_OV_ANY;
1170
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001171 if(isYuvBuffer(hnd)) {
1172 type = MDPCOMP_OV_VG;
Saurabh Shah8a117932013-05-23 12:48:13 -07001173 } else if(!qhwc::needsScaling(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001174 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001175 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001176 type = MDPCOMP_OV_DMA;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001177 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001178
1179 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001180 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type = %d",
1181 __FUNCTION__, (int) type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001182 return false;
1183 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001184 }
1185 return true;
1186}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001187
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001188/*
1189 * Configures pipe(s) for MDP composition
1190 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001191int MDPCompSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001192 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001193 MdpPipeInfoSplit& mdp_info =
1194 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001195 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1196 eIsFg isFg = IS_FG_OFF;
1197 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1198 eDest lDest = mdp_info.lIndex;
1199 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001200
1201 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1202 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1203
Saurabh Shah88e4d272013-09-03 13:31:29 -07001204 return configureSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001205 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001206}
1207
Saurabh Shah88e4d272013-09-03 13:31:29 -07001208bool MDPCompSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001209
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001210 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001211 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1212 return true;
1213 }
1214
1215 if(!ctx || !list) {
1216 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001217 return false;
1218 }
1219
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301220 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1221 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1222 return true;
1223 }
1224
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001225 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001226 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001227 idleInvalidator->markForSleep();
1228
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001229 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001230 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001231
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001232 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1233 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001234 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001235 if(mCurrentFrame.isFBComposed[i]) continue;
1236
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001237 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001238 private_handle_t *hnd = (private_handle_t *)layer->handle;
1239 if(!hnd) {
1240 ALOGE("%s handle null", __FUNCTION__);
1241 return false;
1242 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001243
1244 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1245 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001246 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001247
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001248 int mdpIndex = mCurrentFrame.layerToMDP[i];
1249
Saurabh Shah88e4d272013-09-03 13:31:29 -07001250 MdpPipeInfoSplit& pipe_info =
1251 *(MdpPipeInfoSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001252 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -08001253
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001254 ovutils::eDest indexL = pipe_info.lIndex;
1255 ovutils::eDest indexR = pipe_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001256
Saurabh Shahacf10202013-02-26 10:15:15 -08001257 int fd = hnd->fd;
1258 int offset = hnd->offset;
1259
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001260 if(ctx->mAD->isModeOn()) {
1261 if(ctx->mAD->draw(ctx, fd, offset)) {
1262 fd = ctx->mAD->getDstFd(ctx);
1263 offset = ctx->mAD->getDstOffset(ctx);
1264 }
1265 }
1266
Saurabh Shahacf10202013-02-26 10:15:15 -08001267 if(rot) {
1268 rot->queueBuffer(fd, offset);
1269 fd = rot->getDstMemId();
1270 offset = rot->getDstOffset();
1271 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001272
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001273 //************* play left mixer **********
1274 if(indexL != ovutils::OV_INVALID) {
1275 ovutils::eDest destL = (ovutils::eDest)indexL;
Saurabh Shahacf10202013-02-26 10:15:15 -08001276 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001277 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
Saurabh Shahacf10202013-02-26 10:15:15 -08001278 if (!ov.queueBuffer(fd, offset, destL)) {
1279 ALOGE("%s: queueBuffer failed for left mixer", __FUNCTION__);
1280 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001281 }
1282 }
1283
1284 //************* play right mixer **********
1285 if(indexR != ovutils::OV_INVALID) {
1286 ovutils::eDest destR = (ovutils::eDest)indexR;
Saurabh Shahacf10202013-02-26 10:15:15 -08001287 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001288 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
Saurabh Shahacf10202013-02-26 10:15:15 -08001289 if (!ov.queueBuffer(fd, offset, destR)) {
1290 ALOGE("%s: queueBuffer failed for right mixer", __FUNCTION__);
1291 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001292 }
1293 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001294
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001295 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1296 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001297
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001298 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001299}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001300}; //namespace
1301