blob: 8efe025486458d43243e6810261538aadcbeb87d [file] [log] [blame]
Naseer Ahmed29a26812012-06-14 00:56:20 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
Zohaib Alamc9d00cd2014-01-24 16:38:32 -05003 * Copyright (C) 2012-2014, The Linux Foundation All rights reserved.
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08004 *
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 */
Naseer Ahmed099a6932013-09-09 14:25:20 -040020#define ATRACE_TAG (ATRACE_TAG_GRAPHICS | ATRACE_TAG_HAL)
Arun Kumar K.R361da4f2012-11-28 10:42:59 -080021#define HWC_UTILS_DEBUG 0
Saurabh Shahc5b96dc2013-06-05 13:19:52 -070022#include <math.h>
Naseer Ahmed758bfc52012-11-28 17:02:08 -050023#include <sys/ioctl.h>
Naseer Ahmed66e97882013-03-19 20:42:11 -040024#include <linux/fb.h>
Saurabh Shah86c17292013-02-08 15:24:13 -080025#include <binder/IServiceManager.h>
Naseer Ahmed5b6708a2012-08-02 13:46:08 -070026#include <EGL/egl.h>
Saurabh Shahfc2acbe2012-08-17 19:47:52 -070027#include <cutils/properties.h>
Naseer Ahmed099a6932013-09-09 14:25:20 -040028#include <utils/Trace.h>
Saurabh Shahfc2acbe2012-08-17 19:47:52 -070029#include <gralloc_priv.h>
Naseer Ahmed758bfc52012-11-28 17:02:08 -050030#include <overlay.h>
Saurabh Shahacf10202013-02-26 10:15:15 -080031#include <overlayRotator.h>
Saurabh Shaha9da08f2013-07-03 13:27:53 -070032#include <overlayWriteback.h>
Arun Kumar K.R00b84792015-03-27 11:28:36 -070033#include <overlayCursor.h>
Naseer Ahmed29a26812012-06-14 00:56:20 -070034#include "hwc_utils.h"
Naseer Ahmed54821fe2012-11-28 18:44:38 -050035#include "hwc_mdpcomp.h"
Saurabh Shahcf053c62012-12-13 12:32:55 -080036#include "hwc_fbupdate.h"
Saurabh Shaha9da08f2013-07-03 13:27:53 -070037#include "hwc_ad.h"
Naseer Ahmeda87da602012-07-01 23:54:19 -070038#include "mdp_version.h"
Arun Kumar K.R361da4f2012-11-28 10:42:59 -080039#include "hwc_copybit.h"
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -070040#include "hwc_dump_layers.h"
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -070041#include "hdmi.h"
Saurabh Shah86c17292013-02-08 15:24:13 -080042#include "hwc_qclient.h"
Saurabh Shah56f610d2012-08-07 15:27:06 -070043#include "QService.h"
Arun Kumar K.R361da4f2012-11-28 10:42:59 -080044#include "comptype.h"
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -080045#include "hwc_virtual.h"
Tatenda Chipeperekwaa7dd23c2014-03-05 13:02:24 -080046#include "qd_utils.h"
Zohaib Alam83ea46d2015-03-23 15:44:19 -040047#include "hwc_qdcm.h"
Ramakant Singh98c533c2014-09-30 19:01:54 +053048#include <sys/sysinfo.h>
Krishna Chaitanya Parimidb992fd2014-10-22 20:50:50 +053049#include <dlfcn.h>
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -050050#include <video/msm_hdmi_modes.h>
Saurabh Shah86c17292013-02-08 15:24:13 -080051
52using namespace qClient;
53using namespace qService;
54using namespace android;
Saurabh Shahacf10202013-02-26 10:15:15 -080055using namespace overlay;
56using namespace overlay::utils;
Zohaib Alam83ea46d2015-03-23 15:44:19 -040057using namespace qQdcm;
Saurabh Shahacf10202013-02-26 10:15:15 -080058namespace ovutils = overlay::utils;
Saurabh Shah86c17292013-02-08 15:24:13 -080059
Saurabh Shah74eff4d2014-03-28 16:33:13 -070060#ifdef QCOM_BSP
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -070061#ifdef __cplusplus
62extern "C" {
63#endif
64
65EGLAPI EGLBoolean eglGpuPerfHintQCOM(EGLDisplay dpy, EGLContext ctx,
66 EGLint *attrib_list);
67#define EGL_GPU_HINT_1 0x32D0
68#define EGL_GPU_HINT_2 0x32D1
69
70#define EGL_GPU_LEVEL_0 0x0
71#define EGL_GPU_LEVEL_1 0x1
72#define EGL_GPU_LEVEL_2 0x2
73#define EGL_GPU_LEVEL_3 0x3
74#define EGL_GPU_LEVEL_4 0x4
75#define EGL_GPU_LEVEL_5 0x5
76
77#ifdef __cplusplus
78}
79#endif
Saurabh Shah74eff4d2014-03-28 16:33:13 -070080#endif
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -070081
Ramakant Singhbe390c72014-12-03 23:04:21 +053082#define PROP_DEFAULT_APPBUFFER "hw.sf.app_buff_count"
Ramakant Singh98c533c2014-09-30 19:01:54 +053083#define MAX_RAM_SIZE 512*1024*1024
84#define qHD_WIDTH 540
85
86
Naseer Ahmed29a26812012-06-14 00:56:20 -070087namespace qhwc {
Naseer Ahmed72cf9762012-07-21 12:17:13 -070088
Arun Kumar K.R053dc502014-11-13 11:13:43 -080089// Std refresh rates for digital videos- 24p, 30p, 48p and 60p
90uint32_t stdRefreshRates[] = { 30, 24, 48, 60 };
Arun Kumar K.Ra727a882014-08-20 17:14:26 -070091
radhakrishnac3198ff2015-03-10 17:10:02 +053092static uint32_t getFBformat(fb_var_screeninfo vinfo) {
93 uint32_t fbformat = HAL_PIXEL_FORMAT_RGBA_8888;
94
95#ifdef GET_FRAMEBUFFER_FORMAT_FROM_HWC
96 // Here, we are adding the formats that are supported by both GPU and MDP.
97 // The formats that fall in this category are RGBA_8888, RGB_565, RGB_888
98 switch(vinfo.bits_per_pixel) {
99 case 16:
100 fbformat = HAL_PIXEL_FORMAT_RGB_565;
101 break;
102 case 24:
103 if ((vinfo.transp.offset == 0) && (vinfo.transp.length == 0))
104 fbformat = HAL_PIXEL_FORMAT_RGB_888;
105 break;
106 case 32:
107 if ((vinfo.red.offset == 0) && (vinfo.green.offset == 8) &&
108 (vinfo.blue.offset == 16) && (vinfo.transp.offset == 24))
109 fbformat = HAL_PIXEL_FORMAT_RGBA_8888;
110 break;
111 default:
112 fbformat = HAL_PIXEL_FORMAT_RGBA_8888;
113 }
114#endif
115 return fbformat;
116}
117
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530118bool isValidResolution(hwc_context_t *ctx, uint32_t xres, uint32_t yres)
119{
Jeykumar Sankaran39305802014-12-12 17:55:57 -0800120 return !((xres > qdutils::MDPVersion::getInstance().getMaxPipeWidth() &&
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530121 !isDisplaySplit(ctx, HWC_DISPLAY_PRIMARY)) ||
122 (xres < MIN_DISPLAY_XRES || yres < MIN_DISPLAY_YRES));
123}
124
Saurabh Shah90c55cf2015-02-10 15:37:39 -0800125static void handleFbScaling(hwc_context_t *ctx, int xresPanel, int yresPanel,
126 int width, int height) {
127 const int dpy = HWC_DISPLAY_PRIMARY;
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530128 //Store original display resolution.
Saurabh Shah90c55cf2015-02-10 15:37:39 -0800129 ctx->dpyAttr[dpy].xresFB = xresPanel;
130 ctx->dpyAttr[dpy].yresFB = yresPanel;
131 ctx->dpyAttr[dpy].fbScaling = false;
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530132 char property[PROPERTY_VALUE_MAX] = {'\0'};
133 char *yptr = NULL;
134 if (property_get("debug.hwc.fbsize", property, NULL) > 0) {
135 yptr = strcasestr(property,"x");
Raj Kamal4a443082014-10-12 21:07:59 +0530136 if(yptr) {
Saurabh Shah90c55cf2015-02-10 15:37:39 -0800137 int xresFB = atoi(property);
138 int yresFB = atoi(yptr + 1);
139 if (isValidResolution(ctx, xresFB, yresFB) &&
140 xresFB != xresPanel && yresFB != yresPanel) {
141 ctx->dpyAttr[dpy].xresFB = xresFB;
142 ctx->dpyAttr[dpy].yresFB = yresFB;
143 ctx->dpyAttr[dpy].fbScaling = true;
Praveena Pachipulusu49d62062014-06-06 19:22:23 +0530144
Saurabh Shah90c55cf2015-02-10 15:37:39 -0800145 //Calculate DPI according to changed resolution.
146 float xdpi = ((float)xresFB * 25.4f) / (float)width;
147 float ydpi = ((float)yresFB * 25.4f) / (float)height;
148 ctx->dpyAttr[dpy].xdpi = xdpi;
149 ctx->dpyAttr[dpy].ydpi = ydpi;
Raj Kamal4a443082014-10-12 21:07:59 +0530150 }
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530151 }
152 }
Saurabh Shah90c55cf2015-02-10 15:37:39 -0800153 ctx->dpyAttr[dpy].fbWidthScaleRatio = (float) ctx->dpyAttr[dpy].xres /
154 (float) ctx->dpyAttr[dpy].xresFB;
155 ctx->dpyAttr[dpy].fbHeightScaleRatio = (float) ctx->dpyAttr[dpy].yres /
156 (float) ctx->dpyAttr[dpy].yresFB;
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530157}
158
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700159// Initialize hdmi display attributes based on
160// hdmi display class state
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700161void updateDisplayInfo(hwc_context_t* ctx, int dpy) {
radhakrishnac3198ff2015-03-10 17:10:02 +0530162 struct fb_var_screeninfo info;
163
164 if (ioctl(ctx->mHDMIDisplay->getFd(), FBIOGET_VSCREENINFO, &info) == -1) {
165 ALOGE("%s:Error in ioctl FBIOGET_VSCREENINFO: %s",
166 __FUNCTION__, strerror(errno));
167 }
168
169 ctx->dpyAttr[dpy].fbformat = getFBformat(info);
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700170 ctx->dpyAttr[dpy].fd = ctx->mHDMIDisplay->getFd();
171 ctx->dpyAttr[dpy].xres = ctx->mHDMIDisplay->getWidth();
172 ctx->dpyAttr[dpy].yres = ctx->mHDMIDisplay->getHeight();
173 ctx->dpyAttr[dpy].mMDPScalingMode = ctx->mHDMIDisplay->getMDPScalingMode();
174 ctx->dpyAttr[dpy].vsync_period = ctx->mHDMIDisplay->getVsyncPeriod();
Arun Kumar K.R074c9cf2014-08-21 18:43:53 -0700175 //FIXME: for now assume HDMI as secure
176 //Will need to read the HDCP status from the driver
177 //and update this accordingly
178 ctx->dpyAttr[dpy].secure = true;
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700179 ctx->mViewFrame[dpy].left = 0;
180 ctx->mViewFrame[dpy].top = 0;
181 ctx->mViewFrame[dpy].right = ctx->dpyAttr[dpy].xres;
182 ctx->mViewFrame[dpy].bottom = ctx->dpyAttr[dpy].yres;
183}
184
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700185// Reset hdmi display attributes and list stats structures
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700186void resetDisplayInfo(hwc_context_t* ctx, int dpy) {
187 memset(&(ctx->dpyAttr[dpy]), 0, sizeof(ctx->dpyAttr[dpy]));
188 memset(&(ctx->listStats[dpy]), 0, sizeof(ctx->listStats[dpy]));
189 // We reset the fd to -1 here but External display class is responsible
190 // for it when the display is disconnected. This is handled as part of
191 // EXTERNAL_OFFLINE event.
192 ctx->dpyAttr[dpy].fd = -1;
193}
194
195// Initialize composition resources
196void initCompositionResources(hwc_context_t* ctx, int dpy) {
197 ctx->mFBUpdate[dpy] = IFBUpdate::getObject(ctx, dpy);
198 ctx->mMDPComp[dpy] = MDPComp::getObject(ctx, dpy);
199}
200
201void destroyCompositionResources(hwc_context_t* ctx, int dpy) {
202 if(ctx->mFBUpdate[dpy]) {
203 delete ctx->mFBUpdate[dpy];
204 ctx->mFBUpdate[dpy] = NULL;
205 }
206 if(ctx->mMDPComp[dpy]) {
207 delete ctx->mMDPComp[dpy];
208 ctx->mMDPComp[dpy] = NULL;
209 }
210}
211
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800212static int openFramebufferDevice(hwc_context_t *ctx)
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700213{
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800214 struct fb_fix_screeninfo finfo;
215 struct fb_var_screeninfo info;
216
217 int fb_fd = openFb(HWC_DISPLAY_PRIMARY);
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +0530218 if(fb_fd < 0) {
219 ALOGE("%s: Error Opening FB : %s", __FUNCTION__, strerror(errno));
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800220 return -errno;
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +0530221 }
222
223 if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &info) == -1) {
224 ALOGE("%s:Error in ioctl FBIOGET_VSCREENINFO: %s", __FUNCTION__,
225 strerror(errno));
226 close(fb_fd);
227 return -errno;
228 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800229
230 if (int(info.width) <= 0 || int(info.height) <= 0) {
231 // the driver doesn't return that information
232 // default to 160 dpi
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530233 info.width = (int)(((float)info.xres * 25.4f)/160.0f + 0.5f);
234 info.height = (int)(((float)info.yres * 25.4f)/160.0f + 0.5f);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700235 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800236
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530237 float xdpi = ((float)info.xres * 25.4f) / (float)info.width;
238 float ydpi = ((float)info.yres * 25.4f) / (float)info.height;
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800239
240#ifdef MSMFB_METADATA_GET
241 struct msmfb_metadata metadata;
242 memset(&metadata, 0 , sizeof(metadata));
243 metadata.op = metadata_op_frame_rate;
244
245 if (ioctl(fb_fd, MSMFB_METADATA_GET, &metadata) == -1) {
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +0530246 ALOGE("%s:Error retrieving panel frame rate: %s", __FUNCTION__,
247 strerror(errno));
248 close(fb_fd);
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800249 return -errno;
250 }
251
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530252 float fps = (float)metadata.data.panel_frame_rate;
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800253#else
254 //XXX: Remove reserved field usage on all baselines
255 //The reserved[3] field is used to store FPS by the driver.
256 float fps = info.reserved[3] & 0xFF;
257#endif
258
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +0530259 if (ioctl(fb_fd, FBIOGET_FSCREENINFO, &finfo) == -1) {
260 ALOGE("%s:Error in ioctl FBIOGET_FSCREENINFO: %s", __FUNCTION__,
261 strerror(errno));
262 close(fb_fd);
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800263 return -errno;
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +0530264 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800265
266 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd = fb_fd;
267 //xres, yres may not be 32 aligned
268 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].stride = finfo.line_length /(info.xres/8);
269 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres = info.xres;
270 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres = info.yres;
271 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xdpi = xdpi;
272 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].ydpi = ydpi;
Arun Kumar K.Ra727a882014-08-20 17:14:26 -0700273 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].refreshRate = (uint32_t)fps;
274 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].dynRefreshRate = (uint32_t)fps;
Arun Kumar K.R074c9cf2014-08-21 18:43:53 -0700275 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].secure = true;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530276 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period =
277 (uint32_t)(1000000000l / fps);
radhakrishnac3198ff2015-03-10 17:10:02 +0530278 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fbformat = getFBformat(info);
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800279
Saurabh Shah90c55cf2015-02-10 15:37:39 -0800280 handleFbScaling(ctx, info.xres, info.yres, info.width, info.height);
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530281
Naseer Ahmed22616d92013-05-15 17:20:26 -0400282 //Unblank primary on first boot
283 if(ioctl(fb_fd, FBIOBLANK,FB_BLANK_UNBLANK) < 0) {
284 ALOGE("%s: Failed to unblank display", __FUNCTION__);
285 return -errno;
286 }
287 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].isActive = true;
288
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800289 return 0;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700290}
291
Ramakant Singh98c533c2014-09-30 19:01:54 +0530292static void changeDefaultAppBufferCount() {
293 struct sysinfo info;
294 unsigned long int ramSize = 0;
295 if (!sysinfo(&info)) {
296 ramSize = info.totalram ;
297 }
298 int fb_fd = -1;
299 struct fb_var_screeninfo sInfo ={0};
300 fb_fd = open("/dev/graphics/fb0", O_RDONLY);
301 if (fb_fd >=0) {
302 ioctl(fb_fd, FBIOGET_VSCREENINFO, &sInfo);
303 close(fb_fd);
304 }
305 if ((ramSize && ramSize < MAX_RAM_SIZE) &&
306 (sInfo.xres && sInfo.xres <= qHD_WIDTH )) {
Sanjeev Jakkilinkif8bc0362015-02-23 20:20:17 +0530307 property_set(PROP_DEFAULT_APPBUFFER, "3");
Ramakant Singh98c533c2014-09-30 19:01:54 +0530308 }
309}
310
Arun Kumar K.R205df772015-02-20 18:45:58 -0800311int initContext(hwc_context_t *ctx)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700312{
Arun Kumar K.R205df772015-02-20 18:45:58 -0800313 int error = -1;
314 int compositionType = 0;
315
316 //Right now hwc starts the service but anybody could do it, or it could be
317 //independent process as well.
318 QService::init();
319 sp<IQClient> client = new QClient(ctx);
320 sp<IQService> iqs = interface_cast<IQService>(
321 defaultServiceManager()->getService(
322 String16("display.qservice")));
323 if (iqs.get()) {
324 iqs->connect(client);
325 ctx->mQService = reinterpret_cast<QService* >(iqs.get());
326 } else {
327 ALOGE("%s: Failed to acquire service pointer", __FUNCTION__);
328 return error;
329 }
330
Tatenda Chipeperekwad80b6172014-09-23 11:29:37 -0700331 overlay::Overlay::initOverlay();
332 ctx->mHDMIDisplay = new HDMIDisplay();
333 uint32_t priW = 0, priH = 0;
334 // 1. HDMI as Primary
335 // -If HDMI cable is connected, read display configs from edid data
336 // -If HDMI cable is not connected then use default data in vscreeninfo
337 // 2. HDMI as External
338 // -Initialize HDMI class for use with external display
339 // -Use vscreeninfo to populate display configs
340 if(ctx->mHDMIDisplay->isHDMIPrimaryDisplay()) {
341 int connected = ctx->mHDMIDisplay->getConnectedState();
342 if(connected == 1) {
Arun Kumar K.R205df772015-02-20 18:45:58 -0800343 error = ctx->mHDMIDisplay->configure();
344 if (error < 0) {
345 goto OpenFBError;
346 }
Tatenda Chipeperekwad80b6172014-09-23 11:29:37 -0700347 updateDisplayInfo(ctx, HWC_DISPLAY_PRIMARY);
348 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].connected = true;
349 } else {
Arun Kumar K.R205df772015-02-20 18:45:58 -0800350 error = openFramebufferDevice(ctx);
351 if(error < 0) {
352 goto OpenFBError;
353 }
Tatenda Chipeperekwad80b6172014-09-23 11:29:37 -0700354 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].connected = false;
355 }
356 } else {
Arun Kumar K.R205df772015-02-20 18:45:58 -0800357 error = openFramebufferDevice(ctx);
358 if(error < 0) {
359 goto OpenFBError;
360 }
Tatenda Chipeperekwad80b6172014-09-23 11:29:37 -0700361 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].connected = true;
362 // Send the primary resolution to the hdmi display class
363 // to be used for MDP scaling functionality
364 priW = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
365 priH = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres;
366 ctx->mHDMIDisplay->setPrimaryAttributes(priW, priH);
367 }
368
Raj kamal59fea562014-04-01 16:52:19 +0530369 char value[PROPERTY_VALUE_MAX];
Naseer Ahmed96c4c952012-07-25 18:27:14 -0700370 ctx->mMDP.version = qdutils::MDPVersion::getInstance().getMDPVersion();
371 ctx->mMDP.hasOverlay = qdutils::MDPVersion::getInstance().hasOverlay();
372 ctx->mMDP.panel = qdutils::MDPVersion::getInstance().getPanelType();
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800373 ctx->mOverlay = overlay::Overlay::getInstance();
Saurabh Shah7a606842013-12-11 14:36:04 -0800374 ctx->mRotMgr = RotMgr::getInstance();
Saurabh Shahcd018352014-11-11 13:54:19 -0800375 ctx->mBWCEnabled = qdutils::MDPVersion::getInstance().supportsBWC();
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800376
Ramakant Singh98c533c2014-09-30 19:01:54 +0530377 //default_app_buffer for ferrum
378 if (ctx->mMDP.version == qdutils::MDP_V3_0_5) {
379 changeDefaultAppBufferCount();
380 }
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700381 // Initialize composition objects for the primary display
382 initCompositionResources(ctx, HWC_DISPLAY_PRIMARY);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800383
Arun Kumar K.R9fc89972014-01-02 17:01:02 -0800384 // Check if the target supports copybit compostion (dyn/mdp) to
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800385 // decide if we need to open the copybit module.
Arun Kumar K.R205df772015-02-20 18:45:58 -0800386 compositionType =
387 qdutils::QCCompositionType::getInstance().getCompositionType();
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800388
Arun Kumar K.R9fc89972014-01-02 17:01:02 -0800389 // Only MDP copybit is used
390 if ((compositionType & (qdutils::COMPOSITION_TYPE_DYN |
391 qdutils::COMPOSITION_TYPE_MDP)) &&
Ramakant Singhb4106a12014-10-07 18:06:56 +0530392 ((qdutils::MDPVersion::getInstance().getMDPVersion() ==
393 qdutils::MDP_V3_0_4) ||
Arun Kumar K.R9fc89972014-01-02 17:01:02 -0800394 (qdutils::MDPVersion::getInstance().getMDPVersion() ==
Ramakant Singhb4106a12014-10-07 18:06:56 +0530395 qdutils::MDP_V3_0_5))) {
Arun Kumar K.R9fc89972014-01-02 17:01:02 -0800396 ctx->mCopyBit[HWC_DISPLAY_PRIMARY] = new CopyBit(ctx,
397 HWC_DISPLAY_PRIMARY);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800398 }
399
Manoj Kumar AVM9591a5e2014-08-21 22:50:21 -0700400 ctx->mHWCVirtual = new HWCVirtualVDS();
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700401 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isActive = false;
402 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected = false;
403 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isActive = false;
404 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected = false;
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700405 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].mMDPScalingMode= false;
406 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].mMDPScalingMode = false;
407 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].mMDPScalingMode = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800408
Arun Kumar K.R81f3f2e2014-06-23 14:03:12 -0700409 //Initialize the primary display viewFrame info
410 ctx->mViewFrame[HWC_DISPLAY_PRIMARY].left = 0;
411 ctx->mViewFrame[HWC_DISPLAY_PRIMARY].top = 0;
412 ctx->mViewFrame[HWC_DISPLAY_PRIMARY].right =
413 (int)ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
414 ctx->mViewFrame[HWC_DISPLAY_PRIMARY].bottom =
415 (int)ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres;
Raj kamal59fea562014-04-01 16:52:19 +0530416
Amara Venkata Mastan Manoj Kumar7fb13272013-07-01 13:59:34 -0700417 for (uint32_t i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700418 ctx->mHwcDebug[i] = new HwcDebug(i);
Saurabh Shah23a813c2013-03-20 16:58:12 -0700419 ctx->mLayerRotMap[i] = new LayerRotMap();
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -0700420 ctx->mAnimationState[i] = ANIMATION_STOPPED;
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800421 ctx->dpyAttr[i].mActionSafePresent = false;
422 ctx->dpyAttr[i].mAsWidthRatio = 0;
423 ctx->dpyAttr[i].mAsHeightRatio = 0;
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -0500424 ctx->dpyAttr[i].s3dMode = HDMI_S3D_NONE;
425 ctx->dpyAttr[i].s3dModeForced = false;
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700426 }
Saurabh Shah23a813c2013-03-20 16:58:12 -0700427
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -0500428 //Make sure that the 3D mode is unset at bootup
429 //This makes sure that the state is accurate on framework reboots
430 ctx->mHDMIDisplay->configure3D(HDMI_S3D_NONE);
431
Raj Kamal9ed3d6b2014-02-07 16:15:17 +0530432 for (uint32_t i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
433 ctx->mPrevHwLayerCount[i] = 0;
434 }
435
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500436 MDPComp::init(ctx);
Saurabh Shahc4f1fa62013-09-03 13:12:14 -0700437 ctx->mAD = new AssertiveDisplay(ctx);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700438
Naseer Ahmedff4f0252012-10-01 13:03:01 -0400439 ctx->vstate.enable = false;
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500440 ctx->vstate.fakevsync = false;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700441 ctx->mExtOrientation = 0;
Raj Kamal52b4fdb2014-01-27 19:35:13 +0530442 ctx->numActiveDisplays = 1;
Saurabh Shah86c17292013-02-08 15:24:13 -0800443
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -0700444 // Initialize device orientation to its default orientation
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700445 ctx->deviceOrientation = 0;
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700446 ctx->mBufferMirrorMode = false;
Zohaib Alam1bb65612013-09-28 03:38:20 -0400447
Ramkumar Radhakrishnan812999a2014-09-11 21:42:07 -0700448 property_get("sys.hwc.windowbox_aspect_ratio_tolerance", value, "0");
449 ctx->mAspectRatioToleranceLevel = (((float)atoi(value)) / 100.0f);
450
Ramakant Singh0def28c2014-03-28 20:43:13 +0530451 ctx->enableABC = false;
452 property_get("debug.sf.hwc.canUseABC", value, "0");
453 ctx->enableABC = atoi(value) ? true : false;
454
Krishna Chaitanya Parimidb992fd2014-10-22 20:50:50 +0530455 // Initializing boot anim completed check to false
456 ctx->mBootAnimCompleted = false;
457
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -0700458 // Initialize gpu perfomance hint related parameters
459 property_get("sys.hwc.gpu_perf_mode", value, "0");
Saurabh Shah74eff4d2014-03-28 16:33:13 -0700460#ifdef QCOM_BSP
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -0700461 ctx->mGPUHintInfo.mGpuPerfModeEnable = atoi(value)? true : false;
462
463 ctx->mGPUHintInfo.mEGLDisplay = NULL;
464 ctx->mGPUHintInfo.mEGLContext = NULL;
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -0700465 ctx->mGPUHintInfo.mCompositionState = COMPOSITION_STATE_MDP;
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -0700466 ctx->mGPUHintInfo.mCurrGPUPerfMode = EGL_GPU_LEVEL_0;
Saurabh Shah74eff4d2014-03-28 16:33:13 -0700467#endif
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -0700468 // Read the system property to determine if windowboxing feature is enabled.
469 ctx->mWindowboxFeature = false;
470 if(property_get("sys.hwc.windowbox_feature", value, "false")
471 && !strcmp(value, "true")) {
472 ctx->mWindowboxFeature = true;
473 }
474
Raj Kamal0d53fc62014-11-25 17:36:36 +0530475 ctx->mUseMetaDataRefreshRate = true;
476 if(property_get("persist.metadata_dynfps.disable", value, "false")
477 && !strcmp(value, "true")) {
478 ctx->mUseMetaDataRefreshRate = false;
479 }
480
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700481 memset(&(ctx->mPtorInfo), 0, sizeof(ctx->mPtorInfo));
Arun Kumar K.R2225eaa2014-12-02 15:52:41 -0800482 ctx->mHPDEnabled = false;
Zohaib Alam83ea46d2015-03-23 15:44:19 -0400483
484 //init qdcm service related context.
485 qdcmInitContext(ctx);
486
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700487 ALOGI("Initializing Qualcomm Hardware Composer");
Naseer Ahmed96c4c952012-07-25 18:27:14 -0700488 ALOGI("MDP version: %d", ctx->mMDP.version);
Arun Kumar K.R205df772015-02-20 18:45:58 -0800489
490 return 0;
491
492OpenFBError:
493 ALOGE("%s: Fatal Error: FB Open failed!!!", __FUNCTION__);
494 delete ctx->mHDMIDisplay;
495 return error;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700496}
497
498void closeContext(hwc_context_t *ctx)
499{
Zohaib Alam83ea46d2015-03-23 15:44:19 -0400500 //close qdcm service related context.
501 qdcmCloseContext(ctx);
502
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500503 if(ctx->mOverlay) {
504 delete ctx->mOverlay;
505 ctx->mOverlay = NULL;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700506 }
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700507
Saurabh Shahacf10202013-02-26 10:15:15 -0800508 if(ctx->mRotMgr) {
509 delete ctx->mRotMgr;
510 ctx->mRotMgr = NULL;
511 }
512
Amara Venkata Mastan Manoj Kumar7fb13272013-07-01 13:59:34 -0700513 for(int i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800514 if(ctx->mCopyBit[i]) {
515 delete ctx->mCopyBit[i];
516 ctx->mCopyBit[i] = NULL;
517 }
518 }
519
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800520 if(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700521 close(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd);
522 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd = -1;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700523 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700524
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700525 if(ctx->mHDMIDisplay) {
526 delete ctx->mHDMIDisplay;
527 ctx->mHDMIDisplay = NULL;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700528 }
Naseer Ahmedff4f0252012-10-01 13:03:01 -0400529
Amara Venkata Mastan Manoj Kumar7fb13272013-07-01 13:59:34 -0700530 for(int i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700531 destroyCompositionResources(ctx, i);
532
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700533 if(ctx->mHwcDebug[i]) {
534 delete ctx->mHwcDebug[i];
535 ctx->mHwcDebug[i] = NULL;
536 }
Saurabh Shah23a813c2013-03-20 16:58:12 -0700537 if(ctx->mLayerRotMap[i]) {
538 delete ctx->mLayerRotMap[i];
539 ctx->mLayerRotMap[i] = NULL;
540 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800541 }
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -0800542 if(ctx->mHWCVirtual) {
543 delete ctx->mHWCVirtual;
544 ctx->mHWCVirtual = NULL;
545 }
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700546 if(ctx->mAD) {
547 delete ctx->mAD;
548 ctx->mAD = NULL;
549 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800550
Naseer Ahmed7a7b66d2014-07-23 17:56:26 -0400551 if(ctx->mQService) {
552 delete ctx->mQService;
553 ctx->mQService = NULL;
554 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700555}
556
Arun Kumar K.Ra727a882014-08-20 17:14:26 -0700557//Helper to roundoff the refreshrates
Raj Kamal0d53fc62014-11-25 17:36:36 +0530558uint32_t roundOff(uint32_t refreshRate) {
Arun Kumar K.Ra727a882014-08-20 17:14:26 -0700559 int count = (int) (sizeof(stdRefreshRates)/sizeof(stdRefreshRates[0]));
560 uint32_t rate = refreshRate;
561 for(int i=0; i< count; i++) {
562 if(abs(stdRefreshRates[i] - refreshRate) < 2) {
563 // Most likely used for video, the fps can fluctuate
564 // Ex: b/w 29 and 30 for 30 fps clip
565 rate = stdRefreshRates[i];
566 break;
567 }
568 }
569 return rate;
570}
571
572//Helper func to set the dyn fps
573void setRefreshRate(hwc_context_t* ctx, int dpy, uint32_t refreshRate) {
574 //Update only if different
575 if(!ctx || refreshRate == ctx->dpyAttr[dpy].dynRefreshRate)
576 return;
577 const int fbNum = Overlay::getFbForDpy(dpy);
578 char sysfsPath[qdutils::MAX_SYSFS_FILE_PATH];
579 snprintf (sysfsPath, sizeof(sysfsPath),
Arun Kumar K.Ree4e2392015-01-12 18:08:34 -0800580 "/sys/devices/virtual/graphics/fb%d/dynamic_fps", fbNum);
Arun Kumar K.Ra727a882014-08-20 17:14:26 -0700581
582 int fd = open(sysfsPath, O_WRONLY);
583 if(fd >= 0) {
584 char str[64];
585 snprintf(str, sizeof(str), "%d", refreshRate);
586 ssize_t ret = write(fd, str, strlen(str));
587 if(ret < 0) {
588 ALOGE("%s: Failed to write %d with error %s",
589 __FUNCTION__, refreshRate, strerror(errno));
590 } else {
591 ctx->dpyAttr[dpy].dynRefreshRate = refreshRate;
592 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Wrote %d to dynamic_fps",
593 __FUNCTION__, refreshRate);
594 }
595 close(fd);
596 } else {
597 ALOGE("%s: Failed to open %s with error %s", __FUNCTION__, sysfsPath,
598 strerror(errno));
599 }
600}
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500601
602void dumpsys_log(android::String8& buf, const char* fmt, ...)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700603{
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500604 va_list varargs;
605 va_start(varargs, fmt);
606 buf.appendFormatV(fmt, varargs);
607 va_end(varargs);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700608}
609
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700610int getExtOrientation(hwc_context_t* ctx) {
611 int extOrient = ctx->mExtOrientation;
612 if(ctx->mBufferMirrorMode)
613 extOrient = getMirrorModeOrientation(ctx);
614 return extOrient;
615}
616
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800617/* Calculates the destination position based on the action safe rectangle */
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700618void getActionSafePosition(hwc_context_t *ctx, int dpy, hwc_rect_t& rect) {
619 // Position
620 int x = rect.left, y = rect.top;
621 int w = rect.right - rect.left;
622 int h = rect.bottom - rect.top;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800623
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800624 if(!ctx->dpyAttr[dpy].mActionSafePresent)
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800625 return;
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800626 // Read action safe properties
627 int asWidthRatio = ctx->dpyAttr[dpy].mAsWidthRatio;
628 int asHeightRatio = ctx->dpyAttr[dpy].mAsHeightRatio;
Arun Kumar K.R82f1d282013-05-17 15:37:31 -0700629
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800630 float wRatio = 1.0;
631 float hRatio = 1.0;
632 float xRatio = 1.0;
633 float yRatio = 1.0;
634
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700635 uint32_t fbWidth = ctx->dpyAttr[dpy].xres;
636 uint32_t fbHeight = ctx->dpyAttr[dpy].yres;
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700637 if(ctx->dpyAttr[dpy].mMDPScalingMode) {
638 // if MDP scaling mode is enabled for external, need to query
Arun Kumar KR7b7f4012013-10-29 11:53:11 -0700639 // the actual width and height, as that is the physical w & h
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700640 ctx->mHDMIDisplay->getAttributes(fbWidth, fbHeight);
Arun Kumar KR7b7f4012013-10-29 11:53:11 -0700641 }
642
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800643
Arun Kumar K.R82f1d282013-05-17 15:37:31 -0700644 // Since external is rotated 90, need to swap width/height
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700645 int extOrient = getExtOrientation(ctx);
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700646
647 if(extOrient & HWC_TRANSFORM_ROT_90)
Arun Kumar K.R82f1d282013-05-17 15:37:31 -0700648 swap(fbWidth, fbHeight);
649
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800650 float asX = 0;
651 float asY = 0;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530652 float asW = (float)fbWidth;
653 float asH = (float)fbHeight;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800654
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800655 // based on the action safe ratio, get the Action safe rectangle
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530656 asW = ((float)fbWidth * (1.0f - (float)asWidthRatio / 100.0f));
657 asH = ((float)fbHeight * (1.0f - (float)asHeightRatio / 100.0f));
658 asX = ((float)fbWidth - asW) / 2;
659 asY = ((float)fbHeight - asH) / 2;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800660
661 // calculate the position ratio
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530662 xRatio = (float)x/(float)fbWidth;
663 yRatio = (float)y/(float)fbHeight;
664 wRatio = (float)w/(float)fbWidth;
665 hRatio = (float)h/(float)fbHeight;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800666
667 //Calculate the position...
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530668 x = int((xRatio * asW) + asX);
669 y = int((yRatio * asH) + asY);
670 w = int(wRatio * asW);
671 h = int(hRatio * asH);
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800672
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700673 // Convert it back to hwc_rect_t
674 rect.left = x;
675 rect.top = y;
676 rect.right = w + rect.left;
677 rect.bottom = h + rect.top;
678
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800679 return;
680}
681
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700682// This function gets the destination position for Seconday display
683// based on the position and aspect ratio with orientation
684void getAspectRatioPosition(hwc_context_t* ctx, int dpy, int extOrientation,
685 hwc_rect_t& inRect, hwc_rect_t& outRect) {
686 // Physical display resolution
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530687 float fbWidth = (float)ctx->dpyAttr[dpy].xres;
688 float fbHeight = (float)ctx->dpyAttr[dpy].yres;
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700689 //display position(x,y,w,h) in correct aspectratio after rotation
690 int xPos = 0;
691 int yPos = 0;
692 float width = fbWidth;
693 float height = fbHeight;
694 // Width/Height used for calculation, after rotation
695 float actualWidth = fbWidth;
696 float actualHeight = fbHeight;
697
698 float wRatio = 1.0;
699 float hRatio = 1.0;
700 float xRatio = 1.0;
701 float yRatio = 1.0;
702 hwc_rect_t rect = {0, 0, (int)fbWidth, (int)fbHeight};
703
704 Dim inPos(inRect.left, inRect.top, inRect.right - inRect.left,
705 inRect.bottom - inRect.top);
706 Dim outPos(outRect.left, outRect.top, outRect.right - outRect.left,
707 outRect.bottom - outRect.top);
708
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530709 Whf whf((uint32_t)fbWidth, (uint32_t)fbHeight, 0);
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700710 eTransform extorient = static_cast<eTransform>(extOrientation);
711 // To calculate the destination co-ordinates in the new orientation
712 preRotateSource(extorient, whf, inPos);
713
714 if(extOrientation & HAL_TRANSFORM_ROT_90) {
715 // Swap width/height for input position
716 swapWidthHeight(actualWidth, actualHeight);
Tatenda Chipeperekwace8d5c42014-08-13 10:53:49 -0700717 qdutils::getAspectRatioPosition((int)fbWidth, (int)fbHeight,
718 (int)actualWidth, (int)actualHeight, rect);
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700719 xPos = rect.left;
720 yPos = rect.top;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530721 width = float(rect.right - rect.left);
722 height = float(rect.bottom - rect.top);
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700723 }
Shalaj Jaina70b4352014-06-15 13:47:47 -0700724 xRatio = (float)((float)inPos.x/actualWidth);
725 yRatio = (float)((float)inPos.y/actualHeight);
726 wRatio = (float)((float)inPos.w/actualWidth);
727 hRatio = (float)((float)inPos.h/actualHeight);
Ramkumar Radhakrishnandebfc5a2013-12-04 15:15:42 -0800728
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530729 //Calculate the pos9ition...
730 outPos.x = uint32_t((xRatio * width) + (float)xPos);
731 outPos.y = uint32_t((yRatio * height) + (float)yPos);
732 outPos.w = uint32_t(wRatio * width);
733 outPos.h = uint32_t(hRatio * height);
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700734 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Calculated AspectRatio Position: x = %d,"
735 "y = %d w = %d h = %d", __FUNCTION__, outPos.x, outPos.y,
736 outPos.w, outPos.h);
737
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700738 // For sidesync, the dest fb will be in portrait orientation, and the crop
739 // will be updated to avoid the black side bands, and it will be upscaled
740 // to fit the dest RB, so recalculate
741 // the position based on the new width and height
742 if ((extOrientation & HWC_TRANSFORM_ROT_90) &&
743 isOrientationPortrait(ctx)) {
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800744 hwc_rect_t r = {0, 0, 0, 0};
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700745 //Calculate the position
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530746 xRatio = (float)(outPos.x - xPos)/width;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700747 // GetaspectRatio -- tricky to get the correct aspect ratio
748 // But we need to do this.
Tatenda Chipeperekwace8d5c42014-08-13 10:53:49 -0700749 qdutils::getAspectRatioPosition((int)width, (int)height,
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530750 (int)width,(int)height, r);
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700751 xPos = r.left;
752 yPos = r.top;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530753 float tempHeight = float(r.bottom - r.top);
754 yRatio = (float)yPos/height;
755 wRatio = (float)outPos.w/width;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700756 hRatio = tempHeight/height;
757
758 //Map the coordinates back to Framebuffer domain
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530759 outPos.x = uint32_t(xRatio * fbWidth);
760 outPos.y = uint32_t(yRatio * fbHeight);
761 outPos.w = uint32_t(wRatio * fbWidth);
762 outPos.h = uint32_t(hRatio * fbHeight);
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700763
764 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Calculated AspectRatio for device in"
765 "portrait: x = %d,y = %d w = %d h = %d", __FUNCTION__,
766 outPos.x, outPos.y,
767 outPos.w, outPos.h);
768 }
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700769 if(ctx->dpyAttr[dpy].mMDPScalingMode) {
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700770 uint32_t extW = 0, extH = 0;
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700771 if(dpy == HWC_DISPLAY_EXTERNAL) {
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700772 ctx->mHDMIDisplay->getAttributes(extW, extH);
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700773 } else if(dpy == HWC_DISPLAY_VIRTUAL) {
774 extW = ctx->mHWCVirtual->getScalingWidth();
775 extH = ctx->mHWCVirtual->getScalingHeight();
776 }
777 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Scaling mode extW=%d extH=%d",
778 __FUNCTION__, extW, extH);
779
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530780 fbWidth = (float)ctx->dpyAttr[dpy].xres;
781 fbHeight = (float)ctx->dpyAttr[dpy].yres;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700782 //Calculate the position...
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530783 xRatio = (float)outPos.x/fbWidth;
784 yRatio = (float)outPos.y/fbHeight;
785 wRatio = (float)outPos.w/fbWidth;
786 hRatio = (float)outPos.h/fbHeight;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700787
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530788 outPos.x = uint32_t(xRatio * (float)extW);
789 outPos.y = uint32_t(yRatio * (float)extH);
790 outPos.w = uint32_t(wRatio * (float)extW);
791 outPos.h = uint32_t(hRatio * (float)extH);
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700792 }
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700793 // Convert Dim to hwc_rect_t
794 outRect.left = outPos.x;
795 outRect.top = outPos.y;
796 outRect.right = outPos.x + outPos.w;
797 outRect.bottom = outPos.y + outPos.h;
798
799 return;
800}
801
802bool isPrimaryPortrait(hwc_context_t *ctx) {
803 int fbWidth = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
804 int fbHeight = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres;
805 if(fbWidth < fbHeight) {
806 return true;
807 }
808 return false;
809}
810
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700811bool isOrientationPortrait(hwc_context_t *ctx) {
812 if(isPrimaryPortrait(ctx)) {
813 return !(ctx->deviceOrientation & 0x1);
814 }
815 return (ctx->deviceOrientation & 0x1);
816}
817
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700818void calcExtDisplayPosition(hwc_context_t *ctx,
819 private_handle_t *hnd,
820 int dpy,
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700821 hwc_rect_t& sourceCrop,
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700822 hwc_rect_t& displayFrame,
823 int& transform,
824 ovutils::eTransform& orient) {
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700825 // Swap width and height when there is a 90deg transform
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700826 int extOrient = getExtOrientation(ctx);
Raj Kamal068f4572014-04-14 16:14:06 +0530827 if(dpy && ctx->mOverlay->isUIScalingOnExternalSupported()) {
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700828 if(!isYuvBuffer(hnd)) {
829 if(extOrient & HWC_TRANSFORM_ROT_90) {
830 int dstWidth = ctx->dpyAttr[dpy].xres;
831 int dstHeight = ctx->dpyAttr[dpy].yres;;
832 int srcWidth = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
833 int srcHeight = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres;
834 if(!isPrimaryPortrait(ctx)) {
835 swap(srcWidth, srcHeight);
836 } // Get Aspect Ratio for external
Tatenda Chipeperekwace8d5c42014-08-13 10:53:49 -0700837 qdutils::getAspectRatioPosition(dstWidth, dstHeight, srcWidth,
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700838 srcHeight, displayFrame);
839 // Crop - this is needed, because for sidesync, the dest fb will
840 // be in portrait orientation, so update the crop to not show the
841 // black side bands.
842 if (isOrientationPortrait(ctx)) {
843 sourceCrop = displayFrame;
844 displayFrame.left = 0;
845 displayFrame.top = 0;
846 displayFrame.right = dstWidth;
847 displayFrame.bottom = dstHeight;
848 }
849 }
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700850 if(ctx->dpyAttr[dpy].mMDPScalingMode) {
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700851 uint32_t extW = 0, extH = 0;
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700852 // if MDP scaling mode is enabled, map the co-ordinates to new
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700853 // domain(downscaled)
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530854 float fbWidth = (float)ctx->dpyAttr[dpy].xres;
855 float fbHeight = (float)ctx->dpyAttr[dpy].yres;
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700856 // query MDP configured attributes
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700857 if(dpy == HWC_DISPLAY_EXTERNAL) {
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700858 ctx->mHDMIDisplay->getAttributes(extW, extH);
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700859 } else if(dpy == HWC_DISPLAY_VIRTUAL) {
860 extW = ctx->mHWCVirtual->getScalingWidth();
861 extH = ctx->mHWCVirtual->getScalingHeight();
862 }
863 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Scaling mode extW=%d extH=%d",
864 __FUNCTION__, extW, extH);
865
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700866 //Calculate the ratio...
867 float wRatio = ((float)extW)/fbWidth;
868 float hRatio = ((float)extH)/fbHeight;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700869
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700870 //convert Dim to hwc_rect_t
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530871 displayFrame.left = int(wRatio*(float)displayFrame.left);
872 displayFrame.top = int(hRatio*(float)displayFrame.top);
873 displayFrame.right = int(wRatio*(float)displayFrame.right);
874 displayFrame.bottom = int(hRatio*(float)displayFrame.bottom);
Ramkumar Radhakrishnana5c72872014-08-28 19:04:18 -0700875 ALOGD_IF(DEBUG_MDPDOWNSCALE, "Calculated external display frame"
876 " for MDPDownscale feature [%d %d %d %d]",
877 displayFrame.left, displayFrame.top,
878 displayFrame.right, displayFrame.bottom);
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700879 }
880 }else {
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700881 if(extOrient || ctx->dpyAttr[dpy].mMDPScalingMode) {
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700882 getAspectRatioPosition(ctx, dpy, extOrient,
883 displayFrame, displayFrame);
884 }
885 }
886 // If there is a external orientation set, use that
887 if(extOrient) {
888 transform = extOrient;
889 orient = static_cast<ovutils::eTransform >(extOrient);
890 }
891 // Calculate the actionsafe dimensions for External(dpy = 1 or 2)
892 getActionSafePosition(ctx, dpy, displayFrame);
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700893 }
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700894}
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700895
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700896/* Returns the orientation which needs to be set on External for
897 * SideSync/Buffer Mirrormode
898 */
899int getMirrorModeOrientation(hwc_context_t *ctx) {
900 int extOrientation = 0;
901 int deviceOrientation = ctx->deviceOrientation;
902 if(!isPrimaryPortrait(ctx))
903 deviceOrientation = (deviceOrientation + 1) % 4;
904 if (deviceOrientation == 0)
905 extOrientation = HWC_TRANSFORM_ROT_270;
906 else if (deviceOrientation == 1)//90
907 extOrientation = 0;
908 else if (deviceOrientation == 2)//180
909 extOrientation = HWC_TRANSFORM_ROT_90;
910 else if (deviceOrientation == 3)//270
911 extOrientation = HWC_TRANSFORM_FLIP_V | HWC_TRANSFORM_FLIP_H;
912
913 return extOrientation;
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700914}
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700915
Raj kamal59fea562014-04-01 16:52:19 +0530916/* Get External State names */
917const char* getExternalDisplayState(uint32_t external_state) {
918 static const char* externalStates[EXTERNAL_MAXSTATES] = {0};
919 externalStates[EXTERNAL_OFFLINE] = STR(EXTERNAL_OFFLINE);
920 externalStates[EXTERNAL_ONLINE] = STR(EXTERNAL_ONLINE);
921 externalStates[EXTERNAL_PAUSE] = STR(EXTERNAL_PAUSE);
922 externalStates[EXTERNAL_RESUME] = STR(EXTERNAL_RESUME);
923
924 if(external_state >= EXTERNAL_MAXSTATES) {
925 return "EXTERNAL_INVALID";
926 }
927
928 return externalStates[external_state];
929}
930
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530931bool isDownscaleRequired(hwc_layer_1_t const* layer) {
932 hwc_rect_t displayFrame = layer->displayFrame;
933 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
934 int dst_w, dst_h, src_w, src_h;
935 dst_w = displayFrame.right - displayFrame.left;
936 dst_h = displayFrame.bottom - displayFrame.top;
937 src_w = sourceCrop.right - sourceCrop.left;
938 src_h = sourceCrop.bottom - sourceCrop.top;
939
940 if(((src_w > dst_w) || (src_h > dst_h)))
941 return true;
942
943 return false;
944}
945bool needsScaling(hwc_layer_1_t const* layer) {
Naseer Ahmed018e5452012-12-03 14:46:15 -0500946 int dst_w, dst_h, src_w, src_h;
Naseer Ahmed018e5452012-12-03 14:46:15 -0500947 hwc_rect_t displayFrame = layer->displayFrame;
Saurabh Shah62e1d732013-09-17 10:44:05 -0700948 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
Naseer Ahmed018e5452012-12-03 14:46:15 -0500949
950 dst_w = displayFrame.right - displayFrame.left;
951 dst_h = displayFrame.bottom - displayFrame.top;
Naseer Ahmed018e5452012-12-03 14:46:15 -0500952 src_w = sourceCrop.right - sourceCrop.left;
953 src_h = sourceCrop.bottom - sourceCrop.top;
954
Jeykumar Sankaran6a339522014-11-04 16:14:43 -0800955 if(layer->transform & HWC_TRANSFORM_ROT_90)
956 swap(src_w, src_h);
957
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800958 if(((src_w != dst_w) || (src_h != dst_h)))
959 return true;
960
961 return false;
962}
963
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700964// Checks if layer needs scaling with split
965bool needsScalingWithSplit(hwc_context_t* ctx, hwc_layer_1_t const* layer,
966 const int& dpy) {
967
968 int src_width_l, src_height_l;
969 int src_width_r, src_height_r;
970 int dst_width_l, dst_height_l;
971 int dst_width_r, dst_height_r;
972 int hw_w = ctx->dpyAttr[dpy].xres;
973 int hw_h = ctx->dpyAttr[dpy].yres;
974 hwc_rect_t cropL, dstL, cropR, dstR;
975 const int lSplit = getLeftSplit(ctx, dpy);
Saurabh Shah62e1d732013-09-17 10:44:05 -0700976 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700977 hwc_rect_t displayFrame = layer->displayFrame;
978 private_handle_t *hnd = (private_handle_t *)layer->handle;
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700979
980 cropL = sourceCrop;
981 dstL = displayFrame;
982 hwc_rect_t scissorL = { 0, 0, lSplit, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -0800983 scissorL = getIntersection(ctx->mViewFrame[dpy], scissorL);
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700984 qhwc::calculate_crop_rects(cropL, dstL, scissorL, 0);
985
986 cropR = sourceCrop;
987 dstR = displayFrame;
988 hwc_rect_t scissorR = { lSplit, 0, hw_w, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -0800989 scissorR = getIntersection(ctx->mViewFrame[dpy], scissorR);
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700990 qhwc::calculate_crop_rects(cropR, dstR, scissorR, 0);
991
992 // Sanitize Crop to stitch
993 sanitizeSourceCrop(cropL, cropR, hnd);
994
995 // Calculate the left dst
996 dst_width_l = dstL.right - dstL.left;
997 dst_height_l = dstL.bottom - dstL.top;
998 src_width_l = cropL.right - cropL.left;
999 src_height_l = cropL.bottom - cropL.top;
1000
1001 // check if there is any scaling on the left
1002 if(((src_width_l != dst_width_l) || (src_height_l != dst_height_l)))
1003 return true;
1004
1005 // Calculate the right dst
1006 dst_width_r = dstR.right - dstR.left;
1007 dst_height_r = dstR.bottom - dstR.top;
1008 src_width_r = cropR.right - cropR.left;
1009 src_height_r = cropR.bottom - cropR.top;
1010
1011 // check if there is any scaling on the right
1012 if(((src_width_r != dst_width_r) || (src_height_r != dst_height_r)))
1013 return true;
1014
1015 return false;
1016}
1017
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301018bool isAlphaScaled(hwc_layer_1_t const* layer) {
1019 if(needsScaling(layer) && isAlphaPresent(layer)) {
Sravan Kumar D.V.N075ef002013-03-20 05:22:26 +05301020 return true;
1021 }
1022 return false;
1023}
1024
1025bool isAlphaPresent(hwc_layer_1_t const* layer) {
1026 private_handle_t *hnd = (private_handle_t *)layer->handle;
Naseer Ahmed7a4287c2013-03-26 18:11:41 -04001027 if(hnd) {
1028 int format = hnd->format;
1029 switch(format) {
Sravan Kumar D.V.N075ef002013-03-20 05:22:26 +05301030 case HAL_PIXEL_FORMAT_RGBA_8888:
1031 case HAL_PIXEL_FORMAT_BGRA_8888:
1032 // In any more formats with Alpha go here..
Naseer Ahmed018e5452012-12-03 14:46:15 -05001033 return true;
Sravan Kumar D.V.N075ef002013-03-20 05:22:26 +05301034 default : return false;
Naseer Ahmed7a4287c2013-03-26 18:11:41 -04001035 }
Naseer Ahmed018e5452012-12-03 14:46:15 -05001036 }
1037 return false;
1038}
1039
radhakrishnac3198ff2015-03-10 17:10:02 +05301040bool isAlphaPresentinFB(hwc_context_t *ctx, int dpy) {
1041 switch(ctx->dpyAttr[dpy].fbformat) {
1042 case HAL_PIXEL_FORMAT_RGBA_8888:
1043 case HAL_PIXEL_FORMAT_BGRA_8888:
1044 return true;
1045 default : return false;
1046 }
1047 return false;
1048}
1049
Saurabh Shahd9ff30b2013-10-03 16:37:06 -07001050static void trimLayer(hwc_context_t *ctx, const int& dpy, const int& transform,
1051 hwc_rect_t& crop, hwc_rect_t& dst) {
1052 int hw_w = ctx->dpyAttr[dpy].xres;
1053 int hw_h = ctx->dpyAttr[dpy].yres;
1054 if(dst.left < 0 || dst.top < 0 ||
1055 dst.right > hw_w || dst.bottom > hw_h) {
1056 hwc_rect_t scissor = {0, 0, hw_w, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -08001057 scissor = getIntersection(ctx->mViewFrame[dpy], scissor);
Saurabh Shahd9ff30b2013-10-03 16:37:06 -07001058 qhwc::calculate_crop_rects(crop, dst, scissor, transform);
1059 }
1060}
1061
1062static void trimList(hwc_context_t *ctx, hwc_display_contents_1_t *list,
1063 const int& dpy) {
1064 for(uint32_t i = 0; i < list->numHwLayers - 1; i++) {
1065 hwc_layer_1_t *layer = &list->hwLayers[i];
1066 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Sushil Chauhanfda00fc2014-03-20 11:08:41 -07001067 int transform = (list->hwLayers[i].flags & HWC_COLOR_FILL) ? 0 :
1068 list->hwLayers[i].transform;
Saurabh Shahd9ff30b2013-10-03 16:37:06 -07001069 trimLayer(ctx, dpy,
Sushil Chauhanfda00fc2014-03-20 11:08:41 -07001070 transform,
Saurabh Shahd9ff30b2013-10-03 16:37:06 -07001071 (hwc_rect_t&)crop,
1072 (hwc_rect_t&)list->hwLayers[i].displayFrame);
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301073 layer->sourceCropf.left = (float)crop.left;
1074 layer->sourceCropf.right = (float)crop.right;
1075 layer->sourceCropf.top = (float)crop.top;
1076 layer->sourceCropf.bottom = (float)crop.bottom;
Saurabh Shahd9ff30b2013-10-03 16:37:06 -07001077 }
1078}
1079
Saurabh Shah3e858eb2012-09-17 16:53:21 -07001080void setListStats(hwc_context_t *ctx,
Saurabh Shahd9ff30b2013-10-03 16:37:06 -07001081 hwc_display_contents_1_t *list, int dpy) {
Saurabh Shahd4e65852013-06-17 11:33:53 -07001082 const int prevYuvCount = ctx->listStats[dpy].yuvCount;
1083 memset(&ctx->listStats[dpy], 0, sizeof(ListStats));
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301084 ctx->listStats[dpy].numAppLayers = (int)list->numHwLayers - 1;
1085 ctx->listStats[dpy].fbLayerIndex = (int)list->numHwLayers - 1;
Saurabh Shahc4d034f2012-09-27 15:55:15 -07001086 ctx->listStats[dpy].skipCount = 0;
Sravan Kumar D.V.Nb5ed0292013-03-15 08:51:16 +05301087 ctx->listStats[dpy].preMultipliedAlpha = false;
Saurabh Shah8028e3b2013-10-15 12:27:59 -07001088 ctx->listStats[dpy].isSecurePresent = false;
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001089 ctx->listStats[dpy].yuvCount = 0;
Ping Li9404e2a2013-04-24 16:36:03 -04001090 char property[PROPERTY_VALUE_MAX];
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001091 ctx->listStats[dpy].isDisplayAnimating = false;
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -07001092 ctx->listStats[dpy].secureUI = false;
radhakrishnac9a67412013-09-25 17:40:42 +05301093 ctx->listStats[dpy].yuv4k2kCount = 0;
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -08001094 ctx->dpyAttr[dpy].mActionSafePresent = isActionSafePresent(ctx, dpy);
Ramakant Singh0def28c2014-03-28 20:43:13 +05301095 ctx->listStats[dpy].renderBufIndexforABC = -1;
Ramkumar Radhakrishnan4ec775f2014-07-23 17:43:18 -07001096 ctx->listStats[dpy].secureRGBCount = 0;
Arun Kumar K.Ra727a882014-08-20 17:14:26 -07001097 ctx->listStats[dpy].refreshRateRequest = ctx->dpyAttr[dpy].refreshRate;
Arun Kumar K.R00b84792015-03-27 11:28:36 -07001098 ctx->listStats[dpy].cursorLayerPresent = false;
Arun Kumar K.Ra727a882014-08-20 17:14:26 -07001099 uint32_t refreshRate = 0;
1100 qdutils::MDPVersion& mdpHw = qdutils::MDPVersion::getInstance();
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -05001101 int s3dFormat = HAL_NO_3D;
1102 int s3dLayerCount = 0;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001103
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07001104 ctx->listStats[dpy].mAIVVideoMode = false;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001105 resetROI(ctx, dpy);
1106
Sushil Chauhanf68d0df2014-04-09 09:15:37 -07001107 trimList(ctx, list, dpy);
1108 optimizeLayerRects(list);
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -07001109 for (size_t i = 0; i < (size_t)ctx->listStats[dpy].numAppLayers; i++) {
Naseer Ahmed018e5452012-12-03 14:46:15 -05001110 hwc_layer_1_t const* layer = &list->hwLayers[i];
1111 private_handle_t *hnd = (private_handle_t *)layer->handle;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001112
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001113#ifdef QCOM_BSP
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07001114 // Window boxing feature is applicable obly for external display, So
1115 // enable mAIVVideoMode only for external display
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07001116 if(ctx->mWindowboxFeature && dpy && isAIVVideoLayer(layer)) {
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07001117 ctx->listStats[dpy].mAIVVideoMode = true;
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07001118 }
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001119 if (layer->flags & HWC_SCREENSHOT_ANIMATOR_LAYER) {
1120 ctx->listStats[dpy].isDisplayAnimating = true;
1121 }
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -07001122 if(isSecureDisplayBuffer(hnd)) {
1123 ctx->listStats[dpy].secureUI = true;
1124 }
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001125#endif
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -07001126 // continue if number of app layers exceeds MAX_NUM_APP_LAYERS
1127 if(ctx->listStats[dpy].numAppLayers > MAX_NUM_APP_LAYERS)
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001128 continue;
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001129
Arun Kumar K.R00b84792015-03-27 11:28:36 -07001130 // Valid cursor must be the top most layer
1131 if((int)i == (ctx->listStats[dpy].numAppLayers - 1) &&
1132 isCursorLayer(&list->hwLayers[i])) {
1133 ctx->listStats[dpy].cursorLayerPresent = true;
1134 }
1135
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -07001136 //reset yuv indices
1137 ctx->listStats[dpy].yuvIndices[i] = -1;
radhakrishnac9a67412013-09-25 17:40:42 +05301138 ctx->listStats[dpy].yuv4k2kIndices[i] = -1;
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -07001139
Saurabh Shah8028e3b2013-10-15 12:27:59 -07001140 if (isSecureBuffer(hnd)) {
1141 ctx->listStats[dpy].isSecurePresent = true;
Ramkumar Radhakrishnan4ec775f2014-07-23 17:43:18 -07001142 if(not isYuvBuffer(hnd)) {
1143 // cache secureRGB layer parameters like we cache for YUV layers
1144 int& secureRGBCount = ctx->listStats[dpy].secureRGBCount;
1145 ctx->listStats[dpy].secureRGBIndices[secureRGBCount] = (int)i;
1146 secureRGBCount++;
1147 }
Saurabh Shah8028e3b2013-10-15 12:27:59 -07001148 }
1149
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -07001150 if (isSkipLayer(&list->hwLayers[i])) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -07001151 ctx->listStats[dpy].skipCount++;
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001152 }
1153
1154 if (UNLIKELY(isYuvBuffer(hnd))) {
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001155 int& yuvCount = ctx->listStats[dpy].yuvCount;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301156 ctx->listStats[dpy].yuvIndices[yuvCount] = (int)i;
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001157 yuvCount++;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001158
Raj Kamal389d6e32014-08-04 14:43:24 +05301159 if(UNLIKELY(isYUVSplitNeeded(hnd))){
radhakrishnac9a67412013-09-25 17:40:42 +05301160 int& yuv4k2kCount = ctx->listStats[dpy].yuv4k2kCount;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301161 ctx->listStats[dpy].yuv4k2kIndices[yuv4k2kCount] = (int)i;
radhakrishnac9a67412013-09-25 17:40:42 +05301162 yuv4k2kCount++;
1163 }
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -05001164
1165 // Gets set if one YUV layer is 3D
1166 if (displaySupports3D(ctx,dpy)) {
1167 s3dFormat = get3DFormat(hnd);
1168 if(s3dFormat != HAL_NO_3D)
1169 s3dLayerCount++;
1170 }
1171
Naseer Ahmed29a26812012-06-14 00:56:20 -07001172 }
Sravan Kumar D.V.Nb5ed0292013-03-15 08:51:16 +05301173 if(layer->blending == HWC_BLENDING_PREMULT)
1174 ctx->listStats[dpy].preMultipliedAlpha = true;
Jeykumar Sankaran7535aba2013-02-04 11:03:09 -08001175
Arun Kumar K.Ra727a882014-08-20 17:14:26 -07001176#ifdef DYNAMIC_FPS
Raj Kamal0d53fc62014-11-25 17:36:36 +05301177 if (!dpy && mdpHw.isDynFpsSupported() && ctx->mUseMetaDataRefreshRate){
Arun Kumar K.Ra727a882014-08-20 17:14:26 -07001178 //dyn fps: get refreshrate from metadata
1179 //Support multiple refresh rates if they are same
1180 //else set to default
1181 MetaData_t *mdata = hnd ? (MetaData_t *)hnd->base_metadata : NULL;
1182 if (mdata && (mdata->operation & UPDATE_REFRESH_RATE)) {
1183 // Valid refreshRate in metadata and within the range
1184 uint32_t rate = roundOff(mdata->refreshrate);
1185 if((rate >= mdpHw.getMinFpsSupported() &&
1186 rate <= mdpHw.getMaxFpsSupported())) {
1187 if (!refreshRate) {
1188 refreshRate = rate;
1189 } else if(refreshRate != rate) {
1190 // multiple refreshrate requests, set to default
1191 refreshRate = ctx->dpyAttr[dpy].refreshRate;
1192 }
1193 }
1194 }
1195 }
1196#endif
Naseer Ahmed29a26812012-06-14 00:56:20 -07001197 }
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -05001198
1199 //Set the TV's 3D mode based on format if it was not forced
1200 //Only one 3D YUV layer is supported on external
1201 //If there is more than one 3D YUV layer, the switch to 3D cannot occur.
1202 if( !ctx->dpyAttr[dpy].s3dModeForced && (s3dLayerCount <= 1)) {
1203 //XXX: Rapidly going in and out of 3D mode in some cases such
1204 // as rotation might cause flickers. The OEMs are recommended to disable
1205 // rotation on HDMI globally or in the app that plays 3D video
1206 setup3DMode(ctx, dpy, convertS3DFormatToMode(s3dFormat));
1207 }
1208
Ping Li9404e2a2013-04-24 16:36:03 -04001209 if(ctx->listStats[dpy].yuvCount > 0) {
1210 if (property_get("hw.cabl.yuv", property, NULL) > 0) {
1211 if (atoi(property) != 1) {
1212 property_set("hw.cabl.yuv", "1");
1213 }
1214 }
1215 } else {
1216 if (property_get("hw.cabl.yuv", property, NULL) > 0) {
1217 if (atoi(property) != 0) {
1218 property_set("hw.cabl.yuv", "0");
1219 }
1220 }
1221 }
Saurabh Shahd4e65852013-06-17 11:33:53 -07001222
1223 //The marking of video begin/end is useful on some targets where we need
1224 //to have a padding round to be able to shift pipes across mixers.
1225 if(prevYuvCount != ctx->listStats[dpy].yuvCount) {
1226 ctx->mVideoTransFlag = true;
1227 }
Raj Kamal9ed3d6b2014-02-07 16:15:17 +05301228
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001229 if(dpy == HWC_DISPLAY_PRIMARY) {
1230 ctx->mAD->markDoable(ctx, list);
Arun Kumar K.Ra727a882014-08-20 17:14:26 -07001231 //Store the requested fresh rate
1232 ctx->listStats[dpy].refreshRateRequest = refreshRate ?
1233 refreshRate : ctx->dpyAttr[dpy].refreshRate;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001234 }
Naseer Ahmed29a26812012-06-14 00:56:20 -07001235}
1236
Naseer Ahmed018e5452012-12-03 14:46:15 -05001237
Saurabh Shah68107422013-07-09 11:12:42 -07001238static void calc_cut(double& leftCutRatio, double& topCutRatio,
1239 double& rightCutRatio, double& bottomCutRatio, int orient) {
Saurabh Shah27c1d652012-08-14 19:30:28 -07001240 if(orient & HAL_TRANSFORM_FLIP_H) {
Saurabh Shah541b59d2012-10-11 11:08:12 -07001241 swap(leftCutRatio, rightCutRatio);
Saurabh Shah27c1d652012-08-14 19:30:28 -07001242 }
1243 if(orient & HAL_TRANSFORM_FLIP_V) {
Saurabh Shah541b59d2012-10-11 11:08:12 -07001244 swap(topCutRatio, bottomCutRatio);
Saurabh Shah27c1d652012-08-14 19:30:28 -07001245 }
1246 if(orient & HAL_TRANSFORM_ROT_90) {
1247 //Anti clock swapping
Saurabh Shah68107422013-07-09 11:12:42 -07001248 double tmpCutRatio = leftCutRatio;
Saurabh Shah541b59d2012-10-11 11:08:12 -07001249 leftCutRatio = topCutRatio;
1250 topCutRatio = rightCutRatio;
1251 rightCutRatio = bottomCutRatio;
1252 bottomCutRatio = tmpCutRatio;
Saurabh Shah27c1d652012-08-14 19:30:28 -07001253 }
1254}
1255
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001256bool isSecuring(hwc_context_t* ctx, hwc_layer_1_t const* layer) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001257 if((ctx->mMDP.version < qdutils::MDSS_V5) &&
1258 (ctx->mMDP.version > qdutils::MDP_V3_0) &&
1259 ctx->mSecuring) {
1260 return true;
1261 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001262 if (isSecureModePolicy(ctx->mMDP.version)) {
1263 private_handle_t *hnd = (private_handle_t *)layer->handle;
1264 if(ctx->mSecureMode) {
1265 if (! isSecureBuffer(hnd)) {
1266 ALOGD_IF(HWC_UTILS_DEBUG,"%s:Securing Turning ON ...",
1267 __FUNCTION__);
1268 return true;
1269 }
1270 } else {
1271 if (isSecureBuffer(hnd)) {
1272 ALOGD_IF(HWC_UTILS_DEBUG,"%s:Securing Turning OFF ...",
1273 __FUNCTION__);
1274 return true;
1275 }
1276 }
1277 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001278 return false;
1279}
1280
Sushil Chauhan2515abf2013-01-08 16:40:05 -08001281bool isSecureModePolicy(int mdpVersion) {
1282 if (mdpVersion < qdutils::MDSS_V5)
1283 return true;
1284 else
1285 return false;
1286}
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001287
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001288bool isRotatorSupportedFormat(private_handle_t *hnd) {
1289 // Following rotator src formats are supported by mdp driver
1290 // TODO: Add more formats in future, if mdp driver adds support
Ramkumar Radhakrishnan629cbf52014-10-14 19:36:33 -07001291 if(hnd != NULL) {
1292 switch(hnd->format) {
1293 case HAL_PIXEL_FORMAT_RGBA_8888:
Ramkumar Radhakrishnanb8eb16d2014-10-09 13:54:07 -07001294 case HAL_PIXEL_FORMAT_RGBA_5551:
1295 case HAL_PIXEL_FORMAT_RGBA_4444:
Ramkumar Radhakrishnan629cbf52014-10-14 19:36:33 -07001296 case HAL_PIXEL_FORMAT_RGB_565:
1297 case HAL_PIXEL_FORMAT_RGB_888:
1298 case HAL_PIXEL_FORMAT_BGRA_8888:
1299 return true;
1300 default:
1301 return false;
1302 }
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001303 }
1304 return false;
1305}
1306
1307bool isRotationDoable(hwc_context_t *ctx, private_handle_t *hnd) {
Ramkumar Radhakrishnan629cbf52014-10-14 19:36:33 -07001308 // Rotate layers, if it is not secure display buffer and not
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001309 // for the MDP versions below MDP5
Ramkumar Radhakrishnan629cbf52014-10-14 19:36:33 -07001310 if((!isSecureDisplayBuffer(hnd) && isRotatorSupportedFormat(hnd) &&
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001311 !ctx->mMDP.version < qdutils::MDSS_V5)
1312 || isYuvBuffer(hnd)) {
1313 return true;
1314 }
1315 return false;
1316}
1317
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -08001318// returns true if Action safe dimensions are set and target supports Actionsafe
1319bool isActionSafePresent(hwc_context_t *ctx, int dpy) {
1320 // if external supports underscan, do nothing
1321 // it will be taken care in the driver
Ramkumar Radhakrishnana61a0da2014-03-03 14:46:21 -08001322 // Disable Action safe for 8974 due to HW limitation for downscaling
1323 // layers with overlapped region
1324 // Disable Actionsafe for non HDMI displays.
1325 if(!(dpy == HWC_DISPLAY_EXTERNAL) ||
1326 qdutils::MDPVersion::getInstance().is8x74v2() ||
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -07001327 ctx->mHDMIDisplay->isCEUnderscanSupported()) {
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -08001328 return false;
Ramkumar Radhakrishnana61a0da2014-03-03 14:46:21 -08001329 }
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -08001330
1331 char value[PROPERTY_VALUE_MAX];
1332 // Read action safe properties
1333 property_get("persist.sys.actionsafe.width", value, "0");
1334 ctx->dpyAttr[dpy].mAsWidthRatio = atoi(value);
1335 property_get("persist.sys.actionsafe.height", value, "0");
1336 ctx->dpyAttr[dpy].mAsHeightRatio = atoi(value);
1337
1338 if(!ctx->dpyAttr[dpy].mAsWidthRatio && !ctx->dpyAttr[dpy].mAsHeightRatio) {
1339 //No action safe ratio set, return
1340 return false;
1341 }
1342 return true;
1343}
1344
Naseer Ahmed522ce662013-03-18 20:14:05 -04001345int getBlending(int blending) {
1346 switch(blending) {
1347 case HWC_BLENDING_NONE:
1348 return overlay::utils::OVERLAY_BLENDING_OPAQUE;
1349 case HWC_BLENDING_PREMULT:
1350 return overlay::utils::OVERLAY_BLENDING_PREMULT;
1351 case HWC_BLENDING_COVERAGE :
1352 default:
1353 return overlay::utils::OVERLAY_BLENDING_COVERAGE;
1354 }
1355}
1356
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001357//Crops source buffer against destination and FB boundaries
1358void calculate_crop_rects(hwc_rect_t& crop, hwc_rect_t& dst,
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001359 const hwc_rect_t& scissor, int orient) {
1360
Saurabh Shah27c1d652012-08-14 19:30:28 -07001361 int& crop_l = crop.left;
1362 int& crop_t = crop.top;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001363 int& crop_r = crop.right;
1364 int& crop_b = crop.bottom;
1365 int crop_w = crop.right - crop.left;
1366 int crop_h = crop.bottom - crop.top;
1367
Saurabh Shah27c1d652012-08-14 19:30:28 -07001368 int& dst_l = dst.left;
1369 int& dst_t = dst.top;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001370 int& dst_r = dst.right;
1371 int& dst_b = dst.bottom;
Saurabh Shah27c1d652012-08-14 19:30:28 -07001372 int dst_w = abs(dst.right - dst.left);
1373 int dst_h = abs(dst.bottom - dst.top);
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001374
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001375 const int& sci_l = scissor.left;
1376 const int& sci_t = scissor.top;
1377 const int& sci_r = scissor.right;
1378 const int& sci_b = scissor.bottom;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001379
Saurabh Shah68107422013-07-09 11:12:42 -07001380 double leftCutRatio = 0.0, rightCutRatio = 0.0, topCutRatio = 0.0,
1381 bottomCutRatio = 0.0;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001382
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001383 if(dst_l < sci_l) {
Saurabh Shah68107422013-07-09 11:12:42 -07001384 leftCutRatio = (double)(sci_l - dst_l) / (double)dst_w;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001385 dst_l = sci_l;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001386 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001387
1388 if(dst_r > sci_r) {
Saurabh Shah68107422013-07-09 11:12:42 -07001389 rightCutRatio = (double)(dst_r - sci_r) / (double)dst_w;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001390 dst_r = sci_r;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001391 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001392
1393 if(dst_t < sci_t) {
Saurabh Shah68107422013-07-09 11:12:42 -07001394 topCutRatio = (double)(sci_t - dst_t) / (double)dst_h;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001395 dst_t = sci_t;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001396 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001397
1398 if(dst_b > sci_b) {
Saurabh Shah68107422013-07-09 11:12:42 -07001399 bottomCutRatio = (double)(dst_b - sci_b) / (double)dst_h;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001400 dst_b = sci_b;
Naseer Ahmed29a26812012-06-14 00:56:20 -07001401 }
Saurabh Shah27c1d652012-08-14 19:30:28 -07001402
Saurabh Shah541b59d2012-10-11 11:08:12 -07001403 calc_cut(leftCutRatio, topCutRatio, rightCutRatio, bottomCutRatio, orient);
Dileep Kumar Reddi39e79bf2014-03-06 11:56:10 +05301404 crop_l += (int)round((double)crop_w * leftCutRatio);
1405 crop_t += (int)round((double)crop_h * topCutRatio);
1406 crop_r -= (int)round((double)crop_w * rightCutRatio);
1407 crop_b -= (int)round((double)crop_h * bottomCutRatio);
Naseer Ahmed29a26812012-06-14 00:56:20 -07001408}
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001409
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301410bool areLayersIntersecting(const hwc_layer_1_t* layer1,
1411 const hwc_layer_1_t* layer2) {
1412 hwc_rect_t irect = getIntersection(layer1->displayFrame,
1413 layer2->displayFrame);
1414 return isValidRect(irect);
1415}
1416
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001417bool isSameRect(const hwc_rect& rect1, const hwc_rect& rect2)
1418{
1419 return ((rect1.left == rect2.left) && (rect1.top == rect2.top) &&
1420 (rect1.right == rect2.right) && (rect1.bottom == rect2.bottom));
1421}
1422
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001423bool isValidRect(const hwc_rect& rect)
1424{
1425 return ((rect.bottom > rect.top) && (rect.right > rect.left)) ;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301426}
1427
Ramakant Singh21cec722014-03-07 19:11:45 +05301428bool operator ==(const hwc_rect_t& lhs, const hwc_rect_t& rhs) {
1429 if(lhs.left == rhs.left && lhs.top == rhs.top &&
1430 lhs.right == rhs.right && lhs.bottom == rhs.bottom )
1431 return true ;
1432 return false;
1433}
1434
Jeykumar Sankaran71e597c2014-05-07 16:23:14 -07001435hwc_rect_t moveRect(const hwc_rect_t& rect, const int& x_off, const int& y_off)
1436{
1437 hwc_rect_t res;
1438
1439 if(!isValidRect(rect))
1440 return (hwc_rect_t){0, 0, 0, 0};
1441
1442 res.left = rect.left + x_off;
1443 res.top = rect.top + y_off;
1444 res.right = rect.right + x_off;
1445 res.bottom = rect.bottom + y_off;
1446
1447 return res;
1448}
1449
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001450/* computes the intersection of two rects */
1451hwc_rect_t getIntersection(const hwc_rect_t& rect1, const hwc_rect_t& rect2)
1452{
1453 hwc_rect_t res;
1454
1455 if(!isValidRect(rect1) || !isValidRect(rect2)){
1456 return (hwc_rect_t){0, 0, 0, 0};
1457 }
1458
1459
1460 res.left = max(rect1.left, rect2.left);
1461 res.top = max(rect1.top, rect2.top);
1462 res.right = min(rect1.right, rect2.right);
1463 res.bottom = min(rect1.bottom, rect2.bottom);
1464
1465 if(!isValidRect(res))
1466 return (hwc_rect_t){0, 0, 0, 0};
1467
1468 return res;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301469}
1470
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001471/* computes the union of two rects */
1472hwc_rect_t getUnion(const hwc_rect &rect1, const hwc_rect &rect2)
1473{
1474 hwc_rect_t res;
1475
1476 if(!isValidRect(rect1)){
1477 return rect2;
1478 }
1479
1480 if(!isValidRect(rect2)){
1481 return rect1;
1482 }
1483
1484 res.left = min(rect1.left, rect2.left);
1485 res.top = min(rect1.top, rect2.top);
1486 res.right = max(rect1.right, rect2.right);
1487 res.bottom = max(rect1.bottom, rect2.bottom);
1488
1489 return res;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301490}
1491
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001492/* Not a geometrical rect deduction. Deducts rect2 from rect1 only if it results
1493 * a single rect */
1494hwc_rect_t deductRect(const hwc_rect_t& rect1, const hwc_rect_t& rect2) {
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301495
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001496 hwc_rect_t res = rect1;
1497
1498 if((rect1.left == rect2.left) && (rect1.right == rect2.right)) {
1499 if((rect1.top == rect2.top) && (rect2.bottom <= rect1.bottom))
1500 res.top = rect2.bottom;
1501 else if((rect1.bottom == rect2.bottom)&& (rect2.top >= rect1.top))
1502 res.bottom = rect2.top;
1503 }
1504 else if((rect1.top == rect2.top) && (rect1.bottom == rect2.bottom)) {
1505 if((rect1.left == rect2.left) && (rect2.right <= rect1.right))
1506 res.left = rect2.right;
1507 else if((rect1.right == rect2.right)&& (rect2.left >= rect1.left))
1508 res.right = rect2.left;
1509 }
1510 return res;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301511}
1512
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001513void optimizeLayerRects(const hwc_display_contents_1_t *list) {
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301514 int i= (int)list->numHwLayers-2;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301515 while(i > 0) {
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301516 //see if there is no blending required.
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001517 //If it is opaque see if we can substract this region from below
1518 //layers.
radhakrishna4efbdd62014-11-03 13:19:27 +05301519 if(list->hwLayers[i].blending == HWC_BLENDING_NONE &&
1520 list->hwLayers[i].planeAlpha == 0xFF) {
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301521 int j= i-1;
1522 hwc_rect_t& topframe =
1523 (hwc_rect_t&)list->hwLayers[i].displayFrame;
1524 while(j >= 0) {
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301525 if(!needsScaling(&list->hwLayers[j])) {
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001526 hwc_layer_1_t* layer = (hwc_layer_1_t*)&list->hwLayers[j];
1527 hwc_rect_t& bottomframe = layer->displayFrame;
Jeykumar Sankaran071468b2014-01-14 17:21:49 -08001528 hwc_rect_t bottomCrop =
1529 integerizeSourceCrop(layer->sourceCropf);
Sushil Chauhanfda00fc2014-03-20 11:08:41 -07001530 int transform = (layer->flags & HWC_COLOR_FILL) ? 0 :
1531 layer->transform;
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001532
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001533 hwc_rect_t irect = getIntersection(bottomframe, topframe);
1534 if(isValidRect(irect)) {
Jeykumar Sankaran1b3da402013-12-04 16:22:34 -08001535 hwc_rect_t dest_rect;
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001536 //if intersection is valid rect, deduct it
Jeykumar Sankaran1b3da402013-12-04 16:22:34 -08001537 dest_rect = deductRect(bottomframe, irect);
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001538 qhwc::calculate_crop_rects(bottomCrop, bottomframe,
Jeykumar Sankaran1b3da402013-12-04 16:22:34 -08001539 dest_rect, transform);
Jeykumar Sankaran071468b2014-01-14 17:21:49 -08001540 //Update layer sourceCropf
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301541 layer->sourceCropf.left =(float)bottomCrop.left;
1542 layer->sourceCropf.top = (float)bottomCrop.top;
1543 layer->sourceCropf.right = (float)bottomCrop.right;
1544 layer->sourceCropf.bottom = (float)bottomCrop.bottom;
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08001545#ifdef QCOM_BSP
1546 //Update layer dirtyRect
1547 layer->dirtyRect = getIntersection(bottomCrop,
1548 layer->dirtyRect);
1549#endif
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001550 }
1551 }
1552 j--;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301553 }
1554 }
1555 i--;
1556 }
1557}
1558
Naseer Ahmed64b81212013-02-14 10:29:47 -05001559void getNonWormholeRegion(hwc_display_contents_1_t* list,
1560 hwc_rect_t& nwr)
1561{
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301562 size_t last = list->numHwLayers - 1;
Naseer Ahmed64b81212013-02-14 10:29:47 -05001563 hwc_rect_t fbDisplayFrame = list->hwLayers[last].displayFrame;
1564 //Initiliaze nwr to first frame
1565 nwr.left = list->hwLayers[0].displayFrame.left;
1566 nwr.top = list->hwLayers[0].displayFrame.top;
1567 nwr.right = list->hwLayers[0].displayFrame.right;
1568 nwr.bottom = list->hwLayers[0].displayFrame.bottom;
1569
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301570 for (size_t i = 1; i < last; i++) {
Naseer Ahmed64b81212013-02-14 10:29:47 -05001571 hwc_rect_t displayFrame = list->hwLayers[i].displayFrame;
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001572 nwr = getUnion(nwr, displayFrame);
Naseer Ahmed64b81212013-02-14 10:29:47 -05001573 }
1574
1575 //Intersect with the framebuffer
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001576 nwr = getIntersection(nwr, fbDisplayFrame);
Naseer Ahmed64b81212013-02-14 10:29:47 -05001577}
1578
Saurabh Shah747af1e2013-02-26 10:25:12 -08001579void closeAcquireFds(hwc_display_contents_1_t* list) {
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08001580 if(LIKELY(list)) {
1581 for(uint32_t i = 0; i < list->numHwLayers; i++) {
1582 //Close the acquireFenceFds
1583 //HWC_FRAMEBUFFER are -1 already by SF, rest we close.
1584 if(list->hwLayers[i].acquireFenceFd >= 0) {
1585 close(list->hwLayers[i].acquireFenceFd);
1586 list->hwLayers[i].acquireFenceFd = -1;
1587 }
1588 }
1589 //Writeback
1590 if(list->outbufAcquireFenceFd >= 0) {
1591 close(list->outbufAcquireFenceFd);
1592 list->outbufAcquireFenceFd = -1;
Saurabh Shah747af1e2013-02-26 10:25:12 -08001593 }
1594 }
1595}
1596
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001597int hwc_sync(hwc_context_t *ctx, hwc_display_contents_1_t* list, int dpy,
Saurabh Shah23a813c2013-03-20 16:58:12 -07001598 int fd) {
Naseer Ahmed099a6932013-09-09 14:25:20 -04001599 ATRACE_CALL();
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001600 int ret = 0;
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001601 int acquireFd[MAX_NUM_APP_LAYERS];
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001602 int count = 0;
1603 int releaseFd = -1;
Arun Kumar K.R51835182013-11-19 11:20:28 -08001604 int retireFd = -1;
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001605 int fbFd = -1;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001606 bool swapzero = false;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001607
1608 struct mdp_buf_sync data;
1609 memset(&data, 0, sizeof(data));
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001610 data.acq_fen_fd = acquireFd;
1611 data.rel_fen_fd = &releaseFd;
Arun Kumar K.R51835182013-11-19 11:20:28 -08001612 data.retire_fen_fd = &retireFd;
1613 data.flags = MDP_BUF_SYNC_FLAG_RETIRE_FENCE;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001614
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001615 char property[PROPERTY_VALUE_MAX];
1616 if(property_get("debug.egl.swapinterval", property, "1") > 0) {
1617 if(atoi(property) == 0)
1618 swapzero = true;
1619 }
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001620
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001621 bool isExtAnimating = false;
1622 if(dpy)
1623 isExtAnimating = ctx->listStats[dpy].isDisplayAnimating;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001624
Saurabh Shah23a813c2013-03-20 16:58:12 -07001625 //Send acquireFenceFds to rotator
Saurabh Shah23a813c2013-03-20 16:58:12 -07001626 for(uint32_t i = 0; i < ctx->mLayerRotMap[dpy]->getCount(); i++) {
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001627 int rotFd = ctx->mRotMgr->getRotDevFd();
1628 int rotReleaseFd = -1;
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001629 overlay::Rotator* currRot = ctx->mLayerRotMap[dpy]->getRot(i);
1630 hwc_layer_1_t* currLayer = ctx->mLayerRotMap[dpy]->getLayer(i);
1631 if((currRot == NULL) || (currLayer == NULL)) {
1632 continue;
1633 }
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001634 struct mdp_buf_sync rotData;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001635 memset(&rotData, 0, sizeof(rotData));
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001636 rotData.acq_fen_fd =
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001637 &currLayer->acquireFenceFd;
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001638 rotData.rel_fen_fd = &rotReleaseFd; //driver to populate this
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001639 rotData.session_id = currRot->getSessId();
Saurabh Shah25c04d32014-05-05 10:16:02 -07001640 if(currLayer->acquireFenceFd >= 0) {
1641 rotData.acq_fen_fd_cnt = 1; //1 ioctl call per rot session
1642 }
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001643 int ret = 0;
Raj Kamal4b02b742014-10-12 20:51:14 +05301644 if(LIKELY(!swapzero) and (not ctx->mLayerRotMap[dpy]->isRotCached(i)))
Raj Kamalbd3bdc62014-08-05 18:52:49 +05301645 ret = ioctl(rotFd, MSMFB_BUFFER_SYNC, &rotData);
1646
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001647 if(ret < 0) {
1648 ALOGE("%s: ioctl MSMFB_BUFFER_SYNC failed for rot sync, err=%s",
1649 __FUNCTION__, strerror(errno));
Tatenda Chipeperekwaa4550ce2014-06-06 15:25:37 -07001650 close(rotReleaseFd);
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001651 } else {
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001652 close(currLayer->acquireFenceFd);
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001653 //For MDP to wait on.
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001654 currLayer->acquireFenceFd =
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001655 dup(rotReleaseFd);
1656 //A buffer is free to be used by producer as soon as its copied to
1657 //rotator
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001658 currLayer->releaseFenceFd =
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001659 rotReleaseFd;
1660 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001661 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001662
Balamurugan Thanikachalamf558c862014-01-31 18:23:20 +05301663 //Accumulate acquireFenceFds for MDP Overlays
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08001664 if(list->outbufAcquireFenceFd >= 0) {
1665 //Writeback output buffer
Raj Kamal4b02b742014-10-12 20:51:14 +05301666 if(LIKELY(!swapzero) )
1667 acquireFd[count++] = list->outbufAcquireFenceFd;
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08001668 }
1669
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001670 for(uint32_t i = 0; i < list->numHwLayers; i++) {
Ramakant Singh0def28c2014-03-28 20:43:13 +05301671 if(((isAbcInUse(ctx)== true ) ||
1672 (list->hwLayers[i].compositionType == HWC_OVERLAY)) &&
Saurabh Shah23a813c2013-03-20 16:58:12 -07001673 list->hwLayers[i].acquireFenceFd >= 0) {
Raj Kamal4b02b742014-10-12 20:51:14 +05301674 if(LIKELY(!swapzero) ) {
1675 // if ABC is enabled for more than one layer.
1676 // renderBufIndexforABC will work as FB.Hence
1677 // set the acquireFD from fd - which is coming from copybit
1678 if(fd >= 0 && (isAbcInUse(ctx) == true)) {
1679 if(ctx->listStats[dpy].renderBufIndexforABC ==(int32_t)i)
1680 acquireFd[count++] = fd;
1681 else
1682 continue;
1683 } else
1684 acquireFd[count++] = list->hwLayers[i].acquireFenceFd;
1685 }
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001686 }
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001687 if(list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) {
Raj Kamal4b02b742014-10-12 20:51:14 +05301688 if(LIKELY(!swapzero) ) {
1689 if(fd >= 0) {
1690 //set the acquireFD from fd - which is coming from c2d
1691 acquireFd[count++] = fd;
1692 // Buffer sync IOCTL should be async when using c2d fence is
1693 // used
1694 data.flags &= ~MDP_BUF_SYNC_FLAG_WAIT;
1695 } else if(list->hwLayers[i].acquireFenceFd >= 0)
1696 acquireFd[count++] = list->hwLayers[i].acquireFenceFd;
1697 }
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001698 }
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001699 }
1700
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -07001701 if ((fd >= 0) && !dpy && ctx->mPtorInfo.isActive()) {
Sushil Chauhandefd3522014-05-13 18:17:12 -07001702 // Acquire c2d fence of Overlap render buffer
Raj Kamal4b02b742014-10-12 20:51:14 +05301703 if(LIKELY(!swapzero) )
1704 acquireFd[count++] = fd;
Sushil Chauhandefd3522014-05-13 18:17:12 -07001705 }
1706
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001707 data.acq_fen_fd_cnt = count;
1708 fbFd = ctx->dpyAttr[dpy].fd;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001709
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001710 //Waits for acquire fences, returns a release fence
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001711 if(LIKELY(!swapzero)) {
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001712 ret = ioctl(fbFd, MSMFB_BUFFER_SYNC, &data);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001713 }
Saurabh Shah747af1e2013-02-26 10:25:12 -08001714
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001715 if(ret < 0) {
Ramkumar Radhakrishnanb32a0bc2013-04-11 17:57:32 -07001716 ALOGE("%s: ioctl MSMFB_BUFFER_SYNC failed, err=%s",
1717 __FUNCTION__, strerror(errno));
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301718 ALOGE("%s: acq_fen_fd_cnt=%d flags=%d fd=%d dpy=%d numHwLayers=%zu",
Ramkumar Radhakrishnanb32a0bc2013-04-11 17:57:32 -07001719 __FUNCTION__, data.acq_fen_fd_cnt, data.flags, fbFd,
1720 dpy, list->numHwLayers);
Tatenda Chipeperekwaa4550ce2014-06-06 15:25:37 -07001721 close(releaseFd);
1722 releaseFd = -1;
1723 close(retireFd);
1724 retireFd = -1;
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001725 }
Saurabh Shah747af1e2013-02-26 10:25:12 -08001726
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001727 for(uint32_t i = 0; i < list->numHwLayers; i++) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001728 if(list->hwLayers[i].compositionType == HWC_OVERLAY ||
Saurabh Shah74eff4d2014-03-28 16:33:13 -07001729#ifdef QCOM_BSP
Terence Hampsonc67b0372013-10-09 11:32:21 -04001730 list->hwLayers[i].compositionType == HWC_BLIT ||
Saurabh Shah74eff4d2014-03-28 16:33:13 -07001731#endif
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001732 list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) {
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001733 //Populate releaseFenceFds.
Saurabh Shah23a813c2013-03-20 16:58:12 -07001734 if(UNLIKELY(swapzero)) {
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001735 list->hwLayers[i].releaseFenceFd = -1;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001736 } else if(isExtAnimating) {
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001737 // Release all the app layer fds immediately,
1738 // if animation is in progress.
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -07001739 list->hwLayers[i].releaseFenceFd = -1;
Naseer Ahmed330a2822014-03-05 11:57:23 -05001740 } else if(list->hwLayers[i].releaseFenceFd < 0 ) {
Saurabh Shah74eff4d2014-03-28 16:33:13 -07001741#ifdef QCOM_BSP
Zohaib Alam1bb65612013-09-28 03:38:20 -04001742 //If rotator has not already populated this field
Ramakant Singh0def28c2014-03-28 20:43:13 +05301743 // & if it's a not VPU layer
Ramakant Singh467759f2014-04-16 11:09:40 +05301744
1745 // if ABC is enabled for more than one layer
1746 if(fd >= 0 && (isAbcInUse(ctx) == true) &&
1747 ctx->listStats[dpy].renderBufIndexforABC !=(int32_t)i){
1748 list->hwLayers[i].releaseFenceFd = dup(fd);
1749 } else if((list->hwLayers[i].compositionType == HWC_BLIT)&&
1750 (isAbcInUse(ctx) == false)){
1751 //For Blit, the app layers should be released when the Blit
1752 //is complete. This fd was passed from copybit->draw
Balamurugan Thanikachalamf558c862014-01-31 18:23:20 +05301753 list->hwLayers[i].releaseFenceFd = dup(fd);
Saurabh Shah74eff4d2014-03-28 16:33:13 -07001754 } else
1755#endif
1756 {
Balamurugan Thanikachalamf558c862014-01-31 18:23:20 +05301757 list->hwLayers[i].releaseFenceFd = dup(releaseFd);
1758 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001759 }
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001760 }
1761 }
Saurabh Shah747af1e2013-02-26 10:25:12 -08001762
1763 if(fd >= 0) {
1764 close(fd);
1765 fd = -1;
1766 }
1767
Sushil Chauhanfb8845c2014-07-22 12:42:07 -07001768 if (ctx->mCopyBit[dpy]) {
1769 if (!dpy && ctx->mPtorInfo.isActive())
Sushil Chauhandefd3522014-05-13 18:17:12 -07001770 ctx->mCopyBit[dpy]->setReleaseFdSync(releaseFd);
1771 else
1772 ctx->mCopyBit[dpy]->setReleaseFd(releaseFd);
1773 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001774
Saurabh Shah23a813c2013-03-20 16:58:12 -07001775 //Signals when MDP finishes reading rotator buffers.
1776 ctx->mLayerRotMap[dpy]->setReleaseFd(releaseFd);
Arun Kumar K.R51835182013-11-19 11:20:28 -08001777 close(releaseFd);
1778 releaseFd = -1;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001779
Arun Kumar K.R51835182013-11-19 11:20:28 -08001780 if(UNLIKELY(swapzero)) {
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001781 list->retireFenceFd = -1;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001782 } else {
Arun Kumar K.R51835182013-11-19 11:20:28 -08001783 list->retireFenceFd = retireFd;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001784 }
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001785 return ret;
1786}
1787
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001788void setMdpFlags(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shahacf10202013-02-26 10:15:15 -08001789 ovutils::eMdpFlags &mdpFlags,
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001790 int rotDownscale, int transform) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001791 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shah220a30c2013-10-29 16:12:12 -07001792 MetaData_t *metadata = hnd ? (MetaData_t *)hnd->base_metadata : NULL;
Saurabh Shahacf10202013-02-26 10:15:15 -08001793
1794 if(layer->blending == HWC_BLENDING_PREMULT) {
1795 ovutils::setMdpFlags(mdpFlags,
1796 ovutils::OV_MDP_BLEND_FG_PREMULT);
1797 }
1798
Ramkumar Radhakrishnan4ec775f2014-07-23 17:43:18 -07001799 if(metadata && (metadata->operation & PP_PARAM_INTERLACED) &&
1800 metadata->interlaced) {
1801 ovutils::setMdpFlags(mdpFlags,
1802 ovutils::OV_MDP_DEINTERLACE);
1803 }
1804
1805 // Mark MDP flags with SECURE_OVERLAY_SESSION for driver
1806 if(isSecureBuffer(hnd)) {
1807 ovutils::setMdpFlags(mdpFlags,
1808 ovutils::OV_MDP_SECURE_OVERLAY_SESSION);
Justin Philipd6166602014-08-12 13:42:21 +05301809 ovutils::setMdpFlags(mdpFlags,
1810 ovutils::OV_MDP_SMP_FORCE_ALLOC);
1811 }
1812
1813 if(isProtectedBuffer(hnd)) {
1814 ovutils::setMdpFlags(mdpFlags,
1815 ovutils::OV_MDP_SMP_FORCE_ALLOC);
Saurabh Shahacf10202013-02-26 10:15:15 -08001816 }
1817
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -07001818 if(isSecureDisplayBuffer(hnd)) {
Ramkumar Radhakrishnan4ec775f2014-07-23 17:43:18 -07001819 // Mark MDP flags with SECURE_DISPLAY_OVERLAY_SESSION for driver
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -07001820 ovutils::setMdpFlags(mdpFlags,
1821 ovutils::OV_MDP_SECURE_DISPLAY_OVERLAY_SESSION);
1822 }
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001823
1824 //Pre-rotation will be used using rotator.
1825 if(has90Transform(layer) && isRotationDoable(ctx, hnd)) {
1826 ovutils::setMdpFlags(mdpFlags,
1827 ovutils::OV_MDP_SOURCE_ROTATED_90);
1828 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001829 //No 90 component and no rot-downscale then flips done by MDP
1830 //If we use rot then it might as well do flips
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001831 if(!(transform & HWC_TRANSFORM_ROT_90) && !rotDownscale) {
1832 if(transform & HWC_TRANSFORM_FLIP_H) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001833 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_FLIP_H);
1834 }
1835
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001836 if(transform & HWC_TRANSFORM_FLIP_V) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001837 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_FLIP_V);
1838 }
1839 }
Saurabh Shah5daeee52013-01-23 16:52:26 +08001840
1841 if(metadata &&
1842 ((metadata->operation & PP_PARAM_HSIC)
1843 || (metadata->operation & PP_PARAM_IGC)
1844 || (metadata->operation & PP_PARAM_SHARP2))) {
1845 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_PP_EN);
1846 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001847}
1848
Prabhanjan Kandulaa1d83012013-04-23 13:06:02 +05301849int configRotator(Rotator *rot, Whf& whf,
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001850 hwc_rect_t& crop, const eMdpFlags& mdpFlags,
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001851 const eTransform& orient, const int& downscale) {
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001852
Prabhanjan Kandulaa1d83012013-04-23 13:06:02 +05301853 // Fix alignments for TILED format
1854 if(whf.format == MDP_Y_CRCB_H2V2_TILE ||
1855 whf.format == MDP_Y_CBCR_H2V2_TILE) {
1856 whf.w = utils::alignup(whf.w, 64);
1857 whf.h = utils::alignup(whf.h, 32);
1858 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001859 rot->setSource(whf);
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001860
1861 if (qdutils::MDPVersion::getInstance().getMDPVersion() >=
1862 qdutils::MDSS_V5) {
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001863 Dim rotCrop(crop.left, crop.top, crop.right - crop.left,
1864 crop.bottom - crop.top);
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001865 rot->setCrop(rotCrop);
1866 }
1867
Saurabh Shahacf10202013-02-26 10:15:15 -08001868 rot->setFlags(mdpFlags);
1869 rot->setTransform(orient);
1870 rot->setDownscale(downscale);
1871 if(!rot->commit()) return -1;
1872 return 0;
1873}
1874
Saurabh Shahe2474082013-05-15 16:32:13 -07001875int configMdp(Overlay *ov, const PipeArgs& parg,
Saurabh Shahacf10202013-02-26 10:15:15 -08001876 const eTransform& orient, const hwc_rect_t& crop,
Saurabh Shah5daeee52013-01-23 16:52:26 +08001877 const hwc_rect_t& pos, const MetaData_t *metadata,
1878 const eDest& dest) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001879 ov->setSource(parg, dest);
1880 ov->setTransform(orient, dest);
1881
1882 int crop_w = crop.right - crop.left;
1883 int crop_h = crop.bottom - crop.top;
1884 Dim dcrop(crop.left, crop.top, crop_w, crop_h);
1885 ov->setCrop(dcrop, dest);
1886
1887 int posW = pos.right - pos.left;
1888 int posH = pos.bottom - pos.top;
1889 Dim position(pos.left, pos.top, posW, posH);
1890 ov->setPosition(position, dest);
1891
Saurabh Shah5daeee52013-01-23 16:52:26 +08001892 if (metadata)
1893 ov->setVisualParams(*metadata, dest);
1894
Saurabh Shahacf10202013-02-26 10:15:15 -08001895 if (!ov->commit(dest)) {
1896 return -1;
1897 }
1898 return 0;
1899}
1900
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001901int configColorLayer(hwc_context_t *ctx, hwc_layer_1_t *layer,
1902 const int& dpy, eMdpFlags& mdpFlags, eZorder& z,
Saurabh Shah2c8ad052014-08-15 13:27:46 -07001903 const eDest& dest) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001904
1905 hwc_rect_t dst = layer->displayFrame;
1906 trimLayer(ctx, dpy, 0, dst, dst);
1907
1908 int w = ctx->dpyAttr[dpy].xres;
1909 int h = ctx->dpyAttr[dpy].yres;
1910 int dst_w = dst.right - dst.left;
1911 int dst_h = dst.bottom - dst.top;
1912 uint32_t color = layer->transform;
Sushil Chauhan65e26302015-01-14 10:48:57 -08001913 Whf whf(w, h, getMdpFormat(HAL_PIXEL_FORMAT_RGBA_8888));
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001914
Sushil Chauhanf10c5232013-12-19 10:35:54 -08001915 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_SOLID_FILL);
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001916 if (layer->blending == HWC_BLENDING_PREMULT)
1917 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_BLEND_FG_PREMULT);
1918
Saurabh Shah2c8ad052014-08-15 13:27:46 -07001919 PipeArgs parg(mdpFlags, whf, z, static_cast<eRotFlags>(0),
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001920 layer->planeAlpha,
1921 (ovutils::eBlending) getBlending(layer->blending));
1922
1923 // Configure MDP pipe for Color layer
1924 Dim pos(dst.left, dst.top, dst_w, dst_h);
1925 ctx->mOverlay->setSource(parg, dest);
1926 ctx->mOverlay->setColor(color, dest);
1927 ctx->mOverlay->setTransform(0, dest);
1928 ctx->mOverlay->setCrop(pos, dest);
1929 ctx->mOverlay->setPosition(pos, dest);
1930
1931 if (!ctx->mOverlay->commit(dest)) {
1932 ALOGE("%s: Configure color layer failed!", __FUNCTION__);
1933 return -1;
1934 }
1935 return 0;
1936}
1937
Saurabh Shahe2474082013-05-15 16:32:13 -07001938void updateSource(eTransform& orient, Whf& whf,
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001939 hwc_rect_t& crop, Rotator *rot) {
1940 Dim transformedCrop(crop.left, crop.top,
Saurabh Shahacf10202013-02-26 10:15:15 -08001941 crop.right - crop.left,
1942 crop.bottom - crop.top);
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001943 if (qdutils::MDPVersion::getInstance().getMDPVersion() >=
1944 qdutils::MDSS_V5) {
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001945 //B-family rotator internally could modify destination dimensions if
1946 //downscaling is supported
1947 whf = rot->getDstWhf();
1948 transformedCrop = rot->getDstDimensions();
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001949 } else {
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001950 //A-family rotator rotates entire buffer irrespective of crop, forcing
1951 //us to recompute the crop based on transform
1952 orient = static_cast<eTransform>(ovutils::getMdpOrient(orient));
1953 preRotateSource(orient, whf, transformedCrop);
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001954 }
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001955
1956 crop.left = transformedCrop.x;
1957 crop.top = transformedCrop.y;
1958 crop.right = transformedCrop.x + transformedCrop.w;
1959 crop.bottom = transformedCrop.y + transformedCrop.h;
Saurabh Shahacf10202013-02-26 10:15:15 -08001960}
1961
Arun Kumar K.R00b84792015-03-27 11:28:36 -07001962bool configHwCursor(const int fd, int dpy, hwc_layer_1_t* layer) {
1963 if(dpy > HWC_DISPLAY_PRIMARY) {
1964 // HWCursor not supported on secondary displays
1965 return false;
1966 }
1967 private_handle_t *hnd = (private_handle_t *)layer->handle;
1968 hwc_rect dst = layer->displayFrame;
1969 hwc_rect src = integerizeSourceCrop(layer->sourceCropf);
1970 int srcW = src.right - src.left;
1971 int srcH = src.bottom - src.top;
1972 int dstW = dst.right - dst.left;
1973 int dstH = dst.bottom - dst.top;
1974
1975 Whf whf(getWidth(hnd), getHeight(hnd), hnd->format);
1976 Dim crop(src.left, src.top, srcW, srcH);
1977 Dim dest(dst.left, dst.top, dstW, dstH);
1978
1979 ovutils::PipeArgs pargs(ovutils::OV_MDP_FLAGS_NONE,
1980 whf,
1981 Z_SYSTEM_ALLOC,
1982 ovutils::ROT_FLAGS_NONE,
1983 layer->planeAlpha,
1984 (ovutils::eBlending)
1985 getBlending(layer->blending));
1986
1987 ALOGD_IF(HWC_UTILS_DEBUG, "%s: CursorInfo: w = %d h = %d "
1988 "crop [%d, %d, %d, %d] dst [%d, %d, %d, %d]", __FUNCTION__,
1989 getWidth(hnd), getHeight(hnd), src.left, src.top, srcW, srcH,
1990 dst.left, dst.top, dstW, dstH);
1991
1992 return HWCursor::getInstance()->config(fd, (void*)hnd->base, pargs,
1993 crop, dest);
1994}
1995
1996void freeHwCursor(const int fd, int dpy) {
1997 if (dpy == HWC_DISPLAY_PRIMARY) {
1998 HWCursor::getInstance()->free(fd);
1999 }
2000}
2001
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002002int getRotDownscale(hwc_context_t *ctx, const hwc_layer_1_t *layer) {
2003 if(not qdutils::MDPVersion::getInstance().isRotDownscaleEnabled()) {
2004 return 0;
2005 }
2006
2007 int downscale = 0;
2008 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
2009 hwc_rect_t dst = layer->displayFrame;
2010 private_handle_t *hnd = (private_handle_t *)layer->handle;
2011
2012 if(not hnd) {
2013 return 0;
2014 }
2015
2016 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
2017 bool isInterlaced = metadata && (metadata->operation & PP_PARAM_INTERLACED)
2018 && metadata->interlaced;
2019 int transform = layer->transform;
Sushil Chauhan65e26302015-01-14 10:48:57 -08002020 uint32_t format = ovutils::getMdpFormat(hnd->format, hnd->flags);
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002021
2022 if(isYuvBuffer(hnd)) {
2023 if(ctx->mMDP.version >= qdutils::MDP_V4_2 &&
2024 ctx->mMDP.version < qdutils::MDSS_V5) {
2025 downscale = Rotator::getDownscaleFactor(crop.right - crop.left,
2026 crop.bottom - crop.top, dst.right - dst.left,
2027 dst.bottom - dst.top, format, isInterlaced);
2028 } else {
2029 Dim adjCrop(crop.left, crop.top, crop.right - crop.left,
2030 crop.bottom - crop.top);
2031 Dim pos(dst.left, dst.top, dst.right - dst.left,
2032 dst.bottom - dst.top);
2033 if(transform & HAL_TRANSFORM_ROT_90) {
2034 swap(adjCrop.w, adjCrop.h);
2035 }
2036 downscale = Rotator::getDownscaleFactor(adjCrop.w, adjCrop.h, pos.w,
2037 pos.h, format, isInterlaced);
2038 }
2039 }
2040 return downscale;
2041}
2042
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002043bool isZoomModeEnabled(hwc_rect_t crop) {
2044 // This does not work for zooming in top left corner of the image
2045 return(crop.top > 0 || crop.left > 0);
2046}
2047
2048void updateCropAIVVideoMode(hwc_context_t *ctx, hwc_rect_t& crop, int dpy) {
2049 ALOGD_IF(HWC_UTILS_DEBUG, "dpy %d Source crop [%d %d %d %d]", dpy,
2050 crop.left, crop.top, crop.right, crop.bottom);
2051 if(isZoomModeEnabled(crop)) {
2052 Dim srcCrop(crop.left, crop.top,
2053 crop.right - crop.left,
2054 crop.bottom - crop.top);
2055 int extW = ctx->dpyAttr[dpy].xres;
2056 int extH = ctx->dpyAttr[dpy].yres;
2057 //Crop the original video in order to fit external display aspect ratio
2058 if(srcCrop.w * extH < extW * srcCrop.h) {
2059 int offset = (srcCrop.h - ((srcCrop.w * extH) / extW)) / 2;
2060 crop.top += offset;
2061 crop.bottom -= offset;
2062 } else {
2063 int offset = (srcCrop.w - ((extW * srcCrop.h) / extH)) / 2;
2064 crop.left += offset;
2065 crop.right -= offset;
2066 }
2067 ALOGD_IF(HWC_UTILS_DEBUG, "External Resolution [%d %d] dpy %d Modified"
2068 " source crop [%d %d %d %d]", extW, extH, dpy,
2069 crop.left, crop.top, crop.right, crop.bottom);
2070 }
2071}
2072
2073void updateDestAIVVideoMode(hwc_context_t *ctx, hwc_rect_t crop,
2074 hwc_rect_t& dst, int dpy) {
2075 ALOGD_IF(HWC_UTILS_DEBUG, "dpy %d Destination position [%d %d %d %d]", dpy,
2076 dst.left, dst.top, dst.right, dst.bottom);
2077 Dim srcCrop(crop.left, crop.top,
2078 crop.right - crop.left,
2079 crop.bottom - crop.top);
2080 int extW = ctx->dpyAttr[dpy].xres;
2081 int extH = ctx->dpyAttr[dpy].yres;
2082 // Set the destination coordinates of external display to full screen,
Ramkumar Radhakrishnan812999a2014-09-11 21:42:07 -07002083 // when zoom in mode is enabled or the ratio between video aspect ratio
2084 // and external display aspect ratio is below the minimum tolerance level
2085 // and above maximum tolerance level
2086 float videoAspectRatio = ((float)srcCrop.w / (float)srcCrop.h);
2087 float extDisplayAspectRatio = ((float)extW / (float)extH);
2088 float videoToExternalRatio = videoAspectRatio / extDisplayAspectRatio;
2089 if((fabs(1.0f - videoToExternalRatio) <= ctx->mAspectRatioToleranceLevel) ||
2090 (isZoomModeEnabled(crop))) {
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002091 dst.left = 0;
2092 dst.top = 0;
2093 dst.right = extW;
2094 dst.bottom = extH;
2095 }
2096 ALOGD_IF(HWC_UTILS_DEBUG, "External Resolution [%d %d] dpy %d Modified"
2097 " Destination position [%d %d %d %d] Source crop [%d %d %d %d]",
2098 extW, extH, dpy, dst.left, dst.top, dst.right, dst.bottom,
2099 crop.left, crop.top, crop.right, crop.bottom);
2100}
2101
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07002102void updateCoordinates(hwc_context_t *ctx, hwc_rect_t& crop,
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002103 hwc_rect_t& dst, int dpy) {
2104 updateCropAIVVideoMode(ctx, crop, dpy);
2105 updateDestAIVVideoMode(ctx, crop, dst, dpy);
2106}
2107
Saurabh Shah88e4d272013-09-03 13:31:29 -07002108int configureNonSplit(hwc_context_t *ctx, hwc_layer_1_t *layer,
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07002109 const int& dpy, eMdpFlags& mdpFlags, eZorder& z,
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002110 const eDest& dest, Rotator **rot) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002111
2112 private_handle_t *hnd = (private_handle_t *)layer->handle;
Sushil Chauhan897a9c32013-07-18 11:09:55 -07002113
Saurabh Shahacf10202013-02-26 10:15:15 -08002114 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07002115 if (layer->flags & HWC_COLOR_FILL) {
2116 // Configure Color layer
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002117 return configColorLayer(ctx, layer, dpy, mdpFlags, z, dest);
Sushil Chauhan897a9c32013-07-18 11:09:55 -07002118 }
Saurabh Shahacf10202013-02-26 10:15:15 -08002119 ALOGE("%s: layer handle is NULL", __FUNCTION__);
2120 return -1;
2121 }
2122
Saurabh Shah5daeee52013-01-23 16:52:26 +08002123 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
2124
Saurabh Shah62e1d732013-09-17 10:44:05 -07002125 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shahacf10202013-02-26 10:15:15 -08002126 hwc_rect_t dst = layer->displayFrame;
2127 int transform = layer->transform;
2128 eTransform orient = static_cast<eTransform>(transform);
Saurabh Shahacf10202013-02-26 10:15:15 -08002129 int rotFlags = ovutils::ROT_FLAGS_NONE;
Sushil Chauhan65e26302015-01-14 10:48:57 -08002130 uint32_t format = ovutils::getMdpFormat(hnd->format, hnd->flags);
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05302131 Whf whf(getWidth(hnd), getHeight(hnd), format, (uint32_t)hnd->size);
Zohaib Alam1bb65612013-09-28 03:38:20 -04002132
Sushil Chauhan1f6d68f2013-10-11 11:49:35 -07002133 // Handle R/B swap
2134 if (layer->flags & HWC_FORMAT_RB_SWAP) {
2135 if (hnd->format == HAL_PIXEL_FORMAT_RGBA_8888)
2136 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRA_8888);
2137 else if (hnd->format == HAL_PIXEL_FORMAT_RGBX_8888)
2138 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRX_8888);
2139 }
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002140 // update source crop and destination position of AIV video layer.
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07002141 if(ctx->listStats[dpy].mAIVVideoMode && isYuvBuffer(hnd)) {
2142 updateCoordinates(ctx, crop, dst, dpy);
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002143 }
Ramkumar Radhakrishnan939a9e72013-12-04 18:30:18 -08002144 calcExtDisplayPosition(ctx, hnd, dpy, crop, dst, transform, orient);
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002145 int downscale = getRotDownscale(ctx, layer);
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08002146 setMdpFlags(ctx, layer, mdpFlags, downscale, transform);
Saurabh Shahacf10202013-02-26 10:15:15 -08002147
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08002148 //if 90 component or downscale, use rot
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002149 if((has90Transform(layer) or downscale) and isRotationDoable(ctx, hnd)) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002150 *rot = ctx->mRotMgr->getNext();
2151 if(*rot == NULL) return -1;
Saurabh Shah39240c92014-03-31 10:31:42 -07002152 ctx->mLayerRotMap[dpy]->add(layer, *rot);
Saurabh Shahcd018352014-11-11 13:54:19 -08002153 BwcPM::setBwc(ctx, dpy, hnd, crop, dst, transform, downscale,
2154 mdpFlags);
Saurabh Shahacf10202013-02-26 10:15:15 -08002155 //Configure rotator for pre-rotation
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07002156 if(configRotator(*rot, whf, crop, mdpFlags, orient, downscale) < 0) {
2157 ALOGE("%s: configRotator failed!", __FUNCTION__);
Saurabh Shahacf10202013-02-26 10:15:15 -08002158 return -1;
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07002159 }
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07002160 updateSource(orient, whf, crop, *rot);
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002161 rotFlags |= ROT_PREROTATED;
Saurabh Shahacf10202013-02-26 10:15:15 -08002162 }
2163
Saurabh Shah76fd6552013-03-14 14:45:38 -07002164 //For the mdp, since either we are pre-rotating or MDP does flips
2165 orient = OVERLAY_TRANSFORM_0;
2166 transform = 0;
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002167 PipeArgs parg(mdpFlags, whf, z,
Naseer Ahmed522ce662013-03-18 20:14:05 -04002168 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2169 (ovutils::eBlending) getBlending(layer->blending));
2170
Saurabh Shah5daeee52013-01-23 16:52:26 +08002171 if(configMdp(ctx->mOverlay, parg, orient, crop, dst, metadata, dest) < 0) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002172 ALOGE("%s: commit failed for low res panel", __FUNCTION__);
2173 return -1;
2174 }
2175 return 0;
2176}
2177
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002178//Helper to 1) Ensure crops dont have gaps 2) Ensure L and W are even
Sushil Chauhan15a2ea62013-09-04 18:28:36 -07002179void sanitizeSourceCrop(hwc_rect_t& cropL, hwc_rect_t& cropR,
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002180 private_handle_t *hnd) {
2181 if(cropL.right - cropL.left) {
2182 if(isYuvBuffer(hnd)) {
2183 //Always safe to even down left
2184 ovutils::even_floor(cropL.left);
2185 //If right is even, automatically width is even, since left is
2186 //already even
2187 ovutils::even_floor(cropL.right);
2188 }
2189 //Make sure there are no gaps between left and right splits if the layer
2190 //is spread across BOTH halves
2191 if(cropR.right - cropR.left) {
2192 cropR.left = cropL.right;
2193 }
2194 }
2195
2196 if(cropR.right - cropR.left) {
2197 if(isYuvBuffer(hnd)) {
2198 //Always safe to even down left
2199 ovutils::even_floor(cropR.left);
2200 //If right is even, automatically width is even, since left is
2201 //already even
2202 ovutils::even_floor(cropR.right);
2203 }
2204 }
2205}
2206
Saurabh Shah88e4d272013-09-03 13:31:29 -07002207int configureSplit(hwc_context_t *ctx, hwc_layer_1_t *layer,
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07002208 const int& dpy, eMdpFlags& mdpFlagsL, eZorder& z,
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002209 const eDest& lDest, const eDest& rDest,
Saurabh Shahacf10202013-02-26 10:15:15 -08002210 Rotator **rot) {
2211 private_handle_t *hnd = (private_handle_t *)layer->handle;
2212 if(!hnd) {
2213 ALOGE("%s: layer handle is NULL", __FUNCTION__);
2214 return -1;
2215 }
2216
Saurabh Shah5daeee52013-01-23 16:52:26 +08002217 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
2218
Saurabh Shahacf10202013-02-26 10:15:15 -08002219 int hw_w = ctx->dpyAttr[dpy].xres;
2220 int hw_h = ctx->dpyAttr[dpy].yres;
Saurabh Shah62e1d732013-09-17 10:44:05 -07002221 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shahacf10202013-02-26 10:15:15 -08002222 hwc_rect_t dst = layer->displayFrame;
2223 int transform = layer->transform;
2224 eTransform orient = static_cast<eTransform>(transform);
Saurabh Shahacf10202013-02-26 10:15:15 -08002225 int rotFlags = ROT_FLAGS_NONE;
Sushil Chauhan65e26302015-01-14 10:48:57 -08002226 uint32_t format = ovutils::getMdpFormat(hnd->format, hnd->flags);
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05302227 Whf whf(getWidth(hnd), getHeight(hnd), format, (uint32_t)hnd->size);
Zohaib Alam1bb65612013-09-28 03:38:20 -04002228
Sushil Chauhan1f6d68f2013-10-11 11:49:35 -07002229 // Handle R/B swap
2230 if (layer->flags & HWC_FORMAT_RB_SWAP) {
2231 if (hnd->format == HAL_PIXEL_FORMAT_RGBA_8888)
2232 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRA_8888);
2233 else if (hnd->format == HAL_PIXEL_FORMAT_RGBX_8888)
2234 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRX_8888);
2235 }
2236
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002237 // update source crop and destination position of AIV video layer.
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07002238 if(ctx->listStats[dpy].mAIVVideoMode && isYuvBuffer(hnd)) {
2239 updateCoordinates(ctx, crop, dst, dpy);
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002240 }
2241
2242 /* Calculate the external display position based on MDP downscale,
Ramkumar Radhakrishnana61a0da2014-03-03 14:46:21 -08002243 ActionSafe, and extorientation features. */
2244 calcExtDisplayPosition(ctx, hnd, dpy, crop, dst, transform, orient);
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002245 int downscale = getRotDownscale(ctx, layer);
2246 setMdpFlags(ctx, layer, mdpFlagsL, downscale, transform);
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002247
2248 if(lDest != OV_INVALID && rDest != OV_INVALID) {
2249 //Enable overfetch
2250 setMdpFlags(mdpFlagsL, OV_MDSS_MDP_DUAL_PIPE);
2251 }
2252
Saurabh Shaha9da08f2013-07-03 13:27:53 -07002253 //Will do something only if feature enabled and conditions suitable
2254 //hollow call otherwise
2255 if(ctx->mAD->prepare(ctx, crop, whf, hnd)) {
2256 overlay::Writeback *wb = overlay::Writeback::getInstance();
2257 whf.format = wb->getOutputFormat();
2258 }
2259
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002260 if((has90Transform(layer) or downscale) and isRotationDoable(ctx, hnd)) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002261 (*rot) = ctx->mRotMgr->getNext();
2262 if((*rot) == NULL) return -1;
Saurabh Shah39240c92014-03-31 10:31:42 -07002263 ctx->mLayerRotMap[dpy]->add(layer, *rot);
Saurabh Shahacf10202013-02-26 10:15:15 -08002264 //Configure rotator for pre-rotation
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07002265 if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale) < 0) {
2266 ALOGE("%s: configRotator failed!", __FUNCTION__);
Saurabh Shahacf10202013-02-26 10:15:15 -08002267 return -1;
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07002268 }
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07002269 updateSource(orient, whf, crop, *rot);
Saurabh Shahacf10202013-02-26 10:15:15 -08002270 rotFlags |= ROT_PREROTATED;
2271 }
2272
2273 eMdpFlags mdpFlagsR = mdpFlagsL;
2274 setMdpFlags(mdpFlagsR, OV_MDSS_MDP_RIGHT_MIXER);
2275
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002276 hwc_rect_t tmp_cropL = {0}, tmp_dstL = {0};
2277 hwc_rect_t tmp_cropR = {0}, tmp_dstR = {0};
Saurabh Shahacf10202013-02-26 10:15:15 -08002278
Saurabh Shah07a8ca82013-08-06 18:45:42 -07002279 const int lSplit = getLeftSplit(ctx, dpy);
2280
Jeykumar Sankaran8b40b432014-05-30 23:26:59 -07002281 // Calculate Left rects
2282 if(dst.left < lSplit) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002283 tmp_cropL = crop;
2284 tmp_dstL = dst;
Saurabh Shah67a38c32013-06-10 16:23:15 -07002285 hwc_rect_t scissor = {0, 0, lSplit, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -08002286 scissor = getIntersection(ctx->mViewFrame[dpy], scissor);
Saurabh Shahacf10202013-02-26 10:15:15 -08002287 qhwc::calculate_crop_rects(tmp_cropL, tmp_dstL, scissor, 0);
2288 }
Jeykumar Sankaran8b40b432014-05-30 23:26:59 -07002289
2290 // Calculate Right rects
2291 if(dst.right > lSplit) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002292 tmp_cropR = crop;
2293 tmp_dstR = dst;
Saurabh Shah67a38c32013-06-10 16:23:15 -07002294 hwc_rect_t scissor = {lSplit, 0, hw_w, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -08002295 scissor = getIntersection(ctx->mViewFrame[dpy], scissor);
Saurabh Shahacf10202013-02-26 10:15:15 -08002296 qhwc::calculate_crop_rects(tmp_cropR, tmp_dstR, scissor, 0);
2297 }
2298
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002299 sanitizeSourceCrop(tmp_cropL, tmp_cropR, hnd);
2300
Saurabh Shah94d62362013-07-02 10:58:48 -07002301 //When buffer is H-flipped, contents of mixer config also needs to swapped
Saurabh Shahacf10202013-02-26 10:15:15 -08002302 //Not needed if the layer is confined to one half of the screen.
2303 //If rotator has been used then it has also done the flips, so ignore them.
Jeykumar Sankaran8b40b432014-05-30 23:26:59 -07002304 if((orient & OVERLAY_TRANSFORM_FLIP_H) && (dst.left < lSplit) &&
2305 (dst.right > lSplit) && (*rot) == NULL) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002306 hwc_rect_t new_cropR;
2307 new_cropR.left = tmp_cropL.left;
2308 new_cropR.right = new_cropR.left + (tmp_cropR.right - tmp_cropR.left);
2309
2310 hwc_rect_t new_cropL;
2311 new_cropL.left = new_cropR.right;
2312 new_cropL.right = tmp_cropR.right;
2313
2314 tmp_cropL.left = new_cropL.left;
2315 tmp_cropL.right = new_cropL.right;
2316
2317 tmp_cropR.left = new_cropR.left;
2318 tmp_cropR.right = new_cropR.right;
2319
2320 }
2321
Saurabh Shah76fd6552013-03-14 14:45:38 -07002322 //For the mdp, since either we are pre-rotating or MDP does flips
2323 orient = OVERLAY_TRANSFORM_0;
2324 transform = 0;
2325
Saurabh Shahacf10202013-02-26 10:15:15 -08002326 //configure left mixer
2327 if(lDest != OV_INVALID) {
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002328 PipeArgs pargL(mdpFlagsL, whf, z,
Naseer Ahmed522ce662013-03-18 20:14:05 -04002329 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2330 (ovutils::eBlending) getBlending(layer->blending));
2331
Saurabh Shahacf10202013-02-26 10:15:15 -08002332 if(configMdp(ctx->mOverlay, pargL, orient,
Saurabh Shah5daeee52013-01-23 16:52:26 +08002333 tmp_cropL, tmp_dstL, metadata, lDest) < 0) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002334 ALOGE("%s: commit failed for left mixer config", __FUNCTION__);
2335 return -1;
2336 }
2337 }
2338
2339 //configure right mixer
2340 if(rDest != OV_INVALID) {
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002341 PipeArgs pargR(mdpFlagsR, whf, z,
Naseer Ahmed522ce662013-03-18 20:14:05 -04002342 static_cast<eRotFlags>(rotFlags),
2343 layer->planeAlpha,
2344 (ovutils::eBlending) getBlending(layer->blending));
Saurabh Shah67a38c32013-06-10 16:23:15 -07002345 tmp_dstR.right = tmp_dstR.right - lSplit;
2346 tmp_dstR.left = tmp_dstR.left - lSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08002347 if(configMdp(ctx->mOverlay, pargR, orient,
Saurabh Shah5daeee52013-01-23 16:52:26 +08002348 tmp_cropR, tmp_dstR, metadata, rDest) < 0) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002349 ALOGE("%s: commit failed for right mixer config", __FUNCTION__);
2350 return -1;
2351 }
2352 }
2353
2354 return 0;
2355}
Arun Kumar K.Ra2978452013-02-07 01:34:24 -08002356
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -05002357int configure3DVideo(hwc_context_t *ctx, hwc_layer_1_t *layer,
2358 const int& dpy, eMdpFlags& mdpFlagsL, eZorder& z,
2359 const eDest& lDest, const eDest& rDest,
2360 Rotator **rot) {
2361 private_handle_t *hnd = (private_handle_t *)layer->handle;
2362 if(!hnd) {
2363 ALOGE("%s: layer handle is NULL", __FUNCTION__);
2364 return -1;
2365 }
2366 //Both pipes are configured to the same mixer
2367 eZorder lz = z;
2368 eZorder rz = (eZorder)(z + 1);
2369
2370 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
2371
2372 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
2373 hwc_rect_t dst = layer->displayFrame;
2374 int transform = layer->transform;
2375 eTransform orient = static_cast<eTransform>(transform);
2376 int rotFlags = ROT_FLAGS_NONE;
2377 uint32_t format = ovutils::getMdpFormat(hnd->format, hnd->flags);
2378 Whf whf(getWidth(hnd), getHeight(hnd), format, (uint32_t)hnd->size);
2379
2380 int downscale = getRotDownscale(ctx, layer);
2381 setMdpFlags(ctx, layer, mdpFlagsL, downscale, transform);
2382
2383 //XXX: Check if rotation is supported and valid for 3D
2384 if((has90Transform(layer) or downscale) and isRotationDoable(ctx, hnd)) {
2385 (*rot) = ctx->mRotMgr->getNext();
2386 if((*rot) == NULL) return -1;
2387 ctx->mLayerRotMap[dpy]->add(layer, *rot);
2388 //Configure rotator for pre-rotation
2389 if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale) < 0) {
2390 ALOGE("%s: configRotator failed!", __FUNCTION__);
2391 return -1;
2392 }
2393 updateSource(orient, whf, crop, *rot);
2394 rotFlags |= ROT_PREROTATED;
2395 }
2396
2397 eMdpFlags mdpFlagsR = mdpFlagsL;
2398
2399 hwc_rect_t cropL = crop, dstL = dst;
2400 hwc_rect_t cropR = crop, dstR = dst;
2401 int hw_w = ctx->dpyAttr[dpy].xres;
2402 int hw_h = ctx->dpyAttr[dpy].yres;
2403
2404 if(get3DFormat(hnd) == HAL_3D_SIDE_BY_SIDE_L_R ||
2405 get3DFormat(hnd) == HAL_3D_SIDE_BY_SIDE_R_L) {
2406 // Calculate Left rects
2407 // XXX: This assumes crop.right/2 is the center point of the video
2408 cropL.right = crop.right/2;
2409 dstL.left = dst.left/2;
2410 dstL.right = dst.right/2;
2411
2412 // Calculate Right rects
2413 cropR.left = crop.right/2;
2414 dstR.left = hw_w/2 + dst.left/2;
2415 dstR.right = hw_w/2 + dst.right/2;
2416 } else if(get3DFormat(hnd) == HAL_3D_TOP_BOTTOM) {
2417 // Calculate Left rects
2418 cropL.bottom = crop.bottom/2;
2419 dstL.top = dst.top/2;
2420 dstL.bottom = dst.bottom/2;
2421
2422 // Calculate Right rects
2423 cropR.top = crop.bottom/2;
2424 dstR.top = hw_h/2 + dst.top/2;
2425 dstR.bottom = hw_h/2 + dst.bottom/2;
2426 } else {
2427 ALOGE("%s: Unsupported 3D mode ", __FUNCTION__);
2428 return -1;
2429 }
2430
2431 //For the mdp, since either we are pre-rotating or MDP does flips
2432 orient = OVERLAY_TRANSFORM_0;
2433 transform = 0;
2434
2435 //configure left pipe
2436 if(lDest != OV_INVALID) {
2437 PipeArgs pargL(mdpFlagsL, whf, lz,
2438 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2439 (ovutils::eBlending) getBlending(layer->blending));
2440
2441 if(configMdp(ctx->mOverlay, pargL, orient,
2442 cropL, dstL, metadata, lDest) < 0) {
2443 ALOGE("%s: commit failed for left mixer config", __FUNCTION__);
2444 return -1;
2445 }
2446 }
2447
2448 //configure right pipe
2449 if(rDest != OV_INVALID) {
2450 PipeArgs pargR(mdpFlagsR, whf, rz,
2451 static_cast<eRotFlags>(rotFlags),
2452 layer->planeAlpha,
2453 (ovutils::eBlending) getBlending(layer->blending));
2454 if(configMdp(ctx->mOverlay, pargR, orient,
2455 cropR, dstR, metadata, rDest) < 0) {
2456 ALOGE("%s: commit failed for right mixer config", __FUNCTION__);
2457 return -1;
2458 }
2459 }
2460
2461 return 0;
2462}
2463
radhakrishnac9a67412013-09-25 17:40:42 +05302464int configureSourceSplit(hwc_context_t *ctx, hwc_layer_1_t *layer,
2465 const int& dpy, eMdpFlags& mdpFlagsL, eZorder& z,
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002466 const eDest& lDest, const eDest& rDest,
radhakrishnac9a67412013-09-25 17:40:42 +05302467 Rotator **rot) {
2468 private_handle_t *hnd = (private_handle_t *)layer->handle;
2469 if(!hnd) {
2470 ALOGE("%s: layer handle is NULL", __FUNCTION__);
2471 return -1;
2472 }
2473
2474 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
2475
radhakrishnac9a67412013-09-25 17:40:42 +05302476 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);;
2477 hwc_rect_t dst = layer->displayFrame;
2478 int transform = layer->transform;
2479 eTransform orient = static_cast<eTransform>(transform);
2480 const int downscale = 0;
2481 int rotFlags = ROT_FLAGS_NONE;
2482 //Splitting only YUV layer on primary panel needs different zorders
2483 //for both layers as both the layers are configured to single mixer
2484 eZorder lz = z;
2485 eZorder rz = (eZorder)(z + 1);
2486
2487 Whf whf(getWidth(hnd), getHeight(hnd),
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05302488 getMdpFormat(hnd->format), (uint32_t)hnd->size);
radhakrishnac9a67412013-09-25 17:40:42 +05302489
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002490 // update source crop and destination position of AIV video layer.
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07002491 if(ctx->listStats[dpy].mAIVVideoMode && isYuvBuffer(hnd)) {
2492 updateCoordinates(ctx, crop, dst, dpy);
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002493 }
2494
Ramkumar Radhakrishnan8ab3f5d2014-02-20 19:37:15 -08002495 /* Calculate the external display position based on MDP downscale,
2496 ActionSafe, and extorientation features. */
2497 calcExtDisplayPosition(ctx, hnd, dpy, crop, dst, transform, orient);
2498
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08002499 setMdpFlags(ctx, layer, mdpFlagsL, 0, transform);
radhakrishnac9a67412013-09-25 17:40:42 +05302500 trimLayer(ctx, dpy, transform, crop, dst);
2501
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08002502 if(has90Transform(layer) && isRotationDoable(ctx, hnd)) {
radhakrishnac9a67412013-09-25 17:40:42 +05302503 (*rot) = ctx->mRotMgr->getNext();
2504 if((*rot) == NULL) return -1;
Saurabh Shah39240c92014-03-31 10:31:42 -07002505 ctx->mLayerRotMap[dpy]->add(layer, *rot);
radhakrishnac9a67412013-09-25 17:40:42 +05302506 //Configure rotator for pre-rotation
2507 if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale) < 0) {
2508 ALOGE("%s: configRotator failed!", __FUNCTION__);
radhakrishnac9a67412013-09-25 17:40:42 +05302509 return -1;
2510 }
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07002511 updateSource(orient, whf, crop, *rot);
radhakrishnac9a67412013-09-25 17:40:42 +05302512 rotFlags |= ROT_PREROTATED;
2513 }
2514
2515 eMdpFlags mdpFlagsR = mdpFlagsL;
2516 int lSplit = dst.left + (dst.right - dst.left)/2;
2517
2518 hwc_rect_t tmp_cropL = {0}, tmp_dstL = {0};
2519 hwc_rect_t tmp_cropR = {0}, tmp_dstR = {0};
2520
2521 if(lDest != OV_INVALID) {
2522 tmp_cropL = crop;
2523 tmp_dstL = dst;
2524 hwc_rect_t scissor = {dst.left, dst.top, lSplit, dst.bottom };
2525 qhwc::calculate_crop_rects(tmp_cropL, tmp_dstL, scissor, 0);
2526 }
2527 if(rDest != OV_INVALID) {
2528 tmp_cropR = crop;
2529 tmp_dstR = dst;
2530 hwc_rect_t scissor = {lSplit, dst.top, dst.right, dst.bottom };
2531 qhwc::calculate_crop_rects(tmp_cropR, tmp_dstR, scissor, 0);
2532 }
2533
2534 sanitizeSourceCrop(tmp_cropL, tmp_cropR, hnd);
2535
2536 //When buffer is H-flipped, contents of mixer config also needs to swapped
2537 //Not needed if the layer is confined to one half of the screen.
2538 //If rotator has been used then it has also done the flips, so ignore them.
2539 if((orient & OVERLAY_TRANSFORM_FLIP_H) && lDest != OV_INVALID
2540 && rDest != OV_INVALID && (*rot) == NULL) {
2541 hwc_rect_t new_cropR;
2542 new_cropR.left = tmp_cropL.left;
2543 new_cropR.right = new_cropR.left + (tmp_cropR.right - tmp_cropR.left);
2544
2545 hwc_rect_t new_cropL;
2546 new_cropL.left = new_cropR.right;
2547 new_cropL.right = tmp_cropR.right;
2548
2549 tmp_cropL.left = new_cropL.left;
2550 tmp_cropL.right = new_cropL.right;
2551
2552 tmp_cropR.left = new_cropR.left;
2553 tmp_cropR.right = new_cropR.right;
2554
2555 }
2556
2557 //For the mdp, since either we are pre-rotating or MDP does flips
2558 orient = OVERLAY_TRANSFORM_0;
2559 transform = 0;
2560
2561 //configure left half
2562 if(lDest != OV_INVALID) {
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002563 PipeArgs pargL(mdpFlagsL, whf, lz,
radhakrishnac9a67412013-09-25 17:40:42 +05302564 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2565 (ovutils::eBlending) getBlending(layer->blending));
2566
2567 if(configMdp(ctx->mOverlay, pargL, orient,
2568 tmp_cropL, tmp_dstL, metadata, lDest) < 0) {
2569 ALOGE("%s: commit failed for left half config", __FUNCTION__);
2570 return -1;
2571 }
2572 }
2573
2574 //configure right half
2575 if(rDest != OV_INVALID) {
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002576 PipeArgs pargR(mdpFlagsR, whf, rz,
radhakrishnac9a67412013-09-25 17:40:42 +05302577 static_cast<eRotFlags>(rotFlags),
2578 layer->planeAlpha,
2579 (ovutils::eBlending) getBlending(layer->blending));
2580 if(configMdp(ctx->mOverlay, pargR, orient,
2581 tmp_cropR, tmp_dstR, metadata, rDest) < 0) {
2582 ALOGE("%s: commit failed for right half config", __FUNCTION__);
2583 return -1;
2584 }
2585 }
2586
2587 return 0;
2588}
2589
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -07002590bool canUseRotator(hwc_context_t *ctx, int dpy) {
Raj Kamal068f4572014-04-14 16:14:06 +05302591 if(ctx->mOverlay->isDMAMultiplexingSupported() &&
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08002592 isSecondaryConnected(ctx) &&
Amara Venkata Mastan Manoj Kumar5cbac942013-08-13 19:00:14 -07002593 !ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isPause) {
Raj Kamal068f4572014-04-14 16:14:06 +05302594 /* mdss driver on certain targets support multiplexing of DMA pipe
Raj Kamala8c065f2013-10-22 14:52:45 +05302595 * in LINE and BLOCK modes for writeback panels.
2596 */
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -07002597 if(dpy == HWC_DISPLAY_PRIMARY)
2598 return false;
Saurabh Shahe2474082013-05-15 16:32:13 -07002599 }
Ramakant Singhb4106a12014-10-07 18:06:56 +05302600 if((ctx->mMDP.version == qdutils::MDP_V3_0_4)
2601 ||(ctx->mMDP.version == qdutils::MDP_V3_0_5))
Terence Hampson45c02ef2013-05-17 17:00:11 -04002602 return false;
Saurabh Shahe2474082013-05-15 16:32:13 -07002603 return true;
2604}
2605
Saurabh Shah07a8ca82013-08-06 18:45:42 -07002606int getLeftSplit(hwc_context_t *ctx, const int& dpy) {
2607 //Default even split for all displays with high res
2608 int lSplit = ctx->dpyAttr[dpy].xres / 2;
2609 if(dpy == HWC_DISPLAY_PRIMARY &&
2610 qdutils::MDPVersion::getInstance().getLeftSplit()) {
2611 //Override if split published by driver for primary
2612 lSplit = qdutils::MDPVersion::getInstance().getLeftSplit();
2613 }
2614 return lSplit;
2615}
Saurabh Shah1a03d482013-05-29 13:44:20 -07002616
Saurabh Shah88e4d272013-09-03 13:31:29 -07002617bool isDisplaySplit(hwc_context_t* ctx, int dpy) {
Prabhanjan Kandula5bae9f52014-05-15 16:48:18 +05302618 qdutils::MDPVersion& mdpHw = qdutils::MDPVersion::getInstance();
Jeykumar Sankarandc76ba82015-01-28 14:51:50 -08002619 if(ctx->dpyAttr[dpy].xres > mdpHw.getMaxMixerWidth()) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07002620 return true;
2621 }
Prabhanjan Kandula5bae9f52014-05-15 16:48:18 +05302622 if(dpy == HWC_DISPLAY_PRIMARY && mdpHw.getRightSplit()) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07002623 return true;
2624 }
2625 return false;
2626}
2627
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08002628//clear prev layer prop flags and realloc for current frame
2629void reset_layer_prop(hwc_context_t* ctx, int dpy, int numAppLayers) {
2630 if(ctx->layerProp[dpy]) {
2631 delete[] ctx->layerProp[dpy];
2632 ctx->layerProp[dpy] = NULL;
2633 }
2634 ctx->layerProp[dpy] = new LayerProp[numAppLayers];
2635}
2636
Ramakant Singh0def28c2014-03-28 20:43:13 +05302637bool isAbcInUse(hwc_context_t *ctx){
2638 return (ctx->enableABC && ctx->listStats[0].renderBufIndexforABC == 0);
2639}
2640
Tatenda Chipeperekwa523eac52014-05-29 14:58:39 -07002641void dumpBuffer(private_handle_t *ohnd, char *bufferName) {
2642 if (ohnd != NULL && ohnd->base) {
2643 char dumpFilename[PATH_MAX];
2644 bool bResult = false;
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -07002645 int width = getWidth(ohnd);
2646 int height = getHeight(ohnd);
2647 int format = ohnd->format;
2648 //dummy aligned w & h.
2649 int alW = 0, alH = 0;
2650 int size = getBufferSizeAndDimensions(width, height, format, alW, alH);
Tatenda Chipeperekwa523eac52014-05-29 14:58:39 -07002651 snprintf(dumpFilename, sizeof(dumpFilename), "/data/%s.%s.%dx%d.raw",
2652 bufferName,
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -07002653 overlay::utils::getFormatString(utils::getMdpFormat(format)),
2654 width, height);
Tatenda Chipeperekwa523eac52014-05-29 14:58:39 -07002655 FILE* fp = fopen(dumpFilename, "w+");
2656 if (NULL != fp) {
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -07002657 bResult = (bool) fwrite((void*)ohnd->base, size, 1, fp);
Tatenda Chipeperekwa523eac52014-05-29 14:58:39 -07002658 fclose(fp);
2659 }
2660 ALOGD("Buffer[%s] Dump to %s: %s",
2661 bufferName, dumpFilename, bResult ? "Success" : "Fail");
2662 }
2663}
2664
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002665bool isGLESComp(hwc_context_t *ctx,
2666 hwc_display_contents_1_t* list) {
2667 int numAppLayers = ctx->listStats[HWC_DISPLAY_PRIMARY].numAppLayers;
2668 for(int index = 0; index < numAppLayers; index++) {
2669 hwc_layer_1_t* layer = &(list->hwLayers[index]);
2670 if(layer->compositionType == HWC_FRAMEBUFFER)
2671 return true;
2672 }
2673 return false;
2674}
2675
2676void setGPUHint(hwc_context_t* ctx, hwc_display_contents_1_t* list) {
2677 struct gpu_hint_info *gpuHint = &ctx->mGPUHintInfo;
Saurabh Shah74eff4d2014-03-28 16:33:13 -07002678 if(!gpuHint->mGpuPerfModeEnable || !ctx || !list)
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002679 return;
Saurabh Shah74eff4d2014-03-28 16:33:13 -07002680
2681#ifdef QCOM_BSP
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002682 /* Set the GPU hint flag to high for MIXED/GPU composition only for
2683 first frame after MDP -> GPU/MIXED mode transition. Set the GPU
2684 hint to default if the previous composition is GPU or current GPU
2685 composition is due to idle fallback */
2686 if(!gpuHint->mEGLDisplay || !gpuHint->mEGLContext) {
2687 gpuHint->mEGLDisplay = eglGetCurrentDisplay();
2688 if(!gpuHint->mEGLDisplay) {
2689 ALOGW("%s Warning: EGL current display is NULL", __FUNCTION__);
2690 return;
2691 }
2692 gpuHint->mEGLContext = eglGetCurrentContext();
2693 if(!gpuHint->mEGLContext) {
2694 ALOGW("%s Warning: EGL current context is NULL", __FUNCTION__);
2695 return;
2696 }
2697 }
2698 if(isGLESComp(ctx, list)) {
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -07002699 if(gpuHint->mCompositionState != COMPOSITION_STATE_GPU
2700 && !MDPComp::isIdleFallback()) {
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002701 EGLint attr_list[] = {EGL_GPU_HINT_1,
2702 EGL_GPU_LEVEL_3,
2703 EGL_NONE };
2704 if((gpuHint->mCurrGPUPerfMode != EGL_GPU_LEVEL_3) &&
2705 !eglGpuPerfHintQCOM(gpuHint->mEGLDisplay,
2706 gpuHint->mEGLContext, attr_list)) {
2707 ALOGW("eglGpuPerfHintQCOM failed for Built in display");
2708 } else {
2709 gpuHint->mCurrGPUPerfMode = EGL_GPU_LEVEL_3;
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -07002710 gpuHint->mCompositionState = COMPOSITION_STATE_GPU;
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002711 }
2712 } else {
2713 EGLint attr_list[] = {EGL_GPU_HINT_1,
2714 EGL_GPU_LEVEL_0,
2715 EGL_NONE };
2716 if((gpuHint->mCurrGPUPerfMode != EGL_GPU_LEVEL_0) &&
2717 !eglGpuPerfHintQCOM(gpuHint->mEGLDisplay,
2718 gpuHint->mEGLContext, attr_list)) {
2719 ALOGW("eglGpuPerfHintQCOM failed for Built in display");
2720 } else {
2721 gpuHint->mCurrGPUPerfMode = EGL_GPU_LEVEL_0;
2722 }
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -07002723 if(MDPComp::isIdleFallback()) {
2724 gpuHint->mCompositionState = COMPOSITION_STATE_IDLE_FALLBACK;
2725 }
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002726 }
2727 } else {
2728 /* set the GPU hint flag to default for MDP composition */
2729 EGLint attr_list[] = {EGL_GPU_HINT_1,
2730 EGL_GPU_LEVEL_0,
2731 EGL_NONE };
2732 if((gpuHint->mCurrGPUPerfMode != EGL_GPU_LEVEL_0) &&
2733 !eglGpuPerfHintQCOM(gpuHint->mEGLDisplay,
2734 gpuHint->mEGLContext, attr_list)) {
2735 ALOGW("eglGpuPerfHintQCOM failed for Built in display");
2736 } else {
2737 gpuHint->mCurrGPUPerfMode = EGL_GPU_LEVEL_0;
2738 }
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -07002739 gpuHint->mCompositionState = COMPOSITION_STATE_MDP;
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002740 }
Saurabh Shah74eff4d2014-03-28 16:33:13 -07002741#endif
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002742}
2743
Sushil Chauhandefd3522014-05-13 18:17:12 -07002744bool isPeripheral(const hwc_rect_t& rect1, const hwc_rect_t& rect2) {
2745 // To be peripheral, 3 boundaries should match.
2746 uint8_t eqBounds = 0;
2747 if (rect1.left == rect2.left)
2748 eqBounds++;
2749 if (rect1.top == rect2.top)
2750 eqBounds++;
2751 if (rect1.right == rect2.right)
2752 eqBounds++;
2753 if (rect1.bottom == rect2.bottom)
2754 eqBounds++;
2755 return (eqBounds == 3);
2756}
2757
Krishna Chaitanya Parimidb992fd2014-10-22 20:50:50 +05302758void processBootAnimCompleted(hwc_context_t *ctx) {
2759 char value[PROPERTY_VALUE_MAX];
Nitesh Gupta538e0f72015-03-25 13:22:35 +05302760 int ret = -1;
Krishna Chaitanya Parimidb992fd2014-10-22 20:50:50 +05302761
Nitesh Gupta538e0f72015-03-25 13:22:35 +05302762 // Applying default mode after bootanimation is finished
2763 property_get("init.svc.bootanim", value, "running");
Krishna Chaitanya Parimidb992fd2014-10-22 20:50:50 +05302764
Nitesh Gupta538e0f72015-03-25 13:22:35 +05302765 if (!strncmp(value,"stopped",strlen("stopped"))) {
Nitesh Gupta538e0f72015-03-25 13:22:35 +05302766 ctx->mBootAnimCompleted = true;
Zohaib Alam83ea46d2015-03-23 15:44:19 -04002767
2768 //one-shot action check if bootanimation completed then apply
2769 //default display mode.
2770 qdcmApplyDefaultAfterBootAnimationDone(ctx);
Nitesh Gupta538e0f72015-03-25 13:22:35 +05302771 }
Krishna Chaitanya Parimidb992fd2014-10-22 20:50:50 +05302772}
2773
Saurabh Shahcd018352014-11-11 13:54:19 -08002774void BwcPM::setBwc(const hwc_context_t *ctx, const int& dpy,
2775 const private_handle_t *hnd,
2776 const hwc_rect_t& crop, const hwc_rect_t& dst,
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002777 const int& transform,const int& downscale,
2778 ovutils::eMdpFlags& mdpFlags) {
Saurabh Shah1a03d482013-05-29 13:44:20 -07002779 //Target doesnt support Bwc
Prabhanjan Kandula5bae9f52014-05-15 16:48:18 +05302780 qdutils::MDPVersion& mdpHw = qdutils::MDPVersion::getInstance();
Saurabh Shahcd018352014-11-11 13:54:19 -08002781 if(not mdpHw.supportsBWC()) {
Saurabh Shah1a03d482013-05-29 13:44:20 -07002782 return;
2783 }
Saurabh Shahcd018352014-11-11 13:54:19 -08002784 //Disabled at runtime
2785 if(not ctx->mBWCEnabled) return;
2786 //BWC not supported with rot-downscale
2787 if(downscale) return;
2788 //Not enabled for secondary displays
2789 if(dpy) return;
2790 //Not enabled for non-video buffers
2791 if(not isYuvBuffer(hnd)) return;
2792
Saurabh Shahb6810df2014-06-17 16:00:22 -07002793 int src_w = crop.right - crop.left;
2794 int src_h = crop.bottom - crop.top;
2795 int dst_w = dst.right - dst.left;
2796 int dst_h = dst.bottom - dst.top;
2797 if(transform & HAL_TRANSFORM_ROT_90) {
2798 swap(src_w, src_h);
2799 }
Saurabh Shah1a03d482013-05-29 13:44:20 -07002800 //src width > MAX mixer supported dim
Jeykumar Sankaran39305802014-12-12 17:55:57 -08002801 if(src_w > (int) qdutils::MDPVersion::getInstance().getMaxPipeWidth()) {
Saurabh Shah1a03d482013-05-29 13:44:20 -07002802 return;
2803 }
Saurabh Shah1a03d482013-05-29 13:44:20 -07002804 //Decimation necessary, cannot use BWC. H/W requirement.
2805 if(qdutils::MDPVersion::getInstance().supportsDecimation()) {
Saurabh Shahb6810df2014-06-17 16:00:22 -07002806 uint8_t horzDeci = 0;
2807 uint8_t vertDeci = 0;
2808 ovutils::getDecimationFactor(src_w, src_h, dst_w, dst_h, horzDeci,
2809 vertDeci);
Saurabh Shahc5b96dc2013-06-05 13:19:52 -07002810 if(horzDeci || vertDeci) return;
Saurabh Shah1a03d482013-05-29 13:44:20 -07002811 }
Saurabh Shah1a03d482013-05-29 13:44:20 -07002812
2813 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDSS_MDP_BWC_EN);
2814}
2815
Saurabh Shah23a813c2013-03-20 16:58:12 -07002816void LayerRotMap::add(hwc_layer_1_t* layer, Rotator *rot) {
Raj Kamal389d6e32014-08-04 14:43:24 +05302817 if(mCount >= RotMgr::MAX_ROT_SESS) return;
Saurabh Shah23a813c2013-03-20 16:58:12 -07002818 mLayer[mCount] = layer;
2819 mRot[mCount] = rot;
2820 mCount++;
2821}
2822
2823void LayerRotMap::reset() {
Raj Kamal389d6e32014-08-04 14:43:24 +05302824 for (int i = 0; i < RotMgr::MAX_ROT_SESS; i++) {
Saurabh Shah23a813c2013-03-20 16:58:12 -07002825 mLayer[i] = 0;
2826 mRot[i] = 0;
2827 }
2828 mCount = 0;
2829}
2830
Saurabh Shahda5b3ce2013-11-26 10:48:06 -08002831void LayerRotMap::clear() {
Saurabh Shah7a606842013-12-11 14:36:04 -08002832 RotMgr::getInstance()->markUnusedTop(mCount);
Saurabh Shahda5b3ce2013-11-26 10:48:06 -08002833 reset();
2834}
2835
Raj Kamalbd3bdc62014-08-05 18:52:49 +05302836bool LayerRotMap::isRotCached(uint32_t index) const {
2837 overlay::Rotator* rot = getRot(index);
2838 hwc_layer_1_t* layer = getLayer(index);
2839
2840 if(rot and layer and layer->handle) {
2841 private_handle_t *hnd = (private_handle_t *)(layer->handle);
2842 return (rot->isRotCached(hnd->fd,(uint32_t)(hnd->offset)));
2843 }
2844 return false;
2845}
2846
Saurabh Shah23a813c2013-03-20 16:58:12 -07002847void LayerRotMap::setReleaseFd(const int& fence) {
2848 for(uint32_t i = 0; i < mCount; i++) {
Raj Kamalbd3bdc62014-08-05 18:52:49 +05302849 if(mRot[i] and mLayer[i] and mLayer[i]->handle) {
2850 /* Ensure that none of the above (Rotator-instance,
2851 * layer and layer-handle) are NULL*/
2852 if(isRotCached(i))
2853 mRot[i]->setPrevBufReleaseFd(dup(fence));
2854 else
2855 mRot[i]->setCurrBufReleaseFd(dup(fence));
2856 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07002857 }
2858}
2859
Jeykumar Sankaranaedd1432015-01-15 11:25:03 -08002860hwc_rect expandROIFromMidPoint(hwc_rect roi, hwc_rect fullFrame) {
2861 int lRoiWidth = 0, rRoiWidth = 0;
2862 int half_frame_width = fullFrame.right/2;
2863
2864 hwc_rect lFrame = fullFrame;
2865 hwc_rect rFrame = fullFrame;
2866 lFrame.right = (lFrame.right - lFrame.left)/2;
2867 rFrame.left = lFrame.right;
2868
2869 hwc_rect lRoi = getIntersection(roi, lFrame);
2870 hwc_rect rRoi = getIntersection(roi, rFrame);
2871
2872 lRoiWidth = lRoi.right - lRoi.left;
2873 rRoiWidth = rRoi.right - rRoi.left;
2874
2875 if(lRoiWidth && rRoiWidth) {
2876 if(lRoiWidth < rRoiWidth)
2877 roi.left = half_frame_width - rRoiWidth;
2878 else
2879 roi.right = half_frame_width + lRoiWidth;
2880 }
2881 return roi;
2882}
2883
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002884void resetROI(hwc_context_t *ctx, const int dpy) {
2885 const int fbXRes = (int)ctx->dpyAttr[dpy].xres;
2886 const int fbYRes = (int)ctx->dpyAttr[dpy].yres;
Jeykumar Sankaranf7124b92015-02-26 10:34:35 -08002887
2888 /* When source split is enabled, both the panels are calibrated
2889 * in a single coordinate system. So only one ROI is generated
2890 * for the whole panel extending equally from the midpoint and
2891 * populated for the left side. */
2892 if(!qdutils::MDPVersion::getInstance().isSrcSplit() &&
2893 isDisplaySplit(ctx, dpy)) {
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002894 const int lSplit = getLeftSplit(ctx, dpy);
2895 ctx->listStats[dpy].lRoi = (struct hwc_rect){0, 0, lSplit, fbYRes};
2896 ctx->listStats[dpy].rRoi = (struct hwc_rect){lSplit, 0, fbXRes, fbYRes};
2897 } else {
2898 ctx->listStats[dpy].lRoi = (struct hwc_rect){0, 0,fbXRes, fbYRes};
2899 ctx->listStats[dpy].rRoi = (struct hwc_rect){0, 0, 0, 0};
2900 }
2901}
2902
2903hwc_rect_t getSanitizeROI(struct hwc_rect roi, hwc_rect boundary)
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002904{
2905 if(!isValidRect(roi))
2906 return roi;
2907
2908 struct hwc_rect t_roi = roi;
2909
2910 const int LEFT_ALIGN = qdutils::MDPVersion::getInstance().getLeftAlign();
2911 const int WIDTH_ALIGN = qdutils::MDPVersion::getInstance().getWidthAlign();
2912 const int TOP_ALIGN = qdutils::MDPVersion::getInstance().getTopAlign();
2913 const int HEIGHT_ALIGN = qdutils::MDPVersion::getInstance().getHeightAlign();
2914 const int MIN_WIDTH = qdutils::MDPVersion::getInstance().getMinROIWidth();
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002915 const int MIN_HEIGHT = qdutils::MDPVersion::getInstance().getMinROIHeight();
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002916
2917 /* Align to minimum width recommended by the panel */
2918 if((t_roi.right - t_roi.left) < MIN_WIDTH) {
2919 if((t_roi.left + MIN_WIDTH) > boundary.right)
2920 t_roi.left = t_roi.right - MIN_WIDTH;
2921 else
2922 t_roi.right = t_roi.left + MIN_WIDTH;
2923 }
2924
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002925 /* Align to minimum height recommended by the panel */
2926 if((t_roi.bottom - t_roi.top) < MIN_HEIGHT) {
2927 if((t_roi.top + MIN_HEIGHT) > boundary.bottom)
2928 t_roi.top = t_roi.bottom - MIN_HEIGHT;
2929 else
2930 t_roi.bottom = t_roi.top + MIN_HEIGHT;
2931 }
2932
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002933 /* Align left and width to meet panel restrictions */
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002934 if(LEFT_ALIGN)
2935 t_roi.left = t_roi.left - (t_roi.left % LEFT_ALIGN);
2936
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002937 if(WIDTH_ALIGN) {
2938 int width = t_roi.right - t_roi.left;
2939 width = WIDTH_ALIGN * ((width + (WIDTH_ALIGN - 1)) / WIDTH_ALIGN);
2940 t_roi.right = t_roi.left + width;
2941
2942 if(t_roi.right > boundary.right) {
2943 t_roi.right = boundary.right;
2944 t_roi.left = t_roi.right - width;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002945
2946 if(LEFT_ALIGN)
2947 t_roi.left = t_roi.left - (t_roi.left % LEFT_ALIGN);
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002948 }
2949 }
2950
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002951
2952 /* Align top and height to meet panel restrictions */
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002953 if(TOP_ALIGN)
2954 t_roi.top = t_roi.top - (t_roi.top % TOP_ALIGN);
2955
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002956 if(HEIGHT_ALIGN) {
2957 int height = t_roi.bottom - t_roi.top;
2958 height = HEIGHT_ALIGN * ((height + (HEIGHT_ALIGN - 1)) / HEIGHT_ALIGN);
2959 t_roi.bottom = t_roi.top + height;
2960
2961 if(t_roi.bottom > boundary.bottom) {
2962 t_roi.bottom = boundary.bottom;
2963 t_roi.top = t_roi.bottom - height;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002964
2965 if(TOP_ALIGN)
2966 t_roi.top = t_roi.top - (t_roi.top % TOP_ALIGN);
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002967 }
2968 }
2969
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002970
2971 return t_roi;
2972}
2973
Manoj Kumar AVM9591a5e2014-08-21 22:50:21 -07002974void handle_pause(hwc_context_t* ctx, int dpy) {
Arun Kumar K.R33888f52014-10-09 15:56:33 -07002975 if(ctx->dpyAttr[dpy].connected) {
2976 ctx->mDrawLock.lock();
2977 ctx->dpyAttr[dpy].isActive = true;
2978 ctx->dpyAttr[dpy].isPause = true;
2979 ctx->mDrawLock.unlock();
2980 ctx->proc->invalidate(ctx->proc);
2981
2982 usleep(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period
2983 * 2 / 1000);
2984
2985 // At this point all the pipes used by External have been
2986 // marked as UNSET.
2987 ctx->mDrawLock.lock();
2988 // Perform commit to unstage the pipes.
2989 if (!Overlay::displayCommit(ctx->dpyAttr[dpy].fd)) {
2990 ALOGE("%s: display commit fail! for %d dpy",
2991 __FUNCTION__, dpy);
2992 }
2993 ctx->mDrawLock.unlock();
2994 ctx->proc->invalidate(ctx->proc);
Manoj Kumar AVM9591a5e2014-08-21 22:50:21 -07002995 }
2996 return;
2997}
2998
2999void handle_resume(hwc_context_t* ctx, int dpy) {
Arun Kumar K.R33888f52014-10-09 15:56:33 -07003000 if(ctx->dpyAttr[dpy].connected) {
3001 ctx->mDrawLock.lock();
3002 ctx->dpyAttr[dpy].isConfiguring = true;
3003 ctx->dpyAttr[dpy].isActive = true;
3004 ctx->mDrawLock.unlock();
3005 ctx->proc->invalidate(ctx->proc);
3006
3007 usleep(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period
3008 * 2 / 1000);
3009
3010 //At this point external has all the pipes it would need.
3011 ctx->mDrawLock.lock();
3012 ctx->dpyAttr[dpy].isPause = false;
3013 ctx->mDrawLock.unlock();
3014 ctx->proc->invalidate(ctx->proc);
Manoj Kumar AVM9591a5e2014-08-21 22:50:21 -07003015 }
3016 return;
3017}
3018
Tatenda Chipeperekwad80b6172014-09-23 11:29:37 -07003019void clearPipeResources(hwc_context_t* ctx, int dpy) {
3020 if(ctx->mOverlay) {
3021 ctx->mOverlay->configBegin();
3022 ctx->mOverlay->configDone();
3023 }
3024 if(ctx->mRotMgr) {
3025 ctx->mRotMgr->clear();
3026 }
3027 // Call a display commit to ensure that pipes and associated
3028 // fd's are cleaned up.
3029 if(!Overlay::displayCommit(ctx->dpyAttr[dpy].fd)) {
3030 ALOGE("%s: display commit failed for %d", __FUNCTION__, dpy);
3031 }
3032}
3033
3034// Handles online events when HDMI is the primary display. In particular,
3035// online events for hdmi connected before AND after boot up and HWC init.
3036void handle_online(hwc_context_t* ctx, int dpy) {
3037 // Close the current fd if it was opened earlier on when HWC
3038 // was initialized.
3039 if (ctx->dpyAttr[dpy].fd >= 0) {
3040 close(ctx->dpyAttr[dpy].fd);
3041 ctx->dpyAttr[dpy].fd = -1;
3042 }
3043 // TODO: If HDMI is connected after the display has booted up,
3044 // and the best configuration is different from the default
3045 // then we need to deal with this appropriately.
Arun Kumar K.R205df772015-02-20 18:45:58 -08003046 int error = ctx->mHDMIDisplay->configure();
3047 if (error < 0) {
3048 ALOGE("Error opening FrameBuffer");
3049 return;
3050 }
Tatenda Chipeperekwad80b6172014-09-23 11:29:37 -07003051 updateDisplayInfo(ctx, dpy);
3052 initCompositionResources(ctx, dpy);
3053 ctx->dpyAttr[dpy].connected = true;
3054}
3055
3056// Handles offline events for HDMI. This can be used for offline events
3057// initiated by the HDMI driver and the CEC framework.
3058void handle_offline(hwc_context_t* ctx, int dpy) {
3059 destroyCompositionResources(ctx, dpy);
3060 // Clear all pipe resources and call a display commit to ensure
3061 // that all the fd's are closed. This will ensure that the HDMI
3062 // core turns off and that we receive an event the next time the
3063 // cable is connected.
3064 if (ctx->mHDMIDisplay->isHDMIPrimaryDisplay()) {
3065 clearPipeResources(ctx, dpy);
3066 }
3067 ctx->mHDMIDisplay->teardown();
3068 resetDisplayInfo(ctx, dpy);
3069 ctx->dpyAttr[dpy].connected = false;
3070 ctx->dpyAttr[dpy].isActive = false;
3071}
3072
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -05003073int convertS3DFormatToMode(int s3DFormat) {
3074 int ret;
3075 switch(s3DFormat) {
3076 case HAL_3D_SIDE_BY_SIDE_L_R:
3077 case HAL_3D_SIDE_BY_SIDE_R_L:
3078 ret = HDMI_S3D_SIDE_BY_SIDE;
3079 break;
3080 case HAL_3D_TOP_BOTTOM:
3081 ret = HDMI_S3D_TOP_AND_BOTTOM;
3082 break;
3083 default:
3084 ret = HDMI_S3D_NONE;
3085 }
3086 return ret;
3087}
3088
3089bool needs3DComposition(hwc_context_t* ctx, int dpy) {
3090 return (displaySupports3D(ctx, dpy) && ctx->dpyAttr[dpy].connected &&
3091 ctx->dpyAttr[dpy].s3dMode != HDMI_S3D_NONE);
3092}
3093
3094void setup3DMode(hwc_context_t *ctx, int dpy, int s3dMode) {
3095 if (ctx->dpyAttr[dpy].s3dMode != s3dMode) {
3096 ALOGD("%s: setup 3D mode: %d", __FUNCTION__, s3dMode);
3097 if(ctx->mHDMIDisplay->configure3D(s3dMode)) {
3098 ctx->dpyAttr[dpy].s3dMode = s3dMode;
3099 }
3100 }
3101}
3102
3103bool displaySupports3D(hwc_context_t* ctx, int dpy) {
3104 return ((dpy == HWC_DISPLAY_EXTERNAL) ||
3105 ((dpy == HWC_DISPLAY_PRIMARY) &&
3106 ctx->mHDMIDisplay->isHDMIPrimaryDisplay()));
3107}
3108
3109
Saurabh Shahacf10202013-02-26 10:15:15 -08003110};//namespace qhwc