blob: 7df7bba8a922d395fc0dcbe1f13b5329da30ac33 [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
Raj Kamalf8829b92015-04-08 13:52:58 +0530557uint32_t getRefreshRate(hwc_context_t* ctx, uint32_t requestedRefreshRate) {
558
559 qdutils::MDPVersion& mdpHw = qdutils::MDPVersion::getInstance();
560 int dpy = HWC_DISPLAY_PRIMARY;
561 uint32_t defaultRefreshRate = ctx->dpyAttr[dpy].refreshRate;
562 uint32_t rate = defaultRefreshRate;
563
564 if(!requestedRefreshRate)
565 return defaultRefreshRate;
566
567 uint32_t maxNumIterations =
568 (uint32_t)ceil(
569 (float)mdpHw.getMaxFpsSupported()/
570 (float)requestedRefreshRate);
571
572 for(uint32_t i = 1; i <= maxNumIterations; i++) {
573 rate = roundOff(i * requestedRefreshRate);
574 if(rate < mdpHw.getMinFpsSupported()) {
575 continue;
576 } else if((rate >= mdpHw.getMinFpsSupported() &&
577 rate <= mdpHw.getMaxFpsSupported())) {
578 break;
579 } else {
580 rate = defaultRefreshRate;
581 break;
582 }
583 }
584 return rate;
585}
586
587//Helper to roundoff the refreshrates to the std refresh-rates
Raj Kamal0d53fc62014-11-25 17:36:36 +0530588uint32_t roundOff(uint32_t refreshRate) {
Arun Kumar K.Ra727a882014-08-20 17:14:26 -0700589 int count = (int) (sizeof(stdRefreshRates)/sizeof(stdRefreshRates[0]));
590 uint32_t rate = refreshRate;
591 for(int i=0; i< count; i++) {
592 if(abs(stdRefreshRates[i] - refreshRate) < 2) {
593 // Most likely used for video, the fps can fluctuate
594 // Ex: b/w 29 and 30 for 30 fps clip
595 rate = stdRefreshRates[i];
596 break;
597 }
598 }
599 return rate;
600}
601
602//Helper func to set the dyn fps
603void setRefreshRate(hwc_context_t* ctx, int dpy, uint32_t refreshRate) {
604 //Update only if different
605 if(!ctx || refreshRate == ctx->dpyAttr[dpy].dynRefreshRate)
606 return;
607 const int fbNum = Overlay::getFbForDpy(dpy);
608 char sysfsPath[qdutils::MAX_SYSFS_FILE_PATH];
609 snprintf (sysfsPath, sizeof(sysfsPath),
Arun Kumar K.Ree4e2392015-01-12 18:08:34 -0800610 "/sys/devices/virtual/graphics/fb%d/dynamic_fps", fbNum);
Arun Kumar K.Ra727a882014-08-20 17:14:26 -0700611
612 int fd = open(sysfsPath, O_WRONLY);
613 if(fd >= 0) {
614 char str[64];
615 snprintf(str, sizeof(str), "%d", refreshRate);
616 ssize_t ret = write(fd, str, strlen(str));
617 if(ret < 0) {
618 ALOGE("%s: Failed to write %d with error %s",
619 __FUNCTION__, refreshRate, strerror(errno));
620 } else {
621 ctx->dpyAttr[dpy].dynRefreshRate = refreshRate;
622 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Wrote %d to dynamic_fps",
623 __FUNCTION__, refreshRate);
624 }
625 close(fd);
626 } else {
627 ALOGE("%s: Failed to open %s with error %s", __FUNCTION__, sysfsPath,
628 strerror(errno));
629 }
630}
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500631
632void dumpsys_log(android::String8& buf, const char* fmt, ...)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700633{
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500634 va_list varargs;
635 va_start(varargs, fmt);
636 buf.appendFormatV(fmt, varargs);
637 va_end(varargs);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700638}
639
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700640int getExtOrientation(hwc_context_t* ctx) {
641 int extOrient = ctx->mExtOrientation;
642 if(ctx->mBufferMirrorMode)
643 extOrient = getMirrorModeOrientation(ctx);
644 return extOrient;
645}
646
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800647/* Calculates the destination position based on the action safe rectangle */
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700648void getActionSafePosition(hwc_context_t *ctx, int dpy, hwc_rect_t& rect) {
649 // Position
650 int x = rect.left, y = rect.top;
651 int w = rect.right - rect.left;
652 int h = rect.bottom - rect.top;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800653
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800654 if(!ctx->dpyAttr[dpy].mActionSafePresent)
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800655 return;
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800656 // Read action safe properties
657 int asWidthRatio = ctx->dpyAttr[dpy].mAsWidthRatio;
658 int asHeightRatio = ctx->dpyAttr[dpy].mAsHeightRatio;
Arun Kumar K.R82f1d282013-05-17 15:37:31 -0700659
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800660 float wRatio = 1.0;
661 float hRatio = 1.0;
662 float xRatio = 1.0;
663 float yRatio = 1.0;
664
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700665 uint32_t fbWidth = ctx->dpyAttr[dpy].xres;
666 uint32_t fbHeight = ctx->dpyAttr[dpy].yres;
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700667 if(ctx->dpyAttr[dpy].mMDPScalingMode) {
668 // if MDP scaling mode is enabled for external, need to query
Arun Kumar KR7b7f4012013-10-29 11:53:11 -0700669 // the actual width and height, as that is the physical w & h
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700670 ctx->mHDMIDisplay->getAttributes(fbWidth, fbHeight);
Arun Kumar KR7b7f4012013-10-29 11:53:11 -0700671 }
672
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800673
Arun Kumar K.R82f1d282013-05-17 15:37:31 -0700674 // Since external is rotated 90, need to swap width/height
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700675 int extOrient = getExtOrientation(ctx);
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700676
677 if(extOrient & HWC_TRANSFORM_ROT_90)
Arun Kumar K.R82f1d282013-05-17 15:37:31 -0700678 swap(fbWidth, fbHeight);
679
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800680 float asX = 0;
681 float asY = 0;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530682 float asW = (float)fbWidth;
683 float asH = (float)fbHeight;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800684
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800685 // based on the action safe ratio, get the Action safe rectangle
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530686 asW = ((float)fbWidth * (1.0f - (float)asWidthRatio / 100.0f));
687 asH = ((float)fbHeight * (1.0f - (float)asHeightRatio / 100.0f));
688 asX = ((float)fbWidth - asW) / 2;
689 asY = ((float)fbHeight - asH) / 2;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800690
691 // calculate the position ratio
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530692 xRatio = (float)x/(float)fbWidth;
693 yRatio = (float)y/(float)fbHeight;
694 wRatio = (float)w/(float)fbWidth;
695 hRatio = (float)h/(float)fbHeight;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800696
697 //Calculate the position...
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530698 x = int((xRatio * asW) + asX);
699 y = int((yRatio * asH) + asY);
700 w = int(wRatio * asW);
701 h = int(hRatio * asH);
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800702
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700703 // Convert it back to hwc_rect_t
704 rect.left = x;
705 rect.top = y;
706 rect.right = w + rect.left;
707 rect.bottom = h + rect.top;
708
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800709 return;
710}
711
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700712// This function gets the destination position for Seconday display
713// based on the position and aspect ratio with orientation
714void getAspectRatioPosition(hwc_context_t* ctx, int dpy, int extOrientation,
715 hwc_rect_t& inRect, hwc_rect_t& outRect) {
716 // Physical display resolution
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530717 float fbWidth = (float)ctx->dpyAttr[dpy].xres;
718 float fbHeight = (float)ctx->dpyAttr[dpy].yres;
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700719 //display position(x,y,w,h) in correct aspectratio after rotation
720 int xPos = 0;
721 int yPos = 0;
722 float width = fbWidth;
723 float height = fbHeight;
724 // Width/Height used for calculation, after rotation
725 float actualWidth = fbWidth;
726 float actualHeight = fbHeight;
727
728 float wRatio = 1.0;
729 float hRatio = 1.0;
730 float xRatio = 1.0;
731 float yRatio = 1.0;
732 hwc_rect_t rect = {0, 0, (int)fbWidth, (int)fbHeight};
733
734 Dim inPos(inRect.left, inRect.top, inRect.right - inRect.left,
735 inRect.bottom - inRect.top);
736 Dim outPos(outRect.left, outRect.top, outRect.right - outRect.left,
737 outRect.bottom - outRect.top);
738
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530739 Whf whf((uint32_t)fbWidth, (uint32_t)fbHeight, 0);
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700740 eTransform extorient = static_cast<eTransform>(extOrientation);
741 // To calculate the destination co-ordinates in the new orientation
742 preRotateSource(extorient, whf, inPos);
743
744 if(extOrientation & HAL_TRANSFORM_ROT_90) {
745 // Swap width/height for input position
746 swapWidthHeight(actualWidth, actualHeight);
Tatenda Chipeperekwace8d5c42014-08-13 10:53:49 -0700747 qdutils::getAspectRatioPosition((int)fbWidth, (int)fbHeight,
748 (int)actualWidth, (int)actualHeight, rect);
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700749 xPos = rect.left;
750 yPos = rect.top;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530751 width = float(rect.right - rect.left);
752 height = float(rect.bottom - rect.top);
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700753 }
Shalaj Jaina70b4352014-06-15 13:47:47 -0700754 xRatio = (float)((float)inPos.x/actualWidth);
755 yRatio = (float)((float)inPos.y/actualHeight);
756 wRatio = (float)((float)inPos.w/actualWidth);
757 hRatio = (float)((float)inPos.h/actualHeight);
Ramkumar Radhakrishnandebfc5a2013-12-04 15:15:42 -0800758
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530759 //Calculate the pos9ition...
760 outPos.x = uint32_t((xRatio * width) + (float)xPos);
761 outPos.y = uint32_t((yRatio * height) + (float)yPos);
762 outPos.w = uint32_t(wRatio * width);
763 outPos.h = uint32_t(hRatio * height);
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700764 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Calculated AspectRatio Position: x = %d,"
765 "y = %d w = %d h = %d", __FUNCTION__, outPos.x, outPos.y,
766 outPos.w, outPos.h);
767
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700768 // For sidesync, the dest fb will be in portrait orientation, and the crop
769 // will be updated to avoid the black side bands, and it will be upscaled
770 // to fit the dest RB, so recalculate
771 // the position based on the new width and height
772 if ((extOrientation & HWC_TRANSFORM_ROT_90) &&
773 isOrientationPortrait(ctx)) {
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800774 hwc_rect_t r = {0, 0, 0, 0};
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700775 //Calculate the position
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530776 xRatio = (float)(outPos.x - xPos)/width;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700777 // GetaspectRatio -- tricky to get the correct aspect ratio
778 // But we need to do this.
Tatenda Chipeperekwace8d5c42014-08-13 10:53:49 -0700779 qdutils::getAspectRatioPosition((int)width, (int)height,
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530780 (int)width,(int)height, r);
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700781 xPos = r.left;
782 yPos = r.top;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530783 float tempHeight = float(r.bottom - r.top);
784 yRatio = (float)yPos/height;
785 wRatio = (float)outPos.w/width;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700786 hRatio = tempHeight/height;
787
788 //Map the coordinates back to Framebuffer domain
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530789 outPos.x = uint32_t(xRatio * fbWidth);
790 outPos.y = uint32_t(yRatio * fbHeight);
791 outPos.w = uint32_t(wRatio * fbWidth);
792 outPos.h = uint32_t(hRatio * fbHeight);
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700793
794 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Calculated AspectRatio for device in"
795 "portrait: x = %d,y = %d w = %d h = %d", __FUNCTION__,
796 outPos.x, outPos.y,
797 outPos.w, outPos.h);
798 }
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700799 if(ctx->dpyAttr[dpy].mMDPScalingMode) {
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700800 uint32_t extW = 0, extH = 0;
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700801 if(dpy == HWC_DISPLAY_EXTERNAL) {
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700802 ctx->mHDMIDisplay->getAttributes(extW, extH);
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700803 } else if(dpy == HWC_DISPLAY_VIRTUAL) {
804 extW = ctx->mHWCVirtual->getScalingWidth();
805 extH = ctx->mHWCVirtual->getScalingHeight();
806 }
807 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Scaling mode extW=%d extH=%d",
808 __FUNCTION__, extW, extH);
809
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530810 fbWidth = (float)ctx->dpyAttr[dpy].xres;
811 fbHeight = (float)ctx->dpyAttr[dpy].yres;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700812 //Calculate the position...
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530813 xRatio = (float)outPos.x/fbWidth;
814 yRatio = (float)outPos.y/fbHeight;
815 wRatio = (float)outPos.w/fbWidth;
816 hRatio = (float)outPos.h/fbHeight;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700817
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530818 outPos.x = uint32_t(xRatio * (float)extW);
819 outPos.y = uint32_t(yRatio * (float)extH);
820 outPos.w = uint32_t(wRatio * (float)extW);
821 outPos.h = uint32_t(hRatio * (float)extH);
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700822 }
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700823 // Convert Dim to hwc_rect_t
824 outRect.left = outPos.x;
825 outRect.top = outPos.y;
826 outRect.right = outPos.x + outPos.w;
827 outRect.bottom = outPos.y + outPos.h;
828
829 return;
830}
831
832bool isPrimaryPortrait(hwc_context_t *ctx) {
833 int fbWidth = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
834 int fbHeight = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres;
835 if(fbWidth < fbHeight) {
836 return true;
837 }
838 return false;
839}
840
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700841bool isOrientationPortrait(hwc_context_t *ctx) {
842 if(isPrimaryPortrait(ctx)) {
843 return !(ctx->deviceOrientation & 0x1);
844 }
845 return (ctx->deviceOrientation & 0x1);
846}
847
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700848void calcExtDisplayPosition(hwc_context_t *ctx,
849 private_handle_t *hnd,
850 int dpy,
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700851 hwc_rect_t& sourceCrop,
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700852 hwc_rect_t& displayFrame,
853 int& transform,
854 ovutils::eTransform& orient) {
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700855 // Swap width and height when there is a 90deg transform
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700856 int extOrient = getExtOrientation(ctx);
Tatenda Chipeperekwa748c96f2015-05-19 10:28:29 -0700857 if ((dpy || ctx->mHDMIDisplay->isHDMIPrimaryDisplay())
858 && ctx->mOverlay->isUIScalingOnExternalSupported()) {
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700859 if(!isYuvBuffer(hnd)) {
860 if(extOrient & HWC_TRANSFORM_ROT_90) {
861 int dstWidth = ctx->dpyAttr[dpy].xres;
862 int dstHeight = ctx->dpyAttr[dpy].yres;;
863 int srcWidth = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
864 int srcHeight = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres;
865 if(!isPrimaryPortrait(ctx)) {
866 swap(srcWidth, srcHeight);
867 } // Get Aspect Ratio for external
Tatenda Chipeperekwace8d5c42014-08-13 10:53:49 -0700868 qdutils::getAspectRatioPosition(dstWidth, dstHeight, srcWidth,
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700869 srcHeight, displayFrame);
870 // Crop - this is needed, because for sidesync, the dest fb will
871 // be in portrait orientation, so update the crop to not show the
872 // black side bands.
873 if (isOrientationPortrait(ctx)) {
874 sourceCrop = displayFrame;
875 displayFrame.left = 0;
876 displayFrame.top = 0;
877 displayFrame.right = dstWidth;
878 displayFrame.bottom = dstHeight;
879 }
880 }
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700881 if(ctx->dpyAttr[dpy].mMDPScalingMode) {
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700882 uint32_t extW = 0, extH = 0;
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700883 // if MDP scaling mode is enabled, map the co-ordinates to new
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700884 // domain(downscaled)
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530885 float fbWidth = (float)ctx->dpyAttr[dpy].xres;
886 float fbHeight = (float)ctx->dpyAttr[dpy].yres;
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700887 // query MDP configured attributes
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700888 if(dpy == HWC_DISPLAY_EXTERNAL) {
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700889 ctx->mHDMIDisplay->getAttributes(extW, extH);
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700890 } else if(dpy == HWC_DISPLAY_VIRTUAL) {
891 extW = ctx->mHWCVirtual->getScalingWidth();
892 extH = ctx->mHWCVirtual->getScalingHeight();
893 }
894 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Scaling mode extW=%d extH=%d",
895 __FUNCTION__, extW, extH);
896
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700897 //Calculate the ratio...
898 float wRatio = ((float)extW)/fbWidth;
899 float hRatio = ((float)extH)/fbHeight;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700900
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700901 //convert Dim to hwc_rect_t
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530902 displayFrame.left = int(wRatio*(float)displayFrame.left);
903 displayFrame.top = int(hRatio*(float)displayFrame.top);
904 displayFrame.right = int(wRatio*(float)displayFrame.right);
905 displayFrame.bottom = int(hRatio*(float)displayFrame.bottom);
Ramkumar Radhakrishnana5c72872014-08-28 19:04:18 -0700906 ALOGD_IF(DEBUG_MDPDOWNSCALE, "Calculated external display frame"
907 " for MDPDownscale feature [%d %d %d %d]",
908 displayFrame.left, displayFrame.top,
909 displayFrame.right, displayFrame.bottom);
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700910 }
911 }else {
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700912 if(extOrient || ctx->dpyAttr[dpy].mMDPScalingMode) {
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700913 getAspectRatioPosition(ctx, dpy, extOrient,
914 displayFrame, displayFrame);
915 }
916 }
917 // If there is a external orientation set, use that
918 if(extOrient) {
919 transform = extOrient;
920 orient = static_cast<ovutils::eTransform >(extOrient);
921 }
922 // Calculate the actionsafe dimensions for External(dpy = 1 or 2)
923 getActionSafePosition(ctx, dpy, displayFrame);
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700924 }
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700925}
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700926
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700927/* Returns the orientation which needs to be set on External for
928 * SideSync/Buffer Mirrormode
929 */
930int getMirrorModeOrientation(hwc_context_t *ctx) {
931 int extOrientation = 0;
932 int deviceOrientation = ctx->deviceOrientation;
933 if(!isPrimaryPortrait(ctx))
934 deviceOrientation = (deviceOrientation + 1) % 4;
935 if (deviceOrientation == 0)
936 extOrientation = HWC_TRANSFORM_ROT_270;
937 else if (deviceOrientation == 1)//90
938 extOrientation = 0;
939 else if (deviceOrientation == 2)//180
940 extOrientation = HWC_TRANSFORM_ROT_90;
941 else if (deviceOrientation == 3)//270
942 extOrientation = HWC_TRANSFORM_FLIP_V | HWC_TRANSFORM_FLIP_H;
943
944 return extOrientation;
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700945}
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700946
Raj kamal59fea562014-04-01 16:52:19 +0530947/* Get External State names */
948const char* getExternalDisplayState(uint32_t external_state) {
949 static const char* externalStates[EXTERNAL_MAXSTATES] = {0};
950 externalStates[EXTERNAL_OFFLINE] = STR(EXTERNAL_OFFLINE);
951 externalStates[EXTERNAL_ONLINE] = STR(EXTERNAL_ONLINE);
952 externalStates[EXTERNAL_PAUSE] = STR(EXTERNAL_PAUSE);
953 externalStates[EXTERNAL_RESUME] = STR(EXTERNAL_RESUME);
954
955 if(external_state >= EXTERNAL_MAXSTATES) {
956 return "EXTERNAL_INVALID";
957 }
958
959 return externalStates[external_state];
960}
961
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530962bool isDownscaleRequired(hwc_layer_1_t const* layer) {
963 hwc_rect_t displayFrame = layer->displayFrame;
964 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
965 int dst_w, dst_h, src_w, src_h;
966 dst_w = displayFrame.right - displayFrame.left;
967 dst_h = displayFrame.bottom - displayFrame.top;
968 src_w = sourceCrop.right - sourceCrop.left;
969 src_h = sourceCrop.bottom - sourceCrop.top;
970
radhakrishnafe165702015-05-12 22:24:57 +0530971 if(layer->transform & HWC_TRANSFORM_ROT_90)
972 swap(src_w, src_h);
973
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530974 if(((src_w > dst_w) || (src_h > dst_h)))
975 return true;
976
977 return false;
978}
radhakrishna35e33072015-04-08 17:20:43 +0530979
980bool isDownscaleWithinThreshold(hwc_layer_1_t const* layer, float threshold) {
981 hwc_rect_t displayFrame = layer->displayFrame;
982 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
983 int dst_w, dst_h, src_w, src_h;
984 float downscale = 1.0;
985 dst_w = displayFrame.right - displayFrame.left;
986 dst_h = displayFrame.bottom - displayFrame.top;
987 src_w = sourceCrop.right - sourceCrop.left;
988 src_h = sourceCrop.bottom - sourceCrop.top;
radhakrishnafe165702015-05-12 22:24:57 +0530989
990 if(layer->transform & HWC_TRANSFORM_ROT_90)
991 swap(src_w, src_h);
992
radhakrishna35e33072015-04-08 17:20:43 +0530993 if(dst_w && dst_h) {
994 float w_scale = ((float)src_w / (float)dst_w);
995 float h_scale = ((float)src_h / (float)dst_h);
996
997 if((w_scale > threshold) or (h_scale > threshold))
998 return false;
999 }
1000
1001 return true;
1002}
1003
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301004bool needsScaling(hwc_layer_1_t const* layer) {
Naseer Ahmed018e5452012-12-03 14:46:15 -05001005 int dst_w, dst_h, src_w, src_h;
Naseer Ahmed018e5452012-12-03 14:46:15 -05001006 hwc_rect_t displayFrame = layer->displayFrame;
Saurabh Shah62e1d732013-09-17 10:44:05 -07001007 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
Naseer Ahmed018e5452012-12-03 14:46:15 -05001008
1009 dst_w = displayFrame.right - displayFrame.left;
1010 dst_h = displayFrame.bottom - displayFrame.top;
Naseer Ahmed018e5452012-12-03 14:46:15 -05001011 src_w = sourceCrop.right - sourceCrop.left;
1012 src_h = sourceCrop.bottom - sourceCrop.top;
1013
Jeykumar Sankaran6a339522014-11-04 16:14:43 -08001014 if(layer->transform & HWC_TRANSFORM_ROT_90)
1015 swap(src_w, src_h);
1016
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001017 if(((src_w != dst_w) || (src_h != dst_h)))
1018 return true;
1019
1020 return false;
1021}
1022
Sushil Chauhan15a2ea62013-09-04 18:28:36 -07001023// Checks if layer needs scaling with split
1024bool needsScalingWithSplit(hwc_context_t* ctx, hwc_layer_1_t const* layer,
1025 const int& dpy) {
1026
1027 int src_width_l, src_height_l;
1028 int src_width_r, src_height_r;
1029 int dst_width_l, dst_height_l;
1030 int dst_width_r, dst_height_r;
1031 int hw_w = ctx->dpyAttr[dpy].xres;
1032 int hw_h = ctx->dpyAttr[dpy].yres;
1033 hwc_rect_t cropL, dstL, cropR, dstR;
1034 const int lSplit = getLeftSplit(ctx, dpy);
Saurabh Shah62e1d732013-09-17 10:44:05 -07001035 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
Sushil Chauhan15a2ea62013-09-04 18:28:36 -07001036 hwc_rect_t displayFrame = layer->displayFrame;
1037 private_handle_t *hnd = (private_handle_t *)layer->handle;
Sushil Chauhan15a2ea62013-09-04 18:28:36 -07001038
1039 cropL = sourceCrop;
1040 dstL = displayFrame;
1041 hwc_rect_t scissorL = { 0, 0, lSplit, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -08001042 scissorL = getIntersection(ctx->mViewFrame[dpy], scissorL);
Sushil Chauhan15a2ea62013-09-04 18:28:36 -07001043 qhwc::calculate_crop_rects(cropL, dstL, scissorL, 0);
1044
1045 cropR = sourceCrop;
1046 dstR = displayFrame;
1047 hwc_rect_t scissorR = { lSplit, 0, hw_w, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -08001048 scissorR = getIntersection(ctx->mViewFrame[dpy], scissorR);
Sushil Chauhan15a2ea62013-09-04 18:28:36 -07001049 qhwc::calculate_crop_rects(cropR, dstR, scissorR, 0);
1050
1051 // Sanitize Crop to stitch
1052 sanitizeSourceCrop(cropL, cropR, hnd);
1053
1054 // Calculate the left dst
1055 dst_width_l = dstL.right - dstL.left;
1056 dst_height_l = dstL.bottom - dstL.top;
1057 src_width_l = cropL.right - cropL.left;
1058 src_height_l = cropL.bottom - cropL.top;
1059
1060 // check if there is any scaling on the left
1061 if(((src_width_l != dst_width_l) || (src_height_l != dst_height_l)))
1062 return true;
1063
1064 // Calculate the right dst
1065 dst_width_r = dstR.right - dstR.left;
1066 dst_height_r = dstR.bottom - dstR.top;
1067 src_width_r = cropR.right - cropR.left;
1068 src_height_r = cropR.bottom - cropR.top;
1069
1070 // check if there is any scaling on the right
1071 if(((src_width_r != dst_width_r) || (src_height_r != dst_height_r)))
1072 return true;
1073
1074 return false;
1075}
1076
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301077bool isAlphaScaled(hwc_layer_1_t const* layer) {
1078 if(needsScaling(layer) && isAlphaPresent(layer)) {
Sravan Kumar D.V.N075ef002013-03-20 05:22:26 +05301079 return true;
1080 }
1081 return false;
1082}
1083
1084bool isAlphaPresent(hwc_layer_1_t const* layer) {
1085 private_handle_t *hnd = (private_handle_t *)layer->handle;
Naseer Ahmed7a4287c2013-03-26 18:11:41 -04001086 if(hnd) {
1087 int format = hnd->format;
1088 switch(format) {
Sravan Kumar D.V.N075ef002013-03-20 05:22:26 +05301089 case HAL_PIXEL_FORMAT_RGBA_8888:
1090 case HAL_PIXEL_FORMAT_BGRA_8888:
1091 // In any more formats with Alpha go here..
Naseer Ahmed018e5452012-12-03 14:46:15 -05001092 return true;
Sravan Kumar D.V.N075ef002013-03-20 05:22:26 +05301093 default : return false;
Naseer Ahmed7a4287c2013-03-26 18:11:41 -04001094 }
Naseer Ahmed018e5452012-12-03 14:46:15 -05001095 }
1096 return false;
1097}
1098
radhakrishnac3198ff2015-03-10 17:10:02 +05301099bool isAlphaPresentinFB(hwc_context_t *ctx, int dpy) {
1100 switch(ctx->dpyAttr[dpy].fbformat) {
1101 case HAL_PIXEL_FORMAT_RGBA_8888:
1102 case HAL_PIXEL_FORMAT_BGRA_8888:
1103 return true;
1104 default : return false;
1105 }
1106 return false;
1107}
1108
Saurabh Shahd9ff30b2013-10-03 16:37:06 -07001109static void trimLayer(hwc_context_t *ctx, const int& dpy, const int& transform,
1110 hwc_rect_t& crop, hwc_rect_t& dst) {
1111 int hw_w = ctx->dpyAttr[dpy].xres;
1112 int hw_h = ctx->dpyAttr[dpy].yres;
1113 if(dst.left < 0 || dst.top < 0 ||
1114 dst.right > hw_w || dst.bottom > hw_h) {
1115 hwc_rect_t scissor = {0, 0, hw_w, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -08001116 scissor = getIntersection(ctx->mViewFrame[dpy], scissor);
Saurabh Shahd9ff30b2013-10-03 16:37:06 -07001117 qhwc::calculate_crop_rects(crop, dst, scissor, transform);
1118 }
1119}
1120
1121static void trimList(hwc_context_t *ctx, hwc_display_contents_1_t *list,
1122 const int& dpy) {
1123 for(uint32_t i = 0; i < list->numHwLayers - 1; i++) {
1124 hwc_layer_1_t *layer = &list->hwLayers[i];
1125 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Sushil Chauhanfda00fc2014-03-20 11:08:41 -07001126 int transform = (list->hwLayers[i].flags & HWC_COLOR_FILL) ? 0 :
1127 list->hwLayers[i].transform;
Saurabh Shahd9ff30b2013-10-03 16:37:06 -07001128 trimLayer(ctx, dpy,
Sushil Chauhanfda00fc2014-03-20 11:08:41 -07001129 transform,
Saurabh Shahd9ff30b2013-10-03 16:37:06 -07001130 (hwc_rect_t&)crop,
1131 (hwc_rect_t&)list->hwLayers[i].displayFrame);
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301132 layer->sourceCropf.left = (float)crop.left;
1133 layer->sourceCropf.right = (float)crop.right;
1134 layer->sourceCropf.top = (float)crop.top;
1135 layer->sourceCropf.bottom = (float)crop.bottom;
Saurabh Shahd9ff30b2013-10-03 16:37:06 -07001136 }
1137}
1138
Saurabh Shah3e858eb2012-09-17 16:53:21 -07001139void setListStats(hwc_context_t *ctx,
Saurabh Shahd9ff30b2013-10-03 16:37:06 -07001140 hwc_display_contents_1_t *list, int dpy) {
Saurabh Shahd4e65852013-06-17 11:33:53 -07001141 const int prevYuvCount = ctx->listStats[dpy].yuvCount;
1142 memset(&ctx->listStats[dpy], 0, sizeof(ListStats));
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301143 ctx->listStats[dpy].numAppLayers = (int)list->numHwLayers - 1;
1144 ctx->listStats[dpy].fbLayerIndex = (int)list->numHwLayers - 1;
Saurabh Shahc4d034f2012-09-27 15:55:15 -07001145 ctx->listStats[dpy].skipCount = 0;
Sravan Kumar D.V.Nb5ed0292013-03-15 08:51:16 +05301146 ctx->listStats[dpy].preMultipliedAlpha = false;
Saurabh Shah8028e3b2013-10-15 12:27:59 -07001147 ctx->listStats[dpy].isSecurePresent = false;
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001148 ctx->listStats[dpy].yuvCount = 0;
Ping Li9404e2a2013-04-24 16:36:03 -04001149 char property[PROPERTY_VALUE_MAX];
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001150 ctx->listStats[dpy].isDisplayAnimating = false;
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -07001151 ctx->listStats[dpy].secureUI = false;
radhakrishnac9a67412013-09-25 17:40:42 +05301152 ctx->listStats[dpy].yuv4k2kCount = 0;
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -08001153 ctx->dpyAttr[dpy].mActionSafePresent = isActionSafePresent(ctx, dpy);
Ramakant Singh0def28c2014-03-28 20:43:13 +05301154 ctx->listStats[dpy].renderBufIndexforABC = -1;
Ramkumar Radhakrishnan4ec775f2014-07-23 17:43:18 -07001155 ctx->listStats[dpy].secureRGBCount = 0;
Arun Kumar K.Ra727a882014-08-20 17:14:26 -07001156 ctx->listStats[dpy].refreshRateRequest = ctx->dpyAttr[dpy].refreshRate;
Arun Kumar K.R00b84792015-03-27 11:28:36 -07001157 ctx->listStats[dpy].cursorLayerPresent = false;
Arun Kumar K.Ra727a882014-08-20 17:14:26 -07001158 uint32_t refreshRate = 0;
1159 qdutils::MDPVersion& mdpHw = qdutils::MDPVersion::getInstance();
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -05001160 int s3dFormat = HAL_NO_3D;
1161 int s3dLayerCount = 0;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001162
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07001163 ctx->listStats[dpy].mAIVVideoMode = false;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001164 resetROI(ctx, dpy);
1165
Sushil Chauhanf68d0df2014-04-09 09:15:37 -07001166 trimList(ctx, list, dpy);
1167 optimizeLayerRects(list);
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -07001168 for (size_t i = 0; i < (size_t)ctx->listStats[dpy].numAppLayers; i++) {
Naseer Ahmed018e5452012-12-03 14:46:15 -05001169 hwc_layer_1_t const* layer = &list->hwLayers[i];
1170 private_handle_t *hnd = (private_handle_t *)layer->handle;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001171
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001172#ifdef QCOM_BSP
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07001173 // Window boxing feature is applicable obly for external display, So
1174 // enable mAIVVideoMode only for external display
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07001175 if(ctx->mWindowboxFeature && dpy && isAIVVideoLayer(layer)) {
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07001176 ctx->listStats[dpy].mAIVVideoMode = true;
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07001177 }
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001178 if (layer->flags & HWC_SCREENSHOT_ANIMATOR_LAYER) {
1179 ctx->listStats[dpy].isDisplayAnimating = true;
1180 }
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -07001181 if(isSecureDisplayBuffer(hnd)) {
1182 ctx->listStats[dpy].secureUI = true;
1183 }
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001184#endif
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -07001185 // continue if number of app layers exceeds MAX_NUM_APP_LAYERS
1186 if(ctx->listStats[dpy].numAppLayers > MAX_NUM_APP_LAYERS)
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001187 continue;
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001188
Arun Kumar K.R00b84792015-03-27 11:28:36 -07001189 // Valid cursor must be the top most layer
1190 if((int)i == (ctx->listStats[dpy].numAppLayers - 1) &&
1191 isCursorLayer(&list->hwLayers[i])) {
1192 ctx->listStats[dpy].cursorLayerPresent = true;
1193 }
1194
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -07001195 //reset yuv indices
1196 ctx->listStats[dpy].yuvIndices[i] = -1;
radhakrishnac9a67412013-09-25 17:40:42 +05301197 ctx->listStats[dpy].yuv4k2kIndices[i] = -1;
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -07001198
Saurabh Shah8028e3b2013-10-15 12:27:59 -07001199 if (isSecureBuffer(hnd)) {
1200 ctx->listStats[dpy].isSecurePresent = true;
Ramkumar Radhakrishnan4ec775f2014-07-23 17:43:18 -07001201 if(not isYuvBuffer(hnd)) {
1202 // cache secureRGB layer parameters like we cache for YUV layers
1203 int& secureRGBCount = ctx->listStats[dpy].secureRGBCount;
1204 ctx->listStats[dpy].secureRGBIndices[secureRGBCount] = (int)i;
1205 secureRGBCount++;
1206 }
Saurabh Shah8028e3b2013-10-15 12:27:59 -07001207 }
1208
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -07001209 if (isSkipLayer(&list->hwLayers[i])) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -07001210 ctx->listStats[dpy].skipCount++;
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001211 }
1212
1213 if (UNLIKELY(isYuvBuffer(hnd))) {
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001214 int& yuvCount = ctx->listStats[dpy].yuvCount;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301215 ctx->listStats[dpy].yuvIndices[yuvCount] = (int)i;
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001216 yuvCount++;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001217
Raj Kamal389d6e32014-08-04 14:43:24 +05301218 if(UNLIKELY(isYUVSplitNeeded(hnd))){
radhakrishnac9a67412013-09-25 17:40:42 +05301219 int& yuv4k2kCount = ctx->listStats[dpy].yuv4k2kCount;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301220 ctx->listStats[dpy].yuv4k2kIndices[yuv4k2kCount] = (int)i;
radhakrishnac9a67412013-09-25 17:40:42 +05301221 yuv4k2kCount++;
1222 }
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -05001223
1224 // Gets set if one YUV layer is 3D
1225 if (displaySupports3D(ctx,dpy)) {
1226 s3dFormat = get3DFormat(hnd);
1227 if(s3dFormat != HAL_NO_3D)
1228 s3dLayerCount++;
1229 }
1230
Naseer Ahmed29a26812012-06-14 00:56:20 -07001231 }
Sravan Kumar D.V.Nb5ed0292013-03-15 08:51:16 +05301232 if(layer->blending == HWC_BLENDING_PREMULT)
1233 ctx->listStats[dpy].preMultipliedAlpha = true;
Jeykumar Sankaran7535aba2013-02-04 11:03:09 -08001234
Arun Kumar K.Ra727a882014-08-20 17:14:26 -07001235#ifdef DYNAMIC_FPS
Raj Kamal0d53fc62014-11-25 17:36:36 +05301236 if (!dpy && mdpHw.isDynFpsSupported() && ctx->mUseMetaDataRefreshRate){
Raj Kamalf8829b92015-04-08 13:52:58 +05301237 /* Dyn fps: get refreshrate from metadata */
Arun Kumar K.Ra727a882014-08-20 17:14:26 -07001238 MetaData_t *mdata = hnd ? (MetaData_t *)hnd->base_metadata : NULL;
1239 if (mdata && (mdata->operation & UPDATE_REFRESH_RATE)) {
1240 // Valid refreshRate in metadata and within the range
Raj Kamalf8829b92015-04-08 13:52:58 +05301241 uint32_t rate = getRefreshRate(ctx, mdata->refreshrate);
1242 if (!refreshRate) {
1243 refreshRate = rate;
1244 } else if(refreshRate != rate) {
1245 /* Support multiple refresh rates if they are same
1246 * else set to default.
1247 */
1248 refreshRate = ctx->dpyAttr[dpy].refreshRate;
Arun Kumar K.Ra727a882014-08-20 17:14:26 -07001249 }
1250 }
1251 }
1252#endif
Naseer Ahmed29a26812012-06-14 00:56:20 -07001253 }
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -05001254
1255 //Set the TV's 3D mode based on format if it was not forced
1256 //Only one 3D YUV layer is supported on external
1257 //If there is more than one 3D YUV layer, the switch to 3D cannot occur.
1258 if( !ctx->dpyAttr[dpy].s3dModeForced && (s3dLayerCount <= 1)) {
1259 //XXX: Rapidly going in and out of 3D mode in some cases such
1260 // as rotation might cause flickers. The OEMs are recommended to disable
1261 // rotation on HDMI globally or in the app that plays 3D video
1262 setup3DMode(ctx, dpy, convertS3DFormatToMode(s3dFormat));
1263 }
1264
Ping Li9404e2a2013-04-24 16:36:03 -04001265 if(ctx->listStats[dpy].yuvCount > 0) {
1266 if (property_get("hw.cabl.yuv", property, NULL) > 0) {
1267 if (atoi(property) != 1) {
1268 property_set("hw.cabl.yuv", "1");
1269 }
1270 }
1271 } else {
1272 if (property_get("hw.cabl.yuv", property, NULL) > 0) {
1273 if (atoi(property) != 0) {
1274 property_set("hw.cabl.yuv", "0");
1275 }
1276 }
1277 }
Saurabh Shahd4e65852013-06-17 11:33:53 -07001278
1279 //The marking of video begin/end is useful on some targets where we need
1280 //to have a padding round to be able to shift pipes across mixers.
1281 if(prevYuvCount != ctx->listStats[dpy].yuvCount) {
1282 ctx->mVideoTransFlag = true;
1283 }
Raj Kamal9ed3d6b2014-02-07 16:15:17 +05301284
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001285 if(dpy == HWC_DISPLAY_PRIMARY) {
1286 ctx->mAD->markDoable(ctx, list);
Arun Kumar K.Ra727a882014-08-20 17:14:26 -07001287 //Store the requested fresh rate
1288 ctx->listStats[dpy].refreshRateRequest = refreshRate ?
1289 refreshRate : ctx->dpyAttr[dpy].refreshRate;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001290 }
Naseer Ahmed29a26812012-06-14 00:56:20 -07001291}
1292
Naseer Ahmed018e5452012-12-03 14:46:15 -05001293
Saurabh Shah68107422013-07-09 11:12:42 -07001294static void calc_cut(double& leftCutRatio, double& topCutRatio,
1295 double& rightCutRatio, double& bottomCutRatio, int orient) {
Saurabh Shah27c1d652012-08-14 19:30:28 -07001296 if(orient & HAL_TRANSFORM_FLIP_H) {
Saurabh Shah541b59d2012-10-11 11:08:12 -07001297 swap(leftCutRatio, rightCutRatio);
Saurabh Shah27c1d652012-08-14 19:30:28 -07001298 }
1299 if(orient & HAL_TRANSFORM_FLIP_V) {
Saurabh Shah541b59d2012-10-11 11:08:12 -07001300 swap(topCutRatio, bottomCutRatio);
Saurabh Shah27c1d652012-08-14 19:30:28 -07001301 }
1302 if(orient & HAL_TRANSFORM_ROT_90) {
1303 //Anti clock swapping
Saurabh Shah68107422013-07-09 11:12:42 -07001304 double tmpCutRatio = leftCutRatio;
Saurabh Shah541b59d2012-10-11 11:08:12 -07001305 leftCutRatio = topCutRatio;
1306 topCutRatio = rightCutRatio;
1307 rightCutRatio = bottomCutRatio;
1308 bottomCutRatio = tmpCutRatio;
Saurabh Shah27c1d652012-08-14 19:30:28 -07001309 }
1310}
1311
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001312bool isSecuring(hwc_context_t* ctx, hwc_layer_1_t const* layer) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001313 if((ctx->mMDP.version < qdutils::MDSS_V5) &&
1314 (ctx->mMDP.version > qdutils::MDP_V3_0) &&
1315 ctx->mSecuring) {
1316 return true;
1317 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001318 if (isSecureModePolicy(ctx->mMDP.version)) {
1319 private_handle_t *hnd = (private_handle_t *)layer->handle;
1320 if(ctx->mSecureMode) {
1321 if (! isSecureBuffer(hnd)) {
1322 ALOGD_IF(HWC_UTILS_DEBUG,"%s:Securing Turning ON ...",
1323 __FUNCTION__);
1324 return true;
1325 }
1326 } else {
1327 if (isSecureBuffer(hnd)) {
1328 ALOGD_IF(HWC_UTILS_DEBUG,"%s:Securing Turning OFF ...",
1329 __FUNCTION__);
1330 return true;
1331 }
1332 }
1333 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001334 return false;
1335}
1336
Sushil Chauhan2515abf2013-01-08 16:40:05 -08001337bool isSecureModePolicy(int mdpVersion) {
1338 if (mdpVersion < qdutils::MDSS_V5)
1339 return true;
1340 else
1341 return false;
1342}
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001343
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001344bool isRotatorSupportedFormat(private_handle_t *hnd) {
1345 // Following rotator src formats are supported by mdp driver
1346 // TODO: Add more formats in future, if mdp driver adds support
Ramkumar Radhakrishnan629cbf52014-10-14 19:36:33 -07001347 if(hnd != NULL) {
1348 switch(hnd->format) {
1349 case HAL_PIXEL_FORMAT_RGBA_8888:
Ramkumar Radhakrishnanb8eb16d2014-10-09 13:54:07 -07001350 case HAL_PIXEL_FORMAT_RGBA_5551:
1351 case HAL_PIXEL_FORMAT_RGBA_4444:
Ramkumar Radhakrishnan629cbf52014-10-14 19:36:33 -07001352 case HAL_PIXEL_FORMAT_RGB_565:
1353 case HAL_PIXEL_FORMAT_RGB_888:
1354 case HAL_PIXEL_FORMAT_BGRA_8888:
1355 return true;
1356 default:
1357 return false;
1358 }
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001359 }
1360 return false;
1361}
1362
1363bool isRotationDoable(hwc_context_t *ctx, private_handle_t *hnd) {
Ramkumar Radhakrishnan629cbf52014-10-14 19:36:33 -07001364 // Rotate layers, if it is not secure display buffer and not
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001365 // for the MDP versions below MDP5
Ramkumar Radhakrishnan629cbf52014-10-14 19:36:33 -07001366 if((!isSecureDisplayBuffer(hnd) && isRotatorSupportedFormat(hnd) &&
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001367 !ctx->mMDP.version < qdutils::MDSS_V5)
1368 || isYuvBuffer(hnd)) {
1369 return true;
1370 }
1371 return false;
1372}
1373
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -08001374// returns true if Action safe dimensions are set and target supports Actionsafe
1375bool isActionSafePresent(hwc_context_t *ctx, int dpy) {
1376 // if external supports underscan, do nothing
1377 // it will be taken care in the driver
Ramkumar Radhakrishnana61a0da2014-03-03 14:46:21 -08001378 // Disable Action safe for 8974 due to HW limitation for downscaling
1379 // layers with overlapped region
1380 // Disable Actionsafe for non HDMI displays.
Tatenda Chipeperekwa748c96f2015-05-19 10:28:29 -07001381 if (!(dpy == HWC_DISPLAY_EXTERNAL ||
1382 ctx->mHDMIDisplay->isHDMIPrimaryDisplay()) ||
1383 qdutils::MDPVersion::getInstance().is8x74v2() ||
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -07001384 ctx->mHDMIDisplay->isCEUnderscanSupported()) {
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -08001385 return false;
Ramkumar Radhakrishnana61a0da2014-03-03 14:46:21 -08001386 }
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -08001387
1388 char value[PROPERTY_VALUE_MAX];
1389 // Read action safe properties
1390 property_get("persist.sys.actionsafe.width", value, "0");
1391 ctx->dpyAttr[dpy].mAsWidthRatio = atoi(value);
1392 property_get("persist.sys.actionsafe.height", value, "0");
1393 ctx->dpyAttr[dpy].mAsHeightRatio = atoi(value);
1394
1395 if(!ctx->dpyAttr[dpy].mAsWidthRatio && !ctx->dpyAttr[dpy].mAsHeightRatio) {
1396 //No action safe ratio set, return
1397 return false;
1398 }
1399 return true;
1400}
1401
Naseer Ahmed522ce662013-03-18 20:14:05 -04001402int getBlending(int blending) {
1403 switch(blending) {
1404 case HWC_BLENDING_NONE:
1405 return overlay::utils::OVERLAY_BLENDING_OPAQUE;
1406 case HWC_BLENDING_PREMULT:
1407 return overlay::utils::OVERLAY_BLENDING_PREMULT;
1408 case HWC_BLENDING_COVERAGE :
1409 default:
1410 return overlay::utils::OVERLAY_BLENDING_COVERAGE;
1411 }
1412}
1413
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001414//Crops source buffer against destination and FB boundaries
1415void calculate_crop_rects(hwc_rect_t& crop, hwc_rect_t& dst,
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001416 const hwc_rect_t& scissor, int orient) {
1417
Saurabh Shah27c1d652012-08-14 19:30:28 -07001418 int& crop_l = crop.left;
1419 int& crop_t = crop.top;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001420 int& crop_r = crop.right;
1421 int& crop_b = crop.bottom;
1422 int crop_w = crop.right - crop.left;
1423 int crop_h = crop.bottom - crop.top;
1424
Saurabh Shah27c1d652012-08-14 19:30:28 -07001425 int& dst_l = dst.left;
1426 int& dst_t = dst.top;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001427 int& dst_r = dst.right;
1428 int& dst_b = dst.bottom;
Saurabh Shah27c1d652012-08-14 19:30:28 -07001429 int dst_w = abs(dst.right - dst.left);
1430 int dst_h = abs(dst.bottom - dst.top);
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001431
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001432 const int& sci_l = scissor.left;
1433 const int& sci_t = scissor.top;
1434 const int& sci_r = scissor.right;
1435 const int& sci_b = scissor.bottom;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001436
Saurabh Shah68107422013-07-09 11:12:42 -07001437 double leftCutRatio = 0.0, rightCutRatio = 0.0, topCutRatio = 0.0,
1438 bottomCutRatio = 0.0;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001439
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001440 if(dst_l < sci_l) {
Saurabh Shah68107422013-07-09 11:12:42 -07001441 leftCutRatio = (double)(sci_l - dst_l) / (double)dst_w;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001442 dst_l = sci_l;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001443 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001444
1445 if(dst_r > sci_r) {
Saurabh Shah68107422013-07-09 11:12:42 -07001446 rightCutRatio = (double)(dst_r - sci_r) / (double)dst_w;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001447 dst_r = sci_r;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001448 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001449
1450 if(dst_t < sci_t) {
Saurabh Shah68107422013-07-09 11:12:42 -07001451 topCutRatio = (double)(sci_t - dst_t) / (double)dst_h;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001452 dst_t = sci_t;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001453 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001454
1455 if(dst_b > sci_b) {
Saurabh Shah68107422013-07-09 11:12:42 -07001456 bottomCutRatio = (double)(dst_b - sci_b) / (double)dst_h;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001457 dst_b = sci_b;
Naseer Ahmed29a26812012-06-14 00:56:20 -07001458 }
Saurabh Shah27c1d652012-08-14 19:30:28 -07001459
Saurabh Shah541b59d2012-10-11 11:08:12 -07001460 calc_cut(leftCutRatio, topCutRatio, rightCutRatio, bottomCutRatio, orient);
Dileep Kumar Reddi39e79bf2014-03-06 11:56:10 +05301461 crop_l += (int)round((double)crop_w * leftCutRatio);
1462 crop_t += (int)round((double)crop_h * topCutRatio);
1463 crop_r -= (int)round((double)crop_w * rightCutRatio);
1464 crop_b -= (int)round((double)crop_h * bottomCutRatio);
Naseer Ahmed29a26812012-06-14 00:56:20 -07001465}
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001466
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301467bool areLayersIntersecting(const hwc_layer_1_t* layer1,
1468 const hwc_layer_1_t* layer2) {
1469 hwc_rect_t irect = getIntersection(layer1->displayFrame,
1470 layer2->displayFrame);
1471 return isValidRect(irect);
1472}
1473
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001474bool isSameRect(const hwc_rect& rect1, const hwc_rect& rect2)
1475{
1476 return ((rect1.left == rect2.left) && (rect1.top == rect2.top) &&
1477 (rect1.right == rect2.right) && (rect1.bottom == rect2.bottom));
1478}
1479
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001480bool isValidRect(const hwc_rect& rect)
1481{
1482 return ((rect.bottom > rect.top) && (rect.right > rect.left)) ;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301483}
1484
Ramakant Singh21cec722014-03-07 19:11:45 +05301485bool operator ==(const hwc_rect_t& lhs, const hwc_rect_t& rhs) {
1486 if(lhs.left == rhs.left && lhs.top == rhs.top &&
1487 lhs.right == rhs.right && lhs.bottom == rhs.bottom )
1488 return true ;
1489 return false;
1490}
1491
Jeykumar Sankaran71e597c2014-05-07 16:23:14 -07001492hwc_rect_t moveRect(const hwc_rect_t& rect, const int& x_off, const int& y_off)
1493{
1494 hwc_rect_t res;
1495
1496 if(!isValidRect(rect))
1497 return (hwc_rect_t){0, 0, 0, 0};
1498
1499 res.left = rect.left + x_off;
1500 res.top = rect.top + y_off;
1501 res.right = rect.right + x_off;
1502 res.bottom = rect.bottom + y_off;
1503
1504 return res;
1505}
1506
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001507/* computes the intersection of two rects */
1508hwc_rect_t getIntersection(const hwc_rect_t& rect1, const hwc_rect_t& rect2)
1509{
1510 hwc_rect_t res;
1511
1512 if(!isValidRect(rect1) || !isValidRect(rect2)){
1513 return (hwc_rect_t){0, 0, 0, 0};
1514 }
1515
1516
1517 res.left = max(rect1.left, rect2.left);
1518 res.top = max(rect1.top, rect2.top);
1519 res.right = min(rect1.right, rect2.right);
1520 res.bottom = min(rect1.bottom, rect2.bottom);
1521
1522 if(!isValidRect(res))
1523 return (hwc_rect_t){0, 0, 0, 0};
1524
1525 return res;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301526}
1527
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001528/* computes the union of two rects */
1529hwc_rect_t getUnion(const hwc_rect &rect1, const hwc_rect &rect2)
1530{
1531 hwc_rect_t res;
1532
1533 if(!isValidRect(rect1)){
1534 return rect2;
1535 }
1536
1537 if(!isValidRect(rect2)){
1538 return rect1;
1539 }
1540
1541 res.left = min(rect1.left, rect2.left);
1542 res.top = min(rect1.top, rect2.top);
1543 res.right = max(rect1.right, rect2.right);
1544 res.bottom = max(rect1.bottom, rect2.bottom);
1545
1546 return res;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301547}
1548
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001549/* Not a geometrical rect deduction. Deducts rect2 from rect1 only if it results
1550 * a single rect */
1551hwc_rect_t deductRect(const hwc_rect_t& rect1, const hwc_rect_t& rect2) {
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301552
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001553 hwc_rect_t res = rect1;
1554
1555 if((rect1.left == rect2.left) && (rect1.right == rect2.right)) {
1556 if((rect1.top == rect2.top) && (rect2.bottom <= rect1.bottom))
1557 res.top = rect2.bottom;
1558 else if((rect1.bottom == rect2.bottom)&& (rect2.top >= rect1.top))
1559 res.bottom = rect2.top;
1560 }
1561 else if((rect1.top == rect2.top) && (rect1.bottom == rect2.bottom)) {
1562 if((rect1.left == rect2.left) && (rect2.right <= rect1.right))
1563 res.left = rect2.right;
1564 else if((rect1.right == rect2.right)&& (rect2.left >= rect1.left))
1565 res.right = rect2.left;
1566 }
1567 return res;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301568}
1569
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001570void optimizeLayerRects(const hwc_display_contents_1_t *list) {
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301571 int i= (int)list->numHwLayers-2;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301572 while(i > 0) {
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301573 //see if there is no blending required.
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001574 //If it is opaque see if we can substract this region from below
1575 //layers.
radhakrishna4efbdd62014-11-03 13:19:27 +05301576 if(list->hwLayers[i].blending == HWC_BLENDING_NONE &&
1577 list->hwLayers[i].planeAlpha == 0xFF) {
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301578 int j= i-1;
1579 hwc_rect_t& topframe =
1580 (hwc_rect_t&)list->hwLayers[i].displayFrame;
1581 while(j >= 0) {
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301582 if(!needsScaling(&list->hwLayers[j])) {
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001583 hwc_layer_1_t* layer = (hwc_layer_1_t*)&list->hwLayers[j];
1584 hwc_rect_t& bottomframe = layer->displayFrame;
Jeykumar Sankaran071468b2014-01-14 17:21:49 -08001585 hwc_rect_t bottomCrop =
1586 integerizeSourceCrop(layer->sourceCropf);
Sushil Chauhanfda00fc2014-03-20 11:08:41 -07001587 int transform = (layer->flags & HWC_COLOR_FILL) ? 0 :
1588 layer->transform;
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001589
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001590 hwc_rect_t irect = getIntersection(bottomframe, topframe);
1591 if(isValidRect(irect)) {
Jeykumar Sankaran1b3da402013-12-04 16:22:34 -08001592 hwc_rect_t dest_rect;
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001593 //if intersection is valid rect, deduct it
Jeykumar Sankaran1b3da402013-12-04 16:22:34 -08001594 dest_rect = deductRect(bottomframe, irect);
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001595 qhwc::calculate_crop_rects(bottomCrop, bottomframe,
Jeykumar Sankaran1b3da402013-12-04 16:22:34 -08001596 dest_rect, transform);
Jeykumar Sankaran071468b2014-01-14 17:21:49 -08001597 //Update layer sourceCropf
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301598 layer->sourceCropf.left =(float)bottomCrop.left;
1599 layer->sourceCropf.top = (float)bottomCrop.top;
1600 layer->sourceCropf.right = (float)bottomCrop.right;
1601 layer->sourceCropf.bottom = (float)bottomCrop.bottom;
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08001602#ifdef QCOM_BSP
1603 //Update layer dirtyRect
1604 layer->dirtyRect = getIntersection(bottomCrop,
1605 layer->dirtyRect);
1606#endif
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001607 }
1608 }
1609 j--;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301610 }
1611 }
1612 i--;
1613 }
1614}
1615
Naseer Ahmed64b81212013-02-14 10:29:47 -05001616void getNonWormholeRegion(hwc_display_contents_1_t* list,
1617 hwc_rect_t& nwr)
1618{
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301619 size_t last = list->numHwLayers - 1;
Naseer Ahmed64b81212013-02-14 10:29:47 -05001620 hwc_rect_t fbDisplayFrame = list->hwLayers[last].displayFrame;
1621 //Initiliaze nwr to first frame
1622 nwr.left = list->hwLayers[0].displayFrame.left;
1623 nwr.top = list->hwLayers[0].displayFrame.top;
1624 nwr.right = list->hwLayers[0].displayFrame.right;
1625 nwr.bottom = list->hwLayers[0].displayFrame.bottom;
1626
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301627 for (size_t i = 1; i < last; i++) {
Naseer Ahmed64b81212013-02-14 10:29:47 -05001628 hwc_rect_t displayFrame = list->hwLayers[i].displayFrame;
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001629 nwr = getUnion(nwr, displayFrame);
Naseer Ahmed64b81212013-02-14 10:29:47 -05001630 }
1631
1632 //Intersect with the framebuffer
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001633 nwr = getIntersection(nwr, fbDisplayFrame);
Naseer Ahmed64b81212013-02-14 10:29:47 -05001634}
1635
Saurabh Shah747af1e2013-02-26 10:25:12 -08001636void closeAcquireFds(hwc_display_contents_1_t* list) {
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08001637 if(LIKELY(list)) {
1638 for(uint32_t i = 0; i < list->numHwLayers; i++) {
1639 //Close the acquireFenceFds
1640 //HWC_FRAMEBUFFER are -1 already by SF, rest we close.
1641 if(list->hwLayers[i].acquireFenceFd >= 0) {
1642 close(list->hwLayers[i].acquireFenceFd);
1643 list->hwLayers[i].acquireFenceFd = -1;
1644 }
1645 }
1646 //Writeback
1647 if(list->outbufAcquireFenceFd >= 0) {
1648 close(list->outbufAcquireFenceFd);
1649 list->outbufAcquireFenceFd = -1;
Saurabh Shah747af1e2013-02-26 10:25:12 -08001650 }
1651 }
1652}
1653
radhakrishnad750d002014-10-07 19:46:00 +05301654void hwc_sync_rotator(hwc_context_t *ctx, hwc_display_contents_1_t* list,
1655 int dpy) {
Naseer Ahmed099a6932013-09-09 14:25:20 -04001656 ATRACE_CALL();
Saurabh Shah23a813c2013-03-20 16:58:12 -07001657 //Send acquireFenceFds to rotator
Saurabh Shah23a813c2013-03-20 16:58:12 -07001658 for(uint32_t i = 0; i < ctx->mLayerRotMap[dpy]->getCount(); i++) {
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001659 int rotFd = ctx->mRotMgr->getRotDevFd();
1660 int rotReleaseFd = -1;
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001661 overlay::Rotator* currRot = ctx->mLayerRotMap[dpy]->getRot(i);
1662 hwc_layer_1_t* currLayer = ctx->mLayerRotMap[dpy]->getLayer(i);
1663 if((currRot == NULL) || (currLayer == NULL)) {
1664 continue;
1665 }
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001666 struct mdp_buf_sync rotData;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001667 memset(&rotData, 0, sizeof(rotData));
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001668 rotData.acq_fen_fd =
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001669 &currLayer->acquireFenceFd;
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001670 rotData.rel_fen_fd = &rotReleaseFd; //driver to populate this
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001671 rotData.session_id = currRot->getSessId();
Saurabh Shah25c04d32014-05-05 10:16:02 -07001672 if(currLayer->acquireFenceFd >= 0) {
1673 rotData.acq_fen_fd_cnt = 1; //1 ioctl call per rot session
1674 }
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001675 int ret = 0;
radhakrishnad750d002014-10-07 19:46:00 +05301676 if(not ctx->mLayerRotMap[dpy]->isRotCached(i))
Raj Kamalbd3bdc62014-08-05 18:52:49 +05301677 ret = ioctl(rotFd, MSMFB_BUFFER_SYNC, &rotData);
1678
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001679 if(ret < 0) {
1680 ALOGE("%s: ioctl MSMFB_BUFFER_SYNC failed for rot sync, err=%s",
1681 __FUNCTION__, strerror(errno));
Tatenda Chipeperekwaa4550ce2014-06-06 15:25:37 -07001682 close(rotReleaseFd);
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001683 } else {
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001684 close(currLayer->acquireFenceFd);
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001685 //For MDP to wait on.
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001686 currLayer->acquireFenceFd =
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001687 dup(rotReleaseFd);
1688 //A buffer is free to be used by producer as soon as its copied to
1689 //rotator
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001690 currLayer->releaseFenceFd =
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001691 rotReleaseFd;
1692 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001693 }
radhakrishnad750d002014-10-07 19:46:00 +05301694}
1695
1696int hwc_sync_mdss(hwc_context_t *ctx, hwc_display_contents_1_t *list, int dpy,
1697 bool isExtAnimating, int fd) {
1698 ATRACE_CALL();
1699 int ret = 0;
1700 int acquireFd[MAX_NUM_APP_LAYERS];
1701 int count = 0;
1702 int releaseFd = -1;
1703 int retireFd = -1;
1704 int fbFd = ctx->dpyAttr[dpy].fd;
1705
1706 struct mdp_buf_sync data;
1707 memset(&data, 0, sizeof(data));
1708 data.acq_fen_fd = acquireFd;
1709 data.rel_fen_fd = &releaseFd;
1710 data.retire_fen_fd = &retireFd;
1711 data.flags = MDP_BUF_SYNC_FLAG_RETIRE_FENCE;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001712
Balamurugan Thanikachalamf558c862014-01-31 18:23:20 +05301713 //Accumulate acquireFenceFds for MDP Overlays
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08001714 if(list->outbufAcquireFenceFd >= 0) {
1715 //Writeback output buffer
radhakrishnad750d002014-10-07 19:46:00 +05301716 acquireFd[count++] = list->outbufAcquireFenceFd;
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08001717 }
1718
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001719 for(uint32_t i = 0; i < list->numHwLayers; i++) {
Ramakant Singh0def28c2014-03-28 20:43:13 +05301720 if(((isAbcInUse(ctx)== true ) ||
1721 (list->hwLayers[i].compositionType == HWC_OVERLAY)) &&
Saurabh Shah23a813c2013-03-20 16:58:12 -07001722 list->hwLayers[i].acquireFenceFd >= 0) {
radhakrishnad750d002014-10-07 19:46:00 +05301723 // if ABC is enabled for more than one layer.
1724 // renderBufIndexforABC will work as FB.Hence
1725 // set the acquireFD from fd - which is coming from copybit
1726 if(fd >= 0 && (isAbcInUse(ctx) == true)) {
1727 if(ctx->listStats[dpy].renderBufIndexforABC ==(int32_t)i)
1728 acquireFd[count++] = fd;
1729 else
1730 continue;
1731 } else
1732 acquireFd[count++] = list->hwLayers[i].acquireFenceFd;
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001733 }
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001734 if(list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) {
radhakrishnad750d002014-10-07 19:46:00 +05301735 if(fd >= 0) {
1736 //set the acquireFD from fd - which is coming from c2d
1737 acquireFd[count++] = fd;
1738 // Buffer sync IOCTL should be async when using c2d fence
1739 data.flags &= ~MDP_BUF_SYNC_FLAG_WAIT;
1740 } else if(list->hwLayers[i].acquireFenceFd >= 0)
1741 acquireFd[count++] = list->hwLayers[i].acquireFenceFd;
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001742 }
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001743 }
1744
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001745 data.acq_fen_fd_cnt = count;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001746
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001747 //Waits for acquire fences, returns a release fence
radhakrishnad750d002014-10-07 19:46:00 +05301748 ret = ioctl(fbFd, MSMFB_BUFFER_SYNC, &data);
Saurabh Shah747af1e2013-02-26 10:25:12 -08001749
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001750 if(ret < 0) {
Ramkumar Radhakrishnanb32a0bc2013-04-11 17:57:32 -07001751 ALOGE("%s: ioctl MSMFB_BUFFER_SYNC failed, err=%s",
1752 __FUNCTION__, strerror(errno));
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301753 ALOGE("%s: acq_fen_fd_cnt=%d flags=%d fd=%d dpy=%d numHwLayers=%zu",
Ramkumar Radhakrishnanb32a0bc2013-04-11 17:57:32 -07001754 __FUNCTION__, data.acq_fen_fd_cnt, data.flags, fbFd,
1755 dpy, list->numHwLayers);
Tatenda Chipeperekwaa4550ce2014-06-06 15:25:37 -07001756 close(releaseFd);
1757 releaseFd = -1;
1758 close(retireFd);
1759 retireFd = -1;
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001760 }
Saurabh Shah747af1e2013-02-26 10:25:12 -08001761
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001762 for(uint32_t i = 0; i < list->numHwLayers; i++) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001763 if(list->hwLayers[i].compositionType == HWC_OVERLAY ||
Saurabh Shah74eff4d2014-03-28 16:33:13 -07001764#ifdef QCOM_BSP
Terence Hampsonc67b0372013-10-09 11:32:21 -04001765 list->hwLayers[i].compositionType == HWC_BLIT ||
Saurabh Shah74eff4d2014-03-28 16:33:13 -07001766#endif
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001767 list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) {
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001768 //Populate releaseFenceFds.
radhakrishnad750d002014-10-07 19:46:00 +05301769 if(isExtAnimating) {
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001770 // Release all the app layer fds immediately,
1771 // if animation is in progress.
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -07001772 list->hwLayers[i].releaseFenceFd = -1;
Naseer Ahmed330a2822014-03-05 11:57:23 -05001773 } else if(list->hwLayers[i].releaseFenceFd < 0 ) {
Saurabh Shah74eff4d2014-03-28 16:33:13 -07001774#ifdef QCOM_BSP
Zohaib Alam1bb65612013-09-28 03:38:20 -04001775 //If rotator has not already populated this field
Ramakant Singh0def28c2014-03-28 20:43:13 +05301776 // & if it's a not VPU layer
Ramakant Singh467759f2014-04-16 11:09:40 +05301777
1778 // if ABC is enabled for more than one layer
1779 if(fd >= 0 && (isAbcInUse(ctx) == true) &&
1780 ctx->listStats[dpy].renderBufIndexforABC !=(int32_t)i){
1781 list->hwLayers[i].releaseFenceFd = dup(fd);
1782 } else if((list->hwLayers[i].compositionType == HWC_BLIT)&&
1783 (isAbcInUse(ctx) == false)){
1784 //For Blit, the app layers should be released when the Blit
1785 //is complete. This fd was passed from copybit->draw
Balamurugan Thanikachalamf558c862014-01-31 18:23:20 +05301786 list->hwLayers[i].releaseFenceFd = dup(fd);
Saurabh Shah74eff4d2014-03-28 16:33:13 -07001787 } else
1788#endif
1789 {
Balamurugan Thanikachalamf558c862014-01-31 18:23:20 +05301790 list->hwLayers[i].releaseFenceFd = dup(releaseFd);
1791 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001792 }
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001793 }
1794 }
Saurabh Shah747af1e2013-02-26 10:25:12 -08001795
Sushil Chauhanfb8845c2014-07-22 12:42:07 -07001796 if (ctx->mCopyBit[dpy]) {
radhakrishnad750d002014-10-07 19:46:00 +05301797 if((!dpy && ctx->mPtorInfo.isActive()) or
1798 ctx->mMDP.version < qdutils::MDP_V4_0) {
Sushil Chauhandefd3522014-05-13 18:17:12 -07001799 ctx->mCopyBit[dpy]->setReleaseFd(releaseFd);
radhakrishnad750d002014-10-07 19:46:00 +05301800 }
Sushil Chauhandefd3522014-05-13 18:17:12 -07001801 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001802
Saurabh Shah23a813c2013-03-20 16:58:12 -07001803 //Signals when MDP finishes reading rotator buffers.
1804 ctx->mLayerRotMap[dpy]->setReleaseFd(releaseFd);
Arun Kumar K.R51835182013-11-19 11:20:28 -08001805 close(releaseFd);
1806 releaseFd = -1;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001807
radhakrishnad750d002014-10-07 19:46:00 +05301808 list->retireFenceFd = retireFd;
1809
1810 return ret;
1811}
1812
1813void hwc_sync_sz(hwc_context_t* ctx, hwc_display_contents_1_t* list, int dpy) {
1814 ATRACE_CALL();
1815 for(uint32_t i = 0; i < list->numHwLayers; i++) {
1816 list->hwLayers[i].releaseFenceFd = -1;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001817 }
radhakrishnad750d002014-10-07 19:46:00 +05301818
1819 if (ctx->mCopyBit[dpy]) {
1820 if((!dpy && ctx->mPtorInfo.isActive()) or
1821 ctx->mMDP.version < qdutils::MDP_V4_0) {
1822 ctx->mCopyBit[dpy]->setReleaseFd(-1);
1823 }
1824 }
1825
1826 ctx->mLayerRotMap[dpy]->setReleaseFd(-1);
1827
1828 list->retireFenceFd = -1;
1829}
1830
1831int hwc_sync(hwc_context_t *ctx, hwc_display_contents_1_t* list, int dpy,
1832 int fd) {
1833 ATRACE_CALL();
1834 int ret = 0;
1835
1836 bool isExtAnimating = false;
1837 if(dpy)
1838 isExtAnimating = ctx->listStats[dpy].isDisplayAnimating;
1839
1840 bool swapzero = false;
1841 char property[PROPERTY_VALUE_MAX];
1842 if(property_get("debug.egl.swapinterval", property, "1") > 0) {
1843 if(atoi(property) == 0)
1844 swapzero = true;
1845 }
1846
1847 if(swapzero) {
1848 hwc_sync_sz(ctx, list, dpy);
1849 } else {
1850 hwc_sync_rotator(ctx, list, dpy);
1851 ret = hwc_sync_mdss(ctx, list, dpy,
1852 isExtAnimating, fd);
1853 }
1854
1855 if(fd >= 0) {
1856 close(fd);
1857 fd = -1;
1858 }
1859
1860
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001861 return ret;
1862}
1863
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001864void setMdpFlags(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shahacf10202013-02-26 10:15:15 -08001865 ovutils::eMdpFlags &mdpFlags,
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001866 int rotDownscale, int transform) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001867 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shah220a30c2013-10-29 16:12:12 -07001868 MetaData_t *metadata = hnd ? (MetaData_t *)hnd->base_metadata : NULL;
Saurabh Shahacf10202013-02-26 10:15:15 -08001869
1870 if(layer->blending == HWC_BLENDING_PREMULT) {
1871 ovutils::setMdpFlags(mdpFlags,
1872 ovutils::OV_MDP_BLEND_FG_PREMULT);
1873 }
1874
Ramkumar Radhakrishnan4ec775f2014-07-23 17:43:18 -07001875 if(metadata && (metadata->operation & PP_PARAM_INTERLACED) &&
1876 metadata->interlaced) {
1877 ovutils::setMdpFlags(mdpFlags,
1878 ovutils::OV_MDP_DEINTERLACE);
1879 }
1880
1881 // Mark MDP flags with SECURE_OVERLAY_SESSION for driver
1882 if(isSecureBuffer(hnd)) {
1883 ovutils::setMdpFlags(mdpFlags,
1884 ovutils::OV_MDP_SECURE_OVERLAY_SESSION);
Justin Philipd6166602014-08-12 13:42:21 +05301885 ovutils::setMdpFlags(mdpFlags,
1886 ovutils::OV_MDP_SMP_FORCE_ALLOC);
1887 }
1888
1889 if(isProtectedBuffer(hnd)) {
1890 ovutils::setMdpFlags(mdpFlags,
1891 ovutils::OV_MDP_SMP_FORCE_ALLOC);
Saurabh Shahacf10202013-02-26 10:15:15 -08001892 }
1893
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -07001894 if(isSecureDisplayBuffer(hnd)) {
Ramkumar Radhakrishnan4ec775f2014-07-23 17:43:18 -07001895 // Mark MDP flags with SECURE_DISPLAY_OVERLAY_SESSION for driver
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -07001896 ovutils::setMdpFlags(mdpFlags,
1897 ovutils::OV_MDP_SECURE_DISPLAY_OVERLAY_SESSION);
1898 }
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001899
1900 //Pre-rotation will be used using rotator.
1901 if(has90Transform(layer) && isRotationDoable(ctx, hnd)) {
1902 ovutils::setMdpFlags(mdpFlags,
1903 ovutils::OV_MDP_SOURCE_ROTATED_90);
1904 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001905 //No 90 component and no rot-downscale then flips done by MDP
1906 //If we use rot then it might as well do flips
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001907 if(!(transform & HWC_TRANSFORM_ROT_90) && !rotDownscale) {
1908 if(transform & HWC_TRANSFORM_FLIP_H) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001909 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_FLIP_H);
1910 }
1911
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001912 if(transform & HWC_TRANSFORM_FLIP_V) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001913 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_FLIP_V);
1914 }
1915 }
Saurabh Shah5daeee52013-01-23 16:52:26 +08001916
1917 if(metadata &&
1918 ((metadata->operation & PP_PARAM_HSIC)
1919 || (metadata->operation & PP_PARAM_IGC)
1920 || (metadata->operation & PP_PARAM_SHARP2))) {
1921 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_PP_EN);
1922 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001923}
1924
Prabhanjan Kandulaa1d83012013-04-23 13:06:02 +05301925int configRotator(Rotator *rot, Whf& whf,
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001926 hwc_rect_t& crop, const eMdpFlags& mdpFlags,
radhakrishnab8e2c952015-06-04 16:09:16 +05301927 const eTransform& orient, const int& downscale,
1928 const uint32_t& frame_rate) {
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001929
Prabhanjan Kandulaa1d83012013-04-23 13:06:02 +05301930 // Fix alignments for TILED format
1931 if(whf.format == MDP_Y_CRCB_H2V2_TILE ||
1932 whf.format == MDP_Y_CBCR_H2V2_TILE) {
1933 whf.w = utils::alignup(whf.w, 64);
1934 whf.h = utils::alignup(whf.h, 32);
1935 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001936 rot->setSource(whf);
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001937
1938 if (qdutils::MDPVersion::getInstance().getMDPVersion() >=
1939 qdutils::MDSS_V5) {
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001940 Dim rotCrop(crop.left, crop.top, crop.right - crop.left,
1941 crop.bottom - crop.top);
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001942 rot->setCrop(rotCrop);
1943 }
1944
radhakrishnab8e2c952015-06-04 16:09:16 +05301945 rot->setFrameRate(frame_rate);
Saurabh Shahacf10202013-02-26 10:15:15 -08001946 rot->setFlags(mdpFlags);
1947 rot->setTransform(orient);
1948 rot->setDownscale(downscale);
1949 if(!rot->commit()) return -1;
1950 return 0;
1951}
1952
Saurabh Shahe2474082013-05-15 16:32:13 -07001953int configMdp(Overlay *ov, const PipeArgs& parg,
Saurabh Shahacf10202013-02-26 10:15:15 -08001954 const eTransform& orient, const hwc_rect_t& crop,
Saurabh Shah5daeee52013-01-23 16:52:26 +08001955 const hwc_rect_t& pos, const MetaData_t *metadata,
1956 const eDest& dest) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001957 ov->setSource(parg, dest);
1958 ov->setTransform(orient, dest);
1959
1960 int crop_w = crop.right - crop.left;
1961 int crop_h = crop.bottom - crop.top;
1962 Dim dcrop(crop.left, crop.top, crop_w, crop_h);
1963 ov->setCrop(dcrop, dest);
1964
1965 int posW = pos.right - pos.left;
1966 int posH = pos.bottom - pos.top;
1967 Dim position(pos.left, pos.top, posW, posH);
1968 ov->setPosition(position, dest);
1969
Saurabh Shah5daeee52013-01-23 16:52:26 +08001970 if (metadata)
1971 ov->setVisualParams(*metadata, dest);
1972
Saurabh Shahacf10202013-02-26 10:15:15 -08001973 if (!ov->commit(dest)) {
1974 return -1;
1975 }
1976 return 0;
1977}
1978
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001979int configColorLayer(hwc_context_t *ctx, hwc_layer_1_t *layer,
1980 const int& dpy, eMdpFlags& mdpFlags, eZorder& z,
Saurabh Shah2c8ad052014-08-15 13:27:46 -07001981 const eDest& dest) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001982
1983 hwc_rect_t dst = layer->displayFrame;
1984 trimLayer(ctx, dpy, 0, dst, dst);
1985
1986 int w = ctx->dpyAttr[dpy].xres;
1987 int h = ctx->dpyAttr[dpy].yres;
1988 int dst_w = dst.right - dst.left;
1989 int dst_h = dst.bottom - dst.top;
1990 uint32_t color = layer->transform;
Sushil Chauhan65e26302015-01-14 10:48:57 -08001991 Whf whf(w, h, getMdpFormat(HAL_PIXEL_FORMAT_RGBA_8888));
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001992
Sushil Chauhanf10c5232013-12-19 10:35:54 -08001993 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_SOLID_FILL);
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001994 if (layer->blending == HWC_BLENDING_PREMULT)
1995 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_BLEND_FG_PREMULT);
1996
Saurabh Shah2c8ad052014-08-15 13:27:46 -07001997 PipeArgs parg(mdpFlags, whf, z, static_cast<eRotFlags>(0),
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001998 layer->planeAlpha,
1999 (ovutils::eBlending) getBlending(layer->blending));
2000
2001 // Configure MDP pipe for Color layer
2002 Dim pos(dst.left, dst.top, dst_w, dst_h);
2003 ctx->mOverlay->setSource(parg, dest);
2004 ctx->mOverlay->setColor(color, dest);
2005 ctx->mOverlay->setTransform(0, dest);
2006 ctx->mOverlay->setCrop(pos, dest);
2007 ctx->mOverlay->setPosition(pos, dest);
2008
2009 if (!ctx->mOverlay->commit(dest)) {
2010 ALOGE("%s: Configure color layer failed!", __FUNCTION__);
2011 return -1;
2012 }
2013 return 0;
2014}
2015
Saurabh Shahe2474082013-05-15 16:32:13 -07002016void updateSource(eTransform& orient, Whf& whf,
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07002017 hwc_rect_t& crop, Rotator *rot) {
2018 Dim transformedCrop(crop.left, crop.top,
Saurabh Shahacf10202013-02-26 10:15:15 -08002019 crop.right - crop.left,
2020 crop.bottom - crop.top);
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07002021 if (qdutils::MDPVersion::getInstance().getMDPVersion() >=
2022 qdutils::MDSS_V5) {
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07002023 //B-family rotator internally could modify destination dimensions if
2024 //downscaling is supported
2025 whf = rot->getDstWhf();
2026 transformedCrop = rot->getDstDimensions();
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07002027 } else {
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07002028 //A-family rotator rotates entire buffer irrespective of crop, forcing
2029 //us to recompute the crop based on transform
2030 orient = static_cast<eTransform>(ovutils::getMdpOrient(orient));
2031 preRotateSource(orient, whf, transformedCrop);
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07002032 }
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07002033
2034 crop.left = transformedCrop.x;
2035 crop.top = transformedCrop.y;
2036 crop.right = transformedCrop.x + transformedCrop.w;
2037 crop.bottom = transformedCrop.y + transformedCrop.h;
Saurabh Shahacf10202013-02-26 10:15:15 -08002038}
2039
Arun Kumar K.R00b84792015-03-27 11:28:36 -07002040bool configHwCursor(const int fd, int dpy, hwc_layer_1_t* layer) {
2041 if(dpy > HWC_DISPLAY_PRIMARY) {
2042 // HWCursor not supported on secondary displays
2043 return false;
2044 }
2045 private_handle_t *hnd = (private_handle_t *)layer->handle;
2046 hwc_rect dst = layer->displayFrame;
2047 hwc_rect src = integerizeSourceCrop(layer->sourceCropf);
2048 int srcW = src.right - src.left;
2049 int srcH = src.bottom - src.top;
2050 int dstW = dst.right - dst.left;
2051 int dstH = dst.bottom - dst.top;
2052
2053 Whf whf(getWidth(hnd), getHeight(hnd), hnd->format);
2054 Dim crop(src.left, src.top, srcW, srcH);
2055 Dim dest(dst.left, dst.top, dstW, dstH);
2056
2057 ovutils::PipeArgs pargs(ovutils::OV_MDP_FLAGS_NONE,
2058 whf,
2059 Z_SYSTEM_ALLOC,
2060 ovutils::ROT_FLAGS_NONE,
2061 layer->planeAlpha,
2062 (ovutils::eBlending)
2063 getBlending(layer->blending));
2064
2065 ALOGD_IF(HWC_UTILS_DEBUG, "%s: CursorInfo: w = %d h = %d "
2066 "crop [%d, %d, %d, %d] dst [%d, %d, %d, %d]", __FUNCTION__,
2067 getWidth(hnd), getHeight(hnd), src.left, src.top, srcW, srcH,
2068 dst.left, dst.top, dstW, dstH);
2069
2070 return HWCursor::getInstance()->config(fd, (void*)hnd->base, pargs,
2071 crop, dest);
2072}
2073
2074void freeHwCursor(const int fd, int dpy) {
2075 if (dpy == HWC_DISPLAY_PRIMARY) {
2076 HWCursor::getInstance()->free(fd);
2077 }
2078}
2079
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002080int getRotDownscale(hwc_context_t *ctx, const hwc_layer_1_t *layer) {
2081 if(not qdutils::MDPVersion::getInstance().isRotDownscaleEnabled()) {
2082 return 0;
2083 }
2084
2085 int downscale = 0;
2086 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
2087 hwc_rect_t dst = layer->displayFrame;
2088 private_handle_t *hnd = (private_handle_t *)layer->handle;
2089
2090 if(not hnd) {
2091 return 0;
2092 }
2093
2094 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
2095 bool isInterlaced = metadata && (metadata->operation & PP_PARAM_INTERLACED)
2096 && metadata->interlaced;
2097 int transform = layer->transform;
Sushil Chauhan65e26302015-01-14 10:48:57 -08002098 uint32_t format = ovutils::getMdpFormat(hnd->format, hnd->flags);
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002099
2100 if(isYuvBuffer(hnd)) {
2101 if(ctx->mMDP.version >= qdutils::MDP_V4_2 &&
2102 ctx->mMDP.version < qdutils::MDSS_V5) {
2103 downscale = Rotator::getDownscaleFactor(crop.right - crop.left,
2104 crop.bottom - crop.top, dst.right - dst.left,
2105 dst.bottom - dst.top, format, isInterlaced);
2106 } else {
2107 Dim adjCrop(crop.left, crop.top, crop.right - crop.left,
2108 crop.bottom - crop.top);
2109 Dim pos(dst.left, dst.top, dst.right - dst.left,
2110 dst.bottom - dst.top);
2111 if(transform & HAL_TRANSFORM_ROT_90) {
2112 swap(adjCrop.w, adjCrop.h);
2113 }
2114 downscale = Rotator::getDownscaleFactor(adjCrop.w, adjCrop.h, pos.w,
2115 pos.h, format, isInterlaced);
2116 }
2117 }
2118 return downscale;
2119}
2120
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002121bool isZoomModeEnabled(hwc_rect_t crop) {
2122 // This does not work for zooming in top left corner of the image
2123 return(crop.top > 0 || crop.left > 0);
2124}
2125
2126void updateCropAIVVideoMode(hwc_context_t *ctx, hwc_rect_t& crop, int dpy) {
2127 ALOGD_IF(HWC_UTILS_DEBUG, "dpy %d Source crop [%d %d %d %d]", dpy,
2128 crop.left, crop.top, crop.right, crop.bottom);
2129 if(isZoomModeEnabled(crop)) {
2130 Dim srcCrop(crop.left, crop.top,
2131 crop.right - crop.left,
2132 crop.bottom - crop.top);
2133 int extW = ctx->dpyAttr[dpy].xres;
2134 int extH = ctx->dpyAttr[dpy].yres;
2135 //Crop the original video in order to fit external display aspect ratio
2136 if(srcCrop.w * extH < extW * srcCrop.h) {
2137 int offset = (srcCrop.h - ((srcCrop.w * extH) / extW)) / 2;
2138 crop.top += offset;
2139 crop.bottom -= offset;
2140 } else {
2141 int offset = (srcCrop.w - ((extW * srcCrop.h) / extH)) / 2;
2142 crop.left += offset;
2143 crop.right -= offset;
2144 }
2145 ALOGD_IF(HWC_UTILS_DEBUG, "External Resolution [%d %d] dpy %d Modified"
2146 " source crop [%d %d %d %d]", extW, extH, dpy,
2147 crop.left, crop.top, crop.right, crop.bottom);
2148 }
2149}
2150
2151void updateDestAIVVideoMode(hwc_context_t *ctx, hwc_rect_t crop,
2152 hwc_rect_t& dst, int dpy) {
2153 ALOGD_IF(HWC_UTILS_DEBUG, "dpy %d Destination position [%d %d %d %d]", dpy,
2154 dst.left, dst.top, dst.right, dst.bottom);
2155 Dim srcCrop(crop.left, crop.top,
2156 crop.right - crop.left,
2157 crop.bottom - crop.top);
2158 int extW = ctx->dpyAttr[dpy].xres;
2159 int extH = ctx->dpyAttr[dpy].yres;
2160 // Set the destination coordinates of external display to full screen,
Ramkumar Radhakrishnan812999a2014-09-11 21:42:07 -07002161 // when zoom in mode is enabled or the ratio between video aspect ratio
2162 // and external display aspect ratio is below the minimum tolerance level
2163 // and above maximum tolerance level
2164 float videoAspectRatio = ((float)srcCrop.w / (float)srcCrop.h);
2165 float extDisplayAspectRatio = ((float)extW / (float)extH);
2166 float videoToExternalRatio = videoAspectRatio / extDisplayAspectRatio;
2167 if((fabs(1.0f - videoToExternalRatio) <= ctx->mAspectRatioToleranceLevel) ||
2168 (isZoomModeEnabled(crop))) {
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002169 dst.left = 0;
2170 dst.top = 0;
2171 dst.right = extW;
2172 dst.bottom = extH;
2173 }
2174 ALOGD_IF(HWC_UTILS_DEBUG, "External Resolution [%d %d] dpy %d Modified"
2175 " Destination position [%d %d %d %d] Source crop [%d %d %d %d]",
2176 extW, extH, dpy, dst.left, dst.top, dst.right, dst.bottom,
2177 crop.left, crop.top, crop.right, crop.bottom);
2178}
2179
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07002180void updateCoordinates(hwc_context_t *ctx, hwc_rect_t& crop,
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002181 hwc_rect_t& dst, int dpy) {
2182 updateCropAIVVideoMode(ctx, crop, dpy);
2183 updateDestAIVVideoMode(ctx, crop, dst, dpy);
2184}
2185
Saurabh Shah88e4d272013-09-03 13:31:29 -07002186int configureNonSplit(hwc_context_t *ctx, hwc_layer_1_t *layer,
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07002187 const int& dpy, eMdpFlags& mdpFlags, eZorder& z,
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002188 const eDest& dest, Rotator **rot) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002189
2190 private_handle_t *hnd = (private_handle_t *)layer->handle;
Sushil Chauhan897a9c32013-07-18 11:09:55 -07002191
Saurabh Shahacf10202013-02-26 10:15:15 -08002192 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07002193 if (layer->flags & HWC_COLOR_FILL) {
2194 // Configure Color layer
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002195 return configColorLayer(ctx, layer, dpy, mdpFlags, z, dest);
Sushil Chauhan897a9c32013-07-18 11:09:55 -07002196 }
Saurabh Shahacf10202013-02-26 10:15:15 -08002197 ALOGE("%s: layer handle is NULL", __FUNCTION__);
2198 return -1;
2199 }
2200
Saurabh Shah5daeee52013-01-23 16:52:26 +08002201 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
2202
Saurabh Shah62e1d732013-09-17 10:44:05 -07002203 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shahacf10202013-02-26 10:15:15 -08002204 hwc_rect_t dst = layer->displayFrame;
2205 int transform = layer->transform;
2206 eTransform orient = static_cast<eTransform>(transform);
Saurabh Shahacf10202013-02-26 10:15:15 -08002207 int rotFlags = ovutils::ROT_FLAGS_NONE;
Sushil Chauhan65e26302015-01-14 10:48:57 -08002208 uint32_t format = ovutils::getMdpFormat(hnd->format, hnd->flags);
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05302209 Whf whf(getWidth(hnd), getHeight(hnd), format, (uint32_t)hnd->size);
Zohaib Alam1bb65612013-09-28 03:38:20 -04002210
Sushil Chauhan1f6d68f2013-10-11 11:49:35 -07002211 // Handle R/B swap
2212 if (layer->flags & HWC_FORMAT_RB_SWAP) {
2213 if (hnd->format == HAL_PIXEL_FORMAT_RGBA_8888)
2214 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRA_8888);
2215 else if (hnd->format == HAL_PIXEL_FORMAT_RGBX_8888)
2216 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRX_8888);
2217 }
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002218 // update source crop and destination position of AIV video layer.
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07002219 if(ctx->listStats[dpy].mAIVVideoMode && isYuvBuffer(hnd)) {
2220 updateCoordinates(ctx, crop, dst, dpy);
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002221 }
Ramkumar Radhakrishnan939a9e72013-12-04 18:30:18 -08002222 calcExtDisplayPosition(ctx, hnd, dpy, crop, dst, transform, orient);
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002223 int downscale = getRotDownscale(ctx, layer);
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08002224 setMdpFlags(ctx, layer, mdpFlags, downscale, transform);
Saurabh Shahacf10202013-02-26 10:15:15 -08002225
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08002226 //if 90 component or downscale, use rot
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002227 if((has90Transform(layer) or downscale) and isRotationDoable(ctx, hnd)) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002228 *rot = ctx->mRotMgr->getNext();
2229 if(*rot == NULL) return -1;
Saurabh Shah39240c92014-03-31 10:31:42 -07002230 ctx->mLayerRotMap[dpy]->add(layer, *rot);
Saurabh Shahcd018352014-11-11 13:54:19 -08002231 BwcPM::setBwc(ctx, dpy, hnd, crop, dst, transform, downscale,
2232 mdpFlags);
radhakrishnab8e2c952015-06-04 16:09:16 +05302233 uint32_t frame_rate = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].refreshRate;
2234 if(!dpy && !isSecondaryConnected(ctx)) {
2235 if(metadata && (metadata->operation & UPDATE_REFRESH_RATE))
2236 frame_rate = metadata->refreshrate;
2237 }
Saurabh Shahacf10202013-02-26 10:15:15 -08002238 //Configure rotator for pre-rotation
radhakrishnab8e2c952015-06-04 16:09:16 +05302239 if(configRotator(*rot, whf, crop, mdpFlags, orient, downscale,
2240 frame_rate) < 0) {
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07002241 ALOGE("%s: configRotator failed!", __FUNCTION__);
Saurabh Shahacf10202013-02-26 10:15:15 -08002242 return -1;
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07002243 }
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07002244 updateSource(orient, whf, crop, *rot);
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002245 rotFlags |= ROT_PREROTATED;
Saurabh Shahacf10202013-02-26 10:15:15 -08002246 }
2247
Saurabh Shah76fd6552013-03-14 14:45:38 -07002248 //For the mdp, since either we are pre-rotating or MDP does flips
2249 orient = OVERLAY_TRANSFORM_0;
2250 transform = 0;
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002251 PipeArgs parg(mdpFlags, whf, z,
Naseer Ahmed522ce662013-03-18 20:14:05 -04002252 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2253 (ovutils::eBlending) getBlending(layer->blending));
2254
Saurabh Shah5daeee52013-01-23 16:52:26 +08002255 if(configMdp(ctx->mOverlay, parg, orient, crop, dst, metadata, dest) < 0) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002256 ALOGE("%s: commit failed for low res panel", __FUNCTION__);
2257 return -1;
2258 }
2259 return 0;
2260}
2261
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002262//Helper to 1) Ensure crops dont have gaps 2) Ensure L and W are even
Sushil Chauhan15a2ea62013-09-04 18:28:36 -07002263void sanitizeSourceCrop(hwc_rect_t& cropL, hwc_rect_t& cropR,
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002264 private_handle_t *hnd) {
2265 if(cropL.right - cropL.left) {
2266 if(isYuvBuffer(hnd)) {
2267 //Always safe to even down left
2268 ovutils::even_floor(cropL.left);
2269 //If right is even, automatically width is even, since left is
2270 //already even
2271 ovutils::even_floor(cropL.right);
2272 }
2273 //Make sure there are no gaps between left and right splits if the layer
2274 //is spread across BOTH halves
2275 if(cropR.right - cropR.left) {
2276 cropR.left = cropL.right;
2277 }
2278 }
2279
2280 if(cropR.right - cropR.left) {
2281 if(isYuvBuffer(hnd)) {
2282 //Always safe to even down left
2283 ovutils::even_floor(cropR.left);
2284 //If right is even, automatically width is even, since left is
2285 //already even
2286 ovutils::even_floor(cropR.right);
2287 }
2288 }
2289}
2290
Saurabh Shah88e4d272013-09-03 13:31:29 -07002291int configureSplit(hwc_context_t *ctx, hwc_layer_1_t *layer,
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07002292 const int& dpy, eMdpFlags& mdpFlagsL, eZorder& z,
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002293 const eDest& lDest, const eDest& rDest,
Saurabh Shahacf10202013-02-26 10:15:15 -08002294 Rotator **rot) {
2295 private_handle_t *hnd = (private_handle_t *)layer->handle;
2296 if(!hnd) {
2297 ALOGE("%s: layer handle is NULL", __FUNCTION__);
2298 return -1;
2299 }
2300
Saurabh Shah5daeee52013-01-23 16:52:26 +08002301 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
2302
Saurabh Shahacf10202013-02-26 10:15:15 -08002303 int hw_w = ctx->dpyAttr[dpy].xres;
2304 int hw_h = ctx->dpyAttr[dpy].yres;
Saurabh Shah62e1d732013-09-17 10:44:05 -07002305 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shahacf10202013-02-26 10:15:15 -08002306 hwc_rect_t dst = layer->displayFrame;
2307 int transform = layer->transform;
2308 eTransform orient = static_cast<eTransform>(transform);
Saurabh Shahacf10202013-02-26 10:15:15 -08002309 int rotFlags = ROT_FLAGS_NONE;
Sushil Chauhan65e26302015-01-14 10:48:57 -08002310 uint32_t format = ovutils::getMdpFormat(hnd->format, hnd->flags);
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05302311 Whf whf(getWidth(hnd), getHeight(hnd), format, (uint32_t)hnd->size);
Zohaib Alam1bb65612013-09-28 03:38:20 -04002312
Sushil Chauhan1f6d68f2013-10-11 11:49:35 -07002313 // Handle R/B swap
2314 if (layer->flags & HWC_FORMAT_RB_SWAP) {
2315 if (hnd->format == HAL_PIXEL_FORMAT_RGBA_8888)
2316 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRA_8888);
2317 else if (hnd->format == HAL_PIXEL_FORMAT_RGBX_8888)
2318 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRX_8888);
2319 }
2320
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002321 // update source crop and destination position of AIV video layer.
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07002322 if(ctx->listStats[dpy].mAIVVideoMode && isYuvBuffer(hnd)) {
2323 updateCoordinates(ctx, crop, dst, dpy);
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002324 }
2325
2326 /* Calculate the external display position based on MDP downscale,
Ramkumar Radhakrishnana61a0da2014-03-03 14:46:21 -08002327 ActionSafe, and extorientation features. */
2328 calcExtDisplayPosition(ctx, hnd, dpy, crop, dst, transform, orient);
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002329 int downscale = getRotDownscale(ctx, layer);
2330 setMdpFlags(ctx, layer, mdpFlagsL, downscale, transform);
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002331
2332 if(lDest != OV_INVALID && rDest != OV_INVALID) {
2333 //Enable overfetch
2334 setMdpFlags(mdpFlagsL, OV_MDSS_MDP_DUAL_PIPE);
2335 }
2336
Saurabh Shaha9da08f2013-07-03 13:27:53 -07002337 //Will do something only if feature enabled and conditions suitable
2338 //hollow call otherwise
2339 if(ctx->mAD->prepare(ctx, crop, whf, hnd)) {
2340 overlay::Writeback *wb = overlay::Writeback::getInstance();
2341 whf.format = wb->getOutputFormat();
2342 }
2343
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002344 if((has90Transform(layer) or downscale) and isRotationDoable(ctx, hnd)) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002345 (*rot) = ctx->mRotMgr->getNext();
2346 if((*rot) == NULL) return -1;
Saurabh Shah39240c92014-03-31 10:31:42 -07002347 ctx->mLayerRotMap[dpy]->add(layer, *rot);
radhakrishnab8e2c952015-06-04 16:09:16 +05302348 uint32_t frame_rate = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].refreshRate;
2349 if(!dpy && !isSecondaryConnected(ctx)) {
2350 if(metadata && (metadata->operation & UPDATE_REFRESH_RATE))
2351 frame_rate = metadata->refreshrate;
2352 }
Saurabh Shahacf10202013-02-26 10:15:15 -08002353 //Configure rotator for pre-rotation
radhakrishnab8e2c952015-06-04 16:09:16 +05302354 if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale,
2355 frame_rate) < 0) {
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07002356 ALOGE("%s: configRotator failed!", __FUNCTION__);
Saurabh Shahacf10202013-02-26 10:15:15 -08002357 return -1;
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07002358 }
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07002359 updateSource(orient, whf, crop, *rot);
Saurabh Shahacf10202013-02-26 10:15:15 -08002360 rotFlags |= ROT_PREROTATED;
2361 }
2362
2363 eMdpFlags mdpFlagsR = mdpFlagsL;
2364 setMdpFlags(mdpFlagsR, OV_MDSS_MDP_RIGHT_MIXER);
2365
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002366 hwc_rect_t tmp_cropL = {0}, tmp_dstL = {0};
2367 hwc_rect_t tmp_cropR = {0}, tmp_dstR = {0};
Saurabh Shahacf10202013-02-26 10:15:15 -08002368
Saurabh Shah07a8ca82013-08-06 18:45:42 -07002369 const int lSplit = getLeftSplit(ctx, dpy);
2370
Jeykumar Sankaran8b40b432014-05-30 23:26:59 -07002371 // Calculate Left rects
2372 if(dst.left < lSplit) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002373 tmp_cropL = crop;
2374 tmp_dstL = dst;
Saurabh Shah67a38c32013-06-10 16:23:15 -07002375 hwc_rect_t scissor = {0, 0, lSplit, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -08002376 scissor = getIntersection(ctx->mViewFrame[dpy], scissor);
Saurabh Shahacf10202013-02-26 10:15:15 -08002377 qhwc::calculate_crop_rects(tmp_cropL, tmp_dstL, scissor, 0);
2378 }
Jeykumar Sankaran8b40b432014-05-30 23:26:59 -07002379
2380 // Calculate Right rects
2381 if(dst.right > lSplit) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002382 tmp_cropR = crop;
2383 tmp_dstR = dst;
Saurabh Shah67a38c32013-06-10 16:23:15 -07002384 hwc_rect_t scissor = {lSplit, 0, hw_w, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -08002385 scissor = getIntersection(ctx->mViewFrame[dpy], scissor);
Saurabh Shahacf10202013-02-26 10:15:15 -08002386 qhwc::calculate_crop_rects(tmp_cropR, tmp_dstR, scissor, 0);
2387 }
2388
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002389 sanitizeSourceCrop(tmp_cropL, tmp_cropR, hnd);
2390
Saurabh Shah94d62362013-07-02 10:58:48 -07002391 //When buffer is H-flipped, contents of mixer config also needs to swapped
Saurabh Shahacf10202013-02-26 10:15:15 -08002392 //Not needed if the layer is confined to one half of the screen.
2393 //If rotator has been used then it has also done the flips, so ignore them.
Jeykumar Sankaran8b40b432014-05-30 23:26:59 -07002394 if((orient & OVERLAY_TRANSFORM_FLIP_H) && (dst.left < lSplit) &&
2395 (dst.right > lSplit) && (*rot) == NULL) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002396 hwc_rect_t new_cropR;
2397 new_cropR.left = tmp_cropL.left;
2398 new_cropR.right = new_cropR.left + (tmp_cropR.right - tmp_cropR.left);
2399
2400 hwc_rect_t new_cropL;
2401 new_cropL.left = new_cropR.right;
2402 new_cropL.right = tmp_cropR.right;
2403
2404 tmp_cropL.left = new_cropL.left;
2405 tmp_cropL.right = new_cropL.right;
2406
2407 tmp_cropR.left = new_cropR.left;
2408 tmp_cropR.right = new_cropR.right;
2409
2410 }
2411
Saurabh Shah76fd6552013-03-14 14:45:38 -07002412 //For the mdp, since either we are pre-rotating or MDP does flips
2413 orient = OVERLAY_TRANSFORM_0;
2414 transform = 0;
2415
Saurabh Shahacf10202013-02-26 10:15:15 -08002416 //configure left mixer
2417 if(lDest != OV_INVALID) {
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002418 PipeArgs pargL(mdpFlagsL, whf, z,
Naseer Ahmed522ce662013-03-18 20:14:05 -04002419 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2420 (ovutils::eBlending) getBlending(layer->blending));
2421
Saurabh Shahacf10202013-02-26 10:15:15 -08002422 if(configMdp(ctx->mOverlay, pargL, orient,
Saurabh Shah5daeee52013-01-23 16:52:26 +08002423 tmp_cropL, tmp_dstL, metadata, lDest) < 0) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002424 ALOGE("%s: commit failed for left mixer config", __FUNCTION__);
2425 return -1;
2426 }
2427 }
2428
2429 //configure right mixer
2430 if(rDest != OV_INVALID) {
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002431 PipeArgs pargR(mdpFlagsR, whf, z,
Naseer Ahmed522ce662013-03-18 20:14:05 -04002432 static_cast<eRotFlags>(rotFlags),
2433 layer->planeAlpha,
2434 (ovutils::eBlending) getBlending(layer->blending));
Saurabh Shah67a38c32013-06-10 16:23:15 -07002435 tmp_dstR.right = tmp_dstR.right - lSplit;
2436 tmp_dstR.left = tmp_dstR.left - lSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08002437 if(configMdp(ctx->mOverlay, pargR, orient,
Saurabh Shah5daeee52013-01-23 16:52:26 +08002438 tmp_cropR, tmp_dstR, metadata, rDest) < 0) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002439 ALOGE("%s: commit failed for right mixer config", __FUNCTION__);
2440 return -1;
2441 }
2442 }
2443
2444 return 0;
2445}
Arun Kumar K.Ra2978452013-02-07 01:34:24 -08002446
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -05002447int configure3DVideo(hwc_context_t *ctx, hwc_layer_1_t *layer,
2448 const int& dpy, eMdpFlags& mdpFlagsL, eZorder& z,
2449 const eDest& lDest, const eDest& rDest,
2450 Rotator **rot) {
2451 private_handle_t *hnd = (private_handle_t *)layer->handle;
2452 if(!hnd) {
2453 ALOGE("%s: layer handle is NULL", __FUNCTION__);
2454 return -1;
2455 }
2456 //Both pipes are configured to the same mixer
2457 eZorder lz = z;
2458 eZorder rz = (eZorder)(z + 1);
2459
2460 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
2461
2462 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
2463 hwc_rect_t dst = layer->displayFrame;
2464 int transform = layer->transform;
2465 eTransform orient = static_cast<eTransform>(transform);
2466 int rotFlags = ROT_FLAGS_NONE;
2467 uint32_t format = ovutils::getMdpFormat(hnd->format, hnd->flags);
2468 Whf whf(getWidth(hnd), getHeight(hnd), format, (uint32_t)hnd->size);
2469
2470 int downscale = getRotDownscale(ctx, layer);
2471 setMdpFlags(ctx, layer, mdpFlagsL, downscale, transform);
2472
2473 //XXX: Check if rotation is supported and valid for 3D
2474 if((has90Transform(layer) or downscale) and isRotationDoable(ctx, hnd)) {
2475 (*rot) = ctx->mRotMgr->getNext();
2476 if((*rot) == NULL) return -1;
2477 ctx->mLayerRotMap[dpy]->add(layer, *rot);
radhakrishnab8e2c952015-06-04 16:09:16 +05302478 uint32_t frame_rate = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].refreshRate;
2479 if(!dpy && !isSecondaryConnected(ctx)) {
2480 if(metadata && (metadata->operation & UPDATE_REFRESH_RATE))
2481 frame_rate = metadata->refreshrate;
2482 }
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -05002483 //Configure rotator for pre-rotation
radhakrishnab8e2c952015-06-04 16:09:16 +05302484 if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale,
2485 frame_rate) < 0) {
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -05002486 ALOGE("%s: configRotator failed!", __FUNCTION__);
2487 return -1;
2488 }
2489 updateSource(orient, whf, crop, *rot);
2490 rotFlags |= ROT_PREROTATED;
2491 }
2492
2493 eMdpFlags mdpFlagsR = mdpFlagsL;
2494
2495 hwc_rect_t cropL = crop, dstL = dst;
2496 hwc_rect_t cropR = crop, dstR = dst;
2497 int hw_w = ctx->dpyAttr[dpy].xres;
2498 int hw_h = ctx->dpyAttr[dpy].yres;
2499
2500 if(get3DFormat(hnd) == HAL_3D_SIDE_BY_SIDE_L_R ||
2501 get3DFormat(hnd) == HAL_3D_SIDE_BY_SIDE_R_L) {
2502 // Calculate Left rects
2503 // XXX: This assumes crop.right/2 is the center point of the video
2504 cropL.right = crop.right/2;
2505 dstL.left = dst.left/2;
2506 dstL.right = dst.right/2;
2507
2508 // Calculate Right rects
2509 cropR.left = crop.right/2;
2510 dstR.left = hw_w/2 + dst.left/2;
2511 dstR.right = hw_w/2 + dst.right/2;
2512 } else if(get3DFormat(hnd) == HAL_3D_TOP_BOTTOM) {
2513 // Calculate Left rects
2514 cropL.bottom = crop.bottom/2;
2515 dstL.top = dst.top/2;
2516 dstL.bottom = dst.bottom/2;
2517
2518 // Calculate Right rects
2519 cropR.top = crop.bottom/2;
2520 dstR.top = hw_h/2 + dst.top/2;
2521 dstR.bottom = hw_h/2 + dst.bottom/2;
2522 } else {
2523 ALOGE("%s: Unsupported 3D mode ", __FUNCTION__);
2524 return -1;
2525 }
2526
2527 //For the mdp, since either we are pre-rotating or MDP does flips
2528 orient = OVERLAY_TRANSFORM_0;
2529 transform = 0;
2530
2531 //configure left pipe
2532 if(lDest != OV_INVALID) {
2533 PipeArgs pargL(mdpFlagsL, whf, lz,
2534 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2535 (ovutils::eBlending) getBlending(layer->blending));
2536
2537 if(configMdp(ctx->mOverlay, pargL, orient,
2538 cropL, dstL, metadata, lDest) < 0) {
2539 ALOGE("%s: commit failed for left mixer config", __FUNCTION__);
2540 return -1;
2541 }
2542 }
2543
2544 //configure right pipe
2545 if(rDest != OV_INVALID) {
2546 PipeArgs pargR(mdpFlagsR, whf, rz,
2547 static_cast<eRotFlags>(rotFlags),
2548 layer->planeAlpha,
2549 (ovutils::eBlending) getBlending(layer->blending));
2550 if(configMdp(ctx->mOverlay, pargR, orient,
2551 cropR, dstR, metadata, rDest) < 0) {
2552 ALOGE("%s: commit failed for right mixer config", __FUNCTION__);
2553 return -1;
2554 }
2555 }
2556
2557 return 0;
2558}
2559
radhakrishnac9a67412013-09-25 17:40:42 +05302560int configureSourceSplit(hwc_context_t *ctx, hwc_layer_1_t *layer,
2561 const int& dpy, eMdpFlags& mdpFlagsL, eZorder& z,
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002562 const eDest& lDest, const eDest& rDest,
radhakrishnac9a67412013-09-25 17:40:42 +05302563 Rotator **rot) {
2564 private_handle_t *hnd = (private_handle_t *)layer->handle;
2565 if(!hnd) {
2566 ALOGE("%s: layer handle is NULL", __FUNCTION__);
2567 return -1;
2568 }
2569
2570 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
2571
radhakrishnac9a67412013-09-25 17:40:42 +05302572 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);;
2573 hwc_rect_t dst = layer->displayFrame;
2574 int transform = layer->transform;
2575 eTransform orient = static_cast<eTransform>(transform);
2576 const int downscale = 0;
2577 int rotFlags = ROT_FLAGS_NONE;
2578 //Splitting only YUV layer on primary panel needs different zorders
2579 //for both layers as both the layers are configured to single mixer
2580 eZorder lz = z;
2581 eZorder rz = (eZorder)(z + 1);
2582
2583 Whf whf(getWidth(hnd), getHeight(hnd),
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05302584 getMdpFormat(hnd->format), (uint32_t)hnd->size);
radhakrishnac9a67412013-09-25 17:40:42 +05302585
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002586 // update source crop and destination position of AIV video layer.
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07002587 if(ctx->listStats[dpy].mAIVVideoMode && isYuvBuffer(hnd)) {
2588 updateCoordinates(ctx, crop, dst, dpy);
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002589 }
2590
Ramkumar Radhakrishnan8ab3f5d2014-02-20 19:37:15 -08002591 /* Calculate the external display position based on MDP downscale,
2592 ActionSafe, and extorientation features. */
2593 calcExtDisplayPosition(ctx, hnd, dpy, crop, dst, transform, orient);
2594
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08002595 setMdpFlags(ctx, layer, mdpFlagsL, 0, transform);
radhakrishnac9a67412013-09-25 17:40:42 +05302596 trimLayer(ctx, dpy, transform, crop, dst);
2597
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08002598 if(has90Transform(layer) && isRotationDoable(ctx, hnd)) {
radhakrishnac9a67412013-09-25 17:40:42 +05302599 (*rot) = ctx->mRotMgr->getNext();
2600 if((*rot) == NULL) return -1;
Saurabh Shah39240c92014-03-31 10:31:42 -07002601 ctx->mLayerRotMap[dpy]->add(layer, *rot);
radhakrishnab8e2c952015-06-04 16:09:16 +05302602 uint32_t frame_rate = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].refreshRate;
2603 if(!dpy && !isSecondaryConnected(ctx)) {
2604 if(metadata && (metadata->operation & UPDATE_REFRESH_RATE))
2605 frame_rate = metadata->refreshrate;
2606 }
radhakrishnac9a67412013-09-25 17:40:42 +05302607 //Configure rotator for pre-rotation
radhakrishnab8e2c952015-06-04 16:09:16 +05302608 if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale,
2609 frame_rate) < 0) {
radhakrishnac9a67412013-09-25 17:40:42 +05302610 ALOGE("%s: configRotator failed!", __FUNCTION__);
radhakrishnac9a67412013-09-25 17:40:42 +05302611 return -1;
2612 }
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07002613 updateSource(orient, whf, crop, *rot);
radhakrishnac9a67412013-09-25 17:40:42 +05302614 rotFlags |= ROT_PREROTATED;
2615 }
2616
2617 eMdpFlags mdpFlagsR = mdpFlagsL;
2618 int lSplit = dst.left + (dst.right - dst.left)/2;
2619
2620 hwc_rect_t tmp_cropL = {0}, tmp_dstL = {0};
2621 hwc_rect_t tmp_cropR = {0}, tmp_dstR = {0};
2622
2623 if(lDest != OV_INVALID) {
2624 tmp_cropL = crop;
2625 tmp_dstL = dst;
2626 hwc_rect_t scissor = {dst.left, dst.top, lSplit, dst.bottom };
2627 qhwc::calculate_crop_rects(tmp_cropL, tmp_dstL, scissor, 0);
2628 }
2629 if(rDest != OV_INVALID) {
2630 tmp_cropR = crop;
2631 tmp_dstR = dst;
2632 hwc_rect_t scissor = {lSplit, dst.top, dst.right, dst.bottom };
2633 qhwc::calculate_crop_rects(tmp_cropR, tmp_dstR, scissor, 0);
2634 }
2635
2636 sanitizeSourceCrop(tmp_cropL, tmp_cropR, hnd);
2637
2638 //When buffer is H-flipped, contents of mixer config also needs to swapped
2639 //Not needed if the layer is confined to one half of the screen.
2640 //If rotator has been used then it has also done the flips, so ignore them.
2641 if((orient & OVERLAY_TRANSFORM_FLIP_H) && lDest != OV_INVALID
2642 && rDest != OV_INVALID && (*rot) == NULL) {
2643 hwc_rect_t new_cropR;
2644 new_cropR.left = tmp_cropL.left;
2645 new_cropR.right = new_cropR.left + (tmp_cropR.right - tmp_cropR.left);
2646
2647 hwc_rect_t new_cropL;
2648 new_cropL.left = new_cropR.right;
2649 new_cropL.right = tmp_cropR.right;
2650
2651 tmp_cropL.left = new_cropL.left;
2652 tmp_cropL.right = new_cropL.right;
2653
2654 tmp_cropR.left = new_cropR.left;
2655 tmp_cropR.right = new_cropR.right;
2656
2657 }
2658
2659 //For the mdp, since either we are pre-rotating or MDP does flips
2660 orient = OVERLAY_TRANSFORM_0;
2661 transform = 0;
2662
2663 //configure left half
2664 if(lDest != OV_INVALID) {
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002665 PipeArgs pargL(mdpFlagsL, whf, lz,
radhakrishnac9a67412013-09-25 17:40:42 +05302666 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2667 (ovutils::eBlending) getBlending(layer->blending));
2668
2669 if(configMdp(ctx->mOverlay, pargL, orient,
2670 tmp_cropL, tmp_dstL, metadata, lDest) < 0) {
2671 ALOGE("%s: commit failed for left half config", __FUNCTION__);
2672 return -1;
2673 }
2674 }
2675
2676 //configure right half
2677 if(rDest != OV_INVALID) {
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002678 PipeArgs pargR(mdpFlagsR, whf, rz,
radhakrishnac9a67412013-09-25 17:40:42 +05302679 static_cast<eRotFlags>(rotFlags),
2680 layer->planeAlpha,
2681 (ovutils::eBlending) getBlending(layer->blending));
2682 if(configMdp(ctx->mOverlay, pargR, orient,
2683 tmp_cropR, tmp_dstR, metadata, rDest) < 0) {
2684 ALOGE("%s: commit failed for right half config", __FUNCTION__);
2685 return -1;
2686 }
2687 }
2688
2689 return 0;
2690}
2691
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -07002692bool canUseRotator(hwc_context_t *ctx, int dpy) {
Raj Kamal068f4572014-04-14 16:14:06 +05302693 if(ctx->mOverlay->isDMAMultiplexingSupported() &&
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08002694 isSecondaryConnected(ctx) &&
Amara Venkata Mastan Manoj Kumar5cbac942013-08-13 19:00:14 -07002695 !ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isPause) {
Raj Kamal068f4572014-04-14 16:14:06 +05302696 /* mdss driver on certain targets support multiplexing of DMA pipe
Raj Kamala8c065f2013-10-22 14:52:45 +05302697 * in LINE and BLOCK modes for writeback panels.
2698 */
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -07002699 if(dpy == HWC_DISPLAY_PRIMARY)
2700 return false;
Saurabh Shahe2474082013-05-15 16:32:13 -07002701 }
Ramakant Singhb4106a12014-10-07 18:06:56 +05302702 if((ctx->mMDP.version == qdutils::MDP_V3_0_4)
2703 ||(ctx->mMDP.version == qdutils::MDP_V3_0_5))
Terence Hampson45c02ef2013-05-17 17:00:11 -04002704 return false;
Saurabh Shahe2474082013-05-15 16:32:13 -07002705 return true;
2706}
2707
Saurabh Shah07a8ca82013-08-06 18:45:42 -07002708int getLeftSplit(hwc_context_t *ctx, const int& dpy) {
2709 //Default even split for all displays with high res
2710 int lSplit = ctx->dpyAttr[dpy].xres / 2;
2711 if(dpy == HWC_DISPLAY_PRIMARY &&
2712 qdutils::MDPVersion::getInstance().getLeftSplit()) {
2713 //Override if split published by driver for primary
2714 lSplit = qdutils::MDPVersion::getInstance().getLeftSplit();
2715 }
2716 return lSplit;
2717}
Saurabh Shah1a03d482013-05-29 13:44:20 -07002718
Saurabh Shah88e4d272013-09-03 13:31:29 -07002719bool isDisplaySplit(hwc_context_t* ctx, int dpy) {
Prabhanjan Kandula5bae9f52014-05-15 16:48:18 +05302720 qdutils::MDPVersion& mdpHw = qdutils::MDPVersion::getInstance();
Jeykumar Sankarandc76ba82015-01-28 14:51:50 -08002721 if(ctx->dpyAttr[dpy].xres > mdpHw.getMaxMixerWidth()) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07002722 return true;
2723 }
Prabhanjan Kandula5bae9f52014-05-15 16:48:18 +05302724 if(dpy == HWC_DISPLAY_PRIMARY && mdpHw.getRightSplit()) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07002725 return true;
2726 }
2727 return false;
2728}
2729
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08002730//clear prev layer prop flags and realloc for current frame
2731void reset_layer_prop(hwc_context_t* ctx, int dpy, int numAppLayers) {
2732 if(ctx->layerProp[dpy]) {
2733 delete[] ctx->layerProp[dpy];
2734 ctx->layerProp[dpy] = NULL;
2735 }
2736 ctx->layerProp[dpy] = new LayerProp[numAppLayers];
2737}
2738
Ramakant Singh0def28c2014-03-28 20:43:13 +05302739bool isAbcInUse(hwc_context_t *ctx){
2740 return (ctx->enableABC && ctx->listStats[0].renderBufIndexforABC == 0);
2741}
2742
Tatenda Chipeperekwa523eac52014-05-29 14:58:39 -07002743void dumpBuffer(private_handle_t *ohnd, char *bufferName) {
2744 if (ohnd != NULL && ohnd->base) {
2745 char dumpFilename[PATH_MAX];
2746 bool bResult = false;
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -07002747 int width = getWidth(ohnd);
2748 int height = getHeight(ohnd);
2749 int format = ohnd->format;
2750 //dummy aligned w & h.
2751 int alW = 0, alH = 0;
2752 int size = getBufferSizeAndDimensions(width, height, format, alW, alH);
Tatenda Chipeperekwa523eac52014-05-29 14:58:39 -07002753 snprintf(dumpFilename, sizeof(dumpFilename), "/data/%s.%s.%dx%d.raw",
2754 bufferName,
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -07002755 overlay::utils::getFormatString(utils::getMdpFormat(format)),
2756 width, height);
Tatenda Chipeperekwa523eac52014-05-29 14:58:39 -07002757 FILE* fp = fopen(dumpFilename, "w+");
2758 if (NULL != fp) {
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -07002759 bResult = (bool) fwrite((void*)ohnd->base, size, 1, fp);
Tatenda Chipeperekwa523eac52014-05-29 14:58:39 -07002760 fclose(fp);
2761 }
2762 ALOGD("Buffer[%s] Dump to %s: %s",
2763 bufferName, dumpFilename, bResult ? "Success" : "Fail");
2764 }
2765}
2766
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002767bool isGLESComp(hwc_context_t *ctx,
2768 hwc_display_contents_1_t* list) {
2769 int numAppLayers = ctx->listStats[HWC_DISPLAY_PRIMARY].numAppLayers;
2770 for(int index = 0; index < numAppLayers; index++) {
2771 hwc_layer_1_t* layer = &(list->hwLayers[index]);
2772 if(layer->compositionType == HWC_FRAMEBUFFER)
2773 return true;
2774 }
2775 return false;
2776}
2777
2778void setGPUHint(hwc_context_t* ctx, hwc_display_contents_1_t* list) {
2779 struct gpu_hint_info *gpuHint = &ctx->mGPUHintInfo;
Saurabh Shah74eff4d2014-03-28 16:33:13 -07002780 if(!gpuHint->mGpuPerfModeEnable || !ctx || !list)
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002781 return;
Saurabh Shah74eff4d2014-03-28 16:33:13 -07002782
2783#ifdef QCOM_BSP
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002784 /* Set the GPU hint flag to high for MIXED/GPU composition only for
2785 first frame after MDP -> GPU/MIXED mode transition. Set the GPU
2786 hint to default if the previous composition is GPU or current GPU
2787 composition is due to idle fallback */
2788 if(!gpuHint->mEGLDisplay || !gpuHint->mEGLContext) {
2789 gpuHint->mEGLDisplay = eglGetCurrentDisplay();
2790 if(!gpuHint->mEGLDisplay) {
2791 ALOGW("%s Warning: EGL current display is NULL", __FUNCTION__);
2792 return;
2793 }
2794 gpuHint->mEGLContext = eglGetCurrentContext();
2795 if(!gpuHint->mEGLContext) {
2796 ALOGW("%s Warning: EGL current context is NULL", __FUNCTION__);
2797 return;
2798 }
2799 }
2800 if(isGLESComp(ctx, list)) {
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -07002801 if(gpuHint->mCompositionState != COMPOSITION_STATE_GPU
2802 && !MDPComp::isIdleFallback()) {
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002803 EGLint attr_list[] = {EGL_GPU_HINT_1,
2804 EGL_GPU_LEVEL_3,
2805 EGL_NONE };
2806 if((gpuHint->mCurrGPUPerfMode != EGL_GPU_LEVEL_3) &&
2807 !eglGpuPerfHintQCOM(gpuHint->mEGLDisplay,
2808 gpuHint->mEGLContext, attr_list)) {
2809 ALOGW("eglGpuPerfHintQCOM failed for Built in display");
2810 } else {
2811 gpuHint->mCurrGPUPerfMode = EGL_GPU_LEVEL_3;
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -07002812 gpuHint->mCompositionState = COMPOSITION_STATE_GPU;
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002813 }
2814 } else {
2815 EGLint attr_list[] = {EGL_GPU_HINT_1,
2816 EGL_GPU_LEVEL_0,
2817 EGL_NONE };
2818 if((gpuHint->mCurrGPUPerfMode != EGL_GPU_LEVEL_0) &&
2819 !eglGpuPerfHintQCOM(gpuHint->mEGLDisplay,
2820 gpuHint->mEGLContext, attr_list)) {
2821 ALOGW("eglGpuPerfHintQCOM failed for Built in display");
2822 } else {
2823 gpuHint->mCurrGPUPerfMode = EGL_GPU_LEVEL_0;
2824 }
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -07002825 if(MDPComp::isIdleFallback()) {
2826 gpuHint->mCompositionState = COMPOSITION_STATE_IDLE_FALLBACK;
2827 }
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002828 }
2829 } else {
2830 /* set the GPU hint flag to default for MDP composition */
2831 EGLint attr_list[] = {EGL_GPU_HINT_1,
2832 EGL_GPU_LEVEL_0,
2833 EGL_NONE };
2834 if((gpuHint->mCurrGPUPerfMode != EGL_GPU_LEVEL_0) &&
2835 !eglGpuPerfHintQCOM(gpuHint->mEGLDisplay,
2836 gpuHint->mEGLContext, attr_list)) {
2837 ALOGW("eglGpuPerfHintQCOM failed for Built in display");
2838 } else {
2839 gpuHint->mCurrGPUPerfMode = EGL_GPU_LEVEL_0;
2840 }
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -07002841 gpuHint->mCompositionState = COMPOSITION_STATE_MDP;
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002842 }
Saurabh Shah74eff4d2014-03-28 16:33:13 -07002843#endif
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002844}
2845
Sushil Chauhandefd3522014-05-13 18:17:12 -07002846bool isPeripheral(const hwc_rect_t& rect1, const hwc_rect_t& rect2) {
2847 // To be peripheral, 3 boundaries should match.
2848 uint8_t eqBounds = 0;
2849 if (rect1.left == rect2.left)
2850 eqBounds++;
2851 if (rect1.top == rect2.top)
2852 eqBounds++;
2853 if (rect1.right == rect2.right)
2854 eqBounds++;
2855 if (rect1.bottom == rect2.bottom)
2856 eqBounds++;
2857 return (eqBounds == 3);
2858}
2859
Krishna Chaitanya Parimidb992fd2014-10-22 20:50:50 +05302860void processBootAnimCompleted(hwc_context_t *ctx) {
2861 char value[PROPERTY_VALUE_MAX];
Nitesh Gupta538e0f72015-03-25 13:22:35 +05302862 int ret = -1;
Krishna Chaitanya Parimidb992fd2014-10-22 20:50:50 +05302863
Nitesh Gupta538e0f72015-03-25 13:22:35 +05302864 // Applying default mode after bootanimation is finished
2865 property_get("init.svc.bootanim", value, "running");
Krishna Chaitanya Parimidb992fd2014-10-22 20:50:50 +05302866
Nitesh Gupta538e0f72015-03-25 13:22:35 +05302867 if (!strncmp(value,"stopped",strlen("stopped"))) {
Nitesh Gupta538e0f72015-03-25 13:22:35 +05302868 ctx->mBootAnimCompleted = true;
Zohaib Alam83ea46d2015-03-23 15:44:19 -04002869
2870 //one-shot action check if bootanimation completed then apply
2871 //default display mode.
2872 qdcmApplyDefaultAfterBootAnimationDone(ctx);
Nitesh Gupta538e0f72015-03-25 13:22:35 +05302873 }
Krishna Chaitanya Parimidb992fd2014-10-22 20:50:50 +05302874}
2875
Saurabh Shahcd018352014-11-11 13:54:19 -08002876void BwcPM::setBwc(const hwc_context_t *ctx, const int& dpy,
2877 const private_handle_t *hnd,
2878 const hwc_rect_t& crop, const hwc_rect_t& dst,
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002879 const int& transform,const int& downscale,
2880 ovutils::eMdpFlags& mdpFlags) {
Saurabh Shah1a03d482013-05-29 13:44:20 -07002881 //Target doesnt support Bwc
Prabhanjan Kandula5bae9f52014-05-15 16:48:18 +05302882 qdutils::MDPVersion& mdpHw = qdutils::MDPVersion::getInstance();
Saurabh Shahcd018352014-11-11 13:54:19 -08002883 if(not mdpHw.supportsBWC()) {
Saurabh Shah1a03d482013-05-29 13:44:20 -07002884 return;
2885 }
Saurabh Shahcd018352014-11-11 13:54:19 -08002886 //Disabled at runtime
2887 if(not ctx->mBWCEnabled) return;
2888 //BWC not supported with rot-downscale
2889 if(downscale) return;
2890 //Not enabled for secondary displays
2891 if(dpy) return;
2892 //Not enabled for non-video buffers
2893 if(not isYuvBuffer(hnd)) return;
2894
Saurabh Shahb6810df2014-06-17 16:00:22 -07002895 int src_w = crop.right - crop.left;
2896 int src_h = crop.bottom - crop.top;
2897 int dst_w = dst.right - dst.left;
2898 int dst_h = dst.bottom - dst.top;
2899 if(transform & HAL_TRANSFORM_ROT_90) {
2900 swap(src_w, src_h);
2901 }
Saurabh Shah1a03d482013-05-29 13:44:20 -07002902 //src width > MAX mixer supported dim
Jeykumar Sankaran39305802014-12-12 17:55:57 -08002903 if(src_w > (int) qdutils::MDPVersion::getInstance().getMaxPipeWidth()) {
Saurabh Shah1a03d482013-05-29 13:44:20 -07002904 return;
2905 }
Saurabh Shah1a03d482013-05-29 13:44:20 -07002906 //Decimation necessary, cannot use BWC. H/W requirement.
2907 if(qdutils::MDPVersion::getInstance().supportsDecimation()) {
Saurabh Shahb6810df2014-06-17 16:00:22 -07002908 uint8_t horzDeci = 0;
2909 uint8_t vertDeci = 0;
2910 ovutils::getDecimationFactor(src_w, src_h, dst_w, dst_h, horzDeci,
2911 vertDeci);
Saurabh Shahc5b96dc2013-06-05 13:19:52 -07002912 if(horzDeci || vertDeci) return;
Saurabh Shah1a03d482013-05-29 13:44:20 -07002913 }
Saurabh Shah1a03d482013-05-29 13:44:20 -07002914
2915 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDSS_MDP_BWC_EN);
2916}
2917
Saurabh Shah23a813c2013-03-20 16:58:12 -07002918void LayerRotMap::add(hwc_layer_1_t* layer, Rotator *rot) {
Raj Kamal389d6e32014-08-04 14:43:24 +05302919 if(mCount >= RotMgr::MAX_ROT_SESS) return;
Saurabh Shah23a813c2013-03-20 16:58:12 -07002920 mLayer[mCount] = layer;
2921 mRot[mCount] = rot;
2922 mCount++;
2923}
2924
2925void LayerRotMap::reset() {
Raj Kamal389d6e32014-08-04 14:43:24 +05302926 for (int i = 0; i < RotMgr::MAX_ROT_SESS; i++) {
Saurabh Shah23a813c2013-03-20 16:58:12 -07002927 mLayer[i] = 0;
2928 mRot[i] = 0;
2929 }
2930 mCount = 0;
2931}
2932
Saurabh Shahda5b3ce2013-11-26 10:48:06 -08002933void LayerRotMap::clear() {
Saurabh Shah7a606842013-12-11 14:36:04 -08002934 RotMgr::getInstance()->markUnusedTop(mCount);
Saurabh Shahda5b3ce2013-11-26 10:48:06 -08002935 reset();
2936}
2937
Raj Kamalbd3bdc62014-08-05 18:52:49 +05302938bool LayerRotMap::isRotCached(uint32_t index) const {
2939 overlay::Rotator* rot = getRot(index);
2940 hwc_layer_1_t* layer = getLayer(index);
2941
2942 if(rot and layer and layer->handle) {
2943 private_handle_t *hnd = (private_handle_t *)(layer->handle);
2944 return (rot->isRotCached(hnd->fd,(uint32_t)(hnd->offset)));
2945 }
2946 return false;
2947}
2948
Saurabh Shah23a813c2013-03-20 16:58:12 -07002949void LayerRotMap::setReleaseFd(const int& fence) {
2950 for(uint32_t i = 0; i < mCount; i++) {
Raj Kamalbd3bdc62014-08-05 18:52:49 +05302951 if(mRot[i] and mLayer[i] and mLayer[i]->handle) {
2952 /* Ensure that none of the above (Rotator-instance,
2953 * layer and layer-handle) are NULL*/
2954 if(isRotCached(i))
2955 mRot[i]->setPrevBufReleaseFd(dup(fence));
2956 else
2957 mRot[i]->setCurrBufReleaseFd(dup(fence));
2958 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07002959 }
2960}
2961
Jeykumar Sankaranaedd1432015-01-15 11:25:03 -08002962hwc_rect expandROIFromMidPoint(hwc_rect roi, hwc_rect fullFrame) {
2963 int lRoiWidth = 0, rRoiWidth = 0;
2964 int half_frame_width = fullFrame.right/2;
2965
2966 hwc_rect lFrame = fullFrame;
2967 hwc_rect rFrame = fullFrame;
2968 lFrame.right = (lFrame.right - lFrame.left)/2;
2969 rFrame.left = lFrame.right;
2970
2971 hwc_rect lRoi = getIntersection(roi, lFrame);
2972 hwc_rect rRoi = getIntersection(roi, rFrame);
2973
2974 lRoiWidth = lRoi.right - lRoi.left;
2975 rRoiWidth = rRoi.right - rRoi.left;
2976
2977 if(lRoiWidth && rRoiWidth) {
2978 if(lRoiWidth < rRoiWidth)
2979 roi.left = half_frame_width - rRoiWidth;
2980 else
2981 roi.right = half_frame_width + lRoiWidth;
2982 }
2983 return roi;
2984}
2985
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002986void resetROI(hwc_context_t *ctx, const int dpy) {
2987 const int fbXRes = (int)ctx->dpyAttr[dpy].xres;
2988 const int fbYRes = (int)ctx->dpyAttr[dpy].yres;
Jeykumar Sankaranf7124b92015-02-26 10:34:35 -08002989
2990 /* When source split is enabled, both the panels are calibrated
2991 * in a single coordinate system. So only one ROI is generated
2992 * for the whole panel extending equally from the midpoint and
2993 * populated for the left side. */
2994 if(!qdutils::MDPVersion::getInstance().isSrcSplit() &&
2995 isDisplaySplit(ctx, dpy)) {
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002996 const int lSplit = getLeftSplit(ctx, dpy);
2997 ctx->listStats[dpy].lRoi = (struct hwc_rect){0, 0, lSplit, fbYRes};
2998 ctx->listStats[dpy].rRoi = (struct hwc_rect){lSplit, 0, fbXRes, fbYRes};
2999 } else {
3000 ctx->listStats[dpy].lRoi = (struct hwc_rect){0, 0,fbXRes, fbYRes};
3001 ctx->listStats[dpy].rRoi = (struct hwc_rect){0, 0, 0, 0};
3002 }
3003}
3004
3005hwc_rect_t getSanitizeROI(struct hwc_rect roi, hwc_rect boundary)
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08003006{
3007 if(!isValidRect(roi))
3008 return roi;
3009
3010 struct hwc_rect t_roi = roi;
3011
3012 const int LEFT_ALIGN = qdutils::MDPVersion::getInstance().getLeftAlign();
3013 const int WIDTH_ALIGN = qdutils::MDPVersion::getInstance().getWidthAlign();
3014 const int TOP_ALIGN = qdutils::MDPVersion::getInstance().getTopAlign();
3015 const int HEIGHT_ALIGN = qdutils::MDPVersion::getInstance().getHeightAlign();
3016 const int MIN_WIDTH = qdutils::MDPVersion::getInstance().getMinROIWidth();
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08003017 const int MIN_HEIGHT = qdutils::MDPVersion::getInstance().getMinROIHeight();
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08003018
3019 /* Align to minimum width recommended by the panel */
3020 if((t_roi.right - t_roi.left) < MIN_WIDTH) {
3021 if((t_roi.left + MIN_WIDTH) > boundary.right)
3022 t_roi.left = t_roi.right - MIN_WIDTH;
3023 else
3024 t_roi.right = t_roi.left + MIN_WIDTH;
3025 }
3026
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08003027 /* Align to minimum height recommended by the panel */
3028 if((t_roi.bottom - t_roi.top) < MIN_HEIGHT) {
3029 if((t_roi.top + MIN_HEIGHT) > boundary.bottom)
3030 t_roi.top = t_roi.bottom - MIN_HEIGHT;
3031 else
3032 t_roi.bottom = t_roi.top + MIN_HEIGHT;
3033 }
3034
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08003035 /* Align left and width to meet panel restrictions */
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08003036 if(LEFT_ALIGN)
3037 t_roi.left = t_roi.left - (t_roi.left % LEFT_ALIGN);
3038
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08003039 if(WIDTH_ALIGN) {
3040 int width = t_roi.right - t_roi.left;
3041 width = WIDTH_ALIGN * ((width + (WIDTH_ALIGN - 1)) / WIDTH_ALIGN);
3042 t_roi.right = t_roi.left + width;
3043
3044 if(t_roi.right > boundary.right) {
3045 t_roi.right = boundary.right;
3046 t_roi.left = t_roi.right - width;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08003047
3048 if(LEFT_ALIGN)
3049 t_roi.left = t_roi.left - (t_roi.left % LEFT_ALIGN);
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08003050 }
3051 }
3052
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08003053
3054 /* Align top and height to meet panel restrictions */
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08003055 if(TOP_ALIGN)
3056 t_roi.top = t_roi.top - (t_roi.top % TOP_ALIGN);
3057
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08003058 if(HEIGHT_ALIGN) {
3059 int height = t_roi.bottom - t_roi.top;
3060 height = HEIGHT_ALIGN * ((height + (HEIGHT_ALIGN - 1)) / HEIGHT_ALIGN);
3061 t_roi.bottom = t_roi.top + height;
3062
3063 if(t_roi.bottom > boundary.bottom) {
3064 t_roi.bottom = boundary.bottom;
3065 t_roi.top = t_roi.bottom - height;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08003066
3067 if(TOP_ALIGN)
3068 t_roi.top = t_roi.top - (t_roi.top % TOP_ALIGN);
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08003069 }
3070 }
3071
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08003072
3073 return t_roi;
3074}
3075
Manoj Kumar AVM9591a5e2014-08-21 22:50:21 -07003076void handle_pause(hwc_context_t* ctx, int dpy) {
Arun Kumar K.R33888f52014-10-09 15:56:33 -07003077 if(ctx->dpyAttr[dpy].connected) {
3078 ctx->mDrawLock.lock();
3079 ctx->dpyAttr[dpy].isActive = true;
3080 ctx->dpyAttr[dpy].isPause = true;
3081 ctx->mDrawLock.unlock();
3082 ctx->proc->invalidate(ctx->proc);
3083
3084 usleep(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period
3085 * 2 / 1000);
3086
3087 // At this point all the pipes used by External have been
3088 // marked as UNSET.
3089 ctx->mDrawLock.lock();
3090 // Perform commit to unstage the pipes.
3091 if (!Overlay::displayCommit(ctx->dpyAttr[dpy].fd)) {
3092 ALOGE("%s: display commit fail! for %d dpy",
3093 __FUNCTION__, dpy);
3094 }
3095 ctx->mDrawLock.unlock();
3096 ctx->proc->invalidate(ctx->proc);
Manoj Kumar AVM9591a5e2014-08-21 22:50:21 -07003097 }
3098 return;
3099}
3100
3101void handle_resume(hwc_context_t* ctx, int dpy) {
Arun Kumar K.R33888f52014-10-09 15:56:33 -07003102 if(ctx->dpyAttr[dpy].connected) {
3103 ctx->mDrawLock.lock();
3104 ctx->dpyAttr[dpy].isConfiguring = true;
3105 ctx->dpyAttr[dpy].isActive = true;
3106 ctx->mDrawLock.unlock();
3107 ctx->proc->invalidate(ctx->proc);
3108
3109 usleep(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period
3110 * 2 / 1000);
3111
3112 //At this point external has all the pipes it would need.
3113 ctx->mDrawLock.lock();
3114 ctx->dpyAttr[dpy].isPause = false;
3115 ctx->mDrawLock.unlock();
3116 ctx->proc->invalidate(ctx->proc);
Manoj Kumar AVM9591a5e2014-08-21 22:50:21 -07003117 }
3118 return;
3119}
3120
Tatenda Chipeperekwad80b6172014-09-23 11:29:37 -07003121void clearPipeResources(hwc_context_t* ctx, int dpy) {
3122 if(ctx->mOverlay) {
3123 ctx->mOverlay->configBegin();
3124 ctx->mOverlay->configDone();
3125 }
3126 if(ctx->mRotMgr) {
3127 ctx->mRotMgr->clear();
3128 }
3129 // Call a display commit to ensure that pipes and associated
3130 // fd's are cleaned up.
3131 if(!Overlay::displayCommit(ctx->dpyAttr[dpy].fd)) {
3132 ALOGE("%s: display commit failed for %d", __FUNCTION__, dpy);
3133 }
3134}
3135
3136// Handles online events when HDMI is the primary display. In particular,
3137// online events for hdmi connected before AND after boot up and HWC init.
3138void handle_online(hwc_context_t* ctx, int dpy) {
3139 // Close the current fd if it was opened earlier on when HWC
3140 // was initialized.
3141 if (ctx->dpyAttr[dpy].fd >= 0) {
3142 close(ctx->dpyAttr[dpy].fd);
3143 ctx->dpyAttr[dpy].fd = -1;
3144 }
3145 // TODO: If HDMI is connected after the display has booted up,
3146 // and the best configuration is different from the default
3147 // then we need to deal with this appropriately.
Arun Kumar K.R205df772015-02-20 18:45:58 -08003148 int error = ctx->mHDMIDisplay->configure();
3149 if (error < 0) {
3150 ALOGE("Error opening FrameBuffer");
3151 return;
3152 }
Tatenda Chipeperekwad80b6172014-09-23 11:29:37 -07003153 updateDisplayInfo(ctx, dpy);
3154 initCompositionResources(ctx, dpy);
3155 ctx->dpyAttr[dpy].connected = true;
3156}
3157
3158// Handles offline events for HDMI. This can be used for offline events
3159// initiated by the HDMI driver and the CEC framework.
3160void handle_offline(hwc_context_t* ctx, int dpy) {
3161 destroyCompositionResources(ctx, dpy);
3162 // Clear all pipe resources and call a display commit to ensure
3163 // that all the fd's are closed. This will ensure that the HDMI
3164 // core turns off and that we receive an event the next time the
3165 // cable is connected.
3166 if (ctx->mHDMIDisplay->isHDMIPrimaryDisplay()) {
3167 clearPipeResources(ctx, dpy);
3168 }
3169 ctx->mHDMIDisplay->teardown();
3170 resetDisplayInfo(ctx, dpy);
3171 ctx->dpyAttr[dpy].connected = false;
3172 ctx->dpyAttr[dpy].isActive = false;
3173}
3174
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -05003175int convertS3DFormatToMode(int s3DFormat) {
3176 int ret;
3177 switch(s3DFormat) {
3178 case HAL_3D_SIDE_BY_SIDE_L_R:
3179 case HAL_3D_SIDE_BY_SIDE_R_L:
3180 ret = HDMI_S3D_SIDE_BY_SIDE;
3181 break;
3182 case HAL_3D_TOP_BOTTOM:
3183 ret = HDMI_S3D_TOP_AND_BOTTOM;
3184 break;
3185 default:
3186 ret = HDMI_S3D_NONE;
3187 }
3188 return ret;
3189}
3190
3191bool needs3DComposition(hwc_context_t* ctx, int dpy) {
3192 return (displaySupports3D(ctx, dpy) && ctx->dpyAttr[dpy].connected &&
3193 ctx->dpyAttr[dpy].s3dMode != HDMI_S3D_NONE);
3194}
3195
3196void setup3DMode(hwc_context_t *ctx, int dpy, int s3dMode) {
3197 if (ctx->dpyAttr[dpy].s3dMode != s3dMode) {
3198 ALOGD("%s: setup 3D mode: %d", __FUNCTION__, s3dMode);
3199 if(ctx->mHDMIDisplay->configure3D(s3dMode)) {
3200 ctx->dpyAttr[dpy].s3dMode = s3dMode;
3201 }
3202 }
3203}
3204
3205bool displaySupports3D(hwc_context_t* ctx, int dpy) {
3206 return ((dpy == HWC_DISPLAY_EXTERNAL) ||
3207 ((dpy == HWC_DISPLAY_PRIMARY) &&
3208 ctx->mHDMIDisplay->isHDMIPrimaryDisplay()));
3209}
3210
3211
Saurabh Shahacf10202013-02-26 10:15:15 -08003212};//namespace qhwc