blob: 51c208e1ec0e694c4e22f9c073b89b76acd1a7ac [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"
Ramakant Singh98c533c2014-09-30 19:01:54 +053047#include <sys/sysinfo.h>
Krishna Chaitanya Parimidb992fd2014-10-22 20:50:50 +053048#include <dlfcn.h>
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -050049#include <video/msm_hdmi_modes.h>
Saurabh Shah86c17292013-02-08 15:24:13 -080050
51using namespace qClient;
52using namespace qService;
53using namespace android;
Saurabh Shahacf10202013-02-26 10:15:15 -080054using namespace overlay;
55using namespace overlay::utils;
56namespace ovutils = overlay::utils;
Saurabh Shah86c17292013-02-08 15:24:13 -080057
Saurabh Shah74eff4d2014-03-28 16:33:13 -070058#ifdef QCOM_BSP
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -070059#ifdef __cplusplus
60extern "C" {
61#endif
62
63EGLAPI EGLBoolean eglGpuPerfHintQCOM(EGLDisplay dpy, EGLContext ctx,
64 EGLint *attrib_list);
65#define EGL_GPU_HINT_1 0x32D0
66#define EGL_GPU_HINT_2 0x32D1
67
68#define EGL_GPU_LEVEL_0 0x0
69#define EGL_GPU_LEVEL_1 0x1
70#define EGL_GPU_LEVEL_2 0x2
71#define EGL_GPU_LEVEL_3 0x3
72#define EGL_GPU_LEVEL_4 0x4
73#define EGL_GPU_LEVEL_5 0x5
74
75#ifdef __cplusplus
76}
77#endif
Saurabh Shah74eff4d2014-03-28 16:33:13 -070078#endif
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -070079
Ramakant Singhbe390c72014-12-03 23:04:21 +053080#define PROP_DEFAULT_APPBUFFER "hw.sf.app_buff_count"
Ramakant Singh98c533c2014-09-30 19:01:54 +053081#define MAX_RAM_SIZE 512*1024*1024
82#define qHD_WIDTH 540
83
84
Naseer Ahmed29a26812012-06-14 00:56:20 -070085namespace qhwc {
Naseer Ahmed72cf9762012-07-21 12:17:13 -070086
Arun Kumar K.R053dc502014-11-13 11:13:43 -080087// Std refresh rates for digital videos- 24p, 30p, 48p and 60p
88uint32_t stdRefreshRates[] = { 30, 24, 48, 60 };
Arun Kumar K.Ra727a882014-08-20 17:14:26 -070089
radhakrishnac3198ff2015-03-10 17:10:02 +053090static uint32_t getFBformat(fb_var_screeninfo vinfo) {
91 uint32_t fbformat = HAL_PIXEL_FORMAT_RGBA_8888;
92
93#ifdef GET_FRAMEBUFFER_FORMAT_FROM_HWC
94 // Here, we are adding the formats that are supported by both GPU and MDP.
95 // The formats that fall in this category are RGBA_8888, RGB_565, RGB_888
96 switch(vinfo.bits_per_pixel) {
97 case 16:
98 fbformat = HAL_PIXEL_FORMAT_RGB_565;
99 break;
100 case 24:
101 if ((vinfo.transp.offset == 0) && (vinfo.transp.length == 0))
102 fbformat = HAL_PIXEL_FORMAT_RGB_888;
103 break;
104 case 32:
105 if ((vinfo.red.offset == 0) && (vinfo.green.offset == 8) &&
106 (vinfo.blue.offset == 16) && (vinfo.transp.offset == 24))
107 fbformat = HAL_PIXEL_FORMAT_RGBA_8888;
108 break;
109 default:
110 fbformat = HAL_PIXEL_FORMAT_RGBA_8888;
111 }
112#endif
113 return fbformat;
114}
115
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530116bool isValidResolution(hwc_context_t *ctx, uint32_t xres, uint32_t yres)
117{
Jeykumar Sankaran39305802014-12-12 17:55:57 -0800118 return !((xres > qdutils::MDPVersion::getInstance().getMaxPipeWidth() &&
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530119 !isDisplaySplit(ctx, HWC_DISPLAY_PRIMARY)) ||
120 (xres < MIN_DISPLAY_XRES || yres < MIN_DISPLAY_YRES));
121}
122
Saurabh Shah90c55cf2015-02-10 15:37:39 -0800123static void handleFbScaling(hwc_context_t *ctx, int xresPanel, int yresPanel,
124 int width, int height) {
125 const int dpy = HWC_DISPLAY_PRIMARY;
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530126 //Store original display resolution.
Saurabh Shah90c55cf2015-02-10 15:37:39 -0800127 ctx->dpyAttr[dpy].xresFB = xresPanel;
128 ctx->dpyAttr[dpy].yresFB = yresPanel;
129 ctx->dpyAttr[dpy].fbScaling = false;
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530130 char property[PROPERTY_VALUE_MAX] = {'\0'};
131 char *yptr = NULL;
132 if (property_get("debug.hwc.fbsize", property, NULL) > 0) {
133 yptr = strcasestr(property,"x");
Raj Kamal4a443082014-10-12 21:07:59 +0530134 if(yptr) {
Saurabh Shah90c55cf2015-02-10 15:37:39 -0800135 int xresFB = atoi(property);
136 int yresFB = atoi(yptr + 1);
137 if (isValidResolution(ctx, xresFB, yresFB) &&
138 xresFB != xresPanel && yresFB != yresPanel) {
139 ctx->dpyAttr[dpy].xresFB = xresFB;
140 ctx->dpyAttr[dpy].yresFB = yresFB;
141 ctx->dpyAttr[dpy].fbScaling = true;
Praveena Pachipulusu49d62062014-06-06 19:22:23 +0530142
Saurabh Shah90c55cf2015-02-10 15:37:39 -0800143 //Calculate DPI according to changed resolution.
144 float xdpi = ((float)xresFB * 25.4f) / (float)width;
145 float ydpi = ((float)yresFB * 25.4f) / (float)height;
146 ctx->dpyAttr[dpy].xdpi = xdpi;
147 ctx->dpyAttr[dpy].ydpi = ydpi;
Raj Kamal4a443082014-10-12 21:07:59 +0530148 }
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530149 }
150 }
Saurabh Shah90c55cf2015-02-10 15:37:39 -0800151 ctx->dpyAttr[dpy].fbWidthScaleRatio = (float) ctx->dpyAttr[dpy].xres /
152 (float) ctx->dpyAttr[dpy].xresFB;
153 ctx->dpyAttr[dpy].fbHeightScaleRatio = (float) ctx->dpyAttr[dpy].yres /
154 (float) ctx->dpyAttr[dpy].yresFB;
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530155}
156
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700157// Initialize hdmi display attributes based on
158// hdmi display class state
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700159void updateDisplayInfo(hwc_context_t* ctx, int dpy) {
radhakrishnac3198ff2015-03-10 17:10:02 +0530160 struct fb_var_screeninfo info;
161
162 if (ioctl(ctx->mHDMIDisplay->getFd(), FBIOGET_VSCREENINFO, &info) == -1) {
163 ALOGE("%s:Error in ioctl FBIOGET_VSCREENINFO: %s",
164 __FUNCTION__, strerror(errno));
165 }
166
167 ctx->dpyAttr[dpy].fbformat = getFBformat(info);
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700168 ctx->dpyAttr[dpy].fd = ctx->mHDMIDisplay->getFd();
169 ctx->dpyAttr[dpy].xres = ctx->mHDMIDisplay->getWidth();
170 ctx->dpyAttr[dpy].yres = ctx->mHDMIDisplay->getHeight();
171 ctx->dpyAttr[dpy].mMDPScalingMode = ctx->mHDMIDisplay->getMDPScalingMode();
172 ctx->dpyAttr[dpy].vsync_period = ctx->mHDMIDisplay->getVsyncPeriod();
Arun Kumar K.R074c9cf2014-08-21 18:43:53 -0700173 //FIXME: for now assume HDMI as secure
174 //Will need to read the HDCP status from the driver
175 //and update this accordingly
176 ctx->dpyAttr[dpy].secure = true;
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700177 ctx->mViewFrame[dpy].left = 0;
178 ctx->mViewFrame[dpy].top = 0;
179 ctx->mViewFrame[dpy].right = ctx->dpyAttr[dpy].xres;
180 ctx->mViewFrame[dpy].bottom = ctx->dpyAttr[dpy].yres;
181}
182
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700183// Reset hdmi display attributes and list stats structures
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700184void resetDisplayInfo(hwc_context_t* ctx, int dpy) {
185 memset(&(ctx->dpyAttr[dpy]), 0, sizeof(ctx->dpyAttr[dpy]));
186 memset(&(ctx->listStats[dpy]), 0, sizeof(ctx->listStats[dpy]));
187 // We reset the fd to -1 here but External display class is responsible
188 // for it when the display is disconnected. This is handled as part of
189 // EXTERNAL_OFFLINE event.
190 ctx->dpyAttr[dpy].fd = -1;
191}
192
193// Initialize composition resources
194void initCompositionResources(hwc_context_t* ctx, int dpy) {
195 ctx->mFBUpdate[dpy] = IFBUpdate::getObject(ctx, dpy);
196 ctx->mMDPComp[dpy] = MDPComp::getObject(ctx, dpy);
197}
198
199void destroyCompositionResources(hwc_context_t* ctx, int dpy) {
200 if(ctx->mFBUpdate[dpy]) {
201 delete ctx->mFBUpdate[dpy];
202 ctx->mFBUpdate[dpy] = NULL;
203 }
204 if(ctx->mMDPComp[dpy]) {
205 delete ctx->mMDPComp[dpy];
206 ctx->mMDPComp[dpy] = NULL;
207 }
208}
209
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800210static int openFramebufferDevice(hwc_context_t *ctx)
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700211{
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800212 struct fb_fix_screeninfo finfo;
213 struct fb_var_screeninfo info;
214
215 int fb_fd = openFb(HWC_DISPLAY_PRIMARY);
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +0530216 if(fb_fd < 0) {
217 ALOGE("%s: Error Opening FB : %s", __FUNCTION__, strerror(errno));
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800218 return -errno;
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +0530219 }
220
221 if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &info) == -1) {
222 ALOGE("%s:Error in ioctl FBIOGET_VSCREENINFO: %s", __FUNCTION__,
223 strerror(errno));
224 close(fb_fd);
225 return -errno;
226 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800227
228 if (int(info.width) <= 0 || int(info.height) <= 0) {
229 // the driver doesn't return that information
230 // default to 160 dpi
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530231 info.width = (int)(((float)info.xres * 25.4f)/160.0f + 0.5f);
232 info.height = (int)(((float)info.yres * 25.4f)/160.0f + 0.5f);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700233 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800234
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530235 float xdpi = ((float)info.xres * 25.4f) / (float)info.width;
236 float ydpi = ((float)info.yres * 25.4f) / (float)info.height;
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800237
238#ifdef MSMFB_METADATA_GET
239 struct msmfb_metadata metadata;
240 memset(&metadata, 0 , sizeof(metadata));
241 metadata.op = metadata_op_frame_rate;
242
243 if (ioctl(fb_fd, MSMFB_METADATA_GET, &metadata) == -1) {
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +0530244 ALOGE("%s:Error retrieving panel frame rate: %s", __FUNCTION__,
245 strerror(errno));
246 close(fb_fd);
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800247 return -errno;
248 }
249
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530250 float fps = (float)metadata.data.panel_frame_rate;
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800251#else
252 //XXX: Remove reserved field usage on all baselines
253 //The reserved[3] field is used to store FPS by the driver.
254 float fps = info.reserved[3] & 0xFF;
255#endif
256
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +0530257 if (ioctl(fb_fd, FBIOGET_FSCREENINFO, &finfo) == -1) {
258 ALOGE("%s:Error in ioctl FBIOGET_FSCREENINFO: %s", __FUNCTION__,
259 strerror(errno));
260 close(fb_fd);
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800261 return -errno;
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +0530262 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800263
264 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd = fb_fd;
265 //xres, yres may not be 32 aligned
266 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].stride = finfo.line_length /(info.xres/8);
267 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres = info.xres;
268 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres = info.yres;
269 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xdpi = xdpi;
270 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].ydpi = ydpi;
Arun Kumar K.Ra727a882014-08-20 17:14:26 -0700271 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].refreshRate = (uint32_t)fps;
272 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].dynRefreshRate = (uint32_t)fps;
Arun Kumar K.R074c9cf2014-08-21 18:43:53 -0700273 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].secure = true;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530274 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period =
275 (uint32_t)(1000000000l / fps);
radhakrishnac3198ff2015-03-10 17:10:02 +0530276 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fbformat = getFBformat(info);
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800277
Saurabh Shah90c55cf2015-02-10 15:37:39 -0800278 handleFbScaling(ctx, info.xres, info.yres, info.width, info.height);
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530279
Naseer Ahmed22616d92013-05-15 17:20:26 -0400280 //Unblank primary on first boot
281 if(ioctl(fb_fd, FBIOBLANK,FB_BLANK_UNBLANK) < 0) {
282 ALOGE("%s: Failed to unblank display", __FUNCTION__);
283 return -errno;
284 }
285 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].isActive = true;
286
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800287 return 0;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700288}
289
Ramakant Singh98c533c2014-09-30 19:01:54 +0530290static void changeDefaultAppBufferCount() {
291 struct sysinfo info;
292 unsigned long int ramSize = 0;
293 if (!sysinfo(&info)) {
294 ramSize = info.totalram ;
295 }
296 int fb_fd = -1;
297 struct fb_var_screeninfo sInfo ={0};
298 fb_fd = open("/dev/graphics/fb0", O_RDONLY);
299 if (fb_fd >=0) {
300 ioctl(fb_fd, FBIOGET_VSCREENINFO, &sInfo);
301 close(fb_fd);
302 }
303 if ((ramSize && ramSize < MAX_RAM_SIZE) &&
304 (sInfo.xres && sInfo.xres <= qHD_WIDTH )) {
Sanjeev Jakkilinkif8bc0362015-02-23 20:20:17 +0530305 property_set(PROP_DEFAULT_APPBUFFER, "3");
Ramakant Singh98c533c2014-09-30 19:01:54 +0530306 }
307}
308
Arun Kumar K.R205df772015-02-20 18:45:58 -0800309int initContext(hwc_context_t *ctx)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700310{
Arun Kumar K.R205df772015-02-20 18:45:58 -0800311 int error = -1;
312 int compositionType = 0;
313
314 //Right now hwc starts the service but anybody could do it, or it could be
315 //independent process as well.
316 QService::init();
317 sp<IQClient> client = new QClient(ctx);
318 sp<IQService> iqs = interface_cast<IQService>(
319 defaultServiceManager()->getService(
320 String16("display.qservice")));
321 if (iqs.get()) {
322 iqs->connect(client);
323 ctx->mQService = reinterpret_cast<QService* >(iqs.get());
324 } else {
325 ALOGE("%s: Failed to acquire service pointer", __FUNCTION__);
326 return error;
327 }
328
Tatenda Chipeperekwad80b6172014-09-23 11:29:37 -0700329 overlay::Overlay::initOverlay();
330 ctx->mHDMIDisplay = new HDMIDisplay();
331 uint32_t priW = 0, priH = 0;
332 // 1. HDMI as Primary
333 // -If HDMI cable is connected, read display configs from edid data
334 // -If HDMI cable is not connected then use default data in vscreeninfo
335 // 2. HDMI as External
336 // -Initialize HDMI class for use with external display
337 // -Use vscreeninfo to populate display configs
338 if(ctx->mHDMIDisplay->isHDMIPrimaryDisplay()) {
339 int connected = ctx->mHDMIDisplay->getConnectedState();
340 if(connected == 1) {
Arun Kumar K.R205df772015-02-20 18:45:58 -0800341 error = ctx->mHDMIDisplay->configure();
342 if (error < 0) {
343 goto OpenFBError;
344 }
Tatenda Chipeperekwad80b6172014-09-23 11:29:37 -0700345 updateDisplayInfo(ctx, HWC_DISPLAY_PRIMARY);
346 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].connected = true;
347 } else {
Arun Kumar K.R205df772015-02-20 18:45:58 -0800348 error = openFramebufferDevice(ctx);
349 if(error < 0) {
350 goto OpenFBError;
351 }
Tatenda Chipeperekwad80b6172014-09-23 11:29:37 -0700352 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].connected = false;
353 }
354 } else {
Arun Kumar K.R205df772015-02-20 18:45:58 -0800355 error = openFramebufferDevice(ctx);
356 if(error < 0) {
357 goto OpenFBError;
358 }
Tatenda Chipeperekwad80b6172014-09-23 11:29:37 -0700359 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].connected = true;
360 // Send the primary resolution to the hdmi display class
361 // to be used for MDP scaling functionality
362 priW = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
363 priH = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres;
364 ctx->mHDMIDisplay->setPrimaryAttributes(priW, priH);
365 }
366
Raj kamal59fea562014-04-01 16:52:19 +0530367 char value[PROPERTY_VALUE_MAX];
Naseer Ahmed96c4c952012-07-25 18:27:14 -0700368 ctx->mMDP.version = qdutils::MDPVersion::getInstance().getMDPVersion();
369 ctx->mMDP.hasOverlay = qdutils::MDPVersion::getInstance().hasOverlay();
370 ctx->mMDP.panel = qdutils::MDPVersion::getInstance().getPanelType();
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800371 ctx->mOverlay = overlay::Overlay::getInstance();
Saurabh Shah7a606842013-12-11 14:36:04 -0800372 ctx->mRotMgr = RotMgr::getInstance();
Saurabh Shahcd018352014-11-11 13:54:19 -0800373 ctx->mBWCEnabled = qdutils::MDPVersion::getInstance().supportsBWC();
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800374
Ramakant Singh98c533c2014-09-30 19:01:54 +0530375 //default_app_buffer for ferrum
376 if (ctx->mMDP.version == qdutils::MDP_V3_0_5) {
377 changeDefaultAppBufferCount();
378 }
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700379 // Initialize composition objects for the primary display
380 initCompositionResources(ctx, HWC_DISPLAY_PRIMARY);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800381
Arun Kumar K.R9fc89972014-01-02 17:01:02 -0800382 // Check if the target supports copybit compostion (dyn/mdp) to
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800383 // decide if we need to open the copybit module.
Arun Kumar K.R205df772015-02-20 18:45:58 -0800384 compositionType =
385 qdutils::QCCompositionType::getInstance().getCompositionType();
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800386
Arun Kumar K.R9fc89972014-01-02 17:01:02 -0800387 // Only MDP copybit is used
388 if ((compositionType & (qdutils::COMPOSITION_TYPE_DYN |
389 qdutils::COMPOSITION_TYPE_MDP)) &&
Ramakant Singhb4106a12014-10-07 18:06:56 +0530390 ((qdutils::MDPVersion::getInstance().getMDPVersion() ==
391 qdutils::MDP_V3_0_4) ||
Arun Kumar K.R9fc89972014-01-02 17:01:02 -0800392 (qdutils::MDPVersion::getInstance().getMDPVersion() ==
Ramakant Singhb4106a12014-10-07 18:06:56 +0530393 qdutils::MDP_V3_0_5))) {
Arun Kumar K.R9fc89972014-01-02 17:01:02 -0800394 ctx->mCopyBit[HWC_DISPLAY_PRIMARY] = new CopyBit(ctx,
395 HWC_DISPLAY_PRIMARY);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800396 }
397
Manoj Kumar AVM9591a5e2014-08-21 22:50:21 -0700398 ctx->mHWCVirtual = new HWCVirtualVDS();
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700399 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isActive = false;
400 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected = false;
401 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isActive = false;
402 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected = false;
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700403 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].mMDPScalingMode= false;
404 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].mMDPScalingMode = false;
405 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].mMDPScalingMode = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800406
Arun Kumar K.R81f3f2e2014-06-23 14:03:12 -0700407 //Initialize the primary display viewFrame info
408 ctx->mViewFrame[HWC_DISPLAY_PRIMARY].left = 0;
409 ctx->mViewFrame[HWC_DISPLAY_PRIMARY].top = 0;
410 ctx->mViewFrame[HWC_DISPLAY_PRIMARY].right =
411 (int)ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
412 ctx->mViewFrame[HWC_DISPLAY_PRIMARY].bottom =
413 (int)ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres;
Raj kamal59fea562014-04-01 16:52:19 +0530414
Amara Venkata Mastan Manoj Kumar7fb13272013-07-01 13:59:34 -0700415 for (uint32_t i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700416 ctx->mHwcDebug[i] = new HwcDebug(i);
Saurabh Shah23a813c2013-03-20 16:58:12 -0700417 ctx->mLayerRotMap[i] = new LayerRotMap();
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -0700418 ctx->mAnimationState[i] = ANIMATION_STOPPED;
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800419 ctx->dpyAttr[i].mActionSafePresent = false;
420 ctx->dpyAttr[i].mAsWidthRatio = 0;
421 ctx->dpyAttr[i].mAsHeightRatio = 0;
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -0500422 ctx->dpyAttr[i].s3dMode = HDMI_S3D_NONE;
423 ctx->dpyAttr[i].s3dModeForced = false;
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700424 }
Saurabh Shah23a813c2013-03-20 16:58:12 -0700425
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -0500426 //Make sure that the 3D mode is unset at bootup
427 //This makes sure that the state is accurate on framework reboots
428 ctx->mHDMIDisplay->configure3D(HDMI_S3D_NONE);
429
Raj Kamal9ed3d6b2014-02-07 16:15:17 +0530430 for (uint32_t i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
431 ctx->mPrevHwLayerCount[i] = 0;
432 }
433
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500434 MDPComp::init(ctx);
Saurabh Shahc4f1fa62013-09-03 13:12:14 -0700435 ctx->mAD = new AssertiveDisplay(ctx);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700436
Naseer Ahmedff4f0252012-10-01 13:03:01 -0400437 ctx->vstate.enable = false;
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500438 ctx->vstate.fakevsync = false;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700439 ctx->mExtOrientation = 0;
Raj Kamal52b4fdb2014-01-27 19:35:13 +0530440 ctx->numActiveDisplays = 1;
Saurabh Shah86c17292013-02-08 15:24:13 -0800441
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -0700442 // Initialize device orientation to its default orientation
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700443 ctx->deviceOrientation = 0;
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700444 ctx->mBufferMirrorMode = false;
Zohaib Alam1bb65612013-09-28 03:38:20 -0400445
Ramkumar Radhakrishnan812999a2014-09-11 21:42:07 -0700446 property_get("sys.hwc.windowbox_aspect_ratio_tolerance", value, "0");
447 ctx->mAspectRatioToleranceLevel = (((float)atoi(value)) / 100.0f);
448
Ramakant Singh0def28c2014-03-28 20:43:13 +0530449 ctx->enableABC = false;
450 property_get("debug.sf.hwc.canUseABC", value, "0");
451 ctx->enableABC = atoi(value) ? true : false;
452
Krishna Chaitanya Parimidb992fd2014-10-22 20:50:50 +0530453 // Initializing boot anim completed check to false
454 ctx->mBootAnimCompleted = false;
455
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -0700456 // Initialize gpu perfomance hint related parameters
457 property_get("sys.hwc.gpu_perf_mode", value, "0");
Saurabh Shah74eff4d2014-03-28 16:33:13 -0700458#ifdef QCOM_BSP
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -0700459 ctx->mGPUHintInfo.mGpuPerfModeEnable = atoi(value)? true : false;
460
461 ctx->mGPUHintInfo.mEGLDisplay = NULL;
462 ctx->mGPUHintInfo.mEGLContext = NULL;
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -0700463 ctx->mGPUHintInfo.mCompositionState = COMPOSITION_STATE_MDP;
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -0700464 ctx->mGPUHintInfo.mCurrGPUPerfMode = EGL_GPU_LEVEL_0;
Saurabh Shah74eff4d2014-03-28 16:33:13 -0700465#endif
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -0700466 // Read the system property to determine if windowboxing feature is enabled.
467 ctx->mWindowboxFeature = false;
468 if(property_get("sys.hwc.windowbox_feature", value, "false")
469 && !strcmp(value, "true")) {
470 ctx->mWindowboxFeature = true;
471 }
472
Raj Kamal0d53fc62014-11-25 17:36:36 +0530473 ctx->mUseMetaDataRefreshRate = true;
474 if(property_get("persist.metadata_dynfps.disable", value, "false")
475 && !strcmp(value, "true")) {
476 ctx->mUseMetaDataRefreshRate = false;
477 }
478
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700479 memset(&(ctx->mPtorInfo), 0, sizeof(ctx->mPtorInfo));
Arun Kumar K.R2225eaa2014-12-02 15:52:41 -0800480 ctx->mHPDEnabled = false;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700481 ALOGI("Initializing Qualcomm Hardware Composer");
Naseer Ahmed96c4c952012-07-25 18:27:14 -0700482 ALOGI("MDP version: %d", ctx->mMDP.version);
Arun Kumar K.R205df772015-02-20 18:45:58 -0800483
484 return 0;
485
486OpenFBError:
487 ALOGE("%s: Fatal Error: FB Open failed!!!", __FUNCTION__);
488 delete ctx->mHDMIDisplay;
489 return error;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700490}
491
492void closeContext(hwc_context_t *ctx)
493{
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500494 if(ctx->mOverlay) {
495 delete ctx->mOverlay;
496 ctx->mOverlay = NULL;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700497 }
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700498
Saurabh Shahacf10202013-02-26 10:15:15 -0800499 if(ctx->mRotMgr) {
500 delete ctx->mRotMgr;
501 ctx->mRotMgr = NULL;
502 }
503
Amara Venkata Mastan Manoj Kumar7fb13272013-07-01 13:59:34 -0700504 for(int i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800505 if(ctx->mCopyBit[i]) {
506 delete ctx->mCopyBit[i];
507 ctx->mCopyBit[i] = NULL;
508 }
509 }
510
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800511 if(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700512 close(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd);
513 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd = -1;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700514 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700515
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700516 if(ctx->mHDMIDisplay) {
517 delete ctx->mHDMIDisplay;
518 ctx->mHDMIDisplay = NULL;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700519 }
Naseer Ahmedff4f0252012-10-01 13:03:01 -0400520
Amara Venkata Mastan Manoj Kumar7fb13272013-07-01 13:59:34 -0700521 for(int i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700522 destroyCompositionResources(ctx, i);
523
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700524 if(ctx->mHwcDebug[i]) {
525 delete ctx->mHwcDebug[i];
526 ctx->mHwcDebug[i] = NULL;
527 }
Saurabh Shah23a813c2013-03-20 16:58:12 -0700528 if(ctx->mLayerRotMap[i]) {
529 delete ctx->mLayerRotMap[i];
530 ctx->mLayerRotMap[i] = NULL;
531 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800532 }
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -0800533 if(ctx->mHWCVirtual) {
534 delete ctx->mHWCVirtual;
535 ctx->mHWCVirtual = NULL;
536 }
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700537 if(ctx->mAD) {
538 delete ctx->mAD;
539 ctx->mAD = NULL;
540 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800541
Naseer Ahmed7a7b66d2014-07-23 17:56:26 -0400542 if(ctx->mQService) {
543 delete ctx->mQService;
544 ctx->mQService = NULL;
545 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700546}
547
Arun Kumar K.Ra727a882014-08-20 17:14:26 -0700548//Helper to roundoff the refreshrates
Raj Kamal0d53fc62014-11-25 17:36:36 +0530549uint32_t roundOff(uint32_t refreshRate) {
Arun Kumar K.Ra727a882014-08-20 17:14:26 -0700550 int count = (int) (sizeof(stdRefreshRates)/sizeof(stdRefreshRates[0]));
551 uint32_t rate = refreshRate;
552 for(int i=0; i< count; i++) {
553 if(abs(stdRefreshRates[i] - refreshRate) < 2) {
554 // Most likely used for video, the fps can fluctuate
555 // Ex: b/w 29 and 30 for 30 fps clip
556 rate = stdRefreshRates[i];
557 break;
558 }
559 }
560 return rate;
561}
562
563//Helper func to set the dyn fps
564void setRefreshRate(hwc_context_t* ctx, int dpy, uint32_t refreshRate) {
565 //Update only if different
566 if(!ctx || refreshRate == ctx->dpyAttr[dpy].dynRefreshRate)
567 return;
568 const int fbNum = Overlay::getFbForDpy(dpy);
569 char sysfsPath[qdutils::MAX_SYSFS_FILE_PATH];
570 snprintf (sysfsPath, sizeof(sysfsPath),
Arun Kumar K.Ree4e2392015-01-12 18:08:34 -0800571 "/sys/devices/virtual/graphics/fb%d/dynamic_fps", fbNum);
Arun Kumar K.Ra727a882014-08-20 17:14:26 -0700572
573 int fd = open(sysfsPath, O_WRONLY);
574 if(fd >= 0) {
575 char str[64];
576 snprintf(str, sizeof(str), "%d", refreshRate);
577 ssize_t ret = write(fd, str, strlen(str));
578 if(ret < 0) {
579 ALOGE("%s: Failed to write %d with error %s",
580 __FUNCTION__, refreshRate, strerror(errno));
581 } else {
582 ctx->dpyAttr[dpy].dynRefreshRate = refreshRate;
583 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Wrote %d to dynamic_fps",
584 __FUNCTION__, refreshRate);
585 }
586 close(fd);
587 } else {
588 ALOGE("%s: Failed to open %s with error %s", __FUNCTION__, sysfsPath,
589 strerror(errno));
590 }
591}
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500592
593void dumpsys_log(android::String8& buf, const char* fmt, ...)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700594{
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500595 va_list varargs;
596 va_start(varargs, fmt);
597 buf.appendFormatV(fmt, varargs);
598 va_end(varargs);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700599}
600
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700601int getExtOrientation(hwc_context_t* ctx) {
602 int extOrient = ctx->mExtOrientation;
603 if(ctx->mBufferMirrorMode)
604 extOrient = getMirrorModeOrientation(ctx);
605 return extOrient;
606}
607
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800608/* Calculates the destination position based on the action safe rectangle */
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700609void getActionSafePosition(hwc_context_t *ctx, int dpy, hwc_rect_t& rect) {
610 // Position
611 int x = rect.left, y = rect.top;
612 int w = rect.right - rect.left;
613 int h = rect.bottom - rect.top;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800614
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800615 if(!ctx->dpyAttr[dpy].mActionSafePresent)
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800616 return;
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800617 // Read action safe properties
618 int asWidthRatio = ctx->dpyAttr[dpy].mAsWidthRatio;
619 int asHeightRatio = ctx->dpyAttr[dpy].mAsHeightRatio;
Arun Kumar K.R82f1d282013-05-17 15:37:31 -0700620
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800621 float wRatio = 1.0;
622 float hRatio = 1.0;
623 float xRatio = 1.0;
624 float yRatio = 1.0;
625
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700626 uint32_t fbWidth = ctx->dpyAttr[dpy].xres;
627 uint32_t fbHeight = ctx->dpyAttr[dpy].yres;
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700628 if(ctx->dpyAttr[dpy].mMDPScalingMode) {
629 // if MDP scaling mode is enabled for external, need to query
Arun Kumar KR7b7f4012013-10-29 11:53:11 -0700630 // the actual width and height, as that is the physical w & h
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700631 ctx->mHDMIDisplay->getAttributes(fbWidth, fbHeight);
Arun Kumar KR7b7f4012013-10-29 11:53:11 -0700632 }
633
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800634
Arun Kumar K.R82f1d282013-05-17 15:37:31 -0700635 // Since external is rotated 90, need to swap width/height
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700636 int extOrient = getExtOrientation(ctx);
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700637
638 if(extOrient & HWC_TRANSFORM_ROT_90)
Arun Kumar K.R82f1d282013-05-17 15:37:31 -0700639 swap(fbWidth, fbHeight);
640
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800641 float asX = 0;
642 float asY = 0;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530643 float asW = (float)fbWidth;
644 float asH = (float)fbHeight;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800645
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800646 // based on the action safe ratio, get the Action safe rectangle
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530647 asW = ((float)fbWidth * (1.0f - (float)asWidthRatio / 100.0f));
648 asH = ((float)fbHeight * (1.0f - (float)asHeightRatio / 100.0f));
649 asX = ((float)fbWidth - asW) / 2;
650 asY = ((float)fbHeight - asH) / 2;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800651
652 // calculate the position ratio
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530653 xRatio = (float)x/(float)fbWidth;
654 yRatio = (float)y/(float)fbHeight;
655 wRatio = (float)w/(float)fbWidth;
656 hRatio = (float)h/(float)fbHeight;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800657
658 //Calculate the position...
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530659 x = int((xRatio * asW) + asX);
660 y = int((yRatio * asH) + asY);
661 w = int(wRatio * asW);
662 h = int(hRatio * asH);
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800663
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700664 // Convert it back to hwc_rect_t
665 rect.left = x;
666 rect.top = y;
667 rect.right = w + rect.left;
668 rect.bottom = h + rect.top;
669
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800670 return;
671}
672
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700673// This function gets the destination position for Seconday display
674// based on the position and aspect ratio with orientation
675void getAspectRatioPosition(hwc_context_t* ctx, int dpy, int extOrientation,
676 hwc_rect_t& inRect, hwc_rect_t& outRect) {
677 // Physical display resolution
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530678 float fbWidth = (float)ctx->dpyAttr[dpy].xres;
679 float fbHeight = (float)ctx->dpyAttr[dpy].yres;
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700680 //display position(x,y,w,h) in correct aspectratio after rotation
681 int xPos = 0;
682 int yPos = 0;
683 float width = fbWidth;
684 float height = fbHeight;
685 // Width/Height used for calculation, after rotation
686 float actualWidth = fbWidth;
687 float actualHeight = fbHeight;
688
689 float wRatio = 1.0;
690 float hRatio = 1.0;
691 float xRatio = 1.0;
692 float yRatio = 1.0;
693 hwc_rect_t rect = {0, 0, (int)fbWidth, (int)fbHeight};
694
695 Dim inPos(inRect.left, inRect.top, inRect.right - inRect.left,
696 inRect.bottom - inRect.top);
697 Dim outPos(outRect.left, outRect.top, outRect.right - outRect.left,
698 outRect.bottom - outRect.top);
699
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530700 Whf whf((uint32_t)fbWidth, (uint32_t)fbHeight, 0);
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700701 eTransform extorient = static_cast<eTransform>(extOrientation);
702 // To calculate the destination co-ordinates in the new orientation
703 preRotateSource(extorient, whf, inPos);
704
705 if(extOrientation & HAL_TRANSFORM_ROT_90) {
706 // Swap width/height for input position
707 swapWidthHeight(actualWidth, actualHeight);
Tatenda Chipeperekwace8d5c42014-08-13 10:53:49 -0700708 qdutils::getAspectRatioPosition((int)fbWidth, (int)fbHeight,
709 (int)actualWidth, (int)actualHeight, rect);
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700710 xPos = rect.left;
711 yPos = rect.top;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530712 width = float(rect.right - rect.left);
713 height = float(rect.bottom - rect.top);
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700714 }
Shalaj Jaina70b4352014-06-15 13:47:47 -0700715 xRatio = (float)((float)inPos.x/actualWidth);
716 yRatio = (float)((float)inPos.y/actualHeight);
717 wRatio = (float)((float)inPos.w/actualWidth);
718 hRatio = (float)((float)inPos.h/actualHeight);
Ramkumar Radhakrishnandebfc5a2013-12-04 15:15:42 -0800719
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530720 //Calculate the pos9ition...
721 outPos.x = uint32_t((xRatio * width) + (float)xPos);
722 outPos.y = uint32_t((yRatio * height) + (float)yPos);
723 outPos.w = uint32_t(wRatio * width);
724 outPos.h = uint32_t(hRatio * height);
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700725 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Calculated AspectRatio Position: x = %d,"
726 "y = %d w = %d h = %d", __FUNCTION__, outPos.x, outPos.y,
727 outPos.w, outPos.h);
728
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700729 // For sidesync, the dest fb will be in portrait orientation, and the crop
730 // will be updated to avoid the black side bands, and it will be upscaled
731 // to fit the dest RB, so recalculate
732 // the position based on the new width and height
733 if ((extOrientation & HWC_TRANSFORM_ROT_90) &&
734 isOrientationPortrait(ctx)) {
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800735 hwc_rect_t r = {0, 0, 0, 0};
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700736 //Calculate the position
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530737 xRatio = (float)(outPos.x - xPos)/width;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700738 // GetaspectRatio -- tricky to get the correct aspect ratio
739 // But we need to do this.
Tatenda Chipeperekwace8d5c42014-08-13 10:53:49 -0700740 qdutils::getAspectRatioPosition((int)width, (int)height,
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530741 (int)width,(int)height, r);
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700742 xPos = r.left;
743 yPos = r.top;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530744 float tempHeight = float(r.bottom - r.top);
745 yRatio = (float)yPos/height;
746 wRatio = (float)outPos.w/width;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700747 hRatio = tempHeight/height;
748
749 //Map the coordinates back to Framebuffer domain
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530750 outPos.x = uint32_t(xRatio * fbWidth);
751 outPos.y = uint32_t(yRatio * fbHeight);
752 outPos.w = uint32_t(wRatio * fbWidth);
753 outPos.h = uint32_t(hRatio * fbHeight);
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700754
755 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Calculated AspectRatio for device in"
756 "portrait: x = %d,y = %d w = %d h = %d", __FUNCTION__,
757 outPos.x, outPos.y,
758 outPos.w, outPos.h);
759 }
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700760 if(ctx->dpyAttr[dpy].mMDPScalingMode) {
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700761 uint32_t extW = 0, extH = 0;
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700762 if(dpy == HWC_DISPLAY_EXTERNAL) {
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700763 ctx->mHDMIDisplay->getAttributes(extW, extH);
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700764 } else if(dpy == HWC_DISPLAY_VIRTUAL) {
765 extW = ctx->mHWCVirtual->getScalingWidth();
766 extH = ctx->mHWCVirtual->getScalingHeight();
767 }
768 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Scaling mode extW=%d extH=%d",
769 __FUNCTION__, extW, extH);
770
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530771 fbWidth = (float)ctx->dpyAttr[dpy].xres;
772 fbHeight = (float)ctx->dpyAttr[dpy].yres;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700773 //Calculate the position...
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530774 xRatio = (float)outPos.x/fbWidth;
775 yRatio = (float)outPos.y/fbHeight;
776 wRatio = (float)outPos.w/fbWidth;
777 hRatio = (float)outPos.h/fbHeight;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700778
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530779 outPos.x = uint32_t(xRatio * (float)extW);
780 outPos.y = uint32_t(yRatio * (float)extH);
781 outPos.w = uint32_t(wRatio * (float)extW);
782 outPos.h = uint32_t(hRatio * (float)extH);
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700783 }
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700784 // Convert Dim to hwc_rect_t
785 outRect.left = outPos.x;
786 outRect.top = outPos.y;
787 outRect.right = outPos.x + outPos.w;
788 outRect.bottom = outPos.y + outPos.h;
789
790 return;
791}
792
793bool isPrimaryPortrait(hwc_context_t *ctx) {
794 int fbWidth = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
795 int fbHeight = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres;
796 if(fbWidth < fbHeight) {
797 return true;
798 }
799 return false;
800}
801
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700802bool isOrientationPortrait(hwc_context_t *ctx) {
803 if(isPrimaryPortrait(ctx)) {
804 return !(ctx->deviceOrientation & 0x1);
805 }
806 return (ctx->deviceOrientation & 0x1);
807}
808
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700809void calcExtDisplayPosition(hwc_context_t *ctx,
810 private_handle_t *hnd,
811 int dpy,
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700812 hwc_rect_t& sourceCrop,
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700813 hwc_rect_t& displayFrame,
814 int& transform,
815 ovutils::eTransform& orient) {
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700816 // Swap width and height when there is a 90deg transform
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700817 int extOrient = getExtOrientation(ctx);
Raj Kamal068f4572014-04-14 16:14:06 +0530818 if(dpy && ctx->mOverlay->isUIScalingOnExternalSupported()) {
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700819 if(!isYuvBuffer(hnd)) {
820 if(extOrient & HWC_TRANSFORM_ROT_90) {
821 int dstWidth = ctx->dpyAttr[dpy].xres;
822 int dstHeight = ctx->dpyAttr[dpy].yres;;
823 int srcWidth = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
824 int srcHeight = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres;
825 if(!isPrimaryPortrait(ctx)) {
826 swap(srcWidth, srcHeight);
827 } // Get Aspect Ratio for external
Tatenda Chipeperekwace8d5c42014-08-13 10:53:49 -0700828 qdutils::getAspectRatioPosition(dstWidth, dstHeight, srcWidth,
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700829 srcHeight, displayFrame);
830 // Crop - this is needed, because for sidesync, the dest fb will
831 // be in portrait orientation, so update the crop to not show the
832 // black side bands.
833 if (isOrientationPortrait(ctx)) {
834 sourceCrop = displayFrame;
835 displayFrame.left = 0;
836 displayFrame.top = 0;
837 displayFrame.right = dstWidth;
838 displayFrame.bottom = dstHeight;
839 }
840 }
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700841 if(ctx->dpyAttr[dpy].mMDPScalingMode) {
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700842 uint32_t extW = 0, extH = 0;
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700843 // if MDP scaling mode is enabled, map the co-ordinates to new
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700844 // domain(downscaled)
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530845 float fbWidth = (float)ctx->dpyAttr[dpy].xres;
846 float fbHeight = (float)ctx->dpyAttr[dpy].yres;
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700847 // query MDP configured attributes
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700848 if(dpy == HWC_DISPLAY_EXTERNAL) {
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700849 ctx->mHDMIDisplay->getAttributes(extW, extH);
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700850 } else if(dpy == HWC_DISPLAY_VIRTUAL) {
851 extW = ctx->mHWCVirtual->getScalingWidth();
852 extH = ctx->mHWCVirtual->getScalingHeight();
853 }
854 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Scaling mode extW=%d extH=%d",
855 __FUNCTION__, extW, extH);
856
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700857 //Calculate the ratio...
858 float wRatio = ((float)extW)/fbWidth;
859 float hRatio = ((float)extH)/fbHeight;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700860
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700861 //convert Dim to hwc_rect_t
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530862 displayFrame.left = int(wRatio*(float)displayFrame.left);
863 displayFrame.top = int(hRatio*(float)displayFrame.top);
864 displayFrame.right = int(wRatio*(float)displayFrame.right);
865 displayFrame.bottom = int(hRatio*(float)displayFrame.bottom);
Ramkumar Radhakrishnana5c72872014-08-28 19:04:18 -0700866 ALOGD_IF(DEBUG_MDPDOWNSCALE, "Calculated external display frame"
867 " for MDPDownscale feature [%d %d %d %d]",
868 displayFrame.left, displayFrame.top,
869 displayFrame.right, displayFrame.bottom);
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700870 }
871 }else {
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700872 if(extOrient || ctx->dpyAttr[dpy].mMDPScalingMode) {
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700873 getAspectRatioPosition(ctx, dpy, extOrient,
874 displayFrame, displayFrame);
875 }
876 }
877 // If there is a external orientation set, use that
878 if(extOrient) {
879 transform = extOrient;
880 orient = static_cast<ovutils::eTransform >(extOrient);
881 }
882 // Calculate the actionsafe dimensions for External(dpy = 1 or 2)
883 getActionSafePosition(ctx, dpy, displayFrame);
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700884 }
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700885}
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700886
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700887/* Returns the orientation which needs to be set on External for
888 * SideSync/Buffer Mirrormode
889 */
890int getMirrorModeOrientation(hwc_context_t *ctx) {
891 int extOrientation = 0;
892 int deviceOrientation = ctx->deviceOrientation;
893 if(!isPrimaryPortrait(ctx))
894 deviceOrientation = (deviceOrientation + 1) % 4;
895 if (deviceOrientation == 0)
896 extOrientation = HWC_TRANSFORM_ROT_270;
897 else if (deviceOrientation == 1)//90
898 extOrientation = 0;
899 else if (deviceOrientation == 2)//180
900 extOrientation = HWC_TRANSFORM_ROT_90;
901 else if (deviceOrientation == 3)//270
902 extOrientation = HWC_TRANSFORM_FLIP_V | HWC_TRANSFORM_FLIP_H;
903
904 return extOrientation;
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700905}
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700906
Raj kamal59fea562014-04-01 16:52:19 +0530907/* Get External State names */
908const char* getExternalDisplayState(uint32_t external_state) {
909 static const char* externalStates[EXTERNAL_MAXSTATES] = {0};
910 externalStates[EXTERNAL_OFFLINE] = STR(EXTERNAL_OFFLINE);
911 externalStates[EXTERNAL_ONLINE] = STR(EXTERNAL_ONLINE);
912 externalStates[EXTERNAL_PAUSE] = STR(EXTERNAL_PAUSE);
913 externalStates[EXTERNAL_RESUME] = STR(EXTERNAL_RESUME);
914
915 if(external_state >= EXTERNAL_MAXSTATES) {
916 return "EXTERNAL_INVALID";
917 }
918
919 return externalStates[external_state];
920}
921
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530922bool isDownscaleRequired(hwc_layer_1_t const* layer) {
923 hwc_rect_t displayFrame = layer->displayFrame;
924 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
925 int dst_w, dst_h, src_w, src_h;
926 dst_w = displayFrame.right - displayFrame.left;
927 dst_h = displayFrame.bottom - displayFrame.top;
928 src_w = sourceCrop.right - sourceCrop.left;
929 src_h = sourceCrop.bottom - sourceCrop.top;
930
931 if(((src_w > dst_w) || (src_h > dst_h)))
932 return true;
933
934 return false;
935}
936bool needsScaling(hwc_layer_1_t const* layer) {
Naseer Ahmed018e5452012-12-03 14:46:15 -0500937 int dst_w, dst_h, src_w, src_h;
Naseer Ahmed018e5452012-12-03 14:46:15 -0500938 hwc_rect_t displayFrame = layer->displayFrame;
Saurabh Shah62e1d732013-09-17 10:44:05 -0700939 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
Naseer Ahmed018e5452012-12-03 14:46:15 -0500940
941 dst_w = displayFrame.right - displayFrame.left;
942 dst_h = displayFrame.bottom - displayFrame.top;
Naseer Ahmed018e5452012-12-03 14:46:15 -0500943 src_w = sourceCrop.right - sourceCrop.left;
944 src_h = sourceCrop.bottom - sourceCrop.top;
945
Jeykumar Sankaran6a339522014-11-04 16:14:43 -0800946 if(layer->transform & HWC_TRANSFORM_ROT_90)
947 swap(src_w, src_h);
948
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800949 if(((src_w != dst_w) || (src_h != dst_h)))
950 return true;
951
952 return false;
953}
954
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700955// Checks if layer needs scaling with split
956bool needsScalingWithSplit(hwc_context_t* ctx, hwc_layer_1_t const* layer,
957 const int& dpy) {
958
959 int src_width_l, src_height_l;
960 int src_width_r, src_height_r;
961 int dst_width_l, dst_height_l;
962 int dst_width_r, dst_height_r;
963 int hw_w = ctx->dpyAttr[dpy].xres;
964 int hw_h = ctx->dpyAttr[dpy].yres;
965 hwc_rect_t cropL, dstL, cropR, dstR;
966 const int lSplit = getLeftSplit(ctx, dpy);
Saurabh Shah62e1d732013-09-17 10:44:05 -0700967 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700968 hwc_rect_t displayFrame = layer->displayFrame;
969 private_handle_t *hnd = (private_handle_t *)layer->handle;
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700970
971 cropL = sourceCrop;
972 dstL = displayFrame;
973 hwc_rect_t scissorL = { 0, 0, lSplit, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -0800974 scissorL = getIntersection(ctx->mViewFrame[dpy], scissorL);
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700975 qhwc::calculate_crop_rects(cropL, dstL, scissorL, 0);
976
977 cropR = sourceCrop;
978 dstR = displayFrame;
979 hwc_rect_t scissorR = { lSplit, 0, hw_w, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -0800980 scissorR = getIntersection(ctx->mViewFrame[dpy], scissorR);
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700981 qhwc::calculate_crop_rects(cropR, dstR, scissorR, 0);
982
983 // Sanitize Crop to stitch
984 sanitizeSourceCrop(cropL, cropR, hnd);
985
986 // Calculate the left dst
987 dst_width_l = dstL.right - dstL.left;
988 dst_height_l = dstL.bottom - dstL.top;
989 src_width_l = cropL.right - cropL.left;
990 src_height_l = cropL.bottom - cropL.top;
991
992 // check if there is any scaling on the left
993 if(((src_width_l != dst_width_l) || (src_height_l != dst_height_l)))
994 return true;
995
996 // Calculate the right dst
997 dst_width_r = dstR.right - dstR.left;
998 dst_height_r = dstR.bottom - dstR.top;
999 src_width_r = cropR.right - cropR.left;
1000 src_height_r = cropR.bottom - cropR.top;
1001
1002 // check if there is any scaling on the right
1003 if(((src_width_r != dst_width_r) || (src_height_r != dst_height_r)))
1004 return true;
1005
1006 return false;
1007}
1008
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301009bool isAlphaScaled(hwc_layer_1_t const* layer) {
1010 if(needsScaling(layer) && isAlphaPresent(layer)) {
Sravan Kumar D.V.N075ef002013-03-20 05:22:26 +05301011 return true;
1012 }
1013 return false;
1014}
1015
1016bool isAlphaPresent(hwc_layer_1_t const* layer) {
1017 private_handle_t *hnd = (private_handle_t *)layer->handle;
Naseer Ahmed7a4287c2013-03-26 18:11:41 -04001018 if(hnd) {
1019 int format = hnd->format;
1020 switch(format) {
Sravan Kumar D.V.N075ef002013-03-20 05:22:26 +05301021 case HAL_PIXEL_FORMAT_RGBA_8888:
1022 case HAL_PIXEL_FORMAT_BGRA_8888:
1023 // In any more formats with Alpha go here..
Naseer Ahmed018e5452012-12-03 14:46:15 -05001024 return true;
Sravan Kumar D.V.N075ef002013-03-20 05:22:26 +05301025 default : return false;
Naseer Ahmed7a4287c2013-03-26 18:11:41 -04001026 }
Naseer Ahmed018e5452012-12-03 14:46:15 -05001027 }
1028 return false;
1029}
1030
radhakrishnac3198ff2015-03-10 17:10:02 +05301031bool isAlphaPresentinFB(hwc_context_t *ctx, int dpy) {
1032 switch(ctx->dpyAttr[dpy].fbformat) {
1033 case HAL_PIXEL_FORMAT_RGBA_8888:
1034 case HAL_PIXEL_FORMAT_BGRA_8888:
1035 return true;
1036 default : return false;
1037 }
1038 return false;
1039}
1040
Saurabh Shahd9ff30b2013-10-03 16:37:06 -07001041static void trimLayer(hwc_context_t *ctx, const int& dpy, const int& transform,
1042 hwc_rect_t& crop, hwc_rect_t& dst) {
1043 int hw_w = ctx->dpyAttr[dpy].xres;
1044 int hw_h = ctx->dpyAttr[dpy].yres;
1045 if(dst.left < 0 || dst.top < 0 ||
1046 dst.right > hw_w || dst.bottom > hw_h) {
1047 hwc_rect_t scissor = {0, 0, hw_w, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -08001048 scissor = getIntersection(ctx->mViewFrame[dpy], scissor);
Saurabh Shahd9ff30b2013-10-03 16:37:06 -07001049 qhwc::calculate_crop_rects(crop, dst, scissor, transform);
1050 }
1051}
1052
1053static void trimList(hwc_context_t *ctx, hwc_display_contents_1_t *list,
1054 const int& dpy) {
1055 for(uint32_t i = 0; i < list->numHwLayers - 1; i++) {
1056 hwc_layer_1_t *layer = &list->hwLayers[i];
1057 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Sushil Chauhanfda00fc2014-03-20 11:08:41 -07001058 int transform = (list->hwLayers[i].flags & HWC_COLOR_FILL) ? 0 :
1059 list->hwLayers[i].transform;
Saurabh Shahd9ff30b2013-10-03 16:37:06 -07001060 trimLayer(ctx, dpy,
Sushil Chauhanfda00fc2014-03-20 11:08:41 -07001061 transform,
Saurabh Shahd9ff30b2013-10-03 16:37:06 -07001062 (hwc_rect_t&)crop,
1063 (hwc_rect_t&)list->hwLayers[i].displayFrame);
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301064 layer->sourceCropf.left = (float)crop.left;
1065 layer->sourceCropf.right = (float)crop.right;
1066 layer->sourceCropf.top = (float)crop.top;
1067 layer->sourceCropf.bottom = (float)crop.bottom;
Saurabh Shahd9ff30b2013-10-03 16:37:06 -07001068 }
1069}
1070
Saurabh Shah3e858eb2012-09-17 16:53:21 -07001071void setListStats(hwc_context_t *ctx,
Saurabh Shahd9ff30b2013-10-03 16:37:06 -07001072 hwc_display_contents_1_t *list, int dpy) {
Saurabh Shahd4e65852013-06-17 11:33:53 -07001073 const int prevYuvCount = ctx->listStats[dpy].yuvCount;
1074 memset(&ctx->listStats[dpy], 0, sizeof(ListStats));
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301075 ctx->listStats[dpy].numAppLayers = (int)list->numHwLayers - 1;
1076 ctx->listStats[dpy].fbLayerIndex = (int)list->numHwLayers - 1;
Saurabh Shahc4d034f2012-09-27 15:55:15 -07001077 ctx->listStats[dpy].skipCount = 0;
Sravan Kumar D.V.Nb5ed0292013-03-15 08:51:16 +05301078 ctx->listStats[dpy].preMultipliedAlpha = false;
Saurabh Shah8028e3b2013-10-15 12:27:59 -07001079 ctx->listStats[dpy].isSecurePresent = false;
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001080 ctx->listStats[dpy].yuvCount = 0;
Ping Li9404e2a2013-04-24 16:36:03 -04001081 char property[PROPERTY_VALUE_MAX];
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001082 ctx->listStats[dpy].isDisplayAnimating = false;
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -07001083 ctx->listStats[dpy].secureUI = false;
radhakrishnac9a67412013-09-25 17:40:42 +05301084 ctx->listStats[dpy].yuv4k2kCount = 0;
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -08001085 ctx->dpyAttr[dpy].mActionSafePresent = isActionSafePresent(ctx, dpy);
Ramakant Singh0def28c2014-03-28 20:43:13 +05301086 ctx->listStats[dpy].renderBufIndexforABC = -1;
Ramkumar Radhakrishnan4ec775f2014-07-23 17:43:18 -07001087 ctx->listStats[dpy].secureRGBCount = 0;
Arun Kumar K.Ra727a882014-08-20 17:14:26 -07001088 ctx->listStats[dpy].refreshRateRequest = ctx->dpyAttr[dpy].refreshRate;
Arun Kumar K.R00b84792015-03-27 11:28:36 -07001089 ctx->listStats[dpy].cursorLayerPresent = false;
Arun Kumar K.Ra727a882014-08-20 17:14:26 -07001090 uint32_t refreshRate = 0;
1091 qdutils::MDPVersion& mdpHw = qdutils::MDPVersion::getInstance();
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -05001092 int s3dFormat = HAL_NO_3D;
1093 int s3dLayerCount = 0;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001094
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07001095 ctx->listStats[dpy].mAIVVideoMode = false;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001096 resetROI(ctx, dpy);
1097
Sushil Chauhanf68d0df2014-04-09 09:15:37 -07001098 trimList(ctx, list, dpy);
1099 optimizeLayerRects(list);
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -07001100 for (size_t i = 0; i < (size_t)ctx->listStats[dpy].numAppLayers; i++) {
Naseer Ahmed018e5452012-12-03 14:46:15 -05001101 hwc_layer_1_t const* layer = &list->hwLayers[i];
1102 private_handle_t *hnd = (private_handle_t *)layer->handle;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001103
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001104#ifdef QCOM_BSP
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07001105 // Window boxing feature is applicable obly for external display, So
1106 // enable mAIVVideoMode only for external display
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07001107 if(ctx->mWindowboxFeature && dpy && isAIVVideoLayer(layer)) {
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07001108 ctx->listStats[dpy].mAIVVideoMode = true;
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07001109 }
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001110 if (layer->flags & HWC_SCREENSHOT_ANIMATOR_LAYER) {
1111 ctx->listStats[dpy].isDisplayAnimating = true;
1112 }
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -07001113 if(isSecureDisplayBuffer(hnd)) {
1114 ctx->listStats[dpy].secureUI = true;
1115 }
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001116#endif
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -07001117 // continue if number of app layers exceeds MAX_NUM_APP_LAYERS
1118 if(ctx->listStats[dpy].numAppLayers > MAX_NUM_APP_LAYERS)
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001119 continue;
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001120
Arun Kumar K.R00b84792015-03-27 11:28:36 -07001121 // Valid cursor must be the top most layer
1122 if((int)i == (ctx->listStats[dpy].numAppLayers - 1) &&
1123 isCursorLayer(&list->hwLayers[i])) {
1124 ctx->listStats[dpy].cursorLayerPresent = true;
1125 }
1126
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -07001127 //reset yuv indices
1128 ctx->listStats[dpy].yuvIndices[i] = -1;
radhakrishnac9a67412013-09-25 17:40:42 +05301129 ctx->listStats[dpy].yuv4k2kIndices[i] = -1;
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -07001130
Saurabh Shah8028e3b2013-10-15 12:27:59 -07001131 if (isSecureBuffer(hnd)) {
1132 ctx->listStats[dpy].isSecurePresent = true;
Ramkumar Radhakrishnan4ec775f2014-07-23 17:43:18 -07001133 if(not isYuvBuffer(hnd)) {
1134 // cache secureRGB layer parameters like we cache for YUV layers
1135 int& secureRGBCount = ctx->listStats[dpy].secureRGBCount;
1136 ctx->listStats[dpy].secureRGBIndices[secureRGBCount] = (int)i;
1137 secureRGBCount++;
1138 }
Saurabh Shah8028e3b2013-10-15 12:27:59 -07001139 }
1140
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -07001141 if (isSkipLayer(&list->hwLayers[i])) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -07001142 ctx->listStats[dpy].skipCount++;
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001143 }
1144
1145 if (UNLIKELY(isYuvBuffer(hnd))) {
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001146 int& yuvCount = ctx->listStats[dpy].yuvCount;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301147 ctx->listStats[dpy].yuvIndices[yuvCount] = (int)i;
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001148 yuvCount++;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001149
Raj Kamal389d6e32014-08-04 14:43:24 +05301150 if(UNLIKELY(isYUVSplitNeeded(hnd))){
radhakrishnac9a67412013-09-25 17:40:42 +05301151 int& yuv4k2kCount = ctx->listStats[dpy].yuv4k2kCount;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301152 ctx->listStats[dpy].yuv4k2kIndices[yuv4k2kCount] = (int)i;
radhakrishnac9a67412013-09-25 17:40:42 +05301153 yuv4k2kCount++;
1154 }
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -05001155
1156 // Gets set if one YUV layer is 3D
1157 if (displaySupports3D(ctx,dpy)) {
1158 s3dFormat = get3DFormat(hnd);
1159 if(s3dFormat != HAL_NO_3D)
1160 s3dLayerCount++;
1161 }
1162
Naseer Ahmed29a26812012-06-14 00:56:20 -07001163 }
Sravan Kumar D.V.Nb5ed0292013-03-15 08:51:16 +05301164 if(layer->blending == HWC_BLENDING_PREMULT)
1165 ctx->listStats[dpy].preMultipliedAlpha = true;
Jeykumar Sankaran7535aba2013-02-04 11:03:09 -08001166
Arun Kumar K.Ra727a882014-08-20 17:14:26 -07001167#ifdef DYNAMIC_FPS
Raj Kamal0d53fc62014-11-25 17:36:36 +05301168 if (!dpy && mdpHw.isDynFpsSupported() && ctx->mUseMetaDataRefreshRate){
Arun Kumar K.Ra727a882014-08-20 17:14:26 -07001169 //dyn fps: get refreshrate from metadata
1170 //Support multiple refresh rates if they are same
1171 //else set to default
1172 MetaData_t *mdata = hnd ? (MetaData_t *)hnd->base_metadata : NULL;
1173 if (mdata && (mdata->operation & UPDATE_REFRESH_RATE)) {
1174 // Valid refreshRate in metadata and within the range
1175 uint32_t rate = roundOff(mdata->refreshrate);
1176 if((rate >= mdpHw.getMinFpsSupported() &&
1177 rate <= mdpHw.getMaxFpsSupported())) {
1178 if (!refreshRate) {
1179 refreshRate = rate;
1180 } else if(refreshRate != rate) {
1181 // multiple refreshrate requests, set to default
1182 refreshRate = ctx->dpyAttr[dpy].refreshRate;
1183 }
1184 }
1185 }
1186 }
1187#endif
Naseer Ahmed29a26812012-06-14 00:56:20 -07001188 }
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -05001189
1190 //Set the TV's 3D mode based on format if it was not forced
1191 //Only one 3D YUV layer is supported on external
1192 //If there is more than one 3D YUV layer, the switch to 3D cannot occur.
1193 if( !ctx->dpyAttr[dpy].s3dModeForced && (s3dLayerCount <= 1)) {
1194 //XXX: Rapidly going in and out of 3D mode in some cases such
1195 // as rotation might cause flickers. The OEMs are recommended to disable
1196 // rotation on HDMI globally or in the app that plays 3D video
1197 setup3DMode(ctx, dpy, convertS3DFormatToMode(s3dFormat));
1198 }
1199
Ping Li9404e2a2013-04-24 16:36:03 -04001200 if(ctx->listStats[dpy].yuvCount > 0) {
1201 if (property_get("hw.cabl.yuv", property, NULL) > 0) {
1202 if (atoi(property) != 1) {
1203 property_set("hw.cabl.yuv", "1");
1204 }
1205 }
1206 } else {
1207 if (property_get("hw.cabl.yuv", property, NULL) > 0) {
1208 if (atoi(property) != 0) {
1209 property_set("hw.cabl.yuv", "0");
1210 }
1211 }
1212 }
Saurabh Shahd4e65852013-06-17 11:33:53 -07001213
1214 //The marking of video begin/end is useful on some targets where we need
1215 //to have a padding round to be able to shift pipes across mixers.
1216 if(prevYuvCount != ctx->listStats[dpy].yuvCount) {
1217 ctx->mVideoTransFlag = true;
1218 }
Raj Kamal9ed3d6b2014-02-07 16:15:17 +05301219
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001220 if(dpy == HWC_DISPLAY_PRIMARY) {
1221 ctx->mAD->markDoable(ctx, list);
Arun Kumar K.Ra727a882014-08-20 17:14:26 -07001222 //Store the requested fresh rate
1223 ctx->listStats[dpy].refreshRateRequest = refreshRate ?
1224 refreshRate : ctx->dpyAttr[dpy].refreshRate;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001225 }
Naseer Ahmed29a26812012-06-14 00:56:20 -07001226}
1227
Naseer Ahmed018e5452012-12-03 14:46:15 -05001228
Saurabh Shah68107422013-07-09 11:12:42 -07001229static void calc_cut(double& leftCutRatio, double& topCutRatio,
1230 double& rightCutRatio, double& bottomCutRatio, int orient) {
Saurabh Shah27c1d652012-08-14 19:30:28 -07001231 if(orient & HAL_TRANSFORM_FLIP_H) {
Saurabh Shah541b59d2012-10-11 11:08:12 -07001232 swap(leftCutRatio, rightCutRatio);
Saurabh Shah27c1d652012-08-14 19:30:28 -07001233 }
1234 if(orient & HAL_TRANSFORM_FLIP_V) {
Saurabh Shah541b59d2012-10-11 11:08:12 -07001235 swap(topCutRatio, bottomCutRatio);
Saurabh Shah27c1d652012-08-14 19:30:28 -07001236 }
1237 if(orient & HAL_TRANSFORM_ROT_90) {
1238 //Anti clock swapping
Saurabh Shah68107422013-07-09 11:12:42 -07001239 double tmpCutRatio = leftCutRatio;
Saurabh Shah541b59d2012-10-11 11:08:12 -07001240 leftCutRatio = topCutRatio;
1241 topCutRatio = rightCutRatio;
1242 rightCutRatio = bottomCutRatio;
1243 bottomCutRatio = tmpCutRatio;
Saurabh Shah27c1d652012-08-14 19:30:28 -07001244 }
1245}
1246
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001247bool isSecuring(hwc_context_t* ctx, hwc_layer_1_t const* layer) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001248 if((ctx->mMDP.version < qdutils::MDSS_V5) &&
1249 (ctx->mMDP.version > qdutils::MDP_V3_0) &&
1250 ctx->mSecuring) {
1251 return true;
1252 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001253 if (isSecureModePolicy(ctx->mMDP.version)) {
1254 private_handle_t *hnd = (private_handle_t *)layer->handle;
1255 if(ctx->mSecureMode) {
1256 if (! isSecureBuffer(hnd)) {
1257 ALOGD_IF(HWC_UTILS_DEBUG,"%s:Securing Turning ON ...",
1258 __FUNCTION__);
1259 return true;
1260 }
1261 } else {
1262 if (isSecureBuffer(hnd)) {
1263 ALOGD_IF(HWC_UTILS_DEBUG,"%s:Securing Turning OFF ...",
1264 __FUNCTION__);
1265 return true;
1266 }
1267 }
1268 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001269 return false;
1270}
1271
Sushil Chauhan2515abf2013-01-08 16:40:05 -08001272bool isSecureModePolicy(int mdpVersion) {
1273 if (mdpVersion < qdutils::MDSS_V5)
1274 return true;
1275 else
1276 return false;
1277}
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001278
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001279bool isRotatorSupportedFormat(private_handle_t *hnd) {
1280 // Following rotator src formats are supported by mdp driver
1281 // TODO: Add more formats in future, if mdp driver adds support
Ramkumar Radhakrishnan629cbf52014-10-14 19:36:33 -07001282 if(hnd != NULL) {
1283 switch(hnd->format) {
1284 case HAL_PIXEL_FORMAT_RGBA_8888:
Ramkumar Radhakrishnanb8eb16d2014-10-09 13:54:07 -07001285 case HAL_PIXEL_FORMAT_RGBA_5551:
1286 case HAL_PIXEL_FORMAT_RGBA_4444:
Ramkumar Radhakrishnan629cbf52014-10-14 19:36:33 -07001287 case HAL_PIXEL_FORMAT_RGB_565:
1288 case HAL_PIXEL_FORMAT_RGB_888:
1289 case HAL_PIXEL_FORMAT_BGRA_8888:
1290 return true;
1291 default:
1292 return false;
1293 }
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001294 }
1295 return false;
1296}
1297
1298bool isRotationDoable(hwc_context_t *ctx, private_handle_t *hnd) {
Ramkumar Radhakrishnan629cbf52014-10-14 19:36:33 -07001299 // Rotate layers, if it is not secure display buffer and not
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001300 // for the MDP versions below MDP5
Ramkumar Radhakrishnan629cbf52014-10-14 19:36:33 -07001301 if((!isSecureDisplayBuffer(hnd) && isRotatorSupportedFormat(hnd) &&
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001302 !ctx->mMDP.version < qdutils::MDSS_V5)
1303 || isYuvBuffer(hnd)) {
1304 return true;
1305 }
1306 return false;
1307}
1308
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -08001309// returns true if Action safe dimensions are set and target supports Actionsafe
1310bool isActionSafePresent(hwc_context_t *ctx, int dpy) {
1311 // if external supports underscan, do nothing
1312 // it will be taken care in the driver
Ramkumar Radhakrishnana61a0da2014-03-03 14:46:21 -08001313 // Disable Action safe for 8974 due to HW limitation for downscaling
1314 // layers with overlapped region
1315 // Disable Actionsafe for non HDMI displays.
1316 if(!(dpy == HWC_DISPLAY_EXTERNAL) ||
1317 qdutils::MDPVersion::getInstance().is8x74v2() ||
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -07001318 ctx->mHDMIDisplay->isCEUnderscanSupported()) {
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -08001319 return false;
Ramkumar Radhakrishnana61a0da2014-03-03 14:46:21 -08001320 }
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -08001321
1322 char value[PROPERTY_VALUE_MAX];
1323 // Read action safe properties
1324 property_get("persist.sys.actionsafe.width", value, "0");
1325 ctx->dpyAttr[dpy].mAsWidthRatio = atoi(value);
1326 property_get("persist.sys.actionsafe.height", value, "0");
1327 ctx->dpyAttr[dpy].mAsHeightRatio = atoi(value);
1328
1329 if(!ctx->dpyAttr[dpy].mAsWidthRatio && !ctx->dpyAttr[dpy].mAsHeightRatio) {
1330 //No action safe ratio set, return
1331 return false;
1332 }
1333 return true;
1334}
1335
Naseer Ahmed522ce662013-03-18 20:14:05 -04001336int getBlending(int blending) {
1337 switch(blending) {
1338 case HWC_BLENDING_NONE:
1339 return overlay::utils::OVERLAY_BLENDING_OPAQUE;
1340 case HWC_BLENDING_PREMULT:
1341 return overlay::utils::OVERLAY_BLENDING_PREMULT;
1342 case HWC_BLENDING_COVERAGE :
1343 default:
1344 return overlay::utils::OVERLAY_BLENDING_COVERAGE;
1345 }
1346}
1347
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001348//Crops source buffer against destination and FB boundaries
1349void calculate_crop_rects(hwc_rect_t& crop, hwc_rect_t& dst,
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001350 const hwc_rect_t& scissor, int orient) {
1351
Saurabh Shah27c1d652012-08-14 19:30:28 -07001352 int& crop_l = crop.left;
1353 int& crop_t = crop.top;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001354 int& crop_r = crop.right;
1355 int& crop_b = crop.bottom;
1356 int crop_w = crop.right - crop.left;
1357 int crop_h = crop.bottom - crop.top;
1358
Saurabh Shah27c1d652012-08-14 19:30:28 -07001359 int& dst_l = dst.left;
1360 int& dst_t = dst.top;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001361 int& dst_r = dst.right;
1362 int& dst_b = dst.bottom;
Saurabh Shah27c1d652012-08-14 19:30:28 -07001363 int dst_w = abs(dst.right - dst.left);
1364 int dst_h = abs(dst.bottom - dst.top);
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001365
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001366 const int& sci_l = scissor.left;
1367 const int& sci_t = scissor.top;
1368 const int& sci_r = scissor.right;
1369 const int& sci_b = scissor.bottom;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001370
Saurabh Shah68107422013-07-09 11:12:42 -07001371 double leftCutRatio = 0.0, rightCutRatio = 0.0, topCutRatio = 0.0,
1372 bottomCutRatio = 0.0;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001373
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001374 if(dst_l < sci_l) {
Saurabh Shah68107422013-07-09 11:12:42 -07001375 leftCutRatio = (double)(sci_l - dst_l) / (double)dst_w;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001376 dst_l = sci_l;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001377 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001378
1379 if(dst_r > sci_r) {
Saurabh Shah68107422013-07-09 11:12:42 -07001380 rightCutRatio = (double)(dst_r - sci_r) / (double)dst_w;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001381 dst_r = sci_r;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001382 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001383
1384 if(dst_t < sci_t) {
Saurabh Shah68107422013-07-09 11:12:42 -07001385 topCutRatio = (double)(sci_t - dst_t) / (double)dst_h;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001386 dst_t = sci_t;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001387 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001388
1389 if(dst_b > sci_b) {
Saurabh Shah68107422013-07-09 11:12:42 -07001390 bottomCutRatio = (double)(dst_b - sci_b) / (double)dst_h;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001391 dst_b = sci_b;
Naseer Ahmed29a26812012-06-14 00:56:20 -07001392 }
Saurabh Shah27c1d652012-08-14 19:30:28 -07001393
Saurabh Shah541b59d2012-10-11 11:08:12 -07001394 calc_cut(leftCutRatio, topCutRatio, rightCutRatio, bottomCutRatio, orient);
Dileep Kumar Reddi39e79bf2014-03-06 11:56:10 +05301395 crop_l += (int)round((double)crop_w * leftCutRatio);
1396 crop_t += (int)round((double)crop_h * topCutRatio);
1397 crop_r -= (int)round((double)crop_w * rightCutRatio);
1398 crop_b -= (int)round((double)crop_h * bottomCutRatio);
Naseer Ahmed29a26812012-06-14 00:56:20 -07001399}
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001400
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301401bool areLayersIntersecting(const hwc_layer_1_t* layer1,
1402 const hwc_layer_1_t* layer2) {
1403 hwc_rect_t irect = getIntersection(layer1->displayFrame,
1404 layer2->displayFrame);
1405 return isValidRect(irect);
1406}
1407
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001408bool isSameRect(const hwc_rect& rect1, const hwc_rect& rect2)
1409{
1410 return ((rect1.left == rect2.left) && (rect1.top == rect2.top) &&
1411 (rect1.right == rect2.right) && (rect1.bottom == rect2.bottom));
1412}
1413
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001414bool isValidRect(const hwc_rect& rect)
1415{
1416 return ((rect.bottom > rect.top) && (rect.right > rect.left)) ;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301417}
1418
Ramakant Singh21cec722014-03-07 19:11:45 +05301419bool operator ==(const hwc_rect_t& lhs, const hwc_rect_t& rhs) {
1420 if(lhs.left == rhs.left && lhs.top == rhs.top &&
1421 lhs.right == rhs.right && lhs.bottom == rhs.bottom )
1422 return true ;
1423 return false;
1424}
1425
Jeykumar Sankaran71e597c2014-05-07 16:23:14 -07001426hwc_rect_t moveRect(const hwc_rect_t& rect, const int& x_off, const int& y_off)
1427{
1428 hwc_rect_t res;
1429
1430 if(!isValidRect(rect))
1431 return (hwc_rect_t){0, 0, 0, 0};
1432
1433 res.left = rect.left + x_off;
1434 res.top = rect.top + y_off;
1435 res.right = rect.right + x_off;
1436 res.bottom = rect.bottom + y_off;
1437
1438 return res;
1439}
1440
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001441/* computes the intersection of two rects */
1442hwc_rect_t getIntersection(const hwc_rect_t& rect1, const hwc_rect_t& rect2)
1443{
1444 hwc_rect_t res;
1445
1446 if(!isValidRect(rect1) || !isValidRect(rect2)){
1447 return (hwc_rect_t){0, 0, 0, 0};
1448 }
1449
1450
1451 res.left = max(rect1.left, rect2.left);
1452 res.top = max(rect1.top, rect2.top);
1453 res.right = min(rect1.right, rect2.right);
1454 res.bottom = min(rect1.bottom, rect2.bottom);
1455
1456 if(!isValidRect(res))
1457 return (hwc_rect_t){0, 0, 0, 0};
1458
1459 return res;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301460}
1461
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001462/* computes the union of two rects */
1463hwc_rect_t getUnion(const hwc_rect &rect1, const hwc_rect &rect2)
1464{
1465 hwc_rect_t res;
1466
1467 if(!isValidRect(rect1)){
1468 return rect2;
1469 }
1470
1471 if(!isValidRect(rect2)){
1472 return rect1;
1473 }
1474
1475 res.left = min(rect1.left, rect2.left);
1476 res.top = min(rect1.top, rect2.top);
1477 res.right = max(rect1.right, rect2.right);
1478 res.bottom = max(rect1.bottom, rect2.bottom);
1479
1480 return res;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301481}
1482
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001483/* Not a geometrical rect deduction. Deducts rect2 from rect1 only if it results
1484 * a single rect */
1485hwc_rect_t deductRect(const hwc_rect_t& rect1, const hwc_rect_t& rect2) {
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301486
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001487 hwc_rect_t res = rect1;
1488
1489 if((rect1.left == rect2.left) && (rect1.right == rect2.right)) {
1490 if((rect1.top == rect2.top) && (rect2.bottom <= rect1.bottom))
1491 res.top = rect2.bottom;
1492 else if((rect1.bottom == rect2.bottom)&& (rect2.top >= rect1.top))
1493 res.bottom = rect2.top;
1494 }
1495 else if((rect1.top == rect2.top) && (rect1.bottom == rect2.bottom)) {
1496 if((rect1.left == rect2.left) && (rect2.right <= rect1.right))
1497 res.left = rect2.right;
1498 else if((rect1.right == rect2.right)&& (rect2.left >= rect1.left))
1499 res.right = rect2.left;
1500 }
1501 return res;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301502}
1503
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001504void optimizeLayerRects(const hwc_display_contents_1_t *list) {
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301505 int i= (int)list->numHwLayers-2;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301506 while(i > 0) {
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301507 //see if there is no blending required.
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001508 //If it is opaque see if we can substract this region from below
1509 //layers.
radhakrishna4efbdd62014-11-03 13:19:27 +05301510 if(list->hwLayers[i].blending == HWC_BLENDING_NONE &&
1511 list->hwLayers[i].planeAlpha == 0xFF) {
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301512 int j= i-1;
1513 hwc_rect_t& topframe =
1514 (hwc_rect_t&)list->hwLayers[i].displayFrame;
1515 while(j >= 0) {
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301516 if(!needsScaling(&list->hwLayers[j])) {
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001517 hwc_layer_1_t* layer = (hwc_layer_1_t*)&list->hwLayers[j];
1518 hwc_rect_t& bottomframe = layer->displayFrame;
Jeykumar Sankaran071468b2014-01-14 17:21:49 -08001519 hwc_rect_t bottomCrop =
1520 integerizeSourceCrop(layer->sourceCropf);
Sushil Chauhanfda00fc2014-03-20 11:08:41 -07001521 int transform = (layer->flags & HWC_COLOR_FILL) ? 0 :
1522 layer->transform;
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001523
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001524 hwc_rect_t irect = getIntersection(bottomframe, topframe);
1525 if(isValidRect(irect)) {
Jeykumar Sankaran1b3da402013-12-04 16:22:34 -08001526 hwc_rect_t dest_rect;
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001527 //if intersection is valid rect, deduct it
Jeykumar Sankaran1b3da402013-12-04 16:22:34 -08001528 dest_rect = deductRect(bottomframe, irect);
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001529 qhwc::calculate_crop_rects(bottomCrop, bottomframe,
Jeykumar Sankaran1b3da402013-12-04 16:22:34 -08001530 dest_rect, transform);
Jeykumar Sankaran071468b2014-01-14 17:21:49 -08001531 //Update layer sourceCropf
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301532 layer->sourceCropf.left =(float)bottomCrop.left;
1533 layer->sourceCropf.top = (float)bottomCrop.top;
1534 layer->sourceCropf.right = (float)bottomCrop.right;
1535 layer->sourceCropf.bottom = (float)bottomCrop.bottom;
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08001536#ifdef QCOM_BSP
1537 //Update layer dirtyRect
1538 layer->dirtyRect = getIntersection(bottomCrop,
1539 layer->dirtyRect);
1540#endif
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001541 }
1542 }
1543 j--;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301544 }
1545 }
1546 i--;
1547 }
1548}
1549
Naseer Ahmed64b81212013-02-14 10:29:47 -05001550void getNonWormholeRegion(hwc_display_contents_1_t* list,
1551 hwc_rect_t& nwr)
1552{
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301553 size_t last = list->numHwLayers - 1;
Naseer Ahmed64b81212013-02-14 10:29:47 -05001554 hwc_rect_t fbDisplayFrame = list->hwLayers[last].displayFrame;
1555 //Initiliaze nwr to first frame
1556 nwr.left = list->hwLayers[0].displayFrame.left;
1557 nwr.top = list->hwLayers[0].displayFrame.top;
1558 nwr.right = list->hwLayers[0].displayFrame.right;
1559 nwr.bottom = list->hwLayers[0].displayFrame.bottom;
1560
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301561 for (size_t i = 1; i < last; i++) {
Naseer Ahmed64b81212013-02-14 10:29:47 -05001562 hwc_rect_t displayFrame = list->hwLayers[i].displayFrame;
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001563 nwr = getUnion(nwr, displayFrame);
Naseer Ahmed64b81212013-02-14 10:29:47 -05001564 }
1565
1566 //Intersect with the framebuffer
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001567 nwr = getIntersection(nwr, fbDisplayFrame);
Naseer Ahmed64b81212013-02-14 10:29:47 -05001568}
1569
Saurabh Shah747af1e2013-02-26 10:25:12 -08001570void closeAcquireFds(hwc_display_contents_1_t* list) {
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08001571 if(LIKELY(list)) {
1572 for(uint32_t i = 0; i < list->numHwLayers; i++) {
1573 //Close the acquireFenceFds
1574 //HWC_FRAMEBUFFER are -1 already by SF, rest we close.
1575 if(list->hwLayers[i].acquireFenceFd >= 0) {
1576 close(list->hwLayers[i].acquireFenceFd);
1577 list->hwLayers[i].acquireFenceFd = -1;
1578 }
1579 }
1580 //Writeback
1581 if(list->outbufAcquireFenceFd >= 0) {
1582 close(list->outbufAcquireFenceFd);
1583 list->outbufAcquireFenceFd = -1;
Saurabh Shah747af1e2013-02-26 10:25:12 -08001584 }
1585 }
1586}
1587
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001588int hwc_sync(hwc_context_t *ctx, hwc_display_contents_1_t* list, int dpy,
Saurabh Shah23a813c2013-03-20 16:58:12 -07001589 int fd) {
Naseer Ahmed099a6932013-09-09 14:25:20 -04001590 ATRACE_CALL();
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001591 int ret = 0;
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001592 int acquireFd[MAX_NUM_APP_LAYERS];
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001593 int count = 0;
1594 int releaseFd = -1;
Arun Kumar K.R51835182013-11-19 11:20:28 -08001595 int retireFd = -1;
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001596 int fbFd = -1;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001597 bool swapzero = false;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001598
1599 struct mdp_buf_sync data;
1600 memset(&data, 0, sizeof(data));
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001601 data.acq_fen_fd = acquireFd;
1602 data.rel_fen_fd = &releaseFd;
Arun Kumar K.R51835182013-11-19 11:20:28 -08001603 data.retire_fen_fd = &retireFd;
1604 data.flags = MDP_BUF_SYNC_FLAG_RETIRE_FENCE;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001605
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001606 char property[PROPERTY_VALUE_MAX];
1607 if(property_get("debug.egl.swapinterval", property, "1") > 0) {
1608 if(atoi(property) == 0)
1609 swapzero = true;
1610 }
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001611
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001612 bool isExtAnimating = false;
1613 if(dpy)
1614 isExtAnimating = ctx->listStats[dpy].isDisplayAnimating;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001615
Saurabh Shah23a813c2013-03-20 16:58:12 -07001616 //Send acquireFenceFds to rotator
Saurabh Shah23a813c2013-03-20 16:58:12 -07001617 for(uint32_t i = 0; i < ctx->mLayerRotMap[dpy]->getCount(); i++) {
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001618 int rotFd = ctx->mRotMgr->getRotDevFd();
1619 int rotReleaseFd = -1;
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001620 overlay::Rotator* currRot = ctx->mLayerRotMap[dpy]->getRot(i);
1621 hwc_layer_1_t* currLayer = ctx->mLayerRotMap[dpy]->getLayer(i);
1622 if((currRot == NULL) || (currLayer == NULL)) {
1623 continue;
1624 }
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001625 struct mdp_buf_sync rotData;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001626 memset(&rotData, 0, sizeof(rotData));
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001627 rotData.acq_fen_fd =
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001628 &currLayer->acquireFenceFd;
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001629 rotData.rel_fen_fd = &rotReleaseFd; //driver to populate this
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001630 rotData.session_id = currRot->getSessId();
Saurabh Shah25c04d32014-05-05 10:16:02 -07001631 if(currLayer->acquireFenceFd >= 0) {
1632 rotData.acq_fen_fd_cnt = 1; //1 ioctl call per rot session
1633 }
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001634 int ret = 0;
Raj Kamal4b02b742014-10-12 20:51:14 +05301635 if(LIKELY(!swapzero) and (not ctx->mLayerRotMap[dpy]->isRotCached(i)))
Raj Kamalbd3bdc62014-08-05 18:52:49 +05301636 ret = ioctl(rotFd, MSMFB_BUFFER_SYNC, &rotData);
1637
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001638 if(ret < 0) {
1639 ALOGE("%s: ioctl MSMFB_BUFFER_SYNC failed for rot sync, err=%s",
1640 __FUNCTION__, strerror(errno));
Tatenda Chipeperekwaa4550ce2014-06-06 15:25:37 -07001641 close(rotReleaseFd);
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001642 } else {
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001643 close(currLayer->acquireFenceFd);
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001644 //For MDP to wait on.
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001645 currLayer->acquireFenceFd =
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001646 dup(rotReleaseFd);
1647 //A buffer is free to be used by producer as soon as its copied to
1648 //rotator
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001649 currLayer->releaseFenceFd =
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001650 rotReleaseFd;
1651 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001652 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001653
Balamurugan Thanikachalamf558c862014-01-31 18:23:20 +05301654 //Accumulate acquireFenceFds for MDP Overlays
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08001655 if(list->outbufAcquireFenceFd >= 0) {
1656 //Writeback output buffer
Raj Kamal4b02b742014-10-12 20:51:14 +05301657 if(LIKELY(!swapzero) )
1658 acquireFd[count++] = list->outbufAcquireFenceFd;
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08001659 }
1660
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001661 for(uint32_t i = 0; i < list->numHwLayers; i++) {
Ramakant Singh0def28c2014-03-28 20:43:13 +05301662 if(((isAbcInUse(ctx)== true ) ||
1663 (list->hwLayers[i].compositionType == HWC_OVERLAY)) &&
Saurabh Shah23a813c2013-03-20 16:58:12 -07001664 list->hwLayers[i].acquireFenceFd >= 0) {
Raj Kamal4b02b742014-10-12 20:51:14 +05301665 if(LIKELY(!swapzero) ) {
1666 // if ABC is enabled for more than one layer.
1667 // renderBufIndexforABC will work as FB.Hence
1668 // set the acquireFD from fd - which is coming from copybit
1669 if(fd >= 0 && (isAbcInUse(ctx) == true)) {
1670 if(ctx->listStats[dpy].renderBufIndexforABC ==(int32_t)i)
1671 acquireFd[count++] = fd;
1672 else
1673 continue;
1674 } else
1675 acquireFd[count++] = list->hwLayers[i].acquireFenceFd;
1676 }
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001677 }
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001678 if(list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) {
Raj Kamal4b02b742014-10-12 20:51:14 +05301679 if(LIKELY(!swapzero) ) {
1680 if(fd >= 0) {
1681 //set the acquireFD from fd - which is coming from c2d
1682 acquireFd[count++] = fd;
1683 // Buffer sync IOCTL should be async when using c2d fence is
1684 // used
1685 data.flags &= ~MDP_BUF_SYNC_FLAG_WAIT;
1686 } else if(list->hwLayers[i].acquireFenceFd >= 0)
1687 acquireFd[count++] = list->hwLayers[i].acquireFenceFd;
1688 }
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001689 }
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001690 }
1691
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -07001692 if ((fd >= 0) && !dpy && ctx->mPtorInfo.isActive()) {
Sushil Chauhandefd3522014-05-13 18:17:12 -07001693 // Acquire c2d fence of Overlap render buffer
Raj Kamal4b02b742014-10-12 20:51:14 +05301694 if(LIKELY(!swapzero) )
1695 acquireFd[count++] = fd;
Sushil Chauhandefd3522014-05-13 18:17:12 -07001696 }
1697
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001698 data.acq_fen_fd_cnt = count;
1699 fbFd = ctx->dpyAttr[dpy].fd;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001700
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001701 //Waits for acquire fences, returns a release fence
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001702 if(LIKELY(!swapzero)) {
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001703 ret = ioctl(fbFd, MSMFB_BUFFER_SYNC, &data);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001704 }
Saurabh Shah747af1e2013-02-26 10:25:12 -08001705
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001706 if(ret < 0) {
Ramkumar Radhakrishnanb32a0bc2013-04-11 17:57:32 -07001707 ALOGE("%s: ioctl MSMFB_BUFFER_SYNC failed, err=%s",
1708 __FUNCTION__, strerror(errno));
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301709 ALOGE("%s: acq_fen_fd_cnt=%d flags=%d fd=%d dpy=%d numHwLayers=%zu",
Ramkumar Radhakrishnanb32a0bc2013-04-11 17:57:32 -07001710 __FUNCTION__, data.acq_fen_fd_cnt, data.flags, fbFd,
1711 dpy, list->numHwLayers);
Tatenda Chipeperekwaa4550ce2014-06-06 15:25:37 -07001712 close(releaseFd);
1713 releaseFd = -1;
1714 close(retireFd);
1715 retireFd = -1;
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001716 }
Saurabh Shah747af1e2013-02-26 10:25:12 -08001717
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001718 for(uint32_t i = 0; i < list->numHwLayers; i++) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001719 if(list->hwLayers[i].compositionType == HWC_OVERLAY ||
Saurabh Shah74eff4d2014-03-28 16:33:13 -07001720#ifdef QCOM_BSP
Terence Hampsonc67b0372013-10-09 11:32:21 -04001721 list->hwLayers[i].compositionType == HWC_BLIT ||
Saurabh Shah74eff4d2014-03-28 16:33:13 -07001722#endif
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001723 list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) {
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001724 //Populate releaseFenceFds.
Saurabh Shah23a813c2013-03-20 16:58:12 -07001725 if(UNLIKELY(swapzero)) {
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001726 list->hwLayers[i].releaseFenceFd = -1;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001727 } else if(isExtAnimating) {
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001728 // Release all the app layer fds immediately,
1729 // if animation is in progress.
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -07001730 list->hwLayers[i].releaseFenceFd = -1;
Naseer Ahmed330a2822014-03-05 11:57:23 -05001731 } else if(list->hwLayers[i].releaseFenceFd < 0 ) {
Saurabh Shah74eff4d2014-03-28 16:33:13 -07001732#ifdef QCOM_BSP
Zohaib Alam1bb65612013-09-28 03:38:20 -04001733 //If rotator has not already populated this field
Ramakant Singh0def28c2014-03-28 20:43:13 +05301734 // & if it's a not VPU layer
Ramakant Singh467759f2014-04-16 11:09:40 +05301735
1736 // if ABC is enabled for more than one layer
1737 if(fd >= 0 && (isAbcInUse(ctx) == true) &&
1738 ctx->listStats[dpy].renderBufIndexforABC !=(int32_t)i){
1739 list->hwLayers[i].releaseFenceFd = dup(fd);
1740 } else if((list->hwLayers[i].compositionType == HWC_BLIT)&&
1741 (isAbcInUse(ctx) == false)){
1742 //For Blit, the app layers should be released when the Blit
1743 //is complete. This fd was passed from copybit->draw
Balamurugan Thanikachalamf558c862014-01-31 18:23:20 +05301744 list->hwLayers[i].releaseFenceFd = dup(fd);
Saurabh Shah74eff4d2014-03-28 16:33:13 -07001745 } else
1746#endif
1747 {
Balamurugan Thanikachalamf558c862014-01-31 18:23:20 +05301748 list->hwLayers[i].releaseFenceFd = dup(releaseFd);
1749 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001750 }
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001751 }
1752 }
Saurabh Shah747af1e2013-02-26 10:25:12 -08001753
1754 if(fd >= 0) {
1755 close(fd);
1756 fd = -1;
1757 }
1758
Sushil Chauhanfb8845c2014-07-22 12:42:07 -07001759 if (ctx->mCopyBit[dpy]) {
1760 if (!dpy && ctx->mPtorInfo.isActive())
Sushil Chauhandefd3522014-05-13 18:17:12 -07001761 ctx->mCopyBit[dpy]->setReleaseFdSync(releaseFd);
1762 else
1763 ctx->mCopyBit[dpy]->setReleaseFd(releaseFd);
1764 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001765
Saurabh Shah23a813c2013-03-20 16:58:12 -07001766 //Signals when MDP finishes reading rotator buffers.
1767 ctx->mLayerRotMap[dpy]->setReleaseFd(releaseFd);
Arun Kumar K.R51835182013-11-19 11:20:28 -08001768 close(releaseFd);
1769 releaseFd = -1;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001770
Arun Kumar K.R51835182013-11-19 11:20:28 -08001771 if(UNLIKELY(swapzero)) {
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001772 list->retireFenceFd = -1;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001773 } else {
Arun Kumar K.R51835182013-11-19 11:20:28 -08001774 list->retireFenceFd = retireFd;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001775 }
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001776 return ret;
1777}
1778
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001779void setMdpFlags(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shahacf10202013-02-26 10:15:15 -08001780 ovutils::eMdpFlags &mdpFlags,
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001781 int rotDownscale, int transform) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001782 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shah220a30c2013-10-29 16:12:12 -07001783 MetaData_t *metadata = hnd ? (MetaData_t *)hnd->base_metadata : NULL;
Saurabh Shahacf10202013-02-26 10:15:15 -08001784
1785 if(layer->blending == HWC_BLENDING_PREMULT) {
1786 ovutils::setMdpFlags(mdpFlags,
1787 ovutils::OV_MDP_BLEND_FG_PREMULT);
1788 }
1789
Ramkumar Radhakrishnan4ec775f2014-07-23 17:43:18 -07001790 if(metadata && (metadata->operation & PP_PARAM_INTERLACED) &&
1791 metadata->interlaced) {
1792 ovutils::setMdpFlags(mdpFlags,
1793 ovutils::OV_MDP_DEINTERLACE);
1794 }
1795
1796 // Mark MDP flags with SECURE_OVERLAY_SESSION for driver
1797 if(isSecureBuffer(hnd)) {
1798 ovutils::setMdpFlags(mdpFlags,
1799 ovutils::OV_MDP_SECURE_OVERLAY_SESSION);
Justin Philipd6166602014-08-12 13:42:21 +05301800 ovutils::setMdpFlags(mdpFlags,
1801 ovutils::OV_MDP_SMP_FORCE_ALLOC);
1802 }
1803
1804 if(isProtectedBuffer(hnd)) {
1805 ovutils::setMdpFlags(mdpFlags,
1806 ovutils::OV_MDP_SMP_FORCE_ALLOC);
Saurabh Shahacf10202013-02-26 10:15:15 -08001807 }
1808
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -07001809 if(isSecureDisplayBuffer(hnd)) {
Ramkumar Radhakrishnan4ec775f2014-07-23 17:43:18 -07001810 // Mark MDP flags with SECURE_DISPLAY_OVERLAY_SESSION for driver
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -07001811 ovutils::setMdpFlags(mdpFlags,
1812 ovutils::OV_MDP_SECURE_DISPLAY_OVERLAY_SESSION);
1813 }
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001814
1815 //Pre-rotation will be used using rotator.
1816 if(has90Transform(layer) && isRotationDoable(ctx, hnd)) {
1817 ovutils::setMdpFlags(mdpFlags,
1818 ovutils::OV_MDP_SOURCE_ROTATED_90);
1819 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001820 //No 90 component and no rot-downscale then flips done by MDP
1821 //If we use rot then it might as well do flips
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001822 if(!(transform & HWC_TRANSFORM_ROT_90) && !rotDownscale) {
1823 if(transform & HWC_TRANSFORM_FLIP_H) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001824 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_FLIP_H);
1825 }
1826
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001827 if(transform & HWC_TRANSFORM_FLIP_V) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001828 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_FLIP_V);
1829 }
1830 }
Saurabh Shah5daeee52013-01-23 16:52:26 +08001831
1832 if(metadata &&
1833 ((metadata->operation & PP_PARAM_HSIC)
1834 || (metadata->operation & PP_PARAM_IGC)
1835 || (metadata->operation & PP_PARAM_SHARP2))) {
1836 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_PP_EN);
1837 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001838}
1839
Prabhanjan Kandulaa1d83012013-04-23 13:06:02 +05301840int configRotator(Rotator *rot, Whf& whf,
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001841 hwc_rect_t& crop, const eMdpFlags& mdpFlags,
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001842 const eTransform& orient, const int& downscale) {
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001843
Prabhanjan Kandulaa1d83012013-04-23 13:06:02 +05301844 // Fix alignments for TILED format
1845 if(whf.format == MDP_Y_CRCB_H2V2_TILE ||
1846 whf.format == MDP_Y_CBCR_H2V2_TILE) {
1847 whf.w = utils::alignup(whf.w, 64);
1848 whf.h = utils::alignup(whf.h, 32);
1849 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001850 rot->setSource(whf);
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001851
1852 if (qdutils::MDPVersion::getInstance().getMDPVersion() >=
1853 qdutils::MDSS_V5) {
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001854 Dim rotCrop(crop.left, crop.top, crop.right - crop.left,
1855 crop.bottom - crop.top);
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001856 rot->setCrop(rotCrop);
1857 }
1858
Saurabh Shahacf10202013-02-26 10:15:15 -08001859 rot->setFlags(mdpFlags);
1860 rot->setTransform(orient);
1861 rot->setDownscale(downscale);
1862 if(!rot->commit()) return -1;
1863 return 0;
1864}
1865
Saurabh Shahe2474082013-05-15 16:32:13 -07001866int configMdp(Overlay *ov, const PipeArgs& parg,
Saurabh Shahacf10202013-02-26 10:15:15 -08001867 const eTransform& orient, const hwc_rect_t& crop,
Saurabh Shah5daeee52013-01-23 16:52:26 +08001868 const hwc_rect_t& pos, const MetaData_t *metadata,
1869 const eDest& dest) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001870 ov->setSource(parg, dest);
1871 ov->setTransform(orient, dest);
1872
1873 int crop_w = crop.right - crop.left;
1874 int crop_h = crop.bottom - crop.top;
1875 Dim dcrop(crop.left, crop.top, crop_w, crop_h);
1876 ov->setCrop(dcrop, dest);
1877
1878 int posW = pos.right - pos.left;
1879 int posH = pos.bottom - pos.top;
1880 Dim position(pos.left, pos.top, posW, posH);
1881 ov->setPosition(position, dest);
1882
Saurabh Shah5daeee52013-01-23 16:52:26 +08001883 if (metadata)
1884 ov->setVisualParams(*metadata, dest);
1885
Saurabh Shahacf10202013-02-26 10:15:15 -08001886 if (!ov->commit(dest)) {
1887 return -1;
1888 }
1889 return 0;
1890}
1891
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001892int configColorLayer(hwc_context_t *ctx, hwc_layer_1_t *layer,
1893 const int& dpy, eMdpFlags& mdpFlags, eZorder& z,
Saurabh Shah2c8ad052014-08-15 13:27:46 -07001894 const eDest& dest) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001895
1896 hwc_rect_t dst = layer->displayFrame;
1897 trimLayer(ctx, dpy, 0, dst, dst);
1898
1899 int w = ctx->dpyAttr[dpy].xres;
1900 int h = ctx->dpyAttr[dpy].yres;
1901 int dst_w = dst.right - dst.left;
1902 int dst_h = dst.bottom - dst.top;
1903 uint32_t color = layer->transform;
Sushil Chauhan65e26302015-01-14 10:48:57 -08001904 Whf whf(w, h, getMdpFormat(HAL_PIXEL_FORMAT_RGBA_8888));
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001905
Sushil Chauhanf10c5232013-12-19 10:35:54 -08001906 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_SOLID_FILL);
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001907 if (layer->blending == HWC_BLENDING_PREMULT)
1908 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_BLEND_FG_PREMULT);
1909
Saurabh Shah2c8ad052014-08-15 13:27:46 -07001910 PipeArgs parg(mdpFlags, whf, z, static_cast<eRotFlags>(0),
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001911 layer->planeAlpha,
1912 (ovutils::eBlending) getBlending(layer->blending));
1913
1914 // Configure MDP pipe for Color layer
1915 Dim pos(dst.left, dst.top, dst_w, dst_h);
1916 ctx->mOverlay->setSource(parg, dest);
1917 ctx->mOverlay->setColor(color, dest);
1918 ctx->mOverlay->setTransform(0, dest);
1919 ctx->mOverlay->setCrop(pos, dest);
1920 ctx->mOverlay->setPosition(pos, dest);
1921
1922 if (!ctx->mOverlay->commit(dest)) {
1923 ALOGE("%s: Configure color layer failed!", __FUNCTION__);
1924 return -1;
1925 }
1926 return 0;
1927}
1928
Saurabh Shahe2474082013-05-15 16:32:13 -07001929void updateSource(eTransform& orient, Whf& whf,
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001930 hwc_rect_t& crop, Rotator *rot) {
1931 Dim transformedCrop(crop.left, crop.top,
Saurabh Shahacf10202013-02-26 10:15:15 -08001932 crop.right - crop.left,
1933 crop.bottom - crop.top);
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001934 if (qdutils::MDPVersion::getInstance().getMDPVersion() >=
1935 qdutils::MDSS_V5) {
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001936 //B-family rotator internally could modify destination dimensions if
1937 //downscaling is supported
1938 whf = rot->getDstWhf();
1939 transformedCrop = rot->getDstDimensions();
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001940 } else {
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001941 //A-family rotator rotates entire buffer irrespective of crop, forcing
1942 //us to recompute the crop based on transform
1943 orient = static_cast<eTransform>(ovutils::getMdpOrient(orient));
1944 preRotateSource(orient, whf, transformedCrop);
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001945 }
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001946
1947 crop.left = transformedCrop.x;
1948 crop.top = transformedCrop.y;
1949 crop.right = transformedCrop.x + transformedCrop.w;
1950 crop.bottom = transformedCrop.y + transformedCrop.h;
Saurabh Shahacf10202013-02-26 10:15:15 -08001951}
1952
Arun Kumar K.R00b84792015-03-27 11:28:36 -07001953bool configHwCursor(const int fd, int dpy, hwc_layer_1_t* layer) {
1954 if(dpy > HWC_DISPLAY_PRIMARY) {
1955 // HWCursor not supported on secondary displays
1956 return false;
1957 }
1958 private_handle_t *hnd = (private_handle_t *)layer->handle;
1959 hwc_rect dst = layer->displayFrame;
1960 hwc_rect src = integerizeSourceCrop(layer->sourceCropf);
1961 int srcW = src.right - src.left;
1962 int srcH = src.bottom - src.top;
1963 int dstW = dst.right - dst.left;
1964 int dstH = dst.bottom - dst.top;
1965
1966 Whf whf(getWidth(hnd), getHeight(hnd), hnd->format);
1967 Dim crop(src.left, src.top, srcW, srcH);
1968 Dim dest(dst.left, dst.top, dstW, dstH);
1969
1970 ovutils::PipeArgs pargs(ovutils::OV_MDP_FLAGS_NONE,
1971 whf,
1972 Z_SYSTEM_ALLOC,
1973 ovutils::ROT_FLAGS_NONE,
1974 layer->planeAlpha,
1975 (ovutils::eBlending)
1976 getBlending(layer->blending));
1977
1978 ALOGD_IF(HWC_UTILS_DEBUG, "%s: CursorInfo: w = %d h = %d "
1979 "crop [%d, %d, %d, %d] dst [%d, %d, %d, %d]", __FUNCTION__,
1980 getWidth(hnd), getHeight(hnd), src.left, src.top, srcW, srcH,
1981 dst.left, dst.top, dstW, dstH);
1982
1983 return HWCursor::getInstance()->config(fd, (void*)hnd->base, pargs,
1984 crop, dest);
1985}
1986
1987void freeHwCursor(const int fd, int dpy) {
1988 if (dpy == HWC_DISPLAY_PRIMARY) {
1989 HWCursor::getInstance()->free(fd);
1990 }
1991}
1992
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07001993int getRotDownscale(hwc_context_t *ctx, const hwc_layer_1_t *layer) {
1994 if(not qdutils::MDPVersion::getInstance().isRotDownscaleEnabled()) {
1995 return 0;
1996 }
1997
1998 int downscale = 0;
1999 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
2000 hwc_rect_t dst = layer->displayFrame;
2001 private_handle_t *hnd = (private_handle_t *)layer->handle;
2002
2003 if(not hnd) {
2004 return 0;
2005 }
2006
2007 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
2008 bool isInterlaced = metadata && (metadata->operation & PP_PARAM_INTERLACED)
2009 && metadata->interlaced;
2010 int transform = layer->transform;
Sushil Chauhan65e26302015-01-14 10:48:57 -08002011 uint32_t format = ovutils::getMdpFormat(hnd->format, hnd->flags);
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002012
2013 if(isYuvBuffer(hnd)) {
2014 if(ctx->mMDP.version >= qdutils::MDP_V4_2 &&
2015 ctx->mMDP.version < qdutils::MDSS_V5) {
2016 downscale = Rotator::getDownscaleFactor(crop.right - crop.left,
2017 crop.bottom - crop.top, dst.right - dst.left,
2018 dst.bottom - dst.top, format, isInterlaced);
2019 } else {
2020 Dim adjCrop(crop.left, crop.top, crop.right - crop.left,
2021 crop.bottom - crop.top);
2022 Dim pos(dst.left, dst.top, dst.right - dst.left,
2023 dst.bottom - dst.top);
2024 if(transform & HAL_TRANSFORM_ROT_90) {
2025 swap(adjCrop.w, adjCrop.h);
2026 }
2027 downscale = Rotator::getDownscaleFactor(adjCrop.w, adjCrop.h, pos.w,
2028 pos.h, format, isInterlaced);
2029 }
2030 }
2031 return downscale;
2032}
2033
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002034bool isZoomModeEnabled(hwc_rect_t crop) {
2035 // This does not work for zooming in top left corner of the image
2036 return(crop.top > 0 || crop.left > 0);
2037}
2038
2039void updateCropAIVVideoMode(hwc_context_t *ctx, hwc_rect_t& crop, int dpy) {
2040 ALOGD_IF(HWC_UTILS_DEBUG, "dpy %d Source crop [%d %d %d %d]", dpy,
2041 crop.left, crop.top, crop.right, crop.bottom);
2042 if(isZoomModeEnabled(crop)) {
2043 Dim srcCrop(crop.left, crop.top,
2044 crop.right - crop.left,
2045 crop.bottom - crop.top);
2046 int extW = ctx->dpyAttr[dpy].xres;
2047 int extH = ctx->dpyAttr[dpy].yres;
2048 //Crop the original video in order to fit external display aspect ratio
2049 if(srcCrop.w * extH < extW * srcCrop.h) {
2050 int offset = (srcCrop.h - ((srcCrop.w * extH) / extW)) / 2;
2051 crop.top += offset;
2052 crop.bottom -= offset;
2053 } else {
2054 int offset = (srcCrop.w - ((extW * srcCrop.h) / extH)) / 2;
2055 crop.left += offset;
2056 crop.right -= offset;
2057 }
2058 ALOGD_IF(HWC_UTILS_DEBUG, "External Resolution [%d %d] dpy %d Modified"
2059 " source crop [%d %d %d %d]", extW, extH, dpy,
2060 crop.left, crop.top, crop.right, crop.bottom);
2061 }
2062}
2063
2064void updateDestAIVVideoMode(hwc_context_t *ctx, hwc_rect_t crop,
2065 hwc_rect_t& dst, int dpy) {
2066 ALOGD_IF(HWC_UTILS_DEBUG, "dpy %d Destination position [%d %d %d %d]", dpy,
2067 dst.left, dst.top, dst.right, dst.bottom);
2068 Dim srcCrop(crop.left, crop.top,
2069 crop.right - crop.left,
2070 crop.bottom - crop.top);
2071 int extW = ctx->dpyAttr[dpy].xres;
2072 int extH = ctx->dpyAttr[dpy].yres;
2073 // Set the destination coordinates of external display to full screen,
Ramkumar Radhakrishnan812999a2014-09-11 21:42:07 -07002074 // when zoom in mode is enabled or the ratio between video aspect ratio
2075 // and external display aspect ratio is below the minimum tolerance level
2076 // and above maximum tolerance level
2077 float videoAspectRatio = ((float)srcCrop.w / (float)srcCrop.h);
2078 float extDisplayAspectRatio = ((float)extW / (float)extH);
2079 float videoToExternalRatio = videoAspectRatio / extDisplayAspectRatio;
2080 if((fabs(1.0f - videoToExternalRatio) <= ctx->mAspectRatioToleranceLevel) ||
2081 (isZoomModeEnabled(crop))) {
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002082 dst.left = 0;
2083 dst.top = 0;
2084 dst.right = extW;
2085 dst.bottom = extH;
2086 }
2087 ALOGD_IF(HWC_UTILS_DEBUG, "External Resolution [%d %d] dpy %d Modified"
2088 " Destination position [%d %d %d %d] Source crop [%d %d %d %d]",
2089 extW, extH, dpy, dst.left, dst.top, dst.right, dst.bottom,
2090 crop.left, crop.top, crop.right, crop.bottom);
2091}
2092
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07002093void updateCoordinates(hwc_context_t *ctx, hwc_rect_t& crop,
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002094 hwc_rect_t& dst, int dpy) {
2095 updateCropAIVVideoMode(ctx, crop, dpy);
2096 updateDestAIVVideoMode(ctx, crop, dst, dpy);
2097}
2098
Saurabh Shah88e4d272013-09-03 13:31:29 -07002099int configureNonSplit(hwc_context_t *ctx, hwc_layer_1_t *layer,
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07002100 const int& dpy, eMdpFlags& mdpFlags, eZorder& z,
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002101 const eDest& dest, Rotator **rot) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002102
2103 private_handle_t *hnd = (private_handle_t *)layer->handle;
Sushil Chauhan897a9c32013-07-18 11:09:55 -07002104
Saurabh Shahacf10202013-02-26 10:15:15 -08002105 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07002106 if (layer->flags & HWC_COLOR_FILL) {
2107 // Configure Color layer
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002108 return configColorLayer(ctx, layer, dpy, mdpFlags, z, dest);
Sushil Chauhan897a9c32013-07-18 11:09:55 -07002109 }
Saurabh Shahacf10202013-02-26 10:15:15 -08002110 ALOGE("%s: layer handle is NULL", __FUNCTION__);
2111 return -1;
2112 }
2113
Saurabh Shah5daeee52013-01-23 16:52:26 +08002114 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
2115
Saurabh Shah62e1d732013-09-17 10:44:05 -07002116 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shahacf10202013-02-26 10:15:15 -08002117 hwc_rect_t dst = layer->displayFrame;
2118 int transform = layer->transform;
2119 eTransform orient = static_cast<eTransform>(transform);
Saurabh Shahacf10202013-02-26 10:15:15 -08002120 int rotFlags = ovutils::ROT_FLAGS_NONE;
Sushil Chauhan65e26302015-01-14 10:48:57 -08002121 uint32_t format = ovutils::getMdpFormat(hnd->format, hnd->flags);
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05302122 Whf whf(getWidth(hnd), getHeight(hnd), format, (uint32_t)hnd->size);
Zohaib Alam1bb65612013-09-28 03:38:20 -04002123
Sushil Chauhan1f6d68f2013-10-11 11:49:35 -07002124 // Handle R/B swap
2125 if (layer->flags & HWC_FORMAT_RB_SWAP) {
2126 if (hnd->format == HAL_PIXEL_FORMAT_RGBA_8888)
2127 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRA_8888);
2128 else if (hnd->format == HAL_PIXEL_FORMAT_RGBX_8888)
2129 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRX_8888);
2130 }
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002131 // update source crop and destination position of AIV video layer.
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07002132 if(ctx->listStats[dpy].mAIVVideoMode && isYuvBuffer(hnd)) {
2133 updateCoordinates(ctx, crop, dst, dpy);
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002134 }
Ramkumar Radhakrishnan939a9e72013-12-04 18:30:18 -08002135 calcExtDisplayPosition(ctx, hnd, dpy, crop, dst, transform, orient);
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002136 int downscale = getRotDownscale(ctx, layer);
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08002137 setMdpFlags(ctx, layer, mdpFlags, downscale, transform);
Saurabh Shahacf10202013-02-26 10:15:15 -08002138
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08002139 //if 90 component or downscale, use rot
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002140 if((has90Transform(layer) or downscale) and isRotationDoable(ctx, hnd)) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002141 *rot = ctx->mRotMgr->getNext();
2142 if(*rot == NULL) return -1;
Saurabh Shah39240c92014-03-31 10:31:42 -07002143 ctx->mLayerRotMap[dpy]->add(layer, *rot);
Saurabh Shahcd018352014-11-11 13:54:19 -08002144 BwcPM::setBwc(ctx, dpy, hnd, crop, dst, transform, downscale,
2145 mdpFlags);
Saurabh Shahacf10202013-02-26 10:15:15 -08002146 //Configure rotator for pre-rotation
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07002147 if(configRotator(*rot, whf, crop, mdpFlags, orient, downscale) < 0) {
2148 ALOGE("%s: configRotator failed!", __FUNCTION__);
Saurabh Shahacf10202013-02-26 10:15:15 -08002149 return -1;
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07002150 }
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07002151 updateSource(orient, whf, crop, *rot);
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002152 rotFlags |= ROT_PREROTATED;
Saurabh Shahacf10202013-02-26 10:15:15 -08002153 }
2154
Saurabh Shah76fd6552013-03-14 14:45:38 -07002155 //For the mdp, since either we are pre-rotating or MDP does flips
2156 orient = OVERLAY_TRANSFORM_0;
2157 transform = 0;
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002158 PipeArgs parg(mdpFlags, whf, z,
Naseer Ahmed522ce662013-03-18 20:14:05 -04002159 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2160 (ovutils::eBlending) getBlending(layer->blending));
2161
Saurabh Shah5daeee52013-01-23 16:52:26 +08002162 if(configMdp(ctx->mOverlay, parg, orient, crop, dst, metadata, dest) < 0) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002163 ALOGE("%s: commit failed for low res panel", __FUNCTION__);
2164 return -1;
2165 }
2166 return 0;
2167}
2168
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002169//Helper to 1) Ensure crops dont have gaps 2) Ensure L and W are even
Sushil Chauhan15a2ea62013-09-04 18:28:36 -07002170void sanitizeSourceCrop(hwc_rect_t& cropL, hwc_rect_t& cropR,
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002171 private_handle_t *hnd) {
2172 if(cropL.right - cropL.left) {
2173 if(isYuvBuffer(hnd)) {
2174 //Always safe to even down left
2175 ovutils::even_floor(cropL.left);
2176 //If right is even, automatically width is even, since left is
2177 //already even
2178 ovutils::even_floor(cropL.right);
2179 }
2180 //Make sure there are no gaps between left and right splits if the layer
2181 //is spread across BOTH halves
2182 if(cropR.right - cropR.left) {
2183 cropR.left = cropL.right;
2184 }
2185 }
2186
2187 if(cropR.right - cropR.left) {
2188 if(isYuvBuffer(hnd)) {
2189 //Always safe to even down left
2190 ovutils::even_floor(cropR.left);
2191 //If right is even, automatically width is even, since left is
2192 //already even
2193 ovutils::even_floor(cropR.right);
2194 }
2195 }
2196}
2197
Saurabh Shah88e4d272013-09-03 13:31:29 -07002198int configureSplit(hwc_context_t *ctx, hwc_layer_1_t *layer,
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07002199 const int& dpy, eMdpFlags& mdpFlagsL, eZorder& z,
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002200 const eDest& lDest, const eDest& rDest,
Saurabh Shahacf10202013-02-26 10:15:15 -08002201 Rotator **rot) {
2202 private_handle_t *hnd = (private_handle_t *)layer->handle;
2203 if(!hnd) {
2204 ALOGE("%s: layer handle is NULL", __FUNCTION__);
2205 return -1;
2206 }
2207
Saurabh Shah5daeee52013-01-23 16:52:26 +08002208 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
2209
Saurabh Shahacf10202013-02-26 10:15:15 -08002210 int hw_w = ctx->dpyAttr[dpy].xres;
2211 int hw_h = ctx->dpyAttr[dpy].yres;
Saurabh Shah62e1d732013-09-17 10:44:05 -07002212 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shahacf10202013-02-26 10:15:15 -08002213 hwc_rect_t dst = layer->displayFrame;
2214 int transform = layer->transform;
2215 eTransform orient = static_cast<eTransform>(transform);
Saurabh Shahacf10202013-02-26 10:15:15 -08002216 int rotFlags = ROT_FLAGS_NONE;
Sushil Chauhan65e26302015-01-14 10:48:57 -08002217 uint32_t format = ovutils::getMdpFormat(hnd->format, hnd->flags);
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05302218 Whf whf(getWidth(hnd), getHeight(hnd), format, (uint32_t)hnd->size);
Zohaib Alam1bb65612013-09-28 03:38:20 -04002219
Sushil Chauhan1f6d68f2013-10-11 11:49:35 -07002220 // Handle R/B swap
2221 if (layer->flags & HWC_FORMAT_RB_SWAP) {
2222 if (hnd->format == HAL_PIXEL_FORMAT_RGBA_8888)
2223 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRA_8888);
2224 else if (hnd->format == HAL_PIXEL_FORMAT_RGBX_8888)
2225 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRX_8888);
2226 }
2227
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002228 // update source crop and destination position of AIV video layer.
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07002229 if(ctx->listStats[dpy].mAIVVideoMode && isYuvBuffer(hnd)) {
2230 updateCoordinates(ctx, crop, dst, dpy);
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002231 }
2232
2233 /* Calculate the external display position based on MDP downscale,
Ramkumar Radhakrishnana61a0da2014-03-03 14:46:21 -08002234 ActionSafe, and extorientation features. */
2235 calcExtDisplayPosition(ctx, hnd, dpy, crop, dst, transform, orient);
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002236 int downscale = getRotDownscale(ctx, layer);
2237 setMdpFlags(ctx, layer, mdpFlagsL, downscale, transform);
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002238
2239 if(lDest != OV_INVALID && rDest != OV_INVALID) {
2240 //Enable overfetch
2241 setMdpFlags(mdpFlagsL, OV_MDSS_MDP_DUAL_PIPE);
2242 }
2243
Saurabh Shaha9da08f2013-07-03 13:27:53 -07002244 //Will do something only if feature enabled and conditions suitable
2245 //hollow call otherwise
2246 if(ctx->mAD->prepare(ctx, crop, whf, hnd)) {
2247 overlay::Writeback *wb = overlay::Writeback::getInstance();
2248 whf.format = wb->getOutputFormat();
2249 }
2250
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002251 if((has90Transform(layer) or downscale) and isRotationDoable(ctx, hnd)) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002252 (*rot) = ctx->mRotMgr->getNext();
2253 if((*rot) == NULL) return -1;
Saurabh Shah39240c92014-03-31 10:31:42 -07002254 ctx->mLayerRotMap[dpy]->add(layer, *rot);
Saurabh Shahacf10202013-02-26 10:15:15 -08002255 //Configure rotator for pre-rotation
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07002256 if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale) < 0) {
2257 ALOGE("%s: configRotator failed!", __FUNCTION__);
Saurabh Shahacf10202013-02-26 10:15:15 -08002258 return -1;
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07002259 }
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07002260 updateSource(orient, whf, crop, *rot);
Saurabh Shahacf10202013-02-26 10:15:15 -08002261 rotFlags |= ROT_PREROTATED;
2262 }
2263
2264 eMdpFlags mdpFlagsR = mdpFlagsL;
2265 setMdpFlags(mdpFlagsR, OV_MDSS_MDP_RIGHT_MIXER);
2266
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002267 hwc_rect_t tmp_cropL = {0}, tmp_dstL = {0};
2268 hwc_rect_t tmp_cropR = {0}, tmp_dstR = {0};
Saurabh Shahacf10202013-02-26 10:15:15 -08002269
Saurabh Shah07a8ca82013-08-06 18:45:42 -07002270 const int lSplit = getLeftSplit(ctx, dpy);
2271
Jeykumar Sankaran8b40b432014-05-30 23:26:59 -07002272 // Calculate Left rects
2273 if(dst.left < lSplit) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002274 tmp_cropL = crop;
2275 tmp_dstL = dst;
Saurabh Shah67a38c32013-06-10 16:23:15 -07002276 hwc_rect_t scissor = {0, 0, lSplit, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -08002277 scissor = getIntersection(ctx->mViewFrame[dpy], scissor);
Saurabh Shahacf10202013-02-26 10:15:15 -08002278 qhwc::calculate_crop_rects(tmp_cropL, tmp_dstL, scissor, 0);
2279 }
Jeykumar Sankaran8b40b432014-05-30 23:26:59 -07002280
2281 // Calculate Right rects
2282 if(dst.right > lSplit) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002283 tmp_cropR = crop;
2284 tmp_dstR = dst;
Saurabh Shah67a38c32013-06-10 16:23:15 -07002285 hwc_rect_t scissor = {lSplit, 0, hw_w, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -08002286 scissor = getIntersection(ctx->mViewFrame[dpy], scissor);
Saurabh Shahacf10202013-02-26 10:15:15 -08002287 qhwc::calculate_crop_rects(tmp_cropR, tmp_dstR, scissor, 0);
2288 }
2289
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002290 sanitizeSourceCrop(tmp_cropL, tmp_cropR, hnd);
2291
Saurabh Shah94d62362013-07-02 10:58:48 -07002292 //When buffer is H-flipped, contents of mixer config also needs to swapped
Saurabh Shahacf10202013-02-26 10:15:15 -08002293 //Not needed if the layer is confined to one half of the screen.
2294 //If rotator has been used then it has also done the flips, so ignore them.
Jeykumar Sankaran8b40b432014-05-30 23:26:59 -07002295 if((orient & OVERLAY_TRANSFORM_FLIP_H) && (dst.left < lSplit) &&
2296 (dst.right > lSplit) && (*rot) == NULL) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002297 hwc_rect_t new_cropR;
2298 new_cropR.left = tmp_cropL.left;
2299 new_cropR.right = new_cropR.left + (tmp_cropR.right - tmp_cropR.left);
2300
2301 hwc_rect_t new_cropL;
2302 new_cropL.left = new_cropR.right;
2303 new_cropL.right = tmp_cropR.right;
2304
2305 tmp_cropL.left = new_cropL.left;
2306 tmp_cropL.right = new_cropL.right;
2307
2308 tmp_cropR.left = new_cropR.left;
2309 tmp_cropR.right = new_cropR.right;
2310
2311 }
2312
Saurabh Shah76fd6552013-03-14 14:45:38 -07002313 //For the mdp, since either we are pre-rotating or MDP does flips
2314 orient = OVERLAY_TRANSFORM_0;
2315 transform = 0;
2316
Saurabh Shahacf10202013-02-26 10:15:15 -08002317 //configure left mixer
2318 if(lDest != OV_INVALID) {
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002319 PipeArgs pargL(mdpFlagsL, whf, z,
Naseer Ahmed522ce662013-03-18 20:14:05 -04002320 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2321 (ovutils::eBlending) getBlending(layer->blending));
2322
Saurabh Shahacf10202013-02-26 10:15:15 -08002323 if(configMdp(ctx->mOverlay, pargL, orient,
Saurabh Shah5daeee52013-01-23 16:52:26 +08002324 tmp_cropL, tmp_dstL, metadata, lDest) < 0) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002325 ALOGE("%s: commit failed for left mixer config", __FUNCTION__);
2326 return -1;
2327 }
2328 }
2329
2330 //configure right mixer
2331 if(rDest != OV_INVALID) {
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002332 PipeArgs pargR(mdpFlagsR, whf, z,
Naseer Ahmed522ce662013-03-18 20:14:05 -04002333 static_cast<eRotFlags>(rotFlags),
2334 layer->planeAlpha,
2335 (ovutils::eBlending) getBlending(layer->blending));
Saurabh Shah67a38c32013-06-10 16:23:15 -07002336 tmp_dstR.right = tmp_dstR.right - lSplit;
2337 tmp_dstR.left = tmp_dstR.left - lSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08002338 if(configMdp(ctx->mOverlay, pargR, orient,
Saurabh Shah5daeee52013-01-23 16:52:26 +08002339 tmp_cropR, tmp_dstR, metadata, rDest) < 0) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002340 ALOGE("%s: commit failed for right mixer config", __FUNCTION__);
2341 return -1;
2342 }
2343 }
2344
2345 return 0;
2346}
Arun Kumar K.Ra2978452013-02-07 01:34:24 -08002347
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -05002348int configure3DVideo(hwc_context_t *ctx, hwc_layer_1_t *layer,
2349 const int& dpy, eMdpFlags& mdpFlagsL, eZorder& z,
2350 const eDest& lDest, const eDest& rDest,
2351 Rotator **rot) {
2352 private_handle_t *hnd = (private_handle_t *)layer->handle;
2353 if(!hnd) {
2354 ALOGE("%s: layer handle is NULL", __FUNCTION__);
2355 return -1;
2356 }
2357 //Both pipes are configured to the same mixer
2358 eZorder lz = z;
2359 eZorder rz = (eZorder)(z + 1);
2360
2361 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
2362
2363 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
2364 hwc_rect_t dst = layer->displayFrame;
2365 int transform = layer->transform;
2366 eTransform orient = static_cast<eTransform>(transform);
2367 int rotFlags = ROT_FLAGS_NONE;
2368 uint32_t format = ovutils::getMdpFormat(hnd->format, hnd->flags);
2369 Whf whf(getWidth(hnd), getHeight(hnd), format, (uint32_t)hnd->size);
2370
2371 int downscale = getRotDownscale(ctx, layer);
2372 setMdpFlags(ctx, layer, mdpFlagsL, downscale, transform);
2373
2374 //XXX: Check if rotation is supported and valid for 3D
2375 if((has90Transform(layer) or downscale) and isRotationDoable(ctx, hnd)) {
2376 (*rot) = ctx->mRotMgr->getNext();
2377 if((*rot) == NULL) return -1;
2378 ctx->mLayerRotMap[dpy]->add(layer, *rot);
2379 //Configure rotator for pre-rotation
2380 if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale) < 0) {
2381 ALOGE("%s: configRotator failed!", __FUNCTION__);
2382 return -1;
2383 }
2384 updateSource(orient, whf, crop, *rot);
2385 rotFlags |= ROT_PREROTATED;
2386 }
2387
2388 eMdpFlags mdpFlagsR = mdpFlagsL;
2389
2390 hwc_rect_t cropL = crop, dstL = dst;
2391 hwc_rect_t cropR = crop, dstR = dst;
2392 int hw_w = ctx->dpyAttr[dpy].xres;
2393 int hw_h = ctx->dpyAttr[dpy].yres;
2394
2395 if(get3DFormat(hnd) == HAL_3D_SIDE_BY_SIDE_L_R ||
2396 get3DFormat(hnd) == HAL_3D_SIDE_BY_SIDE_R_L) {
2397 // Calculate Left rects
2398 // XXX: This assumes crop.right/2 is the center point of the video
2399 cropL.right = crop.right/2;
2400 dstL.left = dst.left/2;
2401 dstL.right = dst.right/2;
2402
2403 // Calculate Right rects
2404 cropR.left = crop.right/2;
2405 dstR.left = hw_w/2 + dst.left/2;
2406 dstR.right = hw_w/2 + dst.right/2;
2407 } else if(get3DFormat(hnd) == HAL_3D_TOP_BOTTOM) {
2408 // Calculate Left rects
2409 cropL.bottom = crop.bottom/2;
2410 dstL.top = dst.top/2;
2411 dstL.bottom = dst.bottom/2;
2412
2413 // Calculate Right rects
2414 cropR.top = crop.bottom/2;
2415 dstR.top = hw_h/2 + dst.top/2;
2416 dstR.bottom = hw_h/2 + dst.bottom/2;
2417 } else {
2418 ALOGE("%s: Unsupported 3D mode ", __FUNCTION__);
2419 return -1;
2420 }
2421
2422 //For the mdp, since either we are pre-rotating or MDP does flips
2423 orient = OVERLAY_TRANSFORM_0;
2424 transform = 0;
2425
2426 //configure left pipe
2427 if(lDest != OV_INVALID) {
2428 PipeArgs pargL(mdpFlagsL, whf, lz,
2429 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2430 (ovutils::eBlending) getBlending(layer->blending));
2431
2432 if(configMdp(ctx->mOverlay, pargL, orient,
2433 cropL, dstL, metadata, lDest) < 0) {
2434 ALOGE("%s: commit failed for left mixer config", __FUNCTION__);
2435 return -1;
2436 }
2437 }
2438
2439 //configure right pipe
2440 if(rDest != OV_INVALID) {
2441 PipeArgs pargR(mdpFlagsR, whf, rz,
2442 static_cast<eRotFlags>(rotFlags),
2443 layer->planeAlpha,
2444 (ovutils::eBlending) getBlending(layer->blending));
2445 if(configMdp(ctx->mOverlay, pargR, orient,
2446 cropR, dstR, metadata, rDest) < 0) {
2447 ALOGE("%s: commit failed for right mixer config", __FUNCTION__);
2448 return -1;
2449 }
2450 }
2451
2452 return 0;
2453}
2454
radhakrishnac9a67412013-09-25 17:40:42 +05302455int configureSourceSplit(hwc_context_t *ctx, hwc_layer_1_t *layer,
2456 const int& dpy, eMdpFlags& mdpFlagsL, eZorder& z,
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002457 const eDest& lDest, const eDest& rDest,
radhakrishnac9a67412013-09-25 17:40:42 +05302458 Rotator **rot) {
2459 private_handle_t *hnd = (private_handle_t *)layer->handle;
2460 if(!hnd) {
2461 ALOGE("%s: layer handle is NULL", __FUNCTION__);
2462 return -1;
2463 }
2464
2465 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
2466
radhakrishnac9a67412013-09-25 17:40:42 +05302467 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);;
2468 hwc_rect_t dst = layer->displayFrame;
2469 int transform = layer->transform;
2470 eTransform orient = static_cast<eTransform>(transform);
2471 const int downscale = 0;
2472 int rotFlags = ROT_FLAGS_NONE;
2473 //Splitting only YUV layer on primary panel needs different zorders
2474 //for both layers as both the layers are configured to single mixer
2475 eZorder lz = z;
2476 eZorder rz = (eZorder)(z + 1);
2477
2478 Whf whf(getWidth(hnd), getHeight(hnd),
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05302479 getMdpFormat(hnd->format), (uint32_t)hnd->size);
radhakrishnac9a67412013-09-25 17:40:42 +05302480
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002481 // update source crop and destination position of AIV video layer.
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07002482 if(ctx->listStats[dpy].mAIVVideoMode && isYuvBuffer(hnd)) {
2483 updateCoordinates(ctx, crop, dst, dpy);
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002484 }
2485
Ramkumar Radhakrishnan8ab3f5d2014-02-20 19:37:15 -08002486 /* Calculate the external display position based on MDP downscale,
2487 ActionSafe, and extorientation features. */
2488 calcExtDisplayPosition(ctx, hnd, dpy, crop, dst, transform, orient);
2489
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08002490 setMdpFlags(ctx, layer, mdpFlagsL, 0, transform);
radhakrishnac9a67412013-09-25 17:40:42 +05302491 trimLayer(ctx, dpy, transform, crop, dst);
2492
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08002493 if(has90Transform(layer) && isRotationDoable(ctx, hnd)) {
radhakrishnac9a67412013-09-25 17:40:42 +05302494 (*rot) = ctx->mRotMgr->getNext();
2495 if((*rot) == NULL) return -1;
Saurabh Shah39240c92014-03-31 10:31:42 -07002496 ctx->mLayerRotMap[dpy]->add(layer, *rot);
radhakrishnac9a67412013-09-25 17:40:42 +05302497 //Configure rotator for pre-rotation
2498 if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale) < 0) {
2499 ALOGE("%s: configRotator failed!", __FUNCTION__);
radhakrishnac9a67412013-09-25 17:40:42 +05302500 return -1;
2501 }
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07002502 updateSource(orient, whf, crop, *rot);
radhakrishnac9a67412013-09-25 17:40:42 +05302503 rotFlags |= ROT_PREROTATED;
2504 }
2505
2506 eMdpFlags mdpFlagsR = mdpFlagsL;
2507 int lSplit = dst.left + (dst.right - dst.left)/2;
2508
2509 hwc_rect_t tmp_cropL = {0}, tmp_dstL = {0};
2510 hwc_rect_t tmp_cropR = {0}, tmp_dstR = {0};
2511
2512 if(lDest != OV_INVALID) {
2513 tmp_cropL = crop;
2514 tmp_dstL = dst;
2515 hwc_rect_t scissor = {dst.left, dst.top, lSplit, dst.bottom };
2516 qhwc::calculate_crop_rects(tmp_cropL, tmp_dstL, scissor, 0);
2517 }
2518 if(rDest != OV_INVALID) {
2519 tmp_cropR = crop;
2520 tmp_dstR = dst;
2521 hwc_rect_t scissor = {lSplit, dst.top, dst.right, dst.bottom };
2522 qhwc::calculate_crop_rects(tmp_cropR, tmp_dstR, scissor, 0);
2523 }
2524
2525 sanitizeSourceCrop(tmp_cropL, tmp_cropR, hnd);
2526
2527 //When buffer is H-flipped, contents of mixer config also needs to swapped
2528 //Not needed if the layer is confined to one half of the screen.
2529 //If rotator has been used then it has also done the flips, so ignore them.
2530 if((orient & OVERLAY_TRANSFORM_FLIP_H) && lDest != OV_INVALID
2531 && rDest != OV_INVALID && (*rot) == NULL) {
2532 hwc_rect_t new_cropR;
2533 new_cropR.left = tmp_cropL.left;
2534 new_cropR.right = new_cropR.left + (tmp_cropR.right - tmp_cropR.left);
2535
2536 hwc_rect_t new_cropL;
2537 new_cropL.left = new_cropR.right;
2538 new_cropL.right = tmp_cropR.right;
2539
2540 tmp_cropL.left = new_cropL.left;
2541 tmp_cropL.right = new_cropL.right;
2542
2543 tmp_cropR.left = new_cropR.left;
2544 tmp_cropR.right = new_cropR.right;
2545
2546 }
2547
2548 //For the mdp, since either we are pre-rotating or MDP does flips
2549 orient = OVERLAY_TRANSFORM_0;
2550 transform = 0;
2551
2552 //configure left half
2553 if(lDest != OV_INVALID) {
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002554 PipeArgs pargL(mdpFlagsL, whf, lz,
radhakrishnac9a67412013-09-25 17:40:42 +05302555 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2556 (ovutils::eBlending) getBlending(layer->blending));
2557
2558 if(configMdp(ctx->mOverlay, pargL, orient,
2559 tmp_cropL, tmp_dstL, metadata, lDest) < 0) {
2560 ALOGE("%s: commit failed for left half config", __FUNCTION__);
2561 return -1;
2562 }
2563 }
2564
2565 //configure right half
2566 if(rDest != OV_INVALID) {
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002567 PipeArgs pargR(mdpFlagsR, whf, rz,
radhakrishnac9a67412013-09-25 17:40:42 +05302568 static_cast<eRotFlags>(rotFlags),
2569 layer->planeAlpha,
2570 (ovutils::eBlending) getBlending(layer->blending));
2571 if(configMdp(ctx->mOverlay, pargR, orient,
2572 tmp_cropR, tmp_dstR, metadata, rDest) < 0) {
2573 ALOGE("%s: commit failed for right half config", __FUNCTION__);
2574 return -1;
2575 }
2576 }
2577
2578 return 0;
2579}
2580
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -07002581bool canUseRotator(hwc_context_t *ctx, int dpy) {
Raj Kamal068f4572014-04-14 16:14:06 +05302582 if(ctx->mOverlay->isDMAMultiplexingSupported() &&
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08002583 isSecondaryConnected(ctx) &&
Amara Venkata Mastan Manoj Kumar5cbac942013-08-13 19:00:14 -07002584 !ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isPause) {
Raj Kamal068f4572014-04-14 16:14:06 +05302585 /* mdss driver on certain targets support multiplexing of DMA pipe
Raj Kamala8c065f2013-10-22 14:52:45 +05302586 * in LINE and BLOCK modes for writeback panels.
2587 */
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -07002588 if(dpy == HWC_DISPLAY_PRIMARY)
2589 return false;
Saurabh Shahe2474082013-05-15 16:32:13 -07002590 }
Ramakant Singhb4106a12014-10-07 18:06:56 +05302591 if((ctx->mMDP.version == qdutils::MDP_V3_0_4)
2592 ||(ctx->mMDP.version == qdutils::MDP_V3_0_5))
Terence Hampson45c02ef2013-05-17 17:00:11 -04002593 return false;
Saurabh Shahe2474082013-05-15 16:32:13 -07002594 return true;
2595}
2596
Saurabh Shah07a8ca82013-08-06 18:45:42 -07002597int getLeftSplit(hwc_context_t *ctx, const int& dpy) {
2598 //Default even split for all displays with high res
2599 int lSplit = ctx->dpyAttr[dpy].xres / 2;
2600 if(dpy == HWC_DISPLAY_PRIMARY &&
2601 qdutils::MDPVersion::getInstance().getLeftSplit()) {
2602 //Override if split published by driver for primary
2603 lSplit = qdutils::MDPVersion::getInstance().getLeftSplit();
2604 }
2605 return lSplit;
2606}
Saurabh Shah1a03d482013-05-29 13:44:20 -07002607
Saurabh Shah88e4d272013-09-03 13:31:29 -07002608bool isDisplaySplit(hwc_context_t* ctx, int dpy) {
Prabhanjan Kandula5bae9f52014-05-15 16:48:18 +05302609 qdutils::MDPVersion& mdpHw = qdutils::MDPVersion::getInstance();
Jeykumar Sankarandc76ba82015-01-28 14:51:50 -08002610 if(ctx->dpyAttr[dpy].xres > mdpHw.getMaxMixerWidth()) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07002611 return true;
2612 }
Prabhanjan Kandula5bae9f52014-05-15 16:48:18 +05302613 if(dpy == HWC_DISPLAY_PRIMARY && mdpHw.getRightSplit()) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07002614 return true;
2615 }
2616 return false;
2617}
2618
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08002619//clear prev layer prop flags and realloc for current frame
2620void reset_layer_prop(hwc_context_t* ctx, int dpy, int numAppLayers) {
2621 if(ctx->layerProp[dpy]) {
2622 delete[] ctx->layerProp[dpy];
2623 ctx->layerProp[dpy] = NULL;
2624 }
2625 ctx->layerProp[dpy] = new LayerProp[numAppLayers];
2626}
2627
Ramakant Singh0def28c2014-03-28 20:43:13 +05302628bool isAbcInUse(hwc_context_t *ctx){
2629 return (ctx->enableABC && ctx->listStats[0].renderBufIndexforABC == 0);
2630}
2631
Tatenda Chipeperekwa523eac52014-05-29 14:58:39 -07002632void dumpBuffer(private_handle_t *ohnd, char *bufferName) {
2633 if (ohnd != NULL && ohnd->base) {
2634 char dumpFilename[PATH_MAX];
2635 bool bResult = false;
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -07002636 int width = getWidth(ohnd);
2637 int height = getHeight(ohnd);
2638 int format = ohnd->format;
2639 //dummy aligned w & h.
2640 int alW = 0, alH = 0;
2641 int size = getBufferSizeAndDimensions(width, height, format, alW, alH);
Tatenda Chipeperekwa523eac52014-05-29 14:58:39 -07002642 snprintf(dumpFilename, sizeof(dumpFilename), "/data/%s.%s.%dx%d.raw",
2643 bufferName,
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -07002644 overlay::utils::getFormatString(utils::getMdpFormat(format)),
2645 width, height);
Tatenda Chipeperekwa523eac52014-05-29 14:58:39 -07002646 FILE* fp = fopen(dumpFilename, "w+");
2647 if (NULL != fp) {
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -07002648 bResult = (bool) fwrite((void*)ohnd->base, size, 1, fp);
Tatenda Chipeperekwa523eac52014-05-29 14:58:39 -07002649 fclose(fp);
2650 }
2651 ALOGD("Buffer[%s] Dump to %s: %s",
2652 bufferName, dumpFilename, bResult ? "Success" : "Fail");
2653 }
2654}
2655
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002656bool isGLESComp(hwc_context_t *ctx,
2657 hwc_display_contents_1_t* list) {
2658 int numAppLayers = ctx->listStats[HWC_DISPLAY_PRIMARY].numAppLayers;
2659 for(int index = 0; index < numAppLayers; index++) {
2660 hwc_layer_1_t* layer = &(list->hwLayers[index]);
2661 if(layer->compositionType == HWC_FRAMEBUFFER)
2662 return true;
2663 }
2664 return false;
2665}
2666
2667void setGPUHint(hwc_context_t* ctx, hwc_display_contents_1_t* list) {
2668 struct gpu_hint_info *gpuHint = &ctx->mGPUHintInfo;
Saurabh Shah74eff4d2014-03-28 16:33:13 -07002669 if(!gpuHint->mGpuPerfModeEnable || !ctx || !list)
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002670 return;
Saurabh Shah74eff4d2014-03-28 16:33:13 -07002671
2672#ifdef QCOM_BSP
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002673 /* Set the GPU hint flag to high for MIXED/GPU composition only for
2674 first frame after MDP -> GPU/MIXED mode transition. Set the GPU
2675 hint to default if the previous composition is GPU or current GPU
2676 composition is due to idle fallback */
2677 if(!gpuHint->mEGLDisplay || !gpuHint->mEGLContext) {
2678 gpuHint->mEGLDisplay = eglGetCurrentDisplay();
2679 if(!gpuHint->mEGLDisplay) {
2680 ALOGW("%s Warning: EGL current display is NULL", __FUNCTION__);
2681 return;
2682 }
2683 gpuHint->mEGLContext = eglGetCurrentContext();
2684 if(!gpuHint->mEGLContext) {
2685 ALOGW("%s Warning: EGL current context is NULL", __FUNCTION__);
2686 return;
2687 }
2688 }
2689 if(isGLESComp(ctx, list)) {
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -07002690 if(gpuHint->mCompositionState != COMPOSITION_STATE_GPU
2691 && !MDPComp::isIdleFallback()) {
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002692 EGLint attr_list[] = {EGL_GPU_HINT_1,
2693 EGL_GPU_LEVEL_3,
2694 EGL_NONE };
2695 if((gpuHint->mCurrGPUPerfMode != EGL_GPU_LEVEL_3) &&
2696 !eglGpuPerfHintQCOM(gpuHint->mEGLDisplay,
2697 gpuHint->mEGLContext, attr_list)) {
2698 ALOGW("eglGpuPerfHintQCOM failed for Built in display");
2699 } else {
2700 gpuHint->mCurrGPUPerfMode = EGL_GPU_LEVEL_3;
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -07002701 gpuHint->mCompositionState = COMPOSITION_STATE_GPU;
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002702 }
2703 } else {
2704 EGLint attr_list[] = {EGL_GPU_HINT_1,
2705 EGL_GPU_LEVEL_0,
2706 EGL_NONE };
2707 if((gpuHint->mCurrGPUPerfMode != EGL_GPU_LEVEL_0) &&
2708 !eglGpuPerfHintQCOM(gpuHint->mEGLDisplay,
2709 gpuHint->mEGLContext, attr_list)) {
2710 ALOGW("eglGpuPerfHintQCOM failed for Built in display");
2711 } else {
2712 gpuHint->mCurrGPUPerfMode = EGL_GPU_LEVEL_0;
2713 }
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -07002714 if(MDPComp::isIdleFallback()) {
2715 gpuHint->mCompositionState = COMPOSITION_STATE_IDLE_FALLBACK;
2716 }
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002717 }
2718 } else {
2719 /* set the GPU hint flag to default for MDP composition */
2720 EGLint attr_list[] = {EGL_GPU_HINT_1,
2721 EGL_GPU_LEVEL_0,
2722 EGL_NONE };
2723 if((gpuHint->mCurrGPUPerfMode != EGL_GPU_LEVEL_0) &&
2724 !eglGpuPerfHintQCOM(gpuHint->mEGLDisplay,
2725 gpuHint->mEGLContext, attr_list)) {
2726 ALOGW("eglGpuPerfHintQCOM failed for Built in display");
2727 } else {
2728 gpuHint->mCurrGPUPerfMode = EGL_GPU_LEVEL_0;
2729 }
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -07002730 gpuHint->mCompositionState = COMPOSITION_STATE_MDP;
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002731 }
Saurabh Shah74eff4d2014-03-28 16:33:13 -07002732#endif
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002733}
2734
Sushil Chauhandefd3522014-05-13 18:17:12 -07002735bool isPeripheral(const hwc_rect_t& rect1, const hwc_rect_t& rect2) {
2736 // To be peripheral, 3 boundaries should match.
2737 uint8_t eqBounds = 0;
2738 if (rect1.left == rect2.left)
2739 eqBounds++;
2740 if (rect1.top == rect2.top)
2741 eqBounds++;
2742 if (rect1.right == rect2.right)
2743 eqBounds++;
2744 if (rect1.bottom == rect2.bottom)
2745 eqBounds++;
2746 return (eqBounds == 3);
2747}
2748
Krishna Chaitanya Parimidb992fd2014-10-22 20:50:50 +05302749void processBootAnimCompleted(hwc_context_t *ctx) {
2750 char value[PROPERTY_VALUE_MAX];
Nitesh Gupta538e0f72015-03-25 13:22:35 +05302751 int ret = -1;
Krishna Chaitanya Parimidb992fd2014-10-22 20:50:50 +05302752 int (*applyMode)(int) = NULL;
2753 void *modeHandle = NULL;
2754
Nitesh Gupta538e0f72015-03-25 13:22:35 +05302755 // Applying default mode after bootanimation is finished
2756 property_get("init.svc.bootanim", value, "running");
Krishna Chaitanya Parimidb992fd2014-10-22 20:50:50 +05302757
Nitesh Gupta538e0f72015-03-25 13:22:35 +05302758 if (!strncmp(value,"stopped",strlen("stopped"))) {
2759 modeHandle = dlopen("libmm-qdcm.so", RTLD_NOW);
2760 if (modeHandle) {
2761 *(void **)&applyMode = dlsym(modeHandle, "applyDefaults");
2762 if (applyMode) {
2763 ret = applyMode(HWC_DISPLAY_PRIMARY);
2764 if (ret)
2765 ALOGD("%s: Not able to apply default mode", __FUNCTION__);
2766 } else {
2767 ALOGE("%s: No symbol applyDefaults found", __FUNCTION__);
2768 }
2769 dlclose(modeHandle);
Krishna Chaitanya Parimidb992fd2014-10-22 20:50:50 +05302770 } else {
Nitesh Gupta538e0f72015-03-25 13:22:35 +05302771 ALOGE("%s: Not able to load libmm-qdcm.so", __FUNCTION__);
Krishna Chaitanya Parimidb992fd2014-10-22 20:50:50 +05302772 }
Krishna Chaitanya Parimidb992fd2014-10-22 20:50:50 +05302773
Nitesh Gupta538e0f72015-03-25 13:22:35 +05302774 ctx->mBootAnimCompleted = true;
2775 }
Krishna Chaitanya Parimidb992fd2014-10-22 20:50:50 +05302776}
2777
Saurabh Shahcd018352014-11-11 13:54:19 -08002778void BwcPM::setBwc(const hwc_context_t *ctx, const int& dpy,
2779 const private_handle_t *hnd,
2780 const hwc_rect_t& crop, const hwc_rect_t& dst,
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002781 const int& transform,const int& downscale,
2782 ovutils::eMdpFlags& mdpFlags) {
Saurabh Shah1a03d482013-05-29 13:44:20 -07002783 //Target doesnt support Bwc
Prabhanjan Kandula5bae9f52014-05-15 16:48:18 +05302784 qdutils::MDPVersion& mdpHw = qdutils::MDPVersion::getInstance();
Saurabh Shahcd018352014-11-11 13:54:19 -08002785 if(not mdpHw.supportsBWC()) {
Saurabh Shah1a03d482013-05-29 13:44:20 -07002786 return;
2787 }
Saurabh Shahcd018352014-11-11 13:54:19 -08002788 //Disabled at runtime
2789 if(not ctx->mBWCEnabled) return;
2790 //BWC not supported with rot-downscale
2791 if(downscale) return;
2792 //Not enabled for secondary displays
2793 if(dpy) return;
2794 //Not enabled for non-video buffers
2795 if(not isYuvBuffer(hnd)) return;
2796
Saurabh Shahb6810df2014-06-17 16:00:22 -07002797 int src_w = crop.right - crop.left;
2798 int src_h = crop.bottom - crop.top;
2799 int dst_w = dst.right - dst.left;
2800 int dst_h = dst.bottom - dst.top;
2801 if(transform & HAL_TRANSFORM_ROT_90) {
2802 swap(src_w, src_h);
2803 }
Saurabh Shah1a03d482013-05-29 13:44:20 -07002804 //src width > MAX mixer supported dim
Jeykumar Sankaran39305802014-12-12 17:55:57 -08002805 if(src_w > (int) qdutils::MDPVersion::getInstance().getMaxPipeWidth()) {
Saurabh Shah1a03d482013-05-29 13:44:20 -07002806 return;
2807 }
Saurabh Shah1a03d482013-05-29 13:44:20 -07002808 //Decimation necessary, cannot use BWC. H/W requirement.
2809 if(qdutils::MDPVersion::getInstance().supportsDecimation()) {
Saurabh Shahb6810df2014-06-17 16:00:22 -07002810 uint8_t horzDeci = 0;
2811 uint8_t vertDeci = 0;
2812 ovutils::getDecimationFactor(src_w, src_h, dst_w, dst_h, horzDeci,
2813 vertDeci);
Saurabh Shahc5b96dc2013-06-05 13:19:52 -07002814 if(horzDeci || vertDeci) return;
Saurabh Shah1a03d482013-05-29 13:44:20 -07002815 }
Saurabh Shah1a03d482013-05-29 13:44:20 -07002816
2817 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDSS_MDP_BWC_EN);
2818}
2819
Saurabh Shah23a813c2013-03-20 16:58:12 -07002820void LayerRotMap::add(hwc_layer_1_t* layer, Rotator *rot) {
Raj Kamal389d6e32014-08-04 14:43:24 +05302821 if(mCount >= RotMgr::MAX_ROT_SESS) return;
Saurabh Shah23a813c2013-03-20 16:58:12 -07002822 mLayer[mCount] = layer;
2823 mRot[mCount] = rot;
2824 mCount++;
2825}
2826
2827void LayerRotMap::reset() {
Raj Kamal389d6e32014-08-04 14:43:24 +05302828 for (int i = 0; i < RotMgr::MAX_ROT_SESS; i++) {
Saurabh Shah23a813c2013-03-20 16:58:12 -07002829 mLayer[i] = 0;
2830 mRot[i] = 0;
2831 }
2832 mCount = 0;
2833}
2834
Saurabh Shahda5b3ce2013-11-26 10:48:06 -08002835void LayerRotMap::clear() {
Saurabh Shah7a606842013-12-11 14:36:04 -08002836 RotMgr::getInstance()->markUnusedTop(mCount);
Saurabh Shahda5b3ce2013-11-26 10:48:06 -08002837 reset();
2838}
2839
Raj Kamalbd3bdc62014-08-05 18:52:49 +05302840bool LayerRotMap::isRotCached(uint32_t index) const {
2841 overlay::Rotator* rot = getRot(index);
2842 hwc_layer_1_t* layer = getLayer(index);
2843
2844 if(rot and layer and layer->handle) {
2845 private_handle_t *hnd = (private_handle_t *)(layer->handle);
2846 return (rot->isRotCached(hnd->fd,(uint32_t)(hnd->offset)));
2847 }
2848 return false;
2849}
2850
Saurabh Shah23a813c2013-03-20 16:58:12 -07002851void LayerRotMap::setReleaseFd(const int& fence) {
2852 for(uint32_t i = 0; i < mCount; i++) {
Raj Kamalbd3bdc62014-08-05 18:52:49 +05302853 if(mRot[i] and mLayer[i] and mLayer[i]->handle) {
2854 /* Ensure that none of the above (Rotator-instance,
2855 * layer and layer-handle) are NULL*/
2856 if(isRotCached(i))
2857 mRot[i]->setPrevBufReleaseFd(dup(fence));
2858 else
2859 mRot[i]->setCurrBufReleaseFd(dup(fence));
2860 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07002861 }
2862}
2863
Jeykumar Sankaranaedd1432015-01-15 11:25:03 -08002864hwc_rect expandROIFromMidPoint(hwc_rect roi, hwc_rect fullFrame) {
2865 int lRoiWidth = 0, rRoiWidth = 0;
2866 int half_frame_width = fullFrame.right/2;
2867
2868 hwc_rect lFrame = fullFrame;
2869 hwc_rect rFrame = fullFrame;
2870 lFrame.right = (lFrame.right - lFrame.left)/2;
2871 rFrame.left = lFrame.right;
2872
2873 hwc_rect lRoi = getIntersection(roi, lFrame);
2874 hwc_rect rRoi = getIntersection(roi, rFrame);
2875
2876 lRoiWidth = lRoi.right - lRoi.left;
2877 rRoiWidth = rRoi.right - rRoi.left;
2878
2879 if(lRoiWidth && rRoiWidth) {
2880 if(lRoiWidth < rRoiWidth)
2881 roi.left = half_frame_width - rRoiWidth;
2882 else
2883 roi.right = half_frame_width + lRoiWidth;
2884 }
2885 return roi;
2886}
2887
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002888void resetROI(hwc_context_t *ctx, const int dpy) {
2889 const int fbXRes = (int)ctx->dpyAttr[dpy].xres;
2890 const int fbYRes = (int)ctx->dpyAttr[dpy].yres;
Jeykumar Sankaranf7124b92015-02-26 10:34:35 -08002891
2892 /* When source split is enabled, both the panels are calibrated
2893 * in a single coordinate system. So only one ROI is generated
2894 * for the whole panel extending equally from the midpoint and
2895 * populated for the left side. */
2896 if(!qdutils::MDPVersion::getInstance().isSrcSplit() &&
2897 isDisplaySplit(ctx, dpy)) {
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002898 const int lSplit = getLeftSplit(ctx, dpy);
2899 ctx->listStats[dpy].lRoi = (struct hwc_rect){0, 0, lSplit, fbYRes};
2900 ctx->listStats[dpy].rRoi = (struct hwc_rect){lSplit, 0, fbXRes, fbYRes};
2901 } else {
2902 ctx->listStats[dpy].lRoi = (struct hwc_rect){0, 0,fbXRes, fbYRes};
2903 ctx->listStats[dpy].rRoi = (struct hwc_rect){0, 0, 0, 0};
2904 }
2905}
2906
2907hwc_rect_t getSanitizeROI(struct hwc_rect roi, hwc_rect boundary)
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002908{
2909 if(!isValidRect(roi))
2910 return roi;
2911
2912 struct hwc_rect t_roi = roi;
2913
2914 const int LEFT_ALIGN = qdutils::MDPVersion::getInstance().getLeftAlign();
2915 const int WIDTH_ALIGN = qdutils::MDPVersion::getInstance().getWidthAlign();
2916 const int TOP_ALIGN = qdutils::MDPVersion::getInstance().getTopAlign();
2917 const int HEIGHT_ALIGN = qdutils::MDPVersion::getInstance().getHeightAlign();
2918 const int MIN_WIDTH = qdutils::MDPVersion::getInstance().getMinROIWidth();
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002919 const int MIN_HEIGHT = qdutils::MDPVersion::getInstance().getMinROIHeight();
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002920
2921 /* Align to minimum width recommended by the panel */
2922 if((t_roi.right - t_roi.left) < MIN_WIDTH) {
2923 if((t_roi.left + MIN_WIDTH) > boundary.right)
2924 t_roi.left = t_roi.right - MIN_WIDTH;
2925 else
2926 t_roi.right = t_roi.left + MIN_WIDTH;
2927 }
2928
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002929 /* Align to minimum height recommended by the panel */
2930 if((t_roi.bottom - t_roi.top) < MIN_HEIGHT) {
2931 if((t_roi.top + MIN_HEIGHT) > boundary.bottom)
2932 t_roi.top = t_roi.bottom - MIN_HEIGHT;
2933 else
2934 t_roi.bottom = t_roi.top + MIN_HEIGHT;
2935 }
2936
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002937 /* Align left and width to meet panel restrictions */
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002938 if(LEFT_ALIGN)
2939 t_roi.left = t_roi.left - (t_roi.left % LEFT_ALIGN);
2940
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002941 if(WIDTH_ALIGN) {
2942 int width = t_roi.right - t_roi.left;
2943 width = WIDTH_ALIGN * ((width + (WIDTH_ALIGN - 1)) / WIDTH_ALIGN);
2944 t_roi.right = t_roi.left + width;
2945
2946 if(t_roi.right > boundary.right) {
2947 t_roi.right = boundary.right;
2948 t_roi.left = t_roi.right - width;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002949
2950 if(LEFT_ALIGN)
2951 t_roi.left = t_roi.left - (t_roi.left % LEFT_ALIGN);
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002952 }
2953 }
2954
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002955
2956 /* Align top and height to meet panel restrictions */
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002957 if(TOP_ALIGN)
2958 t_roi.top = t_roi.top - (t_roi.top % TOP_ALIGN);
2959
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002960 if(HEIGHT_ALIGN) {
2961 int height = t_roi.bottom - t_roi.top;
2962 height = HEIGHT_ALIGN * ((height + (HEIGHT_ALIGN - 1)) / HEIGHT_ALIGN);
2963 t_roi.bottom = t_roi.top + height;
2964
2965 if(t_roi.bottom > boundary.bottom) {
2966 t_roi.bottom = boundary.bottom;
2967 t_roi.top = t_roi.bottom - height;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002968
2969 if(TOP_ALIGN)
2970 t_roi.top = t_roi.top - (t_roi.top % TOP_ALIGN);
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002971 }
2972 }
2973
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002974
2975 return t_roi;
2976}
2977
Manoj Kumar AVM9591a5e2014-08-21 22:50:21 -07002978void handle_pause(hwc_context_t* ctx, int dpy) {
Arun Kumar K.R33888f52014-10-09 15:56:33 -07002979 if(ctx->dpyAttr[dpy].connected) {
2980 ctx->mDrawLock.lock();
2981 ctx->dpyAttr[dpy].isActive = true;
2982 ctx->dpyAttr[dpy].isPause = true;
2983 ctx->mDrawLock.unlock();
2984 ctx->proc->invalidate(ctx->proc);
2985
2986 usleep(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period
2987 * 2 / 1000);
2988
2989 // At this point all the pipes used by External have been
2990 // marked as UNSET.
2991 ctx->mDrawLock.lock();
2992 // Perform commit to unstage the pipes.
2993 if (!Overlay::displayCommit(ctx->dpyAttr[dpy].fd)) {
2994 ALOGE("%s: display commit fail! for %d dpy",
2995 __FUNCTION__, dpy);
2996 }
2997 ctx->mDrawLock.unlock();
2998 ctx->proc->invalidate(ctx->proc);
Manoj Kumar AVM9591a5e2014-08-21 22:50:21 -07002999 }
3000 return;
3001}
3002
3003void handle_resume(hwc_context_t* ctx, int dpy) {
Arun Kumar K.R33888f52014-10-09 15:56:33 -07003004 if(ctx->dpyAttr[dpy].connected) {
3005 ctx->mDrawLock.lock();
3006 ctx->dpyAttr[dpy].isConfiguring = true;
3007 ctx->dpyAttr[dpy].isActive = true;
3008 ctx->mDrawLock.unlock();
3009 ctx->proc->invalidate(ctx->proc);
3010
3011 usleep(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period
3012 * 2 / 1000);
3013
3014 //At this point external has all the pipes it would need.
3015 ctx->mDrawLock.lock();
3016 ctx->dpyAttr[dpy].isPause = false;
3017 ctx->mDrawLock.unlock();
3018 ctx->proc->invalidate(ctx->proc);
Manoj Kumar AVM9591a5e2014-08-21 22:50:21 -07003019 }
3020 return;
3021}
3022
Tatenda Chipeperekwad80b6172014-09-23 11:29:37 -07003023void clearPipeResources(hwc_context_t* ctx, int dpy) {
3024 if(ctx->mOverlay) {
3025 ctx->mOverlay->configBegin();
3026 ctx->mOverlay->configDone();
3027 }
3028 if(ctx->mRotMgr) {
3029 ctx->mRotMgr->clear();
3030 }
3031 // Call a display commit to ensure that pipes and associated
3032 // fd's are cleaned up.
3033 if(!Overlay::displayCommit(ctx->dpyAttr[dpy].fd)) {
3034 ALOGE("%s: display commit failed for %d", __FUNCTION__, dpy);
3035 }
3036}
3037
3038// Handles online events when HDMI is the primary display. In particular,
3039// online events for hdmi connected before AND after boot up and HWC init.
3040void handle_online(hwc_context_t* ctx, int dpy) {
3041 // Close the current fd if it was opened earlier on when HWC
3042 // was initialized.
3043 if (ctx->dpyAttr[dpy].fd >= 0) {
3044 close(ctx->dpyAttr[dpy].fd);
3045 ctx->dpyAttr[dpy].fd = -1;
3046 }
3047 // TODO: If HDMI is connected after the display has booted up,
3048 // and the best configuration is different from the default
3049 // then we need to deal with this appropriately.
Arun Kumar K.R205df772015-02-20 18:45:58 -08003050 int error = ctx->mHDMIDisplay->configure();
3051 if (error < 0) {
3052 ALOGE("Error opening FrameBuffer");
3053 return;
3054 }
Tatenda Chipeperekwad80b6172014-09-23 11:29:37 -07003055 updateDisplayInfo(ctx, dpy);
3056 initCompositionResources(ctx, dpy);
3057 ctx->dpyAttr[dpy].connected = true;
3058}
3059
3060// Handles offline events for HDMI. This can be used for offline events
3061// initiated by the HDMI driver and the CEC framework.
3062void handle_offline(hwc_context_t* ctx, int dpy) {
3063 destroyCompositionResources(ctx, dpy);
3064 // Clear all pipe resources and call a display commit to ensure
3065 // that all the fd's are closed. This will ensure that the HDMI
3066 // core turns off and that we receive an event the next time the
3067 // cable is connected.
3068 if (ctx->mHDMIDisplay->isHDMIPrimaryDisplay()) {
3069 clearPipeResources(ctx, dpy);
3070 }
3071 ctx->mHDMIDisplay->teardown();
3072 resetDisplayInfo(ctx, dpy);
3073 ctx->dpyAttr[dpy].connected = false;
3074 ctx->dpyAttr[dpy].isActive = false;
3075}
3076
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -05003077int convertS3DFormatToMode(int s3DFormat) {
3078 int ret;
3079 switch(s3DFormat) {
3080 case HAL_3D_SIDE_BY_SIDE_L_R:
3081 case HAL_3D_SIDE_BY_SIDE_R_L:
3082 ret = HDMI_S3D_SIDE_BY_SIDE;
3083 break;
3084 case HAL_3D_TOP_BOTTOM:
3085 ret = HDMI_S3D_TOP_AND_BOTTOM;
3086 break;
3087 default:
3088 ret = HDMI_S3D_NONE;
3089 }
3090 return ret;
3091}
3092
3093bool needs3DComposition(hwc_context_t* ctx, int dpy) {
3094 return (displaySupports3D(ctx, dpy) && ctx->dpyAttr[dpy].connected &&
3095 ctx->dpyAttr[dpy].s3dMode != HDMI_S3D_NONE);
3096}
3097
3098void setup3DMode(hwc_context_t *ctx, int dpy, int s3dMode) {
3099 if (ctx->dpyAttr[dpy].s3dMode != s3dMode) {
3100 ALOGD("%s: setup 3D mode: %d", __FUNCTION__, s3dMode);
3101 if(ctx->mHDMIDisplay->configure3D(s3dMode)) {
3102 ctx->dpyAttr[dpy].s3dMode = s3dMode;
3103 }
3104 }
3105}
3106
3107bool displaySupports3D(hwc_context_t* ctx, int dpy) {
3108 return ((dpy == HWC_DISPLAY_EXTERNAL) ||
3109 ((dpy == HWC_DISPLAY_PRIMARY) &&
3110 ctx->mHDMIDisplay->isHDMIPrimaryDisplay()));
3111}
3112
3113
Saurabh Shahacf10202013-02-26 10:15:15 -08003114};//namespace qhwc