blob: 5c0ad4dc298b3fd9d7de8cc0ba235ce856deda49 [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;
Naseer Ahmed7c958d42012-07-31 18:57:03 -070045
Saurabh Shah67a38c32013-06-10 16:23:15 -070046MDPComp* MDPComp::getObject(const int& width, const int& rightSplit,
47 const int& dpy) {
48 if(width > MAX_DISPLAY_DIM || rightSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080049 return new MDPCompHighRes(dpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080050 }
Saurabh Shah67a38c32013-06-10 16:23:15 -070051 return new MDPCompLowRes(dpy);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080052}
53
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080054MDPComp::MDPComp(int dpy):mDpy(dpy){};
55
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080056void MDPComp::dump(android::String8& buf)
57{
Prabhanjan Kandula088bd892013-07-02 23:47:13 +053058 Locker::Autolock _l(mMdpCompLock);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080059 dumpsys_log(buf,"HWC Map for Dpy: %s \n",
Jeykumar Sankaran27dee262013-08-01 17:09:54 -070060 (mDpy == 0) ? "\"PRIMARY\"" :
61 (mDpy == 1) ? "\"EXTERNAL\"" : "\"VIRTUAL\"");
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080062 dumpsys_log(buf,"PREV_FRAME: layerCount:%2d mdpCount:%2d \
63 cacheCount:%2d \n", mCachedFrame.layerCount,
64 mCachedFrame.mdpCount, mCachedFrame.cacheCount);
65 dumpsys_log(buf,"CURR_FRAME: layerCount:%2d mdpCount:%2d \
66 fbCount:%2d \n", mCurrentFrame.layerCount,
67 mCurrentFrame.mdpCount, mCurrentFrame.fbCount);
68 dumpsys_log(buf,"needsFBRedraw:%3s pipesUsed:%2d MaxPipesPerMixer: %d \n",
69 (mCurrentFrame.needsRedraw? "YES" : "NO"),
70 mCurrentFrame.mdpCount, sMaxPipesPerMixer);
71 dumpsys_log(buf," --------------------------------------------- \n");
72 dumpsys_log(buf," listIdx | cached? | mdpIndex | comptype | Z \n");
73 dumpsys_log(buf," --------------------------------------------- \n");
74 for(int index = 0; index < mCurrentFrame.layerCount; index++ )
75 dumpsys_log(buf," %7d | %7s | %8d | %9s | %2d \n",
76 index,
77 (mCurrentFrame.isFBComposed[index] ? "YES" : "NO"),
78 mCurrentFrame.layerToMDP[index],
79 (mCurrentFrame.isFBComposed[index] ?
80 (mCurrentFrame.needsRedraw ? "GLES" : "CACHE") : "MDP"),
81 (mCurrentFrame.isFBComposed[index] ? mCurrentFrame.fbZ :
82 mCurrentFrame.mdpToLayer[mCurrentFrame.layerToMDP[index]].pipeInfo->zOrder));
83 dumpsys_log(buf,"\n");
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080084}
85
86bool MDPComp::init(hwc_context_t *ctx) {
87
88 if(!ctx) {
89 ALOGE("%s: Invalid hwc context!!",__FUNCTION__);
90 return false;
91 }
92
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080093 char property[PROPERTY_VALUE_MAX];
94
95 sEnabled = false;
96 if((property_get("persist.hwc.mdpcomp.enable", property, NULL) > 0) &&
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080097 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
98 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -080099 sEnabled = true;
Xiaoming Zhou944e02e2013-05-01 20:54:03 -0400100 if(!setupBasePipe(ctx)) {
101 ALOGE("%s: Failed to setup primary base pipe", __FUNCTION__);
102 return false;
103 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800104 }
105
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700106 sEnableMixedMode = true;
107 if((property_get("debug.mdpcomp.mixedmode.disable", property, NULL) > 0) &&
108 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
109 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
110 sEnableMixedMode = false;
111 }
112
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800113 sDebugLogs = false;
114 if(property_get("debug.mdpcomp.logs", property, NULL) > 0) {
115 if(atoi(property) != 0)
116 sDebugLogs = true;
117 }
118
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800119 sMaxPipesPerMixer = MAX_PIPES_PER_MIXER;
Saurabh Shah85234ec2013-04-12 17:09:00 -0700120 if(property_get("debug.mdpcomp.maxpermixer", property, "-1") > 0) {
121 int val = atoi(property);
122 if(val >= 0)
123 sMaxPipesPerMixer = min(val, MAX_PIPES_PER_MIXER);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800124 }
125
Zohaib Alamd9743242013-07-19 16:07:34 -0400126 long idle_timeout = DEFAULT_IDLE_TIME;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800127 if(property_get("debug.mdpcomp.idletime", property, NULL) > 0) {
128 if(atoi(property) != 0)
129 idle_timeout = atoi(property);
130 }
131
Zohaib Alamd9743242013-07-19 16:07:34 -0400132 //create Idle Invalidator only when not disabled through property
133 if(idle_timeout != -1)
134 idleInvalidator = IdleInvalidator::getInstance();
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800135
136 if(idleInvalidator == NULL) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800137 ALOGE("%s: failed to instantiate idleInvalidator object", __FUNCTION__);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800138 } else {
139 idleInvalidator->init(timeout_handler, ctx, idle_timeout);
140 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700141 return true;
142}
143
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700144void MDPComp::reset(const int& numLayers, hwc_display_contents_1_t* list) {
145 mCurrentFrame.reset(numLayers);
146 mCachedFrame.cacheAll(list);
147 mCachedFrame.updateCounts(mCurrentFrame);
148}
149
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700150void MDPComp::timeout_handler(void *udata) {
151 struct hwc_context_t* ctx = (struct hwc_context_t*)(udata);
152
153 if(!ctx) {
154 ALOGE("%s: received empty data in timer callback", __FUNCTION__);
155 return;
156 }
157
Jesse Hall3be78d92012-08-21 15:12:23 -0700158 if(!ctx->proc) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700159 ALOGE("%s: HWC proc not registered", __FUNCTION__);
160 return;
161 }
162 sIdleFallBack = true;
163 /* Trigger SF to redraw the current frame */
Jesse Hall3be78d92012-08-21 15:12:23 -0700164 ctx->proc->invalidate(ctx->proc);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700165}
166
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800167void MDPComp::setMDPCompLayerFlags(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800168 hwc_display_contents_1_t* list) {
169 LayerProp *layerProp = ctx->layerProp[mDpy];
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800170
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800171 for(int index = 0; index < ctx->listStats[mDpy].numAppLayers; index++) {
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800172 hwc_layer_1_t* layer = &(list->hwLayers[index]);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800173 if(!mCurrentFrame.isFBComposed[index]) {
174 layerProp[index].mFlags |= HWC_MDPCOMP;
175 layer->compositionType = HWC_OVERLAY;
176 layer->hints |= HWC_HINT_CLEAR_FB;
177 mCachedFrame.hnd[index] = NULL;
178 } else {
179 if(!mCurrentFrame.needsRedraw)
180 layer->compositionType = HWC_OVERLAY;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800181 }
182 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700183}
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500184
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800185/*
186 * Sets up BORDERFILL as default base pipe and detaches RGB0.
187 * Framebuffer is always updated using PLAY ioctl.
188 */
189bool MDPComp::setupBasePipe(hwc_context_t *ctx) {
190 const int dpy = HWC_DISPLAY_PRIMARY;
191 int fb_stride = ctx->dpyAttr[dpy].stride;
192 int fb_width = ctx->dpyAttr[dpy].xres;
193 int fb_height = ctx->dpyAttr[dpy].yres;
194 int fb_fd = ctx->dpyAttr[dpy].fd;
195
196 mdp_overlay ovInfo;
197 msmfb_overlay_data ovData;
198 memset(&ovInfo, 0, sizeof(mdp_overlay));
199 memset(&ovData, 0, sizeof(msmfb_overlay_data));
200
201 ovInfo.src.format = MDP_RGB_BORDERFILL;
202 ovInfo.src.width = fb_width;
203 ovInfo.src.height = fb_height;
204 ovInfo.src_rect.w = fb_width;
205 ovInfo.src_rect.h = fb_height;
206 ovInfo.dst_rect.w = fb_width;
207 ovInfo.dst_rect.h = fb_height;
208 ovInfo.id = MSMFB_NEW_REQUEST;
209
210 if (ioctl(fb_fd, MSMFB_OVERLAY_SET, &ovInfo) < 0) {
211 ALOGE("Failed to call ioctl MSMFB_OVERLAY_SET err=%s",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800212 strerror(errno));
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800213 return false;
214 }
215
216 ovData.id = ovInfo.id;
217 if (ioctl(fb_fd, MSMFB_OVERLAY_PLAY, &ovData) < 0) {
218 ALOGE("Failed to call ioctl MSMFB_OVERLAY_PLAY err=%s",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800219 strerror(errno));
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800220 return false;
221 }
222 return true;
223}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800224MDPComp::FrameInfo::FrameInfo() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700225 reset(0);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800226}
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800227
Saurabh Shahaa236822013-04-24 18:07:26 -0700228void MDPComp::FrameInfo::reset(const int& numLayers) {
229 for(int i = 0 ; i < MAX_PIPES_PER_MIXER && numLayers; i++ ) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800230 if(mdpToLayer[i].pipeInfo) {
231 delete mdpToLayer[i].pipeInfo;
232 mdpToLayer[i].pipeInfo = NULL;
233 //We dont own the rotator
234 mdpToLayer[i].rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800235 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800236 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800237
238 memset(&mdpToLayer, 0, sizeof(mdpToLayer));
239 memset(&layerToMDP, -1, sizeof(layerToMDP));
Saurabh Shahaa236822013-04-24 18:07:26 -0700240 memset(&isFBComposed, 1, sizeof(isFBComposed));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800241
Saurabh Shahaa236822013-04-24 18:07:26 -0700242 layerCount = numLayers;
243 fbCount = numLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800244 mdpCount = 0;
Saurabh Shah2f3895f2013-05-02 10:13:31 -0700245 needsRedraw = true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800246 fbZ = 0;
247}
248
Saurabh Shahaa236822013-04-24 18:07:26 -0700249void MDPComp::FrameInfo::map() {
250 // populate layer and MDP maps
251 int mdpIdx = 0;
252 for(int idx = 0; idx < layerCount; idx++) {
253 if(!isFBComposed[idx]) {
254 mdpToLayer[mdpIdx].listIndex = idx;
255 layerToMDP[idx] = mdpIdx++;
256 }
257 }
258}
259
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800260MDPComp::LayerCache::LayerCache() {
261 reset();
262}
263
264void MDPComp::LayerCache::reset() {
Saurabh Shahaa236822013-04-24 18:07:26 -0700265 memset(&hnd, 0, sizeof(hnd));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800266 mdpCount = 0;
267 cacheCount = 0;
268 layerCount = 0;
Saurabh Shahaa236822013-04-24 18:07:26 -0700269 fbZ = -1;
270}
271
272void MDPComp::LayerCache::cacheAll(hwc_display_contents_1_t* list) {
273 const int numAppLayers = list->numHwLayers - 1;
274 for(int i = 0; i < numAppLayers; i++) {
275 hnd[i] = list->hwLayers[i].handle;
276 }
277}
278
279void MDPComp::LayerCache::updateCounts(const FrameInfo& curFrame) {
280 mdpCount = curFrame.mdpCount;
281 cacheCount = curFrame.fbCount;
282 layerCount = curFrame.layerCount;
283 fbZ = curFrame.fbZ;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800284}
285
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530286bool MDPComp::isValidDimension(hwc_context_t *ctx, hwc_layer_1_t *layer) {
Saurabh Shah4fdde762013-04-30 18:47:33 -0700287 const int dpy = HWC_DISPLAY_PRIMARY;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800288 private_handle_t *hnd = (private_handle_t *)layer->handle;
289
290 if(!hnd) {
291 ALOGE("%s: layer handle is NULL", __FUNCTION__);
292 return false;
293 }
294
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800295 int hw_w = ctx->dpyAttr[mDpy].xres;
296 int hw_h = ctx->dpyAttr[mDpy].yres;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800297
Saurabh Shah4fdde762013-04-30 18:47:33 -0700298 hwc_rect_t crop = layer->sourceCrop;
299 hwc_rect_t dst = layer->displayFrame;
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800300
301 if(dst.left < 0 || dst.top < 0 || dst.right > hw_w || dst.bottom > hw_h) {
Saurabh Shah4fdde762013-04-30 18:47:33 -0700302 hwc_rect_t scissor = {0, 0, hw_w, hw_h };
303 qhwc::calculate_crop_rects(crop, dst, scissor, layer->transform);
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800304 }
305
Saurabh Shah4fdde762013-04-30 18:47:33 -0700306 int crop_w = crop.right - crop.left;
307 int crop_h = crop.bottom - crop.top;
308 int dst_w = dst.right - dst.left;
309 int dst_h = dst.bottom - dst.top;
310 float w_dscale = ceilf((float)crop_w / (float)dst_w);
311 float h_dscale = ceilf((float)crop_h / (float)dst_h);
312
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800313 /* Workaround for MDP HW limitation in DSI command mode panels where
314 * FPS will not go beyond 30 if buffers on RGB pipes are of width or height
315 * less than 5 pixels
Sravan Kumar D.V.Nad5d9292013-04-24 14:23:04 +0530316 * There also is a HW limilation in MDP, minimum block size is 2x2
317 * Fallback to GPU if height is less than 2.
318 */
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800319 if((crop_w < 5)||(crop_h < 5))
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800320 return false;
321
Saurabh Shah4fdde762013-04-30 18:47:33 -0700322 const uint32_t downscale =
323 qdutils::MDPVersion::getInstance().getMaxMDPDownscale();
324 if(ctx->mMDP.version >= qdutils::MDSS_V5) {
325 /* Workaround for downscales larger than 4x.
326 * Will be removed once decimator block is enabled for MDSS
327 */
328 if(!qdutils::MDPVersion::getInstance().supportsDecimation()) {
329 if(crop_w > MAX_DISPLAY_DIM || w_dscale > downscale ||
330 h_dscale > downscale)
331 return false;
332 } else {
333 if(w_dscale > 64 || h_dscale > 64)
334 return false;
335 }
336 } else { //A-family
337 if(w_dscale > downscale || h_dscale > downscale)
338 return false;
339 }
340
Jeykumar Sankaranc18dbc22013-02-08 14:29:44 -0800341 return true;
342}
343
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700344ovutils::eDest MDPComp::getMdpPipe(hwc_context_t *ctx, ePipeType type,
345 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800346 overlay::Overlay& ov = *ctx->mOverlay;
347 ovutils::eDest mdp_pipe = ovutils::OV_INVALID;
348
349 switch(type) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800350 case MDPCOMP_OV_DMA:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700351 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_DMA, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800352 if(mdp_pipe != ovutils::OV_INVALID) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800353 return mdp_pipe;
354 }
355 case MDPCOMP_OV_ANY:
356 case MDPCOMP_OV_RGB:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700357 mdp_pipe = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800358 if(mdp_pipe != ovutils::OV_INVALID) {
359 return mdp_pipe;
360 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800361
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800362 if(type == MDPCOMP_OV_RGB) {
363 //Requested only for RGB pipe
364 break;
365 }
366 case MDPCOMP_OV_VG:
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700367 return ov.nextPipe(ovutils::OV_MDP_PIPE_VG, mDpy, mixer);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800368 default:
369 ALOGE("%s: Invalid pipe type",__FUNCTION__);
370 return ovutils::OV_INVALID;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800371 };
372 return ovutils::OV_INVALID;
373}
374
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800375bool MDPComp::isFrameDoable(hwc_context_t *ctx) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700376 bool ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700377 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800378
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800379 if(!isEnabled()) {
380 ALOGD_IF(isDebug(),"%s: MDP Comp. not enabled.", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700381 ret = false;
Saurabh Shahd4e65852013-06-17 11:33:53 -0700382 } else if(qdutils::MDPVersion::getInstance().is8x26() &&
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700383 ctx->mVideoTransFlag && ctx->mVirtualDisplay->isConnected()) {
Saurabh Shahd4e65852013-06-17 11:33:53 -0700384 //1 Padding round to shift pipes across mixers
385 ALOGD_IF(isDebug(),"%s: MDP Comp. video transition padding round",
386 __FUNCTION__);
387 ret = false;
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700388 } else if(ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isConfiguring ||
389 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isConfiguring) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800390 ALOGD_IF( isDebug(),"%s: External Display connection is pending",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800391 __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700392 ret = false;
Saurabh Shahaa236822013-04-24 18:07:26 -0700393 } else if(ctx->isPaddingRound) {
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700394 ctx->isPaddingRound = false;
395 ALOGD_IF(isDebug(), "%s: padding round",__FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700396 ret = false;
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700397 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700398 return ret;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800399}
400
401/* Checks for conditions where all the layers marked for MDP comp cannot be
402 * bypassed. On such conditions we try to bypass atleast YUV layers */
403bool MDPComp::isFullFrameDoable(hwc_context_t *ctx,
404 hwc_display_contents_1_t* list){
405
Saurabh Shahaa236822013-04-24 18:07:26 -0700406 const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800407
Saurabh Shah2d998a92013-05-14 17:55:58 -0700408 if(sIdleFallBack) {
409 ALOGD_IF(isDebug(), "%s: Idle fallback dpy %d",__FUNCTION__, mDpy);
410 return false;
411 }
412
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800413 if(mDpy > HWC_DISPLAY_PRIMARY){
414 ALOGD_IF(isDebug(), "%s: Cannot support External display(s)",
415 __FUNCTION__);
416 return false;
417 }
418
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800419 if(isSkipPresent(ctx, mDpy)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700420 ALOGD_IF(isDebug(),"%s: SKIP present: %d",
421 __FUNCTION__,
422 isSkipPresent(ctx, mDpy));
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800423 return false;
424 }
425
Saurabh Shah9f084ad2013-05-02 11:28:09 -0700426 if(ctx->listStats[mDpy].needsAlphaScale
427 && ctx->mMDP.version < qdutils::MDSS_V5) {
428 ALOGD_IF(isDebug(), "%s: frame needs alpha downscaling",__FUNCTION__);
429 return false;
430 }
431
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800432 //MDP composition is not efficient if layer needs rotator.
433 for(int i = 0; i < numAppLayers; ++i) {
434 // As MDP h/w supports flip operation, use MDP comp only for
435 // 180 transforms. Fail for any transform involving 90 (90, 270).
436 hwc_layer_1_t* layer = &list->hwLayers[i];
437 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800438
Saurabh Shah4fdde762013-04-30 18:47:33 -0700439 if((layer->transform & HWC_TRANSFORM_ROT_90) && !isYuvBuffer(hnd)) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800440 ALOGD_IF(isDebug(), "%s: orientation involved",__FUNCTION__);
441 return false;
442 }
443
Saurabh Shah4fdde762013-04-30 18:47:33 -0700444 if(!isValidDimension(ctx,layer)) {
445 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
446 __FUNCTION__);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800447 return false;
448 }
Prabhanjan Kandula9fb032a2013-06-18 17:37:22 +0530449
450 //For 8x26 with panel width>1k, if RGB layer needs HFLIP fail mdp comp
451 // may not need it if Gfx pre-rotation can handle all flips & rotations
452 if(qdutils::MDPVersion::getInstance().is8x26() &&
453 (ctx->dpyAttr[mDpy].xres > 1024) &&
454 (layer->transform & HWC_TRANSFORM_FLIP_H) &&
455 (!isYuvBuffer(hnd)))
456 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800457 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700458
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700459 if(ctx->mAD->isDoable()) {
460 return false;
461 }
462
Saurabh Shahaa236822013-04-24 18:07:26 -0700463 //If all above hard conditions are met we can do full or partial MDP comp.
464 bool ret = false;
465 if(fullMDPComp(ctx, list)) {
466 ret = true;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700467 } else if(partialMDPComp(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700468 ret = true;
469 }
470 return ret;
471}
472
473bool MDPComp::fullMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
474 //Setup mCurrentFrame
475 mCurrentFrame.mdpCount = mCurrentFrame.layerCount;
476 mCurrentFrame.fbCount = 0;
477 mCurrentFrame.fbZ = -1;
478 memset(&mCurrentFrame.isFBComposed, 0, sizeof(mCurrentFrame.isFBComposed));
479
480 int mdpCount = mCurrentFrame.mdpCount;
481 if(mdpCount > sMaxPipesPerMixer) {
482 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
483 return false;
484 }
485
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700486 if(!arePipesAvailable(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700487 return false;
488 }
489
490 return true;
491}
492
493bool MDPComp::partialMDPComp(hwc_context_t *ctx, hwc_display_contents_1_t* list)
494{
495 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
Jeykumar Sankaran24c199d2013-05-24 09:40:36 -0700496
497 if(!sEnableMixedMode) {
498 //Mixed mode is disabled. No need to even try caching.
499 return false;
500 }
501
Saurabh Shahaa236822013-04-24 18:07:26 -0700502 //Setup mCurrentFrame
503 mCurrentFrame.reset(numAppLayers);
504 updateLayerCache(ctx, list);
505 updateYUV(ctx, list);
506 batchLayers(); //sets up fbZ also
507
508 int mdpCount = mCurrentFrame.mdpCount;
509 if(mdpCount > (sMaxPipesPerMixer - 1)) { // -1 since FB is used
510 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
511 return false;
512 }
513
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700514 if(!arePipesAvailable(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700515 return false;
516 }
517
518 return true;
519}
520
521bool MDPComp::isOnlyVideoDoable(hwc_context_t *ctx,
522 hwc_display_contents_1_t* list){
523 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
524 mCurrentFrame.reset(numAppLayers);
525 updateYUV(ctx, list);
Saurabh Shah4fdde762013-04-30 18:47:33 -0700526 int mdpCount = mCurrentFrame.mdpCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700527 int fbNeeded = int(mCurrentFrame.fbCount != 0);
528
529 if(!isYuvPresent(ctx, mDpy)) {
530 return false;
531 }
532
Saurabh Shah4fdde762013-04-30 18:47:33 -0700533 if(!mdpCount)
534 return false;
535
Saurabh Shahaa236822013-04-24 18:07:26 -0700536 if(mdpCount > (sMaxPipesPerMixer - fbNeeded)) {
537 ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
538 return false;
539 }
540
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700541 if(!arePipesAvailable(ctx, list)) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700542 return false;
543 }
544
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800545 return true;
546}
547
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800548/* Checks for conditions where YUV layers cannot be bypassed */
549bool MDPComp::isYUVDoable(hwc_context_t* ctx, hwc_layer_1_t* layer) {
Saurabh Shahe2474082013-05-15 16:32:13 -0700550 bool extAnimBlockFeature = mDpy && ctx->listStats[mDpy].isDisplayAnimating;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800551
Saurabh Shahe2474082013-05-15 16:32:13 -0700552 if(isSkipLayer(layer) && !extAnimBlockFeature) {
553 ALOGD_IF(isDebug(), "%s: Video marked SKIP dpy %d", __FUNCTION__, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800554 return false;
555 }
556
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800557 if(isSecuring(ctx, layer)) {
558 ALOGD_IF(isDebug(), "%s: MDP securing is active", __FUNCTION__);
559 return false;
560 }
561
Saurabh Shah4fdde762013-04-30 18:47:33 -0700562 if(!isValidDimension(ctx, layer)) {
563 ALOGD_IF(isDebug(), "%s: Buffer is of invalid width",
564 __FUNCTION__);
565 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800566 }
Saurabh Shah4fdde762013-04-30 18:47:33 -0700567
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800568 return true;
569}
570
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800571void MDPComp::batchLayers() {
572 /* Idea is to keep as many contiguous non-updating(cached) layers in FB and
573 * send rest of them through MDP. NEVER mark an updating layer for caching.
574 * But cached ones can be marked for MDP*/
575
576 int maxBatchStart = -1;
577 int maxBatchCount = 0;
578
579 /* All or Nothing is cached. No batching needed */
Saurabh Shahaa236822013-04-24 18:07:26 -0700580 if(!mCurrentFrame.fbCount) {
581 mCurrentFrame.fbZ = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800582 return;
Saurabh Shahaa236822013-04-24 18:07:26 -0700583 }
584 if(!mCurrentFrame.mdpCount) {
585 mCurrentFrame.fbZ = 0;
586 return;
587 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800588
589 /* Search for max number of contiguous (cached) layers */
590 int i = 0;
591 while (i < mCurrentFrame.layerCount) {
592 int count = 0;
593 while(mCurrentFrame.isFBComposed[i] && i < mCurrentFrame.layerCount) {
594 count++; i++;
595 }
596 if(count > maxBatchCount) {
597 maxBatchCount = count;
598 maxBatchStart = i - count;
Saurabh Shahaa236822013-04-24 18:07:26 -0700599 mCurrentFrame.fbZ = maxBatchStart;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800600 }
601 if(i < mCurrentFrame.layerCount) i++;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800602 }
603
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800604 /* reset rest of the layers for MDP comp */
605 for(int i = 0; i < mCurrentFrame.layerCount; i++) {
606 if(i != maxBatchStart){
607 mCurrentFrame.isFBComposed[i] = false;
608 } else {
609 i += maxBatchCount;
610 }
611 }
612
613 mCurrentFrame.fbCount = maxBatchCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700614 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
615 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800616
617 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
618 mCurrentFrame.fbCount);
619}
Saurabh Shah85234ec2013-04-12 17:09:00 -0700620
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800621void MDPComp::updateLayerCache(hwc_context_t* ctx,
622 hwc_display_contents_1_t* list) {
623
624 int numAppLayers = ctx->listStats[mDpy].numAppLayers;
625 int numCacheableLayers = 0;
626
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800627 for(int i = 0; i < numAppLayers; i++) {
628 if (mCachedFrame.hnd[i] == list->hwLayers[i].handle) {
629 numCacheableLayers++;
630 mCurrentFrame.isFBComposed[i] = true;
631 } else {
Saurabh Shahaa236822013-04-24 18:07:26 -0700632 mCurrentFrame.isFBComposed[i] = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800633 mCachedFrame.hnd[i] = list->hwLayers[i].handle;
634 }
635 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700636
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800637 mCurrentFrame.fbCount = numCacheableLayers;
Saurabh Shahaa236822013-04-24 18:07:26 -0700638 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
639 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800640 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__, numCacheableLayers);
641}
642
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800643void MDPComp::updateYUV(hwc_context_t* ctx, hwc_display_contents_1_t* list) {
644
645 int nYuvCount = ctx->listStats[mDpy].yuvCount;
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700646 if(!nYuvCount && mDpy) {
647 //Reset "No animation on external display" related parameters.
648 ctx->mPrevCropVideo.left = ctx->mPrevCropVideo.top =
649 ctx->mPrevCropVideo.right = ctx->mPrevCropVideo.bottom = 0;
650 ctx->mPrevDestVideo.left = ctx->mPrevDestVideo.top =
651 ctx->mPrevDestVideo.right = ctx->mPrevDestVideo.bottom = 0;
652 ctx->mPrevTransformVideo = 0;
653 return;
654 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800655 for(int index = 0;index < nYuvCount; index++){
656 int nYuvIndex = ctx->listStats[mDpy].yuvIndices[index];
657 hwc_layer_1_t* layer = &list->hwLayers[nYuvIndex];
658
659 if(!isYUVDoable(ctx, layer)) {
660 if(!mCurrentFrame.isFBComposed[nYuvIndex]) {
661 mCurrentFrame.isFBComposed[nYuvIndex] = true;
662 mCurrentFrame.fbCount++;
663 }
664 } else {
665 if(mCurrentFrame.isFBComposed[nYuvIndex]) {
666 mCurrentFrame.isFBComposed[nYuvIndex] = false;
667 mCurrentFrame.fbCount--;
668 }
669 }
670 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700671
672 mCurrentFrame.mdpCount = mCurrentFrame.layerCount -
673 mCurrentFrame.fbCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800674 ALOGD_IF(isDebug(),"%s: cached count: %d",__FUNCTION__,
675 mCurrentFrame.fbCount);
676}
677
Saurabh Shahaa236822013-04-24 18:07:26 -0700678bool MDPComp::programMDP(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800679 if(!allocLayerPipes(ctx, list)) {
680 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
Saurabh Shahaa236822013-04-24 18:07:26 -0700681 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800682 }
683
Saurabh Shahaa236822013-04-24 18:07:26 -0700684 bool fbBatch = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800685 for (int index = 0, mdpNextZOrder = 0; index < mCurrentFrame.layerCount;
Saurabh Shahaa236822013-04-24 18:07:26 -0700686 index++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800687 if(!mCurrentFrame.isFBComposed[index]) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800688 int mdpIndex = mCurrentFrame.layerToMDP[index];
689 hwc_layer_1_t* layer = &list->hwLayers[index];
690
691 MdpPipeInfo* cur_pipe = mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
692 cur_pipe->zOrder = mdpNextZOrder++;
693
694 if(configure(ctx, layer, mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
695 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
696 layer %d",__FUNCTION__, index);
Saurabh Shahaa236822013-04-24 18:07:26 -0700697 return false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800698 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700699 } else if(fbBatch == false) {
700 mdpNextZOrder++;
701 fbBatch = true;
702 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800703 }
704
Saurabh Shahaa236822013-04-24 18:07:26 -0700705 return true;
706}
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800707
Saurabh Shahaa236822013-04-24 18:07:26 -0700708bool MDPComp::programYUV(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
709 if(!allocLayerPipes(ctx, list)) {
710 ALOGD_IF(isDebug(), "%s: Unable to allocate MDP pipes", __FUNCTION__);
711 return false;
712 }
713 //If we are in this block, it means we have yuv + rgb layers both
714 int mdpIdx = 0;
715 for (int index = 0; index < mCurrentFrame.layerCount; index++) {
716 if(!mCurrentFrame.isFBComposed[index]) {
717 hwc_layer_1_t* layer = &list->hwLayers[index];
718 int mdpIndex = mCurrentFrame.layerToMDP[index];
719 MdpPipeInfo* cur_pipe =
720 mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
721 cur_pipe->zOrder = mdpIdx++;
722
723 if(configure(ctx, layer,
724 mCurrentFrame.mdpToLayer[mdpIndex]) != 0 ){
725 ALOGD_IF(isDebug(), "%s: Failed to configure overlay for \
726 layer %d",__FUNCTION__, index);
727 return false;
728 }
729 }
730 }
731 return true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800732}
733
734int MDPComp::prepare(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700735 const int numLayers = ctx->listStats[mDpy].numAppLayers;
Ramkumar Radhakrishnanc5893f12013-06-06 19:43:53 -0700736
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530737 { //LOCK SCOPE BEGIN
738 Locker::Autolock _l(mMdpCompLock);
Prabhanjan Kandula088bd892013-07-02 23:47:13 +0530739
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530740 //reset old data
Saurabh Shahaa236822013-04-24 18:07:26 -0700741 mCurrentFrame.reset(numLayers);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800742
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530743 //number of app layers exceeds MAX_NUM_APP_LAYERS fall back to GPU
744 //do not cache the information for next draw cycle.
745 if(numLayers > MAX_NUM_APP_LAYERS) {
746 mCachedFrame.updateCounts(mCurrentFrame);
747 ALOGD_IF(isDebug(), "%s: Number of App layers exceeded the limit ",
748 __FUNCTION__);
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700749 return -1;
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530750 }
751
752 //Hard conditions, if not met, cannot do MDP comp
753 if(!isFrameDoable(ctx)) {
754 ALOGD_IF( isDebug(),"%s: MDP Comp not possible for this frame",
755 __FUNCTION__);
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700756 reset(numLayers, list);
757 return -1;
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530758 }
759
760 //Check whether layers marked for MDP Composition is actually doable.
761 if(isFullFrameDoable(ctx, list)){
762 mCurrentFrame.map();
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700763 //Configure framebuffer first if applicable
764 if(mCurrentFrame.fbZ >= 0) {
765 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list,
766 mCurrentFrame.fbZ)) {
767 ALOGE("%s configure framebuffer failed", __func__);
768 reset(numLayers, list);
769 return -1;
770 }
771 }
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530772 //Acquire and Program MDP pipes
773 if(!programMDP(ctx, list)) {
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700774 reset(numLayers, list);
775 return -1;
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530776 } else { //Success
777 //Any change in composition types needs an FB refresh
778 mCurrentFrame.needsRedraw = false;
779 if(mCurrentFrame.fbCount &&
780 ((mCurrentFrame.mdpCount != mCachedFrame.mdpCount) ||
781 (mCurrentFrame.fbCount != mCachedFrame.cacheCount) ||
782 (mCurrentFrame.fbZ != mCachedFrame.fbZ) ||
783 (!mCurrentFrame.mdpCount) ||
784 (list->flags & HWC_GEOMETRY_CHANGED) ||
785 isSkipPresent(ctx, mDpy) ||
786 (mDpy > HWC_DISPLAY_PRIMARY))) {
787 mCurrentFrame.needsRedraw = true;
788 }
Saurabh Shahaa236822013-04-24 18:07:26 -0700789 }
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530790 } else if(isOnlyVideoDoable(ctx, list)) {
791 //All layers marked for MDP comp cannot be bypassed.
792 //Try to compose atleast YUV layers through MDP comp and let
793 //all the RGB layers compose in FB
794 //Destination over
795 mCurrentFrame.fbZ = -1;
796 if(mCurrentFrame.fbCount)
797 mCurrentFrame.fbZ = mCurrentFrame.mdpCount;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800798
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530799 mCurrentFrame.map();
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700800
801 //Configure framebuffer first if applicable
802 if(mCurrentFrame.fbZ >= 0) {
803 if(!ctx->mFBUpdate[mDpy]->prepare(ctx, list, mCurrentFrame.fbZ)) {
804 ALOGE("%s configure framebuffer failed", __func__);
805 reset(numLayers, list);
806 return -1;
807 }
808 }
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530809 if(!programYUV(ctx, list)) {
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700810 reset(numLayers, list);
811 return -1;
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530812 }
813 } else {
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700814 reset(numLayers, list);
815 return -1;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800816 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800817
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530818 //UpdateLayerFlags
819 setMDPCompLayerFlags(ctx, list);
820 mCachedFrame.updateCounts(mCurrentFrame);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800821
Prabhanjan Kandula25469a52013-07-12 16:19:31 +0530822 } //LOCK SCOPE END. dump also need this lock.
823 // unlock it before calling dump function to avoid deadlock
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800824 if(isDebug()) {
Saurabh Shahaa236822013-04-24 18:07:26 -0700825 ALOGD("GEOMETRY change: %d", (list->flags & HWC_GEOMETRY_CHANGED));
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800826 android::String8 sDump("");
827 dump(sDump);
828 ALOGE("%s",sDump.string());
829 }
830
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700831 return 0;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800832}
833
834//=============MDPCompLowRes===================================================
835
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700836/*
837 * Configures pipe(s) for MDP composition
838 */
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800839int MDPCompLowRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800840 PipeLayerPair& PipeLayerPair) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800841 MdpPipeInfoLowRes& mdp_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800842 *(static_cast<MdpPipeInfoLowRes*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -0800843 eMdpFlags mdpFlags = OV_MDP_BACKEND_COMPOSITION;
844 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
845 eIsFg isFg = IS_FG_OFF;
846 eDest dest = mdp_info.index;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700847
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800848 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipe: %d",
849 __FUNCTION__, layer, zOrder, dest);
850
851 return configureLowRes(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
852 &PipeLayerPair.rot);
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700853}
854
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700855bool MDPCompLowRes::arePipesAvailable(hwc_context_t *ctx,
856 hwc_display_contents_1_t* list) {
857 overlay::Overlay& ov = *ctx->mOverlay;
858 int numPipesNeeded = mCurrentFrame.mdpCount;
859 int availPipes = ov.availablePipes(mDpy, Overlay::MIXER_DEFAULT);
860
861 //Reserve pipe for FB
862 if(mCurrentFrame.fbCount)
863 availPipes -= 1;
864
865 if(numPipesNeeded > availPipes) {
866 ALOGD_IF(isDebug(), "%s: Insufficient pipes, dpy %d needed %d, avail %d",
867 __FUNCTION__, mDpy, numPipesNeeded, availPipes);
868 return false;
869 }
870
871 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700872}
873
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800874bool MDPCompLowRes::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700875 hwc_display_contents_1_t* list) {
876 for(int index = 0; index < mCurrentFrame.layerCount; index++) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700877
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800878 if(mCurrentFrame.isFBComposed[index]) continue;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700879
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800880 hwc_layer_1_t* layer = &list->hwLayers[index];
881 private_handle_t *hnd = (private_handle_t *)layer->handle;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800882 int mdpIndex = mCurrentFrame.layerToMDP[index];
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800883 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800884 info.pipeInfo = new MdpPipeInfoLowRes;
Saurabh Shahacf10202013-02-26 10:15:15 -0800885 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800886 MdpPipeInfoLowRes& pipe_info = *(MdpPipeInfoLowRes*)info.pipeInfo;
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800887 ePipeType type = MDPCOMP_OV_ANY;
888
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700889 if(isYuvBuffer(hnd)) {
890 type = MDPCOMP_OV_VG;
Saurabh Shah8a117932013-05-23 12:48:13 -0700891 } else if(!qhwc::needsScaling(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -0700892 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
893 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800894 type = MDPCOMP_OV_DMA;
895 }
896
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700897 pipe_info.index = getMdpPipe(ctx, type, Overlay::MIXER_DEFAULT);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800898 if(pipe_info.index == ovutils::OV_INVALID) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -0700899 ALOGD_IF(isDebug(), "%s: Unable to get pipe type = %d",
900 __FUNCTION__, (int) type);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500901 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700902 }
903 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700904 return true;
905}
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700906
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800907bool MDPCompLowRes::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700908
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800909 if(!isEnabled()) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500910 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
911 return true;
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800912 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700913
914 if(!ctx || !list) {
915 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500916 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700917 }
918
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +0530919 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
920 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
921 return true;
922 }
923
Prabhanjan Kandula088bd892013-07-02 23:47:13 +0530924 Locker::Autolock _l(mMdpCompLock);
925
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500926 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -0700927 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500928 idleInvalidator->markForSleep();
929
930 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800931 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700932
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800933 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
934 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700935 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800936 if(mCurrentFrame.isFBComposed[i]) continue;
937
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700938 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -0800939 private_handle_t *hnd = (private_handle_t *)layer->handle;
940 if(!hnd) {
941 ALOGE("%s handle null", __FUNCTION__);
942 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700943 }
944
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800945 int mdpIndex = mCurrentFrame.layerToMDP[i];
946
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800947 MdpPipeInfoLowRes& pipe_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800948 *(MdpPipeInfoLowRes*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800949 ovutils::eDest dest = pipe_info.index;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800950 if(dest == ovutils::OV_INVALID) {
951 ALOGE("%s: Invalid pipe index (%d)", __FUNCTION__, dest);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500952 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700953 }
954
Saurabh Shahacf10202013-02-26 10:15:15 -0800955 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
956 continue;
957 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700958
Saurabh Shahacf10202013-02-26 10:15:15 -0800959 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800960 using pipe: %d", __FUNCTION__, layer,
961 hnd, dest );
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700962
Saurabh Shahacf10202013-02-26 10:15:15 -0800963 int fd = hnd->fd;
964 uint32_t offset = hnd->offset;
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700965
966 if(ctx->mAD->isModeOn()) {
967 if(ctx->mAD->draw(ctx, fd, offset)) {
968 fd = ctx->mAD->getDstFd(ctx);
969 offset = ctx->mAD->getDstOffset(ctx);
970 }
971 }
972
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800973 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -0800974 if(rot) {
975 if(!rot->queueBuffer(fd, offset))
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500976 return false;
Saurabh Shahacf10202013-02-26 10:15:15 -0800977 fd = rot->getDstMemId();
978 offset = rot->getDstOffset();
979 }
980
981 if (!ov.queueBuffer(fd, offset, dest)) {
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +0530982 ALOGE("%s: queueBuffer failed for display:%d ", __FUNCTION__, mDpy);
Saurabh Shahacf10202013-02-26 10:15:15 -0800983 return false;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700984 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500985
986 layerProp[i].mFlags &= ~HWC_MDPCOMP;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700987 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500988 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700989}
990
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800991//=============MDPCompHighRes===================================================
992
993int MDPCompHighRes::pipesNeeded(hwc_context_t *ctx,
Saurabh Shahaf5f5972013-07-30 13:56:35 -0700994 hwc_display_contents_1_t* list,
995 int mixer) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800996 int pipesNeeded = 0;
Saurabh Shah67a38c32013-06-10 16:23:15 -0700997 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -0700998
999 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001000
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001001 for(int i = 0; i < mCurrentFrame.layerCount; ++i) {
1002 if(!mCurrentFrame.isFBComposed[i]) {
1003 hwc_layer_1_t* layer = &list->hwLayers[i];
1004 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001005 if(mixer == Overlay::MIXER_LEFT && dst.left < lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001006 pipesNeeded++;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001007 } else if(mixer == Overlay::MIXER_RIGHT && dst.right > lSplit) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001008 pipesNeeded++;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001009 }
1010 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001011 }
1012 return pipesNeeded;
1013}
1014
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001015bool MDPCompHighRes::arePipesAvailable(hwc_context_t *ctx,
1016 hwc_display_contents_1_t* list) {
1017 overlay::Overlay& ov = *ctx->mOverlay;
1018
1019 for(int i = 0; i < Overlay::MIXER_MAX; i++) {
1020 int numPipesNeeded = pipesNeeded(ctx, list, i);
1021 int availPipes = ov.availablePipes(mDpy, i);
1022
1023 //Reserve pipe(s)for FB
1024 if(mCurrentFrame.fbCount)
1025 availPipes -= 1;
1026
1027 if(numPipesNeeded > availPipes) {
1028 ALOGD_IF(isDebug(), "%s: Insufficient pipes for "
1029 "dpy %d mixer %d needed %d, avail %d",
1030 __FUNCTION__, mDpy, i, numPipesNeeded, availPipes);
1031 return false;
1032 }
1033 }
1034 return true;
1035}
1036
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001037bool MDPCompHighRes::acquireMDPPipes(hwc_context_t *ctx, hwc_layer_1_t* layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001038 MdpPipeInfoHighRes& pipe_info,
1039 ePipeType type) {
1040 const int xres = ctx->dpyAttr[mDpy].xres;
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001041 const int lSplit = getLeftSplit(ctx, mDpy);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001042
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001043 hwc_rect_t dst = layer->displayFrame;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001044 pipe_info.lIndex = ovutils::OV_INVALID;
1045 pipe_info.rIndex = ovutils::OV_INVALID;
1046
1047 if (dst.left < lSplit) {
1048 pipe_info.lIndex = getMdpPipe(ctx, type, Overlay::MIXER_LEFT);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001049 if(pipe_info.lIndex == ovutils::OV_INVALID)
1050 return false;
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001051 }
1052
1053 if(dst.right > lSplit) {
1054 pipe_info.rIndex = getMdpPipe(ctx, type, Overlay::MIXER_RIGHT);
1055 if(pipe_info.rIndex == ovutils::OV_INVALID)
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001056 return false;
1057 }
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001058
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001059 return true;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001060}
1061
1062bool MDPCompHighRes::allocLayerPipes(hwc_context_t *ctx,
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001063 hwc_display_contents_1_t* list) {
1064 for(int index = 0 ; index < mCurrentFrame.layerCount; index++) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001065
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001066 if(mCurrentFrame.isFBComposed[index]) continue;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001067
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001068 hwc_layer_1_t* layer = &list->hwLayers[index];
1069 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shah0d65dbe2013-06-06 18:33:16 -07001070 int mdpIndex = mCurrentFrame.layerToMDP[index];
1071 PipeLayerPair& info = mCurrentFrame.mdpToLayer[mdpIndex];
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001072 info.pipeInfo = new MdpPipeInfoHighRes;
Saurabh Shah9e3adb22013-03-26 11:16:27 -07001073 info.rot = NULL;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001074 MdpPipeInfoHighRes& pipe_info = *(MdpPipeInfoHighRes*)info.pipeInfo;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001075 ePipeType type = MDPCOMP_OV_ANY;
1076
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001077 if(isYuvBuffer(hnd)) {
1078 type = MDPCOMP_OV_VG;
Saurabh Shah8a117932013-05-23 12:48:13 -07001079 } else if(!qhwc::needsScaling(ctx, layer, mDpy)
Saurabh Shah85234ec2013-04-12 17:09:00 -07001080 && Overlay::getDMAMode() != Overlay::DMA_BLOCK_MODE
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001081 && ctx->mMDP.version >= qdutils::MDSS_V5) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001082 type = MDPCOMP_OV_DMA;
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001083 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001084
1085 if(!acquireMDPPipes(ctx, layer, pipe_info, type)) {
Saurabh Shahe51f8ca2013-05-06 17:26:16 -07001086 ALOGD_IF(isDebug(), "%s: Unable to get pipe for type = %d",
1087 __FUNCTION__, (int) type);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001088 return false;
1089 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001090 }
1091 return true;
1092}
Saurabh Shahaf5f5972013-07-30 13:56:35 -07001093
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001094/*
1095 * Configures pipe(s) for MDP composition
1096 */
1097int MDPCompHighRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shah67a38c32013-06-10 16:23:15 -07001098 PipeLayerPair& PipeLayerPair) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001099 MdpPipeInfoHighRes& mdp_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001100 *(static_cast<MdpPipeInfoHighRes*>(PipeLayerPair.pipeInfo));
Saurabh Shahacf10202013-02-26 10:15:15 -08001101 eZorder zOrder = static_cast<eZorder>(mdp_info.zOrder);
1102 eIsFg isFg = IS_FG_OFF;
1103 eMdpFlags mdpFlagsL = OV_MDP_BACKEND_COMPOSITION;
1104 eDest lDest = mdp_info.lIndex;
1105 eDest rDest = mdp_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001106
1107 ALOGD_IF(isDebug(),"%s: configuring: layer: %p z_order: %d dest_pipeL: %d"
1108 "dest_pipeR: %d",__FUNCTION__, layer, zOrder, lDest, rDest);
1109
1110 return configureHighRes(ctx, layer, mDpy, mdpFlagsL, zOrder, isFg, lDest,
1111 rDest, &PipeLayerPair.rot);
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001112}
1113
1114bool MDPCompHighRes::draw(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
1115
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001116 if(!isEnabled()) {
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001117 ALOGD_IF(isDebug(),"%s: MDP Comp not configured", __FUNCTION__);
1118 return true;
1119 }
1120
1121 if(!ctx || !list) {
1122 ALOGE("%s: invalid contxt or list",__FUNCTION__);
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001123 return false;
1124 }
1125
Prabhanjan Kandula08222fc2013-07-10 17:20:59 +05301126 if(ctx->listStats[mDpy].numAppLayers > MAX_NUM_APP_LAYERS) {
1127 ALOGD_IF(isDebug(),"%s: Exceeding max layer count", __FUNCTION__);
1128 return true;
1129 }
1130
Prabhanjan Kandula088bd892013-07-02 23:47:13 +05301131 Locker::Autolock _l(mMdpCompLock);
1132
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001133 /* reset Invalidator */
Saurabh Shah2d998a92013-05-14 17:55:58 -07001134 if(idleInvalidator && !sIdleFallBack && mCurrentFrame.mdpCount)
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001135 idleInvalidator->markForSleep();
1136
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001137 overlay::Overlay& ov = *ctx->mOverlay;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001138 LayerProp *layerProp = ctx->layerProp[mDpy];
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001139
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001140 int numHwLayers = ctx->listStats[mDpy].numAppLayers;
1141 for(int i = 0; i < numHwLayers && mCurrentFrame.mdpCount; i++ )
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001142 {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001143 if(mCurrentFrame.isFBComposed[i]) continue;
1144
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001145 hwc_layer_1_t *layer = &list->hwLayers[i];
Saurabh Shahacf10202013-02-26 10:15:15 -08001146 private_handle_t *hnd = (private_handle_t *)layer->handle;
1147 if(!hnd) {
1148 ALOGE("%s handle null", __FUNCTION__);
1149 return false;
1150 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001151
1152 if(!(layerProp[i].mFlags & HWC_MDPCOMP)) {
1153 continue;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001154 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001155
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001156 int mdpIndex = mCurrentFrame.layerToMDP[i];
1157
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001158 MdpPipeInfoHighRes& pipe_info =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001159 *(MdpPipeInfoHighRes*)mCurrentFrame.mdpToLayer[mdpIndex].pipeInfo;
1160 Rotator *rot = mCurrentFrame.mdpToLayer[mdpIndex].rot;
Saurabh Shahacf10202013-02-26 10:15:15 -08001161
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001162 ovutils::eDest indexL = pipe_info.lIndex;
1163 ovutils::eDest indexR = pipe_info.rIndex;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001164
Saurabh Shahacf10202013-02-26 10:15:15 -08001165 int fd = hnd->fd;
1166 int offset = hnd->offset;
1167
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001168 if(ctx->mAD->isModeOn()) {
1169 if(ctx->mAD->draw(ctx, fd, offset)) {
1170 fd = ctx->mAD->getDstFd(ctx);
1171 offset = ctx->mAD->getDstOffset(ctx);
1172 }
1173 }
1174
Saurabh Shahacf10202013-02-26 10:15:15 -08001175 if(rot) {
1176 rot->queueBuffer(fd, offset);
1177 fd = rot->getDstMemId();
1178 offset = rot->getDstOffset();
1179 }
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001180
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001181 //************* play left mixer **********
1182 if(indexL != ovutils::OV_INVALID) {
1183 ovutils::eDest destL = (ovutils::eDest)indexL;
Saurabh Shahacf10202013-02-26 10:15:15 -08001184 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001185 using pipe: %d", __FUNCTION__, layer, hnd, indexL );
Saurabh Shahacf10202013-02-26 10:15:15 -08001186 if (!ov.queueBuffer(fd, offset, destL)) {
1187 ALOGE("%s: queueBuffer failed for left mixer", __FUNCTION__);
1188 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001189 }
1190 }
1191
1192 //************* play right mixer **********
1193 if(indexR != ovutils::OV_INVALID) {
1194 ovutils::eDest destR = (ovutils::eDest)indexR;
Saurabh Shahacf10202013-02-26 10:15:15 -08001195 ALOGD_IF(isDebug(),"%s: MDP Comp: Drawing layer: %p hnd: %p \
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001196 using pipe: %d", __FUNCTION__, layer, hnd, indexR );
Saurabh Shahacf10202013-02-26 10:15:15 -08001197 if (!ov.queueBuffer(fd, offset, destR)) {
1198 ALOGE("%s: queueBuffer failed for right mixer", __FUNCTION__);
1199 return false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001200 }
1201 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001202
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001203 layerProp[i].mFlags &= ~HWC_MDPCOMP;
1204 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001205
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001206 return true;
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001207}
Naseer Ahmed7c958d42012-07-31 18:57:03 -07001208}; //namespace
1209