blob: 565865ab7d80bc97a6ae7c7c70784aa2854b18f4 [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
Terence Hampson9cd5fa92013-09-10 17:06:37 -0400786 if(!qdutils::MDPVersion::getInstance().is8x74v2())
787 return 0;
788
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700789 for (uint32_t i = 0; i < list->numHwLayers - 1; i++) {
790 if(!mCurrentFrame.isFBComposed[i]) {
791 hwc_layer_1_t* layer = &list->hwLayers[i];
792 private_handle_t *hnd = (private_handle_t *)layer->handle;
Terence Hampson9cd5fa92013-09-10 17:06:37 -0400793 if (hnd) {
794 hwc_rect_t crop = layer->sourceCrop;
795 float bpp = ((float)hnd->size) / (hnd->width * hnd->height);
796 size += bpp * ((crop.right - crop.left) *
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700797 (crop.bottom - crop.top));
Terence Hampson9cd5fa92013-09-10 17:06:37 -0400798 }
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700799 }
800 }
801
802 if(mCurrentFrame.fbCount) {
803 hwc_layer_1_t* layer = &list->hwLayers[list->numHwLayers - 1];
804 private_handle_t *hnd = (private_handle_t *)layer->handle;
Terence Hampson9cd5fa92013-09-10 17:06:37 -0400805 if (hnd)
806 size += hnd->size;
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700807 }
808
809 return size;
810}
811
812bool MDPComp::bandwidthCheck(hwc_context_t *ctx, const uint32_t& size) {
813 //Will be added for other targets if we run into bandwidth issues and when
814 //we have profiling data to set an upper limit.
815 if(qdutils::MDPVersion::getInstance().is8x74v2()) {
816 const uint32_t ONE_GIG = 1024 * 1024 * 1024;
817 double panelRefRate =
818 1000000000.0 / ctx->dpyAttr[mDpy].vsync_period;
819 if((size + sCompBytesClaimed) > ((sMaxBw / panelRefRate) * ONE_GIG)) {
820 return false;
821 }
822 }
823 return true;
824}
825
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800826int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700827 int ret = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -0700828 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -0700829
Saurabh Shahb39f8152013-08-22 10:21:44 -0700830 //reset old data
831 mCurrentFrame.reset(numLayers);
Prabhanjan Kandula088bd892013-07-02 23:47:13 +0530832
Saurabh Shahb39f8152013-08-22 10:21:44 -0700833 //number of app layers exceeds MAX_NUM_APP_LAYERS fall back to GPU
834 //do not cache the information for next draw cycle.
835 if(numLayers > MAX_NUM_APP_LAYERS) {
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530836 mCachedFrame.updateCounts(mCurrentFrame);
Saurabh Shahb39f8152013-08-22 10:21:44 -0700837 ALOGD_IF(isDebug(), "%s: Number of App layers exceeded the limit ",
838 __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700839 ret = -1;
840 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -0700841 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800842
Saurabh Shahb39f8152013-08-22 10:21:44 -0700843 //Hard conditions, if not met, cannot do MDP comp
844 if(!isFrameDoable(ctx)) {
845 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
846 __FUNCTION__);
847 reset(numLayers, list);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700848 ret = -1;
849 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -0700850 }
851
852 //Check whether layers marked for MDP Composition is actually doable.
853 if(isFullFrameDoable(ctx, list)) {
854 mCurrentFrame.map();
855 //Configure framebuffer first if applicable
856 if(mCurrentFrame.fbZ >= 0) {
857 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list,
858 mCurrentFrame.fbZ)) {
859 ALOGE("%s configure framebuffer failed", __func__);
860 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -0700861 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700862 ret = -1;
863 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -0700864 }
865 }
866 //Acquire and Program MDP pipes
867 if(!programMDP(ctx, list)) {
868 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -0700869 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700870 ret = -1;
871 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -0700872 } else { //Success
873 //Any change in composition types needs an FB refresh
874 mCurrentFrame.needsRedraw = false;
875 if(mCurrentFrame.fbCount &&
876 ((mCurrentFrame.mdpCount != mCachedFrame.mdpCount) ||
877 (mCurrentFrame.fbCount != mCachedFrame.cacheCount) ||
878 (mCurrentFrame.fbZ != mCachedFrame.fbZ) ||
879 (!mCurrentFrame.mdpCount) ||
880 (list->flags & HWC_GEOMETRY_CHANGED) ||
881 isSkipPresent(ctx, mDpy) ||
882 (mDpy > HWC_DISPLAY_PRIMARY))) {
883 mCurrentFrame.needsRedraw = true;
884 }
885 }
886 } else if(isOnlyVideoDoable(ctx, list)) {
887 //All layers marked for MDP comp cannot be bypassed.
888 //Try to compose atleast YUV layers through MDP comp and let
889 //all the RGB layers compose in FB
890 //Destination over
891 mCurrentFrame.fbZ = -1;
892 if(mCurrentFrame.fbCount)
893 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
894
895 mCurrentFrame.map();
896
897 //Configure framebuffer first if applicable
898 if(mCurrentFrame.fbZ >= 0) {
899 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, mCurrentFrame.fbZ)) {
900 ALOGE("%s configure framebuffer failed", __func__);
901 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -0700902 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700903 ret = -1;
904 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -0700905 }
906 }
907 if(!programYUV(ctx, list)) {
908 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -0700909 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700910 ret = -1;
911 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -0700912 }
913 } else {
914 reset(numLayers, list);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700915 ret = -1;
916 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -0700917 }
918
919 //UpdateLayerFlags
920 setMDPCompLayerFlags(ctx, list);
921 mCachedFrame.updateCounts(mCurrentFrame);
922
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530923 // unlock it before calling dump function to avoid deadlock
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800924 if(isDebug()) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700925 ALOGD("GEOMETRY change: %d", (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800926 android::String8 sDump("");
927 dump(sDump);
928 ALOGE("%s",sDump.string());
929 }
930
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700931exit:
932 sCompBytesClaimed += calcMDPBytesRead(ctx, list);
933 return ret;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800934}
935
Saurabh Shah88e4d272013-09-03 13:31:29 -0700936//=============MDPCompNonSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800937
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700938/*
939 * Configures pipe(s) for MDP composition
940 */
Saurabh Shah88e4d272013-09-03 13:31:29 -0700941int MDPCompNonSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800942 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -0700943 MdpPipeInfoNonSplit& mdp_info =
944 *(static_cast<MdpPipeInfoNonSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -0800945 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
946 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
947 eIsFg isFg = IS_FG_OFF;
948 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700949
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800950 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
951 __FUNCTION__, layer, zOrder, dest);
952
Saurabh Shah88e4d272013-09-03 13:31:29 -0700953 return configureNonSplit(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800954 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700955}
956
Saurabh Shah88e4d272013-09-03 13:31:29 -0700957bool MDPCompNonSplit::arePipesAvailable(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700958 hwc_display_contents_1_t* list) {
959 overlay::Overlay& ov = *ctx->mOverlay;
960 int numPipesNeeded = mCurrentFrame.mdpCount;
961 int availPipes = ov.availablePipes(mDpy, Overlay::MIXER_DEFAULT);
962
963 //Reserve pipe for FB
964 if(mCurrentFrame.fbCount)
965 availPipes -= 1;
966
967 if(numPipesNeeded > availPipes) {
968 ALOGD_IF(isDebug(), "%s: Insufficient pipes, dpy %d needed %d, avail %d",
969 __FUNCTION__, mDpy, numPipesNeeded, availPipes);
970 return false;
971 }
972
973 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700974}
975
Saurabh Shah88e4d272013-09-03 13:31:29 -0700976bool MDPCompNonSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700977 hwc_display_contents_1_t* list) {
978 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700979
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800980 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700981
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800982 hwc_layer_1_t* layer = &list->hwLayers[index];
983 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800984 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800985 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -0700986 info.pipeInfo = new MdpPipeInfoNonSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -0800987 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -0700988 MdpPipeInfoNonSplit& pipe_info = *(MdpPipeInfoNonSplit*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800989 ePipeType type = MDPCOMP_OV_ANY;
990
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700991 if(isYuvBuffer(hnd)) {
992 type = MDPCOMP_OV_VG;
Saurabh Shah8a117932013-05-23 12:48:13 -0700993 } else if(!qhwc::needsScaling(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -0700994 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
995 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800996 type = MDPCOMP_OV_DMA;
997 }
998
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700999 pipe_info.index = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001000 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001001 ALOGD_IF(isDebug(), "%s: Unable to get pipe type = %d",
1002 __FUNCTION__, (int) type);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001003 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001004 }
1005 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001006 return true;
1007}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001008
Saurabh Shah88e4d272013-09-03 13:31:29 -07001009bool MDPCompNonSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001010
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001011 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001012 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1013 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -08001014 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001015
1016 if(!ctx || !list) {
1017 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001018 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001019 }
1020
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301021 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1022 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1023 return true;
1024 }
1025
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001026 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001027 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001028 idleInvalidator->markForSleep();
1029
1030 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001031 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001032
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001033 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1034 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001035 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001036 if(mCurrentFrame.isFBComposed[i]) continue;
1037
Naseer Ahmed5b6708a2012-08-02 13:46:08 -07001038 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001039 private_handle_t *hnd = (private_handle_t *)layer->handle;
1040 if(!hnd) {
1041 ALOGE("%s handle null", __FUNCTION__);
1042 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001043 }
1044
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001045 int mdpIndex = mCurrentFrame.layerToMDP[i];
1046
Saurabh Shah88e4d272013-09-03 13:31:29 -07001047 MdpPipeInfoNonSplit& pipe_info =
1048 *(MdpPipeInfoNonSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001049 ovutils::eDest dest = pipe_info.index;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001050 if(dest == ovutils::OV_INVALID) {
1051 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001052 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001053 }
1054
Saurabh Shahacf10202013-02-26 10:15:15 -08001055 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1056 continue;
1057 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001058
Saurabh Shahacf10202013-02-26 10:15:15 -08001059 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001060 using pipe: %d", __FUNCTION__, layer,
1061 hnd, dest );
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001062
Saurabh Shahacf10202013-02-26 10:15:15 -08001063 int fd = hnd->fd;
1064 uint32_t offset = hnd->offset;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001065
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001066 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -08001067 if(rot) {
1068 if(!rot->queueBuffer(fd, offset))
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001069 return false;
Saurabh Shahacf10202013-02-26 10:15:15 -08001070 fd = rot->getDstMemId();
1071 offset = rot->getDstOffset();
1072 }
1073
1074 if (!ov.queueBuffer(fd, offset, dest)) {
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301075 ALOGE("%s: queueBuffer failed for display:%d ", __FUNCTION__, mDpy);
Saurabh Shahacf10202013-02-26 10:15:15 -08001076 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001077 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001078
1079 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001080 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001081 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001082}
1083
Saurabh Shah88e4d272013-09-03 13:31:29 -07001084//=============MDPCompSplit===================================================
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001085
Saurabh Shah88e4d272013-09-03 13:31:29 -07001086int MDPCompSplit::pipesNeeded(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001087 hwc_display_contents_1_t* list,
1088 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001089 int pipesNeeded = 0;
Saurabh Shah67a38c32013-06-10 16:23:15 -07001090 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001091
1092 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001093
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001094 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1095 if(!mCurrentFrame.isFBComposed[i]) {
1096 hwc_layer_1_t* layer = &list->hwLayers[i];
1097 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001098 if(mixer == Overlay::MIXER_LEFT && dst.left < lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001099 pipesNeeded++;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001100 } else if(mixer == Overlay::MIXER_RIGHT && dst.right > lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001101 pipesNeeded++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001102 }
1103 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001104 }
1105 return pipesNeeded;
1106}
1107
Saurabh Shah88e4d272013-09-03 13:31:29 -07001108bool MDPCompSplit::arePipesAvailable(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001109 hwc_display_contents_1_t* list) {
1110 overlay::Overlay& ov = *ctx->mOverlay;
1111
1112 for(int i = 0; i < Overlay::MIXER_MAX; i++) {
1113 int numPipesNeeded = pipesNeeded(ctx, list, i);
1114 int availPipes = ov.availablePipes(mDpy, i);
1115
1116 //Reserve pipe(s)for FB
1117 if(mCurrentFrame.fbCount)
1118 availPipes -= 1;
1119
1120 if(numPipesNeeded > availPipes) {
1121 ALOGD_IF(isDebug(), "%s: Insufficient pipes for "
1122 "dpy %d mixer %d needed %d, avail %d",
1123 __FUNCTION__, mDpy, i, numPipesNeeded, availPipes);
1124 return false;
1125 }
1126 }
1127 return true;
1128}
1129
Saurabh Shah88e4d272013-09-03 13:31:29 -07001130bool MDPCompSplit::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
1131 MdpPipeInfoSplit& pipe_info,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001132 ePipeType type) {
1133 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001134 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001135
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001136 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001137 pipe_info.lIndex = ovutils::OV_INVALID;
1138 pipe_info.rIndex = ovutils::OV_INVALID;
1139
1140 if (dst.left < lSplit) {
1141 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_LEFT);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001142 if(pipe_info.lIndex == ovutils::OV_INVALID)
1143 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001144 }
1145
1146 if(dst.right > lSplit) {
1147 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_RIGHT);
1148 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001149 return false;
1150 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001151
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001152 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001153}
1154
Saurabh Shah88e4d272013-09-03 13:31:29 -07001155bool MDPCompSplit::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001156 hwc_display_contents_1_t* list) {
1157 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001158
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001159 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001160
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001161 hwc_layer_1_t* layer = &list->hwLayers[index];
1162 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001163 int mdpIndex = mCurrentFrame.layerToMDP[index];
1164 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Saurabh Shah88e4d272013-09-03 13:31:29 -07001165 info.pipeInfo = new MdpPipeInfoSplit;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001166 info.rot = NULL;
Saurabh Shah88e4d272013-09-03 13:31:29 -07001167 MdpPipeInfoSplit& pipe_info = *(MdpPipeInfoSplit*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001168 ePipeType type = MDPCOMP_OV_ANY;
1169
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001170 if(isYuvBuffer(hnd)) {
1171 type = MDPCOMP_OV_VG;
Saurabh Shah8a117932013-05-23 12:48:13 -07001172 } else if(!qhwc::needsScaling(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001173 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001174 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001175 type = MDPCOMP_OV_DMA;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001176 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001177
1178 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001179 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type = %d",
1180 __FUNCTION__, (int) type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001181 return false;
1182 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001183 }
1184 return true;
1185}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001186
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001187/*
1188 * Configures pipe(s) for MDP composition
1189 */
Saurabh Shah88e4d272013-09-03 13:31:29 -07001190int MDPCompSplit::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001191 PipeLayerPair& PipeLayerPair) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07001192 MdpPipeInfoSplit& mdp_info =
1193 *(static_cast<MdpPipeInfoSplit*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001194 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1195 eIsFg isFg = IS_FG_OFF;
1196 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1197 eDest lDest = mdp_info.lIndex;
1198 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001199
1200 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1201 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1202
Saurabh Shah88e4d272013-09-03 13:31:29 -07001203 return configureSplit(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001204 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001205}
1206
Saurabh Shah88e4d272013-09-03 13:31:29 -07001207bool MDPCompSplit::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001208
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001209 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001210 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1211 return true;
1212 }
1213
1214 if(!ctx || !list) {
1215 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001216 return false;
1217 }
1218
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301219 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1220 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1221 return true;
1222 }
1223
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001224 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001225 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001226 idleInvalidator->markForSleep();
1227
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001228 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001229 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001230
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001231 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1232 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001233 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001234 if(mCurrentFrame.isFBComposed[i]) continue;
1235
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001236 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001237 private_handle_t *hnd = (private_handle_t *)layer->handle;
1238 if(!hnd) {
1239 ALOGE("%s handle null", __FUNCTION__);
1240 return false;
1241 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001242
1243 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1244 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001245 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001246
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001247 int mdpIndex = mCurrentFrame.layerToMDP[i];
1248
Saurabh Shah88e4d272013-09-03 13:31:29 -07001249 MdpPipeInfoSplit& pipe_info =
1250 *(MdpPipeInfoSplit*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001251 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -08001252
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001253 ovutils::eDest indexL = pipe_info.lIndex;
1254 ovutils::eDest indexR = pipe_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001255
Saurabh Shahacf10202013-02-26 10:15:15 -08001256 int fd = hnd->fd;
1257 int offset = hnd->offset;
1258
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001259 if(ctx->mAD->isModeOn()) {
1260 if(ctx->mAD->draw(ctx, fd, offset)) {
1261 fd = ctx->mAD->getDstFd(ctx);
1262 offset = ctx->mAD->getDstOffset(ctx);
1263 }
1264 }
1265
Saurabh Shahacf10202013-02-26 10:15:15 -08001266 if(rot) {
1267 rot->queueBuffer(fd, offset);
1268 fd = rot->getDstMemId();
1269 offset = rot->getDstOffset();
1270 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001271
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001272 //************* play left mixer **********
1273 if(indexL != ovutils::OV_INVALID) {
1274 ovutils::eDest destL = (ovutils::eDest)indexL;
Saurabh Shahacf10202013-02-26 10:15:15 -08001275 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001276 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
Saurabh Shahacf10202013-02-26 10:15:15 -08001277 if (!ov.queueBuffer(fd, offset, destL)) {
1278 ALOGE("%s: queueBuffer failed for left mixer", __FUNCTION__);
1279 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001280 }
1281 }
1282
1283 //************* play right mixer **********
1284 if(indexR != ovutils::OV_INVALID) {
1285 ovutils::eDest destR = (ovutils::eDest)indexR;
Saurabh Shahacf10202013-02-26 10:15:15 -08001286 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001287 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
Saurabh Shahacf10202013-02-26 10:15:15 -08001288 if (!ov.queueBuffer(fd, offset, destR)) {
1289 ALOGE("%s: queueBuffer failed for right mixer", __FUNCTION__);
1290 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001291 }
1292 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001293
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001294 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1295 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001296
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001297 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001298}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001299}; //namespace
1300