blob: b0ea0fcd33a38e28cf4fc55b0e558d1ded36498c [file] [log] [blame]
Naseer Ahmed29a26812012-06-14 00:56:20 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08003 * Copyright (C) 2012-2013, The Linux Foundation All rights reserved.
4 *
5 * Not a Contribution, Apache license notifications and license are retained
6 * for attribution purposes only.
Naseer Ahmed29a26812012-06-14 00:56:20 -07007 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
Arun Kumar K.R361da4f2012-11-28 10:42:59 -080020#define HWC_UTILS_DEBUG 0
Naseer Ahmed758bfc52012-11-28 17:02:08 -050021#include <sys/ioctl.h>
Naseer Ahmed66e97882013-03-19 20:42:11 -040022#include <linux/fb.h>
Saurabh Shah86c17292013-02-08 15:24:13 -080023#include <binder/IServiceManager.h>
Naseer Ahmed5b6708a2012-08-02 13:46:08 -070024#include <EGL/egl.h>
Saurabh Shahfc2acbe2012-08-17 19:47:52 -070025#include <cutils/properties.h>
26#include <gralloc_priv.h>
Naseer Ahmed758bfc52012-11-28 17:02:08 -050027#include <overlay.h>
Saurabh Shahacf10202013-02-26 10:15:15 -080028#include <overlayRotator.h>
Naseer Ahmed29a26812012-06-14 00:56:20 -070029#include "hwc_utils.h"
Naseer Ahmed54821fe2012-11-28 18:44:38 -050030#include "hwc_mdpcomp.h"
Saurabh Shahcf053c62012-12-13 12:32:55 -080031#include "hwc_fbupdate.h"
Naseer Ahmeda87da602012-07-01 23:54:19 -070032#include "mdp_version.h"
Arun Kumar K.R361da4f2012-11-28 10:42:59 -080033#include "hwc_copybit.h"
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -070034#include "hwc_dump_layers.h"
Saurabh Shah56f610d2012-08-07 15:27:06 -070035#include "external.h"
Saurabh Shah86c17292013-02-08 15:24:13 -080036#include "hwc_qclient.h"
Saurabh Shah56f610d2012-08-07 15:27:06 -070037#include "QService.h"
Arun Kumar K.R361da4f2012-11-28 10:42:59 -080038#include "comptype.h"
Saurabh Shah86c17292013-02-08 15:24:13 -080039
40using namespace qClient;
41using namespace qService;
42using namespace android;
Saurabh Shahacf10202013-02-26 10:15:15 -080043using namespace overlay;
44using namespace overlay::utils;
45namespace ovutils = overlay::utils;
Saurabh Shah86c17292013-02-08 15:24:13 -080046
Naseer Ahmed29a26812012-06-14 00:56:20 -070047namespace qhwc {
Naseer Ahmed72cf9762012-07-21 12:17:13 -070048
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -080049static int openFramebufferDevice(hwc_context_t *ctx)
Naseer Ahmed72cf9762012-07-21 12:17:13 -070050{
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -080051 struct fb_fix_screeninfo finfo;
52 struct fb_var_screeninfo info;
53
54 int fb_fd = openFb(HWC_DISPLAY_PRIMARY);
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +053055 if(fb_fd < 0) {
56 ALOGE("%s: Error Opening FB : %s", __FUNCTION__, strerror(errno));
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -080057 return -errno;
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +053058 }
59
60 if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &info) == -1) {
61 ALOGE("%s:Error in ioctl FBIOGET_VSCREENINFO: %s", __FUNCTION__,
62 strerror(errno));
63 close(fb_fd);
64 return -errno;
65 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -080066
67 if (int(info.width) <= 0 || int(info.height) <= 0) {
68 // the driver doesn't return that information
69 // default to 160 dpi
70 info.width = ((info.xres * 25.4f)/160.0f + 0.5f);
71 info.height = ((info.yres * 25.4f)/160.0f + 0.5f);
Naseer Ahmed72cf9762012-07-21 12:17:13 -070072 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -080073
74 float xdpi = (info.xres * 25.4f) / info.width;
75 float ydpi = (info.yres * 25.4f) / info.height;
76
77#ifdef MSMFB_METADATA_GET
78 struct msmfb_metadata metadata;
79 memset(&metadata, 0 , sizeof(metadata));
80 metadata.op = metadata_op_frame_rate;
81
82 if (ioctl(fb_fd, MSMFB_METADATA_GET, &metadata) == -1) {
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +053083 ALOGE("%s:Error retrieving panel frame rate: %s", __FUNCTION__,
84 strerror(errno));
85 close(fb_fd);
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -080086 return -errno;
87 }
88
89 float fps = metadata.data.panel_frame_rate;
90#else
91 //XXX: Remove reserved field usage on all baselines
92 //The reserved[3] field is used to store FPS by the driver.
93 float fps = info.reserved[3] & 0xFF;
94#endif
95
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +053096 if (ioctl(fb_fd, FBIOGET_FSCREENINFO, &finfo) == -1) {
97 ALOGE("%s:Error in ioctl FBIOGET_FSCREENINFO: %s", __FUNCTION__,
98 strerror(errno));
99 close(fb_fd);
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800100 return -errno;
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +0530101 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800102
103 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd = fb_fd;
104 //xres, yres may not be 32 aligned
105 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].stride = finfo.line_length /(info.xres/8);
106 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres = info.xres;
107 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres = info.yres;
108 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xdpi = xdpi;
109 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].ydpi = ydpi;
110 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period = 1000000000l / fps;
111
Naseer Ahmed22616d92013-05-15 17:20:26 -0400112 //Unblank primary on first boot
113 if(ioctl(fb_fd, FBIOBLANK,FB_BLANK_UNBLANK) < 0) {
114 ALOGE("%s: Failed to unblank display", __FUNCTION__);
115 return -errno;
116 }
117 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].isActive = true;
118
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800119 return 0;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700120}
121
Naseer Ahmed29a26812012-06-14 00:56:20 -0700122void initContext(hwc_context_t *ctx)
123{
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700124 openFramebufferDevice(ctx);
Naseer Ahmed96c4c952012-07-25 18:27:14 -0700125 ctx->mMDP.version = qdutils::MDPVersion::getInstance().getMDPVersion();
126 ctx->mMDP.hasOverlay = qdutils::MDPVersion::getInstance().hasOverlay();
127 ctx->mMDP.panel = qdutils::MDPVersion::getInstance().getPanelType();
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800128 overlay::Overlay::initOverlay();
129 ctx->mOverlay = overlay::Overlay::getInstance();
130 ctx->mRotMgr = new RotMgr();
131
Saurabh Shahcf053c62012-12-13 12:32:55 -0800132 //Is created and destroyed only once for primary
133 //For external it could get created and destroyed multiple times depending
134 //on what external we connect to.
135 ctx->mFBUpdate[HWC_DISPLAY_PRIMARY] =
136 IFBUpdate::getObject(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres,
137 HWC_DISPLAY_PRIMARY);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800138
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800139 // Check if the target supports copybit compostion (dyn/mdp/c2d) to
140 // decide if we need to open the copybit module.
141 int compositionType =
142 qdutils::QCCompositionType::getInstance().getCompositionType();
143
144 if (compositionType & (qdutils::COMPOSITION_TYPE_DYN |
145 qdutils::COMPOSITION_TYPE_MDP |
146 qdutils::COMPOSITION_TYPE_C2D)) {
147 ctx->mCopyBit[HWC_DISPLAY_PRIMARY] = new CopyBit();
148 }
149
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700150 ctx->mExtDisplay = new ExternalDisplay(ctx);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800151
152 ctx->mMDPComp[HWC_DISPLAY_PRIMARY] =
153 MDPComp::getObject(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres,
154 HWC_DISPLAY_PRIMARY);
155
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700156 for (uint32_t i = 0; i < MAX_DISPLAYS; i++) {
157 ctx->mHwcDebug[i] = new HwcDebug(i);
158 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500159 MDPComp::init(ctx);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700160
Naseer Ahmedff4f0252012-10-01 13:03:01 -0400161 ctx->vstate.enable = false;
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500162 ctx->vstate.fakevsync = false;
Amara Venkata Mastan Manoj Kumar75526f52012-12-27 18:27:01 -0800163 ctx->mExtDispConfiguring = false;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700164 ctx->mExtOrientation = 0;
Saurabh Shah86c17292013-02-08 15:24:13 -0800165
166 //Right now hwc starts the service but anybody could do it, or it could be
167 //independent process as well.
168 QService::init();
169 sp<IQClient> client = new QClient(ctx);
170 interface_cast<IQService>(
171 defaultServiceManager()->getService(
172 String16("display.qservice")))->connect(client);
173
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700174 // Initialize "No animation on external display" related parameters.
175 ctx->deviceOrientation = 0;
176 ctx->mPrevCropVideo.left = ctx->mPrevCropVideo.top =
177 ctx->mPrevCropVideo.right = ctx->mPrevCropVideo.bottom = 0;
178 ctx->mPrevDestVideo.left = ctx->mPrevDestVideo.top =
179 ctx->mPrevDestVideo.right = ctx->mPrevDestVideo.bottom = 0;
180 ctx->mPrevTransformVideo = 0;
181
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700182 ALOGI("Initializing Qualcomm Hardware Composer");
Naseer Ahmed96c4c952012-07-25 18:27:14 -0700183 ALOGI("MDP version: %d", ctx->mMDP.version);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700184}
185
186void closeContext(hwc_context_t *ctx)
187{
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500188 if(ctx->mOverlay) {
189 delete ctx->mOverlay;
190 ctx->mOverlay = NULL;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700191 }
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700192
Saurabh Shahacf10202013-02-26 10:15:15 -0800193 if(ctx->mRotMgr) {
194 delete ctx->mRotMgr;
195 ctx->mRotMgr = NULL;
196 }
197
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800198 for(int i = 0; i < MAX_DISPLAYS; i++) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800199 if(ctx->mCopyBit[i]) {
200 delete ctx->mCopyBit[i];
201 ctx->mCopyBit[i] = NULL;
202 }
203 }
204
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800205 if(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700206 close(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd);
207 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd = -1;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700208 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700209
210 if(ctx->mExtDisplay) {
211 delete ctx->mExtDisplay;
212 ctx->mExtDisplay = NULL;
213 }
Naseer Ahmedff4f0252012-10-01 13:03:01 -0400214
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800215 for(int i = 0; i < MAX_DISPLAYS; i++) {
Saurabh Shahcf053c62012-12-13 12:32:55 -0800216 if(ctx->mFBUpdate[i]) {
217 delete ctx->mFBUpdate[i];
218 ctx->mFBUpdate[i] = NULL;
219 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800220 if(ctx->mMDPComp[i]) {
221 delete ctx->mMDPComp[i];
222 ctx->mMDPComp[i] = NULL;
Saurabh Shahacf10202013-02-26 10:15:15 -0800223 }
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700224 if(ctx->mHwcDebug[i]) {
225 delete ctx->mHwcDebug[i];
226 ctx->mHwcDebug[i] = NULL;
227 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800228 }
229
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800230
Naseer Ahmed29a26812012-06-14 00:56:20 -0700231}
232
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500233
234void dumpsys_log(android::String8& buf, const char* fmt, ...)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700235{
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500236 va_list varargs;
237 va_start(varargs, fmt);
238 buf.appendFormatV(fmt, varargs);
239 va_end(varargs);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700240}
241
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800242/* Calculates the destination position based on the action safe rectangle */
243void getActionSafePosition(hwc_context_t *ctx, int dpy, uint32_t& x,
244 uint32_t& y, uint32_t& w, uint32_t& h) {
245
246 // if external supports underscan, do nothing
247 // it will be taken care in the driver
248 if(ctx->mExtDisplay->isCEUnderscanSupported())
249 return;
250
251 float wRatio = 1.0;
252 float hRatio = 1.0;
253 float xRatio = 1.0;
254 float yRatio = 1.0;
255
256 float fbWidth = ctx->dpyAttr[dpy].xres;
257 float fbHeight = ctx->dpyAttr[dpy].yres;
258
259 float asX = 0;
260 float asY = 0;
261 float asW = fbWidth;
262 float asH= fbHeight;
263 char value[PROPERTY_VALUE_MAX];
264
265 // Apply action safe parameters
Arun Kumar K.R4d73d642013-04-10 17:06:39 -0700266 property_get("persist.sys.actionsafe.width", value, "0");
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800267 int asWidthRatio = atoi(value);
Arun Kumar K.R4d73d642013-04-10 17:06:39 -0700268 property_get("persist.sys.actionsafe.height", value, "0");
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800269 int asHeightRatio = atoi(value);
270 // based on the action safe ratio, get the Action safe rectangle
271 asW = fbWidth * (1.0f - asWidthRatio / 100.0f);
272 asH = fbHeight * (1.0f - asHeightRatio / 100.0f);
273 asX = (fbWidth - asW) / 2;
274 asY = (fbHeight - asH) / 2;
275
276 // calculate the position ratio
277 xRatio = (float)x/fbWidth;
278 yRatio = (float)y/fbHeight;
279 wRatio = (float)w/fbWidth;
280 hRatio = (float)h/fbHeight;
281
282 //Calculate the position...
283 x = (xRatio * asW) + asX;
284 y = (yRatio * asH) + asY;
285 w = (wRatio * asW);
286 h = (hRatio * asH);
287
288 return;
289}
290
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700291/* Calculates the aspect ratio for external based on the primary */
292void getAspectRatioPosition(hwc_context_t *ctx, int dpy, int orientation,
293 uint32_t& x, uint32_t& y, uint32_t& w, uint32_t& h) {
294 int fbWidth = ctx->dpyAttr[dpy].xres;
295 int fbHeight = ctx->dpyAttr[dpy].yres;
296
297 switch(orientation) {
298 case HAL_TRANSFORM_ROT_90:
299 case HAL_TRANSFORM_ROT_270:
300 x = (fbWidth - (ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres
301 * fbHeight/ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres))/2;
302 y = 0;
303 w = (ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres *
304 fbHeight/ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres);
305 h = fbHeight;
306 break;
307 default:
308 //Do nothing
309 break;
310 }
311 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Position: x = %d, y = %d w = %d h = %d",
312 __FUNCTION__, x, y, w ,h);
313}
314
315
Saurabh Shah8a117932013-05-23 12:48:13 -0700316bool needsScaling(hwc_context_t* ctx, hwc_layer_1_t const* layer,
317 const int& dpy) {
Naseer Ahmed018e5452012-12-03 14:46:15 -0500318 int dst_w, dst_h, src_w, src_h;
319
320 hwc_rect_t displayFrame = layer->displayFrame;
321 hwc_rect_t sourceCrop = layer->sourceCrop;
Saurabh Shah8a117932013-05-23 12:48:13 -0700322 trimLayer(ctx, dpy, layer->transform, sourceCrop, displayFrame);
Naseer Ahmed018e5452012-12-03 14:46:15 -0500323
324 dst_w = displayFrame.right - displayFrame.left;
325 dst_h = displayFrame.bottom - displayFrame.top;
Naseer Ahmed018e5452012-12-03 14:46:15 -0500326 src_w = sourceCrop.right - sourceCrop.left;
327 src_h = sourceCrop.bottom - sourceCrop.top;
328
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800329 if(((src_w != dst_w) || (src_h != dst_h)))
330 return true;
331
332 return false;
333}
334
Saurabh Shah8a117932013-05-23 12:48:13 -0700335bool isAlphaScaled(hwc_context_t* ctx, hwc_layer_1_t const* layer,
336 const int& dpy) {
337 if(needsScaling(ctx, layer, dpy) && isAlphaPresent(layer)) {
Sravan Kumar D.V.N075ef002013-03-20 05:22:26 +0530338 return true;
339 }
340 return false;
341}
342
343bool isAlphaPresent(hwc_layer_1_t const* layer) {
344 private_handle_t *hnd = (private_handle_t *)layer->handle;
Naseer Ahmed7a4287c2013-03-26 18:11:41 -0400345 if(hnd) {
346 int format = hnd->format;
347 switch(format) {
Sravan Kumar D.V.N075ef002013-03-20 05:22:26 +0530348 case HAL_PIXEL_FORMAT_RGBA_8888:
349 case HAL_PIXEL_FORMAT_BGRA_8888:
350 // In any more formats with Alpha go here..
Naseer Ahmed018e5452012-12-03 14:46:15 -0500351 return true;
Sravan Kumar D.V.N075ef002013-03-20 05:22:26 +0530352 default : return false;
Naseer Ahmed7a4287c2013-03-26 18:11:41 -0400353 }
Naseer Ahmed018e5452012-12-03 14:46:15 -0500354 }
355 return false;
356}
357
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700358void setListStats(hwc_context_t *ctx,
359 const hwc_display_contents_1_t *list, int dpy) {
360
361 ctx->listStats[dpy].numAppLayers = list->numHwLayers - 1;
362 ctx->listStats[dpy].fbLayerIndex = list->numHwLayers - 1;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700363 ctx->listStats[dpy].skipCount = 0;
Naseer Ahmed018e5452012-12-03 14:46:15 -0500364 ctx->listStats[dpy].needsAlphaScale = false;
Sravan Kumar D.V.Nb5ed0292013-03-15 08:51:16 +0530365 ctx->listStats[dpy].preMultipliedAlpha = false;
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800366 ctx->listStats[dpy].yuvCount = 0;
Ping Li9404e2a2013-04-24 16:36:03 -0400367 char property[PROPERTY_VALUE_MAX];
Arun Kumar K.Ra2978452013-02-07 01:34:24 -0800368 ctx->listStats[dpy].extOnlyLayerIndex = -1;
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700369 ctx->listStats[dpy].isDisplayAnimating = false;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700370
371 for (size_t i = 0; i < list->numHwLayers; i++) {
Naseer Ahmed018e5452012-12-03 14:46:15 -0500372 hwc_layer_1_t const* layer = &list->hwLayers[i];
373 private_handle_t *hnd = (private_handle_t *)layer->handle;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700374
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800375 //reset stored yuv index
376 ctx->listStats[dpy].yuvIndices[i] = -1;
377
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700378 if(list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) {
379 continue;
380 //We disregard FB being skip for now! so the else if
Saurabh Shah35712cb2012-09-14 10:28:18 -0700381 } else if (isSkipLayer(&list->hwLayers[i])) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700382 ctx->listStats[dpy].skipCount++;
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700383 }
384
385 if (UNLIKELY(isYuvBuffer(hnd))) {
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800386 int& yuvCount = ctx->listStats[dpy].yuvCount;
387 ctx->listStats[dpy].yuvIndices[yuvCount] = i;
388 yuvCount++;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800389
Saurabh Shahe2474082013-05-15 16:32:13 -0700390 if((layer->transform & HWC_TRANSFORM_ROT_90) &&
391 canUseRotator(ctx)) {
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700392 if(ctx->mOverlay->isPipeTypeAttached(OV_MDP_PIPE_DMA)) {
393 ctx->isPaddingRound = true;
394 }
Saurabh Shah85234ec2013-04-12 17:09:00 -0700395 Overlay::setDMAMode(Overlay::DMA_BLOCK_MODE);
396 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700397 }
Sravan Kumar D.V.Nb5ed0292013-03-15 08:51:16 +0530398 if(layer->blending == HWC_BLENDING_PREMULT)
399 ctx->listStats[dpy].preMultipliedAlpha = true;
Jeykumar Sankaran7535aba2013-02-04 11:03:09 -0800400
401 if(!ctx->listStats[dpy].needsAlphaScale)
Saurabh Shah8a117932013-05-23 12:48:13 -0700402 ctx->listStats[dpy].needsAlphaScale =
403 isAlphaScaled(ctx, layer, dpy);
Arun Kumar K.Ra2978452013-02-07 01:34:24 -0800404
405 if(UNLIKELY(isExtOnly(hnd))){
406 ctx->listStats[dpy].extOnlyLayerIndex = i;
407 }
Naseer Ahmededbe5182013-05-28 19:56:11 -0400408#ifdef QCOM_BSP
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700409 if (layer->flags & HWC_SCREENSHOT_ANIMATOR_LAYER) {
410 ctx->listStats[dpy].isDisplayAnimating = true;
411 }
Naseer Ahmededbe5182013-05-28 19:56:11 -0400412#endif
Naseer Ahmed29a26812012-06-14 00:56:20 -0700413 }
Ping Li9404e2a2013-04-24 16:36:03 -0400414 if(ctx->listStats[dpy].yuvCount > 0) {
415 if (property_get("hw.cabl.yuv", property, NULL) > 0) {
416 if (atoi(property) != 1) {
417 property_set("hw.cabl.yuv", "1");
418 }
419 }
420 } else {
421 if (property_get("hw.cabl.yuv", property, NULL) > 0) {
422 if (atoi(property) != 0) {
423 property_set("hw.cabl.yuv", "0");
424 }
425 }
426 }
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700427 if(dpy) {
428 //uncomment the below code for testing purpose.
429 /* char value[PROPERTY_VALUE_MAX];
430 property_get("sys.ext_orientation", value, "0");
431 // Assuming the orientation value is in terms of HAL_TRANSFORM,
432 // This needs mapping to HAL, if its in different convention
433 ctx->mExtOrientation = atoi(value); */
434 // Assuming the orientation value is in terms of HAL_TRANSFORM,
435 // This needs mapping to HAL, if its in different convention
436 if(ctx->mExtOrientation) {
437 ALOGD_IF(HWC_UTILS_DEBUG, "%s: ext orientation = %d",
438 __FUNCTION__, ctx->mExtOrientation);
439 if(ctx->mOverlay->isPipeTypeAttached(OV_MDP_PIPE_DMA)) {
440 ctx->isPaddingRound = true;
441 }
442 Overlay::setDMAMode(Overlay::DMA_BLOCK_MODE);
443 }
444 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700445}
446
Naseer Ahmed018e5452012-12-03 14:46:15 -0500447
Saurabh Shahe2474082013-05-15 16:32:13 -0700448static void calc_cut(float& leftCutRatio, float& topCutRatio,
Saurabh Shah541b59d2012-10-11 11:08:12 -0700449 float& rightCutRatio, float& bottomCutRatio, int orient) {
Saurabh Shah27c1d652012-08-14 19:30:28 -0700450 if(orient & HAL_TRANSFORM_FLIP_H) {
Saurabh Shah541b59d2012-10-11 11:08:12 -0700451 swap(leftCutRatio, rightCutRatio);
Saurabh Shah27c1d652012-08-14 19:30:28 -0700452 }
453 if(orient & HAL_TRANSFORM_FLIP_V) {
Saurabh Shah541b59d2012-10-11 11:08:12 -0700454 swap(topCutRatio, bottomCutRatio);
Saurabh Shah27c1d652012-08-14 19:30:28 -0700455 }
456 if(orient & HAL_TRANSFORM_ROT_90) {
457 //Anti clock swapping
Saurabh Shah541b59d2012-10-11 11:08:12 -0700458 float tmpCutRatio = leftCutRatio;
459 leftCutRatio = topCutRatio;
460 topCutRatio = rightCutRatio;
461 rightCutRatio = bottomCutRatio;
462 bottomCutRatio = tmpCutRatio;
Saurabh Shah27c1d652012-08-14 19:30:28 -0700463 }
464}
465
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800466bool isSecuring(hwc_context_t* ctx, hwc_layer_1_t const* layer) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500467 if((ctx->mMDP.version < qdutils::MDSS_V5) &&
468 (ctx->mMDP.version > qdutils::MDP_V3_0) &&
469 ctx->mSecuring) {
470 return true;
471 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800472 if (isSecureModePolicy(ctx->mMDP.version)) {
473 private_handle_t *hnd = (private_handle_t *)layer->handle;
474 if(ctx->mSecureMode) {
475 if (! isSecureBuffer(hnd)) {
476 ALOGD_IF(HWC_UTILS_DEBUG,"%s:Securing Turning ON ...",
477 __FUNCTION__);
478 return true;
479 }
480 } else {
481 if (isSecureBuffer(hnd)) {
482 ALOGD_IF(HWC_UTILS_DEBUG,"%s:Securing Turning OFF ...",
483 __FUNCTION__);
484 return true;
485 }
486 }
487 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500488 return false;
489}
490
Sushil Chauhan2515abf2013-01-08 16:40:05 -0800491bool isSecureModePolicy(int mdpVersion) {
492 if (mdpVersion < qdutils::MDSS_V5)
493 return true;
494 else
495 return false;
496}
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500497
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700498//Crops source buffer against destination and FB boundaries
499void calculate_crop_rects(hwc_rect_t& crop, hwc_rect_t& dst,
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800500 const hwc_rect_t& scissor, int orient) {
501
Saurabh Shah27c1d652012-08-14 19:30:28 -0700502 int& crop_l = crop.left;
503 int& crop_t = crop.top;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700504 int& crop_r = crop.right;
505 int& crop_b = crop.bottom;
506 int crop_w = crop.right - crop.left;
507 int crop_h = crop.bottom - crop.top;
508
Saurabh Shah27c1d652012-08-14 19:30:28 -0700509 int& dst_l = dst.left;
510 int& dst_t = dst.top;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700511 int& dst_r = dst.right;
512 int& dst_b = dst.bottom;
Saurabh Shah27c1d652012-08-14 19:30:28 -0700513 int dst_w = abs(dst.right - dst.left);
514 int dst_h = abs(dst.bottom - dst.top);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700515
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800516 const int& sci_l = scissor.left;
517 const int& sci_t = scissor.top;
518 const int& sci_r = scissor.right;
519 const int& sci_b = scissor.bottom;
520 int sci_w = abs(sci_r - sci_l);
521 int sci_h = abs(sci_b - sci_t);
522
Saurabh Shah541b59d2012-10-11 11:08:12 -0700523 float leftCutRatio = 0.0f, rightCutRatio = 0.0f, topCutRatio = 0.0f,
524 bottomCutRatio = 0.0f;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700525
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800526 if(dst_l < sci_l) {
527 leftCutRatio = (float)(sci_l - dst_l) / (float)dst_w;
528 dst_l = sci_l;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700529 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800530
531 if(dst_r > sci_r) {
532 rightCutRatio = (float)(dst_r - sci_r) / (float)dst_w;
533 dst_r = sci_r;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700534 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800535
536 if(dst_t < sci_t) {
537 topCutRatio = (float)(sci_t - dst_t) / (float)dst_h;
538 dst_t = sci_t;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700539 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800540
541 if(dst_b > sci_b) {
542 bottomCutRatio = (float)(dst_b - sci_b) / (float)dst_h;
543 dst_b = sci_b;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700544 }
Saurabh Shah27c1d652012-08-14 19:30:28 -0700545
Saurabh Shah541b59d2012-10-11 11:08:12 -0700546 calc_cut(leftCutRatio, topCutRatio, rightCutRatio, bottomCutRatio, orient);
547 crop_l += crop_w * leftCutRatio;
548 crop_t += crop_h * topCutRatio;
549 crop_r -= crop_w * rightCutRatio;
550 crop_b -= crop_h * bottomCutRatio;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700551}
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700552
Naseer Ahmed64b81212013-02-14 10:29:47 -0500553void getNonWormholeRegion(hwc_display_contents_1_t* list,
554 hwc_rect_t& nwr)
555{
556 uint32_t last = list->numHwLayers - 1;
557 hwc_rect_t fbDisplayFrame = list->hwLayers[last].displayFrame;
558 //Initiliaze nwr to first frame
559 nwr.left = list->hwLayers[0].displayFrame.left;
560 nwr.top = list->hwLayers[0].displayFrame.top;
561 nwr.right = list->hwLayers[0].displayFrame.right;
562 nwr.bottom = list->hwLayers[0].displayFrame.bottom;
563
564 for (uint32_t i = 1; i < last; i++) {
565 hwc_rect_t displayFrame = list->hwLayers[i].displayFrame;
566 nwr.left = min(nwr.left, displayFrame.left);
567 nwr.top = min(nwr.top, displayFrame.top);
568 nwr.right = max(nwr.right, displayFrame.right);
569 nwr.bottom = max(nwr.bottom, displayFrame.bottom);
570 }
571
572 //Intersect with the framebuffer
573 nwr.left = max(nwr.left, fbDisplayFrame.left);
574 nwr.top = max(nwr.top, fbDisplayFrame.top);
575 nwr.right = min(nwr.right, fbDisplayFrame.right);
576 nwr.bottom = min(nwr.bottom, fbDisplayFrame.bottom);
577
578}
579
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700580bool isExternalActive(hwc_context_t* ctx) {
581 return ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isActive;
Saurabh Shahfc2acbe2012-08-17 19:47:52 -0700582}
583
Saurabh Shah747af1e2013-02-26 10:25:12 -0800584void closeAcquireFds(hwc_display_contents_1_t* list) {
585 for(uint32_t i = 0; list && i < list->numHwLayers; i++) {
586 //Close the acquireFenceFds
587 //HWC_FRAMEBUFFER are -1 already by SF, rest we close.
588 if(list->hwLayers[i].acquireFenceFd >= 0) {
589 close(list->hwLayers[i].acquireFenceFd);
590 list->hwLayers[i].acquireFenceFd = -1;
591 }
592 }
593}
594
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800595int hwc_sync(hwc_context_t *ctx, hwc_display_contents_1_t* list, int dpy,
596 int fd) {
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -0700597 int ret = 0;
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -0700598 struct mdp_buf_sync data;
Naseer Ahmedb1c76322012-10-17 00:32:50 -0400599 int acquireFd[MAX_NUM_LAYERS];
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -0700600 int count = 0;
601 int releaseFd = -1;
602 int fbFd = -1;
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800603 memset(&data, 0, sizeof(data));
Naseer Ahmed94baddc2012-12-17 18:51:01 -0500604 bool swapzero = false;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700605 data.flags = MDP_BUF_SYNC_FLAG_WAIT;
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -0700606 data.acq_fen_fd = acquireFd;
607 data.rel_fen_fd = &releaseFd;
Naseer Ahmed94baddc2012-12-17 18:51:01 -0500608 char property[PROPERTY_VALUE_MAX];
609 if(property_get("debug.egl.swapinterval", property, "1") > 0) {
610 if(atoi(property) == 0)
611 swapzero = true;
612 }
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700613 bool isExtAnimating = false;
614 if(dpy)
615 isExtAnimating = ctx->listStats[dpy].isDisplayAnimating;
Naseer Ahmed94baddc2012-12-17 18:51:01 -0500616
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -0700617 //Accumulate acquireFenceFds
618 for(uint32_t i = 0; i < list->numHwLayers; i++) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800619 if(list->hwLayers[i].compositionType == HWC_OVERLAY &&
620 list->hwLayers[i].acquireFenceFd != -1) {
Naseer Ahmed94baddc2012-12-17 18:51:01 -0500621 if(UNLIKELY(swapzero))
622 acquireFd[count++] = -1;
623 else
624 acquireFd[count++] = list->hwLayers[i].acquireFenceFd;
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -0700625 }
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800626 if(list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) {
627 if(UNLIKELY(swapzero))
628 acquireFd[count++] = -1;
629 else if(fd != -1) {
630 //set the acquireFD from fd - which is coming from c2d
631 acquireFd[count++] = fd;
632 // Buffer sync IOCTL should be async when using c2d fence is
633 // used
634 data.flags &= ~MDP_BUF_SYNC_FLAG_WAIT;
635 } else if(list->hwLayers[i].acquireFenceFd != -1)
636 acquireFd[count++] = list->hwLayers[i].acquireFenceFd;
637 }
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -0700638 }
639
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -0700640 data.acq_fen_fd_cnt = count;
641 fbFd = ctx->dpyAttr[dpy].fd;
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -0700642 //Waits for acquire fences, returns a release fence
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800643 if(LIKELY(!swapzero)) {
644 uint64_t start = systemTime();
Naseer Ahmed94baddc2012-12-17 18:51:01 -0500645 ret = ioctl(fbFd, MSMFB_BUFFER_SYNC, &data);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800646 ALOGD_IF(HWC_UTILS_DEBUG, "%s: time taken for MSMFB_BUFFER_SYNC IOCTL = %d",
647 __FUNCTION__, (size_t) ns2ms(systemTime() - start));
648 }
Saurabh Shah747af1e2013-02-26 10:25:12 -0800649
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -0700650 if(ret < 0) {
Ramkumar Radhakrishnanb32a0bc2013-04-11 17:57:32 -0700651 ALOGE("%s: ioctl MSMFB_BUFFER_SYNC failed, err=%s",
652 __FUNCTION__, strerror(errno));
653 ALOGE("%s: acq_fen_fd_cnt=%d flags=%d fd=%d dpy=%d numHwLayers=%d",
654 __FUNCTION__, data.acq_fen_fd_cnt, data.flags, fbFd,
655 dpy, list->numHwLayers);
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -0700656 }
Saurabh Shah747af1e2013-02-26 10:25:12 -0800657
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -0700658 for(uint32_t i = 0; i < list->numHwLayers; i++) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800659 if(list->hwLayers[i].compositionType == HWC_OVERLAY ||
660 list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) {
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -0700661 //Populate releaseFenceFds.
Naseer Ahmed94baddc2012-12-17 18:51:01 -0500662 if(UNLIKELY(swapzero))
663 list->hwLayers[i].releaseFenceFd = -1;
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700664 else if(isExtAnimating) {
665 // Release all the app layer fds immediately,
666 // if animation is in progress.
667 hwc_layer_1_t const* layer = &list->hwLayers[i];
668 private_handle_t *hnd = (private_handle_t *)layer->handle;
669 if(isYuvBuffer(hnd)) {
670 list->hwLayers[i].releaseFenceFd = dup(releaseFd);
671 } else
672 list->hwLayers[i].releaseFenceFd = -1;
673 } else
Naseer Ahmed94baddc2012-12-17 18:51:01 -0500674 list->hwLayers[i].releaseFenceFd = dup(releaseFd);
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -0700675 }
676 }
Saurabh Shah747af1e2013-02-26 10:25:12 -0800677
678 if(fd >= 0) {
679 close(fd);
680 fd = -1;
681 }
682
Naseer Ahmed64b81212013-02-14 10:29:47 -0500683 if (ctx->mCopyBit[dpy])
684 ctx->mCopyBit[dpy]->setReleaseFd(releaseFd);
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700685 // if external is animating, close the relaseFd
686 if(isExtAnimating) {
687 close(releaseFd);
688 releaseFd = -1;
689 }
Naseer Ahmed94baddc2012-12-17 18:51:01 -0500690 if(UNLIKELY(swapzero)){
691 list->retireFenceFd = -1;
692 close(releaseFd);
693 } else {
694 list->retireFenceFd = releaseFd;
695 }
Saurabh Shah747af1e2013-02-26 10:25:12 -0800696
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -0700697 return ret;
698}
699
Saurabh Shahacf10202013-02-26 10:15:15 -0800700void trimLayer(hwc_context_t *ctx, const int& dpy, const int& transform,
701 hwc_rect_t& crop, hwc_rect_t& dst) {
702 int hw_w = ctx->dpyAttr[dpy].xres;
703 int hw_h = ctx->dpyAttr[dpy].yres;
704 if(dst.left < 0 || dst.top < 0 ||
705 dst.right > hw_w || dst.bottom > hw_h) {
706 hwc_rect_t scissor = {0, 0, hw_w, hw_h };
707 qhwc::calculate_crop_rects(crop, dst, scissor, transform);
708 }
709}
710
711void setMdpFlags(hwc_layer_1_t *layer,
712 ovutils::eMdpFlags &mdpFlags,
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700713 int rotDownscale, int transform) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800714 private_handle_t *hnd = (private_handle_t *)layer->handle;
715 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
Saurabh Shahacf10202013-02-26 10:15:15 -0800716
717 if(layer->blending == HWC_BLENDING_PREMULT) {
718 ovutils::setMdpFlags(mdpFlags,
719 ovutils::OV_MDP_BLEND_FG_PREMULT);
720 }
721
722 if(isYuvBuffer(hnd)) {
723 if(isSecureBuffer(hnd)) {
724 ovutils::setMdpFlags(mdpFlags,
725 ovutils::OV_MDP_SECURE_OVERLAY_SESSION);
726 }
727 if(metadata && (metadata->operation & PP_PARAM_INTERLACED) &&
728 metadata->interlaced) {
729 ovutils::setMdpFlags(mdpFlags,
730 ovutils::OV_MDP_DEINTERLACE);
731 }
732 //Pre-rotation will be used using rotator.
733 if(transform & HWC_TRANSFORM_ROT_90) {
734 ovutils::setMdpFlags(mdpFlags,
735 ovutils::OV_MDP_SOURCE_ROTATED_90);
736 }
737 }
738
739 //No 90 component and no rot-downscale then flips done by MDP
740 //If we use rot then it might as well do flips
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700741 if(!(transform & HWC_TRANSFORM_ROT_90) && !rotDownscale) {
742 if(transform & HWC_TRANSFORM_FLIP_H) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800743 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_FLIP_H);
744 }
745
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700746 if(transform & HWC_TRANSFORM_FLIP_V) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800747 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_FLIP_V);
748 }
749 }
Saurabh Shah5daeee52013-01-23 16:52:26 +0800750
751 if(metadata &&
752 ((metadata->operation & PP_PARAM_HSIC)
753 || (metadata->operation & PP_PARAM_IGC)
754 || (metadata->operation & PP_PARAM_SHARP2))) {
755 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_PP_EN);
756 }
Saurabh Shahacf10202013-02-26 10:15:15 -0800757}
758
Saurabh Shahe2474082013-05-15 16:32:13 -0700759int configRotator(Rotator *rot, const Whf& whf,
Sushil Chauhan1cac8152013-05-08 15:53:51 -0700760 hwc_rect_t& crop, const eMdpFlags& mdpFlags,
Sushil Chauhan80fc1f92013-04-23 17:30:05 -0700761 const eTransform& orient, const int& downscale) {
Sushil Chauhan1cac8152013-05-08 15:53:51 -0700762
Saurabh Shahacf10202013-02-26 10:15:15 -0800763 rot->setSource(whf);
Sushil Chauhan1cac8152013-05-08 15:53:51 -0700764
765 if (qdutils::MDPVersion::getInstance().getMDPVersion() >=
766 qdutils::MDSS_V5) {
767 uint32_t crop_w = (crop.right - crop.left);
768 uint32_t crop_h = (crop.bottom - crop.top);
Sushil Chauhan6181aa22013-05-17 18:04:10 -0700769 if (ovutils::isYuv(whf.format)) {
770 ovutils::normalizeCrop((uint32_t&)crop.left, crop_w);
771 ovutils::normalizeCrop((uint32_t&)crop.top, crop_h);
Sushil Chauhan5491c8a2013-05-24 10:15:30 -0700772 // For interlaced, crop.h should be 4-aligned
773 if ((mdpFlags & ovutils::OV_MDP_DEINTERLACE) && (crop_h % 4))
774 crop_h = ovutils::aligndown(crop_h, 4);
Sushil Chauhan6181aa22013-05-17 18:04:10 -0700775 crop.right = crop.left + crop_w;
776 crop.bottom = crop.top + crop_h;
777 }
Sushil Chauhan1cac8152013-05-08 15:53:51 -0700778 Dim rotCrop(crop.left, crop.top, crop_w, crop_h);
779 rot->setCrop(rotCrop);
780 }
781
Saurabh Shahacf10202013-02-26 10:15:15 -0800782 rot->setFlags(mdpFlags);
783 rot->setTransform(orient);
784 rot->setDownscale(downscale);
785 if(!rot->commit()) return -1;
786 return 0;
787}
788
Saurabh Shahe2474082013-05-15 16:32:13 -0700789int configMdp(Overlay *ov, const PipeArgs& parg,
Saurabh Shahacf10202013-02-26 10:15:15 -0800790 const eTransform& orient, const hwc_rect_t& crop,
Saurabh Shah5daeee52013-01-23 16:52:26 +0800791 const hwc_rect_t& pos, const MetaData_t *metadata,
792 const eDest& dest) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800793 ov->setSource(parg, dest);
794 ov->setTransform(orient, dest);
795
796 int crop_w = crop.right - crop.left;
797 int crop_h = crop.bottom - crop.top;
798 Dim dcrop(crop.left, crop.top, crop_w, crop_h);
799 ov->setCrop(dcrop, dest);
800
801 int posW = pos.right - pos.left;
802 int posH = pos.bottom - pos.top;
803 Dim position(pos.left, pos.top, posW, posH);
804 ov->setPosition(position, dest);
805
Saurabh Shah5daeee52013-01-23 16:52:26 +0800806 if (metadata)
807 ov->setVisualParams(*metadata, dest);
808
Saurabh Shahacf10202013-02-26 10:15:15 -0800809 if (!ov->commit(dest)) {
810 return -1;
811 }
812 return 0;
813}
814
Saurabh Shahe2474082013-05-15 16:32:13 -0700815void updateSource(eTransform& orient, Whf& whf,
Saurabh Shahacf10202013-02-26 10:15:15 -0800816 hwc_rect_t& crop) {
817 Dim srcCrop(crop.left, crop.top,
818 crop.right - crop.left,
819 crop.bottom - crop.top);
Saurabh Shah76fd6552013-03-14 14:45:38 -0700820 orient = static_cast<eTransform>(ovutils::getMdpOrient(orient));
Saurabh Shahacf10202013-02-26 10:15:15 -0800821 preRotateSource(orient, whf, srcCrop);
Sushil Chauhan80fc1f92013-04-23 17:30:05 -0700822 if (qdutils::MDPVersion::getInstance().getMDPVersion() >=
823 qdutils::MDSS_V5) {
824 // Source for overlay will be the cropped (and rotated)
825 crop.left = 0;
826 crop.top = 0;
827 crop.right = srcCrop.w;
828 crop.bottom = srcCrop.h;
829 // Set width & height equal to sourceCrop w & h
830 whf.w = srcCrop.w;
831 whf.h = srcCrop.h;
832 } else {
833 crop.left = srcCrop.x;
834 crop.top = srcCrop.y;
835 crop.right = srcCrop.x + srcCrop.w;
836 crop.bottom = srcCrop.y + srcCrop.h;
837 }
Saurabh Shahacf10202013-02-26 10:15:15 -0800838}
839
840int configureLowRes(hwc_context_t *ctx, hwc_layer_1_t *layer,
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700841 const int& dpy, eMdpFlags& mdpFlags, eZorder& z,
842 eIsFg& isFg, const eDest& dest, Rotator **rot) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800843
844 private_handle_t *hnd = (private_handle_t *)layer->handle;
845 if(!hnd) {
846 ALOGE("%s: layer handle is NULL", __FUNCTION__);
847 return -1;
848 }
849
Saurabh Shah5daeee52013-01-23 16:52:26 +0800850 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
851
Saurabh Shahacf10202013-02-26 10:15:15 -0800852 hwc_rect_t crop = layer->sourceCrop;
853 hwc_rect_t dst = layer->displayFrame;
854 int transform = layer->transform;
855 eTransform orient = static_cast<eTransform>(transform);
856 int downscale = 0;
857 int rotFlags = ovutils::ROT_FLAGS_NONE;
858 Whf whf(hnd->width, hnd->height,
859 getMdpFormat(hnd->format), hnd->size);
860
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700861 if(dpy && isYuvBuffer(hnd)) {
862 if(!ctx->listStats[dpy].isDisplayAnimating) {
863 ctx->mPrevCropVideo = crop;
864 ctx->mPrevDestVideo = dst;
865 ctx->mPrevTransformVideo = transform;
866 } else {
867 // Restore the previous crop, dest rect and transform values, during
868 // animation to avoid displaying videos at random coordinates.
869 crop = ctx->mPrevCropVideo;
870 dst = ctx->mPrevDestVideo;
871 transform = ctx->mPrevTransformVideo;
Ramkumar Radhakrishnand7e8d0c2013-05-20 17:13:12 -0700872 orient = static_cast<eTransform>(transform);
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700873 //In you tube use case when a device rotated from landscape to
874 // portrait, set the isFg flag and zOrder to avoid displaying UI on
875 // hdmi during animation
876 if(ctx->deviceOrientation) {
877 isFg = ovutils::IS_FG_SET;
878 z = ZORDER_1;
879 }
880 }
881 }
882
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700883 uint32_t x = dst.left, y = dst.right;
884 uint32_t w = dst.right - dst.left;
885 uint32_t h = dst.bottom - dst.top;
886
887 if(dpy && ctx->mExtOrientation) {
888 // Just need to set the position to portrait as the transformation
889 // will already be set to required orientation on TV
890 getAspectRatioPosition(ctx, dpy, ctx->mExtOrientation, x, y, w, h);
891 // Convert position to hwc_rect_t
892 dst.left = x;
893 dst.top = y;
894 dst.right = w + dst.left;
895 dst.bottom = h + dst.top;
896 }
897
Saurabh Shahacf10202013-02-26 10:15:15 -0800898 if(isYuvBuffer(hnd) && ctx->mMDP.version >= qdutils::MDP_V4_2 &&
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800899 ctx->mMDP.version < qdutils::MDSS_V5) {
900 downscale = getDownscaleFactor(
901 crop.right - crop.left,
902 crop.bottom - crop.top,
903 dst.right - dst.left,
904 dst.bottom - dst.top);
Saurabh Shahacf10202013-02-26 10:15:15 -0800905 if(downscale) {
906 rotFlags = ROT_DOWNSCALE_ENABLED;
907 }
908 }
909
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700910 setMdpFlags(layer, mdpFlags, downscale, transform);
Saurabh Shahacf10202013-02-26 10:15:15 -0800911 trimLayer(ctx, dpy, transform, crop, dst);
912
913 if(isYuvBuffer(hnd) && //if 90 component or downscale, use rot
914 ((transform & HWC_TRANSFORM_ROT_90) || downscale)) {
915 *rot = ctx->mRotMgr->getNext();
916 if(*rot == NULL) return -1;
Saurabh Shah1a03d482013-05-29 13:44:20 -0700917 BwcPM::setBwc(ctx, crop, dst, transform, mdpFlags);
Saurabh Shahacf10202013-02-26 10:15:15 -0800918 //Configure rotator for pre-rotation
Sushil Chauhan80fc1f92013-04-23 17:30:05 -0700919 if(configRotator(*rot, whf, crop, mdpFlags, orient, downscale) < 0) {
920 ALOGE("%s: configRotator failed!", __FUNCTION__);
Sushil Chauhanbd3ea922013-05-15 12:25:26 -0700921 ctx->mOverlay->clear(dpy);
Saurabh Shahacf10202013-02-26 10:15:15 -0800922 return -1;
Sushil Chauhan80fc1f92013-04-23 17:30:05 -0700923 }
Saurabh Shahacf10202013-02-26 10:15:15 -0800924 whf.format = (*rot)->getDstFormat();
925 updateSource(orient, whf, crop);
Saurabh Shahacf10202013-02-26 10:15:15 -0800926 rotFlags |= ovutils::ROT_PREROTATED;
927 }
928
Saurabh Shah76fd6552013-03-14 14:45:38 -0700929 //For the mdp, since either we are pre-rotating or MDP does flips
930 orient = OVERLAY_TRANSFORM_0;
931 transform = 0;
Saurabh Shahacf10202013-02-26 10:15:15 -0800932 PipeArgs parg(mdpFlags, whf, z, isFg, static_cast<eRotFlags>(rotFlags));
Saurabh Shah5daeee52013-01-23 16:52:26 +0800933 if(configMdp(ctx->mOverlay, parg, orient, crop, dst, metadata, dest) < 0) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800934 ALOGE("%s: commit failed for low res panel", __FUNCTION__);
935 return -1;
936 }
937 return 0;
938}
939
940int configureHighRes(hwc_context_t *ctx, hwc_layer_1_t *layer,
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700941 const int& dpy, eMdpFlags& mdpFlagsL, eZorder& z,
942 eIsFg& isFg, const eDest& lDest, const eDest& rDest,
Saurabh Shahacf10202013-02-26 10:15:15 -0800943 Rotator **rot) {
944 private_handle_t *hnd = (private_handle_t *)layer->handle;
945 if(!hnd) {
946 ALOGE("%s: layer handle is NULL", __FUNCTION__);
947 return -1;
948 }
949
Saurabh Shah5daeee52013-01-23 16:52:26 +0800950 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
951
Saurabh Shahacf10202013-02-26 10:15:15 -0800952 int hw_w = ctx->dpyAttr[dpy].xres;
953 int hw_h = ctx->dpyAttr[dpy].yres;
954 hwc_rect_t crop = layer->sourceCrop;
955 hwc_rect_t dst = layer->displayFrame;
956 int transform = layer->transform;
957 eTransform orient = static_cast<eTransform>(transform);
958 const int downscale = 0;
959 int rotFlags = ROT_FLAGS_NONE;
960
961 Whf whf(hnd->width, hnd->height,
962 getMdpFormat(hnd->format), hnd->size);
963
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700964 if(dpy && isYuvBuffer(hnd)) {
965 if(!ctx->listStats[dpy].isDisplayAnimating) {
966 ctx->mPrevCropVideo = crop;
967 ctx->mPrevDestVideo = dst;
968 ctx->mPrevTransformVideo = transform;
969 } else {
970 // Restore the previous crop, dest rect and transform values, during
971 // animation to avoid displaying videos at random coordinates.
972 crop = ctx->mPrevCropVideo;
973 dst = ctx->mPrevDestVideo;
974 transform = ctx->mPrevTransformVideo;
Ramkumar Radhakrishnand7e8d0c2013-05-20 17:13:12 -0700975 orient = static_cast<eTransform>(transform);
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700976 //In you tube use case when a device rotated from landscape to
977 // portrait, set the isFg flag and zOrder to avoid displaying UI on
978 // hdmi during animation
979 if(ctx->deviceOrientation) {
980 isFg = ovutils::IS_FG_SET;
981 z = ZORDER_1;
982 }
983 }
984 }
985
986
Ramkumar Radhakrishnan9d52f432013-05-14 14:46:59 -0700987 setMdpFlags(layer, mdpFlagsL, 0, transform);
Saurabh Shahacf10202013-02-26 10:15:15 -0800988 trimLayer(ctx, dpy, transform, crop, dst);
989
990 if(isYuvBuffer(hnd) && (transform & HWC_TRANSFORM_ROT_90)) {
991 (*rot) = ctx->mRotMgr->getNext();
992 if((*rot) == NULL) return -1;
993 //Configure rotator for pre-rotation
Sushil Chauhan80fc1f92013-04-23 17:30:05 -0700994 if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale) < 0) {
995 ALOGE("%s: configRotator failed!", __FUNCTION__);
Sushil Chauhanbd3ea922013-05-15 12:25:26 -0700996 ctx->mOverlay->clear(dpy);
Saurabh Shahacf10202013-02-26 10:15:15 -0800997 return -1;
Sushil Chauhan80fc1f92013-04-23 17:30:05 -0700998 }
Saurabh Shahacf10202013-02-26 10:15:15 -0800999 whf.format = (*rot)->getDstFormat();
1000 updateSource(orient, whf, crop);
Saurabh Shahacf10202013-02-26 10:15:15 -08001001 rotFlags |= ROT_PREROTATED;
1002 }
1003
1004 eMdpFlags mdpFlagsR = mdpFlagsL;
1005 setMdpFlags(mdpFlagsR, OV_MDSS_MDP_RIGHT_MIXER);
1006
1007 hwc_rect_t tmp_cropL, tmp_dstL;
1008 hwc_rect_t tmp_cropR, tmp_dstR;
1009
1010 if(lDest != OV_INVALID) {
1011 tmp_cropL = crop;
1012 tmp_dstL = dst;
1013 hwc_rect_t scissor = {0, 0, hw_w/2, hw_h };
1014 qhwc::calculate_crop_rects(tmp_cropL, tmp_dstL, scissor, 0);
1015 }
1016 if(rDest != OV_INVALID) {
1017 tmp_cropR = crop;
1018 tmp_dstR = dst;
1019 hwc_rect_t scissor = {hw_w/2, 0, hw_w, hw_h };
1020 qhwc::calculate_crop_rects(tmp_cropR, tmp_dstR, scissor, 0);
1021 }
1022
1023 //When buffer is flipped, contents of mixer config also needs to swapped.
1024 //Not needed if the layer is confined to one half of the screen.
1025 //If rotator has been used then it has also done the flips, so ignore them.
Saurabh Shah76fd6552013-03-14 14:45:38 -07001026 if((orient & OVERLAY_TRANSFORM_FLIP_V) && lDest != OV_INVALID
Ramkumar Radhakrishnanfe7ce802013-04-30 11:19:17 -07001027 && rDest != OV_INVALID && (*rot) == NULL) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001028 hwc_rect_t new_cropR;
1029 new_cropR.left = tmp_cropL.left;
1030 new_cropR.right = new_cropR.left + (tmp_cropR.right - tmp_cropR.left);
1031
1032 hwc_rect_t new_cropL;
1033 new_cropL.left = new_cropR.right;
1034 new_cropL.right = tmp_cropR.right;
1035
1036 tmp_cropL.left = new_cropL.left;
1037 tmp_cropL.right = new_cropL.right;
1038
1039 tmp_cropR.left = new_cropR.left;
1040 tmp_cropR.right = new_cropR.right;
1041
1042 }
1043
Saurabh Shah76fd6552013-03-14 14:45:38 -07001044 //For the mdp, since either we are pre-rotating or MDP does flips
1045 orient = OVERLAY_TRANSFORM_0;
1046 transform = 0;
1047
Saurabh Shahacf10202013-02-26 10:15:15 -08001048 //configure left mixer
1049 if(lDest != OV_INVALID) {
1050 PipeArgs pargL(mdpFlagsL, whf, z, isFg,
1051 static_cast<eRotFlags>(rotFlags));
1052 if(configMdp(ctx->mOverlay, pargL, orient,
Saurabh Shah5daeee52013-01-23 16:52:26 +08001053 tmp_cropL, tmp_dstL, metadata, lDest) < 0) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001054 ALOGE("%s: commit failed for left mixer config", __FUNCTION__);
1055 return -1;
1056 }
1057 }
1058
1059 //configure right mixer
1060 if(rDest != OV_INVALID) {
1061 PipeArgs pargR(mdpFlagsR, whf, z, isFg,
1062 static_cast<eRotFlags>(rotFlags));
Saurabh Shahbaa68982013-04-26 09:55:29 -07001063 tmp_dstR.right = tmp_dstR.right - hw_w/2;
1064 tmp_dstR.left = tmp_dstR.left - hw_w/2;
Saurabh Shahacf10202013-02-26 10:15:15 -08001065 if(configMdp(ctx->mOverlay, pargR, orient,
Saurabh Shah5daeee52013-01-23 16:52:26 +08001066 tmp_cropR, tmp_dstR, metadata, rDest) < 0) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001067 ALOGE("%s: commit failed for right mixer config", __FUNCTION__);
1068 return -1;
1069 }
1070 }
1071
1072 return 0;
1073}
Arun Kumar K.Ra2978452013-02-07 01:34:24 -08001074
Saurabh Shahe2474082013-05-15 16:32:13 -07001075bool canUseRotator(hwc_context_t *ctx) {
1076 if(qdutils::MDPVersion::getInstance().is8x26() &&
1077 ctx->mExtDisplay->isExternalConnected()) {
1078 return false;
1079 }
Terence Hampson45c02ef2013-05-17 17:00:11 -04001080 if(ctx->mMDP.version == qdutils::MDP_V3_0_4)
1081 return false;
Saurabh Shahe2474082013-05-15 16:32:13 -07001082 return true;
1083}
1084
Saurabh Shah1a03d482013-05-29 13:44:20 -07001085
1086void BwcPM::setBwc(hwc_context_t *ctx, const hwc_rect_t& crop,
1087 const hwc_rect_t& dst, const int& transform,
1088 ovutils::eMdpFlags& mdpFlags) {
1089 //Target doesnt support Bwc
1090 if(!qdutils::MDPVersion::getInstance().supportsBWC()) {
1091 return;
1092 }
1093 //src width > MAX mixer supported dim
1094 if((crop.right - crop.left) > qdutils::MAX_DISPLAY_DIM) {
1095 return;
1096 }
1097 //External connected
1098 if(ctx->mExtDisplay->isExternalConnected()) {
1099 return;
1100 }
1101 //Decimation necessary, cannot use BWC. H/W requirement.
1102 if(qdutils::MDPVersion::getInstance().supportsDecimation()) {
1103 int src_w = crop.right - crop.left;
1104 int src_h = crop.bottom - crop.top;
1105 int dst_w = dst.right - dst.left;
1106 int dst_h = dst.bottom - dst.top;
1107 if(transform & HAL_TRANSFORM_ROT_90) {
1108 swap(src_w, src_h);
1109 }
1110 float horDscale = 0.0f;
1111 float verDscale = 0.0f;
1112 ovutils::getDecimationFactor(src_w, src_h, dst_w, dst_h, horDscale,
1113 verDscale);
1114 if(horDscale || verDscale) return;
1115 }
1116 //Property
1117 char value[PROPERTY_VALUE_MAX];
1118 property_get("debug.disable.bwc", value, "0");
1119 if(atoi(value)) return;
1120
1121 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDSS_MDP_BWC_EN);
1122}
1123
Saurabh Shahacf10202013-02-26 10:15:15 -08001124};//namespace qhwc