blob: 8956be5f07ea649ae03e44906d666dc28029b798 [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 Shah67a38c32013-06-10 16:23:15 -070048MDPComp* MDPComp::getObject(const int& width, const int& rightSplit,
49 const int& dpy) {
50 if(width > MAX_DISPLAY_DIM || rightSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080051 return new MDPCompHighRes(dpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080052 }
Saurabh Shah67a38c32013-06-10 16:23:15 -070053 return new MDPCompLowRes(dpy);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080054}
55
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080056MDPComp::MDPComp(int dpy):mDpy(dpy){};
57
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080058void MDPComp::dump(android::String8& buf)
59{
Jeykumar Sankaran3c6bb042013-08-15 14:01:04 -070060 if(mCurrentFrame.layerCount > MAX_NUM_APP_LAYERS)
61 return;
62
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080063 dumpsys_log(buf,"HWC Map for Dpy: %s \n",
Jeykumar Sankaran27dee262013-08-01 17:09:54 -070064 (mDpy == 0) ? "\"PRIMARY\"" :
65 (mDpy == 1) ? "\"EXTERNAL\"" : "\"VIRTUAL\"");
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080066 dumpsys_log(buf,"PREV_FRAME: layerCount:%2d mdpCount:%2d \
67 cacheCount:%2d \n", mCachedFrame.layerCount,
68 mCachedFrame.mdpCount, mCachedFrame.cacheCount);
69 dumpsys_log(buf,"CURR_FRAME: layerCount:%2d mdpCount:%2d \
70 fbCount:%2d \n", mCurrentFrame.layerCount,
71 mCurrentFrame.mdpCount, mCurrentFrame.fbCount);
72 dumpsys_log(buf,"needsFBRedraw:%3s pipesUsed:%2d MaxPipesPerMixer: %d \n",
73 (mCurrentFrame.needsRedraw? "YES" : "NO"),
74 mCurrentFrame.mdpCount, sMaxPipesPerMixer);
75 dumpsys_log(buf," --------------------------------------------- \n");
76 dumpsys_log(buf," listIdx | cached? | mdpIndex | comptype | Z \n");
77 dumpsys_log(buf," --------------------------------------------- \n");
78 for(int index = 0; index < mCurrentFrame.layerCount; index++ )
79 dumpsys_log(buf," %7d | %7s | %8d | %9s | %2d \n",
80 index,
81 (mCurrentFrame.isFBComposed[index] ? "YES" : "NO"),
82 mCurrentFrame.layerToMDP[index],
83 (mCurrentFrame.isFBComposed[index] ?
84 (mCurrentFrame.needsRedraw ? "GLES" : "CACHE") : "MDP"),
85 (mCurrentFrame.isFBComposed[index] ? mCurrentFrame.fbZ :
86 mCurrentFrame.mdpToLayer[mCurrentFrame.layerToMDP[index]].pipeInfo->zOrder));
87 dumpsys_log(buf,"\n");
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080088}
89
90bool MDPComp::init(hwc_context_t *ctx) {
91
92 if(!ctx) {
93 ALOGE("%s: Invalid hwc context!!",__FUNCTION__);
94 return false;
95 }
96
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080097 char property[PROPERTY_VALUE_MAX];
98
99 sEnabled = false;
100 if((property_get("persist.hwc.mdpcomp.enable", property, NULL) > 0) &&
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800101 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
102 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800103 sEnabled = true;
Xiaoming Zhou944e02e2013-05-01 20:54:03 -0400104 if(!setupBasePipe(ctx)) {
105 ALOGE("%s: Failed to setup primary base pipe", __FUNCTION__);
106 return false;
107 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800108 }
109
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700110 sEnableMixedMode = true;
111 if((property_get("debug.mdpcomp.mixedmode.disable", property, NULL) > 0) &&
112 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
113 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
114 sEnableMixedMode = false;
115 }
116
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800117 sDebugLogs = false;
118 if(property_get("debug.mdpcomp.logs", property, NULL) > 0) {
119 if(atoi(property) != 0)
120 sDebugLogs = true;
121 }
122
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800123 sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
Saurabh Shah85234ec2013-04-12 17:09:00 -0700124 if(property_get("debug.mdpcomp.maxpermixer", property, "-1") > 0) {
125 int val = atoi(property);
126 if(val >= 0)
127 sMaxPipesPerMixer = min(val, MAX_PIPES_PER_MIXER);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800128 }
129
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700130 if(property_get("debug.mdpcomp.bw", property, "0") > 0) {
131 float val = atof(property);
132 if(val > 0.0f) {
133 sMaxBw = val;
134 }
135 }
136
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400137 if(ctx->mMDP.panel != MIPI_CMD_PANEL) {
138 // Idle invalidation is not necessary on command mode panels
139 long idle_timeout = DEFAULT_IDLE_TIME;
140 if(property_get("debug.mdpcomp.idletime", property, NULL) > 0) {
141 if(atoi(property) != 0)
142 idle_timeout = atoi(property);
143 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800144
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400145 //create Idle Invalidator only when not disabled through property
146 if(idle_timeout != -1)
147 idleInvalidator = IdleInvalidator::getInstance();
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800148
Naseer Ahmedf40f2c82013-08-14 16:42:40 -0400149 if(idleInvalidator == NULL) {
150 ALOGE("%s: failed to instantiate idleInvalidator object",
151 __FUNCTION__);
152 } else {
153 idleInvalidator->init(timeout_handler, ctx, idle_timeout);
154 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800155 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700156 return true;
157}
158
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700159void MDPComp::reset(const int& numLayers, hwc_display_contents_1_t* list) {
160 mCurrentFrame.reset(numLayers);
161 mCachedFrame.cacheAll(list);
162 mCachedFrame.updateCounts(mCurrentFrame);
163}
164
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700165void MDPComp::timeout_handler(void *udata) {
166 struct hwc_context_t* ctx = (struct hwc_context_t*)(udata);
167
168 if(!ctx) {
169 ALOGE("%s: received empty data in timer callback", __FUNCTION__);
170 return;
171 }
172
Jesse Hall3be78d92012-08-21 15:12:23 -0700173 if(!ctx->proc) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700174 ALOGE("%s: HWC proc not registered", __FUNCTION__);
175 return;
176 }
177 sIdleFallBack = true;
178 /* Trigger SF to redraw the current frame */
Jesse Hall3be78d92012-08-21 15:12:23 -0700179 ctx->proc->invalidate(ctx->proc);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700180}
181
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800182void MDPComp::setMDPCompLayerFlags(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800183 hwc_display_contents_1_t* list) {
184 LayerProp *layerProp = ctx->layerProp[mDpy];
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800185
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800186 for(int index = 0; index < ctx->listStats[mDpy].numAppLayers; index++) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800187 hwc_layer_1_t* layer = &(list->hwLayers[index]);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800188 if(!mCurrentFrame.isFBComposed[index]) {
189 layerProp[index].mFlags |= HWC_MDPCOMP;
190 layer->compositionType = HWC_OVERLAY;
191 layer->hints |= HWC_HINT_CLEAR_FB;
192 mCachedFrame.hnd[index] = NULL;
193 } else {
194 if(!mCurrentFrame.needsRedraw)
195 layer->compositionType = HWC_OVERLAY;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800196 }
197 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700198}
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500199
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800200/*
201 * Sets up BORDERFILL as default base pipe and detaches RGB0.
202 * Framebuffer is always updated using PLAY ioctl.
203 */
204bool MDPComp::setupBasePipe(hwc_context_t *ctx) {
205 const int dpy = HWC_DISPLAY_PRIMARY;
206 int fb_stride = ctx->dpyAttr[dpy].stride;
207 int fb_width = ctx->dpyAttr[dpy].xres;
208 int fb_height = ctx->dpyAttr[dpy].yres;
209 int fb_fd = ctx->dpyAttr[dpy].fd;
210
211 mdp_overlay ovInfo;
212 msmfb_overlay_data ovData;
213 memset(&ovInfo, 0, sizeof(mdp_overlay));
214 memset(&ovData, 0, sizeof(msmfb_overlay_data));
215
216 ovInfo.src.format = MDP_RGB_BORDERFILL;
217 ovInfo.src.width = fb_width;
218 ovInfo.src.height = fb_height;
219 ovInfo.src_rect.w = fb_width;
220 ovInfo.src_rect.h = fb_height;
221 ovInfo.dst_rect.w = fb_width;
222 ovInfo.dst_rect.h = fb_height;
223 ovInfo.id = MSMFB_NEW_REQUEST;
224
225 if (ioctl(fb_fd, MSMFB_OVERLAY_SET, &ovInfo) < 0) {
226 ALOGE("Failed to call ioctl MSMFB_OVERLAY_SET err=%s",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800227 strerror(errno));
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800228 return false;
229 }
230
231 ovData.id = ovInfo.id;
232 if (ioctl(fb_fd, MSMFB_OVERLAY_PLAY, &ovData) < 0) {
233 ALOGE("Failed to call ioctl MSMFB_OVERLAY_PLAY err=%s",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800234 strerror(errno));
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800235 return false;
236 }
237 return true;
238}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800239MDPComp::FrameInfo::FrameInfo() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700240 reset(0);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800241}
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800242
Saurabh Shahaa236822013-04-24 18:07:26 -0700243void MDPComp::FrameInfo::reset(const int& numLayers) {
244 for(int i = 0 ; i < MAX_PIPES_PER_MIXER && numLayers; i++ ) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800245 if(mdpToLayer[i].pipeInfo) {
246 delete mdpToLayer[i].pipeInfo;
247 mdpToLayer[i].pipeInfo = NULL;
248 //We dont own the rotator
249 mdpToLayer[i].rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800250 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800251 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800252
253 memset(&mdpToLayer, 0, sizeof(mdpToLayer));
254 memset(&layerToMDP, -1, sizeof(layerToMDP));
Saurabh Shahaa236822013-04-24 18:07:26 -0700255 memset(&isFBComposed, 1, sizeof(isFBComposed));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800256
Saurabh Shahaa236822013-04-24 18:07:26 -0700257 layerCount = numLayers;
258 fbCount = numLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800259 mdpCount = 0;
Saurabh Shah2f3895f2013-05-02 10:13:31 -0700260 needsRedraw = true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800261 fbZ = 0;
262}
263
Saurabh Shahaa236822013-04-24 18:07:26 -0700264void MDPComp::FrameInfo::map() {
265 // populate layer and MDP maps
266 int mdpIdx = 0;
267 for(int idx = 0; idx < layerCount; idx++) {
268 if(!isFBComposed[idx]) {
269 mdpToLayer[mdpIdx].listIndex = idx;
270 layerToMDP[idx] = mdpIdx++;
271 }
272 }
273}
274
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800275MDPComp::LayerCache::LayerCache() {
276 reset();
277}
278
279void MDPComp::LayerCache::reset() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700280 memset(&hnd, 0, sizeof(hnd));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800281 mdpCount = 0;
282 cacheCount = 0;
283 layerCount = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -0700284 fbZ = -1;
285}
286
287void MDPComp::LayerCache::cacheAll(hwc_display_contents_1_t* list) {
288 const int numAppLayers = list->numHwLayers - 1;
289 for(int i = 0; i < numAppLayers; i++) {
290 hnd[i] = list->hwLayers[i].handle;
291 }
292}
293
294void MDPComp::LayerCache::updateCounts(const FrameInfo& curFrame) {
295 mdpCount = curFrame.mdpCount;
296 cacheCount = curFrame.fbCount;
297 layerCount = curFrame.layerCount;
298 fbZ = curFrame.fbZ;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800299}
300
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530301bool MDPComp::isValidDimension(hwc_context_t *ctx, hwc_layer_1_t *layer) {
Saurabh Shah4fdde762013-04-30 18:47:33 -0700302 const int dpy = HWC_DISPLAY_PRIMARY;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800303 private_handle_t *hnd = (private_handle_t *)layer->handle;
304
305 if(!hnd) {
306 ALOGE("%s: layer handle is NULL", __FUNCTION__);
307 return false;
308 }
309
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800310 int hw_w = ctx->dpyAttr[mDpy].xres;
311 int hw_h = ctx->dpyAttr[mDpy].yres;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800312
Saurabh Shah4fdde762013-04-30 18:47:33 -0700313 hwc_rect_t crop = layer->sourceCrop;
314 hwc_rect_t dst = layer->displayFrame;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800315
316 if(dst.left < 0 || dst.top < 0 || dst.right > hw_w || dst.bottom > hw_h) {
Saurabh Shah4fdde762013-04-30 18:47:33 -0700317 hwc_rect_t scissor = {0, 0, hw_w, hw_h };
318 qhwc::calculate_crop_rects(crop, dst, scissor, layer->transform);
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800319 }
320
Saurabh Shah4fdde762013-04-30 18:47:33 -0700321 int crop_w = crop.right - crop.left;
322 int crop_h = crop.bottom - crop.top;
323 int dst_w = dst.right - dst.left;
324 int dst_h = dst.bottom - dst.top;
325 float w_dscale = ceilf((float)crop_w / (float)dst_w);
326 float h_dscale = ceilf((float)crop_h / (float)dst_h);
327
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800328 /* Workaround for MDP HW limitation in DSI command mode panels where
329 * FPS will not go beyond 30 if buffers on RGB pipes are of width or height
330 * less than 5 pixels
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530331 * There also is a HW limilation in MDP, minimum block size is 2x2
332 * Fallback to GPU if height is less than 2.
333 */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800334 if((crop_w < 5)||(crop_h < 5))
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800335 return false;
336
Saurabh Shah4fdde762013-04-30 18:47:33 -0700337 const uint32_t downscale =
338 qdutils::MDPVersion::getInstance().getMaxMDPDownscale();
339 if(ctx->mMDP.version >= qdutils::MDSS_V5) {
340 /* Workaround for downscales larger than 4x.
341 * Will be removed once decimator block is enabled for MDSS
342 */
343 if(!qdutils::MDPVersion::getInstance().supportsDecimation()) {
344 if(crop_w > MAX_DISPLAY_DIM || w_dscale > downscale ||
345 h_dscale > downscale)
346 return false;
347 } else {
348 if(w_dscale > 64 || h_dscale > 64)
349 return false;
350 }
351 } else { //A-family
352 if(w_dscale > downscale || h_dscale > downscale)
353 return false;
354 }
355
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800356 return true;
357}
358
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700359ovutils::eDest MDPComp::getMdpPipe(hwc_context_t *ctx, ePipeType type,
360 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800361 overlay::Overlay& ov = *ctx->mOverlay;
362 ovutils::eDest mdp_pipe = ovutils::OV_INVALID;
363
364 switch(type) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800365 case MDPCOMP_OV_DMA:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700366 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_DMA, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800367 if(mdp_pipe != ovutils::OV_INVALID) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800368 return mdp_pipe;
369 }
370 case MDPCOMP_OV_ANY:
371 case MDPCOMP_OV_RGB:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700372 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800373 if(mdp_pipe != ovutils::OV_INVALID) {
374 return mdp_pipe;
375 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800376
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800377 if(type == MDPCOMP_OV_RGB) {
378 //Requested only for RGB pipe
379 break;
380 }
381 case MDPCOMP_OV_VG:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700382 return ov.nextPipe(ovutils::OV_MDP_PIPE_VG, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800383 default:
384 ALOGE("%s: Invalid pipe type",__FUNCTION__);
385 return ovutils::OV_INVALID;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800386 };
387 return ovutils::OV_INVALID;
388}
389
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800390bool MDPComp::isFrameDoable(hwc_context_t *ctx) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700391 bool ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700392 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800393
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800394 if(!isEnabled()) {
395 ALOGD_IF(isDebug(),"%s: MDP Comp. not enabled.", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700396 ret = false;
Saurabh Shahd4e65852013-06-17 11:33:53 -0700397 } else if(qdutils::MDPVersion::getInstance().is8x26() &&
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700398 ctx->mVideoTransFlag && ctx->mVirtualDisplay->isConnected()) {
Saurabh Shahd4e65852013-06-17 11:33:53 -0700399 //1 Padding round to shift pipes across mixers
400 ALOGD_IF(isDebug(),"%s: MDP Comp. video transition padding round",
401 __FUNCTION__);
402 ret = false;
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700403 } else if(ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isConfiguring ||
404 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isConfiguring) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800405 ALOGD_IF( isDebug(),"%s: External Display connection is pending",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800406 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700407 ret = false;
Saurabh Shahaa236822013-04-24 18:07:26 -0700408 } else if(ctx->isPaddingRound) {
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700409 ctx->isPaddingRound = false;
410 ALOGD_IF(isDebug(), "%s: padding round",__FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700411 ret = false;
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700412 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700413 return ret;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800414}
415
416/* Checks for conditions where all the layers marked for MDP comp cannot be
417 * bypassed. On such conditions we try to bypass atleast YUV layers */
418bool MDPComp::isFullFrameDoable(hwc_context_t *ctx,
419 hwc_display_contents_1_t* list){
420
Saurabh Shahaa236822013-04-24 18:07:26 -0700421 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800422
Saurabh Shah2d998a92013-05-14 17:55:58 -0700423 if(sIdleFallBack) {
424 ALOGD_IF(isDebug(), "%s: Idle fallback dpy %d",__FUNCTION__, mDpy);
425 return false;
426 }
427
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800428 if(mDpy > HWC_DISPLAY_PRIMARY){
429 ALOGD_IF(isDebug(), "%s: Cannot support External display(s)",
430 __FUNCTION__);
431 return false;
432 }
433
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800434 if(isSkipPresent(ctx, mDpy)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700435 ALOGD_IF(isDebug(),"%s: SKIP present: %d",
436 __FUNCTION__,
437 isSkipPresent(ctx, mDpy));
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800438 return false;
439 }
440
Saurabh Shah9f084ad2013-05-02 11:28:09 -0700441 if(ctx->listStats[mDpy].needsAlphaScale
442 && ctx->mMDP.version < qdutils::MDSS_V5) {
443 ALOGD_IF(isDebug(), "%s: frame needs alpha downscaling",__FUNCTION__);
444 return false;
445 }
446
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800447 //MDP composition is not efficient if layer needs rotator.
448 for(int i = 0; i < numAppLayers; ++i) {
449 // As MDP h/w supports flip operation, use MDP comp only for
450 // 180 transforms. Fail for any transform involving 90 (90, 270).
451 hwc_layer_1_t* layer = &list->hwLayers[i];
452 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800453
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700454 if(layer->transform & HWC_TRANSFORM_ROT_90) {
455 if(!isYuvBuffer(hnd) ) {
456 ALOGD_IF(isDebug(), "%s: orientation involved",__FUNCTION__);
457 return false;
458 }else if(!canUseRotator(ctx, mDpy)) {
459 ALOGD_IF(isDebug(), "%s: no free DMA pipe",__FUNCTION__);
460 return false;
461 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800462 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700463 if(!isValidDimension(ctx,layer)) {
464 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
465 __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800466 return false;
467 }
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530468
469 //For 8x26 with panel width>1k, if RGB layer needs HFLIP fail mdp comp
470 // may not need it if Gfx pre-rotation can handle all flips & rotations
471 if(qdutils::MDPVersion::getInstance().is8x26() &&
472 (ctx->dpyAttr[mDpy].xres > 1024) &&
473 (layer->transform & HWC_TRANSFORM_FLIP_H) &&
474 (!isYuvBuffer(hnd)))
475 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800476 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700477
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700478 if(ctx->mAD->isDoable()) {
479 return false;
480 }
481
Saurabh Shahaa236822013-04-24 18:07:26 -0700482 //If all above hard conditions are met we can do full or partial MDP comp.
483 bool ret = false;
484 if(fullMDPComp(ctx, list)) {
485 ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700486 } else if(partialMDPComp(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700487 ret = true;
488 }
489 return ret;
490}
491
492bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
493 //Setup mCurrentFrame
494 mCurrentFrame.mdpCount = mCurrentFrame.layerCount;
495 mCurrentFrame.fbCount = 0;
496 mCurrentFrame.fbZ = -1;
497 memset(&mCurrentFrame.isFBComposed, 0, sizeof(mCurrentFrame.isFBComposed));
498
499 int mdpCount = mCurrentFrame.mdpCount;
500 if(mdpCount > sMaxPipesPerMixer) {
501 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
502 return false;
503 }
504
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700505 if(!arePipesAvailable(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700506 return false;
507 }
508
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700509 uint32_t size = calcMDPBytesRead(ctx, list);
510 if(!bandwidthCheck(ctx, size)) {
511 ALOGD_IF(isDebug(), "%s: Exceeds bandwidth",__FUNCTION__);
512 return false;
513 }
514
Saurabh Shahaa236822013-04-24 18:07:26 -0700515 return true;
516}
517
518bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
519{
520 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700521
522 if(!sEnableMixedMode) {
523 //Mixed mode is disabled. No need to even try caching.
524 return false;
525 }
526
Saurabh Shahaa236822013-04-24 18:07:26 -0700527 //Setup mCurrentFrame
528 mCurrentFrame.reset(numAppLayers);
529 updateLayerCache(ctx, list);
530 updateYUV(ctx, list);
531 batchLayers(); //sets up fbZ also
532
533 int mdpCount = mCurrentFrame.mdpCount;
534 if(mdpCount > (sMaxPipesPerMixer - 1)) { // -1 since FB is used
535 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
536 return false;
537 }
538
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700539 if(!arePipesAvailable(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700540 return false;
541 }
542
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700543 uint32_t size = calcMDPBytesRead(ctx, list);
544 if(!bandwidthCheck(ctx, size)) {
545 ALOGD_IF(isDebug(), "%s: Exceeds bandwidth",__FUNCTION__);
546 return false;
547 }
548
Saurabh Shahaa236822013-04-24 18:07:26 -0700549 return true;
550}
551
552bool MDPComp::isOnlyVideoDoable(hwc_context_t *ctx,
553 hwc_display_contents_1_t* list){
554 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
555 mCurrentFrame.reset(numAppLayers);
556 updateYUV(ctx, list);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700557 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700558 int fbNeeded = int(mCurrentFrame.fbCount != 0);
559
560 if(!isYuvPresent(ctx, mDpy)) {
561 return false;
562 }
563
Saurabh Shah4fdde762013-04-30 18:47:33 -0700564 if(!mdpCount)
565 return false;
566
Saurabh Shahaa236822013-04-24 18:07:26 -0700567 if(mdpCount > (sMaxPipesPerMixer - fbNeeded)) {
568 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
569 return false;
570 }
571
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700572 if(!arePipesAvailable(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700573 return false;
574 }
575
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700576 uint32_t size = calcMDPBytesRead(ctx, list);
577 if(!bandwidthCheck(ctx, size)) {
578 ALOGD_IF(isDebug(), "%s: Exceeds bandwidth",__FUNCTION__);
579 return false;
580 }
581
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800582 return true;
583}
584
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800585/* Checks for conditions where YUV layers cannot be bypassed */
586bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Saurabh Shahe2474082013-05-15 16:32:13 -0700587 bool extAnimBlockFeature = mDpy && ctx->listStats[mDpy].isDisplayAnimating;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800588
Saurabh Shahe2474082013-05-15 16:32:13 -0700589 if(isSkipLayer(layer) && !extAnimBlockFeature) {
590 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800591 return false;
592 }
593
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700594 if(layer->transform & HWC_TRANSFORM_ROT_90 && !canUseRotator(ctx,mDpy)) {
595 ALOGD_IF(isDebug(), "%s: no free DMA pipe",__FUNCTION__);
596 return false;
597 }
598
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800599 if(isSecuring(ctx, layer)) {
600 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
601 return false;
602 }
603
Saurabh Shah4fdde762013-04-30 18:47:33 -0700604 if(!isValidDimension(ctx, layer)) {
605 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
606 __FUNCTION__);
607 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800608 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700609
Naseer Ahmeddc61a972013-07-10 17:50:54 -0400610 if(layer->planeAlpha < 0xFF) {
611 ALOGD_IF(isDebug(), "%s: Cannot handle YUV layer with plane alpha\
612 in video only mode",
613 __FUNCTION__);
614 return false;
615 }
616
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800617 return true;
618}
619
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800620void MDPComp::batchLayers() {
621 /* Idea is to keep as many contiguous non-updating(cached) layers in FB and
622 * send rest of them through MDP. NEVER mark an updating layer for caching.
623 * But cached ones can be marked for MDP*/
624
625 int maxBatchStart = -1;
626 int maxBatchCount = 0;
627
628 /* All or Nothing is cached. No batching needed */
Saurabh Shahaa236822013-04-24 18:07:26 -0700629 if(!mCurrentFrame.fbCount) {
630 mCurrentFrame.fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800631 return;
Saurabh Shahaa236822013-04-24 18:07:26 -0700632 }
633 if(!mCurrentFrame.mdpCount) {
634 mCurrentFrame.fbZ = 0;
635 return;
636 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800637
638 /* Search for max number of contiguous (cached) layers */
639 int i = 0;
640 while (i < mCurrentFrame.layerCount) {
641 int count = 0;
642 while(mCurrentFrame.isFBComposed[i] && i < mCurrentFrame.layerCount) {
643 count++; i++;
644 }
645 if(count > maxBatchCount) {
646 maxBatchCount = count;
647 maxBatchStart = i - count;
Saurabh Shahaa236822013-04-24 18:07:26 -0700648 mCurrentFrame.fbZ = maxBatchStart;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800649 }
650 if(i < mCurrentFrame.layerCount) i++;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800651 }
652
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800653 /* reset rest of the layers for MDP comp */
654 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
655 if(i != maxBatchStart){
656 mCurrentFrame.isFBComposed[i] = false;
657 } else {
658 i += maxBatchCount;
659 }
660 }
661
662 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700663 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
664 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800665
666 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
667 mCurrentFrame.fbCount);
668}
Saurabh Shah85234ec2013-04-12 17:09:00 -0700669
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800670void MDPComp::updateLayerCache(hwc_context_t* ctx,
671 hwc_display_contents_1_t* list) {
672
673 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
674 int numCacheableLayers = 0;
675
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800676 for(int i = 0; i < numAppLayers; i++) {
677 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
678 numCacheableLayers++;
679 mCurrentFrame.isFBComposed[i] = true;
680 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -0700681 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800682 mCachedFrame.hnd[i] = list->hwLayers[i].handle;
683 }
684 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700685
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800686 mCurrentFrame.fbCount = numCacheableLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700687 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
688 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800689 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__, numCacheableLayers);
690}
691
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800692void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list) {
693
694 int nYuvCount = ctx->listStats[mDpy].yuvCount;
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700695 if(!nYuvCount && mDpy) {
696 //Reset "No animation on external display" related parameters.
697 ctx->mPrevCropVideo.left = ctx->mPrevCropVideo.top =
698 ctx->mPrevCropVideo.right = ctx->mPrevCropVideo.bottom = 0;
699 ctx->mPrevDestVideo.left = ctx->mPrevDestVideo.top =
700 ctx->mPrevDestVideo.right = ctx->mPrevDestVideo.bottom = 0;
701 ctx->mPrevTransformVideo = 0;
702 return;
703 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800704 for(int index = 0;index < nYuvCount; index++){
705 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
706 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
707
708 if(!isYUVDoable(ctx, layer)) {
709 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
710 mCurrentFrame.isFBComposed[nYuvIndex] = true;
711 mCurrentFrame.fbCount++;
712 }
713 } else {
714 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
715 mCurrentFrame.isFBComposed[nYuvIndex] = false;
716 mCurrentFrame.fbCount--;
717 }
718 }
719 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700720
721 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
722 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800723 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
724 mCurrentFrame.fbCount);
725}
726
Saurabh Shahaa236822013-04-24 18:07:26 -0700727bool MDPComp::programMDP(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800728 if(!allocLayerPipes(ctx, list)) {
729 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700730 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800731 }
732
Saurabh Shahaa236822013-04-24 18:07:26 -0700733 bool fbBatch = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800734 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700735 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800736 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800737 int mdpIndex = mCurrentFrame.layerToMDP[index];
738 hwc_layer_1_t* layer = &list->hwLayers[index];
739
740 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
741 cur_pipe->zOrder = mdpNextZOrder++;
742
743 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
744 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
745 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -0700746 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800747 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700748 } else if(fbBatch == false) {
749 mdpNextZOrder++;
750 fbBatch = true;
751 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800752 }
753
Saurabh Shahaa236822013-04-24 18:07:26 -0700754 return true;
755}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800756
Saurabh Shahaa236822013-04-24 18:07:26 -0700757bool MDPComp::programYUV(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
758 if(!allocLayerPipes(ctx, list)) {
759 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
760 return false;
761 }
762 //If we are in this block, it means we have yuv + rgb layers both
763 int mdpIdx = 0;
764 for (int index = 0; index < mCurrentFrame.layerCount; index++) {
765 if(!mCurrentFrame.isFBComposed[index]) {
766 hwc_layer_1_t* layer = &list->hwLayers[index];
767 int mdpIndex = mCurrentFrame.layerToMDP[index];
768 MdpPipeInfo* cur_pipe =
769 mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
770 cur_pipe->zOrder = mdpIdx++;
771
772 if(configure(ctx, layer,
773 mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
774 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
775 layer %d",__FUNCTION__, index);
776 return false;
777 }
778 }
779 }
780 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800781}
782
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700783uint32_t MDPComp::calcMDPBytesRead(hwc_context_t *ctx,
784 hwc_display_contents_1_t* list) {
785 uint32_t size = 0;
786
787 for (uint32_t i = 0; i < list->numHwLayers - 1; i++) {
788 if(!mCurrentFrame.isFBComposed[i]) {
789 hwc_layer_1_t* layer = &list->hwLayers[i];
790 private_handle_t *hnd = (private_handle_t *)layer->handle;
791 hwc_rect_t crop = layer->sourceCrop;
792 float bpp = ((float)hnd->size) / (hnd->width * hnd->height);
793 size += bpp * ((crop.right - crop.left) *
794 (crop.bottom - crop.top));
795 }
796 }
797
798 if(mCurrentFrame.fbCount) {
799 hwc_layer_1_t* layer = &list->hwLayers[list->numHwLayers - 1];
800 private_handle_t *hnd = (private_handle_t *)layer->handle;
801 size += hnd->size;
802 }
803
804 return size;
805}
806
807bool MDPComp::bandwidthCheck(hwc_context_t *ctx, const uint32_t& size) {
808 //Will be added for other targets if we run into bandwidth issues and when
809 //we have profiling data to set an upper limit.
810 if(qdutils::MDPVersion::getInstance().is8x74v2()) {
811 const uint32_t ONE_GIG = 1024 * 1024 * 1024;
812 double panelRefRate =
813 1000000000.0 / ctx->dpyAttr[mDpy].vsync_period;
814 if((size + sCompBytesClaimed) > ((sMaxBw / panelRefRate) * ONE_GIG)) {
815 return false;
816 }
817 }
818 return true;
819}
820
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800821int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700822 int ret = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -0700823 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -0700824
Saurabh Shahb39f8152013-08-22 10:21:44 -0700825 //reset old data
826 mCurrentFrame.reset(numLayers);
Prabhanjan Kandula088bd892013-07-02 23:47:13 +0530827
Saurabh Shahb39f8152013-08-22 10:21:44 -0700828 //number of app layers exceeds MAX_NUM_APP_LAYERS fall back to GPU
829 //do not cache the information for next draw cycle.
830 if(numLayers > MAX_NUM_APP_LAYERS) {
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530831 mCachedFrame.updateCounts(mCurrentFrame);
Saurabh Shahb39f8152013-08-22 10:21:44 -0700832 ALOGD_IF(isDebug(), "%s: Number of App layers exceeded the limit ",
833 __FUNCTION__);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700834 ret = -1;
835 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -0700836 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800837
Saurabh Shahb39f8152013-08-22 10:21:44 -0700838 //Hard conditions, if not met, cannot do MDP comp
839 if(!isFrameDoable(ctx)) {
840 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
841 __FUNCTION__);
842 reset(numLayers, list);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700843 ret = -1;
844 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -0700845 }
846
847 //Check whether layers marked for MDP Composition is actually doable.
848 if(isFullFrameDoable(ctx, list)) {
849 mCurrentFrame.map();
850 //Configure framebuffer first if applicable
851 if(mCurrentFrame.fbZ >= 0) {
852 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list,
853 mCurrentFrame.fbZ)) {
854 ALOGE("%s configure framebuffer failed", __func__);
855 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -0700856 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700857 ret = -1;
858 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -0700859 }
860 }
861 //Acquire and Program MDP pipes
862 if(!programMDP(ctx, list)) {
863 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -0700864 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700865 ret = -1;
866 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -0700867 } else { //Success
868 //Any change in composition types needs an FB refresh
869 mCurrentFrame.needsRedraw = false;
870 if(mCurrentFrame.fbCount &&
871 ((mCurrentFrame.mdpCount != mCachedFrame.mdpCount) ||
872 (mCurrentFrame.fbCount != mCachedFrame.cacheCount) ||
873 (mCurrentFrame.fbZ != mCachedFrame.fbZ) ||
874 (!mCurrentFrame.mdpCount) ||
875 (list->flags & HWC_GEOMETRY_CHANGED) ||
876 isSkipPresent(ctx, mDpy) ||
877 (mDpy > HWC_DISPLAY_PRIMARY))) {
878 mCurrentFrame.needsRedraw = true;
879 }
880 }
881 } else if(isOnlyVideoDoable(ctx, list)) {
882 //All layers marked for MDP comp cannot be bypassed.
883 //Try to compose atleast YUV layers through MDP comp and let
884 //all the RGB layers compose in FB
885 //Destination over
886 mCurrentFrame.fbZ = -1;
887 if(mCurrentFrame.fbCount)
888 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
889
890 mCurrentFrame.map();
891
892 //Configure framebuffer first if applicable
893 if(mCurrentFrame.fbZ >= 0) {
894 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, mCurrentFrame.fbZ)) {
895 ALOGE("%s configure framebuffer failed", __func__);
896 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -0700897 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700898 ret = -1;
899 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -0700900 }
901 }
902 if(!programYUV(ctx, list)) {
903 reset(numLayers, list);
Saurabh Shah6be7c782013-08-28 15:13:52 -0700904 ctx->mOverlay->clear(mDpy);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700905 ret = -1;
906 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -0700907 }
908 } else {
909 reset(numLayers, list);
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700910 ret = -1;
911 goto exit;
Saurabh Shahb39f8152013-08-22 10:21:44 -0700912 }
913
914 //UpdateLayerFlags
915 setMDPCompLayerFlags(ctx, list);
916 mCachedFrame.updateCounts(mCurrentFrame);
917
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530918 // unlock it before calling dump function to avoid deadlock
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800919 if(isDebug()) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700920 ALOGD("GEOMETRY change: %d", (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800921 android::String8 sDump("");
922 dump(sDump);
923 ALOGE("%s",sDump.string());
924 }
925
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700926exit:
927 sCompBytesClaimed += calcMDPBytesRead(ctx, list);
928 return ret;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800929}
930
931//=============MDPCompLowRes===================================================
932
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700933/*
934 * Configures pipe(s) for MDP composition
935 */
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800936int MDPCompLowRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800937 PipeLayerPair& PipeLayerPair) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800938 MdpPipeInfoLowRes& mdp_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800939 *(static_cast<MdpPipeInfoLowRes*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -0800940 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
941 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
942 eIsFg isFg = IS_FG_OFF;
943 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700944
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800945 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
946 __FUNCTION__, layer, zOrder, dest);
947
948 return configureLowRes(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
949 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700950}
951
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700952bool MDPCompLowRes::arePipesAvailable(hwc_context_t *ctx,
953 hwc_display_contents_1_t* list) {
954 overlay::Overlay& ov = *ctx->mOverlay;
955 int numPipesNeeded = mCurrentFrame.mdpCount;
956 int availPipes = ov.availablePipes(mDpy, Overlay::MIXER_DEFAULT);
957
958 //Reserve pipe for FB
959 if(mCurrentFrame.fbCount)
960 availPipes -= 1;
961
962 if(numPipesNeeded > availPipes) {
963 ALOGD_IF(isDebug(), "%s: Insufficient pipes, dpy %d needed %d, avail %d",
964 __FUNCTION__, mDpy, numPipesNeeded, availPipes);
965 return false;
966 }
967
968 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700969}
970
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800971bool MDPCompLowRes::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700972 hwc_display_contents_1_t* list) {
973 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700974
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800975 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700976
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800977 hwc_layer_1_t* layer = &list->hwLayers[index];
978 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800979 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800980 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800981 info.pipeInfo = new MdpPipeInfoLowRes;
Saurabh Shahacf10202013-02-26 10:15:15 -0800982 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800983 MdpPipeInfoLowRes& pipe_info = *(MdpPipeInfoLowRes*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800984 ePipeType type = MDPCOMP_OV_ANY;
985
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700986 if(isYuvBuffer(hnd)) {
987 type = MDPCOMP_OV_VG;
Saurabh Shah8a117932013-05-23 12:48:13 -0700988 } else if(!qhwc::needsScaling(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -0700989 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
990 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800991 type = MDPCOMP_OV_DMA;
992 }
993
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700994 pipe_info.index = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800995 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700996 ALOGD_IF(isDebug(), "%s: Unable to get pipe type = %d",
997 __FUNCTION__, (int) type);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500998 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700999 }
1000 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001001 return true;
1002}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001003
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -08001004bool MDPCompLowRes::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001005
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001006 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001007 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1008 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -08001009 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001010
1011 if(!ctx || !list) {
1012 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001013 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001014 }
1015
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301016 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1017 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1018 return true;
1019 }
1020
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001021 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001022 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001023 idleInvalidator->markForSleep();
1024
1025 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001026 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001027
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001028 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1029 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001030 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001031 if(mCurrentFrame.isFBComposed[i]) continue;
1032
Naseer Ahmed5b6708a2012-08-02 13:46:08 -07001033 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001034 private_handle_t *hnd = (private_handle_t *)layer->handle;
1035 if(!hnd) {
1036 ALOGE("%s handle null", __FUNCTION__);
1037 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001038 }
1039
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001040 int mdpIndex = mCurrentFrame.layerToMDP[i];
1041
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001042 MdpPipeInfoLowRes& pipe_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001043 *(MdpPipeInfoLowRes*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001044 ovutils::eDest dest = pipe_info.index;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001045 if(dest == ovutils::OV_INVALID) {
1046 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001047 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001048 }
1049
Saurabh Shahacf10202013-02-26 10:15:15 -08001050 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1051 continue;
1052 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001053
Saurabh Shahacf10202013-02-26 10:15:15 -08001054 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001055 using pipe: %d", __FUNCTION__, layer,
1056 hnd, dest );
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001057
Saurabh Shahacf10202013-02-26 10:15:15 -08001058 int fd = hnd->fd;
1059 uint32_t offset = hnd->offset;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001060
1061 if(ctx->mAD->isModeOn()) {
1062 if(ctx->mAD->draw(ctx, fd, offset)) {
1063 fd = ctx->mAD->getDstFd(ctx);
1064 offset = ctx->mAD->getDstOffset(ctx);
1065 }
1066 }
1067
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001068 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -08001069 if(rot) {
1070 if(!rot->queueBuffer(fd, offset))
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001071 return false;
Saurabh Shahacf10202013-02-26 10:15:15 -08001072 fd = rot->getDstMemId();
1073 offset = rot->getDstOffset();
1074 }
1075
1076 if (!ov.queueBuffer(fd, offset, dest)) {
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301077 ALOGE("%s: queueBuffer failed for display:%d ", __FUNCTION__, mDpy);
Saurabh Shahacf10202013-02-26 10:15:15 -08001078 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001079 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001080
1081 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001082 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001083 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001084}
1085
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001086//=============MDPCompHighRes===================================================
1087
1088int MDPCompHighRes::pipesNeeded(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001089 hwc_display_contents_1_t* list,
1090 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001091 int pipesNeeded = 0;
Saurabh Shah67a38c32013-06-10 16:23:15 -07001092 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001093
1094 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001095
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001096 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1097 if(!mCurrentFrame.isFBComposed[i]) {
1098 hwc_layer_1_t* layer = &list->hwLayers[i];
1099 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001100 if(mixer == Overlay::MIXER_LEFT && dst.left < lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001101 pipesNeeded++;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001102 } else if(mixer == Overlay::MIXER_RIGHT && dst.right > lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001103 pipesNeeded++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001104 }
1105 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001106 }
1107 return pipesNeeded;
1108}
1109
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001110bool MDPCompHighRes::arePipesAvailable(hwc_context_t *ctx,
1111 hwc_display_contents_1_t* list) {
1112 overlay::Overlay& ov = *ctx->mOverlay;
1113
1114 for(int i = 0; i < Overlay::MIXER_MAX; i++) {
1115 int numPipesNeeded = pipesNeeded(ctx, list, i);
1116 int availPipes = ov.availablePipes(mDpy, i);
1117
1118 //Reserve pipe(s)for FB
1119 if(mCurrentFrame.fbCount)
1120 availPipes -= 1;
1121
1122 if(numPipesNeeded > availPipes) {
1123 ALOGD_IF(isDebug(), "%s: Insufficient pipes for "
1124 "dpy %d mixer %d needed %d, avail %d",
1125 __FUNCTION__, mDpy, i, numPipesNeeded, availPipes);
1126 return false;
1127 }
1128 }
1129 return true;
1130}
1131
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001132bool MDPCompHighRes::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001133 MdpPipeInfoHighRes& pipe_info,
1134 ePipeType type) {
1135 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001136 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001137
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001138 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001139 pipe_info.lIndex = ovutils::OV_INVALID;
1140 pipe_info.rIndex = ovutils::OV_INVALID;
1141
1142 if (dst.left < lSplit) {
1143 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_LEFT);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001144 if(pipe_info.lIndex == ovutils::OV_INVALID)
1145 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001146 }
1147
1148 if(dst.right > lSplit) {
1149 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_RIGHT);
1150 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001151 return false;
1152 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001153
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001154 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001155}
1156
1157bool MDPCompHighRes::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001158 hwc_display_contents_1_t* list) {
1159 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001160
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001161 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001162
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001163 hwc_layer_1_t* layer = &list->hwLayers[index];
1164 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001165 int mdpIndex = mCurrentFrame.layerToMDP[index];
1166 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001167 info.pipeInfo = new MdpPipeInfoHighRes;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001168 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001169 MdpPipeInfoHighRes& pipe_info = *(MdpPipeInfoHighRes*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001170 ePipeType type = MDPCOMP_OV_ANY;
1171
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001172 if(isYuvBuffer(hnd)) {
1173 type = MDPCOMP_OV_VG;
Saurabh Shah8a117932013-05-23 12:48:13 -07001174 } else if(!qhwc::needsScaling(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001175 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001176 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001177 type = MDPCOMP_OV_DMA;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001178 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001179
1180 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001181 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type = %d",
1182 __FUNCTION__, (int) type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001183 return false;
1184 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001185 }
1186 return true;
1187}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001188
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001189/*
1190 * Configures pipe(s) for MDP composition
1191 */
1192int MDPCompHighRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001193 PipeLayerPair& PipeLayerPair) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001194 MdpPipeInfoHighRes& mdp_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001195 *(static_cast<MdpPipeInfoHighRes*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001196 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1197 eIsFg isFg = IS_FG_OFF;
1198 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1199 eDest lDest = mdp_info.lIndex;
1200 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001201
1202 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1203 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1204
1205 return configureHighRes(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
1206 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001207}
1208
1209bool MDPCompHighRes::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
1210
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001211 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001212 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1213 return true;
1214 }
1215
1216 if(!ctx || !list) {
1217 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001218 return false;
1219 }
1220
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301221 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1222 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1223 return true;
1224 }
1225
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001226 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001227 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001228 idleInvalidator->markForSleep();
1229
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001230 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001231 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001232
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001233 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1234 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001235 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001236 if(mCurrentFrame.isFBComposed[i]) continue;
1237
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001238 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001239 private_handle_t *hnd = (private_handle_t *)layer->handle;
1240 if(!hnd) {
1241 ALOGE("%s handle null", __FUNCTION__);
1242 return false;
1243 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001244
1245 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1246 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001247 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001248
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001249 int mdpIndex = mCurrentFrame.layerToMDP[i];
1250
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001251 MdpPipeInfoHighRes& pipe_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001252 *(MdpPipeInfoHighRes*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1253 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -08001254
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001255 ovutils::eDest indexL = pipe_info.lIndex;
1256 ovutils::eDest indexR = pipe_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001257
Saurabh Shahacf10202013-02-26 10:15:15 -08001258 int fd = hnd->fd;
1259 int offset = hnd->offset;
1260
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001261 if(ctx->mAD->isModeOn()) {
1262 if(ctx->mAD->draw(ctx, fd, offset)) {
1263 fd = ctx->mAD->getDstFd(ctx);
1264 offset = ctx->mAD->getDstOffset(ctx);
1265 }
1266 }
1267
Saurabh Shahacf10202013-02-26 10:15:15 -08001268 if(rot) {
1269 rot->queueBuffer(fd, offset);
1270 fd = rot->getDstMemId();
1271 offset = rot->getDstOffset();
1272 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001273
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001274 //************* play left mixer **********
1275 if(indexL != ovutils::OV_INVALID) {
1276 ovutils::eDest destL = (ovutils::eDest)indexL;
Saurabh Shahacf10202013-02-26 10:15:15 -08001277 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001278 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
Saurabh Shahacf10202013-02-26 10:15:15 -08001279 if (!ov.queueBuffer(fd, offset, destL)) {
1280 ALOGE("%s: queueBuffer failed for left mixer", __FUNCTION__);
1281 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001282 }
1283 }
1284
1285 //************* play right mixer **********
1286 if(indexR != ovutils::OV_INVALID) {
1287 ovutils::eDest destR = (ovutils::eDest)indexR;
Saurabh Shahacf10202013-02-26 10:15:15 -08001288 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001289 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
Saurabh Shahacf10202013-02-26 10:15:15 -08001290 if (!ov.queueBuffer(fd, offset, destR)) {
1291 ALOGE("%s: queueBuffer failed for right mixer", __FUNCTION__);
1292 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001293 }
1294 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001295
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001296 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1297 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001298
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001299 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001300}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001301}; //namespace
1302